<?php

use App\Enums\PostStatus;
use App\Models\Post;
use Livewire\Attributes\Layout;
use Livewire\Volt\Component;

new #[Layout('components.layouts.public')] class extends Component
{
    public Post $post;

    public function mount(Post $post): void
    {
        // Only show published posts
        abort_unless($post->status === PostStatus::Published, 404);

        $this->post = $post;
    }
}; ?>

<article class="max-w-3xl mx-auto">
    <header class="mb-8">
        <flux:heading size="xl" class="text-body">{{ $post->getTitle() }}</flux:heading>

        <time class="text-body/70 mt-2 block">
            {{ $post->published_at?->translatedFormat('l, d F Y') ?? $post->created_at->translatedFormat('l, d F Y') }}
        </time>
    </header>

    <div class="prose prose-lg prose-brand max-w-none">
        {!! $post->getBody() !!}
    </div>

    <footer class="mt-12 pt-6 border-t border-cta/20">
        <a href="{{ route('posts.index') }}" class="text-cta hover:text-cta-hover hover:underline" wire:navigate>
            &larr; {{ __('posts.back_to_posts') }}
        </a>
    </footer>
</article>
