@extends('layouts.app')

@section('title', \App\Models\Setting::get('site_name', 'KiyoKart') . ' - Home')

@section('content')
<!-- Hero Banner Section -->
@if($banners && $banners->count() > 0)
<section class="hero-banner">
    <div id="heroCarousel" class="carousel slide carousel-fade" data-bs-ride="carousel" data-bs-interval="5000" data-bs-pause="hover">
        <div class="carousel-inner">
            @foreach($banners as $index => $banner)
                <div class="carousel-item {{ $index === 0 ? 'active' : '' }}">
                    <div class="hero-banner-wrapper position-relative">
                        <img src="{{ asset('storage/' . $banner->image_path) }}" 
                             class="d-block w-100 hero-banner-image" 
                             alt="{{ $banner->title ?? 'Banner' }}"
                             loading="eager"
                             decoding="async"
                             fetchpriority="high">
                         <div class="hero-banner-content">
                            <div class="container">
                                <div class="row align-items-center">
                                    <div class="col-lg-6">
                                        <h1 class="hero-title">
                                            @if($banner->title)
                                                {{ $banner->title }}
                                            @else
                                                <span style="font-style: italic; font-weight: 400; font-size: 2rem;">Welcome to</span><br>
                                                <span>@php echo strtoupper(\App\Models\Setting::get('site_name', 'KIYOKART')); @endphp</span>
                                            @endif
                                        </h1>
                                        @php
                                            $siteDescription = \App\Models\Setting::get('site_description', 'Premium Quality Products');
                                        @endphp
                                        <p class="hero-subtitle">{{ $siteDescription }}</p>
                                        @if($banner->link)
                                            <a href="{{ $banner->link }}" class="btn btn-hero-cta">
                                                SHOP NOW
                                            </a>
                                        @else
                                            <a href="#featured-products" class="btn btn-hero-cta">
                                                SHOP NOW
                                            </a>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div> 
                    </div>
                </div>
            @endforeach
        </div>
    </div>
</section>
@endif

<!-- Shop by Categories Section -->
@if($categories->count())
<section class="shop-categories bg-secondary-light py-5" id="categories">
    <div class="container">
        <div class="section-header text-center mb-4">
            <h2 class="section-title">SHOP BY CATEGORIES</h2>
            <p class="section-subtitle">Find Your Perfect Match</p>
        </div>
        <div class="row g-3">
            @foreach($categories as $category)
                <div class="col-6 col-sm-4 col-md-3 col-lg-2">
                    <a href="{{ route('collections.show', $category->slug) }}" class="category-card">
                        <div class="category-image-wrapper">
                            @if($category->image_path)
                                <img src="{{ asset('storage/' . $category->image_path) }}" 
                                     alt="{{ $category->name }}" 
                                     class="category-image"
                                     loading="lazy"
                                     decoding="async"
                                     onerror="this.onerror=null; this.style.display='none'; this.nextElementSibling.style.display='flex';">
                                <div class="category-placeholder" style="display: none;">
                                    <i class="bi bi-tag"></i>
                                </div>
                            @else
                                <div class="category-placeholder">
                                    <i class="bi bi-tag"></i>
                                </div>
                            @endif
                        </div>
                        <h5 class="category-name">{{ strtoupper($category->name) }}</h5>
                    </a>
                </div>
            @endforeach
        </div>
    </div>
</section>
@endif

<!-- Best Sellers / New Arrivals Section -->
<section class="products-section pt-5 pb-3" id="featured-products">
    <div class="container">
        <div class="section-header text-center mb-4">
            <h2 class="section-title">YOU ARE IN <span class="pointing-emoji">👇</span></h2>
        </div>
        
        <!-- Tabs -->
        <ul class="nav nav-tabs justify-content-center mb-4 product-tabs" id="productTabs" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="bestsellers-tab" data-bs-toggle="tab" data-bs-target="#bestsellers" type="button" role="tab">
                    Best Sellers
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link active" id="newarrivals-tab" data-bs-toggle="tab" data-bs-target="#newarrivals" type="button" role="tab">
                    New Arrivals
                </button>
            </li>
        </ul>

        <!-- Tab Content -->
        <div class="tab-content" id="productTabsContent">
            <!-- Best Sellers Tab -->
            <div class="tab-pane fade" id="bestsellers" role="tabpanel" data-section="bestsellers">
                @if(isset($bestSellers) && $bestSellers->count() > 0)
                    <div class="row g-4">
                        @foreach($bestSellers->take(12) as $product)
                            <div class="col-6 col-md-4 col-lg-2">
                                @include('partials.product-card', ['product' => $product])
                            </div>
                        @endforeach
                    </div>
                    <div class="text-center mt-4">
                        <a href="{{ route('collections.show', 'best-sellers') }}" class="btn btn-outline-dark btn-shop-all">
                            View All Best Sellers
                        </a>
                    </div>
                @else
                    <div class="text-center py-5">
                        <p class="text-muted">No best sellers available at the moment.</p>
                    </div>
                @endif
            </div>

            <!-- New Arrivals Tab -->
            <div class="tab-pane fade show active" id="newarrivals" role="tabpanel" data-section="newarrivals">
                @if(isset($newArrivals) && $newArrivals->count() > 0)
                    <div class="row g-4">
                        @foreach($newArrivals->take(12) as $product)
                            <div class="col-6 col-md-4 col-lg-2">
                                @include('partials.product-card', ['product' => $product])
                            </div>
                        @endforeach
                    </div>
                    <div class="text-center mt-4">
                        <a href="{{ route('collections.show', 'new-arrivals') }}" class="btn btn-outline-dark btn-shop-all">
                            View All New Arrivals
                        </a>
                    </div>
                @else
                    <div class="text-center py-5">
                        <p class="text-muted">No new arrivals available at the moment.</p>
                    </div>
                @endif
            </div>
        </div>
    </div>
</section>

<!-- On Sale Section -->
@if(isset($onSaleProducts) && $onSaleProducts->count() > 0)
<section class="on-sale-section py-3 bg-primary-light" id="on-sale">
    <div class="container">
        <div class="section-header text-center mb-4">
            <h2 class="section-title">ON SALE <span class="hourglass-emoji">⏳</span></h2>
        </div>
        <div class="row g-4">
            @foreach($onSaleProducts->take(12) as $product)
                <div class="col-6 col-md-4 col-lg-2">
                    @include('partials.product-card', ['product' => $product, 'showDiscount' => true])
                </div>
            @endforeach
        </div>
    </div>
</section>
@endif

<!-- Category-wise Products Section -->
@if(isset($categoryWiseProducts) && count($categoryWiseProducts) > 0)
    @foreach($categoryWiseProducts as $categoryData)
        @php
            $category = $categoryData['category'];
            $products = $categoryData['products'];
            $hasMore = $categoryData['hasMore'] ?? false;
        @endphp
        <section class="category-products-section  {{ $loop->even ? 'bg-primary-light' : '' }}" id="category-{{ $category->id }}">
            <div class="container">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <div>
                        <h2 class="section-title mb-1 mt-2">{{ strtoupper($category->name) }}</h2>
                        <p class="text-muted mb-0">Discover our premium collection</p>
                    </div>
                    <a href="{{ route('collections.show', $category->slug) }}" class="btn btn-outline-dark btn-shop-all">
                        View All <i class="bi bi-arrow-right"></i>
                    </a>
                </div>
                <div class="row g-4">
                    @foreach($products as $product)
                        <div class="col-6 col-md-4 col-lg-2">
                            @include('partials.product-card', ['product' => $product])
                        </div>
                    @endforeach
                </div>
            </div>
        </section>
    @endforeach
@endif


{{-- offline store --}}
<section class="offline-store">
    <h2 class="title">OFFLINE STORE</h2>

    <div class="store-wrapper container">

        <div class="store-card">
            <h3>Vijayawada</h3>
            <p>GJ3R+4P3, Sivananda St,<br> Mogalrajapuram,
            Labbipet, Vijayawada,<br>  AP-520010</p>
            <a href="https://shorturl.at/zaU3s" target="_blank" class="location-btn">Get Location</a>
        </div>

        <div class="store-card">
            <h3>Machilipatnam</h3>
            <p>D.No. 20/159/1, Kibbarithota, <br>Chilakalapudi,
            Machilipatnam, Krishna Dist. AP-520010</p>
            <a href="https://shorturl.at/QT23G" target="_blank" class="location-btn">Get Location</a>
        </div>

        <div class="store-card">
            <h3>Rajahmundry</h3>
            <p>Beside CMR Shopping Mall, Opp BSNL OFFICE,
            Kotagummam, Rajahmundry,<br> AP-533101</p>
            <a href="https://shorturl.at/Oh5sY" target="_blank" class="location-btn">Get Location</a>
        </div>

        <div class="store-card">
            <h3>Visakhapatnam</h3>
            <p>
                D.No:207,Street No:500, Opp South India Shopping Mall,
                Kummara Veedhi-1,Jagadamba Junction
            </p>
            <a href="https://shorturl.at/7Sq8M" target="_blank" class="location-btn">Get Location</a>
        </div>
    </div>
</section>


<!-- Feature Highlights Bar -->
<section class="features-bar py-1">
    <div class="container-fluid px-0">
        <div class="features-scroll">
            <div class="features-track d-flex flex-nowrap align-items-center gap-4 px-3">
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-shield-check feature-icon"></i>
                    <span class="feature-text mb-0">Trusted by 1 Lakh+ Customers</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-lock feature-icon"></i>
                    <span class="feature-text mb-0">Safe & Secure Delivery</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-gem feature-icon"></i>
                    <span class="feature-text mb-0">Premium Quality</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-globe feature-icon"></i>
                    <span class="feature-text mb-0">International Shipping</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-arrow-repeat feature-icon"></i>
                    <span class="feature-text mb-0">Easy Returns</span>
                </div>
                <!-- duplicate for seamless scroll -->
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-shield-check feature-icon"></i>
                    <span class="feature-text mb-0">Trusted by 1 Lakh+ Customers</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-lock feature-icon"></i>
                    <span class="feature-text mb-0">Safe & Secure Delivery</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-gem feature-icon"></i>
                    <span class="feature-text mb-0">Premium Quality</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-globe feature-icon"></i>
                    <span class="feature-text mb-0">International Shipping</span>
                </div>
                <div class="feature-item d-flex align-items-center gap-2">
                    <i class="bi bi-arrow-repeat feature-icon"></i>
                    <span class="feature-text mb-0">Easy Returns</span>
                </div>
            </div>
        </div>
    </div>
</section>
@endsection

@push('styles')
<link rel="stylesheet" href="{{ asset('css/homepage.css') }}">
@endpush
