<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    <title>All Reels - ShopSphere</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet" />
    <link
        href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400&family=Jost:wght@300;400;500;600&display=swap"
        rel="stylesheet" />

    <style>
        :root {
            --ivory: #faf9f7;
            --cream: #f4f1ec;
            --warm-white: #fffef9;
            --gold: #152D6C;
            --gold-light: #1e3a8a;
            --gold-pale: #e0e7ff;
            --charcoal: #1c1c1c;
            --ink: #2d2d2d;
            --slate: #5a5a5a;
            --mist: #9a9a9a;
            --border: #e5dfd5;
            --border-soft: #eeece8;
            --radius-sm: 6px;
            --radius-md: 12px;
            --radius-lg: 20px;
            --shadow-sm: 0 2px 12px rgba(28, 28, 28, .06);
            --shadow-md: 0 8px 32px rgba(28, 28, 28, .10);
            --shadow-lg: 0 20px 60px rgba(28, 28, 28, .13);
            --font-display: 'Cormorant Garamond', Georgia, serif;
            --font-ui: 'Jost', sans-serif;
        }

        *,
        *::before,
        *::after {
            box-sizing: border-box;
        }

        html {
            scroll-behavior: smooth;
        }

        body {
            font-family: var(--font-ui);
            background: var(--ivory);
            color: var(--ink);
            font-weight: 400;
            letter-spacing: .01em;
            -webkit-font-smoothing: antialiased;
        }

        .navbar-elegant {
            background: rgba(250, 249, 247, .96) !important;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-bottom: 1px solid var(--border);
            padding: 0;
            position: sticky;
            top: 0;
            z-index: 1050;
        }

        .navbar-inner {
            display: grid;
            grid-template-columns: 1fr auto 1fr;
            align-items: center;
            padding: 18px 40px;
            gap: 24px;
        }

        @media (max-width: 991px) {
            .navbar-inner {
                grid-template-columns: 1fr auto;
                padding: 16px 20px;
            }

            .nav-left {
                display: none !important;
            }
        }

        .brand-lockup {
            text-align: center;
            text-decoration: none;
        }

        .brand-wordmark {
            font-family: var(--font-display);
            font-size: 1.75rem;
            font-weight: 600;
            color: var(--charcoal);
            letter-spacing: .12em;
            text-transform: uppercase;
            line-height: 1;
            display: block;
        }

        .brand-tagline {
            font-size: .62rem;
            letter-spacing: .22em;
            text-transform: uppercase;
            color: var(--gold);
            margin-top: 2px;
            display: block;
        }

        .nav-left,
        .nav-right {
            display: flex;
            align-items: center;
            gap: 28px;
        }

        .nav-right {
            justify-content: flex-end;
        }

        .nav-link-elegant {
            font-size: .78rem;
            font-weight: 500;
            letter-spacing: .1em;
            text-transform: uppercase;
            color: var(--slate) !important;
            text-decoration: none;
            position: relative;
            padding-bottom: 2px;
            transition: color .2s;
        }

        .nav-link-elegant::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: -2px;
            width: 0;
            height: 1px;
            background: var(--gold);
            transition: width .25s ease;
        }

        .nav-link-elegant:hover {
            color: var(--charcoal) !important;
        }

        .nav-link-elegant:hover::after,
        .nav-link-elegant.active::after {
            width: 100%;
        }

        .nav-link-elegant.active {
            color: var(--charcoal) !important;
        }

        .nav-icon-btn {
            background: none;
            border: none;
            cursor: pointer;
            color: var(--slate);
            font-size: 1.15rem;
            padding: 4px;
            transition: color .2s;
            position: relative;
            display: inline-flex;
            align-items: center;
        }

        .nav-icon-btn:hover {
            color: var(--charcoal);
        }

        .cart-badge {
            position: absolute;
            top: -4px;
            right: -6px;
            background: var(--gold);
            color: #fff;
            font-size: .58rem;
            font-weight: 700;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            letter-spacing: 0;
        }

        .btn-auth {
            font-family: var(--font-ui);
            font-size: .74rem;
            font-weight: 600;
            letter-spacing: .1em;
            text-transform: uppercase;
            background: transparent;
            color: var(--slate);
            border: none;
            border-radius: var(--radius-sm);
            padding: 4px;
            text-decoration: none;
            transition: background .2s, transform .15s, color .2s;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
        }

        .btn-auth:hover {
            background: transparent;
            color: var(--charcoal);
        }

        .toggler-elegant {
            background: none;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 6px 10px;
            color: var(--charcoal);
            cursor: pointer;
        }

        .section-pad {
            padding: 60px 0;
        }

        .section-label {
            font-size: .68rem;
            font-weight: 600;
            letter-spacing: .26em;
            text-transform: uppercase;
            color: var(--gold);
            margin-bottom: 8px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .section-label::before,
        .section-label::after {
            content: '';
            display: block;
            flex: 1;
            max-width: 32px;
            height: 1px;
            background: var(--gold-pale);
        }

        .section-label::before {
            display: none;
        }

        .section-heading {
            font-family: var(--font-display);
            font-size: clamp(1.8rem, 3vw, 2.8rem);
            font-weight: 600;
            color: var(--charcoal);
            line-height: 1.15;
            letter-spacing: .01em;
        }

        .section-heading em {
            font-style: italic;
            color: var(--gold);
        }

        .reel-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
            gap: 24px;
        }

        @media (max-width: 575px) {
            .reel-grid {
                grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
                gap: 16px;
            }
        }

        .reel-card {
            border-radius: var(--radius-md);
            overflow: hidden;
            background: var(--warm-white);
            border: 1px solid var(--border);
            transition: transform .3s ease, box-shadow .3s ease;
            cursor: pointer;
        }

        .reel-card:hover {
            transform: translateY(-6px);
            box-shadow: var(--shadow-lg);
        }

        .reel-thumb {
            position: relative;
            height: 320px;
            overflow: hidden;
        }

        @media (max-width: 575px) {
            .reel-thumb {
                height: 240px;
            }
        }

        .reel-thumb img,
        .reel-thumb video,
        .reel-thumb iframe {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform .4s ease;
        }

        .reel-thumb iframe {
            border: 0;
            pointer-events: none;
        }

        .reel-card:hover .reel-thumb img,
        .reel-card:hover .reel-thumb video,
        .reel-card:hover .reel-thumb iframe {
            transform: scale(1.06);
        }

        .reel-veil {
            position: absolute;
            inset: 0;
            background: linear-gradient(to top, rgba(28, 28, 28, .6) 0%, transparent 60%);
        }

        .reel-play-btn {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -55%);
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: rgba(250, 249, 247, .15);
            backdrop-filter: blur(6px);
            border: 1.5px solid rgba(255, 255, 255, .5);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 1.1rem;
            transition: background .2s, border-color .2s;
        }

        .reel-card:hover .reel-play-btn {
            background: var(--gold);
            border-color: var(--gold);
        }

        .reel-meta {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 14px 14px 10px;
        }

        .reel-shop-name {
            font-size: .75rem;
            font-weight: 600;
            color: #fff;
            letter-spacing: .04em;
            display: block;
        }

        .reel-views {
            font-size: .68rem;
            color: rgba(255, 255, 255, .7);
            margin-top: 2px;
        }

        .reel-caption {
            padding: 12px 14px;
            font-size: .8rem;
            font-weight: 500;
            color: var(--ink);
            border-top: 1px solid var(--border-soft);
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: var(--slate);
        }

        .empty-state i {
            font-size: 4rem;
            color: var(--mist);
            margin-bottom: 16px;
        }

        footer {
            background: #151515;
            color: #a0a0a0;
            padding-top: 72px;
            padding-bottom: 0;
        }

        .footer-brand-name {
            font-family: var(--font-display);
            font-size: 2rem;
            font-weight: 600;
            color: #fff;
            letter-spacing: .12em;
            text-transform: uppercase;
            display: block;
            margin-bottom: 4px;
        }

        .footer-brand-tag {
            font-size: .62rem;
            letter-spacing: .22em;
            text-transform: uppercase;
            color: var(--gold);
        }

        .footer-about {
            font-size: .82rem;
            line-height: 1.85;
            color: #7a7a7a;
            margin: 18px 0 24px;
            max-width: 300px;
        }

        .footer-social a {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            border: 1px solid rgba(255, 255, 255, .12);
            color: #888;
            font-size: .95rem;
            text-decoration: none;
            transition: all .2s;
            margin-right: 8px;
        }

        .footer-social a:hover {
            border-color: var(--gold);
            color: var(--gold);
        }

        .footer-col-title {
            font-size: .68rem;
            font-weight: 700;
            letter-spacing: .2em;
            text-transform: uppercase;
            color: rgba(255, 255, 255, .6);
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .footer-col-title::after {
            content: '';
            flex: 1;
            height: 1px;
            background: rgba(255, 255, 255, .06);
        }

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

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

        .footer-links a {
            font-size: .82rem;
            color: #7a7a7a;
            text-decoration: none;
            transition: color .2s, padding-left .2s;
            display: inline-block;
        }

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

        .newsletter-wrap {
            display: flex;
            gap: 0;
            margin-top: 16px;
        }

        .newsletter-wrap input {
            flex: 1;
            background: rgba(255, 255, 255, .06);
            border: 1px solid rgba(255, 255, 255, .12);
            border-right: none;
            border-radius: var(--radius-sm) 0 0 var(--radius-sm);
            padding: 11px 16px;
            color: #fff;
            font-family: var(--font-ui);
            font-size: .8rem;
            outline: none;
            transition: border-color .2s;
        }

        .newsletter-wrap input::placeholder {
            color: #555;
        }

        .newsletter-wrap input:focus {
            border-color: var(--gold);
        }

        .newsletter-wrap button {
            background: var(--gold);
            border: none;
            border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
            padding: 11px 20px;
            color: #fff;
            font-family: var(--font-ui);
            font-size: .72rem;
            font-weight: 700;
            letter-spacing: .1em;
            text-transform: uppercase;
            cursor: pointer;
            transition: background .2s;
        }

        .newsletter-wrap button:hover {
            background: var(--gold-light);
        }

        .footer-bottom {
            margin-top: 56px;
            padding: 20px 0;
            border-top: 1px solid rgba(255, 255, 255, .06);
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-wrap: wrap;
            gap: 12px;
        }

        .footer-bottom p {
            margin: 0;
            font-size: .74rem;
            color: #444;
        }

        .footer-payment {
            display: flex;
            align-items: center;
            gap: 14px;
        }

        .pay-chip {
            background: rgba(255, 255, 255, .06);
            border: 1px solid rgba(255, 255, 255, .09);
            border-radius: 4px;
            padding: 4px 10px;
            font-size: .68rem;
            color: #666;
            letter-spacing: .06em;
        }

        @media (max-width: 991px) {
            .container {
                padding-left: 20px;
                padding-right: 20px;
            }
        }

        @media (max-width: 575px) {
            .container {
                padding-left: 16px;
                padding-right: 16px;
            }
        }
    </style>
</head>

<body>
    <header>
        <nav class="navbar-elegant">
            <div class="navbar-inner container-fluid">
                <nav class="nav-left" aria-label="Primary navigation left">
                    <a href="{{ route('storefront.home') }}" class="nav-link-elegant">Home</a>
                    <a href="{{ route('storefront.about') }}" class="nav-link-elegant">About</a>
                    <a href="{{ route('storefront.contact') }}" class="nav-link-elegant">Contact</a>
                </nav>

                <a class="brand-lockup" href="{{ route('storefront.home') }}" aria-label="ShopSphere home">
                    <span class="brand-wordmark">SHOP</span>
                    {{-- <img src="{{ asset('assets/img/bali_logo.png') }}" alt=""> --}}
                    <span class="brand-tagline">Curated Commerce</span>
                </a>

                <div class="nav-right">
                    @auth
                        <a style="font-size:20px" href="{{ route('dashboard') }}" class="btn-auth" aria-label="Account">
                            <i class="bi bi-person-circle"></i>
                        </a>
                    @else
                        <a style="font-size:24px" href="{{ route('login') }}" class="btn-auth" aria-label="Sign In">
                            <i class="bi bi-person"></i>
                        </a>
                    @endauth

                    <button class="toggler-elegant d-lg-none" type="button" data-bs-toggle="collapse"
                        data-bs-target="#mobileNav" aria-expanded="false" aria-label="Menu">
                        <i class="bi bi-list fs-5"></i>
                    </button>
                </div>
            </div>

            <div class="collapse" id="mobileNav">
                <div class="mobile-nav-panel">
                    <a href="{{ route('storefront.home') }}" class="nav-link-elegant">Home</a>
                    <a href="{{ route('storefront.about') }}" class="nav-link-elegant">About</a>
                    <a href="{{ route('storefront.contact') }}" class="nav-link-elegant">Contact</a>
                </div>
            </div>
        </nav>
    </header>

    <main class="section-pad">
        <div class="container">
            <div class="mb-4">
                <p class="section-label mb-2">Watch & Shop</p>
                <h1 class="section-heading">All <em>Reels</em></h1>
            </div>

            @if($reels->count() > 0)
                <div class="reel-grid">
                    @foreach($reels as $reel)
                        @php
                            $shopName = optional($reel->shop)->name ?: 'Marketplace';
                            $caption = $reel->title ?: ($reel->caption ?: 'Live shopping reel');
                            $videoUrl = $reel->video_url
                                ? (\Illuminate\Support\Str::startsWith($reel->video_url, ['http://', 'https://'])
                                    ? $reel->video_url
                                    : asset('storage/' . $reel->video_url))
                                : null;
                            $thumbUrl = $reel->thumbnail_url
                                ? (\Illuminate\Support\Str::startsWith($reel->thumbnail_url, ['http://', 'https://'])
                                    ? $reel->thumbnail_url
                                    : asset('storage/' . ltrim($reel->thumbnail_url, '/')))
                                : null;
                            if (
                                !$thumbUrl &&
                                $videoUrl &&
                                preg_match(
                                    '/(?:youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]{11})/',
                                    $videoUrl,
                                    $yt,
                                )
                            ) {
                                $thumbUrl = 'https://img.youtube.com/vi/' . $yt[1] . '/hqdefault.jpg';
                            }
                            if (
                                !$thumbUrl &&
                                $videoUrl &&
                                preg_match('/youtube\.com\/shorts\/([A-Za-z0-9_-]{11})/', $videoUrl, $ytShort)
                            ) {
                                $thumbUrl = 'https://img.youtube.com/vi/' . $ytShort[1] . '/hqdefault.jpg';
                            }
                            $fallbackThumb =
                                'https://images.unsplash.com/photo-1521572267360-ee0c2909d518?w=600&q=80';
                        @endphp
                        <article class="reel-card" role="button" tabindex="0" data-reel-id="{{ $reel->id }}"
                            data-video-url="{{ $videoUrl }}" aria-label="Open reel: {{ $caption }}">
                            <div class="reel-thumb">
                                <img src="{{ $thumbUrl ?: $fallbackThumb }}" alt="{{ $caption }}"
                                    loading="lazy" />
                                <div class="reel-veil"></div>
                                <div class="reel-play-btn"><i class="bi bi-play-fill"></i></div>
                                <div class="reel-meta">
                                    <span class="reel-shop-name">{{ $shopName }}</span>
                                </div>
                            </div>
                            <div class="reel-caption">{{ $caption }}</div>
                        </article>
                    @endforeach
                </div>
            @else
                <div class="empty-state">
                    <i class="bi bi-play-circle"></i>
                    <h3>No Reels Available</h3>
                    <p>Check back soon for new reels from our shops.</p>
                    <a href="{{ route('storefront.home') }}" class="btn btn-primary mt-3">Back to Home</a>
                </div>
            @endif
        </div>
    </main>

    <footer>
        <div class="container">
            <div class="row g-5">
                <div class="col-lg-4 col-md-6">
                    <span class="footer-brand-name">ShopSphere</span>
                    <span class="footer-brand-tag">Curated Commerce</span>
                    <p class="footer-about">A refined marketplace offering quality goods across fashion, technology,
                        groceries, and beauty. Precision-curated. Elegantly delivered.</p>
                    <div class="footer-social">
                        <a href="#" aria-label="Facebook"><i class="bi bi-facebook"></i></a>
                        <a href="#" aria-label="Instagram"><i class="bi bi-instagram"></i></a>
                        <a href="#" aria-label="Twitter/X"><i class="bi bi-twitter-x"></i></a>
                        <a href="#" aria-label="YouTube"><i class="bi bi-youtube"></i></a>
                        <a href="#" aria-label="Pinterest"><i class="bi bi-pinterest"></i></a>
                    </div>
                </div>

                <div class="col-6 col-md-2">
                    <div class="footer-col-title">Explore</div>
                    <ul class="footer-links">
                        <li><a href="{{ route('storefront.home') }}">Home</a></li>
                        <li><a href="{{ route('storefront.reels') }}">Reels</a></li>
                        <li><a href="{{ route('storefront.home') }}#shops">Shop All</a></li>
                        <li><a href="#">New Arrivals</a></li>
                        <li><a href="#">Sale</a></li>
                    </ul>
                </div>

                <div class="col-6 col-md-2">
                    <div class="footer-col-title">Support</div>
                    <ul class="footer-links">
                        <li><a href="#">Help Centre</a></li>
                        <li><a href="#">Track Order</a></li>
                        <li><a href="#">Returns</a></li>
                        <li><a href="#">Shipping Info</a></li>
                        <li><a href="#">Contact Us</a></li>
                    </ul>
                </div>

                <div class="col-lg-4 col-md-6">
                    <div class="footer-col-title">Stay Informed</div>
                    <p style="font-size:.82rem;color:#666;line-height:1.75;margin-bottom:4px;">
                        Subscribe to receive exclusive offers, new arrivals, and curated picks — delivered directly to
                        your inbox.
                    </p>
                    <div class="newsletter-wrap">
                        <input type="email" placeholder="your@email.com" aria-label="Email for newsletter" />
                        <button type="submit">Subscribe</button>
                    </div>
                    <p style="font-size:.7rem;color:#444;margin-top:10px;">No spam. Unsubscribe anytime.</p>
                </div>
            </div>

            <div class="footer-bottom">
                <p>&copy; {{ date('Y') }} ShopSphere. All rights reserved. Crafted with care.</p>
                <div class="footer-payment">
                    <span class="pay-chip">Visa</span>
                    <span class="pay-chip">Mastercard</span>
                    <span class="pay-chip">PayPal</span>
                    <span class="pay-chip">Stripe</span>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '';
        const reelViewUrlTemplate = @json(route('storefront.reels.view', ['reel' => '__REEL_ID__']));

        document.querySelectorAll('.reel-card').forEach((card) => {
            const openReel = () => {
                const reelId = card.dataset.reelId || '';
                const videoUrl = card.dataset.videoUrl || '';

                if (reelId) {
                    const reelViewUrl = reelViewUrlTemplate.replace('__REEL_ID__', reelId);
                    fetch(reelViewUrl, {
                            method: 'POST',
                            headers: {
                                'X-CSRF-TOKEN': csrfToken,
                                'Accept': 'application/json',
                            },
                        })
                        .then((res) => res.ok ? res.json() : null)
                        .then(() => {})
                        .catch(() => {});
                }

                if (videoUrl) {
                    window.open(videoUrl, '_blank');
                    return;
                }
            };

            card.addEventListener('click', openReel);
            card.addEventListener('keydown', (e) => {
                if (e.key === 'Enter' || e.key === ' ') {
                    e.preventDefault();
                    openReel();
                }
            });
        });
    </script>
</body>

</html>
