<?php

namespace App\Http\Controllers;

use App\Models\HeroSlide;
use App\Models\Post;
use App\Models\Setting;

class PostController extends Controller
{
    public function index()
    {
        $settings = Setting::first();

        $heroSlides = HeroSlide::active()
            ->orderBy('sort_order')
            ->orderBy('id')
            ->get();

        $posts = Post::where('is_published', true)
            ->latest()
            ->paginate(9);

        return view('news.index', compact(
            'settings',
            'heroSlides',
            'posts'
        ));
    }

    public function show($slug)
    {
        $settings = Setting::first();

        $heroSlides = HeroSlide::active()
            ->orderBy('sort_order')
            ->orderBy('id')
            ->get();

        $post = Post::where('slug', $slug)
            ->where('is_published', true)
            ->firstOrFail();

        return view('news.show', compact(
            'settings',
            'heroSlides',
            'post'
        ));
    }
}