@extends('layouts.site')

@section('title', optional($page)->meta_title ?: 'News & updates')
@section('meta_description', optional($page)->meta_description ?? 'Latest Hillcrest Living news and updates.')

@section('content')
    <section class="section-contrast-gold section-gap">
        <div class="section-shell relative overflow-hidden">
            <div class="section-orb section-orb-accent -top-16 -left-14 h-52 w-52"></div>
            <div class="section-orb section-orb-primary -bottom-20 right-4 h-56 w-56"></div>
            <div class="max-w-3xl" data-aos="fade-up">
                <p class="text-xs font-semibold uppercase tracking-[0.18em] text-[var(--color-accent)]">Hillcrest Living</p>
                <h1 class="mt-3 font-display text-4xl font-bold text-[var(--color-heading)] md:text-5xl" style="font-family: var(--font-heading);">News and Updates</h1>
                <p class="mt-4 text-lg text-[var(--color-body)]/85">Latest insights, announcements, and updates from Hillcrest Living and the UK supported living sector.</p>
            </div>

            @php
                $featuredPost = $posts->first();
                $remainingPosts = $posts->skip(1);
            @endphp

            @if($featuredPost)
                <article class="group relative mt-10 overflow-hidden rounded-[2rem] bg-[var(--color-primary)] text-white shadow-2xl shadow-neutral-900/15 ring-1 ring-white/10" data-aos="fade-up">
                    @if($featuredPost->cover)
                        <img src="{{ \Illuminate\Support\Facades\Storage::disk($featuredPost->cover->disk)->url($featuredPost->cover->path) }}" alt="{{ $featuredPost->cover->alt_text ?: $featuredPost->title }}" class="absolute inset-0 h-full w-full object-cover opacity-45 transition duration-700 group-hover:scale-105" loading="lazy">
                        <div class="absolute inset-0 bg-gradient-to-r from-[var(--color-primary)] via-[var(--color-primary)]/85 to-[var(--color-primary)]/30"></div>
                    @endif
                    <div class="relative flex min-h-[420px] flex-col justify-end p-6 md:p-10">
                        <span class="w-fit rounded-full bg-white/14 px-3 py-1 text-xs font-semibold uppercase tracking-[0.14em] text-white/80">Latest featured article</span>
                        <div class="mt-4 flex flex-wrap items-center gap-2 text-xs font-semibold uppercase tracking-wide text-[var(--color-accent)]">
                            @if($featuredPost->category)
                                <span>{{ $featuredPost->category->name }}</span>
                                <span class="text-white/40" aria-hidden="true">•</span>
                            @endif
                            <time datetime="{{ $featuredPost->published_at?->toIso8601String() }}">{{ optional($featuredPost->published_at)->format('j F Y') }}</time>
                        </div>
                        <h2 class="mt-3 max-w-3xl font-display text-3xl font-bold leading-tight md:text-5xl" style="font-family: var(--font-heading);">
                            <a href="{{ route('news.show', $featuredPost) }}">{{ $featuredPost->title }}</a>
                        </h2>
                        @if($featuredPost->excerpt)
                            <p class="mt-4 max-w-3xl text-white/85">{{ $featuredPost->excerpt }}</p>
                        @endif
                        <a href="{{ route('news.show', $featuredPost) }}" class="mt-6 inline-flex w-fit min-h-[44px] items-center justify-center rounded-full bg-[var(--color-accent)] px-5 py-2.5 text-sm font-semibold text-white transition hover:bg-white hover:text-[var(--color-primary)]">Read featured article</a>
                    </div>
                </article>
            @else
                <p class="mt-10 text-neutral-700">There are no published articles yet.</p>
            @endif

            <div class="mt-8 grid gap-6 md:grid-cols-2 xl:grid-cols-3">
                @foreach($remainingPosts as $post)
                    <article class="group overflow-hidden rounded-3xl border border-[var(--color-primary)]/15 bg-white/95 shadow-sm backdrop-blur-sm transition duration-300 hover:-translate-y-1 hover:border-[var(--color-accent)]/40 hover:shadow-xl" data-aos="fade-up">
                        @if($post->cover)
                            <div class="h-56 overflow-hidden">
                                <img src="{{ \Illuminate\Support\Facades\Storage::disk($post->cover->disk)->url($post->cover->path) }}" alt="{{ $post->cover->alt_text ?: $post->title }}" class="h-full w-full object-cover transition duration-700 group-hover:scale-105" loading="lazy">
                            </div>
                        @endif
                        <div class="p-6">
                            <div class="flex flex-wrap items-center gap-2 text-xs font-semibold uppercase tracking-wide text-[var(--color-accent)]">
                                @if($post->category)
                                    <span>{{ $post->category->name }}</span>
                                    <span aria-hidden="true">•</span>
                                @endif
                                <time datetime="{{ $post->published_at?->toIso8601String() }}">{{ optional($post->published_at)->format('j F Y') }}</time>
                            </div>
                            <h2 class="mt-3 font-display text-2xl font-semibold leading-tight text-[var(--color-heading)]" style="font-family: var(--font-heading);">
                                <a class="hover:text-[var(--color-accent)]" href="{{ route('news.show', $post) }}">{{ $post->title }}</a>
                            </h2>
                            @if($post->excerpt)
                                <p class="mt-3 text-[var(--color-body)]/85">{{ $post->excerpt }}</p>
                            @endif
                            <a href="{{ route('news.show', $post) }}" class="mt-5 inline-flex text-sm font-semibold text-[var(--color-primary)] underline-offset-4 hover:text-[var(--color-accent)] hover:underline">Read article</a>
                        </div>
                    </article>
                @endforeach
            </div>

            <div class="mt-10">
                {{ $posts->links() }}
            </div>
        </div>
    </section>
@endsection
