<?php

namespace App\Controllers;

use App\Core\Controller;
use App\Models\Announcement;
use App\Models\CmsPage;
use App\Models\CustomLink;
use App\Models\Event;
use App\Models\PhotoAlbum;
use App\Models\Setting;

class HomeController extends Controller
{
    public function index()
    {
        $announcementModel = new Announcement();
        $eventModel = new Event();
        $linkModel = new CustomLink();
        $albumModel = new PhotoAlbum();
        $settingModel = new Setting();
        $cmsModel = new CmsPage();

        $announcements = $announcementModel->getPublic(6);
        $upcomingEvents = $eventModel->getPublicUpcoming(6);
        $quickLinks = $linkModel->getActive();
        $albums = $albumModel->getPublic();

        $homePage = $cmsModel->findBySlug('home');
        $heroTitle = $settingModel->getValue('home_hero_title', 'Advancing Anaesthesiology in Ghana');
        $heroSubtitle = $settingModel->getValue('home_hero_subtitle', '');
        $showAnnouncements = $settingModel->getValue('home_show_announcements', 'true') === 'true';
        $showEvents = $settingModel->getValue('home_show_events', 'true') === 'true';
        $bannerImage = $settingModel->getValue('home_banner_image', '');
        $companyLogo = $settingModel->getValue('company_logo', '');
        $companyFavicon = $settingModel->getValue('company_favicon', '');

        $this->view('home/index', [
            'announcements' => $announcements,
            'upcomingEvents' => $upcomingEvents,
            'quickLinks' => $quickLinks,
            'albums' => $albums,
            'homePage' => $homePage,
            'heroTitle' => $heroTitle,
            'heroSubtitle' => $heroSubtitle,
            'showAnnouncements' => $showAnnouncements,
            'showEvents' => $showEvents,
            'bannerImage' => $bannerImage,
            'companyLogo' => $companyLogo,
            'companyFavicon' => $companyFavicon,
        ], false);
    }
}
