<?php

/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package fast_food_joint
 */


function fast_food_joint_customize_css() {
    ?>
    <style type="text/css">
        :root {
            --primary-color: <?php echo esc_html( get_theme_mod( 'fast_food_joint_primary_color', '#DF9301' ) ); ?>;
        }
    </style>
    <?php
}
add_action( 'wp_head', 'fast_food_joint_customize_css' );

function fast_food_joint_enqueue_selected_fonts() {
    $fast_food_joint_fonts_url = fast_food_joint_get_fonts_url();
    if (!empty($fast_food_joint_fonts_url)) {
        wp_enqueue_style('fast-food-joint-google-fonts', $fast_food_joint_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'fast_food_joint_enqueue_selected_fonts');

function fast_food_joint_layout_customizer_css() {
    $fast_food_joint_margin = get_theme_mod('fast_food_joint_layout_width_margin', 50);
    ?>
    <style type="text/css">
        body.site-boxed--layout #page  {
            margin: 0 <?php echo esc_attr($fast_food_joint_margin); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_layout_customizer_css');

function fast_food_joint_blog_layout_customizer_css() {
    // Retrieve the blog layout option
    $fast_food_joint_blog_layout_option = get_theme_mod('fast_food_joint_blog_layout_option_setting', 'Left');

    // Initialize custom CSS variable
    $fast_food_joint_custom_css = '';

    // Generate custom CSS based on the layout option
    if ($fast_food_joint_blog_layout_option === 'Default') {
        $fast_food_joint_custom_css .= '.mag-post-detail { text-align: center; }';
    } elseif ($fast_food_joint_blog_layout_option === 'Left') {
        $fast_food_joint_custom_css .= '.mag-post-detail { text-align: left; }';
    } elseif ($fast_food_joint_blog_layout_option === 'Right') {
        $fast_food_joint_custom_css .= '.mag-post-detail { text-align: right; }';
    }

    // Output the combined CSS
    ?>
    <style type="text/css">
        <?php echo wp_kses($fast_food_joint_custom_css, array( 'style' => array(), 'text-align' => array() )); ?>
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_blog_layout_customizer_css');

// Featured Image Dimension
function fast_food_joint_custom_featured_image_css() {
    $fast_food_joint_dimension = get_theme_mod('fast_food_joint_blog_post_featured_image_dimension', 'default');
    $fast_food_joint_width = get_theme_mod('fast_food_joint_blog_post_featured_image_custom_width', '');
    $fast_food_joint_height = get_theme_mod('fast_food_joint_blog_post_featured_image_custom_height', '');
    
    if ($fast_food_joint_dimension === 'custom' && $fast_food_joint_width && $fast_food_joint_height) {
        $fast_food_joint_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$fast_food_joint_width}px !important; height: {$fast_food_joint_height}px !important; }";
        wp_add_inline_style('fast-food-joint-style', $fast_food_joint_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'fast_food_joint_custom_featured_image_css');

function fast_food_joint_sidebar_width_customizer_css() {
    $fast_food_joint_sidebar_width = get_theme_mod('fast_food_joint_sidebar_width', '30');
    ?>
    <style type="text/css">
        .right-sidebar .asterthemes-wrapper .asterthemes-page {
            grid-template-columns: auto <?php echo esc_attr($fast_food_joint_sidebar_width); ?>%;
        }
        .left-sidebar .asterthemes-wrapper .asterthemes-page {
            grid-template-columns: <?php echo esc_attr($fast_food_joint_sidebar_width); ?>% auto;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_sidebar_width_customizer_css');

if ( ! function_exists( 'fast_food_joint_get_page_title' ) ) {
    function fast_food_joint_get_page_title() {
        $fast_food_joint_title = '';

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

        return apply_filters('fast_food_joint_page_title', $fast_food_joint_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('fast_food_joint_display_page_header', $fast_food_joint_return);
    }
}

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

function fast_food_joint_page_title_customizer_css() {
    $fast_food_joint_layout_option = get_theme_mod('fast_food_joint_page_header_layout', 'left');
    ?>
    <style type="text/css">
        .asterthemes-wrapper.page-header-inner {
            <?php if ($fast_food_joint_layout_option === 'flex') : ?>
                display: flex;
                justify-content: space-between;
                align-items: center;
            <?php else : ?>
                text-align: <?php echo esc_attr($fast_food_joint_layout_option); ?>;
            <?php endif; ?>
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_page_title_customizer_css');

function fast_food_joint_pagetitle_height_css() {
    $fast_food_joint_height = get_theme_mod('fast_food_joint_pagetitle_height', 50);
    ?>
    <style type="text/css">
        header.page-header {
            padding: <?php echo esc_attr($fast_food_joint_height); ?>px 0;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_pagetitle_height_css');

function fast_food_joint_site_logo_width() {
    $fast_food_joint_site_logo_width = get_theme_mod('fast_food_joint_site_logo_width', 200);
    ?>
    <style type="text/css">
        .site-logo img {
            max-width: <?php echo esc_attr($fast_food_joint_site_logo_width); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_site_logo_width');

function fast_food_joint_menu_font_size_css() {
    $fast_food_joint_menu_font_size = get_theme_mod('fast_food_joint_menu_font_size', 15);
    ?>
    <style type="text/css">
        .main-navigation a {
            font-size: <?php echo esc_attr($fast_food_joint_menu_font_size); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_menu_font_size_css');

//Menu Font Weight
function fast_food_joint_menu_font_weight_css() {
	$fast_food_joint_font_weight = get_theme_mod( 'fast_food_joint_menu_font_weight', 500 );

	$fast_food_joint_custom_css = "
		.main-navigation a {
		    font-weight: {$fast_food_joint_font_weight};
		}
	";

	wp_add_inline_style( 'fast-food-joint-style', $fast_food_joint_custom_css );
}
add_action( 'wp_enqueue_scripts', 'fast_food_joint_menu_font_weight_css' );

function fast_food_joint_menu_text_transform_css() {
    $menu_text_transform = get_theme_mod('fast_food_joint_menu_text_transform', 'uppercase');
    ?>
    <style type="text/css">
        .main-navigation a {
            text-transform: <?php echo esc_attr($menu_text_transform); ?>;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_menu_text_transform_css');

function fast_food_joint_sidebar_widget_font_size_css() {
    $fast_food_joint_sidebar_widget_font_size = get_theme_mod('fast_food_joint_sidebar_widget_font_size', 24);
    ?>
    <style type="text/css">
        h2.wp-block-heading,aside#secondary .widgettitle,aside#secondary .widget-title {
            font-size: <?php echo esc_attr($fast_food_joint_sidebar_widget_font_size); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_sidebar_widget_font_size_css');

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

    if ( $fast_food_joint_related_product_show_hide != true) {
        ?>
        <style type="text/css">
            .related.products {
                display: none;
            }
        </style>
        <?php
    }
}
add_action('wp_head', 'fast_food_joint_related_product_css');

// Woocommerce Product Sale Position 
function fast_food_joint_product_sale_position_customizer_css() {
    $fast_food_joint_layout_option = get_theme_mod('fast_food_joint_product_sale_position', 'left');
    ?>
    <style type="text/css">
        .woocommerce ul.products li.product .onsale{
            <?php if ($fast_food_joint_layout_option === 'left') : ?>
                right: auto;
                left: 0px;
            <?php else : ?>
                left: auto;
                right: 0px;
            <?php endif; ?>
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_product_sale_position_customizer_css');  

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

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

//Copyright Alignment
function fast_food_joint_footer_copyright_alignment_css() {
    $fast_food_joint_footer_bottom_align = get_theme_mod( 'fast_food_joint_footer_bottom_align', 'center' );   
    ?>
    <style type="text/css">
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: <?php echo esc_attr( $fast_food_joint_footer_bottom_align ); ?> 
        }

        /* Mobile Specific */
        @media screen and (max-width: 575px) {
            .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
                justify-content: center;
                text-align:center;
            }
        }
    </style>
    <?php
}
add_action( 'wp_head', 'fast_food_joint_footer_copyright_alignment_css' );

//Copyright Font Size
function fast_food_joint_copyright_font_size_css() {
    $fast_food_joint_copyright_font_size = get_theme_mod('fast_food_joint_copyright_font_size', 16);
    ?>
    <style type="text/css">
        .site-footer-bottom .site-info span {
            font-size: <?php echo esc_attr($fast_food_joint_copyright_font_size); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_copyright_font_size_css');

// Preloader Background Color Setting
function fast_food_joint_preloader_background_colors_css() {
    $fast_food_joint_preloader_background_color_setting = get_theme_mod('fast_food_joint_preloader_background_color_setting', '');
        // Only output CSS if a color is set
        if (empty($fast_food_joint_preloader_background_color_setting)) {
            return;
        }
    ?>
    <style type="text/css">
        #loader {
            background-color: <?php echo esc_attr($fast_food_joint_preloader_background_color_setting); ?>;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_preloader_background_colors_css');

// Preloader Background Image Setting
function fast_food_joint_preloader_background_image_css() {
    $fast_food_joint_preloader_background_image_setting = get_theme_mod('fast_food_joint_preloader_background_image_setting', '');
        // Only output CSS if the background image is set
        if (empty($fast_food_joint_preloader_background_image_setting)) {
            return;
        }
    ?>
    <style type="text/css">
        #loader {
            background-image: url('<?php echo esc_url($fast_food_joint_preloader_background_image_setting); ?>');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }
    </style>
    <?php
}
add_action('wp_head', 'fast_food_joint_preloader_background_image_css');

//Footer Heading Alignment
function fast_food_joint_footer_heading_alignment_css() {
    $fast_food_joint_footer_header_align = get_theme_mod( 'fast_food_joint_footer_header_align', 'left' );   
    ?>
    <style type="text/css">
        .site-footer h4, footer#colophon h2.wp-block-heading, footer#colophon .widgettitle, footer#colophon .widget-title {
            text-align: <?php echo esc_attr( $fast_food_joint_footer_header_align ); ?> 
        }
    </style>
    <?php
}
add_action( 'wp_head', 'fast_food_joint_footer_heading_alignment_css' );

//First Capital Letter
function fast_food_joint_show_first_caps() {
	$fast_food_joint_first_caps = get_theme_mod('fast_food_joint_show_first_caps', false);
	$fast_food_joint_css = '';
	if ( $fast_food_joint_first_caps ) {
	$fast_food_joint_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 {
		$fast_food_joint_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'fast-food-joint-style', $fast_food_joint_css );
}
add_action( 'wp_enqueue_scripts', 'fast_food_joint_show_first_caps' );

// Topbar Padding Dynamic CSS
function fast_food_joint_topbar_padding_css(){
	$padding = get_theme_mod('fast_food_joint_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('fast-food-joint-style',$custom_css);

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

// Banner Button Color
function fast_food_joint_banner_button_color_css() {
    $btn_color = get_theme_mod('fast_food_joint_banner_btn_color');
    $btn_bg_color = get_theme_mod('fast_food_joint_banner_btn_bg_color');
    $btn_border_color = get_theme_mod('fast_food_joint_banner_btn_border_color');

    $custom_css = '';
    if ( !empty($btn_color) ) {
        $custom_css .= "
        .banner-slider-btn a.asterthemes-button{
            color: {$btn_color};
        }";
    }
    if ( !empty($btn_bg_color) ) {
        $custom_css .= "
        .banner-slider-btn a.asterthemes-button{
            background-color: {$btn_bg_color};
        }";
    }
     if ( !empty($btn_border_color) ) {
        $custom_css .= "
        .banner-slider-btn a.asterthemes-button{
            border: 2px solid {$btn_border_color};
        }";
    }

    wp_add_inline_style('fast-food-joint-style', $custom_css);
}
add_action('wp_enqueue_scripts','fast_food_joint_banner_button_color_css');