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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function interior_services_customizer_css_inline() {
	$interior_services_custom_css = '';
	$interior_services_enable_breadcrumb = get_theme_mod( 'interior_services_enable_breadcrumb', true );

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

	if ( ! empty( $interior_services_custom_css ) ) {
		wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'interior_services_customizer_css_inline' );

//Global Color
function interior_services_customize_css() {
	$interior_services_primary_color = get_theme_mod( 'interior_services_primary_color', '#A6A182' );
	$interior_services_custom_css = ":root { --primary-color: {$interior_services_primary_color}; }";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_customize_css' );

//Google Fonts
function interior_services_enqueue_selected_fonts() {
    $interior_services_fonts_url = interior_services_get_fonts_url();
    if (!empty($interior_services_fonts_url)) {
        wp_enqueue_style('interior-services-google-fonts', $interior_services_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'interior_services_enqueue_selected_fonts');

//Set Width
function interior_services_layout_customizer_css() {
	$interior_services_margin = get_theme_mod( 'interior_services_layout_width_margin', 50 );
	$interior_services_custom_css = "body.site-boxed--layout #page { margin: 0 {$interior_services_margin}px; }";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_layout_customizer_css', 20 );

//Blog Content Alignment
function interior_services_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$interior_services_layout_option = get_theme_mod( 'interior_services_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_blog_layout_customizer_css' );

//Sidebar Width Setting
function interior_services_sidebar_width_customizer_css() {
	$interior_services_sidebar_width = get_theme_mod( 'interior_services_sidebar_width', '30' );

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

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_sidebar_width_customizer_css' );


if ( ! function_exists( 'interior_services_get_page_title' ) ) {
    function interior_services_get_page_title() {
        $interior_services_title = '';

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

        return apply_filters('interior_services_page_title', $interior_services_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('interior_services_display_page_header', $interior_services_return);
    }
}

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

//Page Title Options
function interior_services_page_title_customizer_css() {
	$interior_services_layout_option = get_theme_mod( 'interior_services_page_header_layout', 'left' );
	$interior_services_custom_css = '';

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

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_page_title_customizer_css' );

//Set Height
function interior_services_pagetitle_height_css() {
	$interior_services_height = get_theme_mod( 'interior_services_pagetitle_height', 50 );

	$interior_services_custom_css = "
		header.page-header {
			padding: {$interior_services_height}px 0;
		}
	";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_pagetitle_height_css' );

//Adjust Site Logo Width
function interior_services_site_logo_width() {
	$interior_services_logo_width = get_theme_mod( 'interior_services_site_logo_width', 100 );

	$interior_services_custom_css = "
		.site-logo img {
			max-width: {$interior_services_logo_width}px;
		}
	";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_site_logo_width' );

//Menu Font Size
function interior_services_menu_font_size_css() {
	$interior_services_font_size = get_theme_mod( 'interior_services_menu_font_size', 13 );

	$interior_services_custom_css = "
		.main-navigation a {
			font-size: {$interior_services_font_size}px;
		}
	";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_menu_font_size_css' );

//Menu Font Weight
function interior_services_menu_font_weight_css() {
	$interior_services_font_weight = get_theme_mod( 'interior_services_menu_font_weight', 500 );

	$interior_services_custom_css = "
		.main-navigation a {
		    font-weight: {$interior_services_font_weight};
		}
	";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_menu_font_weight_css' );

//Menu text transform
function interior_services_menu_text_transform_css() {
	$interior_services_text_transform = get_theme_mod( 'interior_services_menu_text_transform', 'capitalize' );

	$interior_services_custom_css = "
		.main-navigation a {
			text-transform: {$interior_services_text_transform};
		}
	";

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_menu_text_transform_css' );

// Featured Image Dimension
function interior_services_custom_featured_image_css() {
    $interior_services_dimension = get_theme_mod('interior_services_blog_post_featured_image_dimension', 'default');
    $interior_services_width = get_theme_mod('interior_services_blog_post_featured_image_custom_width', '');
    $interior_services_height = get_theme_mod('interior_services_blog_post_featured_image_custom_height', '');
    
    if ($interior_services_dimension === 'custom' && $interior_services_width && $interior_services_height) {
        $interior_services_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$interior_services_width}px !important; height: {$interior_services_height}px !important; }";
        wp_add_inline_style('interior-services-style', $interior_services_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'interior_services_custom_featured_image_css');

// Featured Image Border Radius
function interior_services_featured_image_border_radius_css() {
	$interior_services_radius = get_theme_mod( 'interior_services_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_featured_image_border_radius_css' );

//Heading Font Size
function interior_services_sidebar_widget_font_size_css() {
	$interior_services_sidebar_widget_font_size = get_theme_mod( 'interior_services_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_sidebar_widget_font_size_css' );

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

    if ( ! $interior_services_related_product_show_hide ) {
        $interior_services_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'interior-services-style', $interior_services_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'interior_services_related_product_css' );

// Product Sale Badge Position
function interior_services_product_sale_position_customizer_css() {
    $interior_services_position = get_theme_mod('interior_services_product_sale_position', 'left');
    $interior_services_css = '.woocommerce ul.products li.product .onsale {';
    if ($interior_services_position === 'left') {
        $interior_services_css .= 'right: auto; left: 0px;';
    } else {
        $interior_services_css .= 'left: auto; right: 0px;';
    }
    $interior_services_css .= '}';
    wp_add_inline_style('interior-services-style', $interior_services_css);
}
add_action('wp_enqueue_scripts', 'interior_services_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function interior_services_footer_copyright_alignment_css() {
    $interior_services_align = get_theme_mod('interior_services_footer_bottom_align', 'center');
    $interior_services_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$interior_services_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('interior-services-style', $interior_services_css);
}
add_action('wp_enqueue_scripts', 'interior_services_footer_copyright_alignment_css');

// Footer Copyright Font Size
function interior_services_copyright_font_size_css() {
    $interior_services_font_size = get_theme_mod('interior_services_copyright_font_size', 16);
    $interior_services_css = ".site-footer-bottom .site-info span {
        font-size: {$interior_services_font_size}px;
    }";
    wp_add_inline_style('interior-services-style', $interior_services_css);
}
add_action('wp_enqueue_scripts', 'interior_services_copyright_font_size_css');

// Preloader Background Color
function interior_services_preloader_background_colors_css() {
    $interior_services_color = get_theme_mod('interior_services_preloader_background_color_setting', '');
    if (!empty($interior_services_color)) {
        $interior_services_css = "#loader {
            background-color: {$interior_services_color};
        }";
        wp_add_inline_style('interior-services-style', $interior_services_css);
    }
}
add_action('wp_enqueue_scripts', 'interior_services_preloader_background_colors_css');

// Preloader Background Image
function interior_services_preloader_background_image_css() {
    $interior_services_image_url = get_theme_mod('interior_services_preloader_background_image_setting', '');
    if (!empty($interior_services_image_url)) {
        $interior_services_css = "#loader {
            background-image: url('{$interior_services_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('interior-services-style', $interior_services_css);
    }
}
add_action('wp_enqueue_scripts', 'interior_services_preloader_background_image_css');

// Footer Heading Alignment
function interior_services_footer_heading_alignment_css() {
    $interior_services_align = get_theme_mod('interior_services_footer_header_align', 'left');
    $interior_services_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$interior_services_align};
        }
    ";
    wp_add_inline_style('interior-services-style', $interior_services_css);
}
add_action('wp_enqueue_scripts', 'interior_services_footer_heading_alignment_css');

//First Capital Letter
function interior_services_show_first_caps() {
	$interior_services_first_caps = get_theme_mod('interior_services_show_first_caps', false);
	$interior_services_css = '';
	if ( $interior_services_first_caps ) {
	$interior_services_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 {
		$interior_services_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'interior-services-style', $interior_services_css );
}
add_action( 'wp_enqueue_scripts', 'interior_services_show_first_caps' );

// Slider Button Color
function interior_services_slider_button_color_css() {
    $interior_services_btn_color = get_theme_mod('interior_services_slider_btn_color');
	$interior_services_btn_bg_color = get_theme_mod('interior_services_slider_btn_bg_color');

	$interior_services_custom_css = '';

    if ( !empty($interior_services_btn_color) ) {
        $interior_services_custom_css .= "
        #interior_services_slider_section .banner-slider-btn a.asterthemes-button{
            color: {$interior_services_btn_color};
        }
        #interior_services_slider_section .banner-slider-btn a.asterthemes-button i{
            color: {$interior_services_btn_color};
        }";
    }

    if ( !empty($interior_services_btn_bg_color) ) {
		$interior_services_custom_css .= "
		#interior_services_slider_section .banner-slider-btn a.asterthemes-button{
			background-color: {$interior_services_btn_bg_color};
		}";
	}
    wp_add_inline_style('interior-services-style', $interior_services_custom_css);

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

// WooCommerce Product Border Radius
function interior_services_woocommerce_border_radius_css() {
	$interior_services_radius = get_theme_mod('interior_services_woocommerce_product_border_radius', 3);
    $interior_services_custom_css = "
		.woocommerce ul.products li.product {
			border-radius: {$interior_services_radius}px;
			overflow: hidden;
		}
	";
    wp_add_inline_style('interior-services-style', $interior_services_custom_css);
}
add_action('wp_enqueue_scripts', 'interior_services_woocommerce_border_radius_css');

