<?php
/**
 * Post Layout Settings
 *
 * @package bootstrap_coach
 */

add_action( 'customize_register', 'bootstrap_coach_customize_register_post_layout' );

function bootstrap_coach_customize_register_post_layout( $wp_customize ) {

	$wp_customize->add_section( 'bootstrap_coach_post_layout_section', array(
		'title'       => esc_attr__( 'Post Options', 'bootstrap-coach' ),
		'description' => esc_attr__( 'Customize Single Posts', 'bootstrap-coach' ),
		'panel'       => 'bootstrap_coach_general_panel',
		'priority'    => 5,
		'capability'  => 'edit_theme_options',
	) );

	$wp_customize->add_setting( 'bootstrap_coach_post_details', array(
		'sanitize_callback' => 'bootstrap_coach_sanitize_array',
		'default'           => array( 'date', 'categories', 'tags', 'author_block' ),
	) );

	$wp_customize->add_control( new Bootstrap_Coach_Multi_Check_Control(
		$wp_customize, 'bootstrap_coach_post_details', array(
			'label'    => esc_attr__( 'Hide / Show Details', 'bootstrap-coach' ),
			'section'  => 'bootstrap_coach_post_layout_section',
			'settings' => 'bootstrap_coach_post_details',
			'type'     => 'multi-check',
			'priority' => 1,
			'choices'  => array(
				'author'            => esc_attr__( 'Show post author', 'bootstrap-coach' ),
				'date'              => esc_attr__( 'Show post date', 'bootstrap-coach' ),
				'categories'        => esc_attr__( 'Show Categories', 'bootstrap-coach' ),
				'tags'              => esc_attr__( 'Show Tags', 'bootstrap-coach' ),
				'number_of_comments' => esc_attr__( 'Show number of comments', 'bootstrap-coach' ),
				'author_block'      => esc_attr__( 'Show Author Block', 'bootstrap-coach' ),
			),
		)
	) );

	$wp_customize->add_setting( 'bootstrap_coach_post_layout_separator1', array(
		'sanitize_callback' => null,
	) );

	$wp_customize->add_control( new Bootstrap_Coach_Separator_Control(
		$wp_customize, 'bootstrap_coach_post_layout_separator1', array(
			'section'  => 'bootstrap_coach_post_layout_section',
			'priority' => 2,
		)
	) );

	$wp_customize->add_setting( 'bootstrap_coach_post_layout_options_text', array(
		'default'           => '',
		'type'              => 'customtext',
		'capability'        => 'edit_theme_options',
		'transport'         => 'refresh',
		'sanitize_callback' => 'sanitize_text_field',
	) );

	$wp_customize->add_control( new Bootstrap_Coach_Custom_Text(
		$wp_customize, 'bootstrap_coach_post_layout_options_text', array(
			'label'    => esc_html__( 'Featured Image Options', 'bootstrap-coach' ),
			'section'  => 'bootstrap_coach_post_layout_section',
			'settings' => 'bootstrap_coach_post_layout_options_text',
			'priority' => 3,
		)
	) );

	$wp_customize->add_setting( 'bootstrap_coach_featured_image_width', array(
		'default'           => 'full',
		'sanitize_callback' => bootstrap_coach_sanitize_choices_with_max_value( 'full', 400, 1200, array( 'full' ) ),
	) );

	$wp_customize->add_control( new Bootstrap_Coach_Slider_Control(
		$wp_customize, 'bootstrap_coach_featured_image_width', array(
			'section'     => 'bootstrap_coach_post_layout_section',
			'settings'    => 'bootstrap_coach_featured_image_width',
			'label'       => esc_attr__( 'Image width', 'bootstrap-coach' ),
			'description' => esc_attr__( 'Set the width of the featured image on single pages and posts.', 'bootstrap-coach' ),
			'priority'    => 5,
			'choices'     => array(
				'min'       => 400,
				'max'       => 1200,
				'step'      => 50,
				'suffix'    => 'px',
				'max_value' => 'full',
				'max_text'  => esc_attr__( 'Full', 'bootstrap-coach' ),
			),
		)
	) );

	$wp_customize->add_setting( 'bootstrap_coach_featured_image_max_height', array(
		'default'           => 'full',
		'sanitize_callback' => bootstrap_coach_sanitize_choices_with_max_value( 'full', 200, 800, array( 'full' ) ),
	) );

	$wp_customize->add_control( new Bootstrap_Coach_Slider_Control(
		$wp_customize, 'bootstrap_coach_featured_image_max_height', array(
			'section'     => 'bootstrap_coach_post_layout_section',
			'settings'    => 'bootstrap_coach_featured_image_max_height',
			'description' => esc_attr__( 'Set the maximal height of the featured image on single pages and posts.', 'bootstrap-coach' ),
			'label'       => esc_attr__( 'Maximal image height', 'bootstrap-coach' ),
			'priority'    => 6,
			'choices'     => array(
				'min'       => 200,
				'max'       => 800,
				'step'      => 25,
				'suffix'    => 'px',
				'max_value' => 'full',
				'max_text'  => esc_attr__( 'Full', 'bootstrap-coach' ),
			),
		)
	) );

	$wp_customize->add_setting( 'bootstrap_coach_featured_image_position', array(
		'default'           => 'center',
		'sanitize_callback' => 'bootstrap_coach_sanitize_choices',
	) );

	$wp_customize->add_control( 'bootstrap_coach_featured_image_position', array(
		'settings'    => 'bootstrap_coach_featured_image_position',
		'label'       => esc_attr__( 'Image position', 'bootstrap-coach' ),
		'description' => esc_attr__( 'Choose the position of the featured image on single pages and posts.', 'bootstrap-coach' ),
		'section'     => 'bootstrap_coach_post_layout_section',
		'type'        => 'select',
		'priority'    => 7,
		'choices'     => array(
			'left'   => esc_attr__( 'Left', 'bootstrap-coach' ),
			'center' => esc_attr__( 'Center', 'bootstrap-coach' ),
			'right'  => esc_attr__( 'Right', 'bootstrap-coach' ),
		),
	) );

	$wp_customize->selective_refresh->add_partial( 'bootstrap_coach_featured_image_width', array(
		'selector' => '#featured-image',
	) );
}
