<?php

function stationary_bookstore_remove_customize_register() {
    global $wp_customize;
    $wp_customize->remove_section( 'author_writer_slider_section' );
    
    $wp_customize->remove_setting( 'author_writer_secondary_color_option' );
    $wp_customize->remove_control( 'author_writer_secondary_color_option' );

    $wp_customize->remove_setting( 'author_writer_slide_btn_2' );
    $wp_customize->remove_control( 'author_writer_slide_btn_2' );

    $wp_customize->remove_setting( 'author_writer_slider_top' );
    $wp_customize->remove_control( 'author_writer_slider_top' );
}

add_action( 'customize_register', 'stationary_bookstore_remove_customize_register', 11 );

if ( ! defined( 'STATIONARY_BOOKSTORE_TEXT' ) ) {
    define( 'STATIONARY_BOOKSTORE_TEXT', __( 'Bookstore Library Pro','stationary-bookstore' ));
}
if ( ! defined( 'STATIONARY_BOOKSTORE__BUY_TEXT' ) ) {
    define( 'STATIONARY_BOOKSTORE__BUY_TEXT', __( 'Upgrade Pro','stationary-bookstore' ));
}


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

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

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

    $manager->add_section(
        new Author_Writer_Button( $manager, 'author_writer_pro', [
            'title'       => esc_html( STATIONARY_BOOKSTORE_TEXT,'stationary-bookstore' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'stationary-bookstore' ),
            'button_url'  => esc_url( AUTHOR_WRITER_PRO_THEME_URL )
        ] )
    );

} );

function stationary_bookstore_customize_register( $wp_customize ) {
// Register the custom control type.
	$wp_customize->register_control_type( 'Stationary_Bookstore_Toggle_Control' );

	// Pro Version
    class Stationary_Bookstore_Customize_Pro_Version extends WP_Customize_Control {
        public $type = 'pro_options';

        public function render_content() {
            echo '<span>Unlock Premium <strong>'. esc_html( $this->label ) .'</strong>? </span>';
            echo '<a href="'. esc_url($this->description) .'" target="_blank">';
                echo '<span class="dashicons dashicons-info"></span>';
                echo '<strong> '. esc_html( STATIONARY_BOOKSTORE__BUY_TEXT,'stationary-bookstore' ) .'<strong></a>';
            echo '</a>';
        }
    }

    // Custom Controls
    function stationary_bookstore_sanitize_custom_control( $input ) {
        return $input;
    }

	$wp_customize->add_section( 'stationary_bookstore_slide_box_section' , array(
    	'title'      => __( 'Slider Settings', 'stationary-bookstore' ),
		'panel' => 'author_writer_panel_id',
		'priority' => 3,
	) );
    $wp_customize->add_setting( 'stationary_bookstore_Slider_show_hide', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'author_writer_sanitize_checkbox',
	) );
	$wp_customize->add_control( new Stationary_Bookstore_Toggle_Control( $wp_customize, 'stationary_bookstore_Slider_show_hide', array(
		'label'       => esc_html__( 'Show / Hide section', 'stationary-bookstore' ),
		'section'     => 'stationary_bookstore_slide_box_section',
		'type'        => 'toggle',
		'settings'    => 'stationary_bookstore_Slider_show_hide',
	) ) );

	$wp_customize->add_setting( 'stationary_bookstore_show_slider_title', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'author_writer_sanitize_checkbox',
	) );
	$wp_customize->add_control( new author_writer_Toggle_Control( $wp_customize, 'stationary_bookstore_show_slider_title', array(
		'label'       => esc_html__( 'Show / Hide Slider Heading', 'author-writer' ),
		'section'     => 'stationary_bookstore_slide_box_section',
		'type'        => 'toggle',
		'settings'    => 'stationary_bookstore_show_slider_title',
	) ) );
	
	$categories = get_categories();
	$cats = array();
	$i = 0;
	$offer_cat[]= 'select';
	foreach($categories as $category){
		if($i==0){
			$default = $category->slug;
			$i++;
		}
		$offer_cat[$category->slug] = $category->name;
	}
	$wp_customize->add_setting('stationary_bookstore_slider_section_category',array(
		'default'	=> 'select',
		'sanitize_callback' => 'author_writer_sanitize_choices',
	));
	$wp_customize->add_control('stationary_bookstore_slider_section_category',array(
		'type'    => 'select',
		'choices' => $offer_cat,
		'label' => __('Select Category','stationary-bookstore'),
		'section' => 'stationary_bookstore_slide_box_section',
	));

	// Pro Version
    $wp_customize->add_setting( 'stationary_bookstore_slider_pro_version_logo', array(
        'sanitize_callback' => 'author_writer_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Stationary_Bookstore_Customize_Pro_Version ( $wp_customize,'stationary_bookstore_slider_pro_version_logo', array(
        'section'     => 'stationary_bookstore_slide_box_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'author-writer' ),
        'description' => esc_url( AUTHOR_WRITER_PRO_THEME_URL ),
        'priority'    => 100
    )));

    $wp_customize->add_setting( 'stationary_bookstore_slider_opacity_setting', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'author_writer_sanitize_checkbox',
	) );
	$wp_customize->add_control( new author_writer_Toggle_Control( $wp_customize, 'stationary_bookstore_slider_opacity_setting', array(
		'label'       => esc_html__( 'Show / Hide Image Opacity', 'author-writer' ),
		'section'     => 'stationary_bookstore_slide_box_section',
		'type'        => 'toggle',
		'settings'    => 'stationary_bookstore_slider_opacity_setting',
	) ) );

    $wp_customize->add_setting( 'stationary_bookstore_image_opacity_color', array(
        'default' => '',
        'sanitize_callback' => 'sanitize_hex_color'
    ));
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'stationary_bookstore_image_opacity_color', array(
        'label' => __('Slider Image Opacity Color', 'author-writer'),
        'section' => 'stationary_bookstore_slide_box_section',
        'settings' => 'stationary_bookstore_image_opacity_color',
    )));

    $wp_customize->add_setting('stationary_bookstore_slider_opacity',array(
        'default'=> '0.5',
        'sanitize_callback' => 'author_writer_sanitize_choices'
    ));
    $wp_customize->add_control('stationary_bookstore_slider_opacity',array(
        'type' => 'select',
        'label' => esc_html__('Slider Image Opacity','author-writer'),
        'choices' => array(
            '0'   => '0',
            '0.1' => '0.1',
            '0.2' => '0.2',
            '0.3' => '0.3',
            '0.4' => '0.4',
            '0.5' => '0.5',
            '0.6' => '0.6',
            '0.7' => '0.7',
            '0.8' => '0.8',
            '0.9' => '0.9',
            '1'   => '1',
        ),
        'section'=> 'stationary_bookstore_slide_box_section',
    ));

    //Slider height
    $wp_customize->add_setting('stationary_bookstore_slider_img_height',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('stationary_bookstore_slider_img_height',array(
        'label' => __('Slider Height','author-writer'),
        'description'   => __('Add slider height in px(eg. 700px).','author-writer'),
        'section'=> 'stationary_bookstore_slide_box_section',
        'type'=> 'text'
    ));
}
add_action( 'customize_register', 'stationary_bookstore_customize_register' );
