<?php
use App\Core\I18n;

if (!function_exists('ec_lang')) {
    function ec_lang(): string {
        return I18n::current();
    }
}

if (!function_exists('ec_dir')) {
    function ec_dir(): string {
        return I18n::dir();
    }
}

if (!function_exists('ec_is_rtl')) {
    function ec_is_rtl(): bool {
        return ec_dir() === 'rtl';
    }
}

/* Keep lang() only because PHP has no built-in lang() */
if (!function_exists('lang')) {
    function lang(): string {
        return ec_lang();
    }
}

/* Do NOT define dir() because PHP already has built-in dir() */

if (!function_exists('is_rtl')) {
    function is_rtl(): bool {
        return ec_is_rtl();
    }
}

if (!function_exists('t')) {
    function t(string $key, ?string $fallback = null, array $replace = []): string {
        return I18n::t($key, $fallback, $replace);
    }
}

if (!function_exists('eh')) {
    function eh($v): string {
        return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
    }
}
