<?php

/**
 * Class LEAPIN_Features
 *
 * @author LeapIn Corp.
 * @since 1.6.14
 */
class LEAPIN_Features
{

    public function __construct()
    {

        $this->registerActionHooks();

        return $this;
    }

    /**
     * [registerActionHooks description]
     * @return [type] [description]
     */
    public function registerActionHooks()
    {

        add_action('customize_register', array($this, 'customizer'));
        add_action('leapin_loc_on_main_header', array($this, 'getButtonOnHeader'), 9);

        return $this;
    }


    /**
     * [customiser description]
     * @return [type] [description]
     */
    public function customizer($wp_customize)
    {

        $this->registerCustomizerSettings('features', $wp_customize);

        return;
    }

    public function registerCustomizerSettings($file_handle = '', $wp_customize)
    {

        require_once get_template_directory() . '/inc/features/customizer/' . sanitize_title($file_handle) . '.php';

        return $this;
    }

    public static function getButtonOnHeader()
    {
        $inst = LEAPIN_Theme_Mod::get_instance();
        $href = $inst->get(LEAPIN_IDs::$leapin_feature_hb_href, LEAPIN_Theme_Mod::$default_leapin_feature_hb_href);
        $target = $inst->get(LEAPIN_IDs::$leapin_feature_hb_link_target) ? '_blank' : '_self';
        $label = sprintf('<span class="main">%s</span>', $inst->get(LEAPIN_IDs::$leapin_feature_hb_label, LEAPIN_Theme_Mod::$default_leapin_feature_hb_label));
        $label_sub = sprintf('<span class="sub">%s</span>', $inst->get(LEAPIN_IDs::$leapin_feature_hb_label_sub, LEAPIN_Theme_Mod::$default_leapin_feature_hb_label_sub));
        $icon = $inst->get(LEAPIN_IDs::$leapin_feature_hb_icon, LEAPIN_Theme_Mod::$default_leapin_feature_hb_icon);
        if(leapin_is_mod_visible(LEAPIN_IDs::$leapin_feature_hb_hide, true)){
            printf('<a class="header-feature-button" href="%s" target="%s"><span class="icon">%s</span><span class="label">%s</span></a>', esc_url($href), $target, $icon , $label . $label_sub);
        }
    }
}
new LEAPIN_Features();
