<?php

namespace App\Http\Controllers\Site;

use App\Http\Controllers\Controller;
use App\Models\Page;
use App\Models\Testimonial;
use Illuminate\Contracts\View\View;

class ContentPageController extends Controller
{
    public function show(string $slug): View
    {
        $routePath = '/'.$slug;

        $page = Page::query()
            ->published()
            ->where('route_path', $routePath)
            ->with('sections')
            ->firstOrFail();

        if ($slug === 'about') {
            return view('site.about', compact('page'));
        }

        if ($slug === 'testimonials') {
            $testimonials = Testimonial::query()->published()->orderBy('sort_order')->get();

            return view('site.testimonials-page', compact('page', 'testimonials'));
        }

        return view('site.page', compact('page'));
    }
}
