<?php
namespace Claromentis\Design\Style;

$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] ?: array()) + array("_7f628626dd1d55c71b1" . "fc0932ffd1d2c" => base64_decode("aXNfY" . "XJyYX" . "k="), "_4d707fab93bebb00bbe69e81596" . "97c90" => base64_decode(""), "_bbf47ecb33399e483a5ba" . "a743a15212d" => base64_decode("JyBiYWNrZ3JvdW5kIFVSTCBmb3Igc" . "mVzb2x1dGlvbiAn"), "_e608e5b5c4c34a67ba97e" . "f84c1e16199" => base64_decode("Jw=" . "="), "_23a260280f" . "beb71416fd7" . "80b8adf18ea" => base64_decode("L21h" . "aW4="), "_646da98b9c1470f95d895beb9d41" . "1702" => base64_decode("bG9n" . "by4="), "_39d4082775b" . "2be44a207f8b" . "0b212fbda" => base64_decode("JyBmYXZpY29uIHVybCBmb3IgcmVzb2x1dGl" . "vbiAn"), "_22e351da3c" . "51b4bb23d06" . "ca9f34ba2e2" => base64_decode("Wyp" . "d"), "_f2065fafda951cfb3eba4c6ad6f" . "ef937" => base64_decode("RmFpbGVkIHRvIGxvYW" . "QgVGhlbWUgJw=="), "_bad6dfc2109d6" . "6c91fc231a4471" . "1c072" => base64_decode("L" . "g" . "=" . "="), "_9b0e879aae86fadb95cda" . "9c5f222d5b3" => base64_decode("Pg" . "=="), "_e55ddb2e629821363757b" . "a6a4b0f8c9a" => base64_decode("JyBMb2dvIFVSTA" . "=="), "_9a2f6a680862ebea63" . "faebf1c5fd1697" => base64_decode("Z2V0aW1h" . "Z2VzaXpl"), "_5e30c4717ced36cff9e93e19a5c57" . "6cc" => base64_decode("aXNf" . "c3Ry" . "aW5n"), "_e3a4c46d182fe6e780904aa33e7ea6" . "a1" => base64_decode("Y3JlYXRl" . "X3RlbXBf" . "cGF0aA=="), "_87daa84e346f6420a3" . "f3426e05d16a7b" => base64_decode("Lw" . "=="));
use ClaImage;
use Claromentis\Core\CDN;
use Claromentis\Core\Imager\Exception\ImagerException;
use Claromentis\Design\Facade\ActiveTheme;
use Claromentis\Design\Model\StyleAsset;
use Claromentis\Design\Model\Theme;
use Claromentis\Design\Repository\GlobalStyleStorage;
use Claromentis\Design\ThemeStyleInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
class Api implements ThemeStyleInterface, LoggerAwareInterface
{
    use LoggerAwareTrait;
    protected CDN\CDNInterface $cdn;
    protected StyleFactory $factory;
    private StyleOptionsEditable $master_design_style;
    public function __construct(GlobalStyleStorage $_1f1784b27681b09fb71a52c7625d43f2, StyleFactory $factory, CDN\CDNInterface $_fee64623e267830531765c6712d0f041, LoggerInterface $logger)
    {
        $this->factory = $factory;
        $this->cdn = $_fee64623e267830531765c6712d0f041;
        $this->setLogger($logger);
        $this->master_design_style = $this->GetStyle($_1f1784b27681b09fb71a52c7625d43f2);
    }
    
    
    
    
    public function GetDefaultStyle() : StyleOptionsEditable
    {
        return $this->master_design_style;
    }
    public function GetStyle(StorageInterface $storage) : StyleOptionsEditable
    {
        $_de3080120c36d7ea0154f3dd76f8b8ca = $storage->GetStyleData();
        if ($storage->GetDirectory()) {
            
            
            if (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::LOGO_EXTENSION]) && $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_5e30c4717ced36cff9" . "e93e19a5c576cc"]($_de3080120c36d7ea0154f3dd76f8b8ca[Option::LOGO_EXTENSION])) {
                try {
                    $_de3080120c36d7ea0154f3dd76f8b8ca[Option::LOGO_URL] = $this->GetLogoUrl($_de3080120c36d7ea0154f3dd76f8b8ca[Option::LOGO_EXTENSION], $storage->GetDirectory());
                } catch (CDN\CDNSystemException|Exceptions\AssetNotFoundException $_c35473364fa7a050299058f332ec29c1) {
                    $this->logger->warning($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_f2065fafda951cfb3eba4c" . "6ad6fef937"] . $_de3080120c36d7ea0154f3dd76f8b8ca[Option::LOGO_EXTENSION] . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_e55ddb2e629821363757ba6a4b0f8c" . "9a"]);
                }
            }
            
            
            
            if (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_DISABLED]) && $_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_DISABLED] === true) {
                $_de3080120c36d7ea0154f3dd76f8b8ca[Option::PAGE_BG_IMAGE] = [];
            } elseif (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_RESOLUTIONS]) && $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_7f628626dd1d55c71b1fc0" . "932ffd1d2c"]($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_RESOLUTIONS])) {
                $_de3080120c36d7ea0154f3dd76f8b8ca[Option::PAGE_BG_IMAGE] = $this->GetBackgroundUrls($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_RESOLUTIONS], $storage->GetDirectory());
            }
            
            
            
            if (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::FAVICON_RESOLUTIONS]) && $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_7f628626dd1d55c71b1" . "fc0932ffd1d2c"]($_de3080120c36d7ea0154f3dd76f8b8ca[Option::FAVICON_RESOLUTIONS])) {
                $_de3080120c36d7ea0154f3dd76f8b8ca[Option::FAVICON] = $this->GetFaviconUrls($_de3080120c36d7ea0154f3dd76f8b8ca[Option::FAVICON_RESOLUTIONS], $storage->GetDirectory());
            }
            
            
        }
        if ($storage instanceof GlobalStyleStorage) {
            $_ec5506f22f4380697838f5559d75d370 = $this->factory->StyleOptionsEditable($_de3080120c36d7ea0154f3dd76f8b8ca, new Option());
        } else {
            $_ec5506f22f4380697838f5559d75d370 = $this->factory->StyleOptionsEditable($_de3080120c36d7ea0154f3dd76f8b8ca, $this->master_design_style);
            $_ec5506f22f4380697838f5559d75d370->Set(Option::HOME_LAYOUT, 0);
        }
        return $_ec5506f22f4380697838f5559d75d370;
    }
    public function ValidateHomepage(Theme $theme)
    {
        
        
        return true;
    }
    public function GetPreviewUrl(ActiveTheme &$active_theme, Theme $theme) : string
    {
        $active_theme->SetLocalTheme($theme);
        return $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_23a260280" . "fbeb71416f" . "d780b8adf1" . "8ea"];
    }
    
    
    
    
    
    
    
    
    
    public function CreateResizedBackgroundAssets(string $_1aecfc3f31ca494fc97184ce4b77600d) : array
    {
        $_64cc3f0af0aeb2b004e7318ec5357113 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_e3a4c46d182fe6e780" . "904aa33e7ea6a1"](true);
        $_e466a9746f3c37e1531c1ac1a5a2580d = $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_9a2f6a680862ebea63faebf1c5f" . "d1697"]($_1aecfc3f31ca494fc97184ce4b77600d);
        $_c0e83ddea064ec2395c9069dbea2f7d5 = [];
        foreach (BackgroundConstants::ALL_RESOLUTIONS as $_1cd382e75da0293cf691fd1aea3b8114 => $_bdc6b14ad778cdf902c1dfc8dfd97380) {
            $_58dfe7f83aa523b9b37253797d030b59 = BackgroundConstants::FILENAME_PREFIX . ($_1cd382e75da0293cf691fd1aea3b8114 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_bad6dfc2109d66c91f" . "c231a44711c072"]) . BackgroundConstants::FILE_EXTENSION;
            $_5c1f50159611a559750b548f9e34dd30 = $_64cc3f0af0aeb2b004e7318ec5357113 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_87daa84e346f6420a3f3" . "426e05d16a7b"] . $_58dfe7f83aa523b9b37253797d030b59;
            ClaImage::Resize($_1aecfc3f31ca494fc97184ce4b77600d, $_5c1f50159611a559750b548f9e34dd30, $_bdc6b14ad778cdf902c1dfc8dfd97380[0], $_bdc6b14ad778cdf902c1dfc8dfd97380[1], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_4d707fab93bebb00" . "bbe69e8159697c90"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_9b0e879aae86fadb95cd" . "a9c5f222d5b3"]);
            $_c0e83ddea064ec2395c9069dbea2f7d5[$_1cd382e75da0293cf691fd1aea3b8114] = new StyleAsset($_58dfe7f83aa523b9b37253797d030b59, $_5c1f50159611a559750b548f9e34dd30);
            if (!$this->IsResolutionBigger($_e466a9746f3c37e1531c1ac1a5a2580d, $_bdc6b14ad778cdf902c1dfc8dfd97380)) {
                break;
            }
        }
        return $_c0e83ddea064ec2395c9069dbea2f7d5;
    }
    
    
    
    
    
    
    
    
    
    public function CreateResizedFaviconAssets(string $_1aecfc3f31ca494fc97184ce4b77600d) : array
    {
        $_741019f65bcf24e24c10625a33c35437 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_e3a4c46d182fe6e780904aa33e7ea6" . "a1"](true);
        $_3109032a72e3912357907157b2c6a6eb = [];
        foreach (FaviconConstants::ALL_RESOLUTIONS as $_1cd382e75da0293cf691fd1aea3b8114 => $_bdc6b14ad778cdf902c1dfc8dfd97380) {
            $_58dfe7f83aa523b9b37253797d030b59 = FaviconConstants::FILENAME_PREFIX . ($_1cd382e75da0293cf691fd1aea3b8114 . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bad6dfc2109" . "d66c91fc231a" . "44711c072"]) . FaviconConstants::FILE_EXTENSION;
            $_5c1f50159611a559750b548f9e34dd30 = $_741019f65bcf24e24c10625a33c35437 . $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_87daa84e346f6420a3f34" . "26e05d16a7b"] . $_58dfe7f83aa523b9b37253797d030b59;
            ClaImage::Resize($_1aecfc3f31ca494fc97184ce4b77600d, $_5c1f50159611a559750b548f9e34dd30, $_bdc6b14ad778cdf902c1dfc8dfd97380[0], $_bdc6b14ad778cdf902c1dfc8dfd97380[1], $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_4d707fab93bebb00bbe69e815" . "9697c90"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_22e351da3c51b4bb23d0" . "6ca9f34ba2e2"]);
            $_3109032a72e3912357907157b2c6a6eb[$_1cd382e75da0293cf691fd1aea3b8114] = new StyleAsset($_58dfe7f83aa523b9b37253797d030b59, $_5c1f50159611a559750b548f9e34dd30);
        }
        return $_3109032a72e3912357907157b2c6a6eb;
    }
    
    
    
    
    
    
    
    
    
    
    
    private function GetLogoUrl(string $_69de296d36a50a8c5167920e97921328, string $_4a92477f9348babb15c20a0ca0f9073b) : string
    {
        $_48dfd8f834d78abaee422695a2382f6a = $_4a92477f9348babb15c20a0ca0f9073b . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_646da98b9c1470f95d895be" . "b9d411702"] . $_69de296d36a50a8c5167920e97921328;
        $_6ae3783b9ad544a6c31a979683fed870 = $this->cdn->GetUrl($_48dfd8f834d78abaee422695a2382f6a);
        if (!isset($_6ae3783b9ad544a6c31a979683fed870)) {
            throw Exceptions\AssetNotFoundException::make($_48dfd8f834d78abaee422695a2382f6a);
        }
        return $_6ae3783b9ad544a6c31a979683fed870;
    }
    
    
    
    
    
    
    
    
    
    private function GetBackgroundUrls(array $_fe0631c08bbf3fe518d3a6fc089ff3a8, string $_4a92477f9348babb15c20a0ca0f9073b) : array
    {
        $_177f8385476cfb943aa76f9087cb8528 = [];
        foreach ($_fe0631c08bbf3fe518d3a6fc089ff3a8 as $_ebb8eed8c3cba0459be35f5cc286790e) {
            try {
                $_177f8385476cfb943aa76f9087cb8528[$_ebb8eed8c3cba0459be35f5cc286790e] = $this->GetBackgroundUrl($_ebb8eed8c3cba0459be35f5cc286790e, $_4a92477f9348babb15c20a0ca0f9073b);
            } catch (CDN\CDNSystemException|Exceptions\AssetNotFoundException $_c35473364fa7a050299058f332ec29c1) {
                $this->logger->warning($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_f2065fafda951cfb3eba4c" . "6ad6fef937"] . $_4a92477f9348babb15c20a0ca0f9073b . $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_bbf47ecb33" . "399e483a5ba" . "a743a15212d"] . $_ebb8eed8c3cba0459be35f5cc286790e . $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_e608e5b5c4c34a67ba97ef84" . "c1e16199"]);
            }
        }
        return $_177f8385476cfb943aa76f9087cb8528;
    }
    
    
    
    
    
    
    
    
    
    
    
    private function GetBackgroundUrl(string $_ebb8eed8c3cba0459be35f5cc286790e, string $_4a92477f9348babb15c20a0ca0f9073b) : string
    {
        $_48dfd8f834d78abaee422695a2382f6a = $_4a92477f9348babb15c20a0ca0f9073b . BackgroundConstants::FILENAME_PREFIX . ($_ebb8eed8c3cba0459be35f5cc286790e . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_bad6dfc2109d66c91fc" . "231a44711c072"]) . BackgroundConstants::FILE_EXTENSION;
        $_6ae3783b9ad544a6c31a979683fed870 = $this->cdn->GetUrl($_48dfd8f834d78abaee422695a2382f6a);
        if (!isset($_6ae3783b9ad544a6c31a979683fed870)) {
            throw Exceptions\AssetNotFoundException::make($_48dfd8f834d78abaee422695a2382f6a);
        }
        return $_6ae3783b9ad544a6c31a979683fed870;
    }
    
    
    
    
    
    
    
    
    
    private function GetFaviconUrls(array $_02ca24d67a520a949f5d6431b2c41162, string $_4a92477f9348babb15c20a0ca0f9073b) : array
    {
        $_a6eb99e6eb8c360663f5c454f69bff5e = [];
        foreach ($_02ca24d67a520a949f5d6431b2c41162 as $_6c2684872178a205b31ec2c7f39b60f7) {
            try {
                $_a6eb99e6eb8c360663f5c454f69bff5e[$_6c2684872178a205b31ec2c7f39b60f7] = $this->GetFaviconUrl($_6c2684872178a205b31ec2c7f39b60f7, $_4a92477f9348babb15c20a0ca0f9073b);
            } catch (CDN\CDNSystemException|Exceptions\AssetNotFoundException $_c35473364fa7a050299058f332ec29c1) {
                $this->logger->warning($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_f2065fafda" . "951cfb3eba4" . "c6ad6fef937"] . $_4a92477f9348babb15c20a0ca0f9073b . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_39d4082775b" . "2be44a207f8b" . "0b212fbda"] . $_6c2684872178a205b31ec2c7f39b60f7 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_e608e5b5c4c34a67ba97ef84c1e16" . "199"]);
            }
        }
        return $_a6eb99e6eb8c360663f5c454f69bff5e;
    }
    
    
    
    
    
    
    
    
    
    
    
    private function GetFaviconUrl(string $_6c2684872178a205b31ec2c7f39b60f7, string $_4a92477f9348babb15c20a0ca0f9073b) : string
    {
        $_48dfd8f834d78abaee422695a2382f6a = $_4a92477f9348babb15c20a0ca0f9073b . FaviconConstants::FILENAME_PREFIX . ($_6c2684872178a205b31ec2c7f39b60f7 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_bad6dfc2109d66c" . "91fc231a44711c07" . "2"]) . FaviconConstants::FILE_EXTENSION;
        $_6ae3783b9ad544a6c31a979683fed870 = $this->cdn->GetUrl($_48dfd8f834d78abaee422695a2382f6a);
        if (!isset($_6ae3783b9ad544a6c31a979683fed870)) {
            throw Exceptions\AssetNotFoundException::make($_48dfd8f834d78abaee422695a2382f6a);
        }
        return $_6ae3783b9ad544a6c31a979683fed870;
    }
    
    
    
    
    
    
    
    
    
    private function IsResolutionBigger($_5ce84c23611b9aa691df65d3990f3b80, $_bc3fc97cbfe329cb32d29ec5bc67a5aa) : bool
    {
        return $_5ce84c23611b9aa691df65d3990f3b80[0] > $_bc3fc97cbfe329cb32d29ec5bc67a5aa[0] || $_5ce84c23611b9aa691df65d3990f3b80[1] > $_bc3fc97cbfe329cb32d29ec5bc67a5aa[1];
    }
}