<?php

namespace App\Livewire\Home;

use App\Models\Announcement as AnnouncementModel;
use Livewire\Attributes\Title;
use Livewire\Component;
use Livewire\WithPagination;

#[Title('Pengumuman')]
class Announcement extends Component
{
    use WithPagination;

    public function render()
    {
        $announcements = AnnouncementModel::query()
            ->public()
            ->latest()
            ->paginate(6)
            ->through(function ($item) {
                $item->formatted_date = $item->created_at?->translatedFormat('d F Y') ?: '-';
                $item->month_year = $item->created_at?->translatedFormat('F Y') ?: '-';
                $item->day = $item->created_at?->translatedFormat('d') ?: '-';

                return $item;
            });

        return view('livewire.home.announcements', [
            'pageTitle' => 'Pengumuman',
            'pageDescription' => 'Dapatkan informasi dan pengumuman terbaru.',
            'announcements' => $announcements,
        ]);
    }
}
