@extends('admin::layouts.master')

@section('title', 'Save The Food Products')

@section('content')
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2xl font-bold">Save The Food Products</h1>
        <a href="{{ route('admin.save-the-food-products.create') }}" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">Add</a>
    </div>

    <div class="bg-white rounded-lg shadow overflow-hidden">
        <table class="w-full">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">ID</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Product</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Discount %</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Stock</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Expires</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Featured</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-200">
                @forelse($saveTheFoodProducts as $stf)
                    <tr class="hover:bg-gray-50">
                        <td class="px-6 py-4">{{ $stf->id }}</td>
                        <td class="px-6 py-4">{{ $stf->product?->name ?? 'N/A' }}</td>
                        <td class="px-6 py-4">{{ $stf->discount_percentage }}%</td>
                        <td class="px-6 py-4">{{ $stf->stock_remaining }}</td>
                        <td class="px-6 py-4">{{ $stf->expires_at ? \Carbon\Carbon::parse($stf->expires_at)->format('Y-m-d') : '-' }}</td>
                        <td class="px-6 py-4">{{ $stf->is_featured ? 'Yes' : 'No' }}</td>
                        <td class="px-6 py-4 space-x-2">
                            <a href="{{ route('admin.save-the-food-products.edit', $stf->id) }}" class="text-blue-600 hover:underline">Edit</a>
                            <form action="{{ route('admin.save-the-food-products.destroy', $stf->id) }}" method="POST" class="inline" onsubmit="return confirm('Delete?')">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="text-red-600 hover:underline">Delete</button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="7" class="px-6 py-4 text-center text-gray-500">No save the food products found.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $saveTheFoodProducts->links() }}</div>
@endsection
