<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package online_school_courses
 */


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function online_school_courses_customizer_css_inline() {
	$online_school_courses_custom_css = '';
	$online_school_courses_enable_breadcrumb = get_theme_mod( 'online_school_courses_enable_breadcrumb', true );

	if ( ! $online_school_courses_enable_breadcrumb ) {
		$online_school_courses_custom_css .= 'nav.woocommerce-breadcrumb { 
            display: none; 
        }';
	}

	if ( ! empty( $online_school_courses_custom_css ) ) {
		wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_customizer_css_inline' );

//Global Color
function online_school_courses_customize_css() {
	$online_school_courses_primary_color = get_theme_mod( 'online_school_courses_primary_color', '#0038B7' );
	$online_school_courses_custom_css = ":root { --primary-color: {$online_school_courses_primary_color}; }";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_customize_css' );

//Google Fonts
function online_school_courses_enqueue_selected_fonts() {
    $online_school_courses_fonts_url = online_school_courses_get_fonts_url();
    if (!empty($online_school_courses_fonts_url)) {
        wp_enqueue_style('online-school-courses-google-fonts', $online_school_courses_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'online_school_courses_enqueue_selected_fonts');

//Set Width
function online_school_courses_layout_customizer_css() {
	$online_school_courses_margin = get_theme_mod( 'online_school_courses_layout_width_margin', 50 );
	$online_school_courses_custom_css = "body.site-boxed--layout #page { margin: 0 {$online_school_courses_margin}px; }";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_layout_customizer_css', 20 );

//Blog Content Alignment
function online_school_courses_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$online_school_courses_layout_option = get_theme_mod( 'online_school_courses_blog_layout_option_setting', 'Left' );

	// Determine text alignment based on option
	switch ( $online_school_courses_layout_option ) {
		case 'Right':
			$online_school_courses_text_align = 'right';
			break;
		case 'Default':
			$online_school_courses_text_align = 'center';
			break;
		case 'Left':
		default:
			$online_school_courses_text_align = 'left';
			break;
	}

	// Create custom CSS
	$online_school_courses_custom_css = ".mag-post-detail { text-align: {$online_school_courses_text_align}; }";

	// Attach CSS to theme style
	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_blog_layout_customizer_css' );

//Sidebar Width Setting
function online_school_courses_sidebar_width_customizer_css() {
	$online_school_courses_sidebar_width = get_theme_mod( 'online_school_courses_sidebar_width', '30' );

	$online_school_courses_custom_css = "
		.right-sidebar .asterthemes-wrapper .asterthemes-page {
			grid-template-columns: auto {$online_school_courses_sidebar_width}%;
		}
		.left-sidebar .asterthemes-wrapper .asterthemes-page {
			grid-template-columns: {$online_school_courses_sidebar_width}% auto;
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_sidebar_width_customizer_css' );


if ( ! function_exists( 'online_school_courses_get_page_title' ) ) {
    function online_school_courses_get_page_title() {
        $online_school_courses_title = '';

        if (is_404()) {
            $online_school_courses_title = esc_html__('Page Not Found', 'online-school-courses');
        } elseif (is_search()) {
            $online_school_courses_title = esc_html__('Search Results for: ', 'online-school-courses') . esc_html(get_search_query());
        } elseif (is_home() && !is_front_page()) {
            $online_school_courses_title = esc_html__('Blogs', 'online-school-courses');
        } elseif (function_exists('is_shop') && is_shop()) {
            $online_school_courses_title = esc_html__('Shop', 'online-school-courses');
        } elseif (is_page()) {
            $online_school_courses_title = get_the_title();
        } elseif (is_single()) {
            $online_school_courses_title = get_the_title();
        } elseif (is_archive()) {
            $online_school_courses_title = get_the_archive_title();
        } else {
            $online_school_courses_title = get_the_archive_title();
        }

        return apply_filters('online_school_courses_page_title', $online_school_courses_title);
    }
}

if ( ! function_exists( 'online_school_courses_has_page_header' ) ) {
    function online_school_courses_has_page_header() {
        // Default to true (display header)
        $online_school_courses_return = true;

        // Custom conditions for disabling the header
        if ('hide-all-devices' === get_theme_mod('online_school_courses_page_header_visibility', 'all-devices')) {
            $online_school_courses_return = false;
        }

        // Apply filters and return
        return apply_filters('online_school_courses_display_page_header', $online_school_courses_return);
    }
}

if ( ! function_exists( 'online_school_courses_page_header_style' ) ) {
    function online_school_courses_page_header_style() {
        $online_school_courses_style = get_theme_mod('online_school_courses_page_header_style', 'default');
        return apply_filters('online_school_courses_page_header_style', $online_school_courses_style);
    }
}

//Page Title Options
function online_school_courses_page_title_customizer_css() {
	$online_school_courses_layout_option = get_theme_mod( 'online_school_courses_page_header_layout', 'left' );
	$online_school_courses_custom_css = '';

	if ( $online_school_courses_layout_option === 'flex' ) {
		$online_school_courses_custom_css .= '
			.asterthemes-wrapper.page-header-inner {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		';
	} else {
		$online_school_courses_custom_css .= "
			.asterthemes-wrapper.page-header-inner {
				text-align: {$online_school_courses_layout_option};
			}
		";
	}

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_page_title_customizer_css' );

//Set Height
function online_school_courses_pagetitle_height_css() {
	$online_school_courses_height = get_theme_mod( 'online_school_courses_pagetitle_height', 50 );

	$online_school_courses_custom_css = "
		header.page-header {
			padding: {$online_school_courses_height}px 0;
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_pagetitle_height_css' );

//Adjust Site Logo Width
function online_school_courses_site_logo_width() {
	$online_school_courses_logo_width = get_theme_mod( 'online_school_courses_site_logo_width', 150 );

	$online_school_courses_custom_css = "
		.site-logo img {
			max-width: {$online_school_courses_logo_width}px;
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_site_logo_width' );

//Menu Font Size
function online_school_courses_menu_font_size_css() {
	$online_school_courses_font_size = get_theme_mod( 'online_school_courses_menu_font_size', 13 );

	$online_school_courses_custom_css = "
		.main-navigation a {
			font-size: {$online_school_courses_font_size}px;
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_menu_font_size_css' );

//Menu Font Weight
function online_school_courses_menu_font_weight_css() {
	$online_school_courses_font_weight = get_theme_mod( 'online_school_courses_menu_font_weight', 500 );

	$online_school_courses_custom_css = "
		.main-navigation a {
		    font-weight: {$online_school_courses_font_weight};
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_menu_font_weight_css' );

//Menu text transform
function online_school_courses_menu_text_transform_css() {
	$online_school_courses_text_transform = get_theme_mod( 'online_school_courses_menu_text_transform', 'capitalize' );

	$online_school_courses_custom_css = "
		.main-navigation a {
			text-transform: {$online_school_courses_text_transform};
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_menu_text_transform_css' );

// Featured Image Dimension
function online_school_courses_custom_featured_image_css() {
    $online_school_courses_dimension = get_theme_mod('online_school_courses_blog_post_featured_image_dimension', 'default');
    $online_school_courses_width = get_theme_mod('online_school_courses_blog_post_featured_image_custom_width', '');
    $online_school_courses_height = get_theme_mod('online_school_courses_blog_post_featured_image_custom_height', '');
    
    if ($online_school_courses_dimension === 'custom' && $online_school_courses_width && $online_school_courses_height) {
        $online_school_courses_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$online_school_courses_width}px !important; height: {$online_school_courses_height}px !important; }";
        wp_add_inline_style('online-school-courses-style', $online_school_courses_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'online_school_courses_custom_featured_image_css');

// Featured Image Border Radius
function online_school_courses_featured_image_border_radius_css() {
	$online_school_courses_radius = get_theme_mod( 'online_school_courses_featured_image_border_radius', 10 );

	$online_school_courses_custom_css = "
		.mag-post-single img {
			border-radius: {$online_school_courses_radius}px;
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_featured_image_border_radius_css' );

//Heading Font Size
function online_school_courses_sidebar_widget_font_size_css() {
	$online_school_courses_sidebar_widget_font_size = get_theme_mod( 'online_school_courses_sidebar_widget_font_size', 24 );

	$online_school_courses_custom_css = "
		h2.wp-block-heading,
		aside#secondary .widgettitle,
		aside#secondary .widget-title {
			font-size: {$online_school_courses_sidebar_widget_font_size}px;
		}
	";

	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_sidebar_widget_font_size_css' );

// Woocommerce Related Products Settings
function online_school_courses_related_product_css() {
    $online_school_courses_related_product_show_hide = get_theme_mod( 'online_school_courses_related_product_show_hide', true );

    if ( ! $online_school_courses_related_product_show_hide ) {
        $online_school_courses_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'online-school-courses-style', $online_school_courses_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_related_product_css' );

// Product Sale Badge Position
function online_school_courses_product_sale_position_customizer_css() {
    $online_school_courses_position = get_theme_mod('online_school_courses_product_sale_position', 'left');
    $online_school_courses_css = '.woocommerce ul.products li.product .onsale {';
    if ($online_school_courses_position === 'left') {
        $online_school_courses_css .= 'right: auto; left: 0px;';
    } else {
        $online_school_courses_css .= 'left: auto; right: 0px;';
    }
    $online_school_courses_css .= '}';
    wp_add_inline_style('online-school-courses-style', $online_school_courses_css);
}
add_action('wp_enqueue_scripts', 'online_school_courses_product_sale_position_customizer_css');

//Footer Social Icon Alignment
function online_school_courses_footer_icons_alignment_css() {
    $online_school_courses_footer_social_align = get_theme_mod( 'online_school_courses_footer_social_align', 'center' );   
    ?>
    <style type="text/css">
        .socialicons {
            text-align: <?php echo esc_attr( $online_school_courses_footer_social_align ); ?> 
        }

        /* Mobile Specific */
        @media screen and (max-width: 575px) {
            .socialicons {
                text-align: center;
            }
        }
    </style>
    <?php
}
add_action( 'wp_head', 'online_school_courses_footer_icons_alignment_css' );

// Footer Copyright Alignment
function online_school_courses_footer_copyright_alignment_css() {
    $online_school_courses_align = get_theme_mod('online_school_courses_footer_bottom_align', 'center');
    $online_school_courses_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$online_school_courses_align};
        }
        @media screen and (max-width: 575px) {
            .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
                justify-content: center;
                text-align: center;
            }
        }
    ";
    wp_add_inline_style('online-school-courses-style', $online_school_courses_css);
}
add_action('wp_enqueue_scripts', 'online_school_courses_footer_copyright_alignment_css');

// Footer Copyright Font Size
function online_school_courses_copyright_font_size_css() {
    $online_school_courses_font_size = get_theme_mod('online_school_courses_copyright_font_size', 16);
    $online_school_courses_css = ".site-footer-bottom .site-info span {
        font-size: {$online_school_courses_font_size}px;
    }";
    wp_add_inline_style('online-school-courses-style', $online_school_courses_css);
}
add_action('wp_enqueue_scripts', 'online_school_courses_copyright_font_size_css');

// Preloader Background Color
function online_school_courses_preloader_background_colors_css() {
    $online_school_courses_color = get_theme_mod('online_school_courses_preloader_background_color_setting', '');
    if (!empty($online_school_courses_color)) {
        $online_school_courses_css = "#loader {
            background-color: {$online_school_courses_color};
        }";
        wp_add_inline_style('online-school-courses-style', $online_school_courses_css);
    }
}
add_action('wp_enqueue_scripts', 'online_school_courses_preloader_background_colors_css');

// Preloader Background Image
function online_school_courses_preloader_background_image_css() {
    $online_school_courses_image_url = get_theme_mod('online_school_courses_preloader_background_image_setting', '');
    if (!empty($online_school_courses_image_url)) {
        $online_school_courses_css = "#loader {
            background-image: url('{$online_school_courses_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('online-school-courses-style', $online_school_courses_css);
    }
}
add_action('wp_enqueue_scripts', 'online_school_courses_preloader_background_image_css');

// Footer Heading Alignment
function online_school_courses_footer_heading_alignment_css() {
    $online_school_courses_align = get_theme_mod('online_school_courses_footer_header_align', 'left');
    $online_school_courses_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$online_school_courses_align};
        }
    ";
    wp_add_inline_style('online-school-courses-style', $online_school_courses_css);
}
add_action('wp_enqueue_scripts', 'online_school_courses_footer_heading_alignment_css');

//First Capital Letter
function online_school_courses_show_first_caps() {
	$online_school_courses_first_caps = get_theme_mod('online_school_courses_show_first_caps', false);
	$online_school_courses_css = '';
	if ( $online_school_courses_first_caps ) {
	$online_school_courses_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
		    font-size: 55px;
			font-weight: 600;
			margin-right: 6px;
			line-height: 1;
			display: inline-block;
			vertical-align: baseline;
		}';
	} else {
		$online_school_courses_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'online-school-courses-style', $online_school_courses_css );
}
add_action( 'wp_enqueue_scripts', 'online_school_courses_show_first_caps' );

// Banner Button Color
function online_school_courses_banner_button_color_css() {
    $btn_color = get_theme_mod('online_school_courses_banner_btn_color');
	$btn_bg_color = get_theme_mod('online_school_courses_banner_btn_bg_color');

	$custom_css = '';
    if ( !empty($btn_color) ) {
		$custom_css .= "
		.banner-single .banner-btn a.asterthemes-button{
			color: {$btn_color};
		}";
	}

	if ( !empty($btn_bg_color) ) {
		$custom_css .= "
		.banner-single .banner-btn a.asterthemes-button{
			background-color: {$btn_bg_color};
		}";
	}

	wp_add_inline_style('online-school-courses-style', $custom_css);
}
add_action('wp_enqueue_scripts','online_school_courses_banner_button_color_css');

// Topbar Padding Dynamic CSS
function online_school_courses_topbar_padding_css(){
	$padding = get_theme_mod('online_school_courses_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('online-school-courses-style',$custom_css);

}
add_action('wp_enqueue_scripts','online_school_courses_topbar_padding_css');

// WooCommerce Product Border Radius
function online_school_courses_woocommerce_border_radius_css() {
	$online_school_courses_radius = get_theme_mod('online_school_courses_woocommerce_product_border_radius', 3);
    $online_school_courses_custom_css = "
		.woocommerce ul.products li.product {
			border-radius: {$online_school_courses_radius}px;
			overflow: hidden;
		}
	";
    wp_add_inline_style('online-school-courses-style', $online_school_courses_custom_css);
}
add_action('wp_enqueue_scripts', 'online_school_courses_woocommerce_border_radius_css');
