@extends('layouts.app')

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

@section('content')
<div class="space-y-6">
    <!-- En-tête avec bouton d'ajout -->
    <div class="flex justify-between items-center">
        <div>
            <h1 class="text-2xl font-bold text-gray-900">Gestion des Produits</h1>
            <p class="mt-1 text-sm text-gray-600">Gérez tous les produits de l'hôpital</p>
        </div>
        <button type="button" data-modal-toggle="modal-new-product" class="inline-flex items-center px-5 py-2.5 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg shadow-sm hover:shadow-md transition-all">
            <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
            </svg>
            Nouveau produit
        </button>
    </div>

    <!-- Filtres et recherche -->
    <div class="bg-white dark:bg-white shadow-sm border border-gray-200 rounded-xl p-4">
        <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
            <div class="md:col-span-2">
                <input type="text" placeholder="Rechercher un produit..." class="w-full px-4 py-2.5 border border-gray-200 rounded-lg bg-white text-gray-900 focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all">
            </div>
            <div>
                <select class="w-full px-4 py-2.5 border border-gray-200 rounded-lg bg-white text-gray-900 focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all">
                    <option>Toutes les catégories</option>
                    <option>Alimentaire</option>
                    <option>Entretien</option>
                    <option>Fournitures</option>
                </select>
            </div>
            <div>
                <select class="w-full px-4 py-2.5 border border-gray-200 rounded-lg bg-white text-gray-900 focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all">
                    <option>Tous les statuts</option>
                    <option>Actif</option>
                    <option>Inactif</option>
                </select>
            </div>
        </div>
    </div>

    <!-- Tableau des produits -->
    <div class="bg-white dark:bg-white shadow-sm border border-gray-200 rounded-xl overflow-hidden">
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider">
                            Produit
                        </th>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider">
                            Catégorie
                        </th>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider">
                            Fournisseur
                        </th>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider">
                            Unité
                        </th>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider">
                            Stock
                        </th>
                        <th class="px-6 py-4 text-right text-xs font-semibold text-gray-700 uppercase tracking-wider">
                            Actions
                        </th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    <tr class="hover:bg-blue-50/50 transition-colors">
                        <td colspan="6" class="px-6 py-12 text-center">
                            <div class="flex flex-col items-center">
                                <svg class="w-16 h-16 text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
                                </svg>
                                <p class="text-sm font-medium text-gray-600 mb-1">Aucun produit trouvé</p>
                                <p class="text-xs text-gray-500">Cliquez sur "Nouveau produit" pour en ajouter un.</p>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Modal Nouveau produit - Version définitive optimisée -->
    <div id="modal-new-product" class="fixed inset-0 z-50 hidden" role="dialog" aria-modal="true">
        <!-- Overlay -->
        <div class="fixed inset-0 bg-gray-900/30 backdrop-blur-sm" data-modal-close="modal-new-product" onclick="closeModal('modal-new-product')"></div>

        <!-- Modal Container -->
        <div class="fixed inset-0 overflow-y-auto flex items-center justify-center p-4">
            <div class="w-full flex items-center justify-center">
                <!-- Modal Panel -->
                <div class="relative bg-white rounded-xl shadow-2xl border border-white w-full max-w-md">
                    <!-- Header -->
                    <div class="flex items-center justify-between px-6 py-4 border-b border-gray-100">
                        <h3 class="text-lg font-semibold text-gray-900">Nouveau produit</h3>
                        <button type="button" data-modal-close="modal-new-product" onclick="closeModal('modal-new-product')" class="text-gray-400 hover:text-gray-600 rounded-lg p-1 hover:bg-gray-100 transition-colors">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                            </svg>
                        </button>
                    </div>

                    <!-- Content -->
                    <form action="" method="POST" class="p-6">
                        @csrf
                        <div class="space-y-6">
                            <!-- Nom du produit -->
                            <div>
                                <label for="product_name" class="block text-sm font-medium text-gray-700 mb-2">
                                    Nom du produit <span class="text-red-500">*</span>
                                </label>
                                <input type="text" id="product_name" name="name" required placeholder="Entrez le nom du produit" class="w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg bg-gray-50 focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all outline-none">
                            </div>

                            <!-- Catégorie -->
                            <div>
                                <label for="product_category" class="block text-sm font-medium text-gray-700 mb-2">
                                    Catégorie
                                </label>
                                <select id="product_category" name="category_id" class="w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg bg-gray-50 focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all outline-none">
                                    <option value="">Choisir une catégorie</option>
                                    <option>Alimentaire</option>
                                    <option>Entretien</option>
                                    <option>Fournitures</option>
                                </select>
                            </div>

                            <!-- Unité -->
                            <div>
                                <label for="product_unit" class="block text-sm font-medium text-gray-700 mb-2">
                                    Unité
                                </label>
                                <select id="product_unit" name="unit_id" class="w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg bg-gray-50 focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all outline-none">
                                    <option value="">Pièce</option>
                                    <option>Boîte</option>
                                    <option>Lot</option>
                                    <option>Kg</option>
                                </select>
                            </div>

                            <!-- Fournisseur -->
                            <div>
                                <label for="product_supplier" class="block text-sm font-medium text-gray-700 mb-2">
                                    Fournisseur
                                </label>
                                <select id="product_supplier" name="supplier_id" class="w-full px-3 py-2.5 text-sm border border-gray-200 rounded-lg bg-gray-50 focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all outline-none">
                                    <option value="">Choisir un fournisseur</option>
                                </select>
                            </div>
                        </div>

                        <!-- Actions -->
                        <div class="flex items-center justify-end  gap-3 mt-6 pt-8 border-t border-gray-200">
                            <button type="button" data-modal-close="modal-new-product" onclick="closeModal('modal-new-product')" class="px-4 py-2.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors">
                                Annuler
                            </button>
                            <button type="submit" class="px-4 py-2.5 text-sm font-medium bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors shadow-sm">
                                Enregistrer
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
