<?php

/*
 * PuzzleApp
 * Webemyos
 * Jérôme Oliva
 * GNU Licence
 */

namespace Apps\DownloadManager\Widget\DownloadManagerDocumentForm;

use Core\Control\Form\Form;
use Core\View\View;
use Core\View\ElementView;

class DownloadManagerDocumentForm extends Form {

    function __construct($core = "", $data = "") {
        $this->Core = $core;
        $this->Data = $data;
        $this->Init($data);
    }

    function Init($data) {

        $this->form = new Form("DownloadManagerDocumentForm", $data);
        $this->form->SetView(__DIR__ . "/View/index.tpl", $this->Core);
        $this->form->SetAction("/View/index.tpl");

        $this->form->Add(["Type" => "Hidden", "Id" => "Id"]);

        $this->form->Add([
            "Type"       => "TextBox",
            "Id"         => "Name",
            "Validators" => ["Required"]
        ]);
       
        $this->form->Add([
            "Type" => "TextArea",
            "Id"   => "Description"
        ]);

        $this->form->Add([
            "Type"       => "EntityListBox",
            "Id"         => "CategoryId",
            "Entity"     => "Apps\\DownloadManager\\Entity\\DmCategory",
            "Values"     => ["" => "-- Choisir une catégorie --"],
            "Field"      => "Name",
        ]);

        $this->form->Add([
            "Type" => "TextBox",
            "Id"   => "FileType",
        ]);

        $this->form->Add([
            "Type" => "TextBox",
            "Id"   => "FileSize",
        ]);

        $this->form->Add([
            "Type"   => "ListBox",
            "Id"     => "Status",
            "Values" => [
                $this->Core->GetCode("DownloadManager.Active")   => 1,
                $this->Core->GetCode("DownloadManager.Inactive") => 0,
            ],
        ]);

        $this->form->Add([
            "Type"   => "Upload",
            "Id"     => "UploadDocument",
            "App"    => "DownloadManager",
            "Method" => "SaveDocumentFile",
            "Accept" => "pdf, doc, docx, zip, xls, xlsx",
        ]);

        $this->form->Add([
            "Type"   => "Upload",
            "Id"     => "UploadThumbnail",
            "App"    => "DownloadManager",
            "Method" => "SaveThumbnailFile",
        ]);

        $this->form->Add([
            "Type"     => "Button",
            "Id"       => "btnSaveDocument",
            "Value"    => $this->Core->GetCode("Save"),
            "CssClass" => "btn btn-primary"
        ]);
    }

    function Render() {
        return $this->form->Render();
    }

        /*     * *
     * Populate the entity with the form Data
     */

    function Populate($entity) {
        
    }

    function Validate($data = "") {
        return $this->form->Validate($this->Data);
    }

    function Load($entity) {
        $this->form->Load($entity);
    }
}

?>
