<?php 
/**
 * Fields For header top stories
 * @since 1.0
 * @package RoyalNews
 */

function royalnews_customizer_footer_news( $section ){
	if( class_exists( 'Kirki' ) ){
		$royalnews_cat = Kirki_Helper::get_terms( 'category' );
		$royalnews_cat[ 0 ] = esc_html__( 'All', 'royalnews' );
	}else{
		$royalnews_cat = array();
	}


	$section[ 'footer-news' ] = array(
		'title' => esc_html__( 'Footer News Options', 'royalnews' ),
		'priority'    => 230,
		'fields' => array(
			'enable-footer-news' => array(
				'type' => 'toggle',
				'label' => esc_html__( 'Enable', 'royalnews' ),
				'default' => true,
				'priority'    => 10,
			),
			'footer-news-title-text' => array(
				'type'        => 'text',
				'label'       => esc_html__( 'Title', 'royalnews' ),
				'default'     => esc_html__( 'You May Miss', 'royalnews' ),
				'active_callback' => array(
					array(
						'setting'  => 'enable-footer-news',
						'operator' => '==',
						'value'    => true,
					)
				),
				'partial' => array(
				    'selector' => '.footer-news-title',
				)
			),
			'footer-news-type' => array(
				'type'        => 'radio-buttonset',
				'label'       => esc_html__( 'News Type', 'royalnews' ),
				'default'     => 'post',
				'priority'    => 20,
				'choices'     => array(
					'post'   => esc_html__( 'Latest Post', 'royalnews' ),
					'category' => esc_html__( 'From Category', 'royalnews' ),
				),
				'active_callback' => array(
					array(
						'setting'  => 'enable-footer-news',
						'operator' => '==',
						'value'    => true,
					)
				),
			),
			'footer-news-category' => array(
    			'type'        => 'select',
    			'label'       => esc_html__( 'Select Category', 'royalnews' ),
    			'default'     => '0',
    			'priority'    => 30,
    			'choices'     => $royalnews_cat,
    			'active_callback' => array(
    				array(
	    				'setting'  => 'stories-type',
	    				'operator' => '==',
	    				'value'    => 'category',	
    				),
    				array(
    					'setting'  => 'enable-footer-news',
    					'operator' => '==',
    					'value'    => true,
    				)
    			),
			)
		)
	);
	return $section;
}

add_filter( 'royalnews_customizer_theme_option_panel', 'royalnews_customizer_footer_news' );
