<?php


namespace App\Components\Forms;


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

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

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

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

    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('name', 'Name')->setRequired();
        $form->addDatetimePicker('start', 'Start')->setRequired();
        $form->addDatetimePicker('end', 'End');
        $form->addText('limit', 'Limit');
        $form->addSelect('template', 'Access rights', $this->siteFacade->getTemplateReader()->getEventSelectBoxPairs($this->site))->setRequired();
        $form->addTextArea('description', 'Description');

        return $form;
    }

}