<?php

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

			$wp_customize->add_control(
				new wrockmetro_Customizer_Heading_Control(
					$wp_customize,
					'wrockmetro_header_heading',
					array(
						'label'    => esc_html__( 'Block Posts Style', 'wrock-metro' ),
						'section'  => 'wrockmetro_list_block_posts',
						'priority' => 15,
					)));
			$wp_customize->add_setting(
			'wrockmetro_blockposts_style',
			array(
				'default'           => 'styleone',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'wrockmetro_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);

		$wp_customize->add_control(
			new wrockmetro_Image_Radio_Control(
				$wp_customize,
				'wrockmetro_blockposts_style',
				array(
					'label'       => __( 'Block Posts Style', 'wrock-metro' ),
					'description' => __( 'Choose Theme Header Style. After Choosing & Publish You need to REFRESH Website', 'wrock-metro' ),
					'section'     => 'wrockmetro_list_block_posts',
					'choices'     => array(
						'styleone'  => get_template_directory_uri() . '/images/block-posts-list/blockpostslist1.png',
					),
					'priority'    => apply_filters( 'wrockmetro_authorprofile_style_priority', 20 ),
				)
			));
			
			$wp_customize->add_setting(
				'wrockmetro_blockposts_headingset',
				array(
					'sanitize_callback' => 'wp_kses',
				));

			$wp_customize->add_control(
				new wrockmetro_Customizer_Heading_Control(
					$wp_customize,
					'wrockmetro_blockposts_headingset',
					array(
						'label'    => esc_html__( 'Block Posts Settings', 'wrock-metro' ),
						'section'  => 'wrockmetro_list_block_posts',
						'priority' => 25,
					)));
			
		$wp_customize->add_setting('wrockmetro_listblock_postson',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'wrockmetro_customize_sanitize_select'
			));
		$wp_customize->add_control('wrockmetro_listblock_postson',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable or Disable Block Posts','wrock-metro'),
				'settings'   => 'wrockmetro_listblock_postson',
				'section' => 'wrockmetro_list_block_posts',
				'transport'   => 'refresh',
				'choices' => array(
					'enable' => __('Enable','wrock-metro'),
					'disable' => __('Disable','wrock-metro'),
				 ),
				 'priority'    => apply_filters( 'wrockmetro_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', 'wrock-metro');
			 
			 $wp_customize->add_setting('wrockmetro_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('wrockmetro_list_block_posts_cat', array(
				'settings' => 'wrockmetro_list_block_posts_cat',
				'label'    => __('Choose Category', 'wrock-metro'),
				'type'     => 'select',
				'choices'  => $cats,
				'section'  => 'wrockmetro_list_block_posts', // Depending on where you want it to be
				'priority' => 35,
			));
			
			// Posts Numbers
		$wp_customize->add_setting('wrockmetro_listblock_posts_count',array(
			'default'		=> '5',
			'sanitize_callback'	=> 'absint'
		));
		$wp_customize->add_control('wrockmetro_listblock_posts_count',array(
			'section' => 'wrockmetro_list_block_posts',
			'label'	=> __('Numbers of Posts to show (Pro only)','wrock-metro'),
			'settings' => 'wrockmetro_listblock_posts_count',
			'priority' => 40,
			'type' => 'number'
		));	
		// Posts title character
		$wp_customize->add_setting('wrockmetro_listblock_posts_title',array(
			'default'		=> '45',
			'sanitize_callback'	=> 'absint'
		));
		$wp_customize->add_control('wrockmetro_listblock_posts_title',array(
			'section' => 'wrockmetro_list_block_posts',
			'label'	=> __('Posts Title Character Length','wrock-metro'),
			'settings' => 'wrockmetro_listblock_posts_title',
			'priority' => 45,
			'type' => 'number'
		));
		
		$wp_customize->add_setting('wrockmetro_list_block_posts_location', array(
			'default' => 'index',
			'sanitize_callback' => 'sanitize_text_field',
		));
		
		$wp_customize->add_control('wrockmetro_list_block_posts_location', array(
			'label' => __('Visiblity on Page Types', 'wrock-metro'),
			'section' => 'wrockmetro_list_block_posts',
			'type' => 'select',
			'choices' => array(
				'all_pages' => __('Everywhere', 'wrock-metro'),
				'single' => __('Single Posts', 'wrock-metro'),
				'page' => __('Pages', 'wrock-metro'),
				'archive' => __('Archive Pages', 'wrock-metro'),
				'index' => __('Index and Home', 'wrock-metro'),
			),
			'priority'    => apply_filters( 'wrockmetro_list_block_posts_location_priority', 60 ),
		));	