<p class="text-lg font-bold leading-normal text-neutral-800 dark:text-white">
    {{ __('home.categories') }}
</p>

@php
    $categories = collect([
        ['name' => 'Uncensored', 'slug' => 'uncensored'],
        ['name' => 'Milf', 'slug' => 'milf'],
        ['name' => 'Maid', 'slug' => 'maid'],
        ['name' => 'School Girl', 'slug' => 'school-girl'],
        ['name' => 'Succubus', 'slug' => 'succubus'],
        ['name' => 'Tentacle', 'slug' => 'tentacle'],
        ['name' => 'Big Boobs', 'slug' => 'big-boobs'],
        ['name' => 'BDSM', 'slug' => 'bdsm'],
        ['name' => 'Elf', 'slug' => 'elf'],
        ['name' => '4K 48FPS', 'slug' => '4k-48fps'],
    ]);
@endphp

<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-5">
    @foreach ($categories as $category)
        @php
            $episodes = cache()->remember(
                "category_{$category['slug']}",
                now()->addMinutes(15),
                fn () => \App\Models\Episode::query()
                    ->withAllTags([$category['slug']])
                    ->inRandomOrder()
                    ->limit(3)
                    ->get()
            );

            [$left, $center, $right] = [
                $episodes->get(0),
                $episodes->get(1),
                $episodes->get(2),
            ];
        @endphp

        <a
            href="{{ route('hentai.search', [
                'order' => 'recently-uploaded',
                'tags[0]' => $category['slug'],
            ]) }}"
            class="group relative overflow-hidden rounded-2xl border dark:border-neutral-800 border-neutral-300 dark:bg-neutral-900 dark:hover:border-neutral-700 hover:border-neutral-400 hover:shadow-2xl hover:shadow-black/30 shadow-md transition-all duration-300 hover:-translate-y-1"
        >
            <div class="p-4">
                <h2 class="text-center text-lg font-semibold text-neutral-900 dark:text-white">
                    {{ $category['name'] }}
                </h2>

                <div class="relative mt-4 flex h-52 items-center justify-center">
                    @if ($left)
                        <img
                            src="{{ $left->cover_url }}"
                            alt="{{ $category['name'] }}"
                            loading="lazy"
                            class="absolute left-2 top-4 h-44 w-32 rotate-[-12deg] rounded-xl object-cover shadow-lg transition-transform duration-300 group-hover:rotate-[-16deg]"
                        >
                    @endif

                    @if ($center)
                        <img
                            src="{{ $center->cover_url }}"
                            alt="{{ $category['name'] }}"
                            loading="lazy"
                            class="absolute top-2 z-10 h-44 w-32 rounded-xl object-cover shadow-2xl transition-transform duration-300 group-hover:scale-105"
                        >
                    @endif

                    @if ($right)
                        <img
                            src="{{ $right->cover_url }}"
                            alt="{{ $category['name'] }}"
                            loading="lazy"
                            class="absolute right-2 top-8 z-20 h-44 w-32 rotate-[12deg] rounded-xl object-cover shadow-lg transition-transform duration-300 group-hover:rotate-[16deg]"
                        >
                    @endif
                </div>
            </div>
        </a>
    @endforeach
</div>