<?php

require_once __DIR__ . '/../../require.php';

use SwissStyle\Viewer\Controller\Viewer;

/**
 * Class AdminDesignsController
 * @extends ModuleAdminControllerCore
 * @property ContextCore $context
 * @property array $toolbar_btn
 * @property array $breadcrumbs
 * @property array $tpl_view_vars
 * @method l
 * @method createTemplate
 */
class AdminDesignCategoriesController extends ModuleAdminController {

    protected $buttons_status = array();

    public function __construct() {
        $this->table = 'admin_design_categories';
        $this->className = 'AdminDesignCategoriesController';
        $this->identifier = 'admin_design_categories';

        $this->buttons_status['new']      = true;
        $this->buttons_status['back']     = true;

        $this->addJquery();

        $this->addJqueryUI(array(
            'ui.core',
            'ui.widget'
        ));

        $this->addjQueryPlugin(array(
            'autocomplete',
//            'thickbox',
            'ajaxfileupload',
            'date',
            'tagify',
            'select2',
            'validate',
            'tablednd'
        ));

        $this->addJS(array(
            _PS_JS_DIR_.'admin-dnd.js',
        ));

        $this->page_header_toolbar_btn['new_category'] = array(
            'href' => 'index.php?tab=AdminDesignCategories&addcategory=1&token=' . Tools::getValue('token') .
                ((isset($_REQUEST['category_id']) ? '&category_id=' . $_REQUEST['category_id'] : '' )),
            'desc' => $this->l('Add new category', null, null, false),
            'icon' => 'process-icon-new'
        );


        parent::__construct();

        $this->tabAccess = Profile::getProfileAccess($this->context->employee->id_profile, Tab::getIdFromClassName('AdminDesignCategories'));
        $this->renderView($_REQUEST);
    }

    public function renderView($args) {
        $this->bootstrap = true;
        $this->lang = true;

        $this->initToolbar();
        $this->initToolbarTitle();
        $this->content .= Viewer::renderBlock('adminStructure',[
            'content' => Viewer::renderBlock('adminDesignCategories',$args)
        ]);

        return parent::renderView();
    }
}