<?php
namespace Claromentis\Design\Style;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] ?: array()) + array("_9b0e879aae86fadb95cda9c" . "5f222d5b3" => base64_decode("Pg" . "=="), "_e55ddb2e629821363757ba6" . "a4b0f8c9a" => base64_decode("JyBMb2dvIFVSTA=" . "="), "_5e30c4717ced36cff9e" . "93e19a5c576cc" => base64_decode("aXNf" . "c3Ry" . "aW5n"), "_87daa84e346f6420a3f3426e05d16a" . "7b" => base64_decode("L" . "w" . "=" . "="), "_39d4082775b2be44a207f8b0b21" . "2fbda" => base64_decode("JyBmYXZpY29uIHVy" . "bCBmb3IgcmVzb2x1" . "dGlvbiAn"), "_f2065fafda951c" . "fb3eba4c6ad6fef" . "937" => base64_decode("RmFpbGVkIHRvIGxvYWQgVGhlbWUg" . "Jw=="), "_23a260280fbeb71416f" . "d780b8adf18ea" => base64_decode("L21haW" . "4="), "_22e351da3c51b" . "4bb23d06ca9f34" . "ba2e2" => base64_decode("Wy" . "pd"), "_e3a4c46d182fe6e780904aa33e7e" . "a6a1" => base64_decode("Y3JlYXRlX3RlbXBf" . "cGF0aA=="), "_9a2f6a680862ebe" . "a63faebf1c5fd169" . "7" => base64_decode("Z2V0aW1h" . "Z2VzaXpl"), "_bad6dfc2109d66c91fc231" . "a44711c072" => base64_decode("Lg" . "=="), "_4d707fab93" . "bebb00bbe69" . "e8159697c90" => base64_decode(""), "_e608e5b5c4c34a67ba97ef" . "84c1e16199" => base64_decode("Jw" . "=="), "_bbf47ecb33399e483a5baa743a1521" . "2d" => base64_decode("JyBiYWNrZ3JvdW5kIFVSTCBmb3Igc" . "mVzb2x1dGlvbiAn"), "_646da98b9c1470f9" . "5d895beb9d411702" => base64_decode("bG9nby4" . "="), "_7f628626dd1d55c71b" . "1fc0932ffd1d2c" => base64_decode("aXNfYXJyYX" . "k="));
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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_5e30c4717ced" . "36cff9e93e19a" . "5c576cc"]($_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["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_f2065fafda951c" . "fb3eba4c6ad6fef" . "937"] . $_de3080120c36d7ea0154f3dd76f8b8ca[Option::LOGO_EXTENSION] . $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e55ddb2e629821363757ba6a4b0f8c9" . "a"]);
                }
            }
            
            
            
            if (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_DISABLED]) && $_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_DISABLED] === true) {
                $_de3080120c36d7ea0154f3dd76f8b8ca[Option::PAGE_BG_IMAGE] = [];
            } elseif (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_RESOLUTIONS]) && $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7f628626dd1d55c7" . "1b1fc0932ffd1d2c"]($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_RESOLUTIONS])) {
                $_de3080120c36d7ea0154f3dd76f8b8ca[Option::PAGE_BG_IMAGE] = $this->GetBackgroundUrls($_de3080120c36d7ea0154f3dd76f8b8ca[Option::BACKGROUND_RESOLUTIONS], $storage->GetDirectory());
            }
            
            
            
            if (isset($_de3080120c36d7ea0154f3dd76f8b8ca[Option::FAVICON_RESOLUTIONS]) && $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_7f628626dd1d55c7" . "1b1fc0932ffd1d2c"]($_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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_23a260280fbeb71416f" . "d780b8adf18ea"];
    }
    
    
    
    
    
    
    
    
    
    public function CreateResizedBackgroundAssets(string $_1aecfc3f31ca494fc97184ce4b77600d) : array
    {
        $_64cc3f0af0aeb2b004e7318ec5357113 = $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_e3a4c46d182fe6e780904aa3" . "3e7ea6a1"](true);
        $_e466a9746f3c37e1531c1ac1a5a2580d = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_9a2f6a680862ebea63faebf1c5fd1" . "697"]($_1aecfc3f31ca494fc97184ce4b77600d);
        $_c0e83ddea064ec2395c9069dbea2f7d5 = [];
        foreach (BackgroundConstants::ALL_RESOLUTIONS as $_1cd382e75da0293cf691fd1aea3b8114 => $_bdc6b14ad778cdf902c1dfc8dfd97380) {
            $_58dfe7f83aa523b9b37253797d030b59 = BackgroundConstants::FILENAME_PREFIX . ($_1cd382e75da0293cf691fd1aea3b8114 . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_bad6dfc2109d66c91fc23" . "1a44711c072"]) . BackgroundConstants::FILE_EXTENSION;
            $_5c1f50159611a559750b548f9e34dd30 = $_64cc3f0af0aeb2b004e7318ec5357113 . $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_87daa84e346f6420a3f3426e05d16" . "a7b"] . $_58dfe7f83aa523b9b37253797d030b59;
            ClaImage::Resize($_1aecfc3f31ca494fc97184ce4b77600d, $_5c1f50159611a559750b548f9e34dd30, $_bdc6b14ad778cdf902c1dfc8dfd97380[0], $_bdc6b14ad778cdf902c1dfc8dfd97380[1], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_4d707fab93bebb00bbe69e8159" . "697c90"], $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_9b0e879aae86fadb95cda9" . "c5f222d5b3"]);
            $_c0e83ddea064ec2395c9069dbea2f7d5[$_1cd382e75da0293cf691fd1aea3b8114] = new StyleAsset($_58dfe7f83aa523b9b37253797d030b59, $_5c1f50159611a559750b548f9e34dd30);
            if (!$this->IsResolutionBigger($_e466a9746f3c37e1531c1ac1a5a2580d, $_bdc6b14ad778cdf902c1dfc8dfd97380)) {
                break;
            }
        }
        return $_c0e83ddea064ec2395c9069dbea2f7d5;
    }
    
    
    
    
    
    
    
    
    
    public function CreateResizedFaviconAssets(string $_1aecfc3f31ca494fc97184ce4b77600d) : array
    {
        $_741019f65bcf24e24c10625a33c35437 = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_e3a4c46d182fe6e780904aa33e7" . "ea6a1"](true);
        $_3109032a72e3912357907157b2c6a6eb = [];
        foreach (FaviconConstants::ALL_RESOLUTIONS as $_1cd382e75da0293cf691fd1aea3b8114 => $_bdc6b14ad778cdf902c1dfc8dfd97380) {
            $_58dfe7f83aa523b9b37253797d030b59 = FaviconConstants::FILENAME_PREFIX . ($_1cd382e75da0293cf691fd1aea3b8114 . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_bad6dfc2109d66c91fc231a44711" . "c072"]) . FaviconConstants::FILE_EXTENSION;
            $_5c1f50159611a559750b548f9e34dd30 = $_741019f65bcf24e24c10625a33c35437 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_87daa84e346f6420a3f3426e05d" . "16a7b"] . $_58dfe7f83aa523b9b37253797d030b59;
            ClaImage::Resize($_1aecfc3f31ca494fc97184ce4b77600d, $_5c1f50159611a559750b548f9e34dd30, $_bdc6b14ad778cdf902c1dfc8dfd97380[0], $_bdc6b14ad778cdf902c1dfc8dfd97380[1], $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4d707fab93bebb00bbe" . "69e8159697c90"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_22e351da3c51b4bb23d06ca9f34ba2" . "e2"]);
            $_3109032a72e3912357907157b2c6a6eb[$_1cd382e75da0293cf691fd1aea3b8114] = new StyleAsset($_58dfe7f83aa523b9b37253797d030b59, $_5c1f50159611a559750b548f9e34dd30);
        }
        return $_3109032a72e3912357907157b2c6a6eb;
    }
    
    
    
    
    
    
    
    
    
    
    
    private function GetLogoUrl(string $_69de296d36a50a8c5167920e97921328, string $_4a92477f9348babb15c20a0ca0f9073b) : string
    {
        $_48dfd8f834d78abaee422695a2382f6a = $_4a92477f9348babb15c20a0ca0f9073b . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_646da98b9c1470f9" . "5d895beb9d411702"] . $_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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_f2065fafda951cf" . "b3eba4c6ad6fef93" . "7"] . $_4a92477f9348babb15c20a0ca0f9073b . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bbf47ec" . "b33399e4" . "83a5baa7" . "43a15212" . "d"] . $_ebb8eed8c3cba0459be35f5cc286790e . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_e608e5b5c4c34a67b" . "a97ef84c1e16199"]);
            }
        }
        return $_177f8385476cfb943aa76f9087cb8528;
    }
    
    
    
    
    
    
    
    
    
    
    
    private function GetBackgroundUrl(string $_ebb8eed8c3cba0459be35f5cc286790e, string $_4a92477f9348babb15c20a0ca0f9073b) : string
    {
        $_48dfd8f834d78abaee422695a2382f6a = $_4a92477f9348babb15c20a0ca0f9073b . BackgroundConstants::FILENAME_PREFIX . ($_ebb8eed8c3cba0459be35f5cc286790e . $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_bad6dfc2109d66c91fc231" . "a44711c072"]) . 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["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_f2065fafda951cfb3eba" . "4c6ad6fef937"] . $_4a92477f9348babb15c20a0ca0f9073b . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_39d4082775b2be44a207f8b0b212fb" . "da"] . $_6c2684872178a205b31ec2c7f39b60f7 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_e608e5b5c4c34a67ba97ef8" . "4c1e16199"]);
            }
        }
        return $_a6eb99e6eb8c360663f5c454f69bff5e;
    }
    
    
    
    
    
    
    
    
    
    
    
    private function GetFaviconUrl(string $_6c2684872178a205b31ec2c7f39b60f7, string $_4a92477f9348babb15c20a0ca0f9073b) : string
    {
        $_48dfd8f834d78abaee422695a2382f6a = $_4a92477f9348babb15c20a0ca0f9073b . FaviconConstants::FILENAME_PREFIX . ($_6c2684872178a205b31ec2c7f39b60f7 . $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_bad6dfc2109d66c91fc231a" . "44711c072"]) . 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];
    }
}