<?php

namespace LivraisonParSecteurs\Hook;

use LivraisonParSecteurs\LivraisonParSecteurs;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\SecurityContext;

/**
 * Class AdminHook
 */
class AdminHook extends BaseHook
{
    protected $securityContext;

    public function __construct(SecurityContext $securityContext)
    {
        $this->securityContext = $securityContext;
    }

    public function onModuleConfig(HookRenderEvent $event)
    {
        $isGranted = $this->securityContext->isGranted(
            ["ADMIN"],
            [],
            [LivraisonParSecteurs::getModuleCode()],
            [AccessManager::VIEW]
        );

        if ($isGranted) {
            $event->add($this->render("deliveryarea-list.html", $event->getArguments()));
        }
    }

}
