<?php

class Controller
{
    protected function view(string $view, array $data = [], string $layout = 'app'): void
    {
        extract($data);

        ob_start();
        require app_path("Views/{$view}.php");
        $content = ob_get_clean();

        require app_path("Views/layouts/{$layout}.php");
    }

    protected function redirect(string $path): void
    {
        header('Location: ' . url($path));
        exit;
    }

    protected function back(): void
    {
        header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? url('/dashboard')));
        exit;
    }

    protected function flash(string $type, string $message): void
    {
        $_SESSION['flash'] = ['type' => $type, 'message' => $message];
    }
}
