<?php
/**
 * Register Archive Settings section, settings and controls for Theme Customizer
 *
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
// Add Post Settings
add_action( 'customize_register', 'pmthemes_customize_register_archive_settings' );
function pmthemes_customize_register_archive_settings( $wp_customize ) {
    // Get Default Fonts from settings
    $theme_def = pmthemes_default_options();
    // Add Sections for Archive Settings
    $wp_customize->add_section( 'pmthemes_section_archives', array(
            'title'    => __( 'Archive Settings', 'pmthemes' ),
            'description' => __( 'To view live changes, please navigate to any archive pages (i.e. Category page, Tag page).', 'pmthemes' ),
            'priority' => 9,
            'panel' => 'pmthemes_options_panel'
        )
    );

    // Post Length on archives
    $wp_customize->add_setting( 'pmthemes_theme_options[posts_length]', array(
            'default'           => $theme_def['posts_length'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_post_length'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_posts_length', array(
            'label'    => __( 'Post Length on Archives', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[posts_length]',
            'type'     => 'select',
            'choices'  => array(
                'excerpt' => __( 'Show post excerpt', 'pmthemes' ),
                'fullpost' => __( 'Show full post', 'pmthemes' ),
            )
        )
    );
    // Excerpt Length on archives
    $wp_customize->add_setting( 'pmthemes_theme_options[arch_excerpt_length]', array(
            'default'           => $theme_def['arch_excerpt_length'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_number'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_arch_excerpt_length', array(
            'label'    => __( 'Excerpt Length', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[arch_excerpt_length]',
            'active_callback' =>'pmthemes_archive_excerpt_length',
            'type'     => 'text',
        )
    );
    // Read More Label
    $wp_customize->add_setting( 'pmthemes_theme_options[excerpt_text]', array(
            'default'           => $theme_def['excerpt_text'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_read_text'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_excerpt_text', array(
            'label'    => __( 'Read More Label', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[excerpt_text]',
            'active_callback' =>'pmthemes_archive_excerpt_length',
            'type'     => 'text',
        )
    );
    // Archive Page Layout
    $wp_customize->add_setting( 'pmthemes_theme_options[archive_lyt_header]', array(
            'type'           	=> 'option',
            'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new pmthemes_Customize_Header_Control(
            $wp_customize, 'pmthemes_control_archive_layout', array(
                'label' => __( 'Archive Page Layout', 'pmthemes' ),
                'section' => 'pmthemes_section_archives',
                'settings' => 'pmthemes_theme_options[archive_lyt_header]',
            )
        )
    );
    // Display Full Width
    $wp_customize->add_setting( 'pmthemes_theme_options[pmthemes_display_fullw]', array(
            'default'           => $theme_def['pmthemes_display_fullw'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_archive_display_fullw', array(
            'label'    => __( 'Display Full Width?', 'pmthemes' ),
            'description'  => __( 'Set to full page and hide sidebar.', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmthemes_display_fullw]',
            'type'     => 'checkbox',
        )
    );
    // Align Archive Title
    $wp_customize->add_setting( 'pmthemes_theme_options[pmth_arc_align_header]', array(
            'default'           => $theme_def['pmth_arc_align_header'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_align_elements'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_archive_center_header', array(
            'label'    => __( 'Archive Title Alignment', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmth_arc_align_header]',
            'type' => 'select',
            'choices' => pmthemes_align_elements(),
        )
    );
    // Grid Column Option
    $wp_customize->add_setting( 'pmthemes_theme_options[pmth_grid_col_opt]', array(
            'default'           => $theme_def['pmth_grid_col_opt'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_grid_col_opt'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_grid_col_opt', array(
            'label'    => __( 'Grid Column Option', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmth_grid_col_opt]',
            'type'     => 'select',
            'choices'  => array(
                'pmth-grid-itmw' => __( 'Item Width', 'pmthemes' ),
                'pmth-grid-coln' => __( 'Column No.', 'pmthemes' ),
            )
        )
    );
    // Grid Item With
    $wp_customize->add_setting( 'pmthemes_theme_options[pmth_grid_width]', array(
            'default'           => $theme_def['pmth_grid_width'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_pmth_grid_width'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_pmth_grid_width', array(
            'label'    => __( 'Grid Item With', 'pmthemes' ),
            'description' => __( 'Set Width for each item on the grid.', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmth_grid_width]',
            'active_callback' =>'pmthemes_pmth_grid_itemw_active',
            'type' => 'select',
            'choices' => pmthemes_grid_widths(),
        )
    );
    // Grid No. of Columns
    $wp_customize->add_setting( 'pmthemes_theme_options[pmth_grid_column]', array(
            'default'           => $theme_def['pmth_grid_column'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_pmth_grid_column'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_pmth_grid_column', array(
            'label'    => __( 'No. of Columns', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmth_grid_column]',
            'active_callback' =>'pmthemes_pmth_grid_coln_active',
            'type' => 'select',
            'choices' => pmthemes_grid_columns(),
        )
    );
    // Archive Featured Images
    $wp_customize->add_setting( 'pmthemes_theme_options[archive_featimg_header]', array(
            'type'           	=> 'option',
            'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new pmthemes_Customize_Header_Control(
            $wp_customize, 'pmthemes_control_archive_images', array(
                'label' => __( 'Archive Featured Images', 'pmthemes' ),
                'section' => 'pmthemes_section_archives',
                'settings' => 'pmthemes_theme_options[archive_featimg_header]',
            )
        )
    );
    // Display featured images
    $wp_customize->add_setting( 'pmthemes_theme_options[post_thumbnails_index]', array(
            'default'           => $theme_def['post_thumbnails_index'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_checkbox'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_posts_thumbnails_index', array(
            'label'    => __( 'Display featured images', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[post_thumbnails_index]',
            'type'     => 'checkbox',
        )
    );
    // Archive Image Size
    $wp_customize->add_setting( 'pmthemes_theme_options[pmth_arc_img_size]', array(
            'default'           => $theme_def['pmth_arc_img_size'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_image_size'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_arc_img_size', array(
            'label'    => __( 'Featured Image Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmth_arc_img_size]',
            'active_callback' =>'pmthemes_archive_images_active',
            'type' => 'select',
            'choices'  => array(
                'pmth-img-thumb' => __( 'Thumbnail', 'pmthemes' ),
                'pmth-img-large' => __( 'Large Size', 'pmthemes' ),
            )
        )
    );
    // Archive Image Alignment
    $wp_customize->add_setting( 'pmthemes_theme_options[pmth_arc_align_img]', array(
            'default'           => $theme_def['pmth_arc_align_img'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_align_images'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_arc_align_img', array(
            'label'    => __( 'Featured Image Alignment', 'pmthemes' ),
            'section'  => 'pmthemes_section_archives',
            'settings' => 'pmthemes_theme_options[pmth_arc_align_img]',
            'active_callback' =>'pmthemes_archive_images_active',
            'type' => 'select',
            'choices' => pmthemes_align_images(),
        )
    );
}