<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Wines</title>
</head>
<body>
    <h1>Wines</h1>

    <a href="{{ route('wines.create') }}">Create New Wine</a>

    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Vintage</th>
                <th>Grape Variety</th>
                <th>Wine Type</th>
                <th>Status</th>
                <th>Price</th>
                <th>Stock</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @forelse($wines as $wine)
                <tr>
                    <td>{{ $wine->wine_name }}</td>
                    <td>{{ $wine->vintage }}</td>
                    <td>{{ $wine->grapeVariety->variety_name ?? 'N/A' }}</td>
                    <td>{{ $wine->wine_type }}</td>
                    <td>{{ $wine->status }}</td>
                    <td>{{ $wine->price_per_bottle ? number_format($wine->price_per_bottle, 2) : 'N/A' }}</td>
                    <td>{{ $wine->bottles_in_stock }} / {{ $wine->bottles_produced }}</td>
                    <td>
                        <a href="{{ route('wines.show', $wine) }}">View</a>
                        <a href="{{ route('wines.edit', $wine) }}">Edit</a>
                        <form action="{{ route('wines.destroy', $wine) }}" method="POST" style="display: inline;">
                            @csrf
                            @method('DELETE')
                            <button type="submit">Delete</button>
                        </form>
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="8">No wines found.</td>
                </tr>
            @endforelse
        </tbody>
    </table>

    {{ $wines->links() }}
</body>
</html>
