<?php
require_once(__DIR__ . "/session.php");
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

function isSubAdminLoggedIn() {
    return isset($_SESSION['sub_admin_id']) && $_SESSION['sub_admin_role'] === 'sub_admin';
}

function requireSubAdminLogin() {
    if (!isSubAdminLoggedIn()) {
        header("Location: login.php");
        exit;
    }
}

function subAdminData() {
    return [
        "id" => $_SESSION['sub_admin_id'] ?? 0,
        "name" => $_SESSION['sub_admin_name'] ?? '',
        "mobile" => $_SESSION['sub_admin_mobile'] ?? '',
        "role" => $_SESSION['sub_admin_role'] ?? '',
        "village_id" => $_SESSION['sub_admin_village_id'] ?? 0
    ];
}
