<?php 
/**
 * NEWS FEATURED SECTION SETTINGS
 */

Kirki::add_section( 'stories_post_section', array(
	'title'    => esc_html__( 'Stories Post Section', 'newscope' ),
	'panel'    => 'newscope_front_page_options',
) );

Kirki::add_field( 'theme_config', [
	'type'        => 'switch',
	'settings'    => 'enable_sories_post',
	'label'       => esc_html__( 'Enable Stories Section', 'newscope' ),
	'section'     => 'stories_post_section',
	'default'     => 'on',
	'priority'        => 1,
	'choices'     => [
		'on'  => esc_html__( 'Enable', 'newscope' ),
		'off' => esc_html__( 'Disable', 'newscope' ),
	],
	'partial_refresh'    => [
		'storis_news_section_title_quick' => [
			'selector'        => '.tranding-stories-title',
			'render_callback' => 'newscope_customizer_quickedit',
		],
	],
] );

new \Kirki\Field\Text(
	[
		'settings' => 'storis_news_section_title',
		'label'    => esc_html__( 'Section Title', 'newscope' ),
		'section'  => 'stories_post_section',
		'default'  => esc_html__( "Trending Stories", 'newscope' ),
		'priority'        => 1,
        'active_callback' => [
            [
                'setting'  => 'enable_sories_post',
                'operator' => '===',
                'value'    => true,
            ],
        ],
	]
);

new \Kirki\Field\Radio_Image(
	[
		'settings'    => 'storis_news_section_title_tag_pro',
		'label'       => esc_html__( 'Purchase Pro', 'newscope' ),
		'description' => newscope_purchase_link(),
		'section'     => 'stories_post_section',
		'default'     => '',
		'transport'   => 'auto',
		'choices'     => [
			'1'   => get_template_directory_uri() . '/assets/image/pro/html-tag2.jpg',
		],
		'active_callback' => [
            [
                'setting'  => 'enable_sories_post',
                'operator' => '===',
                'value'    => true,
            ],
        ], 
	]
);


//===========================================
//========== Main Section Slider Settings ============
//===========================================

new \Kirki\Field\Select(
	[
		'settings'    => 'stories_post_type',
		'label'       => esc_html__( 'Select Post Type', 'newscope' ),
		'section'     => 'stories_post_section',
		'description' => esc_html__( 'Select Your Post Type Blog Post Or Web Stories', 'newscope' ),
		'default'     => 'post',
		'priority'        => 1,
		'choices'     => [
			'post' => esc_html__( 'Blog Post', 'newscope' ),
			'web-story' => esc_html__( 'Web Stories', 'newscope' ),
		],
		'active_callback' => [
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			],
		], 
	]
);

// Start Web Stories Filter

add_action('init', function() {
    if (function_exists('newscope_story_cat')) {
        Kirki::add_field('theme_config', [
            'type'        => 'switch',
            'settings'    => 'enable_stories_story_filter',
            'label'       => esc_html__('Enable Web Stories Filter', 'newscope'),
            'section'     => 'stories_post_section',
            'default'     => 'off',
            'priority'    => 1,
            'choices'     => [
                'on'  => esc_html__('Enable', 'newscope'),
                'off' => esc_html__('Disable', 'newscope'),
            ],
            'active_callback' => [
                [
                    'setting'  => 'enable_sories_post',
                    'operator' => '===',
                    'value'    => true,
                ],
                [
                    'setting'  => 'stories_post_type',
                    'operator' => '===',
                    'value'    => 'web-story',
                ],
            ],
        ]);
		new \Kirki\Field\Radio_Image(
			[
				'settings'    => 'stories_story_filter_cat_pro',
				'label'       => esc_html__( 'Purchase Pro', 'newscope' ),
				'description' => newscope_purchase_link(),
				'section'     => 'stories_post_section',
				'default'     => '',
				'transport'   => 'auto',
				'choices'     => [
					'1'   => get_template_directory_uri() . '/assets/image/pro/story-cat.jpg',
				],
				'active_callback' => [
					[
						'setting'  => 'enable_stories_story_filter',
						'operator' => '===',
						'value'    => true,
					],
					[
						'setting'  => 'enable_sories_post',
						'operator' => '===',
						'value'    => true,
					],
					[
						'setting'  => 'stories_post_type',
						'operator' => '===',
						'value'    => 'web-story',
					],
				],
			]
		);
    } else {
        new \Kirki\Field\Radio_Image([
            'settings'    => 'stories_post_no_plugin',
            'label'       => esc_html__('You Have No Active Or Installed Web Stories Plugin', 'newscope'),
            'section'     => 'stories_post_section',
            'default'     => '',
            'transport'   => 'auto',
            'priority'    => 1,
            'active_callback' => [
                [
                    'setting'  => 'enable_sories_post',
                    'operator' => '===',
                    'value'    => true,
                ],
                [
                    'setting'  => 'stories_post_type',
                    'operator' => '===',
                    'value'    => 'web-story',
                ],
            ],
        ]);
    }
});

// End Web Stories Filter 

Kirki::add_field( 'theme_config', [
	'type'        => 'switch',
	'settings'    => 'enable_stories_filter',
	'label'       => esc_html__( 'Enable Post Filter', 'newscope' ),
	'section'     => 'stories_post_section',
	'default'     => 'off',
	'choices'     => [
		'on'  => esc_html__( 'Enable', 'newscope' ),
		'off' => esc_html__( 'Disable', 'newscope' ),
	],
	'active_callback' => [
		[
			'setting'  => 'enable_sories_post',
			'operator' => '===',
			'value'    => true,
		],
		[
			'setting'  => 'stories_post_type',
			'operator' => '===',
			'value'    => 'post',
		],
	], 
] );

new \Kirki\Field\Select(
	[
		'settings'    => 'stories_select_filter',
		'label'       => esc_html__( 'Select Category Or Tags', 'newscope' ),
		'section'     => 'stories_post_section',
		'default'     => 'one',
		'choices'     => [
			'one' => esc_html__( 'Category', 'newscope' ),
			'two' => esc_html__( 'Tags', 'newscope' ),
		],
		'active_callback' => [
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			],
			[
				'setting'  => 'enable_stories_filter',
				'operator' => '===',
				'value'    => true,
			],
			[
				'setting'  => 'stories_post_type',
				'operator' => '===',
				'value'    => 'post',
			],
		], 
	]
);

new Kirki\Field\Select(
	[
		'settings'    => 'main_stories_post_cat',
		'label'       => __( 'Select Categroy', 'newscope' ),
		'section'     => 'stories_post_section',
		'default'     => '',
		'multiple'    => -1,
		'placeholder' => __( 'Select an Categorys', 'newscope' ),
		'choices'     => Kirki\Util\Helper::get_terms(array('taxonomy' => 'category')),
		'active_callback' => [
			[
				'setting'  => 'stories_select_filter',
				'operator' => '===',
				'value'    => 'one',
			],
			[
				'setting'  => 'enable_stories_filter',
				'operator' => '===',
				'value'    => true,
			],
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			],
			[
				'setting'  => 'stories_post_type',
				'operator' => '===',
				'value'    => 'post',
			],
		], 
	]
);

new \Kirki\Field\Radio_Image(
	[
		'settings'    => 'main_stories_post_tag_pro',
		'label'       => esc_html__( 'Purchase Pro', 'newscope' ),
		'description' => newscope_purchase_link(),
		'section'     => 'stories_post_section',
		'default'     => '',
		'transport'   => 'auto',
		'choices'     => [
			'1'   => get_template_directory_uri() . '/assets/image/pro/tags-pro.jpg',
		],
		'active_callback' => [
			[
				'setting'  => 'stories_select_filter',
				'operator' => '===',
				'value'    => 'two',
			],
			[
				'setting'  => 'enable_stories_filter',
				'operator' => '===',
				'value'    => true,
			],
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			],
			[
				'setting'  => 'stories_post_type',
				'operator' => '===',
				'value'    => 'post',
			],
		],
	]
);

new \Kirki\Field\Select(
	[
		'settings'        => 'stories_post_order',
		'label'           => esc_html__( 'Post Order', 'newscope' ),
		'section'         => 'stories_post_section',
		'default'         => 'ASC',
		'placeholder'     => esc_html__( 'Choose an option', 'newscope' ),
		'choices'         => [
			'ASC'  => esc_html__( 'ASC', 'newscope' ),
			'DESE' => esc_html__( 'DESE', 'newscope' ),
		],
		'active_callback' => [
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			],
		], 
	]
);

new \Kirki\Field\Select(
	[
		'settings'        => 'stories_post_postby',
		'label'           => esc_html__( 'Post Order By', 'newscope' ),
		'section'         => 'stories_post_section',
		'default'         => 'rand',
		'placeholder'     => esc_html__( 'Choose an option', 'newscope' ),
		'choices'         => [
			'none'          => esc_html__( 'None', 'newscope' ),
			'ID'            => esc_html__( 'ID', 'newscope' ),
			'date'          => esc_html__( 'Date', 'newscope' ),
			'name'          => esc_html__( 'Name', 'newscope' ),
			'title'         => esc_html__( 'Title', 'newscope' ),
			'comment_count' => esc_html__( 'Comment count', 'newscope' ),
			'rand'          => esc_html__( 'Random', 'newscope' ),
		],
		'active_callback' => [
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			],
		],
	]
);

new \Kirki\Field\Radio_Image(
	[
		'settings'    => 'stories_post_meta_pro',
		'label'       => esc_html__( 'Purchase Pro', 'newscope' ),
		'description' => newscope_purchase_link(),
		'section'     => 'stories_post_section',
		'default'     => '',
		'transport'   => 'auto',
		'choices'     => [
			'1'   => get_template_directory_uri() . '/assets/image/pro/lanth-c-t-m-d.jpg',
		],
		'active_callback' => [
			[
				'setting'  => 'enable_sories_post',
				'operator' => '===',
				'value'    => true,
			]
		],  
	]
);

		new \Kirki\Field\Background(
			[
				'settings'    => 'stories_bg',
				'label'       => esc_html__( 'Background Control', 'newscope' ),
				'description' => esc_html__( 'add Background Image or color', 'newscope' ),
				'section'     => 'stories_post_section',
				'default'     => [
					'background-color'      => '#FFF6E9',
					'background-image'      => '',
					'background-repeat'     => 'repeat',
					'background-position'   => 'center center',
					'background-size'       => 'cover',
					'background-attachment' => 'scroll',
				],
				'transport'   => 'auto',
				'output'      => [
					[
						'element' => '.trending-stories',
					],
				],
			]
		);


//====================================================
//======== Ads banner Settings ============
//====================================================

Kirki::add_field( 'theme_config', [
	'type'        => 'switch',
	'settings'    => 'stories_ads_banner_section',
	'label'       => esc_html__( 'Enable Ads Banner', 'newscope' ),
	'description' => esc_html__( 'Enable Ads Banner Here', 'newscope' ),
	'section'     => 'stories_post_section',
	'default'     => 'off',
	'choices'     => [
		'on'  => esc_html__( 'Enable', 'newscope' ),
		'off' => esc_html__( 'Disable', 'newscope' ),
	],
] );



new \Kirki\Field\Select(
	[
		'settings'    => 'stories_section_ads_type',
		'label'       => esc_html__( 'Select Ads Type', 'newscope' ),
		'section'     => 'stories_post_section',
		'default'     => 'link',
		'active_callback' => [
			[
				'setting'  => 'stories_ads_banner_section',
				'operator' => '===',
				'value'    => true,
			]
		],
		'choices'     => [
			'link' => esc_html__( 'Link', 'newscope' ),
			'code' => esc_html__( 'Code', 'newscope' ),
		],
	]
);

new \Kirki\Field\Image(
	[
		'settings'    => 'stories_section_ads_image',
		'label'       => esc_html__( 'Upload Ads image', 'newscope' ),
		'section'     => 'stories_post_section',
        'active_callback' => [
			[
				'setting'  => 'stories_section_ads_type',
				'operator' => '===',
				'value'    => 'link',
			],
			[
				'setting'  => 'stories_ads_banner_section',
				'operator' => '===',
				'value'    => true,
			]
		],
        'choices'     => [
			'save_as' => 'array',
		],
	]
);

new \Kirki\Field\URL(
	[
		'settings' => 'stories_section_ads_url',
		'label'    => esc_html__( 'Ads URL', 'newscope' ),
		'section'  => 'stories_post_section',
		'default'  => '#',
        'active_callback' => [
			[
				'setting'  => 'stories_section_ads_type',
				'operator' => '===',
				'value'    => 'link',
			],
			[
				'setting'  => 'stories_ads_banner_section',
				'operator' => '===',
				'value'    => true,
			]
		], 
	]
);

new \Kirki\Field\Radio_Image(
	[
		'settings'    => 'stories_section_ads_code_pro',
		'label'       => esc_html__( 'Purchase Pro', 'newscope' ),
		'description' => newscope_purchase_link(),
		'section'     => 'stories_post_section',
		'default'     => '',
		'transport'   => 'auto',
		'choices'     => [
			'1'   => get_template_directory_uri() . '/assets/image/pro/ads-code.jpg',
		],
		'active_callback' => [
			[
				'setting'  => 'stories_section_ads_type',
				'operator' => '===',
				'value'    => 'code',
			],
			[
				'setting'  => 'stories_ads_banner_section',
				'operator' => '===',
				'value'    => true,
			]
		],  
	]
);
