<?php


namespace App\Components\Forms;


use App\Model\Translator;
use App\Model\Uploader;
use Zet\FileUpload\FileUploadControl;

abstract class JQueryUploaderForm extends BaseForm
{
    /** @var Uploader */
    protected $uploader;

    protected static $filter = FileUploadControl::FILTER_IMAGES;
    protected static $submitCaption = 'Done';
    protected static $templateName = 'jQueryUploader.latte';

    public $onSave;
    public $onError;

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

    protected function setupForm() : BootstrapForm
    {
        $form =  parent::setupForm();
        $form->addFileUpload("uploader")->setFileFilter(static::$filter);
        $form->addSubmit('submit', static::$submitCaption);

        return $form;
    }

    /**
     * @return BootstrapForm
     */
    protected final function createComponentForm() : BootstrapForm
    {
        return $this->setupForm();
    }
}