<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Collection - 
        @if($user->role === 'seller' && $user->shop_name)
            {{ $user->shop_name }}
        @else
            Boutique de {{ $user->name }}
        @endif
    </title>
    <link rel="icon" type="image/svg+xml" href="{{ asset('favicon.svg') }}">
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">

    <!-- AOS Animation -->
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">

    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600;700&family=Montserrat:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <style>
        :root {
            --primary-gold: #D4AF37;
            --primary-dark: #1a1a1a;
            --text-primary: #2c3e50;
            --text-secondary: #7f8c8d;
            --bg-light: #f8f9fa;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Montserrat', sans-serif;
            color: var(--text-primary);
            line-height: 1.6;
            overflow-x: hidden;
        }

        h1, h2, h3, h4, h5, h6 {
            font-family: 'Cormorant Garamond', serif;
        }

        /* ===== TOP BAR ===== */
        .top-bar {
            background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
            color: white;
            padding: 10px 0;
            font-size: 0.85rem;
        }

        .top-bar a {
            color: white;
            text-decoration: none;
            transition: color 0.3s;
        }

        .top-bar a:hover {
            color: var(--primary-gold);
        }

        /* ===== MAIN NAVIGATION ===== */
        .main-nav {
            background: white;
            box-shadow: 0 2px 20px rgba(0,0,0,0.1);
            padding: 20px 0;
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .brand-logo {
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--primary-dark);
            text-decoration: none;
            font-family: 'Cormorant Garamond', serif;
        }

        .brand-logo i {
            font-size: 2rem;
            color: var(--primary-gold);
        }

        .nav-links {
            list-style: none;
            display: flex;
            gap: 40px;
            margin: 0;
        }

        .nav-links a {
            color: var(--text-primary);
            text-decoration: none;
            font-weight: 500;
            font-size: 0.95rem;
            transition: color 0.3s;
            position: relative;
        }

        .nav-links a:hover {
            color: var(--primary-gold);
        }

        .nav-links a::after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 0;
            width: 0;
            height: 2px;
            background: var(--primary-gold);
            transition: width 0.3s;
        }

        .nav-links a:hover::after {
            width: 100%;
        }

        .cart-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            background: var(--primary-gold);
            color: white;
            padding: 10px 20px;
            border-radius: 50px;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s;
            position: relative;
        }

        .cart-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(212, 175, 55, 0.4);
            color: white;
        }

        .cart-badge {
            position: absolute;
            top: -5px;
            right: -5px;
            background: #e74c3c;
            color: white;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.75rem;
            font-weight: bold;
        }

        /* ===== COLLECTION HEADER ===== */
        .collection-header {
            background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
            padding: 80px 0 60px;
            color: white;
            text-align: center;
        }

        .collection-header h1 {
            font-size: 3.5rem;
            font-weight: 700;
            margin-bottom: 20px;
            background: linear-gradient(to right, white, var(--primary-gold));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .collection-header p {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 700px;
            margin: 0 auto;
        }

        /* ===== PRODUCTS SECTION ===== */
        .products-section {
            padding: 80px 0;
            background: var(--bg-light);
        }

        .filter-bar {
            background: white;
            padding: 25px;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.08);
            margin-bottom: 40px;
        }

        .filter-bar .form-select {
            border: 2px solid #e0e0e0;
            padding: 12px;
            border-radius: 10px;
            transition: all 0.3s;
        }

        .filter-bar .form-select:focus {
            border-color: var(--primary-gold);
            box-shadow: 0 0 0 0.2rem rgba(212, 175, 55, 0.25);
        }

        .product-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 30px;
        }

        .product-card {
            background: white;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            position: relative;
        }

        .product-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.15);
        }

        .product-img-wrapper {
            position: relative;
            overflow: hidden;
            height: 320px;
            background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
        }

        .product-img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.6s;
        }

        .product-card:hover .product-img {
            transform: scale(1.1);
        }

        .product-badge {
            position: absolute;
            top: 15px;
            right: 15px;
            background: rgba(212, 175, 55, 0.95);
            color: white;
            padding: 8px 15px;
            border-radius: 50px;
            font-size: 0.8rem;
            font-weight: 600;
            backdrop-filter: blur(10px);
        }

        .product-info {
            padding: 25px;
        }

        .product-category {
            color: var(--primary-gold);
            font-size: 0.8rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 10px;
        }

        .product-title {
            font-size: 1.3rem;
            font-weight: 600;
            margin-bottom: 12px;
            color: var(--primary-dark);
        }

        .product-description {
            color: var(--text-secondary);
            font-size: 0.9rem;
            margin-bottom: 20px;
            line-height: 1.6;
        }

        .product-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-top: 20px;
            border-top: 1px solid #f0f0f0;
        }

        .product-price {
            font-size: 1.6rem;
            font-weight: 700;
            color: var(--primary-gold);
        }

        .product-price small {
            font-size: 0.9rem;
            color: var(--text-secondary);
        }

        .add-to-cart {
            background: var(--primary-dark);
            color: white;
            padding: 12px 20px;
            border-radius: 50px;
            text-decoration: none;
            font-weight: 600;
            font-size: 0.9rem;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .add-to-cart:hover {
            background: var(--primary-gold);
            transform: translateX(5px);
            color: white;
        }

        /* ===== FOOTER ===== */
        .footer {
            background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
            color: white;
            padding: 60px 0 30px;
        }

        .footer h4 {
            color: var(--primary-gold);
            margin-bottom: 25px;
            font-size: 1.5rem;
        }

        .footer-links {
            list-style: none;
            padding: 0;
        }

        .footer-links li {
            margin-bottom: 12px;
        }

        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s;
        }

        .footer-links a:hover {
            color: var(--primary-gold);
            padding-left: 5px;
        }

        .footer-bottom {
            text-align: center;
            margin-top: 50px;
            padding-top: 30px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.6);
        }

        /* Empty State */
        .empty-state {
            text-align: center;
            padding: 80px 20px;
        }

        .empty-state i {
            font-size: 5rem;
            color: var(--primary-gold);
            margin-bottom: 30px;
        }

        .empty-state h3 {
            font-size: 2rem;
            margin-bottom: 15px;
        }

        .empty-state p {
            color: var(--text-secondary);
            font-size: 1.1rem;
        }
    </style>
</head>
<body>

<!-- TOP BAR -->
<div class="top-bar">
    <div class="container">
        <div class="d-flex justify-content-between align-items-center">
            <div>
                <i class="fas fa-phone me-2"></i>
                <a href="tel:{{ $user->phone }}">{{ $user->phone ?? '+225 XX XX XX XX XX' }}</a>
                <span class="mx-3">|</span>
                <i class="fas fa-envelope me-2"></i>
                <a href="mailto:{{ $user->email }}">{{ $user->email ?? 'contact@boutique.com' }}</a>
            </div>
            <div>
                <i class="fas fa-shipping-fast me-2"></i>
                Livraison Gratuite dès 50 000 XOF
            </div>
        </div>
    </div>
</div>

<!-- MAIN NAVIGATION -->
<nav class="main-nav">
    <div class="container">
        <div class="d-flex justify-content-between align-items-center">
            <a href="{{ route('user.shop', $user->username ?? $user->member_code ?? $user->id) }}" class="brand-logo">
                <i class="fas fa-gem"></i>
                <span>
                    @if($user->role === 'seller' && $user->shop_name)
                        {{ $user->shop_name }}
                    @else
                        Boutique de {{ $user->name }}
                    @endif
                </span>
            </a>

            <ul class="nav-links d-none d-lg-flex">
                <li><a href="{{ route('user.shop', $user->username ?? $user->member_code ?? $user->id) }}">Accueil</a></li>
                <li><a href="{{ route('user.shop.collection', $user->username ?? $user->member_code ?? $user->id) }}" style="color: var(--primary-gold);">Collection</a></li>
                <li><a href="{{ route('user.shop.about', $user->username ?? $user->member_code ?? $user->id) }}">À Propos</a></li>
                <li><a href="{{ route('user.shop.contact', $user->username ?? $user->member_code ?? $user->id) }}">Contact</a></li>
            </ul>

            <a href="{{ route('cart.index') }}" class="cart-btn">
                <i class="fas fa-shopping-bag"></i>
                Panier
                <span class="cart-badge">0</span>
            </a>
        </div>
    </div>
</nav>

<!-- COLLECTION HEADER -->
<section class="collection-header">
    <div class="container">
        <h1 data-aos="fade-up">Notre Collection Complète</h1>
        <p data-aos="fade-up" data-aos-delay="100">
            Explorez l'intégralité de nos créations exclusives, chaque bijou est une œuvre d'art unique
        </p>
    </div>
</section>

<!-- PRODUCTS SECTION -->
<section class="products-section">
    <div class="container">
        <!-- Filtres -->
        <div class="filter-bar" data-aos="fade-up">
            <form method="GET" action="{{ route('user.shop.collection', $user->username ?? $user->member_code ?? $user->id) }}" class="filter-form">
                <div class="row g-3">
                    <!-- Catégories -->
                    <div class="col-md-3">
                        <label class="form-label d-flex align-items-center gap-2" style="color: #333; font-weight: 600;">
                            <i class="fas fa-list" style="color: var(--primary-gold);"></i> Catégories
                        </label>
                        <select class="form-select" name="category">
                            <option value="">Toutes les catégories</option>
                            @foreach($categories as $category)
                                <option value="{{ $category->id }}" {{ $filters['category'] == $category->id ? 'selected' : '' }}>
                                    {{ $category->name }} ({{ $category->products_count ?? 0 }})
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <!-- Recherche -->
                    <div class="col-md-3">
                        <label class="form-label d-flex align-items-center gap-2" style="color: #333; font-weight: 600;">
                            <i class="fas fa-search" style="color: var(--primary-gold);"></i> Recherche
                        </label>
                        <input type="text" class="form-control" name="search" placeholder="Nom du bijou..." value="{{ $filters['search'] ?? '' }}">
                    </div>

                    <!-- Prix Min -->
                    <div class="col-md-2">
                        <label class="form-label d-flex align-items-center gap-2" style="color: #333; font-weight: 600;">
                            <i class="fas fa-coins" style="color: var(--primary-gold);"></i> Prix Min
                        </label>
                        <input type="number" class="form-control" name="min_price" placeholder="Min" value="{{ $filters['min_price'] ?? '' }}" min="0">
                    </div>

                    <!-- Prix Max -->
                    <div class="col-md-2">
                        <label class="form-label d-flex align-items-center gap-2" style="color: #333; font-weight: 600;">
                            <i class="fas fa-coins" style="color: var(--primary-gold);"></i> Prix Max
                        </label>
                        <input type="number" class="form-control" name="max_price" placeholder="Max" value="{{ $filters['max_price'] ?? '' }}" min="0">
                    </div>

                    <!-- Tri -->
                    <div class="col-md-2">
                        <label class="form-label d-flex align-items-center gap-2" style="color: #333; font-weight: 600;">
                            <i class="fas fa-sort" style="color: var(--primary-gold);"></i> Trier par
                        </label>
                        <select class="form-select" name="sort_by">
                            <option value="latest" {{ $filters['sort_by'] === 'latest' ? 'selected' : '' }}>Nouveautés</option>
                            <option value="price_asc" {{ $filters['sort_by'] === 'price_asc' ? 'selected' : '' }}>Prix (Bas → Haut)</option>
                            <option value="price_desc" {{ $filters['sort_by'] === 'price_desc' ? 'selected' : '' }}>Prix (Haut → Bas)</option>
                            <option value="popular" {{ $filters['sort_by'] === 'popular' ? 'selected' : '' }}>Populaire</option>
                        </select>
                    </div>
                </div>

                <!-- Boutons d'action -->
                <div class="row g-2 mt-2">
                    <div class="col-auto ms-auto">
                        <button type="submit" class="btn btn-primary d-flex align-items-center gap-2" style="background: linear-gradient(135deg, var(--primary-gold), #b8932f); border: none;">
                            <i class="fas fa-filter"></i> Appliquer les filtres
                        </button>
                        <a href="{{ route('user.shop.collection', $user->username ?? $user->member_code ?? $user->id) }}" class="btn btn-outline-secondary d-inline-flex align-items-center gap-2">
                            <i class="fas fa-redo"></i> Réinitialiser
                        </a>
                    </div>
                </div>

                <!-- Résumé des résultats -->
                @if($products->total() > 0)
                    <div class="mt-3 text-center" style="color: #666; font-size: 0.9rem;">
                        <i class="fas fa-info-circle me-1"></i>
                        <strong>{{ $products->total() }}</strong> résultat(s) trouvé(s)
                    </div>
                @endif
            </form>
        </div>

        <!-- Products Grid -->
        @if($products->count() > 0)
            <div class="product-grid">
                @foreach($products as $product)
                    <article class="product-card" data-aos="fade-up" data-aos-delay="{{ $loop->index * 50 }}">
                        <div class="product-img-wrapper">
                            @if($product->image)
                                <img src="{{ asset('storage/' . $product->image) }}" alt="{{ $product->name }}" class="product-img" loading="lazy">
                            @else
                                <div class="d-flex align-items-center justify-content-center h-100">
                                    <i class="fas fa-gem" style="font-size: 5rem; color: rgba(0,0,0,0.1);"></i>
                                </div>
                            @endif
                            
                            @if($product->stock > 0 && $product->stock < 10)
                                <span class="product-badge"><i class="fas fa-fire me-1"></i>Stock Limité</span>
                            @elseif($product->stock == 0)
                                <span class="product-badge" style="background: rgba(239, 68, 68, 0.95);">Épuisé</span>
                            @endif
                        </div>

                        <div class="product-info">
                            <div class="product-category">{{ $product->category->name ?? 'Bijoux' }}</div>
                            <h3 class="product-title">{{ $product->name }}</h3>
                            <p class="product-description">{{ Str::limit($product->description, 80) }}</p>

                            <div class="product-footer">
                                <div class="product-price">
                                    {{ number_format($product->price, 0, ',', ' ') }} <small>XOF</small>
                                </div>
                                
                                @if($product->stock > 0)
                                    <a href="{{ route('shop.show', $product) }}?ref={{ $user->member_code }}" class="add-to-cart">
                                        <i class="fas fa-shopping-bag"></i>
                                        Voir
                                    </a>
                                @else
                                    <button class="add-to-cart" style="opacity: 0.5; cursor: not-allowed;" disabled>
                                        Épuisé
                                    </button>
                                @endif
                            </div>
                        </div>
                    </article>
                @endforeach
            </div>

            <!-- Pagination -->
            <div class="mt-5 d-flex justify-content-center" data-aos="fade-up">
                {{ $products->links() }}
            </div>
        @else
            <div class="empty-state" data-aos="fade-up">
                <i class="fas fa-gem"></i>
                <h3>Collection Vide</h3>
                <p>Aucun produit n'est disponible pour le moment</p>
            </div>
        @endif
    </div>
</section>

<!-- FOOTER -->
<footer class="footer">
    <div class="container">
        <div class="row g-4">
            <div class="col-lg-4">
                <h4>
                    @if($user->role === 'seller' && $user->shop_name)
                        {{ $user->shop_name }}
                    @else
                        Boutique de {{ $user->name }}
                    @endif
                </h4>
                <p style="opacity: 0.8;">Des bijoux d'exception qui racontent votre histoire avec élégance et raffinement.</p>
            </div>

            <div class="col-lg-4">
                <h4>Navigation</h4>
                <ul class="footer-links">
                    <li><a href="{{ route('user.shop', $user->username ?? $user->member_code ?? $user->id) }}"><i class="fas fa-chevron-right me-2"></i>Accueil</a></li>
                    <li><a href="{{ route('user.shop.collection', $user->username ?? $user->member_code ?? $user->id) }}"><i class="fas fa-chevron-right me-2"></i>Collection</a></li>
                    <li><a href="{{ route('user.shop.about', $user->username ?? $user->member_code ?? $user->id) }}"><i class="fas fa-chevron-right me-2"></i>À Propos</a></li>
                    <li><a href="{{ route('user.shop.contact', $user->username ?? $user->member_code ?? $user->id) }}"><i class="fas fa-chevron-right me-2"></i>Contact</a></li>
                </ul>
            </div>

            <div class="col-lg-4">
                <h4>Contact</h4>
                <ul class="footer-links">
                    <li><i class="fas fa-map-marker-alt me-2"></i>{{ $user->address ?? 'Adresse' }}, {{ $user->city ?? 'Ville' }}, {{ $user->country ?? 'Pays' }}</li>
                    <li><i class="fas fa-phone me-2"></i><a href="tel:{{ $user->phone }}">{{ $user->phone ?? 'Téléphone' }}</a></li>
                    <li><i class="fas fa-envelope me-2"></i><a href="mailto:{{ $user->email }}">{{ $user->email ?? 'Email' }}</a></li>
                </ul>
            </div>
        </div>

        <div class="footer-bottom">
            <p>&copy; {{ date('Y') }} 
                @if($user->role === 'seller' && $user->shop_name)
                    {{ $user->shop_name }}
                @else
                    Boutique de {{ $user->name }}
                @endif
                - Tous droits réservés</p>
        </div>
    </div>
</footer>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

<!-- AOS Animation -->
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>

<script>
    // Initialize AOS
    AOS.init({
        duration: 800,
        easing: 'ease-out-cubic',
        once: true
    });

    // Update cart badge
    function updateCartCount() {
        fetch('/api/cart/count')
            .then(res => res.json())
            .then(data => {
                document.querySelector('.cart-badge').textContent = data.count;
            })
            .catch(() => {
                document.querySelector('.cart-badge').textContent = '0';
            });
    }

    updateCartCount();
</script>

</body>
</html>
