<?php
namespace Claromentis\Menu\Infobar;

$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] ?: array()) + array("_c133e115f1ce8e" . "d7b5a6bced4c874" . "862" => base64_decode("YXJyYXlfcG" . "9w"), "_31767d7ad58e706dbf47b7a51" . "a0fe6c4" => base64_decode("Y291" . "bnQ="), "_822680520327e9387ae2d5c065ea5" . "2e1" => base64_decode("YXJyYXlfZmxp" . "cA=="), "_49c6565477ee9f822b499a5" . "3e6d2995f" => base64_decode("YXJyYXlfa2V5X2V4aXN0cw" . "=="), "_d706c160e" . "45bf7434ff" . "f82a5976f0" . "e19" => base64_decode("YXJyYXlfa2V5cw" . "=="));
use Claromentis\Core\Acl\AclRepository;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Menu\Exception\MenuItemForbiddenException;
use Claromentis\Menu\Exception\MenuItemNotFoundException;
use Claromentis\Menu\Exception\MenuItemValidationException;
use Claromentis\Menu\Exception\MenuItemRepositoryException;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;






class ApplicationsListItems
{
    use LoggerAwareTrait;
    private AclRepository $aclRepository;
    private MenuItemFactory $menuItemFactory;
    private MenuItemRepository $repository;
    private array $cachedDisplayableItems = [];
    public function __construct(MenuItemRepository $_9cc4826fc470a6d42bd40c876b9a30bd, MenuItemFactory $menuItemFactory, AclRepository $aclRepository, LoggerInterface $logger)
    {
        $this->repository = $_9cc4826fc470a6d42bd40c876b9a30bd;
        $this->menuItemFactory = $menuItemFactory;
        $this->aclRepository = $aclRepository;
        $this->setLogger($logger);
    }
    
    
    
    
    
    
    
    
    public function canView(array $_9cee5807b5bab08d25cd4213e63cb764, SecurityContext $context) : bool
    {
        $_efbacf3fcde43c382e36d399f1cd12f0 = $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_822680520327e9387ae2d5c065ea5" . "2e1"]($this->repository->getViewableIds($context));
        foreach ($_9cee5807b5bab08d25cd4213e63cb764 as $id) {
            if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_49c6565477ee9f822b499a" . "53e6d2995f"]($id, $_efbacf3fcde43c382e36d399f1cd12f0)) {
                return false;
            }
        }
        return true;
    }
    
    
    
    
    
    
    
    
    
    public function hasApplication(string $_2d58a9232beb5db16f3d8b9aa1d58c71) : bool
    {
        $_38dc3c4573d1bf70268680af788c25d2 = null;
        try {
            $_38dc3c4573d1bf70268680af788c25d2 = $this->repository->get(null, null, [ItemType::APPLICATION], [$_2d58a9232beb5db16f3d8b9aa1d58c71]);
        } catch (\Throwable $throwable) {
            
            
            
        }
        return !empty($_38dc3c4573d1bf70268680af788c25d2);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function getApplication(string $_2d58a9232beb5db16f3d8b9aa1d58c71, ?SecurityContext $context = null) : MenuItemApplication
    {
        
        
        $_1233ecb7129e4ebf7bca209fc4ca2d77 = $this->repository->get(null, null, [ItemType::APPLICATION], [$_2d58a9232beb5db16f3d8b9aa1d58c71]);
        if (empty($_1233ecb7129e4ebf7bca209fc4ca2d77)) {
            throw MenuItemNotFoundException::appIdNotFound($_2d58a9232beb5db16f3d8b9aa1d58c71);
        }
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_31767d7ad58e" . "706dbf47b7a51" . "a0fe6c4"]($_1233ecb7129e4ebf7bca209fc4ca2d77) > 1) {
            throw MenuItemValidationException::appIdNotUnique($_2d58a9232beb5db16f3d8b9aa1d58c71);
        }
        if ($context && !$this->canView($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_d706c160e45bf7434fff82a5976f" . "0e19"]($_1233ecb7129e4ebf7bca209fc4ca2d77), $context)) {
            throw MenuItemForbiddenException::forbiddenId($_2d58a9232beb5db16f3d8b9aa1d58c71);
        }
        return $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c133e115f1ce8ed" . "7b5a6bced4c87486" . "2"]($_1233ecb7129e4ebf7bca209fc4ca2d77);
    }
    
    
    
    
    
    
    
    
    public function getItem(int $id, SecurityContext $context) : MenuItemInterface
    {
        $_38dc3c4573d1bf70268680af788c25d2 = $this->repository->get([$id]);
        if (!isset($_c5ca63e2f3cceb505a5417b4abb64d55[$id])) {
            throw MenuItemNotFoundException::idNotFound($id);
        }
        $_c5ca63e2f3cceb505a5417b4abb64d55 = $_38dc3c4573d1bf70268680af788c25d2[$id];
        if (!$this->canView([$_c5ca63e2f3cceb505a5417b4abb64d55->getId()], $context)) {
            throw MenuItemForbiddenException::forbiddenId($id);
        }
        return $_c5ca63e2f3cceb505a5417b4abb64d55;
    }
    
    
    
    
    
    
    
    
    public function getDisplayableItems(SecurityContext $context) : array
    {
        $_65976ee34559dcb12bd6d5db68edf074 = $context->GetUserId();
        if (!isset($this->cachedDisplayableItems[$_65976ee34559dcb12bd6d5db68edf074])) {
            $_38dc3c4573d1bf70268680af788c25d2 = $this->repository->get(null, [InfobarMenuType::APPLICATIONS], null, null, $context);
            foreach ($_38dc3c4573d1bf70268680af788c25d2 as $_1f50e30be8c2fefa6881834e71d504a2 => $_c5ca63e2f3cceb505a5417b4abb64d55) {
                if ($_c5ca63e2f3cceb505a5417b4abb64d55 instanceof MenuItemLinkInterface && $_c5ca63e2f3cceb505a5417b4abb64d55->getDisabled()) {
                    unset($_38dc3c4573d1bf70268680af788c25d2[$_1f50e30be8c2fefa6881834e71d504a2]);
                }
            }
            $this->cachedDisplayableItems[$_65976ee34559dcb12bd6d5db68edf074] = $_38dc3c4573d1bf70268680af788c25d2;
        }
        return $this->cachedDisplayableItems[$_65976ee34559dcb12bd6d5db68edf074];
    }
    public function getAdminItems(array $_94bb23a8efc6e7795b00b21626283af1) : array
    {
        return $this->repository->get(null, $_94bb23a8efc6e7795b00b21626283af1);
    }
    
    
    
    
    
    
    public function getAdminItem(int $id) : MenuItemInterface
    {
        $_38dc3c4573d1bf70268680af788c25d2 = $this->repository->get([$id]);
        if (!isset($_38dc3c4573d1bf70268680af788c25d2[$id])) {
            throw MenuItemNotFoundException::idNotFound($id);
        }
        return $_38dc3c4573d1bf70268680af788c25d2[$id];
    }
    
    
    
    
    
    public function getLinks(SecurityContext $context) : array
    {
        return $this->repository->get(null, [InfobarMenuType::APPLICATIONS], [ItemType::APPLICATION, ItemType::LINK], null, $context);
    }
    
    
    
    
    
    
    
    
    
    
    
    public function saveNewDivider(int $menu) : MenuItemDivider
    {
        $_954f14aba204c4076de6dae38c5624c5 = $this->menuItemFactory->createDivider($menu, null, $this->repository->getMaxOrder($menu));
        $this->save($_954f14aba204c4076de6dae38c5624c5);
        return $_954f14aba204c4076de6dae38c5624c5;
    }
    
    
    
    
    
    
    
    
    
    
    public function save(MenuItemInterface $_c5ca63e2f3cceb505a5417b4abb64d55) : void
    {
        $this->repository->save($_c5ca63e2f3cceb505a5417b4abb64d55);
    }
}