@extends('layouts.admin')

@section('title', 'Produits')
@section('page-title', 'Gestion des Produits')

@section('content')

<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
    <div>
        <p class="text-gray-500 text-sm">{{ $products->total() }} produit(s) au total</p>
    </div>
    <a href="{{ route('admin.products.create') }}"
       class="inline-flex items-center gap-2 bg-primary text-white px-5 py-2.5 rounded-xl font-medium hover:bg-primary-dark transition-all shadow-sm hover:shadow-md">
        <i class="fas fa-plus"></i> Ajouter un produit
    </a>
</div>

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
    <div class="overflow-x-auto">
        <table class="w-full text-sm">
            <thead>
                <tr class="bg-gray-50 border-b border-gray-100">
                    <th class="text-left px-5 py-3.5 font-semibold text-gray-600">Produit</th>
                    <th class="text-left px-5 py-3.5 font-semibold text-gray-600 hidden md:table-cell">Catégorie</th>
                    <th class="text-left px-5 py-3.5 font-semibold text-gray-600">Prix</th>
                    <th class="text-left px-5 py-3.5 font-semibold text-gray-600 hidden lg:table-cell">Statut</th>
                    <th class="text-right px-5 py-3.5 font-semibold text-gray-600">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-50">
                @forelse($products as $product)
                <tr class="hover:bg-gray-50 transition-colors">
                    <td class="px-5 py-3.5">
                        <div class="flex items-center gap-3">
                            <img src="{{ $product->image_url }}" alt="{{ $product->name }}"
                                 class="w-10 h-10 rounded-lg object-cover bg-gray-100"
                                 onerror="this.src='https://images.unsplash.com/photo-1578926288207-a90a5366a463?w=80&h=80&fit=crop'">
                            <div>
                                <div class="font-medium text-gray-800">{{ $product->name }}</div>
                                @if($product->is_featured)
                                <span class="inline-block text-xs text-yellow-600 font-medium">⭐ Vedette</span>
                                @endif
                            </div>
                        </div>
                    </td>
                    <td class="px-5 py-3.5 hidden md:table-cell">
                        <span class="bg-blue-50 text-blue-700 px-2.5 py-0.5 rounded-full text-xs font-medium">
                            {{ $product->category->name ?? '—' }}
                        </span>
                    </td>
                    <td class="px-5 py-3.5 font-semibold text-gray-800">
                        {{ number_format($product->price, 0, ',', ' ') }} FCFA
                    </td>
                    <td class="px-5 py-3.5 hidden lg:table-cell">
                        @if($product->is_active)
                        <span class="bg-green-100 text-green-700 px-2.5 py-0.5 rounded-full text-xs font-medium">Actif</span>
                        @else
                        <span class="bg-gray-100 text-gray-500 px-2.5 py-0.5 rounded-full text-xs font-medium">Inactif</span>
                        @endif
                    </td>
                    <td class="px-5 py-3.5 text-right">
                        <div class="flex items-center justify-end gap-2">
                            <a href="{{ route('admin.products.edit', $product) }}"
                               class="p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors" title="Modifier">
                                <i class="fas fa-edit"></i>
                            </a>
                            <form action="{{ route('admin.products.destroy', $product) }}" method="POST"
                                  onsubmit="return confirm('Supprimer ce produit ?')">
                                @csrf @method('DELETE')
                                <button type="submit" class="p-2 text-red-500 hover:bg-red-50 rounded-lg transition-colors" title="Supprimer">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </form>
                        </div>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="6" class="px-5 py-12 text-center text-gray-400">
                        <i class="fas fa-box-open text-3xl mb-2 block"></i>
                        Aucun produit trouvé.
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    @if($products->hasPages())
    <div class="px-5 py-4 border-t border-gray-100">
        {{ $products->links() }}
    </div>
    @endif
</div>

@endsection
