<?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',
	));
	// Theme Activation Notice
	global $pagenow;
	if (
		is_admin()
		&&
		('themes.php' == $pagenow)
		// &&
		// isset( $_GET['activated'] )
	) {
		add_action('admin_notices', 'catering_lite_activation_notice');
	}
}
endif;
add_action('after_setup_theme', 'catering_lite_setup');

function catering_lite_activation_notice() {
	$catering_lite_meta = get_option( 'catering_lite_admin_notice' );

	if (!$catering_lite_meta) {
	echo '<div id="catering-lite-welcome-notice" class="notice notice-success is-dismissible activation-notice">';
		echo '<div class="content">';
			echo '<h2>' . esc_html__( 'Thank You for Choosing Catering Lite by Themesglance!', 'catering-lite' ) . '</h2>';
			echo '<p class="notice-para">' . esc_html__( 'We’re thrilled to have you on board. To help you get started quickly and make the most out of your theme, check out the resources below:', 'catering-lite' ) . '</p>';
			echo '<p>';
				echo '<a href="' . esc_url( admin_url( 'themes.php?page=catering_lite_guide' ) ) . '" class="button">' . esc_html__( 'Get Started', 'catering-lite' ) . '</a>';
				echo '<a href="' . esc_url( 'https://preview.themesglance.com/catering-pro/' ) . '" class="button" target="_blank">' . esc_html__( 'Demo', 'catering-lite' ) . '</a>';
				echo '<a href="' . esc_url( 'https://www.themesglance.com/products/catering-company-wordpress-theme' ) . '" class="button" target="_blank">' . esc_html__( 'Get Premium', 'catering-lite' ) . '</a>';
				echo '<a href="' . esc_url( 'https://preview.themesglance.com/demo/docs/free-catering-lite/' ) . '" class="button" target="_blank">' . esc_html__( 'Documentation', 'catering-lite' ) . '</a>';
			echo '</p>';
		echo '</div>';
		echo '<div class="image-preview">';
                echo '<a  href="https://www.themesglance.com/products/wp-theme-bundle" target="_blank" class="pre-img rel="noopener noreferrer"">';
                echo '<img src="' . esc_url( get_template_directory_uri() . '/images/notice-img.png' ) . '" alt="Notice Image" />';
        echo '</a>';
		echo '</div>';
	echo '</div>';
}
}

add_action( 'wp_enqueue_scripts', 'catering_lite_enqueue_styles' );
function catering_lite_enqueue_styles() {
	wp_enqueue_style( 'bootstrap-css', get_template_directory_uri().'/css/bootstrap.css' );
	$parent_style = 'food-truck-lite-basic-style'; // Style handle of parent theme.
	wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
	wp_enqueue_style( 'catering-lite-style', get_stylesheet_uri(), array( $parent_style ) );
	require get_theme_file_path( '/tg-custom-css.php' );
	wp_add_inline_style( 'catering-lite-style', $catering_lite_custom_css );
	if (is_singular() && comments_open() && get_option('thread_comments')) {
		wp_enqueue_script('comment-reply');
	}
	wp_enqueue_style( 'catering-lite-block-patterns-style-frontend', get_theme_file_uri('/block-patterns/css/block-frontend.css') );

}
function catering_lite_enqueue_customizer_css() {
	wp_enqueue_style( 'catering_lite-customizer-css', get_stylesheet_directory_uri() . '/css/customize-controls.css' );
	}
	add_action( 'customize_controls_print_styles', 'catering_lite_enqueue_customizer_css' );

// Enqueue Customizer JS
function catering_lite_enqueue_customizer_js() {
	wp_enqueue_script('atering_lite-customizer-control', get_stylesheet_directory_uri() . '/js/customize-controls.js', array( 'jquery', 'customize-controls' ), false, true
	);
}
add_action( 'customize_controls_enqueue_scripts', 'catering_lite_enqueue_customizer_js' );

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;
	$wp_customize->remove_setting( 'food_truck_lite_second_theme_color' );
	$wp_customize->remove_control( 'food_truck_lite_second_theme_color' );
	$wp_customize->remove_setting( 'food_truck_lite_menu_settings_premium_features' );
	$wp_customize->remove_control( 'food_truck_lite_menu_settings_premium_features' );
	$wp_customize->remove_setting( 'food_truck_lite_specialmenu_settings_premium_features' );
	$wp_customize->remove_control( 'food_truck_lite_specialmenu_settings_premium_features' );
	$wp_customize->remove_setting( 'food_truck_lite_post_settings_premium_features' );
	$wp_customize->remove_control( 'food_truck_lite_post_settings_premium_features' );
	
	$wp_customize->remove_setting( 'food_truck_lite_reset_color' );
	$wp_customize->remove_control( 'food_truck_lite_reset_color' );

	$wp_customize->remove_setting( 'food_truck_lite_reset_demo_import_settings' );
	$wp_customize->remove_control( 'food_truck_lite_reset_demo_import_settings' );

	// 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_menu_section_hide',array(
        'default' => false,
        'sanitize_callback'	=> 'food_truck_lite_sanitize_checkbox',
		
	));
	$wp_customize->add_control('catering_lite_menu_section_hide',array(
     	'type' => 'checkbox',
      	'label' => __('Show / Hide Special Menu Section','catering-lite'),
      	'section' => 'food_truck_lite_special_menu',
		'priority' => 1,
	));

	$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'
	));

	$wp_customize->add_setting( 'catering_lite_menu_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('catering_lite_menu_settings_premium_features', array(
        'type'=> 'hidden',
        'description' => "<h3>". esc_html('Premium Theme Features!','catering-lite') ."</h3>
            <ul>
                <li>". esc_html('Menu DropDown Background Colors','catering-lite') ."</li>
                <li>". esc_html('Menu Item Fonts','catering-lite') ."</li>
                <li>". esc_html('Active Menu Colors','catering-lite') ."</li>
                <li>". esc_html('Header Search Icons Colors','catering-lite') ."</li>
                <li>". esc_html('... and Other Premium Features','catering-lite') ."</li>
            </ul>
            <a target='_blank' href='". esc_url('https://www.themesglance.com/products/catering-company-wordpress-theme') ." '>". esc_html('Upgrade Now','catering-lite') ."</a>",
        'section' => 'food_truck_lite_header'
        )
    );

    $wp_customize->add_setting( 'catering_lite_specialmenu_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('catering_lite_specialmenu_settings_premium_features', array(
        'type'=> 'hidden',
        'description' => "<h3>". esc_html('Premium Theme Features!','catering-lite') ."</h3>
            <ul>
                <li>". esc_html('Title Font Settings','catering-lite') ."</li>
                <li>". esc_html('Background Image Settings','catering-lite') ."</li>
                <li>". esc_html('... and Other Premium Features','catering-lite') ."</li>
            </ul>
            <a target='_blank' href='". esc_url('https://www.themesglance.com/products/catering-company-wordpress-theme') ." '>". esc_html('Upgrade Now','catering-lite') ."</a>",
        'section' => 'food_truck_lite_special_menu'
        )
    );

    $wp_customize->add_setting( 'catering_lite_post_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('catering_lite_post_settings_premium_features', array(
        'type'=> 'hidden',
        'description' => "<h3>". esc_html('Premium Theme Features!','catering-lite') ."</h3>
            <ul>
                <li>". esc_html('Post Share Facebook,Linkedin,Twitter Setting','catering-lite') ."</li>
                <li>". esc_html('... and Other Premium Features','catering-lite') ."</li>
            </ul>
            <a target='_blank' href='". esc_url('https://www.themesglance.com/products/catering-company-wordpress-theme') ." '>". esc_html('Upgrade Now','catering-lite') ."</a>",
        'section' => 'food_truck_lite_theme_layout'
        )
    );
	//Reset Global Color
	$wp_customize->add_setting('catering_lite_reset_color', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));
	
	$wp_customize->add_control('catering_lite_reset_color', array(
		'type'    => 'button',
		'label'   => __('Reset Global Color', 'catering-lite'),
		'section' => 'food_truck_lite_reset_section',
		'input_attrs' => array(
			'onclick' => 'ResetChildGlobalColor()',
		),
	));
} 
add_action( 'customize_register', 'catering_lite_customize_register', 11 );

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');

/**
 * Enqueue block editor style
 */
function catering_lite_block_editor_styles() {
	wp_enqueue_style( 'catering-lite-font', food_truck_lite_font_url(), array() );
    wp_enqueue_style( 'catering-lite-block-patterns-style-editor', get_theme_file_uri( '/block-patterns/css/block-editor.css' ), false, '1.0', 'all' );
    wp_enqueue_style( 'font-awesome-css', get_template_directory_uri().'/css/fontawesome-all.css' );
}
add_action( 'enqueue_block_editor_assets', 'catering_lite_block_editor_styles' );

function catering_lite_credit_link() {
    echo "<a href=".esc_url(CATERING_LITE_SITE_URL)." target='_blank'>".esc_html__('Catering Lite WordPress Theme','catering-lite')."</a>";
}


function catering_lite_mysetup() {
	/* Theme Credit link */
	define('CATERING_LITE_THEMESGLANCE_PRO_THEME_URL',__('https://www.themesglance.com/products/catering-company-wordpress-theme','catering-lite'));
	define('CATERING_LITE_THEMESGLANCE_THEME_DOC',__('https://preview.themesglance.com/demo/docs/tg-catering-pro/','catering-lite'));
	define('CATERING_LITE_THEMESGLANCE_LIVE_DEMO',__('https://preview.themesglance.com/catering-pro/','catering-lite'));
	define('CATERING_LITE_THEMESGLANCE_FREE_THEME_DOC',__('https://preview.themesglance.com/demo/docs/free-catering-lite/','catering-lite'));
	define('CATERING_LITE_THEMESGLANCE_SUPPORT',__('https://wordpress.org/support/theme/catering-lite/','catering-lite'));
	define('CATERING_LITE_THEMESGLANCE_REVIEW',__('https://wordpress.org/support/theme/catering-lite/reviews/','catering-lite'));
	define('CATERING_LITE_SITE_URL',__('https://www.themesglance.com/products/free-catering-wordpress-theme','catering-lite'));
	define('CATERING_LITE_BUNDLE_URL',__('https://www.themesglance.com/products/wp-theme-bundle','catering-lite'));

	if ( ! defined( 'FOOD_TRUCK_LITE_PRO_NAME' ) ) {
		define( 'FOOD_TRUCK_LITE_PRO_NAME', __( 'Catering Pro', 'catering-lite' ));
	}
	if ( ! defined( 'FOOD_TRUCK_LITE_DOC_NAME' ) ) {
		define( 'FOOD_TRUCK_LITE_DOC_NAME', __( 'Catering Doc', 'catering-lite' ));
	}
	if ( ! defined( 'FOOD_TRUCK_LITE_DEMO_NAME' ) ) {
		define( 'FOOD_TRUCK_LITE_DEMO_NAME', __( 'Catering Demo', 'catering-lite' ));
	}
	if ( ! defined( 'FOOD_TRUCK_LITE_PRO_URL' ) ) {
		define( 'FOOD_TRUCK_LITE_PRO_URL', __( 'https://www.themesglance.com/products/catering-company-wordpress-theme', 'catering-lite' ));
	}
	if ( ! defined( 'FOOD_TRUCK_LITE_FREE_THEME_DOC' ) ) {
		define( 'FOOD_TRUCK_LITE_FREE_THEME_DOC', 'https://preview.themesglance.com/demo/docs/free-catering-lite/');
	}
	if ( ! defined( 'FOOD_TRUCK_LITE_LIVE_DEMO' ) ) {
		define( 'FOOD_TRUCK_LITE_LIVE_DEMO', 'https://preview.themesglance.com/catering-pro/');
	}
	
	/* Block Pattern */
	require get_theme_file_path('/block-patterns/block-patterns.php');
}
add_action( 'after_setup_theme', 'catering_lite_mysetup' );

/* Implement the get started page */
require get_theme_file_path() . '/inc/getting-started/getting-started.php';


// Admin notice code START
function catering_lite_dismissed_notice() {
	update_option( 'catering_lite_admin_notice', true );
}
add_action( 'wp_ajax_catering_lite_dismissed_notice', 'catering_lite_dismissed_notice' );


//After Switch theme function
add_action('after_switch_theme', 'catering_lite_getstart_setup_options');
function catering_lite_getstart_setup_options () {
    update_option('catering_lite_admin_notice', false );
}
// Admin notice code END
