<?php
/**
 * hexagon: Customizer
 *
 * @subpackage hexagon
 * @since 1.0
 */

function hexagon_customize_register( $wp_customize ) {

	$wp_customize->add_setting('hexagon_logo_padding',array(
		'sanitize_callback'	=> 'esc_html'
	));
	$wp_customize->add_control('hexagon_logo_padding',array(
		'label' => __('Logo Padding','hexagon'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('hexagon_logo_top_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_logo_top_padding',array(
		'type' => 'number',
		'description' => __('Top','hexagon'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('hexagon_logo_bottom_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_logo_bottom_padding',array(
		'type' => 'number',
		'description' => __('Bottom','hexagon'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('hexagon_logo_left_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_logo_left_padding',array(
		'type' => 'number',
		'description' => __('Left','hexagon'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('hexagon_logo_right_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_logo_right_padding',array(
		'type' => 'number',
		'description' => __('Right','hexagon'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('hexagon_show_site_title',array(
		'default' => true,
		'sanitize_callback'	=> 'hexagon_sanitize_checkbox'
	));
	$wp_customize->add_control('hexagon_show_site_title',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Title','hexagon'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('hexagon_site_title_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_site_title_font_size',array(
		'type' => 'number',
		'label' => __('Site Title Font Size','hexagon'),
		'section' => 'title_tagline',
	));
	
	$wp_customize->add_setting( 'hexagon_site_title_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
   ));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_site_title_color', array(
		'label' => 'Title Color',
		'section' => 'title_tagline',
	)));

	$wp_customize->add_setting('hexagon_show_tagline',array(
		'default' => true,
		'sanitize_callback'	=> 'hexagon_sanitize_checkbox'
	));
	$wp_customize->add_control('hexagon_show_tagline',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Tagline','hexagon'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('hexagon_site_tagline_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_site_tagline_font_size',array(
		'type' => 'number',
		'label' => __('Site Tagline Font Size','hexagon'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting( 'hexagon_site_tagline_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
   ));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_site_tagline_color', array(
		'label' => 'Tagline Color',
		'section' => 'title_tagline',
	)));

	$wp_customize->add_panel( 'hexagon_panel_id', array(
		'priority' => 10,
		'capability' => 'edit_theme_options',
		'theme_supports' => '',
		'title' => __( 'Theme Settings', 'hexagon' ),
		'description' => __( 'Description of what this panel does.', 'hexagon' ),
	) );

	$wp_customize->add_section( 'hexagon_theme_options_section', array(
    	'title'      => __( 'General Settings', 'hexagon' ),
		'priority'   => 30,
		'panel' => 'hexagon_panel_id'
	) );

	// Add Settings and Controls for Layout
	$wp_customize->add_setting('hexagon_theme_options',array(
        'default' => 'Right Sidebar',
        'sanitize_callback' => 'hexagon_sanitize_choices'	        
	));

	$wp_customize->add_control('hexagon_theme_options',array(
        'type' => 'radio',
        'label' => __('Do you want this section','hexagon'),
        'section' => 'hexagon_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','hexagon'),
            'Right Sidebar' => __('Right Sidebar','hexagon'),
            'One Column' => __('One Column','hexagon'),
            'Three Columns' => __('Three Columns','hexagon'),
            'Four Columns' => __('Four Columns','hexagon'),
            'Grid Layout' => __('Grid Layout','hexagon')
        ),
	));

	$wp_customize->add_setting( 'hexagon_boxfull_width', array(
		'default'           => '',
		'sanitize_callback' => 'hexagon_sanitize_choices'
	));
	$wp_customize->add_control( 'hexagon_boxfull_width', array(
		'label'    => __( 'Section Width', 'hexagon' ),
		'section'  => 'hexagon_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'container'  => __('Box Width', 'hexagon'),
			'container-fluid' => __('Full Width', 'hexagon'),
			'none' => __('None', 'hexagon')
		),
	));

	$wp_customize->add_setting( 'hexagon_dropdown_anim', array(
		'default'           => 'None',
		'sanitize_callback' => 'hexagon_sanitize_choices'
	));
	$wp_customize->add_control( 'hexagon_dropdown_anim', array(
		'label'    => __( 'Menu Dropdown Animations', 'hexagon' ),
		'section'  => 'hexagon_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'bounceInUp'  => __('bounceInUp', 'hexagon'),
			'fadeInUp' => __('fadeInUp', 'hexagon'),
			'zoomIn'    => __('zoomIn', 'hexagon'),
			'None'    => __('None', 'hexagon')
		),
	));

	//Header section
	$wp_customize->add_section( 'hexagon_header_section' , array(
    	'title'      => __( 'Header Settings', 'hexagon' ),
		'priority'   => null,
		'panel' => 'hexagon_panel_id'
	));

	$wp_customize->add_setting( 'hexagon_header_menu_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_header_menu_color', array(
		'label' => 'Menus Color',
		'section' => 'hexagon_header_section',
	)));

	$wp_customize->add_setting( 'hexagon_header_menubdr_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_header_menubdr_color', array(
		'label' => 'Menus Hover Border Color',
		'section' => 'hexagon_header_section',
	)));

	//home page slider
	$wp_customize->add_section( 'hexagon_slider_section' , array(
    	'title'      => __( 'Slider Settings', 'hexagon' ),
		'priority'   => null,
		'panel' => 'hexagon_panel_id'
	) );

	$wp_customize->add_setting('hexagon_slider_hide_show',array(
    	'default' => false,
    	'sanitize_callback'	=> 'hexagon_sanitize_checkbox'
	));
	$wp_customize->add_control('hexagon_slider_hide_show',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide slider','hexagon'),
		'description' => __('Image Size ( 375px x 375px )','hexagon'),
		'section' => 'hexagon_slider_section',
	));

	$wp_customize->add_setting( 'hexagon_slider_effect', array(
		'default'           => '',
		'sanitize_callback' => 'hexagon_sanitize_choices'
	));
	$wp_customize->add_control( 'hexagon_slider_effect', array(
		'label'    => __( 'Onload Transactions Effects', 'hexagon' ),
		'section'  => 'hexagon_slider_section',
		'type'     => 'select',
		'choices'  => array(
			'bounceInLeft'  => __('bounceInLeft', 'hexagon'),
			'bounceInRight' => __('bounceInRight', 'hexagon'),
			'bounceInUp'    => __('bounceInUp', 'hexagon'),
			'bounceInDown'    => __('bounceInDown', 'hexagon'),
			'zoomIn'  => __('zoomIn', 'hexagon'),
			'zoomOut' => __('zoomOut', 'hexagon'),
			'fadeInDown'    => __('fadeInDown', 'hexagon'),
			'fadeInUp'    => __('fadeInUp', 'hexagon'),
			'fadeInLeft'  => __('fadeInLeft', 'hexagon'),
			'fadeInRight' => __('fadeInRight', 'hexagon'),
			'flip-up'    => __('flip-up', 'hexagon'),
			'none'    => __('none', 'hexagon')
		),
	));

	$categories = get_categories();
	$cats = array();
	$i = 0;
	$cat_post[]= 'select';
	foreach($categories as $category){
		if($i==0){
			$default = $category->slug;
			$i++;
		}
		$cat_post[$category->slug] = $category->name;
	}

 	$wp_customize->add_setting('hexagon_slider_cat',array(
    	'default' => 'select',
    	'sanitize_callback' => 'hexagon_sanitize_choices',
  	));
  	$wp_customize->add_control('hexagon_slider_cat',array(
		'type'    => 'select',
		'choices' => $cat_post,
		'label' => __('Select Category To Display Latest Post','hexagon'),
		'section' => 'hexagon_slider_section',
	));

	$wp_customize->add_setting('hexagon_slider_excerpt_length',array(
		'default' => '20',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_slider_excerpt_length',array(
		'type' => 'number',
		'label' => __('Slider Excerpt Length','hexagon'),
		'section' => 'hexagon_slider_section',
	));

	$wp_customize->add_setting('hexagon_slider_title_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_slider_title_font_size',array(
		'type' => 'number',
		'label' => __('Title Font Size','hexagon'),
		'section' => 'hexagon_slider_section',
	));

	$wp_customize->add_setting('hexagon_slider_text_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_slider_text_font_size',array(
		'type' => 'number',
		'label' => __('Text Font Size','hexagon'),
		'section' => 'hexagon_slider_section',
	));

	$wp_customize->add_setting( 'hexagon_slider_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_slider_color', array(
		'label' => 'Text Color',
		'section' => 'hexagon_slider_section',
	)));

	// Our Services 
	$wp_customize->add_section('hexagon_services_section',array(
		'title'	=> __('Our Services','hexagon'),
		'description'=> __('<b>Note :</b> This section will appear below the services.','hexagon'),
		'panel' => 'hexagon_panel_id',
	));
	
	$wp_customize->add_setting('hexagon_section_title',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('hexagon_section_title',array(
		'label'	=> __('Section Title','hexagon'),
		'section'	=> 'hexagon_services_section',
		'setting'	=> 'hexagon_section_title',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('hexagon_services_title_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_services_title_font_size',array(
		'type' => 'number',
		'label' => __('Section Title Font Size','hexagon'),
		'section' => 'hexagon_services_section',
	));

	$categories = get_categories();
	$cats = array();
	$i = 0;
	$cat_pst[]= 'select';
	foreach($categories as $category){
		if($i==0){
			$default = $category->slug;
			$i++;
		}
		$cat_pst[$category->slug] = $category->name;
	}

	$wp_customize->add_setting('hexagon_services_cat',array(
		'default'	=> 'select',
		'sanitize_callback' => 'hexagon_sanitize_choices',
	));
	$wp_customize->add_control('hexagon_services_cat',array(
		'type'    => 'select',
		'choices' => $cat_pst,
		'label' => __('Select Category To Display Post','hexagon'),
		'section' => 'hexagon_services_section',
	));

	$wp_customize->add_setting('hexagon_service_img_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_service_img_size',array(
		'type' => 'number',
		'label' => __('Image Size','hexagon'),
		'section' => 'hexagon_services_section',
	));

	$wp_customize->add_setting('hexagon_services_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_services_font_size',array(
		'type' => 'number',
		'label' => __('Title Font Size','hexagon'),
		'section' => 'hexagon_services_section',
	));

	$wp_customize->add_setting('hexagon_service_section_padding',array(
      'default' => '',
      'sanitize_callback'	=> 'hexagon_sanitize_float'
	));
	$wp_customize->add_control('hexagon_service_section_padding',array(
		'type' => 'number',
		'label' => __('Section Top Bottom Padding','hexagon'),
		'section' => 'hexagon_services_section',
	));

   	$wp_customize->add_setting( 'hexagon_title_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
 	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_title_color', array(
		'label' => 'Section Title Color',
		'section' => 'hexagon_services_section',
	)));

	$wp_customize->add_setting( 'hexagon_service_title_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
  	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_service_title_color', array(
		'label' => 'Title Color',
		'section' => 'hexagon_services_section',
	)));

	$wp_customize->add_setting( 'hexagon_service_btn_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
  	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_service_btn_color', array(
		'label' => 'Button Text Color',
		'section' => 'hexagon_services_section',
	)));

	$wp_customize->add_setting( 'hexagon_servicebg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
  	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'hexagon_servicebg_color', array(
		'label' => 'Box Bg Color',
		'section' => 'hexagon_services_section',
	)));

	//Footer
   	$wp_customize->add_section( 'hexagon_footer', array(
    	'title'      => __( 'Footer Text', 'hexagon' ),
		'priority'   => null,
		'panel' => 'hexagon_panel_id'
	) );

	$wp_customize->add_setting('hexagon_show_back_totop',array(
 		'default' => true,
   	'sanitize_callback'	=> 'hexagon_sanitize_checkbox'
	));
	$wp_customize->add_control('hexagon_show_back_totop',array(
   	'type' => 'checkbox',
   	'label' => __('Show / Hide Back to Top','hexagon'),
   	'section' => 'hexagon_footer'
	));

 	$wp_customize->add_setting('hexagon_footer_link',array(
		'default'	=> 'https://www.luzuk.com/products/free-hexagon-wordpress-theme/',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('hexagon_footer_link',array(
		'label'	=> __('Footer Link','hexagon'),
		'section'	=> 'hexagon_footer',
		'setting'	=> 'hexagon_footer_link',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('hexagon_footer_copy',array(
		'default'	=> 'Hexagon WordPress Theme By Luzuk',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('hexagon_footer_copy',array(
		'label'	=> __('Footer Text','hexagon'),
		'section'	=> 'hexagon_footer',
		'setting'	=> 'hexagon_footer_copy',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('hexagon_copyright_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'hexagon_sanitize_float'
 	));
 	$wp_customize->add_control('hexagon_copyright_padding',array(
		'type' => 'number',
		'label' => __('Copyright Top Bottom Padding','hexagon'),
		'section' => 'hexagon_footer',
	));

	$wp_customize->get_setting( 'blogname' )->transport          = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport   = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport  = 'postMessage';

	$wp_customize->selective_refresh->add_partial( 'blogname', array(
		'selector' => '.site-title a',
		'render_callback' => 'hexagon_customize_partial_blogname',
	) );
	$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
		'selector' => '.site-description',
		'render_callback' => 'hexagon_customize_partial_blogdescription',
	) );
}
add_action( 'customize_register', 'hexagon_customize_register' );

function hexagon_customize_partial_blogname() {
	bloginfo( 'name' );
}

function hexagon_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

function hexagon_is_static_front_page() {
	return ( is_front_page() && ! is_home() );
}

function hexagon_is_view_with_layout_option() {
	// This option is available on all pages. It's also available on archives when there isn't a sidebar.
	return ( is_page() || ( is_archive() && ! is_active_sidebar( 'sidebar-1' ) ) );
}

/**
 * Singleton class for handling the theme's customizer integration.
 *
 * @since  1.0.0
 * @access public
 */
final class Hexagon_Customize {

	/**
	 * Returns the instance.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return object
	 */
	public static function get_instance() {

		static $instance = null;

		if ( is_null( $instance ) ) {
			$instance = new self;
			$instance->setup_actions();
		}

		return $instance;
	}

	/**
	 * Constructor method.
	 *
	 * @since  1.0.0
	 * @access private
	 * @return void
	 */
	private function __construct() {}

	/**
	 * Sets up initial actions.
	 *
	 * @since  1.0.0
	 * @access private
	 * @return void
	 */
	private function setup_actions() {

		// Register panels, sections, settings, controls, and partials.
		add_action( 'customize_register', array( $this, 'sections' ) );

		// Register scripts and styles for the controls.
		add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ), 0 );
	}

	/**
	 * Sets up the customizer sections.
	 *
	 * @since  1.0.0
	 * @access public
	 * @param  object  $manager
	 * @return void
	 */
	public function sections( $manager ) {

		// Load custom sections.
		load_template( trailingslashit( get_template_directory() ) . '/inc/section-pro.php' );

		// Register custom section types.
		$manager->register_section_type( 'Hexagon_Customize_Section_Pro' );

		// Register sections.
		$manager->add_section(
			new Hexagon_Customize_Section_Pro(
				$manager,
				'hexagon_example_1',
				array(
					'priority' => 9,
					'title'    => esc_html__( 'Hexagon Pro ', 'hexagon' ),
					'pro_text' => esc_html__( 'Go Pro','hexagon' ),
					'pro_url'  => esc_url( 'https://www.luzuk.com/products/hexagon-wordpress-theme/' ),
				)
			)
		);
	}

	/**
	 * Loads theme customizer CSS.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return void
	 */
	public function enqueue_control_scripts() {

		wp_enqueue_script( 'hexagon-customize-controls', trailingslashit( esc_url(get_template_directory_uri()) ) . '/assets/js/customize-controls.js', array( 'customize-controls' ) );

		wp_enqueue_style( 'hexagon-customize-controls', trailingslashit( esc_url(get_template_directory_uri()) ) . '/assets/css/customize-controls.css' );
	}
}

// Doing this customizer thang!
Hexagon_Customize::get_instance();