<?php
namespace App\Core;

abstract class Controller {
    protected function render(string $viewPath, array $data = [], string $layout = 'layouts/header'): void {
        extract($data);
        $contentView = dirname(__DIR__, 2) . '/views/' . $viewPath . '.php';

        if (!file_exists($contentView)) {
            die("View file not found: views/{$viewPath}.php");
        }

        // Layout wrapping
        $headerPath = dirname(__DIR__, 2) . '/views/layouts/header.php';
        $footerPath = dirname(__DIR__, 2) . '/views/layouts/footer.php';
        $authLayout = dirname(__DIR__, 2) . '/views/layouts/auth.php';

        if ($layout === 'layouts/auth') {
            require $authLayout;
        } else {
            require $headerPath;
            require $contentView;
            require $footerPath;
        }
    }

    protected function json(mixed $data, int $statusCode = 200): void {
        Response::json($data, $statusCode);
    }

    protected function success(mixed $data = null, string $message = 'Success'): void {
        Response::success($data, $message);
    }

    protected function error(string $message, int $statusCode = 400): void {
        Response::error($message, $statusCode);
    }

    protected function redirect(string $url): void {
        Response::redirect($url);
    }
}
