<?php

namespace App\Http\Controllers\Public;

use App\Http\Controllers\Controller;
use App\Models\Post;

class PostController extends Controller
{
    public function berita()
    {
        $posts = Post::berita()->orderByDesc('tanggal')->paginate(9);
        return view('public.berita.index', compact('posts'));
    }

    public function pengumuman()
    {
        $posts = Post::pengumuman()->orderByDesc('tanggal')->paginate(9);
        return view('public.pengumuman.index', compact('posts'));
    }

    public function show(string $slug)
    {
        $post = Post::where('slug', $slug)->firstOrFail();
        $related = Post::where('tipe', $post->tipe)
                       ->where('id', '!=', $post->id)
                       ->orderByDesc('tanggal')
                       ->limit(3)
                       ->get();

        return view('public.berita.show', compact('post', 'related'));
    }
}
