<?php
function __($key) {
    static $langData = null;
    static $currentLang = null;

    if (session_status() === PHP_SESSION_NONE) {
        session_start();
    }

    $lang = $_SESSION['admin_lang'] ?? 'en';
    
    if ($currentLang !== $lang || $langData === null) {
        $file = __DIR__ . '/../resources/lang/' . $lang . '.php';
        if (file_exists($file)) {
            $langData = require $file;
        } else {
            $langData = require __DIR__ . '/../resources/lang/en.php';
        }
        $currentLang = $lang;
    }

    return $langData[$key] ?? $key;
}

function getLang() {
    if (session_status() === PHP_SESSION_NONE) {
        session_start();
    }
    return $_SESSION['admin_lang'] ?? 'en';
}

function isRTL() {
    return getLang() === 'ar';
}
