<?php
/**
 * Register Navigation Content section, settings and controls for Theme Customizer
 *
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
// Add Navigation Settings
add_action( 'customize_register', 'pmthemes_customize_register_navig_settings' );
function pmthemes_customize_register_navig_settings( $wp_customize ) {
    // Get Default Fonts from settings
    $theme_def = pmthemes_default_options();
    // Add Navigation Section
    $wp_customize->add_section('pmthemes_section_navigation', array(
            'title' => __('Navigation Settings', 'pmthemes'),
            'priority' => 3,
            'panel' => 'pmthemes_options_panel'
        )
    );
    $wp_customize->add_control(new Pmthemes_Control_Toggle($wp_customize, 'pmthemes_navigation_settings_toggle', array(
                'section' => 'pmthemes_section_navigation',
                'targets' => array(
                    'main-navigation' => __( 'Main', 'pmthemes' ),
                    'top-navigation' => __( 'Top', 'pmthemes' )
                ),
                'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
                'priority' => 0,
            )
        )
    );
    // Top Menu Alignment
    $wp_customize->add_setting( 'pmthemes_theme_options[topnav_align]', array(
            'default'           => $theme_def['topnav_align'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_topnav_align'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_topnav_align', array(
            'label'    => __( 'Top Menu Alignment', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[topnav_align]',
            'active_callback' => 'pmthemes_secondary_menu_active',
            'priority' => 1,
            'type'     => 'select',
            'choices'  => array(
                'top-menu-left' => __( 'Left (Default)', 'pmthemes' ),
                'top-menu-right' => __( 'Right', 'pmthemes'),
            )
        )
    );
    // Move Top Menu Below Title
    $wp_customize->add_setting( 'pmthemes_theme_options[topnav_down]', array(
            'default'           => $theme_def['topnav_down'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_topnav_down', array(
            'label'    => __( 'Move Top Menu Below Site Title', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[topnav_down]',
            'active_callback' => 'pmthemes_secondary_menu_active',
            'type'     => 'checkbox',
            'priority' => 2,
        )
    );
    // Enable Header Line
    $wp_customize->add_setting( 'pmthemes_theme_options[header_line_enable]', array(
            'default'           => $theme_def['header_line_enable'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_header_line_enable', array(
            'label'    => __( 'Enable Header Line Color', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[header_line_enable]',
            'active_callback' => 'pmthemes_is_navi_top_down',
            'type'     => 'checkbox',
            'priority' => 3,
        )
    );
    // Social Icons on Top Menu
    $wp_customize->add_setting( 'pmthemes_theme_options[header_icons]', array(
            'default'           => $theme_def['header_icons'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_header_icons', array(
            'label'    => __( 'Display Social Icons on Top Menu.', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[header_icons]',
            'active_callback' => 'pmthemes_secondary_menu_active',
            'type'     => 'checkbox',
            'priority' => 4,
        )
    );
    // Main Menu Location
    $wp_customize->add_setting( 'pmthemes_theme_options[nav_on_header]', array(
            'default'           => $theme_def['nav_on_header'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_main_nav_loc'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_nav_on_header', array(
            'label'    => __( 'Main Menu Location', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[nav_on_header]',
            'priority' => 5,
            'type'     => 'select',
            'choices'  => array(
                'main-menu-below' => __( 'Below Site Title (Default)', 'pmthemes' ),
                'main-menu-header' => __( 'Beside Site Title', 'pmthemes'),
            )
        )
    );
    // Sticky Navigation
    $wp_customize->add_setting( 'pmthemes_theme_options[sticky_navi]', array(
            'default'           => $theme_def['sticky_navi'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_sticky_navi', array(
            'label'    => __( 'Enable Sticky Navigation', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[sticky_navi]',
            'type'     => 'checkbox',
            'priority' => 6,
        )
    );
    // Search on Main Menu
    $wp_customize->add_setting( 'pmthemes_theme_options[search_icon]', array(
            'default'           => $theme_def['search_icon'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_search_icon', array(
            'label'    => __( 'Enable Search on Main Menu', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[search_icon]',
            'type'     => 'checkbox',
            'priority' => 7,
        )
    );
    // Hide Dropdown Indicator
    $wp_customize->add_setting( 'pmthemes_theme_options[no_drpdown_ind]', array(
            'default'           => $theme_def['no_drpdown_ind'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_no_drpdown_ind', array(
            'label'    => __( 'Hide Dropdown Indicator', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[no_drpdown_ind]',
            'type'     => 'checkbox',
            'priority' => 8,
        )
    );
    // Merged Menus on Mobile
    $wp_customize->add_setting( 'pmthemes_theme_options[pmthemes_merge_menus]', array(
            'default'           => $theme_def['pmth_merge_menus'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_merge_menus', array(
            'label'    => __( 'Merged Menus on Mobile', 'pmthemes' ),
            'description'    => __( 'Click mobile icon at the bottom of this panel to see live changes.', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[pmthemes_merge_menus]',
            'type'     => 'checkbox',
            'priority' => 9,
        )
    );
    // Top Menu Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[topmenu_font_size]', array(
            'default'           => $theme_def['topmenu_font_size'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_topmenu_font_size', array(
            'label'    => __( 'Top Menu Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[topmenu_font_size]',
            'active_callback' => 'pmthemes_secondary_menu_active',
            'priority' => 10,
            'min' => 0.7,
            'max' => 1.65,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Top Menu Bar Padding
    $wp_customize->add_setting( 'pmthemes_theme_options[topmenu_bar_padding]', array(
            'default'           => $theme_def['topmenu_bar_padding'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_topmenu_bar_padding', array(
            'label'    => __( 'Top Menu Bar Padding', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[topmenu_bar_padding]',
            'active_callback' => 'pmthemes_secondary_menu_active',
            'priority' => 11,
            'min' => 0.5,
            'max' => 1.5,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Main Menu Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[mainmenu_font_size]', array(
            'default'           => $theme_def['mainmenu_font_size'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_mainmenu_font_size', array(
            'label'    => __( 'Main Menu Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[mainmenu_font_size]',
            'priority' => 12,
            'min' => 0.75,
            'max' => 1.95,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Main Menu Bar Padding
    $wp_customize->add_setting( 'pmthemes_theme_options[mainmenu_bar_padding]', array(
            'default'           => $theme_def['mainmenu_bar_padding'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_mainmenu_bar_padding', array(
            'label'    => __( 'Main Menu Bar Padding', 'pmthemes' ),
            'section'  => 'pmthemes_section_navigation',
            'settings' => 'pmthemes_theme_options[mainmenu_bar_padding]',
            'priority' => 13,
            'min' => 0.25,
            'max' => 2.75,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Secondary Navigation Not Active
    $wp_customize->add_setting( 'pmthemes_theme_options[top_nav_inactive]', array(
            'default'           => '',
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
            $wp_customize, 'pmthemes_control_top_nav_inactive', array(
                'label' => __( 'Top/Secondary Navigation Not Active', 'pmthemes' ),
                'section' => 'pmthemes_section_navigation',
                'description' =>'The top/secondary menu is not active.
If you want a top menu, please go to <a href="'. esc_url( home_url() ) .'/wp-admin/nav-menus.php">Menus</a> section and assign menu items to "Top Navigation" then come back here to edit settings.',
                'settings' => 'pmthemes_theme_options[top_nav_inactive]',
                'active_callback' => 'pmthemes_secondary_menu_inactive',
                'priority' => 14,
            )
        )
    );

}
