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

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

	$section[ 'header_stories_options' ] = array(
		'title' => esc_html__( 'Header Top Stories Options', 'royalnews' ),
		'priority'    => 15,
		'fields' => array(
			'enable-haeder-stories' => array(
				'type' => 'toggle',
				'label' => esc_html__( 'Enable Header Stories', 'royalnews' ),
				'default' => true,
				'priority'    => 10,
			),
			'stories-title-text' => array(
				'type'        => 'text',
				'label'       => esc_html__( 'Title', 'royalnews' ),
				'default'     => esc_html__( 'Top Stories', 'royalnews' ),
				'active_callback' => array(
					array(
						'setting'  => 'enable-haeder-stories',
						'operator' => '==',
						'value'    => true,
					)
				),
				'partial' => array(
				    'selector' => '.royalnews-stoories-title',
				)
			),
			'stories-type' => array(
				'type'        => 'radio-buttonset',
				'label'       => esc_html__( 'Top stories 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-haeder-stories',
						'operator' => '==',
						'value'    => true,
					)
				),
			),
			'stories-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-haeder-stories',
    					'operator' => '==',
    					'value'    => true,
    				)
    			),
			),
			'story-bg-color'    => array(
			    'label' => esc_html__( 'Background Color', 'royalnews' ),
			    'type'  => 'color',
			    'default'   => '#000000',
			    'priority'    => 40,
			    'active_callback' => array(
			    	array(
			    		'setting'  => 'enable-haeder-stories',
			    		'operator' => '==',
			    		'value'    => true,
			    	)
			    ),
			    'output' => array(
			        array(
			            'element'  => '.royalnews-stories-main-wrapper',
			            'property' => 'background',
			        )
			    ),
			),
			'story-text-color'    => array(
			    'label' => esc_html__( 'Terxt Color', 'royalnews' ),
			    'type'  => 'color',
			    'default'   => '#ffffff',
			    'priority'    => 50,
			    'active_callback' => array(
			    	array(
			    		'setting'  => 'enable-haeder-stories',
			    		'operator' => '==',
			    		'value'    => true,
			    	)
			    ),
			    'output' => array(
			        array(
			            'element'  => '.royalnews-stories-main-wrapper',
			            'property' => 'color',
			        )
			    ),
			),
		)
	);
	return $section;
}

add_filter( 'royalnews_customizer_theme_option_panel', 'royalnews_customizer_header_stories' );
