<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Request;
use App\Core\Response;
use App\Core\Settings;
use App\Core\View;
use App\Models\Gallery;
use App\Models\Page;

final class HomeController
{
    /** @param array<string,string> $params */
    public function index(Request $request, array $params): Response
    {
        $siteTitle = (string) Settings::get('site_title', 'DANIEL TIZIANI');
        $home      = Page::findPublishedBySlug('home');

        $seoTitle = is_array($home) && is_string($home['seo_title'] ?? null) && $home['seo_title'] !== ''
            ? (string) $home['seo_title'] : $siteTitle;

        return Response::html(View::render('public/home', [
            'pageTitle'       => $seoTitle,
            'metaDescription' => (is_array($home) ? ($home['seo_description'] ?? null) : null) ?? $siteTitle,
            'introHtml'       => (string) (is_array($home) ? ($home['body_html'] ?? '') : ''),
            'galleries'       => Gallery::publishedList(),
        ]));
    }
}
