<?php
/**
 * Mobile Repair: Customizer
 *
 * @subpackage Mobile Repair
 * @since 1.0
 */

use WPTRT\Customize\Section\Mobile_Repair_Button;

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

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

	$manager->add_section(
		new Mobile_Repair_Button( $manager, 'mobile_repair_pro', [
			'title'      => __( 'Mobile Repair Pro', 'mobile-repair' ),
			'priority'    => 0,
			'button_text' => __( 'Go Pro', 'mobile-repair' ),
			'button_url'  => esc_url( 'https://www.luzuk.com/products/mobile-repair-wordpress-theme/', 'mobile-repair')
		] )
	);

} );

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

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

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

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

} );

function mobile_repair_customize_register( $wp_customize ) {

	$wp_customize->add_setting('mobile_repair_logo_size',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_logo_size',array(
		'type' => 'range',
		'description' => __('Logo Size (0-100%)','mobile-repair'),
		'section' => 'title_tagline',
	));

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

	$wp_customize->add_setting('mobile_repair_logo_top_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_logo_top_padding',array(
		'type' => 'number',
		'description' => __('Top','mobile-repair'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('mobile_repair_logo_bottom_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_logo_bottom_padding',array(
		'type' => 'number',
		'description' => __('Bottom','mobile-repair'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('mobile_repair_logo_left_padding',array(
		'default' => '',
		'sanitize_callback' => 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_logo_left_padding',array(
		'type' => 'number',
		'description' => __('Left','mobile-repair'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('mobile_repair_logo_right_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_logo_right_padding',array(
		'type' => 'number',
		'description' => __('Right','mobile-repair'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('mobile_repair_show_site_title',array(
		'default' => true,
		'sanitize_callback'	=> 'mobile_repair_sanitize_checkbox'
	));
	$wp_customize->add_control('mobile_repair_show_site_title',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Title','mobile-repair'),
		'section' => 'title_tagline'
	));
 
	$wp_customize->add_setting('mobile_repair_show_site_title_color',array(
		'default' => '#fff',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_show_site_title_color',array(
		'type' => 'color',
		'label' => __('Site Title Color','mobile-repair'),
		'section' => 'title_tagline'
	));


	$wp_customize->add_setting('mobile_repair_site_title_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_site_title_font_size',array(
		'type' => 'number',
		'label' => __('Site Title Font Size','mobile-repair'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('mobile_repair_show_tagline',array(
		'default' => true,
		'sanitize_callback'	=> 'mobile_repair_sanitize_checkbox'
	));
	$wp_customize->add_control('mobile_repair_show_tagline',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Tagline','mobile-repair'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('mobile_repair_show_site_tagline_color',array(
		'default' => '#fff',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_show_site_tagline_color',array(
		'type' => 'color',
		'label' => __('Site Tagline Color','mobile-repair'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('mobile_repair_site_tagline_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_site_tagline_font_size',array(
		'type' => 'number',
		'label' => __('Site Tagline Font Size','mobile-repair'),
		'section' => 'title_tagline',
	));

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

	$wp_customize->add_section( 'mobile_repair_theme_options_section', array(
    	'title'      => __( 'General Settings', 'mobile-repair' ),
		'priority'   => 30,
		'panel' => 'mobile_repair_panel_id'
	) );

	$wp_customize->add_setting('mobile_repair_theme_options',array(
		'default' => 'Right Sidebar',
		'sanitize_callback' => 'mobile_repair_sanitize_choices'
	));
	$wp_customize->add_control('mobile_repair_theme_options',array(
		'type' => 'radio',
		'label' => __('Do you want this section','mobile-repair'),
		'section' => 'mobile_repair_theme_options_section',
		'choices' => array(
		   'Left Sidebar' => __('Left Sidebar','mobile-repair'),
		   'Right Sidebar' => __('Right Sidebar','mobile-repair'),
		   'One Column' => __('One Column','mobile-repair'),
		   'Three Columns' => __('Three Columns','mobile-repair'),
		   'Four Columns' => __('Four Columns','mobile-repair'),
		   'Grid Layout' => __('Grid Layout','mobile-repair')
		),
	));

	$wp_customize->add_setting( 'mobile_repair_boxfull_width', array(
		'default'           => '',
		'sanitize_callback' => 'mobile_repair_sanitize_choices'
	));
	
	$wp_customize->add_control( 'mobile_repair_boxfull_width', array(
		'label'    => __( 'Section Width', 'mobile-repair' ),
		'section'  => 'mobile_repair_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'container'  => __('Box Width', 'mobile-repair'),
			'container-fluid' => __('Full Width', 'mobile-repair'),
			'none' => __('None', 'mobile-repair')
		),
	));

	$wp_customize->add_setting( 'mobile_repair_dropdown_anim', array(
		'default'           => 'None',
		'sanitize_callback' => 'mobile_repair_sanitize_choices'
	));
	$wp_customize->add_control( 'mobile_repair_dropdown_anim', array(
		'label'    => __( 'Menu Dropdown Animations', 'mobile-repair' ),
		'section'  => 'mobile_repair_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'bounceInUp'  => __('bounceInUp', 'mobile-repair'),
			'fadeInUp' => __('fadeInUp', 'mobile-repair'),
			'zoomIn'    => __('zoomIn', 'mobile-repair'),
			'None'    => __('None', 'mobile-repair')
		),
	));

	//Bottom Header
	$wp_customize->add_section( 'mobile_repair_header_section' , array(
    	'title'    => __( 'Header', 'mobile-repair' ),
		'priority' => null,
		'panel' => 'mobile_repair_panel_id'
	) );

	$wp_customize->add_setting('mobile_repair_topheader_phone_no',array(
    	'default' => '',
    	'sanitize_callback' => 'mobile_repair_sanitize_phone_number'
	));
	$wp_customize->add_control('mobile_repair_topheader_phone_no',array(
   	'type' => 'text',
   	'label' => __('Add Phone Number','mobile-repair'),
   	'section' => 'mobile_repair_header_section',
	));

	$wp_customize->add_setting('mobile_repair_phone_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_phone_color',array(
		'type' => 'color',
		'label' => __('Number Color','mobile-repair'),
		'section' => 'mobile_repair_header_section'
	));

	$wp_customize->add_setting('mobile_repair_menu_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_menu_color',array(
		'type' => 'color',
		'label' => __('Menu Color','mobile-repair'),
		'section' => 'mobile_repair_header_section'
	));

	$wp_customize->add_setting('mobile_repair_submenu_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_submenu_color',array(
		'type' => 'color',
		'label' => __('Submenu Color','mobile-repair'),
		'section' => 'mobile_repair_header_section'
	));

	//home page slider
	$wp_customize->add_section( 'mobile_repair_slider_section' , array(
    	'title'    => __( 'Slider Settings', 'mobile-repair' ),
		'priority' => null,
		'panel' => 'mobile_repair_panel_id'
	) );

	$wp_customize->add_setting('mobile_repair_slider_hide_show',array(
    	'default' => false,
    	'sanitize_callback'	=> 'mobile_repair_sanitize_checkbox'
	));
	$wp_customize->add_control('mobile_repair_slider_hide_show',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Slider','mobile-repair'),
		'section' => 'mobile_repair_slider_section',
	));

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

	for ( $count = 1; $count <= 4; $count++ ) {
		$wp_customize->add_setting( 'mobile_repair_slider' . $count, array(
			'default'           => '',
			'sanitize_callback' => 'mobile_repair_sanitize_dropdown_pages'
		));
		$wp_customize->add_control( 'mobile_repair_slider' . $count, array(
			'label' => __('Select Slider Image Page', 'mobile-repair' ),
			'description' => __('Image Size (300px x 350px)', 'mobile-repair' ),
			'section' => 'mobile_repair_slider_section',
			'type' => 'dropdown-pages'
		));
	}

	$wp_customize->add_setting('mobile_repair_slider_excerpt_length',array(
		'default' => '20',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_slider_excerpt_length',array(
		'type' => 'number',
		'label' => __('Slider Excerpt Length','mobile-repair'),
		'section' => 'mobile_repair_slider_section',
	));

	$wp_customize->add_setting('mobile_repair_slider_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_slider_font_size',array(
		'type' => 'number',
		'label' => __('Title Font Size','mobile-repair'),
		'section' => 'mobile_repair_slider_section',
	));

	$wp_customize->add_setting('mobile_repair_slider_text_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_slider_text_font_size',array(
		'type' => 'number',
		'label' => __('Text Font Size','mobile-repair'),
		'section' => 'mobile_repair_slider_section',
	));

	$wp_customize->add_setting('mobile_repair_slider_opacity',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_slider_opacity',array(
		'type' => 'range',
		'label' => __('Image Opacity','mobile-repair'),
		'section' => 'mobile_repair_slider_section',
		'input_attrs' => array(
			'min'  => 0,
			'max'  => 1,
			'step' => 0.1,
		),
	));

	$wp_customize->add_setting('mobile_repair_slidertitle_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_slidertitle_color',array(
		'type' => 'color',
		'label' => __('Title Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	$wp_customize->add_setting('mobile_repair_slidertext_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_slidertext_color',array(
		'type' => 'color',
		'label' => __('Text Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	$wp_customize->add_setting('mobile_repair_sliderbtn_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_sliderbtn_color',array(
		'type' => 'color',
		'label' => __('Button Text Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	$wp_customize->add_setting('mobile_repair_sliderbtnbg_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_sliderbtnbg_color',array(
		'type' => 'color',
		'label' => __('Button Background Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	$wp_customize->add_setting('mobile_repair_sliderbtnhvr_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_sliderbtnhvr_color',array(
		'type' => 'color',
		'label' => __('Button Hover Text Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	$wp_customize->add_setting('mobile_repair_sliderbtnhvrbg_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_sliderbtnhvrbg_color',array(
		'type' => 'color',
		'label' => __('Button Hover Bg Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	$wp_customize->add_setting('mobile_repair_slidericons_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_slidericons_color',array(
		'type' => 'color',
		'label' => __('Icons Color','mobile-repair'),
		'section' => 'mobile_repair_slider_section'
	));

	//Why Choose Us Section
	$wp_customize->add_section('mobile_repair_chooseus_section',array(
		'title'	=> __('Why Choose Us Section','mobile-repair'),
		'description'=> __('<b>Note :</b> This section will appear below the slider.','mobile-repair'),
		'panel' => 'mobile_repair_panel_id',
	));

	$wp_customize->add_setting('mobile_repair_choose_section_title',array(
    	'default' => '',
    	'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_choose_section_title',array(
   	'type' => 'text',
   	'label' => __('Add Section Title','mobile-repair'),
   	'section' => 'mobile_repair_chooseus_section',
	));

	$wp_customize->add_setting('mobile_repair_chooseus_text',array(
    	'default' => '',
    	'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_chooseus_text',array(
   	'type' => 'text',
   	'label' => __('Add Section Text','mobile-repair'),
   	'section' => 'mobile_repair_chooseus_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('mobile_repair_choose_category',array(
		'default' => 'select',
		'sanitize_callback' => 'mobile_repair_sanitize_choices',
	));
	$wp_customize->add_control('mobile_repair_choose_category',array(
		'type' => 'select',
		'choices' => $cat_pst,
		'label' => __('Select Category To Display Post','mobile-repair'),
		'section' => 'mobile_repair_chooseus_section',
	));

	$wp_customize->add_setting('mobile_repair_chooseus_img_size',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_chooseus_img_size',array(
		'type' => 'number',
		'label' => __('Post Image Size','mobile-repair'),
		'section' => 'mobile_repair_chooseus_section',
	));

	$wp_customize->add_setting('mobile_repair_chooseus_background_img',array(
		'default'	=> '',
		'sanitize_callback'	=> 'esc_url_raw',
	));
	$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'mobile_repair_chooseus_background_img',array(
		'label' => __('Choose Us Background Image','mobile-repair'),
		'description' => __('Image size (1300px x 600px)','mobile-repair'),
		'section' => 'mobile_repair_chooseus_section'
	)));

	$wp_customize->add_setting('mobile_repair_chooseus_section_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
	));
	$wp_customize->add_control('mobile_repair_chooseus_section_padding',array(
		'type' => 'number',
		'label' => __('Section Top Bottom Padding','mobile-repair'),
		'section' => 'mobile_repair_chooseus_section',
	));

	$wp_customize->add_setting('mobile_repair_chooseus_title_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_chooseus_title_color',array(
		'type' => 'color',
		'label' => __('Title Color','mobile-repair'),
		'section' => 'mobile_repair_chooseus_section'
	));

	$wp_customize->add_setting('mobile_repair_chooseus_text_color',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_repair_chooseus_text_color',array(
		'type' => 'color',
		'label' => __('Text Color','mobile-repair'),
		'section' => 'mobile_repair_chooseus_section'
	));

	//Footer
    $wp_customize->add_section( 'mobile_repair_footer', array(
    	'title'  => __( 'Footer Settings', 'mobile-repair' ),
		'priority' => null,
		'panel' => 'mobile_repair_panel_id'
	) );

	$wp_customize->add_setting('mobile_repair_show_back_totop',array(
 		'default' => true,
   		'sanitize_callback'	=> 'mobile_repair_sanitize_checkbox'
	));
	$wp_customize->add_control('mobile_repair_show_back_totop',array(
	   	'type' => 'checkbox',
	   	'label' => __('Show / Hide Back to Top','mobile-repair'),
	   	'section' => 'mobile_repair_footer'
	));

    $wp_customize->add_setting('mobile_repair_footer_copy',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('mobile_repair_footer_copy',array(
		'label'	=> __('Copyright Text','mobile-repair'),
		'section' => 'mobile_repair_footer',
		'setting' => 'mobile_repair_footer_copy',
		'type' => 'text'
	));

	$wp_customize->register_section_type( Mobile_Repair_Button::class );

	$wp_customize->add_section(
		new Mobile_Repair_Button( $wp_customize, 'mobile_repair_pro_link', [
			'title'      => __( 'Mobile Repair Pro', 'mobile-repair' ),
			'priority'    => 0,
			'button_text' => __( 'Go Pro', 'mobile-repair' ),
			'button_url'  => esc_url( 'https://www.luzuk.com/products/mobile-repair-wordpress-theme/', 'mobile-repair'),
			'panel' => 'mobile_repair_panel_id'
		] )
	);

	$wp_customize->add_setting('mobile_repair_copyright_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'mobile_repair_sanitize_float'
 	));
 	$wp_customize->add_control('mobile_repair_copyright_padding',array(
		'type' => 'number',
		'label' => __('Copyright Top Bottom Padding','mobile-repair'),
		'section' => 'mobile_repair_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' => 'mobile_repair_customize_partial_blogname',
	) );
	$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
		'selector' => '.site-description',
		'render_callback' => 'mobile_repair_customize_partial_blogdescription',
	) );
}
add_action( 'customize_register', 'mobile_repair_customize_register' );

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

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

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

function mobile_repair_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' ) ) );
}