<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/*********************
Posts Blocks
*******************/
		$wp_customize->add_section('poster_list_block_posts',
			array(
				'title'       => __( 'List Block - Style Block 1', 'poster' ),
				'description'       => __( 'Control List Block Posts also available as WIDGET', 'poster' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'poster_theme_elements',
				'priority'    => apply_filters( 'poster_list_block_posts_priority', 10 ),
			));
			
		$wp_customize->add_setting(
				'poster_header_heading',
				array(
					'sanitize_callback' => 'wp_kses',
				));

			$wp_customize->add_control(
				new poster_Customizer_Heading_Control(
					$wp_customize,
					'poster_header_heading',
					array(
						'label'    => esc_html__( 'Block Posts Style', 'poster' ),
						'section'  => 'poster_list_block_posts',
						'priority' => 15,
					)));
			$wp_customize->add_setting(
			'poster_blockposts_style',
			array(
				'default'           => 'styleone',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'poster_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);

		$wp_customize->add_control(
			new poster_Image_Radio_Control(
				$wp_customize,
				'poster_blockposts_style',
				array(
					'label'       => __( 'Block Posts Style', 'poster' ),
					'description' => __( 'Choose Theme Header Style. After Choosing & Publish You need to REFRESH Website', 'poster' ),
					'section'     => 'poster_list_block_posts',
					'choices'     => array(
						'styleone'  => get_template_directory_uri() . '/images/block-posts-list/blockpostslist1.png',
					),
					'priority'    => apply_filters( 'poster_authorprofile_style_priority', 20 ),
				)
			));
			
			$wp_customize->add_setting(
				'poster_blockposts_headingset',
				array(
					'sanitize_callback' => 'wp_kses',
				));

			$wp_customize->add_control(
				new poster_Customizer_Heading_Control(
					$wp_customize,
					'poster_blockposts_headingset',
					array(
						'label'    => esc_html__( 'Block Posts Settings', 'poster' ),
						'section'  => 'poster_list_block_posts',
						'priority' => 25,
					)));
			
		$wp_customize->add_setting('poster_listblock_postson',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'poster_customize_sanitize_select'
			));
		$wp_customize->add_control('poster_listblock_postson',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable or Disable Block Posts','poster'),
				'settings'   => 'poster_listblock_postson',
				'section' => 'poster_list_block_posts',
				'transport'   => 'refresh',
				'choices' => array(
					'enable' => __('Enable','poster'),
					'disable' => __('Disable','poster'),
				 ),
				 'priority'    => apply_filters( 'poster_listblock_postson_priority', 30 ),
			 ));
		
			 
			$categories = get_categories();
			// Prepare categories for dropdown
			$cats = array();
			foreach ($categories as $category) {
				$cats[$category->term_id] = $category->name;
			}
			// Add an "All Categories" option
			$cats['all'] = __('All Categories', 'poster');
			 
			 $wp_customize->add_setting('poster_list_block_posts_cat', array(
				'default'            => 'all', // Set the default value to 'all'
				'sanitize_callback'  => 'sanitize_text_field' // Use appropriate sanitization
			));

			$wp_customize->add_control('poster_list_block_posts_cat', array(
				'settings' => 'poster_list_block_posts_cat',
				'label'    => __('Choose Category', 'poster'),
				'type'     => 'select',
				'choices'  => $cats,
				'section'  => 'poster_list_block_posts', // Depending on where you want it to be
				'priority' => 35,
			));
			
			// Posts Numbers
		$wp_customize->add_setting('poster_listblock_posts_count',array(
			'default'		=> '5',
			'sanitize_callback'	=> 'absint'
		));
		$wp_customize->add_control('poster_listblock_posts_count',array(
			'section' => 'poster_list_block_posts',
			'label'	=> __('Numbers of Posts to show (Pro only)','poster'),
			'settings' => 'poster_listblock_posts_count',
			'priority' => 40,
			'type' => 'number'
		));	
		// Posts title character
		$wp_customize->add_setting('poster_listblock_posts_title',array(
			'default'		=> '45',
			'sanitize_callback'	=> 'absint'
		));
		$wp_customize->add_control('poster_listblock_posts_title',array(
			'section' => 'poster_list_block_posts',
			'label'	=> __('Posts Title Character Length','poster'),
			'settings' => 'poster_listblock_posts_title',
			'priority' => 45,
			'type' => 'number'
		));
		
		$wp_customize->add_setting('poster_list_block_posts_location', array(
			'default' => 'index',
			'sanitize_callback' => 'sanitize_text_field',
		));
		
		$wp_customize->add_control('poster_list_block_posts_location', array(
			'label' => __('Visiblity on Page Types', 'poster'),
			'section' => 'poster_list_block_posts',
			'type' => 'select',
			'choices' => array(
				'all_pages' => __('Everywhere', 'poster'),
				'single' => __('Single Posts', 'poster'),
				'page' => __('Pages', 'poster'),
				'archive' => __('Archive Pages', 'poster'),
				'index' => __('Index and Home', 'poster'),
			),
			'priority'    => apply_filters( 'poster_list_block_posts_location_priority', 60 ),
		));	