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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function clothing_marketplace_customizer_css_inline() {
	$clothing_marketplace_custom_css = '';
	$clothing_marketplace_enable_breadcrumb = get_theme_mod( 'clothing_marketplace_enable_breadcrumb', true );

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

	if ( ! empty( $clothing_marketplace_custom_css ) ) {
		wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_customizer_css_inline' );

//Global Color
function clothing_marketplace_customize_css() {
	$clothing_marketplace_primary_color = get_theme_mod( 'clothing_marketplace_primary_color', '#5F222A' );
	$clothing_marketplace_custom_css = ":root { --primary-color: {$clothing_marketplace_primary_color}; }";

    $clothing_marketplace_secondary_color = get_theme_mod( 'clothing_marketplace_secondary_color', '#FD6564' );
	$clothing_marketplace_custom_css = ":root { --secondary-color: {$clothing_marketplace_secondary_color}; }";

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_customize_css' );

//Google Fonts
function clothing_marketplace_enqueue_selected_fonts() {
    $clothing_marketplace_fonts_url = clothing_marketplace_get_fonts_url();
    if (!empty($clothing_marketplace_fonts_url)) {
        wp_enqueue_style('clothing-marketplace-google-fonts', $clothing_marketplace_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_enqueue_selected_fonts');

//Set Width
function clothing_marketplace_layout_customizer_css() {
	$clothing_marketplace_margin = get_theme_mod( 'clothing_marketplace_layout_width_margin', 50 );
	$clothing_marketplace_custom_css = "body.site-boxed--layout #page { margin: 0 {$clothing_marketplace_margin}px; }";

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_layout_customizer_css', 20 );

//Blog Content Alignment
function clothing_marketplace_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$clothing_marketplace_layout_option = get_theme_mod( 'clothing_marketplace_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_blog_layout_customizer_css' );

//Sidebar Width Setting
function clothing_marketplace_sidebar_width_customizer_css() {
	$clothing_marketplace_sidebar_width = get_theme_mod( 'clothing_marketplace_sidebar_width', '30' );

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

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_sidebar_width_customizer_css' );


if ( ! function_exists( 'clothing_marketplace_get_page_title' ) ) {
    function clothing_marketplace_get_page_title() {
        $clothing_marketplace_title = '';

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

        return apply_filters('clothing_marketplace_page_title', $clothing_marketplace_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('clothing_marketplace_display_page_header', $clothing_marketplace_return);
    }
}

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

//Page Title Options
function clothing_marketplace_page_title_customizer_css() {
	$clothing_marketplace_layout_option = get_theme_mod( 'clothing_marketplace_page_header_layout', 'left' );
	$clothing_marketplace_custom_css = '';

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

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_page_title_customizer_css' );

//Set Height
function clothing_marketplace_pagetitle_height_css() {
	$clothing_marketplace_height = get_theme_mod( 'clothing_marketplace_pagetitle_height', 50 );

	$clothing_marketplace_custom_css = "
		header.page-header {
			padding: {$clothing_marketplace_height}px 0;
		}
	";

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_pagetitle_height_css' );

//Adjust Site Logo Width
function clothing_marketplace_site_logo_width() {
	$clothing_marketplace_logo_width = get_theme_mod( 'clothing_marketplace_site_logo_width' );

	$clothing_marketplace_custom_css = "
		.site-logo img {
			max-width: {$clothing_marketplace_logo_width}px;
		}
	";

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_site_logo_width' );

//Menu Font Size
function clothing_marketplace_menu_font_size_css() {
	$clothing_marketplace_font_size = get_theme_mod( 'clothing_marketplace_menu_font_size', 15 );

	$clothing_marketplace_custom_css = "
		.main-navigation a {
			font-size: {$clothing_marketplace_font_size}px;
		}
	";

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_menu_font_size_css' );

//Menu Font Weight
function clothing_marketplace_menu_font_weight_css() {
	$clothing_marketplace_font_weight = get_theme_mod( 'clothing_marketplace_menu_font_weight', 400 );

	$clothing_marketplace_custom_css = "
		.main-navigation a {
		    font-weight: {$clothing_marketplace_font_weight};
		}
	";

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_menu_font_weight_css' );

//Menu text transform
function clothing_marketplace_menu_text_transform_css() {
	$clothing_marketplace_text_transform = get_theme_mod( 'clothing_marketplace_menu_text_transform', 'uppercase' );

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

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_menu_text_transform_css' );

// Featured Image Dimension
function clothing_marketplace_custom_featured_image_css() {
    $clothing_marketplace_dimension = get_theme_mod('clothing_marketplace_blog_post_featured_image_dimension', 'default');
    $clothing_marketplace_width = get_theme_mod('clothing_marketplace_blog_post_featured_image_custom_width', '');
    $clothing_marketplace_height = get_theme_mod('clothing_marketplace_blog_post_featured_image_custom_height', '');
    
    if ($clothing_marketplace_dimension === 'custom' && $clothing_marketplace_width && $clothing_marketplace_height) {
        $clothing_marketplace_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$clothing_marketplace_width}px !important; height: {$clothing_marketplace_height}px !important; }";
        wp_add_inline_style('clothing-marketplace-style', $clothing_marketplace_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_custom_featured_image_css');

// Featured Image Border Radius
function clothing_marketplace_featured_image_border_radius_css() {
	$clothing_marketplace_radius = get_theme_mod( 'clothing_marketplace_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_featured_image_border_radius_css' );

//Heading Font Size
function clothing_marketplace_sidebar_widget_font_size_css() {
	$clothing_marketplace_sidebar_widget_font_size = get_theme_mod( 'clothing_marketplace_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_sidebar_widget_font_size_css' );

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

    if ( ! $clothing_marketplace_related_product_show_hide ) {
        $clothing_marketplace_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_related_product_css' );

// Product Sale Badge Position
function clothing_marketplace_product_sale_position_customizer_css() {
    $clothing_marketplace_position = get_theme_mod('clothing_marketplace_product_sale_position', 'left');
    $clothing_marketplace_css = '.woocommerce ul.products li.product .onsale {';
    if ($clothing_marketplace_position === 'left') {
        $clothing_marketplace_css .= 'right: auto; left: 0px;';
    } else {
        $clothing_marketplace_css .= 'left: auto; right: 0px;';
    }
    $clothing_marketplace_css .= '}';
    wp_add_inline_style('clothing-marketplace-style', $clothing_marketplace_css);
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function clothing_marketplace_footer_copyright_alignment_css() {
    $clothing_marketplace_align = get_theme_mod('clothing_marketplace_footer_bottom_align', 'center');
    $clothing_marketplace_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$clothing_marketplace_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('clothing-marketplace-style', $clothing_marketplace_css);
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_footer_copyright_alignment_css');

// Footer Copyright Font Size
function clothing_marketplace_copyright_font_size_css() {
    $clothing_marketplace_font_size = get_theme_mod('clothing_marketplace_copyright_font_size', 16);
    $clothing_marketplace_css = ".site-footer-bottom .site-info span {
        font-size: {$clothing_marketplace_font_size}px;
    }";
    wp_add_inline_style('clothing-marketplace-style', $clothing_marketplace_css);
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_copyright_font_size_css');

// Preloader Background Color
function clothing_marketplace_preloader_background_colors_css() {
    $clothing_marketplace_color = get_theme_mod('clothing_marketplace_preloader_background_color_setting', '');
    if (!empty($clothing_marketplace_color)) {
        $clothing_marketplace_css = "#loader {
            background-color: {$clothing_marketplace_color};
        }";
        wp_add_inline_style('clothing-marketplace-style', $clothing_marketplace_css);
    }
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_preloader_background_colors_css');

// Preloader Background Image
function clothing_marketplace_preloader_background_image_css() {
    $clothing_marketplace_image_url = get_theme_mod('clothing_marketplace_preloader_background_image_setting', '');
    if (!empty($clothing_marketplace_image_url)) {
        $clothing_marketplace_css = "#loader {
            background-image: url('{$clothing_marketplace_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('clothing-marketplace-style', $clothing_marketplace_css);
    }
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_preloader_background_image_css');

// Footer Heading Alignment
function clothing_marketplace_footer_heading_alignment_css() {
    $clothing_marketplace_align = get_theme_mod('clothing_marketplace_footer_header_align', 'left');
    $clothing_marketplace_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$clothing_marketplace_align};
        }
    ";
    wp_add_inline_style('clothing-marketplace-style', $clothing_marketplace_css);
}
add_action('wp_enqueue_scripts', 'clothing_marketplace_footer_heading_alignment_css');


function clothing_marketplace_banner_dynamic_css() {

    $clothing_marketplace_banner_bg = get_theme_mod(
        'clothing_marketplace_banner_background_image'
    );

    if ( empty( $clothing_marketplace_banner_bg ) ) {
        $clothing_marketplace_banner_bg = get_template_directory_uri() . '/resource/img/background.png';
    }

    $clothing_marketplace_css = "
    .fashion-banner {
        background-image: url('{$clothing_marketplace_banner_bg}');
    }";

    wp_add_inline_style( 'clothing-marketplace-style', $clothing_marketplace_css );
}
add_action( 'wp_enqueue_scripts', 'clothing_marketplace_banner_dynamic_css' );

// Topbar Padding Dynamic CSS
function clothing_marketplace_topbar_padding_css(){
	$padding = get_theme_mod('clothing_marketplace_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('clothing-marketplace-style',$custom_css);

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

// Banner Button Color
function clothing_marketplace_banner_button_color_css() {
    $btn_color = get_theme_mod('clothing_marketplace_banner_btn_color');
    $btn_bg_color = get_theme_mod('clothing_marketplace_banner_btn_bg_color');
    $btn_border_color = get_theme_mod('clothing_marketplace_banner_btn_border_color');

    $custom_css = '';
    if ( !empty($btn_color) ) {
        $custom_css .= "
        .banner-slider-btn a.asterthemes-button,
        .banner-slider-btn-1 a.asterthemes-button,
        .banner-slider-btn a.asterthemes-button i,
        .banner-slider-btn-1 a.asterthemes-button i{
            color: {$btn_color};
        }";
    }

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

    wp_add_inline_style('clothing-marketplace-style', $custom_css);
}
add_action('wp_enqueue_scripts','clothing_marketplace_banner_button_color_css');
