<?php
/**
 * Register Widget Bar section, settings and controls for Theme Customizer
 *
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
// Add Widget Bar Settings
add_action( 'customize_register', 'pmthemes_customize_register_wgtbar_settings' );
function pmthemes_customize_register_wgtbar_settings( $wp_customize ) {
    // Get Default Fonts from settings
    $theme_def = pmthemes_default_options();
    // Add Widgets Section
    $wp_customize->add_section( 'pmthemes_section_sidebar', array(
            'title'    => __( 'Sidebar Settings', 'pmthemes' ),
            'priority' => 4,
            'panel' => 'pmthemes_options_panel'
        )
    );
    // Sidebar Location
    $wp_customize->add_setting( 'pmthemes_theme_options[layout]', array(
            'default'           => $theme_def['layout'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_layout'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_layout', array(
            'label'    => __( 'Sidebar Location', 'pmthemes' ),
            'section'  => 'pmthemes_section_sidebar',
            'settings' => 'pmthemes_theme_options[layout]',
            'type'     => 'select',
            'choices'  => array(
                'right-sidebar' => __( 'Right (Default)', 'pmthemes'),
                'left-sidebar' => __( 'Left Side', 'pmthemes' ),
            )
        )
    );
    // Content & Sidebar Balance
    $wp_customize->add_setting( 'pmthemes_theme_options[sidecon_width]', array(
            'default'           => $theme_def['sidecon_width'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_number'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_sidecon_width', array(
            'label'    => __( 'Content & Sidebar Balance', 'pmthemes' ),
            'section'  => 'pmthemes_section_sidebar',
            'settings' => 'pmthemes_theme_options[sidecon_width]',
            'min' => 20,
            'max' => 50,
            'step' => 0.01,
            'unit' => '%',
        ))
    );
    // Enable Sidebar Padding Adjustments
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_padding_adjust]', array(
            'default'           => $theme_def['sidebar_padding_adjust'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_sidebar_padding_adjust', array(
            'label'    => __( 'Enable Sidebar Padding Adjustments', 'pmthemes' ),
            'section'  => 'pmthemes_section_sidebar',
            'settings' => 'pmthemes_theme_options[sidebar_padding_adjust]',
            'type'     => 'checkbox',
        )
    );
    // Sidebar padding top
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_padding_top]', array(
            'default' 			=> $theme_def['sidebar_padding_top'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int',
        )
    );
    // Sidebar padding right
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_padding_right]', array(
            'default' 			=> $theme_def['sidebar_padding_right'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int',
        )
    );
    // Sidebar padding bottom
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_padding_bottom]', array(
            'default' 			=> $theme_def['sidebar_padding_bottom'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int',
        )
    );
    // Sidebar padding left
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_padding_left]', array(
            'default' 			=> $theme_def['sidebar_padding_left'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int',
        )
    );
    // Sidebar padding controls
    $wp_customize->add_control(new Pmthemes_Spacing_Control($wp_customize, 'sidebar_spacing', array(
                'type' => 'pmthemes-spacing',
                'label'       => esc_html__( 'Adjust sidebar padding (em)', 'pmthemes' ),
                'section'     => 'pmthemes_section_sidebar',
                'description' => 'Default for all is 1.0',
                'settings'    => array(
                    'top'     => 'pmthemes_theme_options[sidebar_padding_top]',
                    'right'   => 'pmthemes_theme_options[sidebar_padding_right]',
                    'bottom'  => 'pmthemes_theme_options[sidebar_padding_bottom]',
                    'left'    => 'pmthemes_theme_options[sidebar_padding_left]',
                ),
                'active_callback' => 'pmthemes_sidebar_padding_adjust_active',
                'element' => 'sidebar',
            )
        )
    );
    // Sidebar Header Bar
    $wp_customize->add_setting( 'pmthemes_theme_options[wdgt_bar_hd]', array(
            'type'           	=> 'option',
            'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
            $wp_customize, 'pmthemes_control_wdgt_bar_hd', array(
                'label' => __( 'Header Bar', 'pmthemes' ),
                'section' => 'pmthemes_section_sidebar',
                'settings' => 'pmthemes_theme_options[wdgt_bar_hd]',
            )
        )
    );
    // Widget Header Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[wgtbar_font_size]', array(
            'default'           => $theme_def['wgtbar_font_size'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_wgtbar_font_size', array(
            'label'    => __( 'Header Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_sidebar',
            'settings' => 'pmthemes_theme_options[wgtbar_font_size]',
            'min' => 0.75,
            'max' => 2.75,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Sidebar Widget Header Font Padding
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_font_pad_top]', array(
            'default' 			=> $theme_def['sidebar_font_pad_top'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'absint',
        )
    );
    // Header right
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_font_pad_right]', array(
            'default' 			=> $theme_def['sidebar_font_pad_right'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'absint',
        )
    );
    // Header bottom
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_font_pad_bottom]', array(
            'default' 			=> $theme_def['sidebar_font_pad_bottom'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'absint',
        )
    );
    // Header left
    $wp_customize->add_setting( 'pmthemes_theme_options[sidebar_font_pad_left]', array(
            'default' 			=> $theme_def['sidebar_font_pad_left'],
            'type' 				=> 'option',
            'transport' 		=> 'postMessage',
            'sanitize_callback' => 'absint',
        )
    );
    // Header controls
    $wp_customize->add_control(new Pmthemes_Spacing_Control($wp_customize, 'wdgt-font-spacing', array(
                'type' => 'pmthemes-spacing',
                'label'       => esc_html__( 'Header Font Padding (px)', 'pmthemes' ),
                'section'     => 'pmthemes_section_sidebar',
                'settings'    => array(
                    'top'     => 'pmthemes_theme_options[sidebar_font_pad_top]',
                    'right'   => 'pmthemes_theme_options[sidebar_font_pad_right]',
                    'bottom'  => 'pmthemes_theme_options[sidebar_font_pad_bottom]',
                    'left'    => 'pmthemes_theme_options[sidebar_font_pad_left]',
                ),
                'element' => 'wdgt-font-padding',
            )
        )
    );
    // Tabbed Widget
    $wp_customize->add_setting( 'pmthemes_theme_options[tabbed_wdgt_hd]', array(
            'type'           	=> 'option',
            'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
            $wp_customize, 'pmthemes_control_tabbed_wdgt_hd', array(
                'label' => __( 'Tabbed Widget', 'pmthemes' ),
                'section' => 'pmthemes_section_sidebar',
                'settings' => 'pmthemes_theme_options[tabbed_wdgt_hd]',
                'active_callback' => 'pmthemes_tabbed_content_active',
            )
        )
    );
    // Tabbed Widget Header Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[tabbed_font_size]', array(
            'default'           => $theme_def['tabbed_font_size'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_tabbed_font_size', array(
            'label'    => __( 'Tabbed Widget Header Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_sidebar',
            'settings' => 'pmthemes_theme_options[tabbed_font_size]',
            'active_callback' => 'pmthemes_tabbed_content_active',
            'active_callback' => 'pmthemes_tabbed_content_active',
            'min' => 0.50,
            'max' => 1.75,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Tabbed Widget Header Padding
    $wp_customize->add_setting( 'pmthemes_theme_options[side_tabbed_padding]', array(
            'default'           => $theme_def['side_tabbed_padding'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_side_tabbed_padding', array(
            'label'    => __( 'Tabbed Widget Header Padding', 'pmthemes' ),
            'section'  => 'pmthemes_section_sidebar',
            'settings' => 'pmthemes_theme_options[side_tabbed_padding]',
            'active_callback' => 'pmthemes_tabbed_content_active',
            'active_callback' => 'pmthemes_tabbed_content_active',
            'min' => 0.15,
            'max' => 1.5,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
}