@php
    $useUnifiedSeo = true;
    $seo = \App\Support\Seo\SeoDataBuilder::fromArray(
        app(\App\Support\Seo\SeoFactory::class)->fromViewData(get_defined_vars())
    )
        ->addJsonLd([
            '@context' => 'https://schema.org',
            '@type' => 'CollectionPage',
            'name' => $collection['name'],
            'description' => $meta['description'] ?? $collection['description'],
            'url' => $meta['canonical'] ?? $collection['public_url'],
            'creator' => [
                '@type' => 'Person',
                'name' => data_get($collection, 'owner.username'),
            ],
            'mainEntity' => collect($collection['items'] ?? [])->map(fn ($item) => [
                '@type' => 'CreativeWork',
                'name' => data_get($item, 'card.title'),
                'url' => data_get($item, 'card.public_url'),
            ])->values()->all(),
        ])
        ->build();
@endphp
@extends('layouts.nova')

@section('meta-description', $meta['description'] ?? '')

@section('content')
    <section class="px-6 pt-8 md:px-10">
        <div class="rounded-[34px] border border-white/10 bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.14),transparent_38%),linear-gradient(180deg,rgba(15,23,42,0.96),rgba(2,6,23,0.88))] p-6 shadow-[0_24px_70px_rgba(2,6,23,0.32)] md:p-8">
            <div class="flex flex-wrap items-center gap-2">
                <span class="inline-flex items-center rounded-full border border-white/10 bg-white/[0.05] px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-200">{{ $collection['cards_count'] }} cards</span>
                @if(!empty($collection['official']))
                    <span class="inline-flex items-center rounded-full border border-amber-300/25 bg-amber-300/10 px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.18em] text-amber-100">Official</span>
                @endif
            </div>
            <h1 class="mt-4 text-3xl font-semibold tracking-[-0.04em] text-white md:text-5xl">{{ $collection['name'] }}</h1>
            <p class="mt-4 max-w-3xl text-sm leading-7 text-slate-300 md:text-base">{{ $collection['description'] ?: 'A curated Nova Cards collection.' }}</p>
            <div class="mt-5 text-sm text-slate-400">
                Curated by <a href="{{ route('cards.creator', ['username' => strtolower($collection['owner']['username'])]) }}" class="font-semibold text-sky-100 transition hover:text-white">@{{ $collection['owner']['username'] }}</a>
            </div>
        </div>
    </section>

    <section class="px-6 pt-8 md:px-10">
        @if(empty($collection['items']))
            <div class="rounded-[28px] border border-dashed border-white/12 bg-white/[0.03] px-6 py-14 text-center">
                <h2 class="text-2xl font-semibold text-white">No public cards in this collection yet</h2>
                <p class="mx-auto mt-3 max-w-xl text-sm leading-7 text-slate-300">Cards added here will appear once they are public and approved.</p>
            </div>
        @else
            <div class="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
                @foreach($collection['items'] as $item)
                    <div class="space-y-3">
                        @include('cards.partials.tile', ['card' => $item['card']])
                        @if(!empty($item['note']))
                            <div class="rounded-[20px] border border-white/10 bg-white/[0.03] px-4 py-3 text-sm leading-6 text-slate-300">{{ $item['note'] }}</div>
                        @endif
                    </div>
                @endforeach
            </div>
        @endif
    </section>
@endsection