<?php

namespace App\Controllers\Admin;

use App\Core\Auth;
use App\Core\Controller;

abstract class AdminController extends Controller
{
    public function __construct()
    {
        if (!Auth::check()) {
            header('Location: ' . APP_URL . '/admin/login');
            exit;
        }
    }

    /**
     * Render view dengan prefix folder admin/ secara otomatis.
     */
    protected function adminView(string $view, array $data = []): void
    {
        $data['admin'] = Auth::user();
        $this->view('admin/' . $view, $data);
    }
}
