<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"] ?: array()) + array("_0c5123aa744f69bbc0e8b3ea2f" . "6e847d" => base64_decode("bG1" . "zZw" . "=="), "_9468bcca52266e7b5b" . "790ff2da0228de" => base64_decode("bWVud" . "Q=="), "_d08c05c40f92aa613" . "c70db35b3aa5173" => base64_decode("TWVudSBpdGVt" . "IA=="), "_490121543017a" . "2eadd82fd67745" . "0b84d" => base64_decode("IChzaXRlICM" . "="), "_4ff1ee8e5525f0578fe4c5768757127" . "4" => base64_decode("KSB3YXMgcmVwb3Np" . "dGlvbmVk"), "_3f05c7e033d5" . "fa5883b27e924" . "8e3ab53" => base64_decode("cGF" . "nZX" . "M="), "_476d68daeb2c1641d23c48b2df79a" . "f28" => base64_decode("cGFnZXMubWVudS5ub19tb3ZlX" . "3JpZ2h0cw=="), "_061bb9e394136e" . "d89ff46ed817b65" . "bcf" => base64_decode("aW5oZ" . "XJpdG" . "Vk"));
use Claromentis\Core\Acl\Operations;
use Claromentis\Core\Audit\Audit;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Pages\Exception\AccessDeniedException;
use Claromentis\Pages\Facade\ChangePageUrl;
use Claromentis\Pages\PagesAcl;
use Claromentis\Pages\Repository\MenuItemRepository;
use Claromentis\Pages\Repository\PagesRepository;
use Claromentis\Pages\Repository\UrlRepository;




class MenuItemMoved
{
    protected $acl;
    protected $menu_item_repository;
    protected $url_repository;
    protected $change_page_url;
    protected $pages_repo;
    protected $children_perms;
    protected Audit $audit;
    public function __construct(PagesAcl $acl, MenuItemRepository $_10aca790e0352d5c4b5c3bbaa9c9a43e, UrlRepository $_0ffc8e5433da0b1c27f79e871fb130bc, ChangePageUrl $_a934a06b0fef4520ac64197f25eae4b0, PagesRepository $pages_repo, UpdateChildrenPermissions $_8f0423d13feb70826d98d5aaf616b9a4, Audit $audit)
    {
        $this->acl = $acl;
        $this->menu_item_repository = $_10aca790e0352d5c4b5c3bbaa9c9a43e;
        $this->url_repository = $_0ffc8e5433da0b1c27f79e871fb130bc;
        $this->change_page_url = $_a934a06b0fef4520ac64197f25eae4b0;
        $this->pages_repo = $pages_repo;
        $this->children_perms = $_8f0423d13feb70826d98d5aaf616b9a4;
        $this->audit = $audit;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function Move(SecurityContext $context, $_a1053c2fc8090400c07497f8420a3587, $_6e38cb9e043a07cd69a1711a6704c62a, $_5f0544f6574b4b4f08a4496c49353826)
    {
        $_d43c6db6d25c2749f65bc7bc28bd8df3 = $this->menu_item_repository->GetById($_a1053c2fc8090400c07497f8420a3587);
        $_7b1c953dc85a8c7efa87840f5d59ef15 = $this->menu_item_repository->GetById($_6e38cb9e043a07cd69a1711a6704c62a);
        $_e0909ca198ece23ebf0445fe2c1fd80c = $this->url_repository->GetById($_7b1c953dc85a8c7efa87840f5d59ef15->url_id);
        if (!$this->acl->CanMoveChildMenuItems($context, $_e0909ca198ece23ebf0445fe2c1fd80c->active_page_id)) {
            throw new AccessDeniedException($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_0c5123aa744f69bbc" . "0e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_476d68daeb2c1641d" . "23c48b2df79af28"]));
        }
        
        
        $this->menu_item_repository->Move($_d43c6db6d25c2749f65bc7bc28bd8df3, $_6e38cb9e043a07cd69a1711a6704c62a, $_5f0544f6574b4b4f08a4496c49353826);
        if ($_d43c6db6d25c2749f65bc7bc28bd8df3->url_id > 0) {
            
            
            $url = $this->url_repository->GetById($_d43c6db6d25c2749f65bc7bc28bd8df3->url_id);
            $this->change_page_url->ChangeParentUrl($url, $_e0909ca198ece23ebf0445fe2c1fd80c);
            
            
            $_221da17e3055fae8d3ff516b832a5f3b = $this->pages_repo->GetById($url->latest_page_id);
            $_2646d6fbf5913a7d1b6a0870252e257a = $this->pages_repo->GetLatestPageIdForMenuItem($_6e38cb9e043a07cd69a1711a6704c62a);
            $_df60df7baa4a9fd765bc41a011958f94 = $this->acl->GetPageAcl($_221da17e3055fae8d3ff516b832a5f3b->id);
            $_3a6f27fdff0c41d95f14a7f3fb4d06fb = $this->acl->GetPageAcl($_2646d6fbf5913a7d1b6a0870252e257a);
            if (!$_221da17e3055fae8d3ff516b832a5f3b->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_061bb9e394136" . "ed89ff46ed817b" . "65bcf"])) {
                $_96ef573f98c400e15b4086769cccd197 = new Operations();
                $_96ef573f98c400e15b4086769cccd197->Restrict($_df60df7baa4a9fd765bc41a011958f94, $_3a6f27fdff0c41d95f14a7f3fb4d06fb);
                $this->acl->SetPageAcl($_221da17e3055fae8d3ff516b832a5f3b->id, $_df60df7baa4a9fd765bc41a011958f94);
            } else {
                $this->acl->InheritFromParent($_221da17e3055fae8d3ff516b832a5f3b->id, $_2646d6fbf5913a7d1b6a0870252e257a);
            }
            $this->children_perms->Update($_221da17e3055fae8d3ff516b832a5f3b->id);
        }
        $this->audit->success($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_3f05c7e033d5fa5883b27e9248e3ab5" . "3"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_9468bcca52266e7b5b790" . "ff2da0228de"], $_d43c6db6d25c2749f65bc7bc28bd8df3->id, $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_d08c05c40f92" . "aa613c70db35b" . "3aa5173"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_490121543017a2eadd82fd677450b" . "84d"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id . $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_4ff1ee8e5525f0578fe" . "4c57687571274"]);
    }
}