<?php

namespace App\Controllers;

use App\Core\Controller;
use App\Models\FooterModel;
use App\Models\GaleriFotoDetailModel;
use App\Models\GaleriFotoModel;
use App\Models\GaleriVideoModel;
use App\Models\IdentitasModel;
use App\Models\MenuModel;
use App\Models\WidgetModel;

class GaleriController extends Controller
{
    public function foto(): void
    {
        $this->view('galeri/foto-index', array_merge($this->layoutData(), [
            'daftarAlbum' => (new GaleriFotoModel())->getAllWithCount(),
        ]));
    }

    public function fotoShow(string $id): void
    {
        $album = (new GaleriFotoModel())->find((int) $id);

        if (!$album) {
            http_response_code(404);
            $this->view('errors/404');
            return;
        }

        $this->view('galeri/foto-show', array_merge($this->layoutData(), [
            'album'      => $album,
            'daftarFoto' => (new GaleriFotoDetailModel())->getByGaleriId((int) $id),
        ]));
    }

    public function video(): void
    {
        $this->view('galeri/video-index', array_merge($this->layoutData(), [
            'daftarVideo' => (new GaleriVideoModel())->all(),
        ]));
    }

    private function layoutData(): array
    {
        return [
            'identitas'     => (new IdentitasModel())->getIdentitas(),
            'menus'         => (new MenuModel())->getMenuUtama(),
            'footerKolom'   => (new FooterModel())->getKolom(),
            'widgetSidebar' => (new WidgetModel())->getByPosisi('sidebar'),
        ];
    }
}
