<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] ?: array()) + array("_c6e0d99bc8661906976eb" . "246e146757c" => base64_decode("T3B0aW9ucyBtZW51IG5vdCBsb2FkZWQuIFBsZWFzZSB3YWl0IGZvciB" . "0aGUgcGFnZSB0byBsb2Fk"), "_7681c2a2b7e1bdf69c23c6cd6411" . "4ad3" => base64_decode("anNvbl9" . "kZWNvZG" . "U="), "_96be32a6f44bf54e" . "635e1736acf7a96c" => base64_decode("c2VyaWFsaXp" . "l"), "_8dc0592537dc5fb48873bb" . "782fa6feb1" => base64_decode("ZGVmYXV" . "sdA=="), "_50e4b8284a9211710fcf2bd34f53" . "eeb3" => base64_decode("R1BDIEVy" . "cm9y"), "_daa515038e26b00079981dc6" . "1ccb22f9" => base64_decode("c3l" . "tbm" . "FtZ" . "Q=="), "_54436074ae" . "265f81462e2" . "8f52f8962b7" => base64_decode("X2N1c" . "3RvbV" . "9f"), "_7f628626dd" . "1d55c71b1fc" . "0932ffd1d2c" => base64_decode("aXNfYX" . "JyYXk="));
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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_96be32a6f44bf54e635e1736" . "acf7a96c"]($_8dd62279a981b9051240125b1b6fbc70);
        $component->html = $_decf18bb747cbba55f12f65abcc00797;
        $component->css = $_48d41111fac15f40b9dcad36482b5b9b;
        $component->js = $_a9f1a5b5b3ed5cca5dfde1821c673037;
        
        
        $options = $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_7681c2a2b7e1bdf6" . "9c23c6cd64114ad3"]($options);
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_7f628626dd1d55c71b1fc0932ffd1" . "d2c"]($options)) {
            throw new InvalidObjectStateException($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_c6e0d99bc8661906976eb" . "246e146757c"]);
        }
        $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["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_daa515038e26b00079981dc61ccb22" . "f9"]) {
                    continue;
                }
                
                
                if ($_9b0ea340144ed317311382ed6e881e9a === $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8dc0592537dc5fb" . "48873bb782fa6feb" . "1"]) {
                    $_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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_50e4b8284" . "a9211710fc" . "f2bd34f53e" . "eb3"]);
        }
        $component->Validate();
        $this->repository->deleteExistingOptions($component->id);
        $this->repository->save($component);
        
        
        if ($_4d7321870b14b5d27d3d9e723653b5c2 !== $_daa515038e26b00079981dc61ccb22f9) {
            $this->tile_provider->UpdateComponentSymname($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_54436074ae265f" . "81462e28f52f896" . "2b7"] . $_4d7321870b14b5d27d3d9e723653b5c2, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_54436074ae265f8146" . "2e28f52f8962b7"] . $_daa515038e26b00079981dc61ccb22f9);
        }
        
        
        return true;
    }
}