<?php

class ControllerCommonFooter extends Controller {

    protected $configurations = array();
    protected $referencePathFile = 'common/footer';

    public function loadLanguage() {
        $this->configurations['language'] = array_merge($this->configurations, $this->language->load('common/footer'));
    }

    public function loadScript() {
        $this->document->addScript('public/js/common/footer.js');
    }

    public function loadStyle() {

        $this->configurations['footerStyle'] = array(
            'bottom_background' => [
                'var'   => '--bottom-footer-bg-color',
                'value' => $this->config->get('wg24_fot_bbg_col'),
            ],
            'bottom_text_color' => [
                'var'   => '--bottom-footer-text-color',
                'value' => $this->config->get('wg24_fot_powerred_col'),
            ],
            'bottom_text_color_hover' => [
                'var'   => '--bottom-footer-text-color-hover',
                'value' => $this->config->get('wg24_fot_powerred_hover_col'),
            ],
            'footer_background' => [
                'var'   => '--footer-bg-color',
                'value' => $this->config->get('wg24_footer_bg_col'),
            ],
            'footer_top_border' => [
                'var'   => '--footer-top-border',
                'value' => $this->config->get('wg24_fot_line'),
            ],
            'footer_link' => [
                'var'   => '--footer-link',
                'value' => $this->config->get('wg24_fotlin_col'),
            ],
            'footer_link_hover' => [
                'var'   => '--footer-link-hover',
                'value' => $this->config->get('wg24_fotlin_h_col'),
            ],
            'footer_title' => [
                'var'   => '--footer-title',
                'value' => $this->config->get('wg24_fotheadin_col'),
            ],
        );
    }

    public function loadModel() {
        $this->load->dmodel('tool/online');
        $this->load->dmodel('tool/image');
        $this->load->model('design/banner');
        $this->load->model('setting/extension');
        $this->load->model('catalog/information');
        $this->load->type('tipocomum');
        $this->load->helper('ftr_geral');
    }

    public function loadData() {
        $base_layout = boolval($this->config->get('footer_model_able')) ?? false;
        $keyDatabase = $base_layout ? 'custom_': 'dinamic_';
        $this->configurations['base_layout'] = $base_layout;
        $this->configurations['enableComponents'] = array();

        $arrayData = [
            'facebook'  => $keyDatabase.'foot_social_midia_link_facebook',
            'twitter'   => $keyDatabase.'foot_social_midia_link_twitter',
            'google'    => $keyDatabase.'foot_social_midia_link_google',
            'rss'       => $keyDatabase.'foot_social_midia_link_rss',
            'pinterest' => $keyDatabase.'foot_social_midia_link_pinterest',
            'linkedin'  => $keyDatabase.'foot_social_midia_link_linkedin',
            'youtube'   => $keyDatabase.'foot_social_midia_link_youtube',
            'instagram' => $keyDatabase.'foot_social_midia_link_instagram',
            'blogger'   => $keyDatabase.'foot_social_midia_link_blogger',
            'tiktok'    => $keyDatabase.'foot_social_midia_link_tiktok',
        ];

        $socialMedias = array();
        foreach ($arrayData as $key => $value) {
            if (!empty($this->config->get($value))) {
                $socialMedias[$key]['url'] = $this->config->get($value);
            }
        }

        if ($base_layout) {
            $this->configurations['enableComponents'] = [
                'customContact'      => $this->config->get('custom_foot_contact_show_address') == 'yes' ?? false,
                'customSocial'       => count($socialMedias) > 0 ?? false,
                'customPayment'      => $this->config->get('custom_foot_icon_payment_status') == 'enable' ?? false,
                'customCertificates' => $this->config->get('custom_foot_certificate_type') != 0 ?? false,
            ];
        } else {
            $this->configurations['enableComponents'] = [
                'dynamicContact'      => $this->config->get('dinamic_foot_contact_show_address') == 'yes' ?? false,
                'dynamicSocial'       => count($socialMedias) > 0 ?? false,
                'dynamicPayment'      => $this->config->get('dinamic_foot_icon_payment_status') == 'enable' ?? false,
                'dynamicCertificates' => $this->config->get('dinamic_foot_certificate_type') != 0 ?? false,
            ];
        }

        return [
            'base_layout' => $base_layout,
            'keyDatabase' => $keyDatabase,
        ];
    }

    public function index() {

        $this->loadLanguage();
        $this->loadScript();
        $this->loadStyle();
        $this->loadModel();

        $mainData = $this->loadData();
        $type_layout = $mainData['base_layout'];
        $keyDatabase = $mainData['keyDatabase'];

        $this->getInformation($type_layout);
        $this->getServices($type_layout, $keyDatabase);
        $this->getAccount($type_layout);
        $this->getContact($type_layout, $keyDatabase);
        $this->getSocialMedias($type_layout, $keyDatabase);
        $this->getPaymentOptions($type_layout, $keyDatabase);
        $this->getCertificates($type_layout, $keyDatabase);
        $this->getCustomOptions($type_layout, $keyDatabase);

        $this->floatingContent();
        $this->cookiesPolicy();
        $this->costumersOnline();

        $this->children = array(
            'common/scripts_bottom'
        );

        $this->configurations['google_recaptcha_status'] = $this->config->get('wg24_google_recaptcha_status');
        $this->configurations['scripts_async'] = $this->ftrgeralregistry->getScriptManifest('catalog/view/theme/vista/public/js/scripts-async.js', true);
        $this->configurations['testEnvironment']['status'] = (defined('AMBIENTE_TESTE')) ?? false;

        //Para funcionar a compra pelo app que parou de funcionar depois da alteração no rodape
        $this->data['futuraquantidadeatacado_status'] = $this->config->get('futuraquantidadeatacado_status');
        $this->data['text_quantity'] = $this->language->get('text_quantity');
        $this->data['text_apply'] = $this->language->get('text_apply');
        if (ftr_geral::isIsset($this->config->get('avise_me_status'))) {
            if ($this->config->get('config_stock_checkout')) {
                $this->data['aviseme_status'] = Type_Status::Tp_Desabilitado;
            } else {
                $this->data['aviseme_status'] = $this->config->get('avise_me_status');
            }
        } else {
            $this->data['aviseme_status'] = Type_Status::Tp_Desabilitado;
        }
        $this->app();
        //fim do bloco

        $this->data['data'] = $this->configurations;
        $this->response->setOutput($this->render('common/footer'));
    }

    //Para funcionar a compra pelo app que parou de funcionar depois da alteração no rodape
    private function app()
    {
        $this->data['mainheader_js'] = $this->ftrgeralregistry->getScriptManifest('catalog/view/theme/appmobile/public/js/mainheader.js', true);
        if (isset($this->data['aviseme_status']) && $this->data['aviseme_status']) {
            $this->document->addScriptApp(array(
                'catalog/view/theme/appmobile/public/js/mainheaderform.js',
                'catalog/view/theme/appmobile/js/jquery.aviseme.js'
            ));

            $this->data['aviseme_info']['heading_title_aviseme'] = $this->language->get('heading_title_aviseme');
            $this->data['aviseme_info']['text_nome'] = $this->language->get('text_nome');
            $this->data['aviseme_info']['text_email'] = $this->language->get('text_email');
            $this->data['aviseme_info']['entry_captcha'] = $this->language->get('entry_captcha');
            $this->data['aviseme_info']['text_continue'] = $this->language->get('text_continue');
            $this->data['aviseme_info']['entry_nome'] = $this->language->get('entry_nome');
            $this->data['aviseme_info']['entry_email'] = $this->language->get('entry_email');
            $this->data['aviseme_info']['sucess_send'] = $this->language->get('sucess_send');
            $this->data['aviseme_info']['body_message'] = $this->language->get('body_message');
            $this->data['aviseme_info']['price_esgotado'] = $this->language->get('price_esgotado');
            $this->data['aviseme_info']['heading_title_aviseme_btn'] = $this->language->get('heading_title_aviseme_btn');
            $this->data['aviseme_info']['text_send'] = $this->language->get('text_send');
            $this->data['aviseme_info']['text_cancel'] = $this->language->get('text_cancel');
            $this->data['aviseme_info']['text_conclude'] = $this->language->get('text_conclude');
        }
    }
    //fim do bloco

    public function getInformation($type_layout) {
        $this->loadLanguage();
        $this->loadModel();

        $typeInfo = $type_layout ? 'customInformations' : 'dynamicInformations';
        $this->configurations[$typeInfo] = array();

        if ($type_layout) {
            $footer_logo = $this->config->get('wg24_logo_image');
            $default_lang = $this->config->get('config_language_id');

            $this->configurations['customInformations'] = array(
                'column_type' => $this->config->get('custom_foot_first_column'),
                'footer_logo' => html_entity_decode($footer_logo[$default_lang]),
                'color'       => $this->config->get('wg24_fotaout_des_col') ?? '',
            );
        }

        foreach ($this->model_catalog_information->getInformations() as $result) {
            if ($result['bottom']) {
                $this->configurations[$typeInfo]['data'][] = array(
                    'text' => $result['title'],
                    'link' => $this->url->link('information/information', 'information_id=' . $result['information_id'])
                );
            }
        }
    }

    public function getServices($type_layout, $keyDatabase) {

        $typeAccount = $type_layout ? 'customServices' : 'dynamicServices';

        $this->configurations[$typeAccount] = array();
        $this->configurations[$typeAccount] = array(
            'contact_link' => [
                'link' => $this->url->link('information/contact'),
                'text' => $this->configurations['language']['text_contact'],
            ],
            'sitemap' => [
                'link' => $this->url->link('information/sitemap'),
                'text' => $this->configurations['language']['text_sitemap'],
            ],
        );

        $servicesMapping = array(
            'return' => [
                'status'   => $this->config->get($keyDatabase . 'foot_link_add_devolution'),
                'text_key' => 'text_return',
                'link'     => 'account/return',
            ],
            'manufacturer' => [
                'status'   => $this->config->get($keyDatabase . 'foot_link_add_manufacturer'),
                'text_key' => 'text_manufacturer',
                'link'     => 'product/manufacturer',
            ],
        );

        foreach ($servicesMapping as $serviceName => $serviceData) {
            if (ftr_geral::isType($serviceData['status'], Type_Status::getEnumList(), Type_Status::Tp_Habilitado)) {
                $this->configurations[$typeAccount][$serviceName] = array(
                    'link' => $this->url->link($serviceData['link']),
                    'text' => $this->configurations['language'][$serviceData['text_key']],
                );
            }
        }
    }

    public function getAccount($type_layout) {

        $typeAccount = $type_layout ? 'customAccount' : 'dynamicAccount';

        $this->configurations[$typeAccount] = array();
        $this->configurations[$typeAccount] = array(
            'account' => [
                'link' => $this->url->link('account/account', '', 'SSL'),
                'text' => $this->configurations['language']['text_registration_data'],
            ],
            'order' => [
                'link' => $this->url->link('account/order', '', 'SSL'),
                'text' => $this->configurations['language']['text_order'],
            ],
            'newsletter' => [
                'link' => $this->url->link('account/newsletter', '', 'SSL'),
                'text' => $this->configurations['language']['text_newsletter'],
            ],
        );

        $accountMapping = array(
            'wishlist' => [
                'status'   => $this->config->get('wg24_futura_status_lista_desejos'),
                'text_key' => 'text_wishlist',
                'link'     => 'account/wishlist',
            ],
        );

        foreach ($accountMapping as $accountName => $accountData) {
            if (ftr_geral::isType($accountData['status'], Type_Status::getEnumList(), Type_Status::Tp_Habilitado)) {
                $this->configurations[$typeAccount][$accountName] = array(
                    'link' => $this->url->link($accountData['link']),
                    'text' => $this->configurations['language'][$accountData['text_key']],
                );
            }
        }
    }

    public function getContact($type_layout, $keyDatabase) {

        $this->loadLanguage();
        $index = 0;
        $phones = array();
        $type_phone = $this->load->typeForTwig('Type_Phone');
        $config_telephone = $this->config->get('config_telephone');

        $default_lang = intval($this->config->get('config_language_id'));
        $type_avanced = $this->config->get('custom_foot_contact_type_config') == 'advance' ?? false;
        $footer_contact = $this->config->get('custom_foot_contact_type_config_code');

        if ($config_telephone) {
            foreach (array_reverse($config_telephone) as $telephone) {
                if (isset($telephone['display'])) {
                    $phones[$index] = [
                        'type'        => $telephone['type'],
                        'number'      => $telephone['numero'],
                        'only_number' => ftr_geral::removeMaskToInt($telephone['numero']),

                    ];

                    switch ($phones[$index]['type']) {
                        case $type_phone->Tp_Telefone:
                            $phones[$index]['icon'] = 'fas fa-phone';
                            break;
                            case $type_phone->Tp_Fax:
                                $phones[$index]['icon'] = 'fas fa-fax';
                                break;
                                case $type_phone->Tp_Celular:
                                    case $type_phone->Tp_Whatsapp:
                                        $phones[$index]['icon'] = 'fab fa-whatsapp';
                                        break;
                                    }
                                }
                $index++;
            }
        }

        $moreInfo = [
            'email' => [
                'text' => $this->config->get('config_email') ?? '',
                'icon' => (!empty($this->config->get('config_email'))? 'far fa-envelope' : ''),
            ],
            'address' => [
                'text' => $this->config->get('config_address') ?? '',
                'icon' =>  (!empty($this->config->get('config_address')) ? 'fas fa-map-marker-alt' : ''),
            ],
        ];

        $typeInfo = $type_layout ? 'customContact' : 'dynamicContact';

        $this->configurations[$typeInfo] = array();
        $this->configurations[$typeInfo] = array(
            'show_contact_content' => $this->config->get($keyDatabase.'foot_contact_show_address'),
            'column_type'          => $this->config->get($keyDatabase.'foot_contact_type_config'),
            'contact_title'        => ($this->config->get($keyDatabase.'foot_contact_title')) ? $this->config->get($keyDatabase.'foot_contact_title') : $this->language->get('contact_titulo_rodape'),
            'telephones'           => (!empty($phones) ? $phones : ''),
            'color'                => $this->config->get('wg24_fotlinicon_col') ? $this->config->get('wg24_fotlinicon_col') : $this->config->get('wg24_menum_lcolor'),
            'moreInfo'             => $moreInfo,
        );

        if (is_array($footer_contact) && $type_avanced) {
            $this->configurations[$typeInfo]['customHtml'] = html_entity_decode($footer_contact[$default_lang], ENT_COMPAT, 'UTF-8');
        }
    }

    public function getSocialMedias($type_layout, $keyDatabase) {

        $fontKey  = $keyDatabase . 'foot_social_midia_font';
        $styleKey = $keyDatabase . 'foot_social_midia_bg';

        $mediaUrls = array();
        $mediaStyle = array();
        $mediaStyle = array(
            'deep' => (!empty($this->config->get($styleKey)) ? $this->config->get($styleKey) : '#222b34'),
            'font' => (!empty($this->config->get($fontKey)) ? $this->config->get($fontKey) : '#FFF'),
        );

        $arrayData = array(
            'facebook'  => $keyDatabase . 'foot_social_midia_link_facebook',
            'twitter'   => $keyDatabase . 'foot_social_midia_link_twitter',
            'google'    => $keyDatabase . 'foot_social_midia_link_google',
            'rss'       => $keyDatabase . 'foot_social_midia_link_rss',
            'pinterest' => $keyDatabase . 'foot_social_midia_link_pinterest',
            'linkedin'  => $keyDatabase . 'foot_social_midia_link_linkedin',
            'youtube'   => $keyDatabase . 'foot_social_midia_link_youtube',
            'instagram' => $keyDatabase . 'foot_social_midia_link_instagram',
            'blogger'   => $keyDatabase . 'foot_social_midia_link_blogger',
            'tiktok'    => $keyDatabase . 'foot_social_midia_link_tiktok',
        );

        foreach ($arrayData as $key => $value) {
            $configValue = $this->config->get($value);
            if (!empty($configValue)) {

                $mediaUrls[$key]['url'] = $configValue;
                switch ($key) {
                    case 'facebook':
                        $mediaUrls[$key]['icon'] = 'fab fa-facebook-f';
                        break;
                    case 'twitter':
                        $mediaUrls[$key]['icon'] = 'fab fa-twitter';
                        break;
                    case 'google':
                        $mediaUrls[$key]['icon'] = 'fab fa-google-plus-g';
                        break;
                    case 'rss':
                        $mediaUrls[$key]['icon'] = 'fas fa-rss';
                        break;
                    case 'pinterest':
                        $mediaUrls[$key]['icon'] = 'fab fa-pinterest';
                        break;
                    case 'linkedin':
                        $mediaUrls[$key]['icon'] = 'fab fa-linkedin-in';
                        break;
                    case 'youtube':
                        $mediaUrls[$key]['icon'] = 'fab fa-youtube';
                        break;
                    case 'instagram':
                        $mediaUrls[$key]['icon'] = 'fab fa-instagram';
                        break;
                    case 'blogger':
                        $mediaUrls[$key]['icon'] = 'fab fa-blogger-b';
                        break;
                    case 'tiktok':
                        $mediaUrls[$key]['icon'] = 'fab fa-tiktok';
                        break;
                }
            }
        }

        $configKey = $type_layout ? 'customMedias' : 'dynamicMedias';

        $this->configurations[$configKey . 'Style'] = $mediaStyle;
        $this->configurations[$configKey . 'Urls'] = $mediaUrls;
    }

    public function getPaymentOptions($type_layout, $keyDatabase) {

        $this->configurations['banners'] = array();

        $typePayment = $type_layout ? 'customPayment': 'dynamicPayment';
        $this->configurations[$typePayment] = array();

        $payment_status = $this->config->get($keyDatabase.'foot_icon_payment_status') == 'enable' ?? false;
        $this->configurations[$typePayment]['paymentStatus'] = $payment_status;

        if ($payment_status) {

            $results = $this->model_design_banner->getBanner($this->config->get($keyDatabase.'foot_icon_payment_layout'));
            $isAutoBrands = Ftr_Geral::isType($this->config->get($keyDatabase.'foot_icon_payment_auto_flag'), Type_DsimDnao::getEnumList(), Type_DsimDnao::Tp_Nao);
            $this->configurations[$typePayment]['bandeiras_automaticas'] = $isAutoBrands;

            if (intval($isAutoBrands) == Type_DsimDnao::Tp_Nao) {
                foreach ($results as $result) {
                    if (file_exists(DIR_IMAGE . $result['image'])) {
                        $this->configurations[$typePayment]['banners'][] = array(
                            'title' => $result['title'],
                            'link' => $result['link'],
                            'image' => $this->dmodel_tool_image->resizeWebp($result['image'], $this->config->get($keyDatabase.'foot_icon_payment_width_image'), $this->config->get($keyDatabase.'foot_icon_payment_height_image'))
                        );
                    }
                }
            } else {
                $bandeiras = array(
                    'master'        => 'MasterCard',
                    'visa'          => 'Visa',
                    'elo'           => 'Elo',
                    'amex'          => 'American Express',
                    'hipercard'     => 'Hipercard',
                    'diners'        => 'Diners',
                    'cabal'         => 'Cabal',
                    'aura'          => 'Aura',
                    'sorocred'      => 'Sorocred',
                    'bradesco'      => 'Banco Bradesco',
                    'brasil'        => 'Banco do Brasil',
                    'itau'          => 'Banco Itaú',
                    'banrisul'      => 'Banco Banrisul',
                    'discover'      => 'Discover',
                    'jcb'           => 'JCB',
                    'boleto'        => 'Boleto Bancário',
                    'hiper'         => 'Hiper card',
                    'ml'            => 'Mercado Livre',
                    'transferencia' => 'Transferencia Bancária',
                    'paypal'        => 'PayPal',
                    'pix'           => 'Pix'
                );
                // pagseguro
                $payment_method['pagseguro'] = array(
                    'master',
                    'visa',
                    'elo',
                    'amex',
                    'hipercard',
                    'diners',
                    'cabal',
                    'aura',
                    'sorocred',
                    'bradesco',
                    'brasil',
                    'itau',
                    'banrisul',
                    'boleto'
                );
                // pagseguro_api
                $payment_method['pagseguro_api'] = array(
                    'master',
                    'visa',
                    'elo',
                    'amex',
                    'hiper',
                    'hipercard',
                    'diners',
                    'boleto'
                );
                // eRede
                $payment_method['FuturaKomerci'] = array(
                    'master',
                    'visa',
                    'diners',
                    'hiper',
                    'hipercard',
                    'jcb'
                );

                // cielo_checkout
                $payment_method['cielo_transparente'] = array();
                if ($this->config->get('cielo_transparente_master'))   array_push($payment_method['cielo_transparente'], 'master');
                if ($this->config->get('cielo_transparente_visa'))     array_push($payment_method['cielo_transparente'], 'visa');
                if ($this->config->get('cielo_transparente_amex'))     array_push($payment_method['cielo_transparente'], 'amex');
                if ($this->config->get('cielo_transparente_diners'))   array_push($payment_method['cielo_transparente'], 'diners');
                if ($this->config->get('cielo_transparente_elo'))      array_push($payment_method['cielo_transparente'], 'elo');
                if ($this->config->get('cielo_transparente_discover')) array_push($payment_method['cielo_transparente'], 'discover');

                //cielo api 3.0
                $payment_method['cielo_api_credito'] = array();
                $cielo_credit_cards = $this->config->get('cielo_api_credit_card');
                if($cielo_credit_cards){
                    foreach ($cielo_credit_cards as $cielo_credit_card){
                        if (strtolower($cielo_credit_card['descricao'])) {
                            $payment_method['cielo_api_credito'][] = strtolower($cielo_credit_card['descricao']);
                        }
                    }
                }

                //e-rede
                $payment_method['rede_credito'] = array();
                $rede_credit_cards = $this->config->get('rede_credit_card');
                if($rede_credit_cards){
                    foreach ($rede_credit_cards as $rede_credit_card){
                        switch (strtolower($rede_credit_card['descricao'])) {
                            case Type_RedeBandeira::getNickFromValue(Type_RedeBandeira::Tp_Mastercard):
                                $payment_method['rede_credito'][] = 'master';
                                break;
                            case Type_RedeBandeira::getNickFromValue(Type_RedeBandeira::Tp_Amex):
                                $payment_method['rede_credito'][] = 'amex';
                                break;
                            default:
                                $payment_method['rede_credito'][] = strtolower($rede_credit_card['descricao']);
                        }
                    }
                }

                //yapay
                $payment_method['yapay'] = array();
                if ($this->config->get('yapay_credit_card')) {
                    $yapay_credit_cards = $this->config->get('yapay_credit_card');
                    foreach ($yapay_credit_cards as $yapay_credit_card) {
                        switch (strtolower($yapay_credit_card['descricao'])) {
                            case Type_FormPgtoYapayCartao::getNickFromValue(Type_FormPgtoYapayCartao::Tp_MasterCard):
                                $payment_method['yapay'][] = 'master';
                                break;
                            case Type_FormPgtoYapayCartao::getNickFromValue(Type_FormPgtoYapayCartao::Tp_AmericanExpress):
                                $payment_method['yapay'][] = 'amex';
                                break;
                            default:
                                $payment_method['yapay'][] = strtolower($yapay_credit_card['descricao']);
                        }
                    }
                }
                if ($this->config->get('yapay_billet'))        array_push($payment_method['yapay'], 'boleto');
                if ($this->config->get('yapay_bank_transfer')) array_push($payment_method['yapay'], 'transferencia');

                //wirecard
                $payment_method['wirecard'] = array();
                if ($this->config->get('wirecard_credit_card')) {
                    $wirecard_credit_cards = $this->config->get('wirecard_credit_card');
                    foreach ($wirecard_credit_cards as $wirecard_credit_card) {
                        switch (strtolower($wirecard_credit_card['descricao'])) {
                            case Type_FormPgtoWirecardCartao::getNickFromValue(Type_FormPgtoWirecardCartao::Tp_MasterCard):
                                $payment_method['wirecard'][] = 'master';
                                break;
                            case Type_FormPgtoWirecardCartao::getNickFromValue(Type_FormPgtoWirecardCartao::Tp_AmericanExpress):
                                $payment_method['wirecard'][] = 'amex';
                                break;
                            case Type_FormPgtoWirecardCartao::getNickFromValue(Type_FormPgtoWirecardCartao::Tp_DinnersClub):
                                $payment_method['wirecard'][] = 'diners';
                                break;
                            default:
                                $payment_method['wirecard'][] = strtolower($wirecard_credit_card['descricao']);
                        }
                    }
                }

                if ($this->config->get('wirecard_billet'))        array_push($payment_method['wirecard'], 'boleto');
                if ($this->config->get('wirecard_bank_transfer')) array_push($payment_method['wirecard'], 'transferencia');

                //getnet
                $payment_method['getnet'] = array();
                if ($this->config->get('getnet_credit_card')) {
                    $getnet_credit_cards = $this->config->get('getnet_credit_card');
                    foreach ($getnet_credit_cards as $getnet_credit_card) {
                        if($getnet_credit_card['status'] == "1") {
                            switch (strtolower($getnet_credit_card['descricao'])) {
                                case Type_GetnetBandeira::getNickFromValue(Type_GetnetBandeira::Tp_Mastercard):
                                    $payment_method['getnet'][] = 'master';
                                    break;
                                default:
                                    $payment_method['getnet'][] = strtolower($getnet_credit_card['descricao']);
                            }
                        }
                    }
                }
                $getnet_billet_status = $this->config->get('getnet_billet');
                if (isset($getnet_billet_status['status'])&&($getnet_billet_status['status']==1)) array_push($payment_method['getnet'], 'boleto');

                $getnet_pix_status = $this->config->get('getnet_pix');
                if (isset($getnet_pix_status['status']) && ($getnet_pix_status['status'] == 1)) array_push($payment_method['getnet'], 'pix');

                $payment_method['cielointegradofutura'] = array(
                    'master',
                    'visa',
                    'amex',
                    'diners',
                    'elo',
                    'discover'
                );
                // itau_shopline
                $payment_method['itaushopline'] = array(
                    'itau',
                    'boleto',
                    'transferencia'
                );
                // bcash
                $payment_method['pagamento_digital'] = array(
                    'visa',
                    'master',
                    'aura',
                    'amex',
                    'diners',
                    'hipercard',
                    'elo',
                    'boleto'
                );
                // paypal
                $payment_method['paypal'] = array(
                    'visa',
                    'master',
                    'amex',
                    'hiper',
                    'hipercard',
                    'elo',
                    'paypal'
                );
                // mercado_pago
                $payment_method['mercadopago2'] = array(
                    'master',
                    'visa',
                    'elo',
                    'amex',
                    'hipercard',
                    'diners',
                    'ml',
                    'boleto'
                );
                $payment_method['payu'] = array(
                    'visa',
                    'master',
                    'amex',
                    'diners',
                    'hipercard',
                    'elo',
                    'boleto'
                );

              $payment_method['pagarme'] = array();
              if ($this->config->get('pagarme_credit_card')) {
                $pagarme_credit_cards = $this->config->get('pagarme_credit_card');
                foreach ($pagarme_credit_cards as $pagarme_credit_card) {
                  if($pagarme_credit_card['status'] == "1"){
                    switch (strtolower($pagarme_credit_card['descricao'])) {
                      case Type_PagarmeBandeira::getNickFromValue(Type_PagarmeBandeira::Tp_Mastercard):
                        $payment_method['pagarme'][] = 'master';
                        break;
                      default:
                        $payment_method['pagarme'][] = strtolower($pagarme_credit_card['descricao']);
                    }
                  }
                }
              }

              $pagarme_pix_status = $this->config->get('pagarme_pix');
              if (isset($pagarme_pix_status['status']) && ($pagarme_pix_status['status'] == 1)) array_push($payment_method['pagarme'], 'pix');


                //boleto
                $payment_method['boleto_santander'] = $payment_method['boleto_bb'] = $payment_method['boleto_bradesco'] = array(
                    'boleto'
                );

                //transferencia bancaria
                $payment_method['bank_transfer'] = array(
                    'transferencia'
                );

                //Pix matera
                $payment_method['matera'] = array(
                    'pix'
                );

                $bandeirasKeys = array();
                $results = $this->model_setting_extension->getExtensions('payment');
                foreach ($results as $result) {
                    $exclude_payments = array(
                        'cod',
                        'orcamento',
                        'pagamentodinamico'
                    );
                    if (!in_array($result['code'], $exclude_payments) && $this->config->get($result['code'] . '_status')) {
                        $bandeirasKeys = array_merge($bandeirasKeys, $payment_method[$result['code']]);
                    }
                }

                $bandeirasKeys = array_unique($bandeirasKeys);
                foreach ($bandeirasKeys as $key) {
                  if($key != '') {
                    $this->configurations[$typePayment]['banners'][] = array(
                      'title' => $bandeiras[$key],
                      'class' => $key
                    );
                  }
                }
            }
        }
    }

    public function getCertificates($type_layout, $keyDatabase) {

        $ebitData = [
            'ebit_status'   => $this->config->get('certificate_ebit_status'),
            'ebit_store_id' => $this->config->get('certificate_ebit_store_id'),
            'ebit_lightbox' => $this->config->get('certificate_ebit_lightbox'),
        ];

        $certificates = [
            'certificates_status' => $this->config->get($keyDatabase . 'foot_certificate_type'),
            'eBitCertificate'     => $ebitData,
        ];

        if ($this->config->get($keyDatabase . 'foot_certificate_type') == Type_Certificado::TpCert_Personalizado) {
            $widthConfigKey  = $keyDatabase .'foot_certificate_width_img';
            $heightConfigKey = $keyDatabase .'foot_certificate_height_img';

            $results = $this->model_design_banner->getBanner($this->config->get('wg24_certificado_banner'));

            foreach ($results as $result) {
                if (file_exists(DIR_IMAGE . $result['image'])) {
                    $certificates['banners_certificado'][] = [
                        'title' => $result['title'],
                        'link'  => $result['link'],
                        'image' => $this->dmodel_tool_image->resize($result['image'], $this->config->get($widthConfigKey), $this->config->get($heightConfigKey)),
                    ];
                }
            }
        }

        $configKey = $type_layout ? 'customCertificates' : 'dynamicCertificates';
        $this->configurations[$configKey] = $certificates;
    }

    public function getCustomOptions($type_layout, $keyDatabase) {

        $data_phone ='';
        $config_phone = $this->config->get('config_telephone');

        $configKey = $type_layout ? 'customOptions' : 'dynamicOptions';
        $this->configurations[$configKey] = array();

        if ($config_phone) {
            $phone = array_filter($config_phone, function($telephone) {
                return isset($telephone['display']) && $telephone['display'] == Type_Status::Tp_Habilitado;
            });

            if (!empty($phone)) $data_phone = implode(', ', array_column($phone, 'numero'));
        }

        $customcommonData = [
            'config_name' => [
                'data' => $this->config->get('config_address'),
                'text' => $this->config->get('config_name') . ':',
            ],
            'config_phone' => [
                'data' => (isset($data_phone) && !empty($data_phone) ? $data_phone : ''),
                'text' => (isset($data_phone) && !empty($data_phone) ? $this->configurations['language']['config_phone'] : ''),
            ],
            'config_email' => [
              'data' => $this->config->get('config_email'),
              'text' => $this->configurations['language']['config_email'],
            ],
            'config_owner' => [
                'data' => $this->config->get('config_owner'),
                'text' => $this->configurations['language']['config_owner'],
            ],
            'config_ie' => [
                'data' => $this->config->get('config_ie'),
                'text' => $this->configurations['language']['config_IE']
            ],
            'config_cnpj' => [
               'data' => $this->config->get('config_cnpj'),
               'text' => $this->configurations['language']['config_cnpj'],
            ],
            'config_year' => [
               'data' => $this->configurations['language']['config_year'],
               'text' => '© ' . date("Y"),
            ],
        ];

        if ($type_layout) {

            $default_lang = $this->config->get('config_language_id');
            $copyright = $this->config->get('custom_foot_type_container_code');
            if (!empty($copyright[$default_lang])) $copyrightFormated = html_entity_decode($copyright[$default_lang]);

            $tipo_rodape = ftr_geral::isType($this->config->get('custom_foot_type_container'), Type_AutoOrPersonalizado::getEnumList(), Type_AutoOrPersonalizado::Tp_Personalizado);

            $this->configurations['customLayout'] = array(
                'tipo_rodape' => $tipo_rodape,
                'copyright'   => isset($copyrightFormated) ? $copyrightFormated : '',
            );
        }

        $this->configurations[$configKey] = [
            'developmentBy' => $this->config->get('futura_desenvolvidopor'),
            'infos'         => !$this->config->get($keyDatabase . 'foot_type_container') ? $customcommonData : [],
        ];
    }

    public function floatingContent() {
        $this->configurations['backToTop'] = $this->config->get('fc_back_to_top');
        if (isset($this->configurations['backToTop'])) {
            if ($this->configurations['backToTop']['position'] == Type_Position::Tp_Right) {
                $this->configurations['backToTop']['position'] = 'scroll-to-top-right';
            } else {
                $this->configurations['backToTop']['position'] = 'scroll-to-top-left';
            }
        }

        $this->configurations['whatsApp'] = $this->config->get('fc_whatsapp');
        if (isset($this->configurations['whatsApp'])) {
            $this->configurations['whatsApp']['url'] = 'https://wa.me/55' . preg_replace('/\D/', '', $this->configurations['whatsApp']['number']);
            if (isset($this->configurations['whatsApp']['position']) && $this->configurations['whatsApp']['position'] == Type_Position::Tp_Right) {
                $this->configurations['whatsApp']['position'] = 'footer-whatsapp-right';
            } else {
                $this->configurations['whatsApp']['position'] = 'footer-whatsapp-left';
            }
        }
    }

    public function cookiesPolicy() {
        $cookiesId = (int) $this->config->get('config_cookies_id');

        $this->configurations['cookiesPolicy'] = [
            'id' => $cookiesId,
            'url' => $this->url->link('information/information', 'information_id=' . $cookiesId),
        ];
    }

    public function costumersOnline() {
        $ip = (isset($this->request->server['REMOTE_ADDR']) ? $this->request->server['REMOTE_ADDR'] : '');
        $url = ((isset($this->request->server['HTTP_HOST']) && isset($this->request->server['REQUEST_URI'])) ? 'http://' . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI'] : '');
        $referer = (isset($this->request->server['HTTP_REFERER']) ? $this->request->server['HTTP_REFERER'] : '');

        $this->dmodel_tool_online->whosonline($ip, $this->customer->getId(), $url, $referer);
    }
}