<?php
namespace Claromentis\Design;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("_40434e3a21b1" . "e9b323ebc5306" . "a5f9ab6" => base64_decode("ZGVzaWduLnZhbGlkYXRpb24uaW52YWxpZF9o" . "b21lcGFnZQ=="), "_0c5123aa744f69bbc0e8b3ea2" . "f6e847d" => base64_decode("bG" . "1z" . "Zw" . "=="), "_22e88c0d92b954ab307" . "5ac36c84d7fda" => base64_decode("L21haW4tb2xk" . "Lw=="));
use Claromentis\Core\CDN;
use Claromentis\Design\Exception\HomepageNotFoundException;
use Claromentis\Design\Facade\ActiveTheme;
use Claromentis\Design\Model\Theme;
use Claromentis\Design\Repository\GlobalStyleStorage;
use Claromentis\Design\Style\Api;
use Claromentis\Design\Style\StyleFactory;
use Claromentis\Design\Style\InheritableStyle;
use Claromentis\Design\Style\Option;
use Claromentis\Design\Style\StyleOptionsEditable;
use Claromentis\Design\Style\StorageInterface;
use Claromentis\Design\View\LayoutSelect;
use Claromentis\Pages\Exception\PageNotFoundException;
use Claromentis\Pages\Model\PageUrl;
use Claromentis\Pages\Repository\UrlRepository;
use Psr\Log\LoggerInterface;
class ThemeStyle extends Api
{
    protected UrlRepository $url_repo;
    public function __construct(UrlRepository $_4fd544a0039d23957d8ced73ba74acb9, GlobalStyleStorage $_1f1784b27681b09fb71a52c7625d43f2, StyleFactory $factory, CDN\CDNInterface $_fee64623e267830531765c6712d0f041, LoggerInterface $logger)
    {
        $this->url_repo = $_4fd544a0039d23957d8ced73ba74acb9;
        parent::__construct($_1f1784b27681b09fb71a52c7625d43f2, $factory, $_fee64623e267830531765c6712d0f041, $logger);
    }
    public function GetStyle(StorageInterface $storage) : StyleOptionsEditable
    {
        $_ec5506f22f4380697838f5559d75d370 = parent::GetStyle($storage);
        if ($storage instanceof Theme) {
            $_7c7c9c63e1edfaf2a33ddf2c785e6a4a = $storage->pages_url_id;
            switch ($_7c7c9c63e1edfaf2a33ddf2c785e6a4a) {
                case LayoutSelect::LAYOUT_VI:
                    $_7c7c9c63e1edfaf2a33ddf2c785e6a4a = 0;
                    break;
                case Layoutselect::LAYOUT_DEFAULT:
                    $_7c7c9c63e1edfaf2a33ddf2c785e6a4a = $_ec5506f22f4380697838f5559d75d370->Get(Option::HOME_LAYOUT);
                    break;
                default:
                    $_7c7c9c63e1edfaf2a33ddf2c785e6a4a = (int) $_7c7c9c63e1edfaf2a33ddf2c785e6a4a;
                    break;
            }
            try {
                $this->ValidateHomepage($storage);
            } catch (HomepageNotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
                $_7c7c9c63e1edfaf2a33ddf2c785e6a4a = $this->GetDefaultStyle()->Get(Option::HOME_LAYOUT);
            }
            $_ec5506f22f4380697838f5559d75d370->Set(Option::HOME_LAYOUT, $_7c7c9c63e1edfaf2a33ddf2c785e6a4a);
        }
        return $_ec5506f22f4380697838f5559d75d370;
    }
    public function ValidateHomepage(Theme $theme)
    {
        $_7c7c9c63e1edfaf2a33ddf2c785e6a4a = $theme->pages_url_id;
        if ($_7c7c9c63e1edfaf2a33ddf2c785e6a4a == 0) {
            return;
        }
        
        
        if ($_7c7c9c63e1edfaf2a33ddf2c785e6a4a > 0) {
            try {
                $this->url_repo->GetById($_7c7c9c63e1edfaf2a33ddf2c785e6a4a);
            } catch (PageNotFoundException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
                throw new HomepageNotFoundException($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_0c5123aa744f69b" . "bc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_40434e3a21b1e9b3" . "23ebc5306a5f9ab6"]));
            }
        }
    }
    public function GetPreviewUrl(ActiveTheme &$active_theme, Theme $theme) : string
    {
        
        
        $_ec5506f22f4380697838f5559d75d370 = $this->GetStyle($theme);
        $active_theme->SetLocalTheme($theme);
        $_ac4dbc10ecf438074b2cfc89879aacb5 = $_ec5506f22f4380697838f5559d75d370->Get(Option::HOME_LAYOUT);
        if ($_ac4dbc10ecf438074b2cfc89879aacb5 > 0) {
            
            
            $_a50cb37feb2486bcac87f47b51c37824 = $this->url_repo->GetById($_ac4dbc10ecf438074b2cfc89879aacb5);
            $url = $_a50cb37feb2486bcac87f47b51c37824->GetUrl();
        } else {
            $url = $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_22e88c0d92b954ab3075a" . "c36c84d7fda"];
        }
        return $url;
    }
}