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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function jeweler_shop_customizer_css_inline() {
	$jeweler_shop_custom_css = '';
	$jeweler_shop_enable_breadcrumb = get_theme_mod( 'jeweler_shop_enable_breadcrumb', true );

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

	if ( ! empty( $jeweler_shop_custom_css ) ) {
		wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_customizer_css_inline' );

//
function jeweler_shop_custom_css() {
    $jeweler_shop_slider = get_theme_mod('jeweler_shop_enable_slider_section', false);
    ?>
    <style type="text/css">
        .home .bottom-header-outer-wrapper {
            z-index: 99;
            width: 100%;
            <?php if ( $jeweler_shop_slider ) : ?>
                background: transparent;
                position: absolute;
            <?php else : ?>
                background: var(--secondary-color);
                position: static;  
                padding: 10px 0;     
            <?php endif; ?>
        }
    </style>
    <?php
}
add_action( 'wp_head', 'jeweler_shop_custom_css' );

//Global Color
function jeweler_shop_customize_css() {
	$jeweler_shop_primary_color = get_theme_mod( 'jeweler_shop_primary_color', '#314B4C' );
	$jeweler_shop_custom_css = ":root { --primary-color: {$jeweler_shop_primary_color}; }";

	$jeweler_shop_secondary_color = get_theme_mod( 'jeweler_shop_secondary_color', '#F1C1BD' );
	$jeweler_shop_custom_css = ":root { --secondary-color: {$jeweler_shop_secondary_color}; }";

    $jeweler_shop_tertiary_color = get_theme_mod( 'jeweler_shop_tertiary_color', '#182C2B' );
	$jeweler_shop_custom_css = ":root { --tertiary-color: {$jeweler_shop_tertiary_color}; }";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_customize_css' );

//Google Fonts
function jeweler_shop_enqueue_selected_fonts() {
    $jeweler_shop_fonts_url = jeweler_shop_get_fonts_url();
    if (!empty($jeweler_shop_fonts_url)) {
        wp_enqueue_style('jeweler-shop-google-fonts', $jeweler_shop_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'jeweler_shop_enqueue_selected_fonts');

//Set Width
function jeweler_shop_layout_customizer_css() {
	$jeweler_shop_margin = get_theme_mod( 'jeweler_shop_layout_width_margin', 50 );
	$jeweler_shop_custom_css = "body.site-boxed--layout #page { margin: 0 {$jeweler_shop_margin}px; }";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_layout_customizer_css', 20 );

//Blog Content Alignment
function jeweler_shop_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$jeweler_shop_layout_option = get_theme_mod( 'jeweler_shop_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_blog_layout_customizer_css' );

//Sidebar Width Setting
function jeweler_shop_sidebar_width_customizer_css() {
	$jeweler_shop_sidebar_width = get_theme_mod( 'jeweler_shop_sidebar_width', '30' );

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

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_sidebar_width_customizer_css' );


if ( ! function_exists( 'jeweler_shop_get_page_title' ) ) {
    function jeweler_shop_get_page_title() {
        $jeweler_shop_title = '';

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

        return apply_filters('jeweler_shop_page_title', $jeweler_shop_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('jeweler_shop_display_page_header', $jeweler_shop_return);
    }
}

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

//Page Title Options
function jeweler_shop_page_title_customizer_css() {
	$jeweler_shop_layout_option = get_theme_mod( 'jeweler_shop_page_header_layout', 'left' );
	$jeweler_shop_custom_css = '';

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

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_page_title_customizer_css' );

//Set Height
function jeweler_shop_pagetitle_height_css() {
	$jeweler_shop_height = get_theme_mod( 'jeweler_shop_pagetitle_height', 50 );

	$jeweler_shop_custom_css = "
		header.page-header {
			padding: {$jeweler_shop_height}px 0;
		}
	";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_pagetitle_height_css' );

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

	$jeweler_shop_custom_css = "
		.site-logo img {
			max-width: {$jeweler_shop_logo_width}px;
		}
	";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_site_logo_width' );

//Menu Font Size
function jeweler_shop_menu_font_size_css() {
	$jeweler_shop_font_size = get_theme_mod( 'jeweler_shop_menu_font_size', 13 );

	$jeweler_shop_custom_css = "
		.main-navigation a {
			font-size: {$jeweler_shop_font_size}px;
		}
	";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_menu_font_size_css' );

//Menu Font Weight
function jeweler_shop_menu_font_weight_css() {
	$jeweler_shop_font_weight = get_theme_mod( 'jeweler_shop_menu_font_weight', 500 );

	$jeweler_shop_custom_css = "
		.main-navigation a {
		    font-weight: {$jeweler_shop_font_weight};
		}
	";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_menu_font_weight_css' );

//Menu text transform
function jeweler_shop_menu_text_transform_css() {
	$jeweler_shop_text_transform = get_theme_mod( 'jeweler_shop_menu_text_transform', 'capitalize' );

	$jeweler_shop_custom_css = "
		.main-navigation a {
			text-transform: {$jeweler_shop_text_transform};
		}
	";

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_menu_text_transform_css' );

// Featured Image Dimension
function jeweler_shop_custom_featured_image_css() {
    $jeweler_shop_dimension = get_theme_mod('jeweler_shop_blog_post_featured_image_dimension', 'default');
    $jeweler_shop_width = get_theme_mod('jeweler_shop_blog_post_featured_image_custom_width', '');
    $jeweler_shop_height = get_theme_mod('jeweler_shop_blog_post_featured_image_custom_height', '');
    
    if ($jeweler_shop_dimension === 'custom' && $jeweler_shop_width && $jeweler_shop_height) {
        $jeweler_shop_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$jeweler_shop_width}px !important; height: {$jeweler_shop_height}px !important; }";
        wp_add_inline_style('jeweler-shop-style', $jeweler_shop_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'jeweler_shop_custom_featured_image_css');

// Featured Image Border Radius
function jeweler_shop_featured_image_border_radius_css() {
	$jeweler_shop_radius = get_theme_mod( 'jeweler_shop_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_featured_image_border_radius_css' );

//Heading Font Size
function jeweler_shop_sidebar_widget_font_size_css() {
	$jeweler_shop_sidebar_widget_font_size = get_theme_mod( 'jeweler_shop_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_sidebar_widget_font_size_css' );

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

    if ( ! $jeweler_shop_related_product_show_hide ) {
        $jeweler_shop_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_related_product_css' );

// Product Sale Badge Position
function jeweler_shop_product_sale_position_customizer_css() {
    $jeweler_shop_position = get_theme_mod('jeweler_shop_product_sale_position', 'left');
    $jeweler_shop_css = '.woocommerce ul.products li.product .onsale {';
    if ($jeweler_shop_position === 'left') {
        $jeweler_shop_css .= 'right: auto; left: 0px;';
    } else {
        $jeweler_shop_css .= 'left: auto; right: 0px;';
    }
    $jeweler_shop_css .= '}';
    wp_add_inline_style('jeweler-shop-style', $jeweler_shop_css);
}
add_action('wp_enqueue_scripts', 'jeweler_shop_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function jeweler_shop_footer_copyright_alignment_css() {
    $jeweler_shop_align = get_theme_mod('jeweler_shop_footer_bottom_align', 'center');
    $jeweler_shop_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$jeweler_shop_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('jeweler-shop-style', $jeweler_shop_css);
}
add_action('wp_enqueue_scripts', 'jeweler_shop_footer_copyright_alignment_css');

// Footer Copyright Font Size
function jeweler_shop_copyright_font_size_css() {
    $jeweler_shop_font_size = get_theme_mod('jeweler_shop_copyright_font_size', 16);
    $jeweler_shop_css = ".site-footer-bottom .site-info span {
        font-size: {$jeweler_shop_font_size}px;
    }";
    wp_add_inline_style('jeweler-shop-style', $jeweler_shop_css);
}
add_action('wp_enqueue_scripts', 'jeweler_shop_copyright_font_size_css');

// Preloader Background Color
function jeweler_shop_preloader_background_colors_css() {
    $jeweler_shop_color = get_theme_mod('jeweler_shop_preloader_background_color_setting', '');
    if (!empty($jeweler_shop_color)) {
        $jeweler_shop_css = "#loader {
            background-color: {$jeweler_shop_color};
        }";
        wp_add_inline_style('jeweler-shop-style', $jeweler_shop_css);
    }
}
add_action('wp_enqueue_scripts', 'jeweler_shop_preloader_background_colors_css');

// Preloader Background Image
function jeweler_shop_preloader_background_image_css() {
    $jeweler_shop_image_url = get_theme_mod('jeweler_shop_preloader_background_image_setting', '');
    if (!empty($jeweler_shop_image_url)) {
        $jeweler_shop_css = "#loader {
            background-image: url('{$jeweler_shop_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('jeweler-shop-style', $jeweler_shop_css);
    }
}
add_action('wp_enqueue_scripts', 'jeweler_shop_preloader_background_image_css');

// Footer Heading Alignment
function jeweler_shop_footer_heading_alignment_css() {
    $jeweler_shop_align = get_theme_mod('jeweler_shop_footer_header_align', 'left');
    $jeweler_shop_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$jeweler_shop_align};
        }
    ";
    wp_add_inline_style('jeweler-shop-style', $jeweler_shop_css);
}
add_action('wp_enqueue_scripts', 'jeweler_shop_footer_heading_alignment_css');

//First Capital Letter
function jeweler_shop_show_first_caps() {
	$jeweler_shop_first_caps = get_theme_mod('jeweler_shop_show_first_caps', false);
	$jeweler_shop_css = '';
	if ( $jeweler_shop_first_caps ) {
	$jeweler_shop_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 {
		$jeweler_shop_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'jeweler-shop-style', $jeweler_shop_css );
}
add_action( 'wp_enqueue_scripts', 'jeweler_shop_show_first_caps' );

// Slider Button Color
function jeweler_shop_slider_button_color_css() {
    $jeweler_shop_btn_color = get_theme_mod('jeweler_shop_slider_btn_color');
	$jeweler_shop_btn_bg_color = get_theme_mod('jeweler_shop_slider_btn_bg_color');

	$jeweler_shop_custom_css = '';

	if ( !empty($jeweler_shop_btn_color) ) {
		$jeweler_shop_custom_css .= "
		#jeweler_shop_slider_section .banner-slider-btn a.asterthemes-button{
			color: {$jeweler_shop_btn_color};
		}";
	}
    if ( !empty($jeweler_shop_btn_bg_color) ) {
		$jeweler_shop_custom_css .= "
		#jeweler_shop_slider_section .banner-slider-btn a.asterthemes-button{
			background-color: {$jeweler_shop_btn_bg_color};
		}";
	}
    wp_add_inline_style('jeweler-shop-style', $jeweler_shop_custom_css);

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


// Topbar Padding Dynamic CSS
function jeweler_shop_topbar_padding_css(){
	$padding = get_theme_mod('jeweler_shop_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('jeweler-shop-style',$custom_css);

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

// WooCommerce Product Border Radius
function jeweler_shop_woocommerce_border_radius_css() {
	$jeweler_shop_radius = get_theme_mod('jeweler_shop_woocommerce_product_border_radius', 3);
    $jeweler_shop_custom_css = "
		.woocommerce ul.products li.product {
			border-radius: {$jeweler_shop_radius}px;
			overflow: hidden;
		}
	";
    wp_add_inline_style('jeweler-shop-style', $jeweler_shop_custom_css);
}
add_action('wp_enqueue_scripts', 'jeweler_shop_woocommerce_border_radius_css');
