<?php
/**
 * Ultra Print: Customizer
 *
 * @subpackage Ultra Print
 * @since 1.0
 */

use WPTRT\Customize\Section\Ultra_Print_Button;

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

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

	$manager->add_section(
		new Ultra_Print_Button( $manager, 'ultra_print_pro', [
			'title'       => __( 'Ultra Print Pro', 'ultra-print' ),
			'priority'    => 0,
			'button_text' => __( 'Go Pro', 'ultra-print' ),
			'button_url'  => esc_url( 'https://www.luzuk.com/products/printing-wordpress-theme/', 'ultra-print')
		] )
	);

} );

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

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

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

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

} );

function ultra_print_customize_register( $wp_customize ) {

	$wp_customize->add_setting('ultra_print_logo_size',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_logo_size',array(
		'type' => 'range',
		'description' => __('Logo Size (0-100%)','ultra-print'),
		'section' => 'title_tagline',
	));

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

	$wp_customize->add_setting('ultra_print_logo_top_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_logo_top_padding',array(
		'type' => 'number',
		'description' => __('Top','ultra-print'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('ultra_print_logo_bottom_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_logo_bottom_padding',array(
		'type' => 'number',
		'description' => __('Bottom','ultra-print'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('ultra_print_logo_left_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_logo_left_padding',array(
		'type' => 'number',
		'description' => __('Left','ultra-print'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('ultra_print_logo_right_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_logo_right_padding',array(
		'type' => 'number',
		'description' => __('Right','ultra-print'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('ultra_print_show_site_title',array(
		'default' => true,
		'sanitize_callback'	=> 'ultra_print_sanitize_checkbox'
	));
	$wp_customize->add_control('ultra_print_show_site_title',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Title','ultra-print'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('ultra_print_site_title_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_site_title_font_size',array(
		'type' => 'number',
		'label' => __('Site Title Font Size','ultra-print'),
		'section' => 'title_tagline',
	));

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

	$wp_customize->add_setting('ultra_print_show_tagline',array(
		'default' => true,
		'sanitize_callback'	=> 'ultra_print_sanitize_checkbox'
	));
	$wp_customize->add_control('ultra_print_show_tagline',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Tagline','ultra-print'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('ultra_print_site_tagline_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_site_tagline_font_size',array(
		'type' => 'number',
		'label' => __('Site Tagline Font Size','ultra-print'),
		'section' => 'title_tagline',
	));

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

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

	$wp_customize->add_section( 'ultra_print_theme_options_section', array(
    	'title'      => __( 'General Settings', 'ultra-print' ),
		'priority'   => 30,
		'panel' => 'ultra_print_panel_id'
	) );

	$wp_customize->add_setting('ultra_print_theme_options',array(
		'default' => 'Right Sidebar',
		'sanitize_callback' => 'ultra_print_sanitize_choices'	        
	));
	$wp_customize->add_control('ultra_print_theme_options',array(
		'type' => 'radio',
		'label' => __('Sidebar Option','ultra-print'),
		'section' => 'ultra_print_theme_options_section',
		'choices' => array(
		   'Left Sidebar' => __('Left Sidebar','ultra-print'),
		   'Right Sidebar' => __('Right Sidebar','ultra-print'),
		   'One Column' => __('One Column','ultra-print'),
		   'Three Columns' => __('Three Columns','ultra-print'),
		   'Four Columns' => __('Four Columns','ultra-print'),
		   'Grid Layout' => __('Grid Layout','ultra-print')
		),
	));

	$wp_customize->add_setting( 'ultra_print_boxfull_width', array(
		'default'           => '',
		'sanitize_callback' => 'ultra_print_sanitize_choices'
	));
	
	$wp_customize->add_control( 'ultra_print_boxfull_width', array(
		'label'    => __( 'Section Width', 'ultra-print' ),
		'section'  => 'ultra_print_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'container'  => __('Box Width', 'ultra-print'),
			'container-fluid' => __('Full Width', 'ultra-print'),
			'none' => __('None', 'ultra-print')
		),
	));

	$wp_customize->add_setting( 'ultra_print_dropdown_anim', array(
		'default'           => 'None',
		'sanitize_callback' => 'ultra_print_sanitize_choices'
	));
	$wp_customize->add_control( 'ultra_print_dropdown_anim', array(
		'label'    => __( 'Menu Dropdown Animations', 'ultra-print' ),
		'section'  => 'ultra_print_theme_options_section',
		'type'     => 'select',
		'choices'  => array(
			'bounceInUp'  => __('bounceInUp', 'ultra-print'),
			'fadeInUp' => __('fadeInUp', 'ultra-print'),
			'zoomIn'    => __('zoomIn', 'ultra-print'),
			'None'    => __('None', 'ultra-print')
		),
	));

	//Header section
	$wp_customize->add_section( 'ultra_print_header_section' , array(
    	'title' => __( 'Header Section', 'ultra-print' ),
		'priority' => null,
		'panel' => 'ultra_print_panel_id'
	) );

	$wp_customize->add_setting('ultra_print_button_text',array(
    	'default' => '',
    	'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('ultra_print_button_text',array(
   	'type' => 'text',
   	'label' => __('Add Button Text','ultra-print'),
   	'section' => 'ultra_print_header_section',
	));

	$wp_customize->add_setting('ultra_print_button_url',array(
    	'default' => '',
    	'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('ultra_print_button_url',array(
   	'type' => 'url',
   	'label' => __('Add Button URL','ultra-print'),
   	'section' => 'ultra_print_header_section',
	));

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

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

	//home page slider
	$wp_customize->add_section( 'ultra_print_slider_section' , array(
    	'title'      => __( 'Slider Settings', 'ultra-print' ),
		'priority'   => null,
		'panel' => 'ultra_print_panel_id'
	) );

	$wp_customize->add_setting('ultra_print_slider_hide_show',array(
    	'default' => false,
    	'sanitize_callback'	=> 'ultra_print_sanitize_checkbox'
	));
	$wp_customize->add_control('ultra_print_slider_hide_show',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide slider','ultra-print'),
		'section' => 'ultra_print_slider_section',
	));

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

	for ( $count = 1; $count <= 4; $count++ ) {
		$wp_customize->add_setting( 'ultra_print_slider' . $count, array(
			'default'           => '',
			'sanitize_callback' => 'ultra_print_sanitize_dropdown_pages'
		) );
		$wp_customize->add_control( 'ultra_print_slider' . $count, array(
			'label' => __( 'Select Slide Image Page', 'ultra-print' ),
			'section' => 'ultra_print_slider_section',
			'type' => 'dropdown-pages'
		) );
	}

	$wp_customize->add_setting('ultra_print_slider_excerpt_length',array(
		'default' => '20',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_slider_excerpt_length',array(
		'type' => 'number',
		'label' => __('Slider Excerpt Length','ultra-print'),
		'section' => 'ultra_print_slider_section',
	));

	$wp_customize->add_setting('ultra_print_slider_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_slider_font_size',array(
		'type' => 'number',
		'label' => __('Title Font Size','ultra-print'),
		'section' => 'ultra_print_slider_section',
	));

	$wp_customize->add_setting('ultra_print_slider_text_font_size',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_slider_text_font_size',array(
		'type' => 'number',
		'label' => __('Text Font Size','ultra-print'),
		'section' => 'ultra_print_slider_section',
	));

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

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

	//Our Services
	$wp_customize->add_section('ultra_print_service',array(
		'title'	=> __('Services Section','ultra-print'),
		'description'=> __('<b>Note :</b> This section will appear below the slider.','ultra-print'),
		'panel' => 'ultra_print_panel_id',
	));

	$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('ultra_print_category_setting',array(
		'default'	=> 'select',
		'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('ultra_print_category_setting',array(
		'type'    => 'select',
		'choices' => $cat_pst,
		'label' => __('Select Category To Display Post','ultra-print'),
		'description' => __('Image Size (58px x 58px)','ultra-print'),
		'section' => 'ultra_print_service',
	));

	$wp_customize->add_setting('ultra_print_service_img_size',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
	));
	$wp_customize->add_control('ultra_print_service_img_size',array(
		'type' => 'number',
		'label' => __('Image Height','ultra-print'),
		'section' => 'ultra_print_service',
	));

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

	$wp_customize->add_setting( 'ultra_print_service_img_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'ultra_print_service_img_color', array(
		'label' => 'Service Image Bg Color',
		'section' => 'ultra_print_service',
	)));

	//About Section 
	$wp_customize->add_section('ultra_print_services_section',array(
		'title'	=> __('About Section','ultra-print'),
		'description'=> __('<b>Note :</b> This section will appear below the Slider section.','ultra-print'),
		'panel' => 'ultra_print_panel_id',
	));
	
	$wp_customize->add_setting( 'ultra_print_services_page', array(
		'default'           => '',
		'sanitize_callback' => 'ultra_print_sanitize_dropdown_pages'
	));
	$wp_customize->add_control( 'ultra_print_services_page', array(
		'label'    => __( 'Select About Page', 'ultra-print' ),
		'description' => __('Image size (255px x 300px)', 'ultra-print'),
		'section'  => 'ultra_print_services_section',
		'type'     => 'dropdown-pages'
	));

	$wp_customize->add_setting('ultra_print_about_section_padding',array(
       'default' => '',
       'sanitize_callback'	=> 'ultra_print_sanitize_float'
    ));
    $wp_customize->add_control('ultra_print_about_section_padding',array(
       'type' => 'number',
       'label' => __('Section Top Bottom Padding','ultra-print'),
       'section' => 'ultra_print_services_section',
    ));

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

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

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

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

	//Footer
    $wp_customize->add_section( 'ultra_print_footer', array(
    	'title'      => __( 'Footer Setting', 'ultra-print' ),
		'priority'   => null,
		'panel' => 'ultra_print_panel_id'
	) );

	$wp_customize->add_setting('ultra_print_show_back_totop',array(
 		'default' => true,
   	'sanitize_callback'	=> 'ultra_print_sanitize_checkbox'
	));
	$wp_customize->add_control('ultra_print_show_back_totop',array(
   	'type' => 'checkbox',
   	'label' => __('Show / Hide Back to Top','ultra-print'),
   	'section' => 'ultra_print_footer'
	));

   	$wp_customize->add_setting('ultra_print_footer_link',array(
		'default'	=> 'https://www.luzuk.com/products/free-printing-wordpress-theme/',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('ultra_print_footer_link',array(
		'label'	=> __('Copyright Link','ultra-print'),
		'section'	=> 'ultra_print_footer',
		'setting'	=> 'ultra_print_footer_link',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('ultra_print_footer_copy',array(
		'default'	=> 'Printing WordPress Theme By Luzuk',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('ultra_print_footer_copy',array(
		'label'	=> __('Copyright Text','ultra-print'),
		'section'	=> 'ultra_print_footer',
		'setting'	=> 'ultra_print_footer_copy',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('ultra_print_copyright_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'ultra_print_sanitize_float'
 	));
 	$wp_customize->add_control('ultra_print_copyright_padding',array(
		'type' => 'number',
		'label' => __('Copyright Top Bottom Padding','ultra-print'),
		'section' => 'ultra_print_footer',
	));

	$wp_customize->add_setting( 'ultra_print_copyright_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'ultra_print_copyright_color', array(
		'label' => 'Copyright text Color',
		'section' => 'ultra_print_footer',
	)));

	$wp_customize->add_setting( 'ultra_print_aboutbtnbg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'ultra_print_aboutbtnbg_color', array(
		'label' => 'Copyright Border Color',
		'section' => 'ultra_print_footer',
	)));

	$wp_customize->add_setting( 'ultra_print_tbtext_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'ultra_print_tbtext_color', array(
		'label' => 'Back To Top Text Color',
		'section' => 'ultra_print_footer',
	)));

	$wp_customize->add_setting( 'ultra_print_tbbg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'ultra_print_tbbg_color', array(
		'label' => 'Back To Top Bg Color',
		'section' => 'ultra_print_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' => 'ultra_print_customize_partial_blogname',
	) );
	$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
		'selector' => '.site-description',
		'render_callback' => 'ultra_print_customize_partial_blogdescription',
	) );
}
add_action( 'customize_register', 'ultra_print_customize_register' );

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

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

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

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