<?php
/**
 * Classic Kindergarten functions and definitions
 *
 * @package Classic Kindergarten
 */

if ( ! function_exists( 'classic_kindergarten_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook. The init hook is too late for some features, such as indicating
 * support post thumbnails.
 */
function classic_kindergarten_setup() {
	global $classic_kindergarten_content_width;
	if ( ! isset( $classic_kindergarten_content_width ) )
		$classic_kindergarten_content_width = 680;

	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'wp-block-styles');
	add_theme_support( 'align-wide' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-logo', array(
		'height'      => 100,
		'width'       => 100,
		'flex-height' => true,
	) );
	add_theme_support( 'custom-background', array(
		'default-color' => 'ffffff'
	) );
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );
	add_editor_style( 'editor-style.css' );
}
endif; // kindergarten_school_setup
add_action( 'after_setup_theme', 'classic_kindergarten_setup' );

function classic_kindergarten_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'classic-kindergarten' ),
		'description'   => __( 'Appears on blog page sidebar', 'classic-kindergarten' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	$classic_kindergarten_widget_areas = get_theme_mod('kindergarten_school_footer_widget_areas', '4');
	for ($classic_kindergarten_i=1; $classic_kindergarten_i <= 4; $classic_kindergarten_i++) {
		register_sidebar( array(
			'name'          => __( 'Footer Widget ', 'classic-kindergarten' ) . $classic_kindergarten_i,
			'id'            => 'footer-' . $classic_kindergarten_i,
			'description'   => '',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
	}
}
add_action( 'widgets_init', 'classic_kindergarten_widgets_init' );

add_action( 'wp_enqueue_scripts', 'classic_kindergarten_enqueue_styles' );
function classic_kindergarten_enqueue_styles() {
    $parenthandle = 'classic-kindergarten-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    $theme = wp_get_theme();
    wp_enqueue_style( $parenthandle, esc_url(get_template_directory_uri()) . '/style.css',
        array(),  // if the parent theme code has a dependency, copy it to here
        $theme->parent()->get('Version')
    );
    wp_enqueue_style( 'classic-kindergarten-child-style', get_stylesheet_uri(),
        array( $parenthandle ),
        $theme->get('Version') // this only works if you have Version in the style header
    );

    require get_parent_theme_file_path( '/inc/color-scheme/custom-color-control.php' );
	wp_add_inline_style( 'classic-kindergarten-style',$kindergarten_school_color_scheme_css );
	require get_theme_file_path( '/inc/color-scheme/custom-color-control.php' );
	wp_add_inline_style( 'classic-kindergarten-style',$classic_kindergarten_color_scheme_css);
}

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

function classic_kindergarten_scripts() {

	wp_enqueue_style( 'classic-kindergarten-responsive', esc_url(get_theme_file_uri())."/css/responsive.css" );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'classic_kindergarten_scripts' );

add_action( 'customize_register', 'classic_kindergarten_customize_register', 11 );
function classic_kindergarten_customize_register() {
	global $wp_customize;

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

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

}

// Customizer Section
function classic_kindergarten_customizer ( $wp_customize ) {

	$wp_customize->add_setting('classic_kindergarten_color_scheme_one',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	));
	
	$wp_customize->add_control(
		new WP_Customize_Color_Control(
		$wp_customize,
		'classic_kindergarten_color_scheme_one',
		array(
			'label'      => __( 'Color Scheme', 'classic-kindergarten' ),
			'section'    => 'kindergarten_school_global_color',
			'settings'   => 'classic_kindergarten_color_scheme_one',
		) )
	);
	
	$wp_customize->add_setting('classic_kindergarten_color_scheme_two',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	));
	
	$wp_customize->add_control(
		new WP_Customize_Color_Control(
		$wp_customize,
		'classic_kindergarten_color_scheme_two',
		array(
			'label'      => __( 'Color Scheme', 'classic-kindergarten' ),
			'section'    => 'kindergarten_school_global_color',
			'settings'   => 'classic_kindergarten_color_scheme_two',
		) )
	);	

	$wp_customize->add_setting('classic_kindergarten_color_scheme_three',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	));
	
	$wp_customize->add_control(
		new WP_Customize_Color_Control(
		$wp_customize,
		'classic_kindergarten_color_scheme_three',
		array(
			'label'      => __( 'Color Scheme', 'classic-kindergarten' ),
			'section'    => 'kindergarten_school_global_color',
			'settings'   => 'classic_kindergarten_color_scheme_three',
		) )
	);		

	$wp_customize->add_setting('classic_kindergarten_color_scheme_four',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color',
	));
	
	$wp_customize->add_control(
		new WP_Customize_Color_Control(
		$wp_customize,
		'classic_kindergarten_color_scheme_four',
		array(
			'label'      => __( 'Color Scheme', 'classic-kindergarten' ),
			'section'    => 'kindergarten_school_global_color',
			'settings'   => 'classic_kindergarten_color_scheme_four',
		) )
	);	

}
add_action( 'customize_register', 'classic_kindergarten_customizer' );

function classic_kindergarten_setup_theme() {
	// Footer Link
	define('CLASSIC_KINDERGARTEN_FOOTER_LINK',__('https://www.theclassictemplates.com/products/free-kindergarten-wordpress-theme','classic-kindergarten'));

	if ( ! defined( 'KINDERGARTEN_SCHOOL_PRO_NAME' ) ) {
		define( 'KINDERGARTEN_SCHOOL_PRO_NAME', __( 'About Classic Kindergarten', 'classic-kindergarten' ));
	}
	if ( ! defined( 'CLASSIC_KINDERGARTEN_THEME_PAGE' ) ) {
	define('CLASSIC_KINDERGARTEN_THEME_PAGE',__('https://www.theclassictemplates.com/collections/best-wordpress-templates','classic-kindergarten'));
	}
	if ( ! defined( 'KINDERGARTEN_SCHOOL_SUPPORT' ) ) {
	define('KINDERGARTEN_SCHOOL_SUPPORT',__('https://wordpress.org/support/theme/classic-kindergarten/','classic-kindergarten'));
	}
	if ( ! defined( 'KINDERGARTEN_SCHOOL_REVIEW' ) ) {
	define('KINDERGARTEN_SCHOOL_REVIEW',__('https://wordpress.org/support/theme/classic-kindergarten/reviews/','classic-kindergarten'));
	}
	if ( ! defined( 'KINDERGARTEN_SCHOOL_PRE_DEMO' ) ) {
	define('KINDERGARTEN_SCHOOL_PRE_DEMO',__('https://live.theclassictemplates.com/classic-kindergarten-pro/','classic-kindergarten'));
	}
	if ( ! defined( 'KINDERGARTEN_SCHOOL_PREMIUM_PAGE' ) ) {
	define('KINDERGARTEN_SCHOOL_PREMIUM_PAGE',__('https://www.theclassictemplates.com/products/classic-kindergarten-premium','classic-kindergarten'));
	}
	if ( ! defined( 'KINDERGARTEN_SCHOOL_THEME_DOCUMENTATION' ) ) {
	define('KINDERGARTEN_SCHOOL_THEME_DOCUMENTATION',__('https://live.theclassictemplates.com/demo/docs/classic-kindergarten-free/','classic-kindergarten'));
	}
	if ( ! defined( 'KINDERGARTEN_SCHOOL_BUNDLE_PAGE' ) ) {
		define('KINDERGARTEN_SCHOOL_BUNDLE_PAGE',__('https://www.theclassictemplates.com/products/wordpress-theme-bundle','kindergarten-school'));
	}
}
add_action( 'after_setup_theme', 'classic_kindergarten_setup_theme' );

if ( ! function_exists( 'kindergarten_school_the_custom_logo' ) ) :
	/**
	 * Displays the optional custom logo.
	 *
	 * Does nothing if the custom logo is not available.
	 *
	 * @since classic-kindergarten
	 */
	function kindergarten_school_the_custom_logo() {
		if ( function_exists( 'the_custom_logo' ) ) {
			// Check if custom logo is set via the customizer
			if ( has_custom_logo() ) {
				the_custom_logo();
			} else {
				// If no custom logo, display the logo from the child theme directory
				echo "<a href='" . esc_url( home_url() ) . "' rel='home'>
						<img src='" . esc_url( get_stylesheet_directory_uri() ) . "/images/logo.png' alt='" . esc_attr__( 'Classic Kindergarten logo', 'classic-kindergarten' ) . "' />
					  </a>";
			}
		}
	}
endif;


// Redirect to a custom page after theme activation in the child theme
function classic_kindergarten_options() {
    global $pagenow;

    if ( is_admin() && 'themes.php' === $pagenow && isset( $_GET['activated'] ) && current_user_can( 'manage_options' ) ) {
        // Theme activated — future actions can go here, like setting theme mods or showing notices.
    }
}
add_action( 'admin_init', 'classic_kindergarten_options' );

function classic_kindergarten_hide_parent_demo_menu() {
    remove_submenu_page( 'themes.php', 'kindergarten-school-demo' );
}
add_action( 'admin_menu', 'classic_kindergarten_hide_parent_demo_menu', 999 );

add_filter( 'kindergarten_school_demo_content_path', function( $kindergarten_school_default_path ) {
    $kindergarten_school_child_path = get_stylesheet_directory() . '/inc/demo-content.php';

    if ( file_exists( $kindergarten_school_child_path ) ) {
        return $kindergarten_school_child_path;
    }

    return $kindergarten_school_default_path; 
});

// Load additional admin styles for the child theme
function classic_kindergarten_admin_enqueue_scripts() {
    wp_enqueue_style( 'classic-kindergarten-admin-style', get_stylesheet_directory_uri() . '/css/addon.css' );
}
add_action( 'admin_enqueue_scripts', 'classic_kindergarten_admin_enqueue_scripts' );
?>