<?php

loadController('base/module');

class ControllerDesignVisual extends ControllerBaseModule
{
    protected $referencePathFile = 'design/visual';

    protected function breadcrumbs()
    {
        $this->dataVue['breadcrumbs'] = [
            [
                'href' => $this->url->link('common/home', 'token=' . $this->token, 'SSL'),
                'text' => $this->language->get('text_home'),
            ],
            [
                'href' => $this->url->link($this->referencePathFile, 'token=' . $this->token, 'SSL'),
                'text' => $this->language->get('heading_title'),
            ]
        ];
    }

    protected function actionUrls()
    {
        $this->dataVue['action'] = $this->url->link(
            "$this->referencePathFile/save",
            'token=' . $this->token,
            'SSL'
        );

        $this->dataVue['back'] = $this->url->link(
            'common/home',
            'token=' . $this->token,
            'SSL'
        );
    }

    public function loadModel()
    {
        parent::loadModel();
        $this->load->dmodel('tool/image');
    }

    public function loadData()
    {
        parent::loadData();

        $this->dataVue['TypesForJs'] = array(
            Type_Status::getTypeForJs(),
            Type_DsimDnao::getTypeForJs(),
            Type_SearchBarForm::getTypeForJs(),
            Type_SearchBarButtonBackground::getTypeForJs(),
            Type_StatusEn::getTypeForJs(),
            Type_ProductBoxPromotionStyle::getTypeForJs(),
            Type_Tamanho::getTypeForJs(),
            Type_EfeitoImagem::getTypeForJs(),
            Type_CartIcon::getTypeForJs(),
            Type_ProductListTitleStyle::getTypeForJs(),
            Type_HeaderLogoPosition::getTypeForJs(),
        );

        // o inicio("../") parte da raiz, se voltar mais pastas, não vai achar o arquivo
        $this->document->addStyle('../assets/css/visual.css');
        $this->document->addStyle('../catalog/view/theme/vista/stylesheet/itembox.css');
        $this->document->addStyle('../catalog/view/theme/vista/stylesheet/vista/default.css');

        $configs = ['wg24_header_btsearch', 'wg24_icon_btnsearch_color', 'wg24_header_bg_color', 'wg24_heade_m_lin_bg_c',
            'wg24_color_border_background', 'wg24_product_box_sicon_bgcolor', 'wg24_product_box_sale_nicontcolor',
            'wg24_product_box_price_col', 'wg24_product_box_oldprce_col', 'wg24_product_bx_bgclr', 'wg24_product_bx_bdrclr',
            'wg24_btn_1bg_col', 'wg24_btn_text_col', 'wg24_l_linkc', 'wg24_product_box_n_col', 'config_product_list_rating_status',
            'wg24_link_color_stick', 'wg24_heading_transfrom', 'wg24_l_header_color', 'wg24_l_bodyb', 'wg24_finalizar_carrinho',
            'wg24_finalizar_carrinho_texto'];

        foreach ($configs as $value){
            $this->dataVue[$value] = $this->config->get($value);
        }

        $this->dataVue['product'] = $this->getProductExample();
        $this->dataVue['productBoxButton'] = $this->config->get('futuraquantidadeatacado_status');
        $this->dataVue['typeProductBoxButton'] = $this->load->typeForTwig('Type_ProductBoxButton');
        $this->dataVue['futura_habilita_lista_comparacao'] = ($this->config->get('wg24_futura_status_lista_comparacao') == '') || ($this->config->get('wg24_futura_status_lista_comparacao') == Type_Status::Tp_Habilitado);
        $this->dataVue['futura_habilita_lista_desejos']    = ($this->config->get('wg24_futura_status_lista_desejos') 	== '') || ($this->config->get('wg24_futura_status_lista_desejos') 	 == Type_Status::Tp_Habilitado);
        $this->dataVue['novo_selo'] = 'NOVO';
        $this->dataVue['exibe_futura_preco_dinamico'] = false;
        $this->dataVue['efeitoimg'] = $this->config->get('wg24_prod_efec_img');
        $this->dataVue['title_page'] = Type_TitlePage::getNickFromValue($this->config->get('wg24_page_h_font_size'));
        $this->dataVue['logo'] = $this->dmodel_tool_image->resize($this->config->get('config_logo'), 160, 40);

        $this->dataVue['product_list_title_style_font_family'] = (
            $this->config->get('wg24_header_font_source') == "google"
                ? str_replace('+', ' ', $this->config->get('wg24_header_fontto_google')).', sans-serif'
                : str_replace('+', ' ', $this->config->get('wg24_header_fontto_system'))
        );

        if ($this->config->get('wg24_l_sale_icon_style') == 'circle') {
            $this->dataVue['itembox_sale_label'] = 'itembox-sale-label-circle';
        } elseif ($this->config->get('wg24_l_sale_icon_style') == 'square') {
            $this->dataVue['itembox_sale_label'] = 'itembox-sale-label-square';
        } else {
            $this->dataVue['itembox_sale_label'] = '';
        }

        $this->dataVue['configurations'] = $this->model_setting_setting->getSetting('visual');
    }

    public function getProductExample(){
        $this->load->dmodel('tool/image');

        $aspect_ratio = str_replace(',', '.', ($this->config->get('config_image_category_height') / $this->config->get('config_image_category_width') * 100)) . '%';
        $image  = $this->dmodel_tool_image->resize('data/sem-imagem.png', $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
        $image2 = $this->dmodel_tool_image->resize('data/sem-imagem.png', $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
        $thumb  = $this->dmodel_tool_image->resize('data/sem-imagem.png', $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));

        return [
            'gridhave' => false,
            'product_id' => 0,
            'price_pr' => 50,
            'tabela_preco' => 0,
            'model' => '123456',
            'quantity_unit' => 1,
            'fator_multiplicador' => 0,
            'quantity_initial' => 1,
            'thumb' => $image,
            'thumb_mini' => $thumb,
            'date_added' => date('d/m/Y'),
            'porcentagemDesconto' => '-10%',
            'valida_selo' => true,
            'name' => 'PRODUTO DE EXEMPLO',
            'quantity' => 1,
            'description' => 'Produto utilizado para exemplo',
            'promotion_id' => 0,
            'promotion_started' => 0,
            'title_promotion' => 'Promoção',
            'price' => 'R$ 50,00',
            'special' => 'R$ 45,00',
            'image_extra' => $image2,
            'rating' => 5,
            'content' => false,
            'ratio' => ($aspect_ratio) ? 'style="height: 0; padding-bottom: ' . $aspect_ratio . '"' : '',
            'aviseme' => false,
            'class_one_line' => 'one-line',
            'reviews' => false,
            'href' => false,
            'product_color_description' => false,
            'notification_value' => false
        ];
    }

}