<?php
namespace Claromentis\Pages\UseCase;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] ?: array()) + array("_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d" => base64_decode("bG1" . "zZw" . "=="), "_490121543017a2eadd82fd67" . "7450b84d" => base64_decode("IChzaXRlI" . "CM="), "_4ff1ee8e5525f0578fe4c5768757" . "1274" => base64_decode("KSB3YXM" . "gcmVwb3" . "NpdGlvb" . "mVk"), "_061bb9e394136ed8" . "9ff46ed817b65bcf" => base64_decode("aW5oZXJpd" . "GVk"), "_3f05c7e033d5fa5883b27e9248e3ab" . "53" => base64_decode("cG" . "Fn" . "ZX" . "M="), "_9468bcca52266e7b5b790ff" . "2da0228de" => base64_decode("bWVud" . "Q=="), "_d08c05c40f92aa613c70db35b3aa" . "5173" => base64_decode("TWVudSBpdG" . "VtIA=="), "_476d68da" . "eb2c1641d" . "23c48b2df" . "79af28" => base64_decode("cGFnZXMubWVudS5ub19tb" . "3ZlX3JpZ2h0cw=="));
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["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_0c5123aa744" . "f69bbc0e8b3e" . "a2f6e847d"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_476d68da" . "eb2c1641d" . "23c48b2df" . "79af28"]));
        }
        
        
        $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"]["_061bb9e394136ed89" . "ff46ed817b65bcf"])) {
                $_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["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_3f05c7e033d5fa5883b27e924" . "8e3ab53"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_9468bcca52266e7b5b790ff2da0" . "228de"], $_d43c6db6d25c2749f65bc7bc28bd8df3->id, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_d08c05c40f92aa61" . "3c70db35b3aa5173"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->title . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_49012154301" . "7a2eadd82fd6" . "77450b84d"] . $_d43c6db6d25c2749f65bc7bc28bd8df3->site_id . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4ff1ee8e5525f057" . "8fe4c57687571274"]);
    }
}