<?php
/**
 * Theme Functions.
 */

/* Theme Setup */
if (!function_exists('it_services_setup')):

function it_services_setup() {

	$GLOBALS['content_width'] = apply_filters('it_services_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',
	));

	/*
	 * This theme styles the visual editor to resemble the theme style,
	 * specifically font, colors, icons, and column width.
	 */
	add_editor_style(array('css/editor-style.css', it_services_font_url()));
	// Theme Activation Notice
	global $pagenow;
	if (
		is_admin()
		&&
		('themes.php' == $pagenow)
		// &&
		// isset( $_GET['activated'] )
	) {
		add_action('admin_notices', 'it_services_activation_notice');
	}
}
endif;
add_action('after_setup_theme', 'it_services_setup');

function it_services_activation_notice() {
	$it_services_meta = get_option( 'it_services_admin_notice' );

	if (!$it_services_meta) {
	echo '<div id="it-services-welcome-notice" class="notice notice-success is-dismissible activation-notice">';
		echo '<div class="content">';
			echo '<h2>' . esc_html__( 'Thank You for Choosing It Services by Themesglance!', 'it-services' ) . '</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:', 'it-services' ) . '</p>';
			echo '<p>';
				echo '<a href="' . esc_url( admin_url( 'themes.php?page=it_services_guide' ) ) . '" class="button">' . esc_html__( 'Demo Import', 'it-services' ) . '</a>';
				echo '<a href="' . esc_url( 'https://preview.themesglance.com/it-company-pro/' ) . '" class="button" target="_blank">' . esc_html__( 'Demo', 'it-services' ) . '</a>';
				echo '<a href="' . esc_url( 'https://www.themesglance.com/products/it-company-wordpress-theme' ) . '" class="button" target="_blank">' . esc_html__( 'Get Premium', 'it-services' ) . '</a>';
				echo '<a href="' . esc_url( 'https://preview.themesglance.com/demo/docs/free-it-company/' ) . '" class="button" target="_blank">' . esc_html__( 'Documentation', 'it-services' ) . '</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>';
}
}

// Admin notice code START
function it_services_dismissed_notice() {
	update_option( 'it_services_admin_notice', true );
}
add_action( 'wp_ajax_it_services_dismissed_notice', 'it_services_dismissed_notice' );


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

add_action( 'wp_enqueue_scripts', 'it_services_enqueue_styles' );
function it_services_enqueue_styles() {
	wp_enqueue_style( 'bootstrap-css', get_template_directory_uri().'/css/bootstrap.css' );
	$parent_style = 'it-company-basic-style'; // Style handle of parent theme.
	wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
	wp_enqueue_style( 'it-services-style', get_stylesheet_uri(), array( $parent_style ) );
	require get_parent_theme_file_path( '/inc/tg-custom-css.php' );
	wp_add_inline_style( 'it-services-style', $it_company_custom_css );
	require get_theme_file_path( '/tg-custom-css.php' );
	wp_add_inline_style( 'it-services-style', $it_services_custom_css );
	if (is_singular() && comments_open() && get_option('thread_comments')) {
		wp_enqueue_script('comment-reply');
	}
	wp_enqueue_style( 'it-services-block-patterns-style-frontend', get_theme_file_uri('/block-patterns/css/block-frontend.css') );
}
function it_services_enqueue_customizer_css() {
	wp_enqueue_style( 'it_services-customizer-css', get_stylesheet_directory_uri() . '/css/customize-controls.css' );
	}
	add_action( 'customize_controls_print_styles', 'it_services_enqueue_customizer_css' );

// Enqueue Customizer JS
function it_services_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', 'it_services_enqueue_customizer_js' );

	
function it_services_font_url(){
	$font_url = '';
	$font_family = array();
	$font_family[] = 'Abhaya Libre:wght@400;500;600;700;800';
	$font_family[] = 'Raleway:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900';

	$query_args = array(
		'family'	=> rawurlencode(implode('|',$font_family)),
	);
	$font_url = add_query_arg($query_args,'//fonts.googleapis.com/css');
	return $font_url;
}

function it_services_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'it-services' ),
		'description'   => __( 'Appears on blog page sidebar', 'it-services' ),
		'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', 'it_services_widgets_init' );

function it_services_mysetup() {
	
/* Theme Credit link */
	define('IT_SERVICES_THEMESGLANCE_PRO_THEME_URL',__('https://www.themesglance.com/products/it-company-wordpress-theme','it-services'));
	define('IT_SERVICES_THEMESGLANCE_THEME_DOC',__('https://preview.themesglance.com/demo/docs/it-company-pro/','it-services'));
	define('IT_SERVICES_THEMESGLANCE_LIVE_DEMO',__('https://preview.themesglance.com/it-company-pro/','it-services'));
	define('IT_SERVICES_THEMESGLANCE_FREE_THEME_DOC',__('https://preview.themesglance.com/demo/docs/free-it-company/','it-services'));
	define('IT_SERVICES_THEMESGLANCE_SUPPORT',__('https://wordpress.org/support/theme/it-services/','it-company'));
	define('IT_SERVICES_THEMESGLANCE_REVIEW',__('https://wordpress.org/support/theme/it-services/reviews/','it-services'));
	define('IT_SERVICES_SITE_URL',__('https://www.themesglance.com/products/free-it-services-wordpress-theme','it-services'));
	define('IT_SERVICES_BUNDLE_URL',__('https://www.themesglance.com/products/wp-theme-bundle','it-services'));

	if ( ! defined( 'IT_COMPANY_PRO_NAME' ) ) {
		define( 'IT_COMPANY_PRO_NAME', __( 'IT Services Pro', 'it-services' ));
	}
	if ( ! defined( 'IT_COMPANY_DOC_NAME' ) ) {
		define( 'IT_COMPANY_DOC_NAME', __( 'IT Services Doc', 'it-services' ));
	}
	if ( ! defined( 'IT_COMPANY_DEMO_NAME' ) ) {
		define( 'IT_COMPANY_DEMO_NAME', __( 'IT Services Demo', 'it-services' ));
	}
	/* Block Pattern */
	require get_theme_file_path('/block-patterns/block-patterns.php');

}
add_action( 'after_setup_theme', 'it_services_mysetup' );

/**
 * Enqueue block editor style
 */
function it_services_block_editor_styles() {
	wp_enqueue_style( 'it-services-font', it_services_font_url(), array() );
    wp_enqueue_style( 'it-services-block-patterns-style-editor', get_theme_file_uri( '/block-patterns/css/block-editor.css' ), false, '1.0', 'all' );
}
add_action( 'enqueue_block_editor_assets', 'it_services_block_editor_styles' );

function it_services_customize_register() {     
	global $wp_customize;
	$wp_customize->remove_control("it_company_facebook_icon");
	$wp_customize->remove_setting("it_company_facebook_icon");

	$wp_customize->remove_control("it_company_facebook");
	$wp_customize->remove_setting("it_company_facebook");

	$wp_customize->remove_control("it_company_twitter_icon");
	$wp_customize->remove_setting("it_company_twitter_icon");

	$wp_customize->remove_control("it_company_twitter");
	$wp_customize->remove_setting("it_company_twitter");

	$wp_customize->remove_control("it_company_youtube_icon");
	$wp_customize->remove_setting("it_company_youtube_icon");

	$wp_customize->remove_control("it_company_youtube");
	$wp_customize->remove_setting("it_company_youtube");

	$wp_customize->remove_control("it_company_linkedin_icon");
	$wp_customize->remove_setting("it_company_linkedin_icon");

	$wp_customize->remove_control("it_company_linkedin");
	$wp_customize->remove_setting("it_company_linkedin");

	$wp_customize->remove_control("it_company_social_icons_font_size");
	$wp_customize->remove_setting("it_company_social_icons_font_size");

	$wp_customize->remove_control("it_company_show_search");
	$wp_customize->remove_setting("it_company_show_search");

	$wp_customize->remove_control("it_company_search_responsive");
	$wp_customize->remove_setting("it_company_search_responsive");

	$wp_customize->remove_control("it_company_second_theme_color");
	$wp_customize->remove_setting("it_company_second_theme_color");

	$wp_customize->remove_control("it_company_slider_button_label");
	$wp_customize->remove_setting("it_company_slider_button_label");	

	$wp_customize->remove_control("it_company_menu_settings_premium_features");
	$wp_customize->remove_setting("it_company_menu_settings_premium_features");

	$wp_customize->remove_control("it_company_services_settings_premium_features");
	$wp_customize->remove_setting("it_company_services_settings_premium_features");

	$wp_customize->remove_control("it_company_post_settings_premium_features");
	$wp_customize->remove_setting("it_company_post_settings_premium_features");

	$wp_customize->remove_section("it_company_about");
	
	$wp_customize->remove_setting( 'it_company_reset_color' );
	$wp_customize->remove_control( 'it_company_reset_color' );

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

	//content Alignment
    $wp_customize->add_setting('it_company_slider_alignment_option',array(
    'default' => 'Left Align',
        'sanitize_callback' => 'it_company_sanitize_choices'
	));
	$wp_customize->add_control('it_company_slider_alignment_option',array(
        'type' => 'radio',
        'label' => __('Slider Content Alignment','it-services'),
        'section' => 'it_company_slider_section',
        'choices' => array(
            'Center Align' => __('Center Align','it-services'),
            'Left Align' => __('Left Align','it-services'),
            'Right Align' => __('Right Align','it-services'),
        ),
		'active_callback' => 'it_company_slider_enabled'
	) );

	// What we do Section
	$wp_customize->add_section('it_services_what_we_do_section',array(
		'title'	=> __('What we do','it-services'),
		'description'	=> __('Add What we do sections below.','it-services'),
		'priority' => 90,
		'panel' => 'it_company_panel_id',
	));

	$wp_customize->add_setting('it_services_section_title',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('it_services_section_title',array(
		'label'	=> __('Section Title','it-services'),
		'section'	=> 'it_services_what_we_do_section',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('it_services_slider_button_label',array(
		'default'	=> 'Read More',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('it_services_slider_button_label',array(
		'label'	=> __('Slider Button Label','it-services'),
		'section'	=> 'it_company_slider_section',
		'type'		=> 'text'
	));

	// category right
	$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( 'it_services_what_we_do_category', array(
      	'default'           => '',
      	'sanitize_callback' => 'it_company_sanitize_choices'
    ));
    $wp_customize->add_control('it_services_what_we_do_category',array(
		'type'    => 'select',
		'choices' => $cat_post1,
		'label' => __('Select Category to display Latest Post','it-services'),
		'section' => 'it_services_what_we_do_section',
	));

	$wp_customize->add_setting( 'it_services_we_do_excerpt_number', array(
		'default' => 30,
		'sanitize_callback'	=> 'absint'
	) );
	$wp_customize->add_control( 'it_services_we_do_excerpt_number', array(
		'label' => esc_html__( 'About Excerpt length','it-services' ),
		'section' => 'it_services_what_we_do_section',
		'type'  => 'number',
		'settings' => 'it_services_we_do_excerpt_number',
		'input_attrs' => array(
			'step' => 1,
			'min' => 0,
			'max' => 50,
		),
	) );

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

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

	$wp_customize->add_setting( 'it_services_post_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('it_services_post_settings_premium_features', array(
        'type'=> 'hidden',
        'description' => "<h3>". esc_html('Premium Theme Features!','it-services') ."</h3>
            <ul>
                <li>". esc_html('Post Share Facebook,Linkedin,Twitter Setting','it-services') ."</li>
                <li>". esc_html('... and Other Premium Features','it-services') ."</li>
            </ul>
            <a target='_blank' href='". esc_url('https://www.themesglance.com/products/it-company-wordpress-theme') ." '>". esc_html('Upgrade Now','it-services') ."</a>",
        'section' => 'it_company_theme_layout'
        )
    );

	//Reset Global Color
	$wp_customize->add_setting('it_services_reset_color', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));
	
	$wp_customize->add_control('it_services_reset_color', array(
		'type'    => 'button',
		'label'   => __('Reset Global Color', 'it-services'),
		'section' => 'it_company_reset_section',
		'input_attrs' => array(
			'onclick' => 'ResetChildGlobalColor()',
		),
	));	

	//Reset Demo Import
	$wp_customize->add_setting( 'it_services_reset_demo_import_settings', array(
		'sanitize_callback' => 'sanitize_text_field',
	));

	$wp_customize->add_control('it_services_reset_demo_import_settings',array(
		'label'   => __( 'Reset Demo Import', 'it-services' ),
		'section' => 'it_company_reset_section',
		'type'    => 'button',
		'input_attrs' => array(
			'onclick' => 'ResetChildDemoSettings()',
		),
	));

} 
add_action( 'customize_register', 'it_services_customize_register', 11 );

function it_services_remove_parent_function() {
	remove_action( 'admin_notices', 'it_company_activation_notice' );
	remove_action( 'admin_menu', 'it_company_gettingstarted' );
}
add_action( 'init', 'it_services_remove_parent_function');

function it_services_credit_link() {
    echo "<a href=".esc_url(IT_SERVICES_SITE_URL)." target='_blank'>".esc_html__('IT Services WordPress Theme','it-services')."</a>";
}

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

// Reset all theme settings
function it_services_reset_demo_import_settings() {
    if (current_user_can('manage_options')) {

		remove_theme_mod( 'it_company_top_header' ); 
		remove_theme_mod( 'it_company_email' );
		remove_theme_mod( 'it_company_call_number' ); 
		remove_theme_mod( 'it_company_question' ); 
		remove_theme_mod( 'it_company_slider_hide' );
		remove_theme_mod( 'it_company_slider_page1' );
		remove_theme_mod( 'it_company_slider_page2' );
		remove_theme_mod( 'it_company_slider_page3' );
		remove_theme_mod( 'it_company_slider_page4' );
		remove_theme_mod( 'it_services_section_title' );
		remove_theme_mod( 'it_services_what_we_do_category' );
		remove_theme_mod( 'it_services_footer_text' );

        wp_send_json_success(array('message' => __('Demo import settings have been reset.', 'it-services')));
    } else {
        wp_send_json_error(array('message' => __('Permission denied.', 'it-services')));
    }
}
add_action('wp_ajax_it_services_reset_demo_import_settings', 'it_services_reset_demo_import_settings'); 



