@extends('layouts.nova')

<?php $useUnifiedSeo = true; ?>

@push('head')
    {{-- Preload hero image for faster LCP --}}
    @if(!empty($props['hero']['featured_image']['preload_url']))
        <link
            rel="preload"
            as="image"
            href="{{ $props['hero']['featured_image']['preload_url'] }}"
            @if(!empty($props['hero']['featured_image']['preload_srcset'])) imagesrcset="{{ $props['hero']['featured_image']['preload_srcset'] }}" imagesizes="{{ $props['hero']['featured_image']['preload_sizes'] ?? '100vw' }}" @endif
            fetchpriority="high"
        >
    @elseif(!empty($props['hero']['thumb']) || !empty($props['hero']['thumb_lg']))
        <link
            rel="preload"
            as="image"
            href="{{ $props['hero']['thumb_lg'] ?? $props['hero']['thumb'] }}"
            @if(!empty($props['hero']['thumb_srcset'])) imagesrcset="{{ $props['hero']['thumb_srcset'] }}" imagesizes="100vw" @endif
            fetchpriority="high"
        >
    @elseif(!empty($props['hero']['thumb']))
        <link rel="preload" as="image" href="{{ $props['hero']['thumb'] }}" fetchpriority="high">
    @endif
@endpush

@section('main-class', '')

@section('content')
    <?php
        $isLoggedIn = ! empty($props['is_logged_in']);
        $guestArtworkSections = [
            [
                'title' => 'Rising Now',
                'href' => '/discover/rising',
                'items' => is_array($props['rising'] ?? null) ? $props['rising'] : [],
                'layout' => 'rail',
                'columns' => 'lg:grid-cols-5',
                'badge' => 'Rising',
                'badge_class' => 'bg-emerald-500/80 text-white',
            ],
            [
                'title' => 'Trending This Week',
                'href' => '/discover/trending',
                'items' => is_array($props['trending'] ?? null) ? $props['trending'] : [],
                'layout' => 'grid',
                'columns' => 'xl:grid-cols-4',
            ],
            [
                'title' => 'Community Favorites',
                'href' => '/explore?sort=top-rated',
                'items' => is_array($props['community_favorites'] ?? null) ? $props['community_favorites'] : [],
                'layout' => 'grid',
                'columns' => 'xl:grid-cols-4',
                'description' => 'Recent medal momentum from the community. This rail highlights the strongest 30-day medal signal.',
            ],
            [
                'title' => 'Hall of Fame',
                'href' => '/explore/best',
                'items' => is_array($props['hall_of_fame'] ?? null) ? $props['hall_of_fame'] : [],
                'layout' => 'grid',
                'columns' => 'xl:grid-cols-4',
                'description' => 'All-time medal standouts that keep being remembered long after publication.',
            ],
            [
                'title' => 'Fresh Uploads',
                'href' => '/discover/fresh',
                'items' => is_array($props['fresh'] ?? null) ? $props['fresh'] : [],
                'layout' => 'grid',
                'columns' => 'xl:grid-cols-4',
            ],
        ];
    ?>

    @include('web.home.hero', ['artwork' => $props['hero'] ?? null])

    <main class="pb-24">
        @include('web.home.announcement', ['announcement' => $props['announcement'] ?? null])

        @if($isLoggedIn)
            @include('web.home.sections.welcome-row', ['userData' => $props['user_data'] ?? null])
            @include('web.home.sections.artwork-section', ['title' => 'From Creators You Follow', 'href' => '/discover/following', 'items' => $props['from_following'] ?? [], 'layout' => 'grid', 'columns' => 'lg:grid-cols-5', 'emptyMessage' => "You're not following anyone yet.", 'emptyDescription' => 'Follow creators you love to see their latest uploads here.', 'emptyCtaHref' => '/creators/top', 'emptyCtaLabel' => 'Discover creators'])
            @include('web.home.sections.artwork-section', ['eyebrow' => 'Personalized feed', 'title' => 'Picked For You', 'description' => !empty($props['preferences']['top_tags'][0]) ? 'Fresh recommendations informed by your recent interest in #' . $props['preferences']['top_tags'][0] . '.' : 'A live preview of your personalized discovery feed.', 'href' => '/discover/for-you', 'items' => $props['for_you'] ?? [], 'layout' => 'grid', 'columns' => 'xl:grid-cols-4'])
            @include('web.home.sections.artwork-section', ['title' => 'Rising Now', 'href' => '/discover/rising', 'items' => $props['rising'] ?? [], 'layout' => 'rail', 'columns' => 'lg:grid-cols-5', 'badge' => 'Rising', 'badge_class' => 'bg-emerald-500/80 text-white'])
            @include('web.home.sections.artwork-section', ['title' => 'Trending This Week', 'href' => '/discover/trending', 'items' => $props['trending'] ?? [], 'layout' => 'grid', 'columns' => 'xl:grid-cols-4'])
            @include('web.home.sections.artwork-section', ['title' => 'Community Favorites', 'href' => '/explore?sort=top-rated', 'items' => $props['community_favorites'] ?? [], 'layout' => 'grid', 'columns' => 'xl:grid-cols-4', 'description' => 'Recent medal momentum from the community. This rail highlights the strongest 30-day medal signal.'])
            @include('web.home.sections.artwork-section', ['title' => 'Hall of Fame', 'href' => '/explore/best', 'items' => $props['hall_of_fame'] ?? [], 'layout' => 'grid', 'columns' => 'xl:grid-cols-4', 'description' => 'All-time medal standouts that keep being remembered long after publication.'])
            @if(!empty($props['preferences']['top_tags'][0]))
                @include('web.home.sections.artwork-section', ['title' => 'Because You Like #' . $props['preferences']['top_tags'][0], 'href' => '/browse?tags=' . rawurlencode((string) $props['preferences']['top_tags'][0]), 'items' => $props['by_categories'] ?? [], 'layout' => 'grid', 'columns' => 'lg:grid-cols-5'])
            @endif
            @include('web.home.sections.artwork-section', ['title' => 'Fresh Uploads', 'href' => '/discover/fresh', 'items' => $props['fresh'] ?? [], 'layout' => 'grid', 'columns' => 'xl:grid-cols-4'])
            @include('web.home.sections.collections', ['collections' => $props['collections_trending'] ?: ($props['collections_featured'] ?: ($props['collections_recent'] ?? []))])
            @include('web.home.sections.world-spotlight', ['world' => $props['world_spotlight'] ?? null])
            @include('web.home.sections.groups', ['groups' => $props['groups'] ?? []])
            @include('web.home.sections.categories')
            @include('web.home.sections.suggested-creators', ['creators' => $props['suggested_creators'] ?? []])
            @include('web.home.sections.tags', ['tags' => $props['tags'] ?? []])
            @include('web.home.sections.creators', ['creators' => $props['creators'] ?? []])
            @include('web.home.sections.news', ['items' => $props['news'] ?? []])
            @include('web.home.sections.cta', ['isLoggedIn' => true])
        @else
            @foreach ($guestArtworkSections as $section)
                @include('web.home.sections.artwork-section', $section)
            @endforeach
            @include('web.home.sections.collections', ['collections' => $props['collections_trending'] ?: ($props['collections_featured'] ?: ($props['collections_editorial'] ?? []))])
            @include('web.home.sections.world-spotlight', ['world' => $props['world_spotlight'] ?? null])
            @include('web.home.sections.groups', ['groups' => $props['groups'] ?? []])
            @include('web.home.sections.categories')
            @include('web.home.sections.tags', ['tags' => $props['tags'] ?? []])
            @include('web.home.sections.creators', ['creators' => $props['creators'] ?? []])
            @include('web.home.sections.news', ['items' => $props['news'] ?? []])
            @include('web.home.sections.cta', ['isLoggedIn' => false])
        @endif
    </main>

    @vite(['resources/js/public/home.js'])
@endsection

