<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"] = (@$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] ?: array()) + array("_50e4b8284a9211710fcf2bd34" . "f53eeb3" => base64_decode("R1BDIEV" . "ycm9y"), "_54436074ae265f" . "81462e28f52f896" . "2b7" => base64_decode("X2N1c3" . "RvbV9f"), "_7f628626dd1d55c" . "71b1fc0932ffd1d2" . "c" => base64_decode("aXNfY" . "XJyYX" . "k="), "_8dc0592537dc5fb48873bb782fa6f" . "eb1" => base64_decode("ZGVmYXVsdA=" . "="), "_96be32a6" . "f44bf54e6" . "35e1736ac" . "f7a96c" => base64_decode("c2VyaWFsa" . "Xpl"), "_daa515038e26b00079981" . "dc61ccb22f9" => base64_decode("c3lt" . "bmFt" . "ZQ=="), "_7681c2a2b7e1bdf69c23c6cd6411" . "4ad3" => base64_decode("anNvbl9k" . "ZWNvZGU="), "_c6e0d99bc8661906" . "976eb246e146757c" => base64_decode("T3B0aW9ucyBtZW51IG5vdCBsb2FkZWQuIFBsZWFzZSB3YWl0IGZvciB0aGUgcGFnZ" . "SB0byBsb2Fk"));
use Analogue\ORM\EntityCollection;
use Claromentis\Core\Component\ValueType\ValueTypeFactory;
use Claromentis\Pages\Exception\InvalidObjectStateException;
use Claromentis\Pages\Model\CustomComponent;
use Claromentis\Pages\Model\CustomComponentField;
use Claromentis\Pages\Model\CustomComponentKey;
use Claromentis\Pages\Repository\CustomComponentRepository;
use Claromentis\Pages\Repository\TileProvider;
class SaveCustomComponent extends \ErrorHandler
{
    
    
    protected $repository;
    
    
    protected $tile_provider;
    public function __construct(CustomComponentRepository $_8652ba33e6ffeba02459fa9cbb320851, TileProvider $tile_provider)
    {
        $this->repository = $_8652ba33e6ffeba02459fa9cbb320851;
        $this->tile_provider = $tile_provider;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Save(CustomComponent &$component, $_daa515038e26b00079981dc61ccb22f9, $name, $_28fd57f750dbb5ffb3ffad3a888358a9, $_d43b1a885195a4b6ccc7d38ba3fcb1f9, $_8dd62279a981b9051240125b1b6fbc70, $options, $_decf18bb747cbba55f12f65abcc00797, $_48d41111fac15f40b9dcad36482b5b9b, $_a9f1a5b5b3ed5cca5dfde1821c673037, $_c34332af832a8a853954cc8a2b59cf7a)
    {
        $_4d7321870b14b5d27d3d9e723653b5c2 = $component->symname;
        
        
        $component->name = $name;
        $component->symname = $_daa515038e26b00079981dc61ccb22f9;
        $component->description = $_28fd57f750dbb5ffb3ffad3a888358a9;
        $component->glyphicon = $_d43b1a885195a4b6ccc7d38ba3fcb1f9;
        $component->size_constraints = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_96be32a6f44bf54e635e1736a" . "cf7a96c"]($_8dd62279a981b9051240125b1b6fbc70);
        $component->html = $_decf18bb747cbba55f12f65abcc00797;
        $component->css = $_48d41111fac15f40b9dcad36482b5b9b;
        $component->js = $_a9f1a5b5b3ed5cca5dfde1821c673037;
        
        
        $options = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_7681c2a2" . "b7e1bdf69" . "c23c6cd64" . "114ad3"]($options);
        if (!$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_7f628626dd1d55c71b1fc0932ff" . "d1d2c"]($options)) {
            throw new InvalidObjectStateException($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_c6e0d99bc8661" . "906976eb246e14" . "6757c"]);
        }
        $component->fields = new EntityCollection();
        $_068ab9b9340314c5b07e3e5cc31d925b = 1;
        foreach ($options as $_ab3f4d20f08bd694b2839e5c36c149a2) {
            $_13d133c615714d50832f54e91fea8fb0 = new CustomComponentField();
            $_13d133c615714d50832f54e91fea8fb0->option_field = $_ab3f4d20f08bd694b2839e5c36c149a2->symname;
            $_13d133c615714d50832f54e91fea8fb0->sort_order = $_068ab9b9340314c5b07e3e5cc31d925b;
            $_13d133c615714d50832f54e91fea8fb0->keys = new EntityCollection();
            foreach ($_ab3f4d20f08bd694b2839e5c36c149a2 as $_9b0ea340144ed317311382ed6e881e9a => $_a7217e247f981bdc28a20320b6a8b3cb) {
                if ($_9b0ea340144ed317311382ed6e881e9a === $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_daa515038e26b00079" . "981dc61ccb22f9"]) {
                    continue;
                }
                
                
                if ($_9b0ea340144ed317311382ed6e881e9a === $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8dc0592537dc5fb48873" . "bb782fa6feb1"]) {
                    $_dadf790baf241afac942824c1e6e37c4 = ValueTypeFactory::Create((array) $_ab3f4d20f08bd694b2839e5c36c149a2);
                    $_a7217e247f981bdc28a20320b6a8b3cb = $_dadf790baf241afac942824c1e6e37c4->Serialize($_a7217e247f981bdc28a20320b6a8b3cb);
                }
                $_cbc91abf342819eec93ad5eca696836a = new CustomComponentKey();
                $_cbc91abf342819eec93ad5eca696836a->option_key = $_9b0ea340144ed317311382ed6e881e9a;
                $_cbc91abf342819eec93ad5eca696836a->option_value = $_a7217e247f981bdc28a20320b6a8b3cb;
                $_13d133c615714d50832f54e91fea8fb0->keys->add($_cbc91abf342819eec93ad5eca696836a);
            }
            $component->fields->add($_13d133c615714d50832f54e91fea8fb0);
            $_068ab9b9340314c5b07e3e5cc31d925b++;
        }
        if ($_c34332af832a8a853954cc8a2b59cf7a) {
            throw new InvalidObjectStateException($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_50e4b8284a9211710fcf2bd34f53ee" . "b3"]);
        }
        $component->Validate();
        $this->repository->deleteExistingOptions($component->id);
        $this->repository->save($component);
        
        
        if ($_4d7321870b14b5d27d3d9e723653b5c2 !== $_daa515038e26b00079981dc61ccb22f9) {
            $this->tile_provider->UpdateComponentSymname($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_54436074ae26" . "5f81462e28f52" . "f8962b7"] . $_4d7321870b14b5d27d3d9e723653b5c2, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_54436074ae265f81462e" . "28f52f8962b7"] . $_daa515038e26b00079981dc61ccb22f9);
        }
        
        
        return true;
    }
}