<?php

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

 function moving_truck_rental_customize_css() {
    ?>
    <style type="text/css">
        :root {
            --primary-color: <?php echo esc_html( get_theme_mod( 'moving_truck_rental_primary_color', '#FC3F3A' ) ); ?>;
            --secondary_color: <?php echo esc_html( get_theme_mod( 'primary_gradient', '#F69940' ) ); ?>;
        }
    </style>
    <?php
}
add_action( 'wp_head', 'moving_truck_rental_customize_css' );



function moving_truck_rental_enqueue_selected_fonts() {
    $moving_truck_rental_fonts_url = moving_truck_rental_get_fonts_url();
    if (!empty($moving_truck_rental_fonts_url)) {
        wp_enqueue_style('moving-truck-rental-google-fonts', $moving_truck_rental_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'moving_truck_rental_enqueue_selected_fonts');

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

function moving_truck_rental_blog_layout_customizer_css() {
    // Retrieve the blog layout option
    $moving_truck_rental_blog_layout_option = get_theme_mod('moving_truck_rental_blog_layout_option_setting', 'Left');

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

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

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

// Featured Image Dimension
function moving_truck_rental_custom_featured_image_css() {
    $moving_truck_rental_dimension = get_theme_mod('moving_truck_rental_blog_post_featured_image_dimension', 'default');
    $moving_truck_rental_width = get_theme_mod('moving_truck_rental_blog_post_featured_image_custom_width', '');
    $moving_truck_rental_height = get_theme_mod('moving_truck_rental_blog_post_featured_image_custom_height', '');
    
    if ($moving_truck_rental_dimension === 'custom' && $moving_truck_rental_width && $moving_truck_rental_height) {
        $moving_truck_rental_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$moving_truck_rental_width}px !important; height: {$moving_truck_rental_height}px !important; }";
        wp_add_inline_style('moving-truck-rental-style', $moving_truck_rental_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'moving_truck_rental_custom_featured_image_css');

// Featured Image Border Radius
function moving_truck_rental_featured_image_border_radius_css() {
    $moving_truck_rental_featured_image_border_radius = get_theme_mod('moving_truck_rental_featured_image_border_radius', 10);
    ?>
    <style type="text/css">  
        .mag-post-single img {
            border-radius: <?php echo esc_attr($moving_truck_rental_featured_image_border_radius); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'moving_truck_rental_featured_image_border_radius_css');

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

function moving_truck_rental_customize_scss() {
    // Retrieve the two colors from the customizer settings.
    $moving_truck_rental_color1 = get_theme_mod('moving_truck_rental_primary_color', '#DA2A56'); // Default start color
    $moving_truck_rental_color2 = get_theme_mod('moving_truck_rental_secondary_color', '#F69940'); // Default end color

    // Generate the gradient.
    $moving_truck_rental_gradient = "linear-gradient(90.09deg, $moving_truck_rental_color1 0%, $moving_truck_rental_color2 99.23%)";
    ?>
    <style type="text/css">
        :root {
            --primary-color: <?php echo esc_html($moving_truck_rental_color1); ?>; /* Fallback color (color1) */
            --secondary-color: <?php echo esc_html($moving_truck_rental_color2); ?>; /* Dynamically generated gradient */
             --primary-gradient: <?php echo esc_html($moving_truck_rental_gradient); ?>; 
        }
    </style>
    <?php
}
add_action('wp_head', 'moving_truck_rental_customize_scss');

if ( ! function_exists( 'moving_truck_rental_get_page_title' ) ) {
    function moving_truck_rental_get_page_title() {
        $moving_truck_rental_title = '';

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

        return apply_filters('moving_truck_rental_page_title', $moving_truck_rental_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('moving_truck_rental_display_page_header', $moving_truck_rental_return);
    }
}

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

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

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

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

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

//Menu Font Weight
function moving_truck_rental_menu_font_weight_css() {
	$moving_truck_rental_font_weight = get_theme_mod( 'moving_truck_rental_menu_font_weight', 500);

	$moving_truck_rental_custom_css = "
		.main-navigation a {
		    font-weight: {$moving_truck_rental_font_weight};
		}
	";

	wp_add_inline_style( 'moving-truck-rental-style', $moving_truck_rental_custom_css );
}
add_action( 'wp_enqueue_scripts', 'moving_truck_rental_menu_font_weight_css' );

function moving_truck_rental_sidebar_widget_font_size_css() {
    $moving_truck_rental_sidebar_widget_font_size = get_theme_mod('moving_truck_rental_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($moving_truck_rental_sidebar_widget_font_size); ?>px;
        }
    </style>
    <?php
}
add_action('wp_head', 'moving_truck_rental_sidebar_widget_font_size_css');

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

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

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

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

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

//Copyright Alignment
function moving_truck_rental_footer_copyright_alignment_css() {
    $moving_truck_rental_footer_bottom_align = get_theme_mod( 'moving_truck_rental_footer_bottom_align', 'center' );   
    ?>
    <style type="text/css">
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: <?php echo esc_attr( $moving_truck_rental_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', 'moving_truck_rental_footer_copyright_alignment_css' );

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

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

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

//Footer Heading Alignment
function moving_truck_rental_footer_heading_alignment_css() {
    $moving_truck_rental_footer_header_align = get_theme_mod( 'moving_truck_rental_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( $moving_truck_rental_footer_header_align ); ?> 
        }
    </style>
    <?php
}
add_action( 'wp_head', 'moving_truck_rental_footer_heading_alignment_css' );

//First Capital Letter
function moving_truck_rental_show_first_caps() {
	$moving_truck_rental_first_caps = get_theme_mod('moving_truck_rental_show_first_caps', false);
	$moving_truck_rental_css = '';
	if ( $moving_truck_rental_first_caps ) {
	$moving_truck_rental_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 {
		$moving_truck_rental_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'moving-truck-rental-style', $moving_truck_rental_css );
}
add_action( 'wp_enqueue_scripts', 'moving_truck_rental_show_first_caps' );