<?php

$wp_customize->add_section('constructionarc_blog_template', array(
    'title'		  => esc_html__('Blog / Single Post Settings','construction-arc'),
    'priority'	  => 65,
));

    $wp_customize->add_setting('constructionarc_blog_nav', array(
        'transport' => 'postMessage',
        'sanitize_callback' => 'wp_kses_post',
        'priority' => -1,
    ));
    $wp_customize->add_control(new constructionarc_Custom_Control_Tab($wp_customize, 'constructionarc_blog_nav', array(
        'type' => 'tab',
        'section' => 'constructionarc_blog_template',
        'buttons' => array(
            array(
                'name' => esc_html__('Blog List', 'construction-arc'),
                'fields' => array(
                    'constructionarc_blogtemplate_postcat',
                    'constructionarc_blog_template_sidebar',
                    'constructionarc_post_heading',
                    'constructionarc_post_column',
                    'constructionarc_blog_post_space',
                    'constructionarc_blogtemplate_btn',
                    'constructionarc_post_excerpt_length',
                    'constructionarc_post_date_options',
                    'constructionarc_post_comments_options',
                    'constructionarc_post_author_options',
                    'constructionarc_post_reading_time',
                    'constructionarc_blog_alignment'
                ),
                'active' => true,
            ),
            array(
                'name' => esc_html__('Single Blog', 'construction-arc'),
                'fields' => array(
                    'constructionarc_blog_single_template_sidebar',
                    'constructionarc_blog_single_alignment',
                    'constructionarc_single_blog_title',
                    'constructionarc_single_post_top_elements',
                    'constructionarc_single_post_bottom_elements'
                )
            )
        )
    )));

	$wp_customize->add_setting('constructionarc_blog_template_sidebar', array(
		'default' => 'right',
		'sanitize_callback' => 'constructionarc_themes_sanitize_options',
	));
	$wp_customize->add_control(new constructionarc_Selector($wp_customize, 'constructionarc_blog_template_sidebar', array(
		'section' => 'constructionarc_blog_template',
        'label' => esc_html__('Blog Page Sidebar', 'construction-arc'),
		'options' => array(
			'left' => get_template_directory_uri() . '/inc/customizer/images/left-sidebar.png',
			'right' => get_template_directory_uri() . '/inc/customizer/images/right-sidebar.png',
			'no' => get_template_directory_uri() . '/inc/customizer/images/no-sidebar.png',
		)
	)));

    $wp_customize->add_setting('constructionarc_post_column', array(
        'sanitize_callback' => 'absint',
        'default' => 2,
        'transport' => 'postMessage',
    ));
    $wp_customize->add_control(new constructionarc_Themes_Range_Control($wp_customize, 'constructionarc_post_column', array(
        'section' => 'constructionarc_blog_template',
        'label' => esc_html__('No of Column(s)', 'construction-arc'),
        'input_attrs' => array(
            'min' => 1,
            'max' => 4,
            'step' => 1,
        )
    )));

    $wp_customize->add_setting('constructionarc_blog_post_space', array(
        'sanitize_callback' => 'absint',
        'default' => 1,
        'transport' => 'postMessage',
    ));
    $wp_customize->add_control(new constructionarc_Themes_Range_Control($wp_customize, 'constructionarc_blog_post_space', array(
        'section' => 'constructionarc_blog_template',
        'label' => esc_html__('Block Space (rem)', 'construction-arc'),
        'input_attrs' => array(
            'min' => 0,
            'max' => 4,
            'step' => 1,
        )
    )));

    $wp_customize->add_setting( 'constructionarc_blog_alignment', array(
        'default'           => 'text-center',
        'sanitize_callback' => 'constructionarc_themes_sanitize_select',
        'transport'         => 'postMessage'
    ));
    $wp_customize->add_control(new constructionarc_Custom_Control_Buttonset($wp_customize,'constructionarc_blog_alignment',
        array(
            'choices'  => array(
                'text-left' => esc_html__('Left', 'construction-arc'),
                'text-right' => esc_html__('Right', 'construction-arc'),
                'text-center' => esc_html__('Center', 'construction-arc'),
            ),
            'label'    => esc_html__( 'Alignment', 'construction-arc' ),
            'section'  => 'constructionarc_blog_template',
            'settings' => 'constructionarc_blog_alignment',
        )
    ));

    $wp_customize->add_setting( 'constructionarc_blogtemplate_btn', array(
        'default'           => esc_html__( 'Read More','construction-arc' ),
        'sanitize_callback' => 'sanitize_text_field',		
        'transport'         => 'postMessage',
    ));
    $wp_customize->add_control('constructionarc_blogtemplate_btn', array(
        'label'		  => esc_html__( 'Button Text', 'construction-arc' ),
        'section'	  => 'constructionarc_blog_template',
        'type' 		  => 'text',
    ));
    
    $wp_customize->add_setting( 'constructionarc_post_excerpt_length', array(
        'default'    => 20,
        'sanitize_callback' => 'absint'
    ));
    $wp_customize->add_control(new constructionarc_Themes_Range_Control($wp_customize, 'constructionarc_post_excerpt_length', array(
        'section' => 'constructionarc_blog_template',
        'label' => esc_html__('Excerpt Length (words number)', 'construction-arc'),
        'input_attrs' => array(
            'min' => 10,
            'max' => 100,
            'step' => 5
        )
    )));
    
    $wp_customize->add_setting('constructionarc_post_date_options', array(
        'default' => 'enable',
        'sanitize_callback' => 'constructionarc_themes_sanitize_switch',    
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new constructionarc_Switch_Control($wp_customize, 'constructionarc_post_date_options', array(
        'label' => esc_html__('Post Meta Date', 'construction-arc'),
        'section' => 'constructionarc_blog_template',
        'switch_label' => array(
            'enable' => esc_html__('Yes', 'construction-arc'),
            'disable' => esc_html__('No', 'construction-arc'),
        ),
    )));
   
    $wp_customize->add_setting('constructionarc_post_comments_options', array(
        'default' => 'enable',
        'sanitize_callback' => 'constructionarc_themes_sanitize_switch',    
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new constructionarc_Switch_Control($wp_customize, 'constructionarc_post_comments_options', array(
        'label' => esc_html__('Post Comments', 'construction-arc'),
        'section' => 'constructionarc_blog_template',
        'switch_label' => array(
            'enable' => esc_html__('Yes', 'construction-arc'),
            'disable' => esc_html__('No', 'construction-arc'),
        ),
    )));
   
    $wp_customize->add_setting('constructionarc_post_author_options', array(
        'default' => 'enable',
        'sanitize_callback' => 'constructionarc_themes_sanitize_switch',    
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new constructionarc_Switch_Control($wp_customize, 'constructionarc_post_author_options', array(
        'label' => esc_html__('Post Meta Author', 'construction-arc'),
        'section' => 'constructionarc_blog_template',
        'switch_label' => array(
            'enable' => esc_html__('Yes', 'construction-arc'),
            'disable' => esc_html__('No', 'construction-arc'),
        ),
    )));

    $wp_customize->add_setting('constructionarc_post_reading_time', array(
        'default' => 'enable',
        'sanitize_callback' => 'constructionarc_themes_sanitize_switch',    
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new constructionarc_Switch_Control($wp_customize, 'constructionarc_post_reading_time', array(
        'label' => esc_html__('Reading Time', 'construction-arc'),
        'section' => 'constructionarc_blog_template',
        'switch_label' => array(
            'enable' => esc_html__('Yes', 'construction-arc'),
            'disable' => esc_html__('No', 'construction-arc'),
        ),
    )));

	$wp_customize->add_setting('constructionarc_blog_single_template_sidebar', array(
		'default' => 'right',
		'sanitize_callback' => 'constructionarc_themes_sanitize_options'
	));
	$wp_customize->add_control(new constructionarc_Selector($wp_customize, 'constructionarc_blog_single_template_sidebar', array(
		'section' => 'constructionarc_blog_template',
        'label' => esc_html__('Blog Single Post', 'construction-arc'),
		'options' => array(
			'left' => get_template_directory_uri() . '/inc/customizer/images/left-sidebar.png',
			'right' => get_template_directory_uri() . '/inc/customizer/images/right-sidebar.png',
			'no' => get_template_directory_uri() . '/inc/customizer/images/no-sidebar.png',
		)
	)));


    $wp_customize->add_setting('constructionarc_blog_single_alignment',
        array(
            'default'           => 'text-left',
            'sanitize_callback' => 'constructionarc_themes_sanitize_select',
            'transport'         => 'postMessage',
        )
    );
    $wp_customize->add_control(new constructionarc_Custom_Control_Buttonset($wp_customize,'constructionarc_blog_single_alignment',
         array(
            'label'    => esc_html__( 'Main Content Alignment', 'construction-arc' ),
            'section'  => 'constructionarc_blog_template',
            'choices'  => array(
                'text-left' => esc_html__('Left', 'construction-arc'),
                'text-right' => esc_html__('Right', 'construction-arc'),
                'text-center' => esc_html__('Center', 'construction-arc'),
            )
        )
    ));

    $wp_customize->add_setting('constructionarc_single_post_top_elements', array(
        'default' => array('title', 'post_meta', 'content'),
        'sanitize_callback' => 'constructionarc_themes_sanitize_multi_choices',
        'transport' => 'postMessage'
    ));
    
    $wp_customize->add_control(new constructionarc_Sortable_Control($wp_customize, 'constructionarc_single_post_top_elements', array(
        'label' => esc_html__('Main Content Display & Order', 'construction-arc'),
        'section' => 'constructionarc_blog_template',
        'settings' => 'constructionarc_single_post_top_elements',
        'choices' => array(
            'title' => esc_html__('Title', 'construction-arc'),
            'post_meta' => esc_html__('Post Meta', 'construction-arc'),
            'content' => esc_html__('Content', 'construction-arc'),
        )
    )));
    

    $wp_customize->add_setting('constructionarc_single_post_bottom_elements', array(
        'default' => array('pagination', 'comment', 'related_posts'),
        'sanitize_callback' => 'constructionarc_themes_sanitize_multi_choices',
    ));
    
    $wp_customize->add_control(new constructionarc_Sortable_Control($wp_customize, 'constructionarc_single_post_bottom_elements', array(
        'label' => esc_html__('Other Content Display & Order', 'construction-arc'),
        'section' => 'constructionarc_blog_template',
        'settings' => 'constructionarc_single_post_bottom_elements',
        'choices' => array(
            'pagination' => esc_html__('Prev/Next Navigation', 'construction-arc'),
            'comment' => esc_html__('Comment', 'construction-arc'),
            'related_posts' => esc_html__('Related Posts', 'construction-arc')
        )
    )));

    $wp_customize->selective_refresh->add_partial( 'constructionarc_single_post_top_elements', array(
    'selector'        => '.singlearticle',
    'container_inclusive'  => false,
    'render_callback' => function() {
        get_template_part( 'template-parts/content', 'single' ); 
    }
) );