<?php
/// file: app/Controllers/WorkController.php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;
use App\Helpers\Seo;
use App\Models\Project;

final class WorkController extends Controller
{
    public function index(Request $request): Response
    {
        $category = $request->input('category');
        $projects = Project::filterByCategory($category);
        $categories = ['all' => __('work.cat_all')];
        foreach (Project::categorySlugs() as $slug) {
            $categories[$slug] = __(Project::categoryMessageKey($slug));
        }

        $html = $this->view('work/index', [
            'meta' => Seo::page('work'),
            'page' => 'work',
            'projects' => $projects,
            'activeCategory' => $category ?? 'all',
            'categories' => $categories,
        ], 'layouts/base');

        return Response::html($html);
    }
}
