<?php

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

			$wp_customize->add_control(
				new magazinestyle_Customizer_Heading_Control(
					$wp_customize,
					'magazinestyle_header_heading',
					array(
						'label'    => esc_html__( 'Block Posts Style', 'magazine-style' ),
						'section'  => 'magazinestyle_list_block_posts',
						'priority' => 15,
					)));
			$wp_customize->add_setting(
			'magazinestyle_blockposts_style',
			array(
				'default'           => 'styleone',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'magazinestyle_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);

		$wp_customize->add_control(
			new magazinestyle_Image_Radio_Control(
				$wp_customize,
				'magazinestyle_blockposts_style',
				array(
					'label'       => __( 'Block Posts Style', 'magazine-style' ),
					'description' => __( 'Choose Theme Header Style. After Choosing & Publish You need to REFRESH Website', 'magazine-style' ),
					'section'     => 'magazinestyle_list_block_posts',
					'choices'     => array(
						'styleone'  => get_template_directory_uri() . '/images/block-posts-list/blockpostslist1.png',
					),
					'priority'    => apply_filters( 'magazinestyle_authorprofile_style_priority', 20 ),
				)
			));
			
			$wp_customize->add_setting(
				'magazinestyle_blockposts_headingset',
				array(
					'sanitize_callback' => 'wp_kses',
				));

			$wp_customize->add_control(
				new magazinestyle_Customizer_Heading_Control(
					$wp_customize,
					'magazinestyle_blockposts_headingset',
					array(
						'label'    => esc_html__( 'Block Posts Settings', 'magazine-style' ),
						'section'  => 'magazinestyle_list_block_posts',
						'priority' => 25,
					)));
			
		$wp_customize->add_setting('magazinestyle_list_block_posts_on',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'magazinestyle_customize_sanitize_select'
			));
		$wp_customize->add_control('magazinestyle_list_block_posts_on',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable or Disable Block Posts','magazine-style'),
				'settings'   => 'magazinestyle_list_block_posts_on',
				'section' => 'magazinestyle_list_block_posts',
				'transport'   => 'refresh',
				'choices' => array(
					'enable' => __('Enable','magazine-style'),
					'disable' => __('Disable','magazine-style'),
				 ),
				 'priority'    => apply_filters( 'magazinestyle_authorpro_on_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', 'magazine-style');
			 
			 $wp_customize->add_setting('magazinestyle_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('magazinestyle_list_block_posts_cat', array(
				'settings' => 'magazinestyle_list_block_posts_cat',
				'label'    => __('Choose Category', 'magazine-style'),
				'type'     => 'select',
				'choices'  => $cats,
				'section'  => 'magazinestyle_list_block_posts', // Depending on where you want it to be
				'priority' => 35,
			));
			
			// Posts Numbers
		$wp_customize->add_setting('magazinestyle_listblock_posts_count',array(
			'default'		=> '5',
			'sanitize_callback'	=> 'absint'
		));
		$wp_customize->add_control('magazinestyle_listblock_posts_count',array(
			'section' => 'magazinestyle_list_block_posts',
			'label'	=> __('Numbers of Posts to show (Pro Only)','magazine-style'),
			'settings' => 'magazinestyle_listblock_posts_count',
			'priority' => 40,
			'type' => 'number'
		));	
		// Posts title character
		$wp_customize->add_setting('magazinestyle_listblock_posts_title',array(
			'default'		=> '45',
			'sanitize_callback'	=> 'absint'
		));
		$wp_customize->add_control('magazinestyle_listblock_posts_title',array(
			'section' => 'magazinestyle_list_block_posts',
			'label'	=> __('Posts Title Character Length','magazine-style'),
			'settings' => 'magazinestyle_listblock_posts_title',
			'priority' => 45,
			'type' => 'number'
		));
		
		$wp_customize->add_setting('magazinestyle_list_block_posts_location', array(
			'default' => 'index',
			'sanitize_callback' => 'sanitize_text_field',
		));
		
		$wp_customize->add_control('magazinestyle_list_block_posts_location', array(
			'label' => __('Visiblity on Page Types', 'magazine-style'),
			'section' => 'magazinestyle_list_block_posts',
			'type' => 'select',
			'choices' => array(
				'all_pages' => __('Everywhere', 'magazine-style'),
				'single' => __('Single Posts', 'magazine-style'),
				'page' => __('Pages', 'magazine-style'),
				'archive' => __('Archive Pages', 'magazine-style'),
				'index' => __('Index and Home', 'magazine-style'),
			),
			'priority'    => apply_filters( 'magazinestyle_list_block_posts_location_priority', 60 ),
		));	