<?php
loadController('base/module');

class ControllerDesignFooter extends ControllerBaseModule
{
    protected $referencePathFile = 'design/footer';

    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');
        $this->load->model('design/banner');
    }

    public function loadData()
    {
        parent::loadData();
        
        $this->dataVue['TypesForJs'] = array(
            Type_Footer::getTypeForJs(),
            Type_FooterDinamicFirstColumn::getTypeForJs(),
            Type_FooterCustomFirstColumn::getTypeForJs(),
            Type_FooterDinamicContact::getTypeForJs(),
            Type_FooterCustomContact::getTypeForJs(),
            Type_FooterCustomContainer::getTypeForJs(),
            Type_FooterDinamicContainer::getTypeForJs(),
            Type_DsimDnao::getTypeForJs(),
            Type_StatusEn::getTypeForJs(),
            Type_Status::getTypeForJs(),
            Type_FooterYesOrNo::getTypeForJs(),
            Type_Certificado::getTypeForJs()
        );
        
        $this->dataVue['configurations'] = $this->model_setting_setting->getSetting('colors');
        $this->dataVue['configurations']['custom_foot_social_midia_bg'] = !empty($this->config->get('custom_foot_social_midia_bg')) ? $this->config->get('custom_foot_social_midia_bg') : '#000';
        
        $bgSocialDefault = '#222B34';
        $colorFontDefault = '#ffffff'; 

        $this->dataVue['configurations']['dinamic_foot_social_midia_bg'] = $this->config->get('dinamic_foot_social_midia_bg') ? $this->config->get('dinamic_foot_social_midia_bg') : $bgSocialDefault;

        $databanner = array (
            'status' => Type_Status::Tp_Habilitado
        );

        $banners = $this->model_design_banner->getBanners($databanner);
        $bannersLayout = array();

        foreach($banners as $banner){
            $bannersLayout[$banner['banner_id']] = $banner['name'];
        }

        $this->dataVue['bannersLayout'] = $bannersLayout;

        $footer_model_Able = $this->config->get('footer_model_able');
        $first_column_custom = $this->config->get('custom_foot_first_column_code') ?? []; 
        $contact_config_code = $this->config->get('custom_foot_contact_type_config_code') ?? [];
        $container_custom = $this->config->get('custom_foot_type_container_code') ?? [];
        $custom_foot_certificate_type = $this->config->get('custom_foot_certificate_type');

        $dinamic_foot_first_colunm = $this->config->get('dinamic_foot_first_colunm');
        $dinamic_foot_social_midia_bg = $this->config->get('dinamic_foot_social_midia_bg');
        $dinamic_foot_social_midia_font = $this->config->get('dinamic_foot_social_midia_font');
        $dinamic_foot_social_midia_link_facebook = $this->config->get('dinamic_foot_social_midia_link_twitter');
        $dinamic_foot_social_midia_link_twitter = $this->config->get('dinamic_foot_social_midia_link_twitter');
        $dinamic_foot_social_midia_link_google = $this->config->get('dinamic_foot_social_midia_link_google');
        $dinamic_foot_social_midia_link_rss = $this->config->get('dinamic_foot_social_midia_link_rss');
        $dinamic_foot_social_midia_link_pinterest = $this->config->get('dinamic_foot_social_midia_link_pinterest');
        $dinamic_foot_social_midia_link_linkedin = $this->config->get('dinamic_foot_social_midia_link_linkedin');
        $dinamic_foot_social_midia_link_youtube = $this->config->get('dinamic_foot_social_midia_link_youtube');
        $dinamic_foot_social_midia_link_instagram = $this->config->get('dinamic_foot_social_midia_link_instagram');
        $dinamic_foot_social_midia_link_blogger = $this->config->get('dinamic_foot_social_midia_link_blogger');
        $dinamic_foot_link_add_manufacturer = $this->config->get('dinamic_foot_link_add_manufacturer');
        $dinamic_foot_link_add_devolution = $this->config->get('dinamic_foot_link_add_devolution');
        $dinamic_foot_certificate_type = $this->config->get('dinamic_foot_certificate_type');
        $dinamic_foot_type_container = $this->config->get('dinamic_foot_type_container');
        $dinamic_foot_icon_payment_status = $this->config->get('dinamic_foot_icon_payment_status');
        $dinamic_foot_icon_payment_auto_flag = $this->config->get('dinamic_foot_icon_payment_auto_flag');
        $dinamic_foot_contact_type_config = $this->config->get('dinamic_foot_contact_type_config');
        $dinamic_foot_contact_show_address = $this->config->get('dinamic_foot_contact_show_address');
        $dinamic_foot_certificate_width_img = $this->config->get('dinamic_foot_certificate_width_img');
        $dinamic_foot_certificate_height_img = $this->config->get('dinamic_foot_certificate_height_img');

        $this->dataVue['configurations']['module'] = array(
            'footer_model_able' => isset($footer_model_Able) ? $footer_model_Able : (string)Type_Footer::Tp_Custom,
            'custom_foot_first_column_code' => htmlspecialchars_decode(is_array($first_column_custom) ? array_shift($first_column_custom) : '') ?? '',
            'custom_foot_contact_type_config_code' => htmlspecialchars_decode(is_array($contact_config_code) ? array_shift($contact_config_code) : '') ?? '',
            'custom_foot_type_container_code' => htmlspecialchars_decode(is_array($container_custom) ? array_shift($container_custom) : '') ?? '',
            'custom_foot_first_column' => $this->config->get('custom_foot_first_column'),
            'custom_foot_contact_show_address' => $this->config->get('custom_foot_contact_show_address'),
            'custom_foot_contact_type_config' => $this->config->get('custom_foot_contact_type_config'),
            'custom_foot_contact_title' => $this->config->get('custom_foot_contact_title'),
            'custom_foot_social_midia_bg' => $this->config->get('custom_foot_social_midia_bg') ?? '',
            'custom_foot_social_midia_font' => $this->config->get('custom_foot_social_midia_font') ?? '',
            'custom_foot_social_midia_link_facebook' => $this->config->get('custom_foot_social_midia_link_facebook'),
            'custom_foot_social_midia_link_twitter' => $this->config->get('custom_foot_social_midia_link_twitter'),
            'custom_foot_social_midia_link_google' => $this->config->get('custom_foot_social_midia_link_google'),
            'custom_foot_social_midia_link_rss' => $this->config->get('custom_foot_social_midia_link_rss'),
            'custom_foot_social_midia_link_pinterest' => $this->config->get('custom_foot_social_midia_link_pinterest'),
            'custom_foot_social_midia_link_linkedin' => $this->config->get('custom_foot_social_midia_link_linkedin'),
            'custom_foot_social_midia_link_youtube' => $this->config->get('custom_foot_social_midia_link_youtube'),
            'custom_foot_social_midia_link_instagram' => $this->config->get('custom_foot_social_midia_link_instagram'),
            'custom_foot_social_midia_link_blogger' => $this->config->get('custom_foot_social_midia_link_blogger'),
            'custom_foot_type_container' => $this->config->get('custom_foot_type_container'),
            'custom_foot_icon_payment_status' => $this->config->get('custom_foot_icon_payment_status'),
            'custom_foot_icon_payment_auto_flag' => $this->config->get('custom_foot_icon_payment_auto_flag'),
            'custom_foot_icon_payment_layout' => $this->config->get('custom_foot_icon_payment_layout'),
            'custom_foot_icon_payment_width_image' => $this->config->get('custom_foot_icon_payment_width_image'),
            'custom_foot_icon_payment_height_image' => $this->config->get('custom_foot_icon_payment_height_image'),
            'custom_foot_link_add_manufacturer' => $this->config->get('custom_foot_link_add_manufacturer'),
            'custom_foot_link_add_devolution' => $this->config->get('custom_foot_link_add_devolution'),
            'custom_foot_certificate_width_img' => $this->config->get('custom_foot_certificate_width_img'),
            'custom_foot_certificate_height_img' => $this->config->get('custom_foot_certificate_height_img'),
            'custom_foot_certificate_layout' => $this->config->get('custom_foot_certificate_layout'),
            'dinamic_foot_first_colunm' => isset($dinamic_foot_first_colunm) ? $dinamic_foot_first_colunm : (string)Type_FooterDinamicFirstColumn::Tp_Dinamic,
            'dinamic_foot_social_midia_bg' => isset($dinamic_foot_social_midia_bg) ? $dinamic_foot_social_midia_bg : $bgSocialDefault,
            'dinamic_foot_social_midia_font' => isset($dinamic_foot_social_midia_font) ? $dinamic_foot_social_midia_font : $colorFontDefault,
            'dinamic_foot_social_midia_link_facebook' => isset($dinamic_foot_social_midia_link_facebook) ? $dinamic_foot_social_midia_link_facebook : '',
            'dinamic_foot_social_midia_link_twitter' => isset($dinamic_foot_social_midia_link_twitter) ? $dinamic_foot_social_midia_link_twitter : '',
            'dinamic_foot_social_midia_link_google' => isset($dinamic_foot_social_midia_link_google) ? $dinamic_foot_social_midia_link_google : '',
            'dinamic_foot_social_midia_link_rss' => isset($dinamic_foot_social_midia_link_rss) ? $dinamic_foot_social_midia_link_rss : '',
            'dinamic_foot_social_midia_link_pinterest' => isset($dinamic_foot_social_midia_link_pinterest) ? $dinamic_foot_social_midia_link_pinterest : '',
            'dinamic_foot_social_midia_link_linkedin' => isset($dinamic_foot_social_midia_link_linkedin) ? $dinamic_foot_social_midia_link_linkedin : '',
            'dinamic_foot_social_midia_link_youtube' => isset($dinamic_foot_social_midia_link_youtube) ? $dinamic_foot_social_midia_link_youtube : '',
            'dinamic_foot_social_midia_link_instagram' => isset($dinamic_foot_social_midia_link_instagram) ? $dinamic_foot_social_midia_link_instagram : '',
            'dinamic_foot_social_midia_link_blogger' => isset($dinamic_foot_social_midia_link_blogger) ? $dinamic_foot_social_midia_link_blogger : '',
            'dinamic_foot_link_add_manufacturer' => isset($dinamic_foot_link_add_manufacturer) ? $dinamic_foot_link_add_manufacturer : (string)Type_Status::Tp_Habilitado, 
            'dinamic_foot_link_add_devolution' => isset($dinamic_foot_link_add_devolution) ? $dinamic_foot_link_add_devolution : (string)Type_Status::Tp_Habilitado,
            'custom_foot_certificate_type' => isset($custom_foot_certificate_type) ? $custom_foot_certificate_type : (string)Type_Certificado::TpCert_Desabilitado,
            'dinamic_foot_certificate_type' => isset($dinamic_foot_certificate_type) ? $dinamic_foot_certificate_type : (string)Type_Certificado::TpCert_Futura, 
            'dinamic_foot_type_container' => isset($dinamic_foot_type_container) ? $dinamic_foot_type_container : (string)Type_FooterCustomContainer::Tp_Auto,
            'dinamic_foot_icon_payment_status' => isset($dinamic_foot_icon_payment_status) ? $dinamic_foot_icon_payment_status : (string)Type_StatusEn::Tp_Enable,
            'dinamic_foot_icon_payment_auto_flag' => isset($dinamic_foot_icon_payment_auto_flag) ? $dinamic_foot_icon_payment_auto_flag : (string)Type_DsimDnao::Tp_Sim,
            'dinamic_foot_contact_type_config' => isset($dinamic_foot_contact_type_config) ? $dinamic_foot_contact_type_config : (string)Type_FooterDinamicContact::Tp_Easy,
            'dinamic_foot_contact_show_address' => isset($dinamic_foot_contact_show_address) ? $dinamic_foot_contact_show_address : (string)Type_FooterYesOrNo::Tp_Yes,
            'dinamic_foot_certificate_width_img' => isset($dinamic_foot_certificate_width_img) ? $dinamic_foot_certificate_width_img : '',
            'dinamic_foot_certificate_height_img' => isset($dinamic_foot_certificate_height_img) ? $dinamic_foot_certificate_height_img : '',
            'dinamic_foot_icon_payment_layout' => $this->config->get('dinamic_foot_icon_payment_layout'),
            'dinamic_foot_certificate_layout' => $this->config->get('dinamic_foot_certificate_layout'),
            'dinamic_foot_icon_payment_width_image' => $this->config->get('dinamic_foot_icon_payment_width_image'),
            'dinamic_foot_icon_payment_height_image' => $this->config->get('dinamic_foot_icon_payment_height_image'),
        );
    }

    protected function saveSetting()
    {
        $this->load->model('setting/setting');
        
        $defaultLanguage = $this->config->get('config_language_id');

        $data = $this->request->post['module'];

        $data['custom_foot_first_column_code'] = $data['custom_foot_first_column_code'] ? array(
            $defaultLanguage => $data['custom_foot_first_column_code']
        ) : array(
            $defaultLanguage => ''
        );
        $data['custom_foot_contact_type_config_code'] = $data['custom_foot_contact_type_config_code'] ? array(
            $defaultLanguage => $data['custom_foot_contact_type_config_code']
        ) : array(
            $defaultLanguage => ''
        );
        $data['custom_foot_type_container_code'] = $data['custom_foot_type_container_code'] ? array(
            $defaultLanguage => $data['custom_foot_type_container_code']
        ) : array(
            $defaultLanguage => ''
        );
        
        $this->model_setting_setting->editSetting($this->fileName, $data, 0, $this->arrayJson);
    }

    public function loadScript()
    {
        $this->document->addScript("view/public/js/$this->referencePathFile.js");
        $this->document->addStyle('../catalog/view/theme/vista/stylesheet/nav.css');
        $this->document->addScript('view/javascript/ckeditor/ckeditor.js');
    }
}

?>