<?php
/**
 * Register Post 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_post_settings' );
function pmthemes_customize_register_post_settings( $wp_customize ) {
    // Get Default Fonts from settings
    $theme_def = pmthemes_default_options();
	// Add Sections for Post Settings
	$wp_customize->add_section( 'pmthemes_section_post', array(
        'title'    => __( 'Post Settings', 'pmthemes' ),
        'priority' => 8,
		'panel' => 'pmthemes_options_panel' 
		)
	);
	// Add Sections for Related Posts
	$wp_customize->add_section( 'pmthemes_section_related', array(
        'title'    => __( 'Related Posts', 'pmthemes' ),
        'priority' => 10,
		'panel' => 'pmthemes_options_panel' 
		)
	);
    // Page and Title Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[posts_title_font_size]', array(
            'default'           => $theme_def['posts_title_font_size'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_posts_title_font_size', array(
            'label'    => __( 'Posts Title Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_post',
            'settings' => 'pmthemes_theme_options[posts_title_font_size]',
            'priority' => 1,
            'min' => 0.95,
            'max' => 4,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
    // Product Title Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[product_title_font_size]', array(
            'default'           => $theme_def['product_title_font_size'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_product_title_font_size', array(
            'label'    => __( 'Product Title Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_post',
            'settings' => 'pmthemes_theme_options[product_title_font_size]',
            'active_callback' => 'pmthemes_woocommerce_class_active',
            'priority' => 2,
            'min' => 0.95,
            'max' => 4,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );

    // Entry Font Size
    $wp_customize->add_setting( 'pmthemes_theme_options[entry_font_sizes]', array(
            'default'           => $theme_def['entry_font_sizes'],
            'type'           	=> 'option',
            'transport'         => 'postMessage',
            'sanitize_callback' => 'pmthemes_sanitize_decimal_int'
        )
    );
    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'pmthemes_control_entry_font_sizes', array(
            'label'    => __( 'Entry/Content Font Size', 'pmthemes' ),
            'section'  => 'pmthemes_section_post',
            'settings' => 'pmthemes_theme_options[entry_font_sizes]',
            'priority' => 3,
            'min' => 0.75,
            'max' => 1.95,
            'step' => 0.01,
            'unit' => 'em',
        ))
    );
	// Add Post Meta Headline
	$wp_customize->add_setting( 'pmthemes_theme_options[post_dates]', array(
		'type'           	=> 'option',
        'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
        $wp_customize, 'pmthemes_control_post_dates', array(
            'label' => __( 'Post Meta', 'pmthemes' ),
            'section' => 'pmthemes_section_post',
            'settings' => 'pmthemes_theme_options[post_dates]',
            'priority' => 4,
            )
        )
    );
	//Post Dates
	$wp_customize->add_setting( 'pmthemes_theme_options[show_post_dates]', array(
        'default'           => $theme_def['show_post_dates'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_hide_post_dates', array(
        'label'    => __( 'Show Post Dates', 'pmthemes' ),
        'section'  => 'pmthemes_section_post',
        'settings' => 'pmthemes_theme_options[show_post_dates]',
        'type'     => 'checkbox',
		'priority' => 5,
		)
	);
	// Author
	$wp_customize->add_setting( 'pmthemes_theme_options[show_post_author]', array(
        'default'           => $theme_def['show_post_author'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_hide_post_author', array(
        'label'    => __( 'Show Post Author', 'pmthemes' ),
        'section'  => 'pmthemes_section_post',
        'settings' => 'pmthemes_theme_options[show_post_author]',
        'type'     => 'checkbox',
		'priority' => 6,
		)
	);	
	// Category
	$wp_customize->add_setting( 'pmthemes_theme_options[show_post_category]', array(
        'default'           => $theme_def['show_post_category'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_hide_post_category', array(
        'label'    => __( 'Show Post Category', 'pmthemes' ),
        'section'  => 'pmthemes_section_post',
        'settings' => 'pmthemes_theme_options[show_post_category]',
        'type'     => 'checkbox',
		'priority' => 7,
		)
	);

	// Add Post Images Title
	$wp_customize->add_setting( 'pmthemes_theme_options[post_images]', array(
        'default'           => '',
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
        $wp_customize, 'pmthemes_control_post_images', array(
            'label' => __( 'Post Images', 'pmthemes' ),
            'section' => 'pmthemes_section_post',
            'settings' => 'pmthemes_theme_options[post_images]',
            'priority' => 10,
            )
        )
    );
	$wp_customize->add_setting( 'pmthemes_theme_options[post_thumbnails_single]', array(
        'default'           => $theme_def['post_thumbnails_single'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_posts_thumbnails_single', array(
        'label'    => __( 'Display featured images', 'pmthemes' ),
        'section'  => 'pmthemes_section_post',
        'settings' => 'pmthemes_theme_options[post_thumbnails_single]',
        'type'     => 'checkbox',
		'priority' => 12,
		)
	);
	// Add Comments Headline
	$wp_customize->add_setting( 'pmthemes_theme_options[comments_option]', array(
        'default'           => '',
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_attr'
        )
    );
    $wp_customize->add_control( new Pmthemes_Customize_Header_Control(
        $wp_customize, 'pmthemes_control_comments_option', array(
            'label' => __( 'Comment Section', 'pmthemes' ),
            'section' => 'pmthemes_section_post',
            'settings' => 'pmthemes_theme_options[comments_option]',
            'priority' => 13,
            )
        )
    );
	//Disable Comments
	$wp_customize->add_setting( 'pmthemes_theme_options[hide_post_comment]', array(
        'default'           => $theme_def['hide_post_comment'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_hide_post_comment', array(
        'label'    => __( 'Hide Comment Section', 'pmthemes' ),
        'section'  => 'pmthemes_section_post',
        'settings' => 'pmthemes_theme_options[hide_post_comment]',
        'type'     => 'checkbox',
		'priority' => 14,
		)
	);
	//// Add Related Posts Settings
	$wp_customize->add_setting( 'pmthemes_theme_options[related_posts_single]', array(
        'default'           => $theme_def['related_posts_single'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_related_posts_single', array(
        'label'    => __( 'Display related posts?', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_posts_single]',
        'type'     => 'checkbox',
		'priority' => 2,
		)
	);
	$wp_customize->add_setting( 'pmthemes_theme_options[related_posts_thumb]', array(
        'default'           => $theme_def['related_posts_thumb'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);	
    $wp_customize->add_control( 'pmthemes_control_related_posts_thumb', array(
        'label'    => __( 'Display thumbnails?', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_posts_thumb]',
        'type'     => 'checkbox',
		'priority' => 3
		)
	);
	$wp_customize->add_setting( 'pmthemes_theme_options[related_posts_excerpt]', array(
        'default'           => $theme_def['related_posts_excerpt'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_checkbox'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_related_posts_excerpt', array(
        'label'    => __( 'Display excerpts?', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_posts_excerpt]',
        'type'     => 'checkbox',
		'priority' => 4
		)
	);
	$wp_customize->add_setting( 'pmthemes_theme_options[related_excerpt_length]', array(
        'default'           => $theme_def['related_excerpt_length'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_number'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_related_excerpt_length', array(
        'label'    => __( 'Excerpt Length', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_excerpt_length]',
        'type'     => 'text',
		'priority' => 5,
		)
	);
    // Number of Related Posts
	$wp_customize->add_setting( 'pmthemes_theme_options[related_post_count]', array(
        'default'           => $theme_def['related_post_count'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_read_text'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_related_post_count', array(
        'label'    => __( 'Number of Related Posts', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_post_count]',
        'type'     => 'text',
		'priority' => 6
		)
	);
    // Related Header Title
	$wp_customize->add_setting( 'pmthemes_theme_options[related_header_title]', array(
        'default'           => $theme_def['related_header_title'],
		'type'           	=> 'option',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'pmthemes_sanitize_read_text'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_related_header_title', array(
        'label'    => __( 'Related Header Title', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_header_title]',
        'type'     => 'text',
		'priority' => 7,
		)
	);
    // Display Style
	$wp_customize->add_setting( 'pmthemes_theme_options[related_post_style]', array(
        'default'           => $theme_def['related_post_style'],
		'type'           	=> 'option',
        'transport'         => 'refresh',
        'sanitize_callback' => 'pmthemes_sanitize_related_post_style'
		)
	);
    $wp_customize->add_control( 'pmthemes_control_related_post_style', array(
        'label'    => __( 'Display Style', 'pmthemes' ),
        'section'  => 'pmthemes_section_related',
        'settings' => 'pmthemes_theme_options[related_post_style]',
        'type'     => 'select',
		'priority' => 8,
        'choices'  => array(
            'four-cols' => __( 'Four Columns (Default)', 'pmthemes' ),
			'three-cols' => __( 'Three Columns', 'pmthemes' ),
			'two-cols' => __( 'Two Columns', 'pmthemes' ),
            'simple-list' => __( 'One Column', 'pmthemes')
			)
		)
	);
    $wp_customize->add_setting( 'pmthemes_theme_options[related_post_order]', array(
            'default'           => $theme_def['related_post_order'],
            'type'           	=> 'option',
            'transport'         => 'refresh',
            'sanitize_callback' => 'pmthemes_sanitize_related_post_order'
        )
    );
    $wp_customize->add_control( 'pmthemes_control_related_post_order', array(
            'label'    => __( 'Display Order', 'pmthemes' ),
            'section'  => 'pmthemes_section_related',
            'settings' => 'pmthemes_theme_options[related_post_order]',
            'type'     => 'select',
            'priority' => 9,
            'choices'  => array(
                'latest-posts' => __( 'Latest Posts', 'pmthemes' ),
                'random-posts' => __( 'Random Posts', 'pmthemes' ),
                'old-posts' => __( 'Oldest Posts', 'pmthemes' ),
            )
        )
    );
}