<?php

namespace App\FrontModule\Presenters;

use App\Model\Enums\FlashMessage;
use App\Model\Exceptions\Db\RecordNotFoundException;
use Nette;
use Nette\Application\AbortException;


class HomepagePresenter extends FrontBasePresenter
{
    protected $publicAccess = true;

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

        try {
            $homepage = $this->siteFacade->getNavigationReader()->findHomepage($this->site);
            $this->redirect($homepage->getLinkDestination(), $homepage->getLinkParams());
        } catch (RecordNotFoundException $e) {
            $this->flashMessage('Homepage is not set.', FlashMessage::WARNING);
        } catch (AbortException $e) {
            throw $e;   //redirect
        }

        $this->pageHeader = 'Homepage not set';
    }


}
