<?php 

/**
 * Theme Options Panel.
 *
 * @package guj
 */

$default = guj_get_default_theme_options();

    // Add Theme Options Panel.
    $wp_customize->add_panel( 'guj_theme_option_panel', array(
            'title'             => esc_html__( 'Theme Options', 'guj' ),
            'priority'          => 50,
            'capability'        => 'edit_theme_options',
        )
    );

    // Add Theme Colors Section
    $wp_customize->add_section( 'guj_theme_colors_section', array(
            'title'             => esc_html__( 'Theme Colors', 'guj' ),
            'priority'          => 95,
            'capability'        => 'edit_theme_options',
            'panel'             => 'guj_theme_option_panel',
        )
    );

    // Add background color
    $wp_customize->get_control( 'background_color'  )->section   = 'guj_theme_colors_section';
    
    // Add Header text color
    $wp_customize->get_setting( 'header_textcolor'  )->transport = 'postMessage';

    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize,'header_textcolor', array(
            'label'             => esc_html__( 'Header Text Color', 'guj'),
            'section'           => 'guj_theme_colors_section',
            'settings'          => 'header_textcolor'
        ))
    );

    // Add Setting for header background color
    $wp_customize->add_setting( 'header_bg_color', array(
            'default'           => $default['header_bg_color'],
            'transport'         => 'postMessage',
            'type'              => 'theme_mod',
            'sanitize_callback' => 'sanitize_hex_color',
    ));

    // Add Control for header background color.
    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize,'header_bg_color', array(
            'label'             => esc_html__( 'Header Background color', 'guj'),
            'section'           => 'guj_theme_colors_section',
            'settings'          => 'header_bg_color'
        ))
    );
    
    // Add Setting for content text color
    $wp_customize->add_setting( 'content_text_color', array(
            'default'		=> $default['content_text_color'],
            'transport'		=> 'postMessage',
            'type'		=> 'theme_mod',
            'sanitize_callback'	=> 'sanitize_hex_color',
            'transport'		=> 'postMessage',
        )
    );

    // Add control for content text color
    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize,'content_text_color', array(
            'label'		=> esc_html__( 'Content Text Color', 'guj' ),
            'section'           => 'guj_theme_colors_section',
            'settings'          => 'content_text_color'
        ))
    );
    
    // Add Setting for content links color
    $wp_customize->add_setting( 'content_links_color', array(
            'default'		=> $default['content_links_color'],
            'transport'		=> 'postMessage',
            'type'		=> 'theme_mod',
            'sanitize_callback'	=> 'sanitize_hex_color',
            'transport'		=> 'postMessage',
        )
    );

    // Add control for content links color
    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize,'content_links_color', array(
            'label'		=> esc_html__( 'Content Links Color', 'guj' ),
            'section'           => 'guj_theme_colors_section',
            'settings'          => 'content_links_color'
        ))
    );

    
    // Add Setting for footer text color
    $wp_customize->add_setting( 'footer_text_color', array(
            'default'           => $default['footer_text_color'],
            'transport'         => 'postMessage',
            'type'              => 'theme_mod',
            'sanitize_callback' => 'sanitize_hex_color',
    ));

    // Add Control for footer text color.
    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize,'footer_text_color', array(
            'label'             => esc_html__( 'Footer Text color', 'guj'),
            'section'           => 'guj_theme_colors_section',
            'settings'          => 'footer_text_color'
        ))
    );
    
    // Add Setting for footer background color
    $wp_customize->add_setting( 'footer_bg_color', array(
            'default'           => $default['footer_bg_color'],
            'transport'         => 'postMessage',
            'type'              => 'theme_mod',
            'sanitize_callback' => 'sanitize_hex_color',
    ));

    // Add Control for footer background color.
    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize,'footer_bg_color', array(
            'label'             => esc_html__( 'Footer Background color', 'guj'),
            'section'           => 'guj_theme_colors_section',
            'settings'          => 'footer_bg_color'
        ))
    );
    
    
    $social_sites = guj_social_array();
    // Social Profiles Section
    $wp_customize->add_section( 'social_option_section_settings', array(
            'title'             => esc_html__( 'Social Profile Options', 'guj' ),
            'priority'          => 120,
            'capability'        => 'edit_theme_options',
            'panel'             => 'guj_theme_option_panel',
            'description'       => __( 'Add the URL for each of your social profiles.', 'guj' )
	)
    );

    // Set a priority used to order the social sites
    $priority = 5;

    // Add a setting and control for each social profile url
    foreach ( $social_sites as $social_site => $value ) {

        $label = ucfirst( $social_site );

        if ( $social_site == 'google-plus' ) {
            $label = 'Google Plus';
        } elseif ( $social_site == 'rss' ) {
            $label = 'RSS';
        } elseif ( $social_site == 'soundcloud' ) {
            $label = 'SoundCloud';
        } elseif ( $social_site == 'stumbleupon' ) {
            $label = 'StumbleUpon';
        } elseif ( $social_site == 'vk' ) {
            $label = 'VK';
        } elseif ( $social_site == 'tencent-weibo' ) {
            $label = 'Tencent Weibo';
        } 
        
        // Social Profiles setting
        $wp_customize->add_setting( $social_site, array(
            'default'           => esc_url( $default['social_profile_link'] ),
            'capability'        => 'edit_theme_options',
            'sanitize_callback' => 'esc_url_raw'
        ) );
        
        // Social Profiles control
        $wp_customize->add_control( $social_site, array(
            'type'     => 'url',
            'label'    => $label,
            'section'  => 'social_option_section_settings',
            'priority' => $priority
        ) );
        
        // Increment the priority for next site
        $priority = $priority + 5;
    }
    
    
    // Blog Management
    $wp_customize->add_section( 'guj_blog_management_section', array(
            'title'             => esc_html__( 'Blog Management', 'guj' ),
            'priority'          => 95,
            'capability'        => 'edit_theme_options',
            'panel'             => 'guj_theme_option_panel',
        )
    );
    
    //Posts Layout Options Setting
    $wp_customize->add_setting( 'blog_layout_options', array(
            'default'           => $default['blog_layout'],
            'capability'        => 'edit_theme_options',
            'sanitize_callback' => 'guj_select_sanitize',
        )
    );
    
    //Posts Layout Options Control
    $wp_customize->add_control( 'blog_layout_options', array(
            'label'             => esc_html__( 'Blog Layout Options', 'guj' ),
            'description'       => esc_html__( 'Choose between different layout options to be used as default', 'guj' ),
            'section'           => 'guj_blog_management_section',
            'choices'           => array(
                    'pull-left'     => esc_html__( 'Primary Sidebar - Content', 'guj' ),
                    'pull-right'    => esc_html__( 'Content - Primary Sidebar', 'guj' ),
                    'no-sidebar'    => esc_html__( 'No Sidebar', 'guj' ),
                    ),
            'type'              => 'select',
        )
    );	
    
    //Excerpt or full content settings
    $wp_customize->add_setting(	'content_length_setting', array(
            'default'		=> 'excerpt',
            'type'		=> 'theme_mod',
            'sanitize_callback' => 'absint',
        )
    );

    //Excerpt or full content control
    $wp_customize->add_control(	'content_length_setting', array(
            'type'		=> 'radio',
            'label'		=> __( 'Index/archive displays', 'guj' ),
            'section'           => 'guj_blog_management_section',
            'choices'           => array(
                    'excerpt'           => __( 'Excerpt (default)', 'guj' ),
                    'full-content'	=> __( 'Full content', 'guj' )
                ),
            'settings'          => 'content_length_setting',
        )
    );
    
    //Excerpt Length Setting
    $wp_customize->add_setting( 'excerpt_blog_length', array(
            'default'           => $default['length_excerpt_blog'],
            'capability'        => 'edit_theme_options',
            'sanitize_callback' => 'guj_positive_integer_sanitize',
        )
    );
    
    //Excerpt Length Control
    $wp_customize->add_control( 'excerpt_blog_length', array(
            'label'             => esc_html__( 'Set Blog Excerpt Length', 'guj' ),
            'section'           => 'guj_blog_management_section',
            'type'              => 'number',
            'input_attrs'       => array( 'min' => 1, 'max' => 200, 'style' => 'width: 150px;' ),
        )
    );
    
    //Page Mangement Section
    $wp_customize->add_section( 'page_option_section_settings', array(
            'title'             => esc_html__( 'Page Management', 'guj' ),
            'priority'          => 100,
            'capability'        => 'edit_theme_options',
            'panel'             => 'guj_theme_option_panel',
	)
    );

	
    //Page Layout Setting
    $wp_customize->add_setting( 'page_layout', array(
            'default'           => $default['page_layout'],
            'capability'        => 'edit_theme_options',
            'sanitize_callback' => 'guj_select_sanitize',
        )
    );
    
    //Page Layout Control
    $wp_customize->add_control( 'page_layout', array(
            'label'             => esc_html__( 'Page Layout Options', 'guj' ),
            'section'           => 'page_option_section_settings',
            'description'       => esc_html__( 'Choose between different layout options to be used as default', 'guj' ),
            'choices'           => array(
                    'page-pull-left'     => esc_html__( 'Page Sidebar - Content', 'guj' ),
                    'page-pull-right'    => esc_html__( 'Content - Page Sidebar', 'guj' ),
                    'page-no-sidebar'    => esc_html__( 'No Sidebar', 'guj' ),
                    ),
            'type'              => 'select',
            'priority'          => 170,
        )
    );


    //Footer Section
    $wp_customize->add_section( 'footer_section', array(
            'title'             => esc_html__( 'Footer Options', 'guj' ),
            'priority'          => 130,
            'capability'        => 'edit_theme_options',
            'panel'             => 'guj_theme_option_panel',
        )
    );

    //Copyright text setting
    $wp_customize->add_setting( 'copyright_text', array(
            'default'           => $default['copyright_text'],
            'capability'        => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );
    
    $wp_customize->add_control( 'copyright_text', array(
            'label'    => esc_html__( 'Footer Copyright Text', 'guj' ),
            'section'  => 'footer_section',
            'type'     => 'text',
            'priority' => 120,
        )
    );
    