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

use WPTRT\Customize\Section\Musicians_Button;

add_action( 'customize_register', function( $manager ) {

	$manager->register_section_type( Musicians_Button::class );

	$manager->add_section(
		new Musicians_Button( $manager, 'musicians_pro', [
			'title' => __( 'Musicians Pro', 'musicians' ),
			'priority' => 0,
			'button_text' => __( 'Go Pro', 'musicians' ),
			'button_url'  => esc_url( 'https://www.luzuk.com/products/best-wordpress-themes-for-musicians', 'musicians')
		] )
	);

} );

// Load the JS and CSS.
add_action( 'customize_controls_enqueue_scripts', function() {

	$version = wp_get_theme()->get( 'Version' );

	wp_enqueue_script(
		'musicians-customize-section-button',
		get_theme_file_uri( 'vendor/wptrt/customize-section-button/public/js/customize-controls.js' ),
		[ 'customize-controls' ],
		$version,
		true
	);

	wp_enqueue_style(
		'musicians-customize-section-button',
		get_theme_file_uri( 'vendor/wptrt/customize-section-button/public/css/customize-controls.css' ),
		[ 'customize-controls' ],
 		$version
	);

} );

function musicians_customize_register( $wp_customize ) {

	$wp_customize->add_setting('musicians_logo_size',array(
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_logo_size',array(
		'type' => 'range',
		'label' => __('Logo Size','musicians'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('musicians_logo_padding',array(
		'sanitize_callback'	=> 'esc_html'
	));
	$wp_customize->add_control('musicians_logo_padding',array(
		'label' => __('Logo Margin','musicians'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('musicians_logo_top_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_logo_top_padding',array(
		'type' => 'number',
		'description' => __('Top','musicians'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('musicians_logo_bottom_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_logo_bottom_padding',array(
		'type' => 'number',
		'description' => __('Bottom','musicians'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('musicians_logo_left_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_logo_left_padding',array(
		'type' => 'number',
		'description' => __('Left','musicians'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('musicians_logo_right_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
 	));
 	$wp_customize->add_control('musicians_logo_right_padding',array(
		'type' => 'number',
		'description' => __('Right','musicians'),
		'section' => 'title_tagline',
    ));

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

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

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

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

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

	$wp_customize->add_section( 'musicians_theme_options_section', array(
    	'title'      => __( 'General Settings', 'musicians' ),
		'priority'   => 30,
		'panel' => 'musicians_panel_id'
	) );

	$wp_customize->add_setting('musicians_theme_options',array(
		'default' => 'One Column',
		'sanitize_callback' => 'musicians_sanitize_choices'
	));
	$wp_customize->add_control('musicians_theme_options',array(
		'type' => 'select',
		'label' => __('Blog Page Sidebar Layout','musicians'),
		'section' => 'musicians_theme_options_section',
		'choices' => array(
		   'Left Sidebar' => __('Left Sidebar','musicians'),
		   'Right Sidebar' => __('Right Sidebar','musicians'),
		   'One Column' => __('One Column','musicians'),
		   'Grid Layout' => __('Grid Layout','musicians')
		),
	));

	$wp_customize->add_setting('musicians_single_post_sidebar',array(
		'default' => 'Right Sidebar',
		'sanitize_callback' => 'musicians_sanitize_choices'
	));
	$wp_customize->add_control('musicians_single_post_sidebar',array(
        'type' => 'select',
        'label' => __('Single Post Sidebar Layout','musicians'),
        'section' => 'musicians_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','musicians'),
            'Right Sidebar' => __('Right Sidebar','musicians'),
            'One Column' => __('One Column','musicians')
        ),
	));

	$wp_customize->add_setting('musicians_page_sidebar',array(
		'default' => 'One Column',
		'sanitize_callback' => 'musicians_sanitize_choices'
	));
	$wp_customize->add_control('musicians_page_sidebar',array(
        'type' => 'select',
        'label' => __('Page Sidebar Layout','musicians'),
        'section' => 'musicians_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','musicians'),
            'Right Sidebar' => __('Right Sidebar','musicians'),
            'One Column' => __('One Column','musicians')
        ),
	));

	$wp_customize->add_setting('musicians_archive_page_sidebar',array(
		'default' => 'One Column',
		'sanitize_callback' => 'musicians_sanitize_choices'
	));
	$wp_customize->add_control('musicians_archive_page_sidebar',array(
        'type' => 'select',
        'label' => __('Archive & Search Page Sidebar Layout','musicians'),
        'section' => 'musicians_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','musicians'),
            'Right Sidebar' => __('Right Sidebar','musicians'),
            'One Column' => __('One Column','musicians'),
            'Grid Layout' => __('Grid Layout','musicians')
        ),
	));

	$wp_customize->add_setting( 'musicians_boxfull_width', array(
		'default'           => '',
		'sanitize_callback' => 'musicians_sanitize_choices'
	));
	$wp_customize->add_control( 'musicians_boxfull_width', array(
		'label'    => __( 'Section Width', 'musicians' ),
		'section'  => 'musicians_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'container'  => __('Box Width', 'musicians'),
			'container-fluid' => __('Full Width', 'musicians'),
			'none' => __('None', 'musicians')
		),
	));

	$wp_customize->add_setting( 'musicians_dropdown_anim', array(
		'default'           => 'None',
		'sanitize_callback' => 'musicians_sanitize_choices'
	));
	$wp_customize->add_control( 'musicians_dropdown_anim', array(
		'label'    => __( 'Menu Dropdown Animations', 'musicians' ),
		'section'  => 'musicians_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'bounceInUp'  => __('bounceInUp', 'musicians'),
			'fadeInUp' => __('fadeInUp', 'musicians'),
			'zoomIn'    => __('zoomIn', 'musicians'),
			'None'    => __('None', 'musicians')
		),
	));

	//home page header
	$wp_customize->add_section( 'musicians_header_section' , array(
    	'title'    => __( 'Header Settings', 'musicians' ),
		'priority' => null,
		'panel' => 'musicians_panel_id'
	) );

	$wp_customize->add_setting('musicians_headerbuttontext',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_headerbuttontext',array(
		'label'	=> __('Button Text','musicians'),
		'section' => 'musicians_header_section',
		'type' => 'text'
	));

	$wp_customize->add_setting('musicians_headerbuttonlink',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_headerbuttonlink',array(
		'label'	=> __('Button Link','musicians'),
		'section' => 'musicians_header_section',
		'type' => 'text'
	));

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

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

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

	$wp_customize->add_setting( 'musicians_header_btnbg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'musicians_header_btnbg_color', array(
		'label' => 'Button Bg Color',
		'section' => 'musicians_header_section',
	)));

	//home page slider
	$wp_customize->add_section( 'musicians_slider_section' , array(
    	'title'    => __( 'Slider Settings', 'musicians' ),
		'priority' => null,
		'panel' => 'musicians_panel_id'
	) );

	$wp_customize->add_setting('musicians_slider_hide_show',array(
    	'default' => false,
    	'sanitize_callback'	=> 'musicians_sanitize_checkbox'
	));
	$wp_customize->add_control('musicians_slider_hide_show',array(
	   	'type' => 'checkbox',
	   	'label' => __('Show / Hide Slider','musicians'),
	   	'section' => 'musicians_slider_section',
	));

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

	for ( $count = 1; $count <= 4; $count++ ) {
		$wp_customize->add_setting( 'musicians_slider' . $count, array(
			'default'           => '',
			'sanitize_callback' => 'musicians_sanitize_dropdown_pages'
		));
		$wp_customize->add_control( 'musicians_slider' . $count, array(
			'label' => __('Select Slider Image Page', 'musicians' ),
			'section' => 'musicians_slider_section',
			'type' => 'dropdown-pages'
		));
	}

	$wp_customize->add_setting('musicians_slider_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_slider_font_size',array(
		'type' => 'number',
		'label' => __('Title Font Size','musicians'),
		'section' => 'musicians_slider_section',
	));

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

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

	//Feature Section
	$wp_customize->add_section('musicians_feature_section',array(
		'title'	=> __('Feature Section','musicians'),
		'description'=> __('<b>Note :</b> This section will appear below the Banner.','musicians'),
		'panel' => 'musicians_panel_id',
	));
 
    $wp_customize->add_setting('musicians_section_titleservice',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_section_titleservice',array(
		'label'	=> __('Section Title','musicians'),
		'section' => 'musicians_feature_section',
		'type' => 'text'
	));

	$wp_customize->add_setting('musicians_section_titleservice_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_section_titleservice_font_size',array(
		'type' => 'number',
		'label' => __('Font Size','musicians'),
		'section' => 'musicians_feature_section',
	));

	$wp_customize->add_setting('musicians_section_subtitleservice',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_section_subtitleservice',array(
		'label'	=> __('Section SubTitle','musicians'),
		'section' => 'musicians_feature_section',
		'type' => 'text'
	));

	$wp_customize->add_setting('musicians_section_subtitleservice_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'musicians_sanitize_float'
	));
	$wp_customize->add_control('musicians_section_subtitleservice_font_size',array(
		'type' => 'number',
		'label' => __('Font Size','musicians'),
		'section' => 'musicians_feature_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('musicians_category_settingfeature',array(
		'default' => 'select',
		'sanitize_callback' => 'musicians_sanitize_choices',
	));
	$wp_customize->add_control('musicians_category_settingfeature',array(
		'type' => 'select',
		'choices' => $cat_pst,
		'label' => __('Select Category To Display Post','musicians'),
		'section' => 'musicians_feature_section',
	));


	$wp_customize->add_setting('musicians_features_number',array(
		'default'	=> '4',
		'sanitize_callback'	=> 'sanitize_text_field',
	));
	$wp_customize->add_control('musicians_features_number',array(
		'label'	=> __('Number Of Icons To Show In A Category','musicians'),
		'section' => 'musicians_feature_section',
		'type'	  => 'number'
	));

	$musicians_features_number = get_theme_mod('musicians_features_number', 4);
	for ($i=1; $i <= $musicians_features_number; $i++) { 
	   	$wp_customize->add_setting('musicians_feature_icon' . $i, array(
	      	'default' => 'fa fa-music',
	      	'sanitize_callback' => 'sanitize_text_field'
	   	));
	   	$wp_customize->add_control(new musicians_Fontawesome_Icon_Chooser($wp_customize, 'musicians_feature_icon' . $i, array(
	      	'section' => 'musicians_feature_section',
	      	'type' => 'icon',
	      	'label' => esc_html__('Feature Icon ', 'musicians') . $i
	  	)));
	}


	//Service Section
	$wp_customize->add_section('musicians_service_section',array(
		'title'	=> __('Service Section','musicians'),
		'description'=> __('<b>Note :</b> This section will appear below the Feature.','musicians'),
		'panel' => 'musicians_panel_id',
	));

 
    $wp_customize->add_setting('musicians_section_title',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_section_title',array(
		'label'	=> __('Section Title','musicians'),
		'section' => 'musicians_service_section',
		'type' => 'text'
	));

	$wp_customize->add_setting('musicians_section_subtitle',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_section_subtitle',array(
		'label'	=> __('Section SubTitle','musicians'),
		'section' => 'musicians_service_section',
		'type' => 'text'
	));

	$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('musicians_category_setting',array(
		'default' => 'select',
		'sanitize_callback' => 'musicians_sanitize_choices',
	));
	$wp_customize->add_control('musicians_category_setting',array(
		'type' => 'select',
		'choices' => $cat_pst,
		'label' => __('Select Category To Display Post','musicians'),
		'section' => 'musicians_service_section',
	));

	//Footer
    $wp_customize->add_section( 'musicians_footer', array(
    	'title'  => __( 'Footer Text', 'musicians' ),
		'priority' => null,
		'panel' => 'musicians_panel_id'
	) );

	$wp_customize->add_setting('musicians_show_back_totop',array(
       'default' => true,
       'sanitize_callback'	=> 'musicians_sanitize_checkbox'
    ));
    $wp_customize->add_control('musicians_show_back_totop',array(
       'type' => 'checkbox',
       'label' => __('Show / Hide Back to Top','musicians'),
       'section' => 'musicians_footer'
    ));

    $wp_customize->add_setting('musicians_footer_copy',array(
		'default' => 'Musicians WordPress Theme By Luzuk',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('musicians_footer_copy',array(
		'label'	=> __('Footer Text','musicians'),
		'section' => 'musicians_footer',
		'setting' => 'musicians_footer_copy',
		'type' => 'text'
	));

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

	$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' => 'musicians_customize_partial_blogname',
	) );
	$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
		'selector' => '.site-description',
		'render_callback' => 'musicians_customize_partial_blogdescription',
	) );
}
add_action( 'customize_register', 'musicians_customize_register' );

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

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

if (class_exists('WP_Customize_Control')) {

   	class musicians_Fontawesome_Icon_Chooser extends WP_Customize_Control {

      	public $type = 'icon';

      	public function render_content() { ?>
	     	<label>
	            <span class="customize-control-title">
	               <?php echo esc_html($this->label); ?>
	            </span>

	            <?php if ($this->description) { ?>
	                <span class="description customize-control-description">
	                   <?php echo wp_kses_post($this->description); ?>
	                </span>
	            <?php } ?>

	            <div class="musicians-selected-icon">
	                <i class="fa <?php echo esc_attr($this->value()); ?>"></i>
	                <span><i class="fa fa-angle-down"></i></span>
	            </div>

	            <ul class="musicians-icon-list clearfix">
	                <?php
	                $musicians_font_awesome_icon_array = musicians_font_awesome_icon_array();
	                foreach ($musicians_font_awesome_icon_array as $musicians_font_awesome_icon) {
	                   $icon_class = $this->value() == $musicians_font_awesome_icon ? 'icon-active' : '';
	                   echo '<li class=' . esc_attr($icon_class) . '><i class="' . esc_attr($musicians_font_awesome_icon) . '"></i></li>';
	                }
	                ?>
	            </ul>
	            <input type="hidden" value="<?php $this->value(); ?>" <?php $this->link(); ?> />
	        </label>
	        <?php
      	}
  	}
}
function musicians_customizer_script() {
   wp_enqueue_style( 'font-awesome-1', get_template_directory_uri().'/assets/css/fontawesome-all.css');
}
add_action( 'customize_controls_enqueue_scripts', 'musicians_customizer_script' );