<?php
/**
 * Post Layout Settings
 *
 * @package chic-lifestyle
 */

add_action( 'customize_register', 'chic_lifestyle_customize_register_post_layout' );

function chic_lifestyle_customize_register_post_layout( $wp_customize ) {

	$wp_customize->add_section( 'chic_lifestyle_post_layout_section', array(
    'title'          => esc_attr__( 'Post Options', 'chic-lifestyle' ),
	  'description'    => esc_attr__( 'Customize Single Post Options', 'chic-lifestyle' ),
    'panel'          => 'chic_lifestyle_general_panel',
    'priority'       => 6,
    'capability'     => 'edit_theme_options',
  ) );
	
	$wp_customize->add_setting( 'chic_lifestyle_post_details', array(
    'sanitize_callback' => 'chic_lifestyle_sanitize_array',
    'default'     => array( 'date', 'categories', 'tags', 'author_block' ),
  ) );

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

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

  $wp_customize->add_control( new Chic_Lifestyle_Separator_Control(
      $wp_customize, 'chic_lifestyle_post_layout_separator1', array(
        'section' => 'chic_lifestyle_post_layout_section',
        'priority'    => 2
      )
  ) );

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

  $wp_customize->add_control( new Chic_Lifestyle_Custom_Text(
    $wp_customize, 'chic_lifestyle_post_layout_options_text', array(
      'label' => esc_html__( 'Featured Image Options', 'chic-lifestyle' ),
      'section' => 'chic_lifestyle_post_layout_section',
      'settings' => 'chic_lifestyle_post_layout_options_text',
      'priority'    => 3
    )
  ) );

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

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

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

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

  $wp_customize->add_setting( 'chic_lifestyle_featured_image_position', array(
		'default'           => 'center',
		'sanitize_callback' => 'chic_lifestyle_sanitize_choices',
	) );

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

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