<?php
/**
 * Theme functions.
 */

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

function core_fitness_setup() {

	$GLOBALS['content_width'] = apply_filters( 'core_fitness_content_width', 640 );
	
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'html5', array( 'comment-list', 'search-form', 'comment-form', ) );
	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' => 'f1f1f1'
	) );	
	/*
	 * 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', the_wp_fitness_font_url() ) );

global $pagenow;
if (
		is_admin()
		&&
		('themes.php' == $pagenow)
		// &&
		// isset( $_GET['activated'] )
	) {
		add_action('admin_notices', 'core_fitness_activation_notice');
	}
}
endif;
add_action( 'after_setup_theme', 'core_fitness_setup' );

//Activation notice
function core_fitness_activation_notice() {
	$core_fitness_meta = get_option( 'core_fitness_admin_notice' );

	if (!$core_fitness_meta) {
	echo '<div id="core-fitness-welcome-notice" class="notice notice-success is-dismissible activation-notice">';
		echo '<div class="content">';
			echo '<h2>' . esc_html__( 'Thank You for Choosing Core Fitness by Themesglance!', 'core-fitness' ) . '</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:', 'core-fitness' ) . '</p>';
			echo '<p>';
				echo '<a href="' . esc_url( admin_url( 'themes.php?page=core_fitness_guide' ) ) . '" class="button">' . esc_html__( 'Get Started', 'core-fitness' ) . '</a>';
				echo '<a href="' . esc_url( 'https://preview.themesglance.com/wp-fitness-pro/' ) . '" class="button" target="_blank">' . esc_html__( 'Demo', 'core-fitness' ) . '</a>';
				echo '<a href="' . esc_url( 'https://www.themesglance.com/products/fitness-wordpress-theme' ) . '" class="button" target="_blank">' . esc_html__( 'Get Premium', 'core-fitness' ) . '</a>';
				echo '<a href="' . esc_url( 'https://preview.themesglance.com/demo/docs/free-wp-fitness/' ) . '" class="button" target="_blank">' . esc_html__( 'Documentation', 'core-fitness' ) . '</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 core_fitness_dismissed_notice() {
	update_option( 'core_fitness_admin_notice', true );
}
add_action( 'wp_ajax_core_fitness_dismissed_notice', 'core_fitness_dismissed_notice' );


//After Switch theme function
add_action('after_switch_theme', 'core_fitness_getstart_setup_options');
function core_fitness_getstart_setup_options () {
    update_option('core_fitness_admin_notice', false );
}

add_action( 'wp_enqueue_scripts', 'core_fitness_enqueue_styles' );
function core_fitness_enqueue_styles() {
	$parent_style = 'core-fitness-style'; // Style handle of parent theme.
	wp_enqueue_style( 'bootstrap-css', get_template_directory_uri().'/css/bootstrap.css' );
	wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
	wp_enqueue_style( 'core-fitness-style', get_stylesheet_uri(), array( $parent_style ) );
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	wp_enqueue_style( 'core-fitness-block-patterns-style-frontend', get_theme_file_uri('/block-patterns/css/block-frontend.css') );

	require get_theme_file_path( '/inc/color-option.php' );
	wp_add_inline_style( 'core-fitness-style',$core_fitness_custom_css);
}

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

function core_fitness_customize_register() {
	global $wp_customize;
	$wp_customize->remove_setting( 'core_fitness_slider_arrows_hover_color' );
	$wp_customize->remove_control( 'core_fitness_slider_arrows_hover_color' );
	$wp_customize->remove_setting( 'the_wp_fitness_first_theme_color' );	
	$wp_customize->remove_control( 'the_wp_fitness_first_theme_color' );
	$wp_customize->remove_setting( 'the_wp_fitness_second_theme_color' );	
	$wp_customize->remove_control( 'the_wp_fitness_second_theme_color' );	
	$wp_customize->remove_section( 'the_wp_fitness_about' );
	$wp_customize->remove_setting( 'the_wp_fitness_reset_color' );
	$wp_customize->remove_control( 'the_wp_fitness_reset_color' );
	$wp_customize->remove_setting( 'the_wp_fitness_reset_demo_import_settings' );
	$wp_customize->remove_control( 'the_wp_fitness_reset_demo_import_settings' );

	//Reset Global Color
	$wp_customize->add_setting('core-fitness_reset_color', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));
	
	$wp_customize->add_control('core-fitness_reset_color', array(
		'type'    => 'button',
		'label'   => __('Reset Global Color', 'core-fitness'),
		'section' => 'the_wp_fitness_reset_section',
		'input_attrs' => array(
			'onclick' => 'ResetChildGlobalColor()',
		),
	));
} 
add_action( 'customize_register', 'core_fitness_customize_register', 11 );

function core_fitness_remove_parent_function() {
	remove_action( 'admin_notices', 'the_wp_fitness_activation_notice' );
	remove_action( 'admin_menu', 'the_wp_fitness_gettingstarted' );
}
add_action( 'init', 'core_fitness_remove_parent_function');

/* Theme Widgets Setup */
function core_fitness_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'core-fitness' ),
		'description'   => __( 'Appears on blog page sidebar', 'core-fitness' ),
		'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">',
		'after_title'   => '</h3>',
	) );
	
	register_sidebar( array(
		'name'          => __( 'Page Sidebar', 'core-fitness' ),
		'description'   => __( 'Appears on page sidebar', 'core-fitness' ),
		'id'            => 'sidebar-2',
		'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">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Third Column Sidebar', 'core-fitness' ),
		'description'   => __( 'Appears on page sidebar', 'core-fitness' ),
		'id'            => 'sidebar-3',
		'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">',
		'after_title'   => '</h3>',
	) );

	$core_fitness_footer_columns = get_theme_mod('core_fitness_footer_widget', '4');
	for ($i=1; $i<=$core_fitness_footer_columns; $i++) {
		register_sidebar( array(
			'name'          => __( 'Footer ', 'core-fitness' ) . $i,
			'id'            => 'footer-' . $i,
			'description'   => '',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title mb-2">',
			'after_title'   => '</h3>',
		) );
	}
}
add_action( 'widgets_init', 'core_fitness_widgets_init' );

/**
 * Enqueue block editor style
 */
function core_fitness_block_editor_styles() {
	wp_enqueue_style( 'core-fitness-font', the_wp_fitness_font_url(), array() );
    wp_enqueue_style( 'core-fitness-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', 'core_fitness_block_editor_styles' );

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


function core_fitness_customizer ( $wp_customize ) {
	
	//Trending Product
	$wp_customize->add_section('core_fitness_products',array(
		'title'	=> __('New Products','core-fitness'),
		'description'=> __('This section will appear below the slider.','core-fitness'),
		'panel' => 'core_fitness_panel_id',
	));	
	
	$wp_customize->add_setting('core_fitness_title',array(
		'default'=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	
	$wp_customize->add_control('core_fitness_title',array(
		'label'	=> __('Section Title','core-fitness'),
		'section'=> 'core_fitness_products',
		'setting'=> 'core_fitness_title',
		'type'=> 'text'
	));	

	$wp_customize->add_setting( 'core_fitness_page', array(
		'default'           => '',
		'sanitize_callback' => 'core_fitness_sanitize_dropdown_pages'
	));
	$wp_customize->add_control( 'core_fitness_page', array(
		'label'    => __( 'Select Page', 'core-fitness' ),
		'section'  => 'core_fitness_products',
		'type'     => 'dropdown-pages'
	));

	$wp_customize->add_setting( 'core_fitness_first_theme_color', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'core_fitness_first_theme_color', array(
  		'label' => 'Color Option',
	    'description' => __('One can change complete theme global color settings on just one click.', 'core-fitness'),
	    'section' => 'the_wp_fitness_theme_color_option',
	    'settings' => 'core_fitness_first_theme_color',
  	)));
}

add_action( 'customize_register', 'core_fitness_customizer' );


function core_fitness_mysetup() {
	define('CORE_FITNESS_THEMESGLANCE_PRO_THEME_URL',__('https://www.themesglance.com/products/fitness-wordpress-theme','core-fitness'));
	define('CORE_FITNESS_THEMESGLANCE_THEME_DOC',__('https://preview.themesglance.com/demo/docs/tg-fitness-pro/','core-fitness'));
	define('CORE_FITNESS_THEMESGLANCE_LIVE_DEMO',__('https://preview.themesglance.com/wp-fitness-pro/','core-fitness'));
	define('CORE_FITNESS_THEMESGLANCE_FREE_THEME_DOC',__('https://preview.themesglance.com/demo/docs/free-wp-fitness/','core-fitness'));
	define('CORE_FITNESS_THEMESGLANCE_SUPPORT',__('https://wordpress.org/support/theme/core-fitness/','core-fitness'));
	define('CORE_FITNESS_THEMESGLANCE_REVIEW',__('https://wordpress.org/support/theme/core-fitness/reviews/','core-fitness'));
	define('CORE_FITNESS_CREDIT',__('https://www.themesglance.com/products/wp-fitness-wordpress-theme','core-fitness'));
	define('CORE_FITNESS_BUNDLE_URL',__('https://www.themesglance.com/products/wp-theme-bundle','core-fitness'));
	/* Block Pattern */
	require get_theme_file_path('/block-patterns/block-patterns.php');
}
add_action( 'after_setup_theme', 'core_fitness_mysetup' );

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



