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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function technology_software_firm_customizer_css_inline() {
	$technology_software_firm_custom_css = '';
	$technology_software_firm_enable_breadcrumb = get_theme_mod( 'technology_software_firm_enable_breadcrumb', true );

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

	if ( ! empty( $technology_software_firm_custom_css ) ) {
		wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_customizer_css_inline' );

//Global Color
function technology_software_firm_customize_css() {
	$technology_software_firm_primary_color = get_theme_mod( 'technology_software_firm_primary_color', '#6DE1F8' );
	$technology_software_firm_custom_css = ":root { --primary-color: {$technology_software_firm_primary_color}; }";

    $technology_software_firm_secondary_color = get_theme_mod( 'technology_software_firm_secondary_color', '#01002A' );
	$technology_software_firm_custom_css = ":root { --secondary-color: {$technology_software_firm_secondary_color}; }";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_customize_css' );

//Google Fonts
function technology_software_firm_enqueue_selected_fonts() {
    $technology_software_firm_fonts_url = technology_software_firm_get_fonts_url();
    if (!empty($technology_software_firm_fonts_url)) {
        wp_enqueue_style('technology-software-firm-google-fonts', $technology_software_firm_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'technology_software_firm_enqueue_selected_fonts');

//Set Width
function technology_software_firm_layout_customizer_css() {
	$technology_software_firm_margin = get_theme_mod( 'technology_software_firm_layout_width_margin', 50 );
	$technology_software_firm_custom_css = "body.site-boxed--layout #page { margin: 0 {$technology_software_firm_margin}px; }";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_layout_customizer_css', 20 );

//Blog Content Alignment
function technology_software_firm_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$technology_software_firm_layout_option = get_theme_mod( 'technology_software_firm_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_blog_layout_customizer_css' );

//Sidebar Width Setting
function technology_software_firm_sidebar_width_customizer_css() {
	$technology_software_firm_sidebar_width = get_theme_mod( 'technology_software_firm_sidebar_width', '30' );

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

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_sidebar_width_customizer_css' );


if ( ! function_exists( 'technology_software_firm_get_page_title' ) ) {
    function technology_software_firm_get_page_title() {
        $technology_software_firm_title = '';

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

        return apply_filters('technology_software_firm_page_title', $technology_software_firm_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('technology_software_firm_display_page_header', $technology_software_firm_return);
    }
}

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

//Page Title Options
function technology_software_firm_page_title_customizer_css() {
	$technology_software_firm_layout_option = get_theme_mod( 'technology_software_firm_page_header_layout', 'left' );
	$technology_software_firm_custom_css = '';

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

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_page_title_customizer_css' );

//Set Height
function technology_software_firm_pagetitle_height_css() {
	$technology_software_firm_height = get_theme_mod( 'technology_software_firm_pagetitle_height', 50 );

	$technology_software_firm_custom_css = "
		header.page-header {
			padding: {$technology_software_firm_height}px 0;
		}
	";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_pagetitle_height_css' );

//Adjust Site Logo Width
function technology_software_firm_site_logo_width() {
	$technology_software_firm_logo_width = get_theme_mod( 'technology_software_firm_site_logo_width' );

	$technology_software_firm_custom_css = "
		.site-logo img {
			max-width: {$technology_software_firm_logo_width}px;
		}
	";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_site_logo_width' );

//Menu Font Size
function technology_software_firm_menu_font_size_css() {
	$technology_software_firm_font_size = get_theme_mod( 'technology_software_firm_menu_font_size', 14 );

	$technology_software_firm_custom_css = "
		.main-navigation a {
			font-size: {$technology_software_firm_font_size}px;
		}
	";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_menu_font_size_css' );

//Menu Font Weight
function technology_software_firm_menu_font_weight_css() {
	$technology_software_firm_font_weight = get_theme_mod( 'technology_software_firm_menu_font_weight', 400 );

	$technology_software_firm_custom_css = "
		.main-navigation a {
		    font-weight: {$technology_software_firm_font_weight};
		}
	";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_menu_font_weight_css' );

//Menu text transform
function technology_software_firm_menu_text_transform_css() {
	$technology_software_firm_text_transform = get_theme_mod( 'technology_software_firm_menu_text_transform', 'capitalize' );

	$technology_software_firm_custom_css = "
		.main-navigation a {
			text-transform: {$technology_software_firm_text_transform} !important;
		}
	";

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_menu_text_transform_css' );

// Featured Image Dimension
function technology_software_firm_custom_featured_image_css() {
    $technology_software_firm_dimension = get_theme_mod('technology_software_firm_blog_post_featured_image_dimension', 'default');
    $technology_software_firm_width = get_theme_mod('technology_software_firm_blog_post_featured_image_custom_width', '');
    $technology_software_firm_height = get_theme_mod('technology_software_firm_blog_post_featured_image_custom_height', '');
    
    if ($technology_software_firm_dimension === 'custom' && $technology_software_firm_width && $technology_software_firm_height) {
        $technology_software_firm_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$technology_software_firm_width}px !important; height: {$technology_software_firm_height}px !important; }";
        wp_add_inline_style('technology-software-firm-style', $technology_software_firm_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'technology_software_firm_custom_featured_image_css');

// Featured Image Border Radius
function technology_software_firm_featured_image_border_radius_css() {
	$technology_software_firm_radius = get_theme_mod( 'technology_software_firm_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_featured_image_border_radius_css' );

//Heading Font Size
function technology_software_firm_sidebar_widget_font_size_css() {
	$technology_software_firm_sidebar_widget_font_size = get_theme_mod( 'technology_software_firm_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_sidebar_widget_font_size_css' );

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

    if ( ! $technology_software_firm_related_product_show_hide ) {
        $technology_software_firm_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'technology-software-firm-style', $technology_software_firm_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'technology_software_firm_related_product_css' );

// Product Sale Badge Position
function technology_software_firm_product_sale_position_customizer_css() {
    $technology_software_firm_position = get_theme_mod('technology_software_firm_product_sale_position', 'left');
    $technology_software_firm_css = '.woocommerce ul.products li.product .onsale {';
    if ($technology_software_firm_position === 'left') {
        $technology_software_firm_css .= 'right: auto; left: 0px;';
    } else {
        $technology_software_firm_css .= 'left: auto; right: 0px;';
    }
    $technology_software_firm_css .= '}';
    wp_add_inline_style('technology-software-firm-style', $technology_software_firm_css);
}
add_action('wp_enqueue_scripts', 'technology_software_firm_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function technology_software_firm_footer_copyright_alignment_css() {
    $technology_software_firm_align = get_theme_mod('technology_software_firm_footer_bottom_align', 'center');
    $technology_software_firm_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$technology_software_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('technology-software-firm-style', $technology_software_firm_css);
}
add_action('wp_enqueue_scripts', 'technology_software_firm_footer_copyright_alignment_css');

// Footer Copyright Font Size
function technology_software_firm_copyright_font_size_css() {
    $technology_software_firm_font_size = get_theme_mod('technology_software_firm_copyright_font_size', 16);
    $technology_software_firm_css = ".site-footer-bottom .site-info span {
        font-size: {$technology_software_firm_font_size}px;
    }";
    wp_add_inline_style('technology-software-firm-style', $technology_software_firm_css);
}
add_action('wp_enqueue_scripts', 'technology_software_firm_copyright_font_size_css');

// Preloader Background Color
function technology_software_firm_preloader_background_colors_css() {
    $technology_software_firm_color = get_theme_mod('technology_software_firm_preloader_background_color_setting', '');
    if (!empty($technology_software_firm_color)) {
        $technology_software_firm_css = "#loader {
            background-color: {$technology_software_firm_color};
        }";
        wp_add_inline_style('technology-software-firm-style', $technology_software_firm_css);
    }
}
add_action('wp_enqueue_scripts', 'technology_software_firm_preloader_background_colors_css');

// Preloader Background Image
function technology_software_firm_preloader_background_image_css() {
    $technology_software_firm_image_url = get_theme_mod('technology_software_firm_preloader_background_image_setting', '');
    if (!empty($technology_software_firm_image_url)) {
        $technology_software_firm_css = "#loader {
            background-image: url('{$technology_software_firm_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('technology-software-firm-style', $technology_software_firm_css);
    }
}
add_action('wp_enqueue_scripts', 'technology_software_firm_preloader_background_image_css');

// Footer Heading Alignment
function technology_software_firm_footer_heading_alignment_css() {
    $technology_software_firm_align = get_theme_mod('technology_software_firm_footer_header_align', 'left');
    $technology_software_firm_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$technology_software_firm_align};
        }
    ";
    wp_add_inline_style('technology-software-firm-style', $technology_software_firm_css);
}
add_action('wp_enqueue_scripts', 'technology_software_firm_footer_heading_alignment_css');

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

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

// Banner Button Color
function technology_software_firm_banner_button_color_css() {
    $btn_color                    = get_theme_mod( 'technology_software_firm_banner_btn_color' );
    $btn_bg_color                 = get_theme_mod( 'technology_software_firm_banner_btn_bg_color' );
    $btn_border_color             = get_theme_mod( 'technology_software_firm_banner_btn_border_color' );
    $secondary_btn_color          = get_theme_mod( 'technology_software_firm_banner_secondary_btn_color' );
    $secondary_btn_bg_color       = get_theme_mod( 'technology_software_firm_banner_secondary_btn_bg_color' );
    $secondary_btn_border_color   = get_theme_mod( 'technology_software_firm_banner_secondary_btn_border_color' );

    $custom_css = '';

    if ( ! empty( $btn_color ) ) {
        $custom_css .= "
        #technology_software_firm_banner_section .sale-banner__button--primary,
        #technology_software_firm_banner_section .sale-banner__button--primary i {
            color: {$btn_color};
        }";
    }

    if ( ! empty( $btn_bg_color ) ) {
        $custom_css .= "
        #technology_software_firm_banner_section .sale-banner__button--primary {
            background: {$btn_bg_color};
        }";
    }

    if ( ! empty( $btn_border_color ) ) {
        $custom_css .= "
        #technology_software_firm_banner_section .sale-banner__button--primary {
            border-color: {$btn_border_color};
        }";
    }

    if ( ! empty( $secondary_btn_color ) ) {
        $custom_css .= "
        #technology_software_firm_banner_section .sale-banner__button--secondary,
        #technology_software_firm_banner_section .sale-banner__button--secondary i {
            color: {$secondary_btn_color};
        }";
    }

    if ( ! empty( $secondary_btn_bg_color ) ) {
        $custom_css .= "
        #technology_software_firm_banner_section .sale-banner__button--secondary {
            background: {$secondary_btn_bg_color};
        }";
    }

    if ( ! empty( $secondary_btn_border_color ) ) {
        $custom_css .= "
        #technology_software_firm_banner_section .sale-banner__button--secondary {
            border-color: {$secondary_btn_border_color};
        }";
    }

    if ( ! empty( $custom_css ) ) {
        wp_add_inline_style( 'technology-software-firm-style', $custom_css );
    }
}
add_action('wp_enqueue_scripts','technology_software_firm_banner_button_color_css');
