<?php
/**
 * Theme Functions.
 */

/* Theme Setup */
if (!function_exists('catering_lite_setup')):

function catering_lite_setup() {

	$GLOBALS['content_width'] = apply_filters('catering_lite_content_width', 640);

	add_theme_support('automatic-feed-links');
	add_theme_support('post-thumbnails');
	add_theme_support('title-tag');
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'html5', array( 'comment-list', 'search-form', 'comment-form', ) );
	add_theme_support( 'align-wide' );
	add_theme_support( 'wp-block-styles' );
	add_theme_support('custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	));

	add_theme_support('custom-background', array(
		'default-color' => 'ffffff',
	));
}
endif;
add_action('after_setup_theme', 'catering_lite_setup');

add_action( 'wp_enqueue_scripts', 'catering_lite_enqueue_styles' );
function catering_lite_enqueue_styles() {
	wp_enqueue_style( 'bootstrap-css', esc_url(get_template_directory_uri()).'/css/bootstrap.css' );
	$parent_style = 'food-truck-lite-basic-style'; // Style handle of parent theme.
	wp_enqueue_style( $parent_style, esc_url(get_template_directory_uri()) . '/style.css' );
	wp_enqueue_style( 'catering-lite-style', get_stylesheet_uri(), array( $parent_style ) );
	if (is_singular() && comments_open() && get_option('thread_comments')) {
		wp_enqueue_script('comment-reply');
	}
}

function catering_lite_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'catering-lite' ),
		'description'   => __( 'Appears on blog page sidebar', 'catering-lite' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s p-2 mb-4">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title pt-0 mb-2">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'catering_lite_widgets_init' );

function catering_lite_customize_register() {     
	global $wp_customize;

	// What we do Section
	$wp_customize->add_section('catering_lite_recipe_section',array(
		'title'	=> __('Recipe Section','catering-lite'),
		'description'	=> __('Add Recipee sections below.','catering-lite'),
		'priority' => 30,
		'panel' => 'food_truck_lite_panel_id',
	));

	$wp_customize->add_setting('catering_lite_small_title',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('catering_lite_small_title',array(
		'label'	=> __('Section Small Title','catering-lite'),
		'section' => 'catering_lite_recipe_section',
		'type'	 => 'text'
	));

	$wp_customize->add_setting('catering_lite_section_title',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('catering_lite_section_title',array(
		'label'	=> __('Section Title','catering-lite'),
		'section'	=> 'catering_lite_recipe_section',
		'type'		=> 'text'
	));

	$args = array('numberposts' => -1);
	$post_list = get_posts($args);
	$i = 0;
	$pst2[]='Select';  
	foreach($post_list as $post){
		$pst2[$post->post_title] = $post->post_title;
	}

	$wp_customize->add_setting('catering_lite_video_post',array(
		'sanitize_callback' => 'food_truck_lite_sanitize_choices',
	));
	$wp_customize->add_control('catering_lite_video_post',array(
		'type'    => 'select',
		'choices' => $pst2,
		'label' => __('Select video post','catering-lite'),
		'section' => 'catering_lite_recipe_section',
	));

	// category
	$categories = get_categories();
	$cats = array();
	$i = 0;
	$cat_post1[]= 'select';
	foreach($categories as $category){
		if($i==0){
			$default = $category->slug;
			$i++;
		}
		$cat_post1[$category->slug] = $category->name;
	}

	$wp_customize->add_setting( 'catering_lite_recipe_category', array(
      	'default'           => '',
      	'sanitize_callback' => 'food_truck_lite_sanitize_choices'
    ));
    $wp_customize->add_control('catering_lite_recipe_category',array(
		'type'    => 'select',
		'choices' => $cat_post1,
		'label' => __('Select Category to display Latest Post','catering-lite'),
		'section' => 'catering_lite_recipe_section',
	));

	$wp_customize->add_setting('catering_lite_viewall_btn_text',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('catering_lite_viewall_btn_text',array(
		'label'	=> __('View All Button Text','catering-lite'),
		'section'	=> 'catering_lite_recipe_section',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('catering_lite_viewall_btn_url',array(
		'default'	=> '',
		'sanitize_callback'	=> 'esc_url_raw'
	));	
	$wp_customize->add_control('catering_lite_viewall_btn_url',array(
		'label'	=> __('View All Button URL','catering-lite'),
		'section'	=> 'catering_lite_recipe_section',
		'type'		=> 'text'
	));
} 
add_action( 'customize_register', 'catering_lite_customize_register', 11 );

if ( ! defined( 'FOOD_TRUCK_LITE_PRO_NAME' ) ) {
	define( 'FOOD_TRUCK_LITE_PRO_NAME', __( 'Catering Pro', 'catering-lite' ));
}
if ( ! defined( 'FOOD_TRUCK_LITE_PRO_URL' ) ) {
	define( 'FOOD_TRUCK_LITE_PRO_URL', __( 'https://www.themesglance.com/themes/catering-company-wordpress-theme/', 'catering-lite' ));
}

function catering_lite_remove_parent_function() {
	remove_action( 'admin_notices', 'food_truck_lite_activation_notice' );
	remove_action( 'admin_menu', 'food_truck_lite_gettingstarted' );
}
add_action( 'init', 'catering_lite_remove_parent_function');