<?php

namespace ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Pages;

use \ModulesGarden\HostingQuotaNotifications\Core\UI\Interfaces\AdminArea;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\DataTable\DataTable;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\DataTable\Column;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\DataTable\DataProviders\DataProvider;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
use \ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Providers\TicketTemplatesProvider;
use \ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Buttons\EditTicketTemplateButton;
use \ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Buttons\AddTicketTemplateButton;
use \ModulesGarden\HostingQuotaNotifications\Core\Helper\BuildUrl;
use \ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Buttons\DeleteTicketTemplateButton;
use \ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Buttons\MassDeleteButton;
/**
 * Description of TicketTemplates
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class TicketTemplates extends DataTable implements AdminArea
{
    protected $id    = 'ticketTemplates';
    protected $name  = 'ticketTemplates';


    public function __construct($baseId = null)
    {
        parent::__construct($baseId);
    }

    protected function loadHtml()
    {
        $this
                ->addColumn((new Column('id'))
                        ->setOrderable(DataProvider::SORT_ASC)
                        ->setSearchable(true, Column::TYPE_INT))
                ->addColumn((new Column('name'))
                        ->setOrderable()
                        ->setSearchable(true))
                ->addColumn((new Column('department_id'))
                        ->setOrderable()
                        ->setSearchable(true));
    }

    public function initContent()
    {
        $this->appendMassActionButtons();
        $this->appendButtons();
        $this->appendActionButtons();
    }

    public function loadData()
    {
        $provider = new TicketTemplatesProvider();
        $query    = $provider->loadTemplates();
        $dataProv = new ArrayDataProvider();
        $dataProv->setData($query);
        $this->setDataProvider($dataProv);
    }
    

    protected function appendMassActionButtons()
    {
        $this->addMassActionButton(new MassDeleteButton());
    }
    
    protected function appendButtons()
    {
        $this->addButton(new AddTicketTemplateButton());
        
    }
    
    protected function appendActionButtons()
    {
        $edit = new EditTicketTemplateButton();
        $edit->setRawUrl(BuildUrl::getUrl('TicketTemplates', 'edit'))
                ->setRedirectParams(['templateId' => ':id']);
        $this->addActionButton($edit);
        
        $this->addActionButton(new DeleteTicketTemplateButton());
    }
}
