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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function lawyer_consultant_firm_customizer_css_inline() {
	$lawyer_consultant_firm_custom_css = '';
	$lawyer_consultant_firm_enable_breadcrumb = get_theme_mod( 'lawyer_consultant_firm_enable_breadcrumb', true );

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

	if ( ! empty( $lawyer_consultant_firm_custom_css ) ) {
		wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_customizer_css_inline' );

function lawyer_consultant_firm_custom_css() {
    $lawyer_consultant_firm_slider = get_theme_mod('lawyer_consultant_firm_enable_slider_section', false);
    ?>
    <style type="text/css">
        .home .bottom-header-outer-wrapper {
            z-index: 99;
            width: 100%;
            <?php if ( $lawyer_consultant_firm_slider ) : ?>
                background: transparent;
                position: absolute;
            <?php else : ?>
				background: #0A0C1499;
    			backdrop-filter: blur(10px);
                position: static;      
            <?php endif; ?>
        }
    </style>
    <?php
}
add_action( 'wp_head', 'lawyer_consultant_firm_custom_css' );

function lawyer_consultant_firm_topbar_custom_css() {
    $lawyer_consultant_firm_enable_topbar = get_theme_mod('lawyer_consultant_firm_enable_topbar', false);

    if ( $lawyer_consultant_firm_enable_topbar ) : ?>
        <style type="text/css">
            /* Media queries for topbar adjustments */
            @media (max-width: 991px) {
                #site-navigation button.menu-toggle.open {
                    top: -116px;
                }
                #site-navigation .main-navigation-links {
                    top: -200px;
                }
            }

            @media (max-width: 991px) and (min-width: 886px){
                #site-navigation .main-navigation-links {
                    top: -75px;
                }
                #site-navigation button.menu-toggle.open {
                    top: -50px;
                }
            }

            @media (max-width: 885px) and (min-width: 653px){
                #site-navigation .main-navigation-links {
                    top: -123px;
                }
                #site-navigation button.menu-toggle.open {
                    top: -80px;
                }
            }

            @media (max-width: 652px) and (min-width: 369px){
                #site-navigation .main-navigation-links {
                    top: -158px;
                }
                #site-navigation button.menu-toggle.open {
                    top: -115px;
                }
            }
        </style>
    <?php endif;
}
add_action( 'wp_head', 'lawyer_consultant_firm_topbar_custom_css' );

//Global Color
function lawyer_consultant_firm_customize_css() {
	$lawyer_consultant_firm_primary_color = get_theme_mod( 'lawyer_consultant_firm_primary_color', '#CD8437' );
	$lawyer_consultant_firm_custom_css = ":root { --primary-color: {$lawyer_consultant_firm_primary_color}; }";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_customize_css' );

//Google Fonts
function lawyer_consultant_firm_enqueue_selected_fonts() {
    $lawyer_consultant_firm_fonts_url = lawyer_consultant_firm_get_fonts_url();
    if (!empty($lawyer_consultant_firm_fonts_url)) {
        wp_enqueue_style('lawyer-consultant-firm-google-fonts', $lawyer_consultant_firm_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_enqueue_selected_fonts');

//Set Width
function lawyer_consultant_firm_layout_customizer_css() {
	$lawyer_consultant_firm_margin = get_theme_mod( 'lawyer_consultant_firm_layout_width_margin', 50 );
	$lawyer_consultant_firm_custom_css = "body.site-boxed--layout #page { margin: 0 {$lawyer_consultant_firm_margin}px; }";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_layout_customizer_css', 20 );

//Blog Content Alignment
function lawyer_consultant_firm_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$lawyer_consultant_firm_layout_option = get_theme_mod( 'lawyer_consultant_firm_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_blog_layout_customizer_css' );

//Sidebar Width Setting
function lawyer_consultant_firm_sidebar_width_customizer_css() {
	$lawyer_consultant_firm_sidebar_width = get_theme_mod( 'lawyer_consultant_firm_sidebar_width', '30' );

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

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_sidebar_width_customizer_css' );


if ( ! function_exists( 'lawyer_consultant_firm_get_page_title' ) ) {
    function lawyer_consultant_firm_get_page_title() {
        $lawyer_consultant_firm_title = '';

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

        return apply_filters('lawyer_consultant_firm_page_title', $lawyer_consultant_firm_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('lawyer_consultant_firm_display_page_header', $lawyer_consultant_firm_return);
    }
}

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

//Page Title Options
function lawyer_consultant_firm_page_title_customizer_css() {
	$lawyer_consultant_firm_layout_option = get_theme_mod( 'lawyer_consultant_firm_page_header_layout', 'left' );
	$lawyer_consultant_firm_custom_css = '';

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

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_page_title_customizer_css' );

//Set Height
function lawyer_consultant_firm_pagetitle_height_css() {
	$lawyer_consultant_firm_height = get_theme_mod( 'lawyer_consultant_firm_pagetitle_height', 50 );

	$lawyer_consultant_firm_custom_css = "
		header.page-header {
			padding: {$lawyer_consultant_firm_height}px 0;
		}
	";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_pagetitle_height_css' );

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

	$lawyer_consultant_firm_custom_css = "
		.site-logo img {
			max-width: {$lawyer_consultant_firm_logo_width}px;
		}
	";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_site_logo_width' );

//Menu Font Size
function lawyer_consultant_firm_menu_font_size_css() {
	$lawyer_consultant_firm_font_size = get_theme_mod( 'lawyer_consultant_firm_menu_font_size', 13 );

	$lawyer_consultant_firm_custom_css = "
		.main-navigation a {
			font-size: {$lawyer_consultant_firm_font_size}px;
		}
	";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_menu_font_size_css' );

//Menu Font Weight
function lawyer_consultant_firm_menu_font_weight_css() {
	$lawyer_consultant_firm_font_weight = get_theme_mod( 'lawyer_consultant_firm_menu_font_weight', 500 );

	$lawyer_consultant_firm_custom_css = "
		.main-navigation a {
		    font-weight: {$lawyer_consultant_firm_font_weight};
		}
	";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_menu_font_weight_css' );

//Menu text transform
function lawyer_consultant_firm_menu_text_transform_css() {
	$lawyer_consultant_firm_text_transform = get_theme_mod( 'lawyer_consultant_firm_menu_text_transform', 'capitalize' );

	$lawyer_consultant_firm_custom_css = "
		.main-navigation a {
			text-transform: {$lawyer_consultant_firm_text_transform};
		}
	";

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_menu_text_transform_css' );

// Featured Image Dimension
function lawyer_consultant_firm_custom_featured_image_css() {
    $lawyer_consultant_firm_dimension = get_theme_mod('lawyer_consultant_firm_blog_post_featured_image_dimension', 'default');
    $lawyer_consultant_firm_width = get_theme_mod('lawyer_consultant_firm_blog_post_featured_image_custom_width', '');
    $lawyer_consultant_firm_height = get_theme_mod('lawyer_consultant_firm_blog_post_featured_image_custom_height', '');
    
    if ($lawyer_consultant_firm_dimension === 'custom' && $lawyer_consultant_firm_width && $lawyer_consultant_firm_height) {
        $lawyer_consultant_firm_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$lawyer_consultant_firm_width}px !important; height: {$lawyer_consultant_firm_height}px !important; }";
        wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_custom_featured_image_css');

// Featured Image Border Radius
function lawyer_consultant_firm_featured_image_border_radius_css() {
	$lawyer_consultant_firm_radius = get_theme_mod( 'lawyer_consultant_firm_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_featured_image_border_radius_css' );

//Heading Font Size
function lawyer_consultant_firm_sidebar_widget_font_size_css() {
	$lawyer_consultant_firm_sidebar_widget_font_size = get_theme_mod( 'lawyer_consultant_firm_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_sidebar_widget_font_size_css' );

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

    if ( ! $lawyer_consultant_firm_related_product_show_hide ) {
        $lawyer_consultant_firm_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_related_product_css' );

// Product Sale Badge Position
function lawyer_consultant_firm_product_sale_position_customizer_css() {
    $lawyer_consultant_firm_position = get_theme_mod('lawyer_consultant_firm_product_sale_position', 'left');
    $lawyer_consultant_firm_css = '.woocommerce ul.products li.product .onsale {';
    if ($lawyer_consultant_firm_position === 'left') {
        $lawyer_consultant_firm_css .= 'right: auto; left: 0px;';
    } else {
        $lawyer_consultant_firm_css .= 'left: auto; right: 0px;';
    }
    $lawyer_consultant_firm_css .= '}';
    wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_css);
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function lawyer_consultant_firm_footer_copyright_alignment_css() {
    $lawyer_consultant_firm_align = get_theme_mod('lawyer_consultant_firm_footer_bottom_align', 'center');
    $lawyer_consultant_firm_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$lawyer_consultant_firm_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('lawyer-consultant-firm-style', $lawyer_consultant_firm_css);
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_footer_copyright_alignment_css');

// Footer Copyright Font Size
function lawyer_consultant_firm_copyright_font_size_css() {
    $lawyer_consultant_firm_font_size = get_theme_mod('lawyer_consultant_firm_copyright_font_size', 16);
    $lawyer_consultant_firm_css = ".site-footer-bottom .site-info span {
        font-size: {$lawyer_consultant_firm_font_size}px;
    }";
    wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_css);
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_copyright_font_size_css');

// Preloader Background Color
function lawyer_consultant_firm_preloader_background_colors_css() {
    $lawyer_consultant_firm_color = get_theme_mod('lawyer_consultant_firm_preloader_background_color_setting', '');
    if (!empty($lawyer_consultant_firm_color)) {
        $lawyer_consultant_firm_css = "#loader {
            background-color: {$lawyer_consultant_firm_color};
        }";
        wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_css);
    }
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_preloader_background_colors_css');

// Preloader Background Image
function lawyer_consultant_firm_preloader_background_image_css() {
    $lawyer_consultant_firm_image_url = get_theme_mod('lawyer_consultant_firm_preloader_background_image_setting', '');
    if (!empty($lawyer_consultant_firm_image_url)) {
        $lawyer_consultant_firm_css = "#loader {
            background-image: url('{$lawyer_consultant_firm_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_css);
    }
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_preloader_background_image_css');

// Footer Heading Alignment
function lawyer_consultant_firm_footer_heading_alignment_css() {
    $lawyer_consultant_firm_align = get_theme_mod('lawyer_consultant_firm_footer_header_align', 'left');
    $lawyer_consultant_firm_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$lawyer_consultant_firm_align};
        }
    ";
    wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_css);
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_footer_heading_alignment_css');

//First Capital Letter
function lawyer_consultant_firm_show_first_caps() {
	$lawyer_consultant_firm_first_caps = get_theme_mod('lawyer_consultant_firm_show_first_caps', false);
	$lawyer_consultant_firm_css = '';
	if ( $lawyer_consultant_firm_first_caps ) {
	$lawyer_consultant_firm_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 {
		$lawyer_consultant_firm_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'lawyer-consultant-firm-style', $lawyer_consultant_firm_css );
}
add_action( 'wp_enqueue_scripts', 'lawyer_consultant_firm_show_first_caps' );

// Slider Button Color
function lawyer_consultant_firm_slider_button_color_css() {
    $lawyer_consultant_firm_btn_color = get_theme_mod('lawyer_consultant_firm_slider_btn_color');
	$lawyer_consultant_firm_btn_bg_color = get_theme_mod('lawyer_consultant_firm_slider_btn_bg_color');

	$lawyer_consultant_firm_custom_css = '';

	if ( !empty($lawyer_consultant_firm_btn_color) ) {
		$lawyer_consultant_firm_custom_css .= "
		#lawyer_consultant_firm_slider_section .banner-slider-btn a.asterthemes-button{
			color: {$lawyer_consultant_firm_btn_color};
		}";
	}
    if ( !empty($lawyer_consultant_firm_btn_bg_color) ) {
		$lawyer_consultant_firm_custom_css .= "
		#lawyer_consultant_firm_slider_section .banner-slider-btn a.asterthemes-button{
			background-color: {$lawyer_consultant_firm_btn_bg_color};
		}";
	}
    wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css);

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


// Topbar Padding Dynamic CSS
function lawyer_consultant_firm_topbar_padding_css(){
	$padding = get_theme_mod('lawyer_consultant_firm_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('lawyer-consultant-firm-style',$custom_css);

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

// WooCommerce Product Border Radius
function lawyer_consultant_firm_woocommerce_border_radius_css() {
	$lawyer_consultant_firm_radius = get_theme_mod('lawyer_consultant_firm_woocommerce_product_border_radius', 3);
    $lawyer_consultant_firm_custom_css = "
		.woocommerce ul.products li.product {
			border-radius: {$lawyer_consultant_firm_radius}px;
			overflow: hidden;
		}
	";
    wp_add_inline_style('lawyer-consultant-firm-style', $lawyer_consultant_firm_custom_css);
}
add_action('wp_enqueue_scripts', 'lawyer_consultant_firm_woocommerce_border_radius_css');
