<?php
declare(strict_types=1);

function post(string $key, mixed $default = ''): mixed
{
    return $_POST[$key] ?? $default;
}

function get_value(string $key, mixed $default = ''): mixed
{
    return $_GET[$key] ?? $default;
}

function is_post(): bool
{
    return ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST';
}

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

function get_flash(): ?array
{
    if (!isset($_SESSION['flash_message'])) {
        return null;
    }

    $flash = $_SESSION['flash_message'];
    unset($_SESSION['flash_message']);

    return $flash;
}

function old(string $key, mixed $default = ''): mixed
{
    return $_POST[$key] ?? $default;
}

function admin_role_label(string $role): string
{
    return match ($role) {
        'super_admin' => 'Super Admin',
        'admin' => 'Admin',
        default => 'Staff',
    };
}

function admin_status_label(int $status): string
{
    return $status === 1 ? 'Active' : 'Inactive';
}

function format_datetime(?string $datetime): string
{
    if (empty($datetime)) {
        return '-';
    }

    return date('Y-m-d h:i A', strtotime($datetime));
}
?>