<?php
namespace Claromentis\Core\Localization;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_e608e5b5c4c34a67ba97ef84c1e161" . "99" => base64_decode("J" . "w" . "=" . "="), "_8ab6ddf42088608c501fcded8995e7" . "6c" => base64_decode("I" . "A" . "=" . "="), "_83078c85038df2" . "951be949e6830f2" . "2f3" => base64_decode("Y29t" . "bW9u"), "_a591754" . "a8ddcdbd" . "a9c80f1d" . "b4d911e1" . "4" => base64_decode("aXNfbnV" . "sbA=="), "_4d707fab93" . "bebb00bbe69" . "e8159697c90" => base64_decode(""), "_3c7e5a84d6bd647cca7f631004fa64" . "5b" => base64_decode("X3N5c3Rlb" . "S5pc28="), "_24401d7f17" . "5c5083e17a2" . "5fd234d9c4c" => base64_decode("X3N5c3RlbS5sb2NhbGU" . "="), "_7f628626dd" . "1d55c71b1fc" . "0932ffd1d2c" => base64_decode("aXNfYXJ" . "yYXk="), "_822614a7e682852b781fb34eccacf" . "8ad" => base64_decode("TG9jYWxpemF0aW9uIFBocmFzZSBub3QgZm91bmQgaW4gZXhwZWN0ZWQgTG9jYWxpemF0aW9uIFB" . "yb3ZpZGVyLCBmYWxsaW5nIGJhY2sgdG8gJ2NvbW1vbic="), "_eae08e7ca777f6" . "16bd20ef76a73dd" . "052" => base64_decode("VG9vIGRlZXAgbmVzdGlu" . "ZyBmb3IgdmFsdWUgb2Yg" . "a2V5ICc="), "_2a5789b3d67b8" . "cd24b7372ffe23" . "9c928" => base64_decode("b" . "W" . "Q" . "1"));
use Claromentis\Core\Date\DateFormatter;
use Claromentis\Core\Localization\Exception\MissingPhraseException;
use Claromentis\Core\Localization\Exception\RecursionException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;




class Localization implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    
    
    private $api;
    
    
    
    
    
    
    protected $language;
    
    
    
    
    
    
    
    protected $domains_cb;
    
    
    
    
    
    
    protected $domains_list_cb;
    
    
    
    
    
    
    protected $locale;
    
    
    
    
    protected ?string $iso = null;
    
    
    
    
    protected $date_formatter;
    public function __construct(callable $_7981049853d32e68edddb123832515d1, callable $_e625ee578ba02a17432afa008d0dbae9, Api $api, ?LoggerInterface $logger = null)
    {
        $this->domains_cb = $_7981049853d32e68edddb123832515d1;
        $this->domains_list_cb = $_e625ee578ba02a17432afa008d0dbae9;
        $this->api = $api;
        $this->logger = $logger ?? new NullLogger();
    }
    
    
    
    
    
    
    
    
    
    
    
    
    protected function getProviderForKey(string $key) : LocalizationProviderInterface
    {
        return ($this->domains_cb)($this->api->getDomainFromKey($key));
    }
    
    
    
    
    
    
    public function SetLanguage($_059707644b06dfe19a36970b58499427)
    {
        $this->language = $_059707644b06dfe19a36970b58499427;
        try {
            $this->locale = $this->getTranslation($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_24401d7f175c5083e17a25fd234d9" . "c4c"]);
        } catch (MissingPhraseException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            
            
        }
        try {
            $this->iso = $this->getTranslation($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_3c7e5a84d6bd647cca7f63" . "1004fa645b"]);
        } catch (MissingPhraseException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            
            
        }
        if ($this->date_formatter) {
            $this->date_formatter->SetLocale($this->locale);
        }
    }
    
    
    
    
    public function GetDateFormatter()
    {
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_a591754a8ddcd" . "bda9c80f1db4d9" . "11e14"]($this->date_formatter)) {
            $this->date_formatter = new DateFormatter($this->GetLocale());
        }
        return $this->date_formatter;
    }
    
    
    
    
    public function SetDateFormatter(DateFormatter $_839c3c073c96f9bdfd39dc906bb225ca)
    {
        $this->date_formatter = $_839c3c073c96f9bdfd39dc906bb225ca;
    }
    public function GetLocale()
    {
        return $this->locale;
    }
    
    
    
    
    public function GetLanguage()
    {
        return $this->language;
    }
    
    
    
    
    
    
    public function GetIsoLanguageCode() : ?string
    {
        return $this->iso;
    }
    
    
    
    
    
    
    
    
    
    public function getTranslation($key) : string
    {
        $_3ce61d3a8a385e00d1583b95ce3eacb0 = 0;
        $_a2c1535293d134e078c87c81de95f1d1 = [$key];
        while ($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7f628626dd1d55c7" . "1b1fc0932ffd1d2c"]($_a2c1535293d134e078c87c81de95f1d1)) {
            if (++$_3ce61d3a8a385e00d1583b95ce3eacb0 > 6) {
                throw new RecursionException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_eae08e7" . "ca777f61" . "6bd20ef7" . "6a73dd05" . "2"] . $key . $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_e608e5b5c4c34a67ba97e" . "f84c1e16199"]);
            }
            [$_55f9450437d59e5f75ccef38c0869e77] = $_a2c1535293d134e078c87c81de95f1d1;
            $_a12c8da0f19064827eae63fd854c04e5 = $this->getProviderForKey((string) $_55f9450437d59e5f75ccef38c0869e77);
            try {
                $_a2c1535293d134e078c87c81de95f1d1 = $_a12c8da0f19064827eae63fd854c04e5->getTranslation((string) $_55f9450437d59e5f75ccef38c0869e77, (string) $this->language);
            } catch (MissingPhraseException $_c35473364fa7a050299058f332ec29c1) {
                $domain = $_a12c8da0f19064827eae63fd854c04e5->getDomain();
                if ($domain === $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_83078c85038df2951be949e6830f" . "22f3"]) {
                    throw $_c35473364fa7a050299058f332ec29c1;
                }
                $this->logger->info($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_822614a" . "7e682852" . "b781fb34" . "eccacf8a" . "d"], [$_55f9450437d59e5f75ccef38c0869e77, $domain, $this->language, $_c35473364fa7a050299058f332ec29c1]);
                $this->logger->debug((string) $_c35473364fa7a050299058f332ec29c1);
                $_a2c1535293d134e078c87c81de95f1d1 = $this->getProviderForKey($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_83078c85038df" . "2951be949e6830" . "f22f3"])->getTranslation((string) $_55f9450437d59e5f75ccef38c0869e77, (string) $this->language);
            }
        }
        return $_a2c1535293d134e078c87c81de95f1d1;
    }
    public function KeyExist($key)
    {
        return $this->getProviderForKey((string) $key)->hasKey((string) $key, (string) $this->language);
    }
    public function GetTemplaterPhrases()
    {
        $_7981049853d32e68edddb123832515d1 = $this->domains_cb;
        $_e625ee578ba02a17432afa008d0dbae9 = $this->domains_list_cb;
        $_bdcd291bc93c7fda12750881300b2c23 = [];
        $domains = $_e625ee578ba02a17432afa008d0dbae9();
        foreach ($domains as $domain) {
            
            
            $_a12c8da0f19064827eae63fd854c04e5 = $_7981049853d32e68edddb123832515d1($domain);
            $_bdcd291bc93c7fda12750881300b2c23 = $_bdcd291bc93c7fda12750881300b2c23 + $_a12c8da0f19064827eae63fd854c04e5->getTemplaterPhrases((string) $this->language);
        }
        return $_bdcd291bc93c7fda12750881300b2c23;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function GetDataHash($_c46b5858233c8518dcb829bc6f4ce867 = null)
    {
        $_7981049853d32e68edddb123832515d1 = $this->domains_cb;
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_7f628626dd1d55c71b1fc0932ffd1d" . "2c"]($_c46b5858233c8518dcb829bc6f4ce867)) {
            $domains = $_c46b5858233c8518dcb829bc6f4ce867;
        } else {
            $_e625ee578ba02a17432afa008d0dbae9 = $this->domains_list_cb;
            $domains = $_e625ee578ba02a17432afa008d0dbae9();
        }
        $_9a780f2665988298e8d07fb17b28337b = $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_4d707fab93bebb00b" . "be69e8159697c90"];
        foreach ($domains as $domain) {
            
            
            $_a12c8da0f19064827eae63fd854c04e5 = $_7981049853d32e68edddb123832515d1($domain);
            $_72a7209efcd9c803cef80753f412d5cd = $_a12c8da0f19064827eae63fd854c04e5->getDataHash((string) $this->language);
            if ($_72a7209efcd9c803cef80753f412d5cd !== null && $_72a7209efcd9c803cef80753f412d5cd !== $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_4d707fab93bebb00bbe69e" . "8159697c90"]) {
                $_9a780f2665988298e8d07fb17b28337b .= $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_8ab6ddf42088608c501fcded" . "8995e76c"] . $_72a7209efcd9c803cef80753f412d5cd;
            }
        }
        
        
        return $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_2a5789b3d67b8cd24b7372ffe23" . "9c928"]($_9a780f2665988298e8d07fb17b28337b);
    }
}