<?php
namespace Claromentis\Design\Controller;

$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"] ?: array()) + array("_1d785f3719d3e17aa1fa66" . "543cdad7a8" => base64_decode("ZGVzaWduL2FkbWluL2Rlc2lnbi5" . "odG1s"), "_4d707fab" . "93bebb00b" . "be69e8159" . "697c90" => base64_decode(""), "_0c5123aa744" . "f69bbc0e8b3e" . "a2f6e847d" => base64_decode("bG1zZ" . "w=="), "_8df4fa2d5c8d8c2e6d" . "e4577a36506bb1" => base64_decode("aXNfZXJyb" . "3JfbWVzc2" . "FnZQ=="), "_d1d997d6b7fd" . "c02cc83b4b996" . "482c63a" => base64_decode("M" . "A" . "=" . "="), "_31767d7ad58e706dbf47b7a51a" . "0fe6c4" => base64_decode("Y29" . "1bn" . "Q="), "_902d544c7" . "022c3ffc6d" . "bf5f6624ab" . "476" => base64_decode("ZGVzaWduLmN1c3RvbWl" . "6YXRpb24ucGFnZV90aX" . "RsZQ=="), "_42dfd69ddb8f231de5" . "a03ef8c6445564" => base64_decode("aXNfbWFzdG" . "Vy"), "_e1c171f83" . "013d274f6d" . "1b6310186c" . "93e" => base64_decode("bWFzdGVyX2VkaXRfd2" . "FybmluZy52aXNpYmxl"), "_7cdca53cdfce163" . "c0734ccbfdcc55bc" . "2" => base64_decode("aG9tZV9sYXlvdXQ" . "="), "_aba0c73" . "535f3743" . "41b36b30" . "1c69d583" . "3" => base64_decode("WC1YU1" . "MtUHJv" . "dGVjdG" . "lvbg=="), "_e05e0022" . "a2e5ad344" . "b9c4a0d3f" . "64e1a5" => base64_decode("bWVzc2FnZQ" . "=="));
use Claromentis\Core\Http\gpc;
use Claromentis\Core\Http\TemplaterCallResponse;
use Claromentis\Design\Exception\StyleDialogException;
use Claromentis\Design\Repository\GlobalStyleStorage;
use Claromentis\Design\Repository\LayoutsProvider;
use Claromentis\Design\Repository\ThemeRepository;
use Claromentis\Design\Style\InheritableStyle;
use Claromentis\Design\Style\Option;
use Claromentis\Design\Style\StyleOptionsEditable;
use Claromentis\Design\View\LayoutSelect;
use Claromentis\Design\View\StyleDialog;
use Claromentis\Menu\MenuRepository;
use Psr\Http\Message\ServerRequestInterface;




class AdminDesignController
{
    
    
    
    
    
    
    protected $result;
    
    
    
    
    protected $global_style;
    
    
    
    
    protected $style_dialog;
    
    
    
    
    protected $layouts;
    
    
    
    
    protected $menu_repository;
    
    
    
    
    protected $storage;
    
    
    protected $theme_repo;
    protected $message;
    protected $is_error_message;
    
    
    
    
    
    
    
    
    
    
    
    public function __construct(InheritableStyle $global_style, StyleDialog $style_dialog, LayoutsProvider $layouts, MenuRepository $menu_repository, GlobalStyleStorage $storage, ThemeRepository $theme_repo)
    {
        $this->result = [];
        $this->global_style = $global_style;
        $this->style_dialog = $style_dialog;
        $this->layouts = $layouts;
        $this->menu_repository = $menu_repository;
        $this->storage = $storage;
        $this->theme_repo = $theme_repo;
    }
    
    
    
    
    
    
    public function OnShow()
    {
        
        
        $options = $this->global_style;
        $_852c74516beb573b14f5d099fd5c7980 = $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_31767d7ad58e7" . "06dbf47b7a51a0" . "fe6c4"]($this->theme_repo->GetThemes());
        $args = [];
        $args[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_42dfd69ddb8" . "f231de5a03ef" . "8c6445564"]] = 1;
        
        
        $args[$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_e1c171f83013d274f6d1b6310" . "186c93e"]] = $_852c74516beb573b14f5d099fd5c7980 > 0 ? 1 : 0;
        $dialog = $this->style_dialog;
        $dialog->Show($options, $args);
        $_a96218ce0c4fc65335887d2e5f59ed2b = new LayoutSelect($this->global_style);
        $_a96218ce0c4fc65335887d2e5f59ed2b->Show($this->layouts, $options->Get(Option::HOME_LAYOUT), $args);
        $_e05e0022a2e5ad344b9c4a0d3f64e1a5 = $this->result[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_e05e0022a2e5ad344b9c4a0d3f" . "64e1a5"]] ?? $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4d707fab9" . "3bebb00bbe" . "69e8159697" . "c90"];
        $_8df4fa2d5c8d8c2e6de4577a36506bb1 = $this->result[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_8df4fa2d5c8d" . "8c2e6de4577a3" . "6506bb1"]] ?? 0;
        $_fd5a3a643834299cbdadfc3540ba0bcb = new TemplaterCallResponse($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_1d785f3719d3e17aa1fa66543" . "cdad7a8"], $args, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0c5123aa744" . "f69bbc0e8b3e" . "a2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_902d544c7" . "022c3ffc6d" . "bf5f6624ab" . "476"]));
        if (isset($this->message)) {
            $_fd5a3a643834299cbdadfc3540ba0bcb->SetMessage($this->message, $this->is_error_message);
        }
        $_fd5a3a643834299cbdadfc3540ba0bcb->SetMessage($_e05e0022a2e5ad344b9c4a0d3f64e1a5, $_8df4fa2d5c8d8c2e6de4577a36506bb1);
        $_fd5a3a643834299cbdadfc3540ba0bcb->http_headers[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_aba0c73535f374341b36b301c69d5" . "833"]] = $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_d1d997d6b7fdc02cc83b4" . "b996482c63a"];
        return $_fd5a3a643834299cbdadfc3540ba0bcb;
    }
    
    
    
    
    
    
    
    
    public function OnSubmit(ServerRequestInterface $request)
    {
        if (!gpc::IsSubmit($request)) {
            return $this->OnShow();
        }
        $storage = $this->storage;
        $_ec5506f22f4380697838f5559d75d370 = $this->global_style;
        $dialog = $this->style_dialog;
        try {
            $this->result = $dialog->Update($request, $_ec5506f22f4380697838f5559d75d370);
            if (isset($request->getParsedBody()[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_7cdca53cdfce16" . "3c0734ccbfdcc55" . "bc2"]])) {
                $_10445cd0658e5be199bc9eb15a44fd5c = gpc::get($request, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_7cdca53cdfce16" . "3c0734ccbfdcc55" . "bc2"], $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_4d707fab93bebb00bbe69e8159697c9" . "0"]);
                $_ec5506f22f4380697838f5559d75d370->Set(Option::HOME_LAYOUT, $_10445cd0658e5be199bc9eb15a44fd5c !== $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_4d707fab93be" . "bb00bbe69e815" . "9697c90"] ? (int) $_10445cd0658e5be199bc9eb15a44fd5c : null);
            }
            $storage->SaveStyle($_ec5506f22f4380697838f5559d75d370);
        } catch (StyleDialogException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->message = $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage();
            $this->is_error_message = 1;
        }
        return $this->OnShow();
    }
}