@extends('layouts.app')

@section('title', 'Wallpapers - Premium Custom Designs')

@section('styles')
<style>
.hero-slider {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    margin: 20px;
    height: 600px;
}

.hero-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.8s ease-in-out;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.hero-slide.active {
    opacity: 1;
}

.hero-slide-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: center;
    padding: 6rem 5rem;
    height: 100%;
}

.hero-dots {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 10;
}

.hero-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
}

.hero-dot.active {
    background: white;
    width: 32px;
    border-radius: 6px;
}

.hero-content {
    color: white;
}

.hero-cta {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.hero-slider:hover .hero-dot {
    background: rgba(255, 255, 255, 0.7);
}

.hero-slider:hover .hero-dot.active {
    background: white;
}
</style>
@endsection

@section('content')
    <!-- HERO SECTION -->
    <section class="section" id="hero">
        <div class="hero-slider">
            @forelse($heroImages as $index => $image)
            <div class="hero-slide @if($index === 0) active @endif" style="background-image: url('{{ asset('storage/' . $image->image_path) }}');">
                <div class="hero-slide-content">
                    <div>
                        <div class="hero-content">
                            <h1 style="color: white; font-size: 3rem;">{{ $image->title }}</h1>
                            @if($image->description)
                            <p style="color: rgba(255, 255, 255, 0.9); font-size: 1.1rem; max-width: 95%;">{{ $image->description }}</p>
                            @endif
                            <div class="hero-cta">
                                @if($image->button_text && $image->button_link)
                                    @if(str_starts_with($image->button_link, '#'))
                                    <button class="btn" onclick="document.getElementById('{{ substr($image->button_link, 1) }}').scrollIntoView({behavior: 'smooth'})">{{ $image->button_text }}</button>
                                    @else
                                    <a href="{{ $image->button_link }}" class="btn">{{ $image->button_text }}</a>
                                    @endif
                                @else
                                <button class="btn" onclick="document.getElementById('wallpaper-grid').scrollIntoView({behavior: 'smooth'})">Browse Wallpapers</button>
                                @endif
                            </div>
                        </div>
                    </div>
                    <div></div>
                </div>
            </div>
            @empty
            <!-- Fallback hero image if none are configured in admin -->
            <div class="hero-slide active" style="background: linear-gradient(to right, rgba(45, 80, 71, 0.7), rgba(45, 80, 71, 0.5)), url('https://images.unsplash.com/photo-1552321554-5fefe8c9ef14?w=1200&q=80') center/cover no-repeat;">
                <div class="hero-slide-content">
                    <div>
                        <div class="hero-content">
                            <h1 style="color: white; font-size: 3rem;">Premium Custom Wallpapers</h1>
                            <p style="color: rgba(255, 255, 255, 0.95); font-size: 1.1rem;">Transform your spaces with our carefully curated collection of high-quality wallpapers. From botanical motifs to contemporary geometric patterns, each design is crafted with precision and printed to perfection.</p>
                            <div class="hero-cta">
                                <button class="btn" onclick="document.getElementById('wallpaper-grid').scrollIntoView({behavior: 'smooth'})">Browse Wallpapers</button>
                            </div>
                        </div>
                    </div>
                    <div></div>
                </div>
            </div>
            @endforelse

            <div class="hero-dots">
                @forelse($heroImages as $index => $image)
                <div class="hero-dot @if($index === 0) active @endif" data-slide="{{ $index }}"></div>
                @empty
                <div class="hero-dot active" data-slide="0"></div>
                @endforelse
            </div>
        </div>
    </section>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const slides = document.querySelectorAll('.hero-slide');
            const dots = document.querySelectorAll('.hero-dot');
            const slider = document.querySelector('.hero-slider');
            let currentSlide = 0;
            let autoAdvanceInterval;

            function showSlide(n) {
                if (slides.length === 0) return;
                slides.forEach(s => s.classList.remove('active'));
                dots.forEach(d => d.classList.remove('active'));
                currentSlide = (n + slides.length) % slides.length;
                slides[currentSlide].classList.add('active');
                dots[currentSlide].classList.add('active');
            }

            function startAutoAdvance() {
                autoAdvanceInterval = setInterval(() => {
                    showSlide(currentSlide + 1);
                }, 5000);
            }

            function resetAutoAdvance() {
                clearInterval(autoAdvanceInterval);
                startAutoAdvance();
            }

            dots.forEach(dot => {
                dot.addEventListener('click', () => {
                    showSlide(parseInt(dot.getAttribute('data-slide')));
                    resetAutoAdvance();
                });
            });

            slider.addEventListener('mouseenter', () => clearInterval(autoAdvanceInterval));
            slider.addEventListener('mouseleave', startAutoAdvance);

            startAutoAdvance();
        });
    </script>


    <!-- WALLPAPER GRID -->
    <section class="section" id="wallpaper-grid" style="padding: 2rem 0;">
        <div class="container">
            <div style="display: flex; gap: 2rem; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 2rem;">
                <div>
                    <h3>All Wallpapers</h3>
                    <p style="color: var(--text-secondary);">Showing all designs</p>
                </div>
                <div style="display: flex; gap: 1rem;">
                    <select style="padding: 8px 12px; border: 1px solid var(--border-color); border-radius: 4px; font-size: 0.9rem;">
                        <option>Sort by: Featured</option>
                        <option>Newest</option>
                        <option>Price: Low to High</option>
                        <option>Price: High to Low</option>
                    </select>
                </div>
            </div>

            <div style="display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 2rem;">
                <button class="filter-btn active" data-filter="all">All</button>
                <button class="filter-btn" data-filter="botanical">Botanical</button>
                <button class="filter-btn" data-filter="vintage">Vintage</button>
                <button class="filter-btn" data-filter="modern">Modern</button>
                <button class="filter-btn" data-filter="geometric">Geometric</button>
                <button class="filter-btn" data-filter="texture">Texture</button>
                <button class="filter-btn" data-filter="floral">Floral</button>
            </div>
        </div>
        <div class="container">
            <div class="grid grid--3">
                @forelse($products as $product)
                    @include('components.product-card', ['product' => $product])
                @empty
                    <p>No products available</p>
                @endforelse
            </div>
        </div>
    </section>

    <!-- CTA SECTION -->
    <section class="section section--highlight">
        <div class="container" style="text-align: center;">
            <h2>Need Help Choosing?</h2>
            <p style="max-width: 600px; margin: 0 auto var(--spacing-lg); color: var(--text-primary);">
                Schedule a free consultation with our design experts. We'll help you find the perfect wallpaper for your space.
            </p>
            <button class="btn btn--secondary">Book a Free Consultation</button>
        </div>
    </section>
@endsection

@section('scripts')
    <script>
        document.querySelectorAll('.filter-btn').forEach(btn => {
            btn.addEventListener('click', function() {
                const filter = this.dataset.filter;
                document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
                this.classList.add('active');

                document.querySelectorAll('[data-category]').forEach(card => {
                    if (filter === 'all' || card.dataset.category === filter) {
                        card.style.display = '';
                    } else {
                        card.style.display = 'none';
                    }
                });
            });
        });
    </script>
@endsection
