<?php


namespace App\AdminModule\Presenters;


use App\Components\Sidebar\SidebarMenu\SidebarMenu;
use App\Model\Entities\PortalSite;
use App\Model\Exceptions\Db\RecordNotFoundException;
use App\Model\Facades\SiteFacade;
use App\Presenters\BasePresenter;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Nette\Http\IResponse;
use Tracy\Debugger;

abstract class AdminBasePresenter extends BasePresenter
{
    /** @var  SiteFacade */
    protected $siteFacade;
    /** @var  PortalSite */
    protected $site;    // permission resource

    public function injectAdminBase(SiteFacade $siteFacade)
    {
        $this->siteFacade = $siteFacade;
    }

    protected function startup()
    {
        parent::startup();

        try {
            $this->site = $this->siteFacade->getSiteReader()->findPortalSite();
        } catch (RecordNotFoundException $e) {
            $this->error('Default data are not set.', IResponse::S404_NOT_FOUND);
        } catch (TableNotFoundException $e) {
            // db not set
        }

    }

    /**
     * @return SidebarMenu
     */
    protected function createComponentSidebarMenu()
    {
        $menu = new SidebarMenu();
//        $menu->addHeader('header', 'HEADER');
        $menu->addLink('home', 'Usage statistics', 'Homepage:')->addFaIcon('home');

        $localization = $menu->addLinkGroup('localization', 'Localization');
        $localization->addFaIcon('globe');
        $localization->addLink('languages', 'Languages', 'Localization:languages');
        $localization->addLink('translations', 'Translations', 'Localization:translations');

        $gameManagement = $menu->addLinkGroup('gameManagement', 'Game management');
        $gameManagement->addFaIcon('gamepad');
        $gameManagement->addLink('games', 'Games', 'Game:list');
//        $gameManagement->addLink('platforms', 'Platforms', 'Game:platforms');
        $gameManagement->addLink('publishers', 'Publishers', 'Game:publishers');
        $gameManagement->addLink('studios', 'Studios', 'Game:studios');

        return $menu;
    }
}