<?php
class Themia_Customizer {
    public static function Themia_Register($wp_customize) {
        self::Themia_Sections($wp_customize);
        self::Themia_Controls($wp_customize);
    }
    public static function Themia_Sections($wp_customize) {
        /**
         * General Section
         */
        $wp_customize->add_section('general_setting', array(
            'title' => __('General Settings', 'themia-lite'),
            'description' => __('Allows you to customize header logo, favicon etc settings for Themia Theme.', 'themia-lite'), //Descriptive tooltip
            'panel' => '',
            'priority' => '10',
            'capability' => 'edit_theme_options'
                )
        );
        /**
         * Home Page Top Section
         */
        $wp_customize->add_section('home_top_section', array(
            'title' => __('Top Feature Image Section', 'themia-lite'),
            'description' => __('Allows you to setup Top Feature Image for Themia Theme.', 'themia-lite'), //Descriptive tooltip
            'panel' => '',
            'priority' => '11',
            'capability' => 'edit_theme_options'
                )
        );
        /**
        * Add panel for home page feature area
        */
        $wp_customize->add_panel('home_feature_area_panel', array(
            'title' => __('Home Page Feature Area', 'themia-lite'),
            'description' => __('Allows you to setup home page feature area section for Themia Theme.', 'themia-lite'),
            'priority' => '12',
            'capability' => 'edit_theme_options'
        ));
        /**
         * Home Page feature area 1
         */
        $wp_customize->add_section('home_feature_area_1', array(
            'title' => __('First Feature Area', 'themia-lite'),
            'description' => __('Allows you to setup first feature area section for Themia Theme.', 'themia-lite'),
            'panel' => 'home_feature_area_panel',
            'priority' => '',
            'capability' => 'edit_theme_options'
                )
        );
        /**
         * Home Page feature area 2
         */
        $wp_customize->add_section('home_feature_area_2', array(
            'title' => __('Second Feature Area', 'themia-lite'),
            'description' => __('Allows you to setup second feature area section for Themia Theme.', 'themia-lite'),
            'panel' => 'home_feature_area_panel',
            'priority' => '',
            'capability' => 'edit_theme_options'
                )
        );
        /**
         * Home Page feature area 3
         */
        $wp_customize->add_section('home_feature_area_3', array(
            'title' => __('Third Feature Area', 'themia-lite'),
            'description' => __('Allows you to setup third feature area section for Themia Theme.', 'themia-lite'),
            'panel' => 'home_feature_area_panel',
            'priority' => '',
            'capability' => 'edit_theme_options'
                )
        );
    }
    public static function Themia_Section_Content() {
        $section_content = array(
            'general_setting' => array(
                'inkthemes_logo',
                'inkthemes_favicon'
            ),
            'home_top_section' => array(
                'inkthemes_featureimg'
            ),
            'home_feature_area_1' => array(
                'inkthemes_headline1',
                'inkthemes_img1',
                'inkthemes_feature1',
                'inkthemes_link1'
            ),
            'home_feature_area_2' => array(
                'inkthemes_headline2',
                'inkthemes_img2',
                'inkthemes_feature2',
                'inkthemes_link2'
            ),
            'home_feature_area_3' => array(
                'inkthemes_headline3',
                'inkthemes_img3',
                'inkthemes_feature3',
                'inkthemes_link3'
            ),
            );
        return $section_content;
    }
    public static function Themia_Settings() {
        $bizway_settings = array(
            'inkthemes_logo' => array(
                'id' => 'inkthemes_options[inkthemes_logo]',
                'label' => __('Custom Logo', 'themia-lite'),
                'description' => __('Choose your own logo. Optimal Size: 300px Wide by 90px Height.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'image',
                'default' => get_template_directory_uri() . '/images/logo.png'
            ),
            'inkthemes_favicon' => array(
                'id' => 'inkthemes_options[inkthemes_favicon]',
                'label' => __('Custom Favicon', 'themia-lite'),
                'description' => __('Specify a 16px x 16px image that will represent your website&#039;s favicon.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'image',
                'default' => ''
            ),
            'inkthemes_featureimg' => array(
                'id' => 'inkthemes_options[inkthemes_featureimg]',
                'label' => __('First Slider Image', 'themia-lite'),
                'description' => __('Choose a image for top feature. Optimal size: 928px x 355px', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'image',
                'default' => get_template_directory_uri() . '/images/slideimg.jpg'
            ),            
            'inkthemes_headline1' => array(
                'id' => 'inkthemes_options[inkthemes_headline1]',
                'label' => __('First Feature Heading', 'themia-lite'),
                'description' => __('Enter your text for first feature area heading.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => __('Four Different Skins', 'themia-lite')
            ),
            'inkthemes_img1' => array(
                'id' => 'inkthemes_options[inkthemes_img1]',
                'label' => __('First Feature Image', 'themia-lite'),
                'description' => __('Choose your image for first feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'image',
                'default' => get_template_directory_uri() . '/images/featureimg-1.jpg'
            ),
            'inkthemes_feature1' => array(
                'id' => 'inkthemes_options[inkthemes_feature1]',
                'label' => __('First Feature Description', 'themia-lite'),
                'description' => __('Enter your text for first feature area description.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => __('Just a Click and your website is ready for use. Your Site is faster to built, easy to use & Search Engine Optimized.', 'themia-lite')
            ),
            'inkthemes_link1' => array(
                'id' => 'inkthemes_options[inkthemes_link1]',
                'label' => __('First feature Link', 'themia-lite'),
                'description' => __('Enter your link url for first feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'link',
                'default' => '#'
            ),            
            'inkthemes_headline2' => array(
                'id' => 'inkthemes_options[inkthemes_headline2]',
                'label' => __('Second Feature Heading', 'themia-lite'),
                'description' => __('Enter your text for second feature area heading.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => __('Amazing Shortcodes', 'themia-lite')
            ),
            'inkthemes_img2' => array(
                'id' => 'inkthemes_options[inkthemes_img2]',
                'label' => __('Second Feature Image', 'themia-lite'),
                'description' => __('Choose your image for second feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'image',
                'default' => get_template_directory_uri() . '/images/featureimg-2.jpg'
            ),
            'inkthemes_feature2' => array(
                'id' => 'inkthemes_options[inkthemes_feature2]',
                'label' => __('Second Feature Description', 'themia-lite'),
                'description' => __('Write short description for your second feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => __('Just a Click and your website is ready for use. Your Site is faster to built, easy to use & Search Engine Optimized.', 'themia-lite')
            ),
            'inkthemes_link2' => array(
                'id' => 'inkthemes_options[inkthemes_link2]',
                'label' => __('Second Feature Link', 'themia-lite'),
                'description' => __('Enter your link url for second feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'link',
                'default' => '#'
            ),            
            'inkthemes_headline3' => array(
                'id' => 'inkthemes_options[inkthemes_headline3]',
                'label' => __('Third Feature Heading', 'themia-lite'),
                'description' => __('Enter your text for second feature area heading.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => __('Full Localisation Support', 'themia-lite')
            ),
            'inkthemes_img3' => array(
                'id' => 'inkthemes_options[inkthemes_img3]',
                'label' => __('Third Feature Image', 'themia-lite'),
                'description' => __('Choose your image for Third feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'image',
                'default' => get_template_directory_uri() . '/images/featureimg-3.jpg'
            ),
            'inkthemes_feature3' => array(
                'id' => 'inkthemes_options[inkthemes_feature3]',
                'label' => __('Third Feature Description', 'themia-lite'),
                'description' => __('Enter your text for Third feature area description.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => __('Just a Click and your website is ready for use. Your Site is faster to built, easy to use & Search Engine Optimized.', 'themia-lite')
            ),
            'inkthemes_link3' => array(
                'id' => 'inkthemes_options[inkthemes_link3]',
                'label' => __('Third feature Link', 'themia-lite'),
                'description' => __('Enter your link url for third feature area.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'link',
                'default' => '#'
            ),
            'bizway_customcss' => array(
                'id' => 'inkthemes_options[bizway_customcss]',
                'label' => __('Custom CSS', 'themia-lite'),
                'description' => __('Quickly add your custom CSS code to your theme by writing the code in this block.', 'themia-lite'),
                'type' => 'option',
                'setting_type' => 'textarea',
                'default' => ''
            )
        );
        return $bizway_settings;
    }
    public static function Themia_Controls($wp_customize) {
        $sections = self::Themia_Section_Content();
        $settings = self::Themia_Settings();
        foreach ($sections as $section_id => $section_content) {
            foreach ($section_content as $section_content_id) {
                switch ($settings[$section_content_id]['setting_type']) {
                    case 'image':
                        self::add_setting($wp_customize, $settings[$section_content_id]['id'], $settings[$section_content_id]['default'], $settings[$section_content_id]['type'], 'bizway_sanitize_url');
                        $wp_customize->add_control(new WP_Customize_Image_Control(
                                $wp_customize, $settings[$section_content_id]['id'], array(
                            'label' => $settings[$section_content_id]['label'],
                            'description' => $settings[$section_content_id]['description'],
                            'section' => $section_id,
                            'settings' => $settings[$section_content_id]['id']
                                )
                        ));
                        break;
                    case 'text':
                        self::add_setting($wp_customize, $settings[$section_content_id]['id'], $settings[$section_content_id]['default'], $settings[$section_content_id]['type'], 'bizway_sanitize_text');
                        $wp_customize->add_control(new WP_Customize_Control(
                                $wp_customize, $settings[$section_content_id]['id'], array(
                            'label' => $settings[$section_content_id]['label'],
                            'description' => $settings[$section_content_id]['description'],
                            'section' => $section_id,
                            'settings' => $settings[$section_content_id]['id'],
                            'type' => 'text'
                                )
                        ));
                        break;
                    case 'textarea':
                        self::add_setting($wp_customize, $settings[$section_content_id]['id'], $settings[$section_content_id]['default'], $settings[$section_content_id]['type'], 'bizway_sanitize_textarea');
                        $wp_customize->add_control(new WP_Customize_Control(
                                $wp_customize, $settings[$section_content_id]['id'], array(
                            'label' => $settings[$section_content_id]['label'],
                            'description' => $settings[$section_content_id]['description'],
                            'section' => $section_id,
                            'settings' => $settings[$section_content_id]['id'],
                            'type' => 'textarea'
                                )
                        ));
                        break;
                    case 'link':
                        self::add_setting($wp_customize, $settings[$section_content_id]['id'], $settings[$section_content_id]['default'], $settings[$section_content_id]['type'], 'bizway_sanitize_url');
                        $wp_customize->add_control(new WP_Customize_Control(
                                $wp_customize, $settings[$section_content_id]['id'], array(
                            'label' => $settings[$section_content_id]['label'],
                            'description' => $settings[$section_content_id]['description'],
                            'section' => $section_id,
                            'settings' => $settings[$section_content_id]['id'],
                            'type' => 'text'
                                )
                        ));
                        break;
                    default:
                        break;
                }
            }
        }
    }
    public static function add_setting($wp_customize, $setting_id, $default, $type, $sanitize_callback) {
        $wp_customize->add_setting($setting_id, array(
            'default' => $default,
            'capability' => 'edit_theme_options',
            'sanitize_callback' => array('Themia_Customizer', $sanitize_callback),
            'type' => $type
                )
        );
    }
    /**
     * adds sanitization callback funtion : textarea
     * @package Themia
     */
    public static function bizway_sanitize_textarea($value) {
        $value = esc_html($value);
        return $value;
    }
    /**
     * adds sanitization callback funtion : url
     * @package Themia
     */
    public static function bizway_sanitize_url($value) {
        $value = esc_url($value);
        return $value;
    }
    /**
     * adds sanitization callback funtion : text
     * @package Themia
     */
    public static function bizway_sanitize_text($value) {
        $value = sanitize_text_field($value);
        return $value;
    }
    /**
     * adds sanitization callback funtion : email
     * @package Themia
     */
    public static function bizway_sanitize_email($value) {
        $value = sanitize_email($value);
        return $value;
    }
    /**
     * adds sanitization callback funtion : number
     * @package Themia
     */
    public static function bizway_sanitize_number($value) {
        $value = preg_replace("/[^0-9+ ]/", "", $value);
        return $value;
    }
}
// Setup the Theme Customizer settings and controls...
add_action('customize_register', array('Themia_Customizer', 'Themia_Register'));
function inkthemes_registers() {
          wp_register_script( 'inkthemes_jquery_ui', '//code.jquery.com/ui/1.11.0/jquery-ui.js', array("jquery"), true  );
	wp_register_script( 'inkthemes_customizer_script', get_template_directory_uri() . '/functions/js/inkthemes_customizer.js', array("jquery","inkthemes_jquery_ui"), true  );
	wp_enqueue_script( 'inkthemes_customizer_script' );
	wp_localize_script( 'inkthemes_customizer_script', 'ink_advert', array(
		'pro' => __('View PRO version','themia-lite'),
		'url' => esc_url('http://www.inkthemes.com/wp-themes/simple-and-unique-wordpress-theme/'),
		'support_text' => __('Need Help!','themia-lite'),
		'support_url' => esc_url('http://www.inkthemes.com/lets-connect/'),
	) );
}
add_action( 'customize_controls_enqueue_scripts', 'inkthemes_registers' );