<?php


namespace App\Components\Forms;


use App\Model\Facades\SiteFacade;
use App\Model\Interfaces\ISite;
use App\Model\Translator;

abstract class NavItemForm extends BaseForm
{
    public $onSave;
    public $onError;

    /** @var  ISite */
    protected $site;
    /** @var SiteFacade */
    protected $siteFacade;

    public function __construct(Translator $translator, SiteFacade $siteFacade)
    {
        parent::__construct($translator);
        $this->siteFacade = $siteFacade;
    }

    public function setSite($site)
    {
        $this->site = $this->siteFacade->getSiteReader()->validateSite($site);
    }

    protected function setupForm() : BootstrapForm
    {
        $form = parent::setupForm();
        $form->addText('title', 'Title')->setRequired();
        $form->addText('navTitle', 'Navigation title')->setRequired();
        $form->addSelect('icon', 'Icon', $this->selectBoxIcons())
            ->setAttribute('class', ['select2-icons'])
            ->setTranslator(null);
        $form->addSelect('template', 'Access', $this->getTemplates())
            ->setRequired();

        return $form;
    }

    protected abstract function getTemplates() : array;

    protected function selectBoxIcons()
    {
        return [
            'circle-thin' => 'circle',
            'calendar' => 'calendar',
            'picture-o' => 'picture',
            'newspaper-o' => 'newspaper',
            'comments' => 'comments',
            'comment' => 'comment',
            'gamepad' => 'gamepad',
            'crosshairs' => 'crosshairs',
            'bolt' => 'bolt',
            'bookmark' => 'bookmark',
            'group' => 'group',
            'beer' => 'beer'
        ];
    }
}