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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function jewelry_accessories_customizer_css_inline() {
	$jewelry_accessories_custom_css = '';
	$jewelry_accessories_enable_breadcrumb = get_theme_mod( 'jewelry_accessories_enable_breadcrumb', true );

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

	if ( ! empty( $jewelry_accessories_custom_css ) ) {
		wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_customizer_css_inline' );

//Global Color
function jewelry_accessories_customize_css() {
	$jewelry_accessories_primary_color = get_theme_mod( 'jewelry_accessories_primary_color', '#BC913E' );
    $jewelry_accessories_secondary_color = get_theme_mod( 'jewelry_accessories_secondary_color', '#657150' );
	$jewelry_accessories_custom_css = ":root { --primary-color: {$jewelry_accessories_primary_color}; }";
    $jewelry_accessories_custom_css = ":root { --secondary_color: {$jewelry_accessories_secondary_color}; }";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_customize_css' );

//Google Fonts
function jewelry_accessories_enqueue_selected_fonts() {
    $jewelry_accessories_fonts_url = jewelry_accessories_get_fonts_url();
    if (!empty($jewelry_accessories_fonts_url)) {
        wp_enqueue_style('jewelry-accessories-google-fonts', $jewelry_accessories_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_enqueue_selected_fonts');

//Set Width
function jewelry_accessories_layout_customizer_css() {
	$jewelry_accessories_margin = get_theme_mod( 'jewelry_accessories_layout_width_margin', 50 );
	$jewelry_accessories_custom_css = "body.site-boxed--layout #page { margin: 0 {$jewelry_accessories_margin}px; }";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_layout_customizer_css', 20 );

//Blog Content Alignment
function jewelry_accessories_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$jewelry_accessories_layout_option = get_theme_mod( 'jewelry_accessories_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_blog_layout_customizer_css' );

//Sidebar Width Setting
function jewelry_accessories_sidebar_width_customizer_css() {
	$jewelry_accessories_sidebar_width = get_theme_mod( 'jewelry_accessories_sidebar_width', '30' );

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

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_sidebar_width_customizer_css' );


if ( ! function_exists( 'jewelry_accessories_get_page_title' ) ) {
    function jewelry_accessories_get_page_title() {
        $jewelry_accessories_title = '';

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

        return apply_filters('jewelry_accessories_page_title', $jewelry_accessories_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('jewelry_accessories_display_page_header', $jewelry_accessories_return);
    }
}

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

//Page Title Options
function jewelry_accessories_page_title_customizer_css() {
	$jewelry_accessories_layout_option = get_theme_mod( 'jewelry_accessories_page_header_layout', 'left' );
	$jewelry_accessories_custom_css = '';

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

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_page_title_customizer_css' );

//Set Height
function jewelry_accessories_pagetitle_height_css() {
	$jewelry_accessories_height = get_theme_mod( 'jewelry_accessories_pagetitle_height', 50 );

	$jewelry_accessories_custom_css = "
		header.page-header {
			padding: {$jewelry_accessories_height}px 0;
		}
	";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_pagetitle_height_css' );

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

	$jewelry_accessories_custom_css = "
		.site-logo img {
			max-width: {$jewelry_accessories_logo_width}px;
		}
	";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_site_logo_width' );

//Menu Font Size
function jewelry_accessories_menu_font_size_css() {
	$jewelry_accessories_font_size = get_theme_mod( 'jewelry_accessories_menu_font_size', 14 );

	$jewelry_accessories_custom_css = "
		.main-navigation a {
			font-size: {$jewelry_accessories_font_size}px;
		}
	";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_menu_font_size_css' );

//Menu Font Weight
function jewelry_accessories_menu_font_weight_css() {
	$jewelry_accessories_font_weight = get_theme_mod( 'jewelry_accessories_menu_font_weight', 400 );

	$jewelry_accessories_custom_css = "
		.main-navigation a {
		    font-weight: {$jewelry_accessories_font_weight};
		}
	";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_menu_font_weight_css' );

//Menu text transform
function jewelry_accessories_menu_text_transform_css() {
	$jewelry_accessories_text_transform = get_theme_mod( 'jewelry_accessories_menu_text_transform', 'capitalize' );

	$jewelry_accessories_custom_css = "
		.main-navigation a {
			text-transform: {$jewelry_accessories_text_transform};
		}
	";

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_menu_text_transform_css' );

// Featured Image Dimension
function jewelry_accessories_custom_featured_image_css() {
    $jewelry_accessories_dimension = get_theme_mod('jewelry_accessories_blog_post_featured_image_dimension', 'default');
    $jewelry_accessories_width = get_theme_mod('jewelry_accessories_blog_post_featured_image_custom_width', '');
    $jewelry_accessories_height = get_theme_mod('jewelry_accessories_blog_post_featured_image_custom_height', '');
    
    if ($jewelry_accessories_dimension === 'custom' && $jewelry_accessories_width && $jewelry_accessories_height) {
        $jewelry_accessories_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$jewelry_accessories_width}px !important; height: {$jewelry_accessories_height}px !important; }";
        wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_custom_featured_image_css');

// Featured Image Border Radius
function jewelry_accessories_featured_image_border_radius_css() {
	$jewelry_accessories_radius = get_theme_mod( 'jewelry_accessories_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_featured_image_border_radius_css' );

//Heading Font Size
function jewelry_accessories_sidebar_widget_font_size_css() {
	$jewelry_accessories_sidebar_widget_font_size = get_theme_mod( 'jewelry_accessories_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_sidebar_widget_font_size_css' );

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

    if ( ! $jewelry_accessories_related_product_show_hide ) {
        $jewelry_accessories_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_related_product_css' );

// Product Sale Badge Position
function jewelry_accessories_product_sale_position_customizer_css() {
    $jewelry_accessories_position = get_theme_mod('jewelry_accessories_product_sale_position', 'left');
    $jewelry_accessories_css = '.woocommerce ul.products li.product .onsale {';
    if ($jewelry_accessories_position === 'left') {
        $jewelry_accessories_css .= 'right: auto; left: 0px;';
    } else {
        $jewelry_accessories_css .= 'left: auto; right: 0px;';
    }
    $jewelry_accessories_css .= '}';
    wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_css);
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function jewelry_accessories_footer_copyright_alignment_css() {
    $jewelry_accessories_align = get_theme_mod('jewelry_accessories_footer_bottom_align', 'center');
    $jewelry_accessories_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$jewelry_accessories_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('jewelry-accessories-style', $jewelry_accessories_css);
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_footer_copyright_alignment_css');

// Footer Copyright Font Size
function jewelry_accessories_copyright_font_size_css() {
    $jewelry_accessories_font_size = get_theme_mod('jewelry_accessories_copyright_font_size', 16);
    $jewelry_accessories_css = ".site-footer-bottom .site-info span {
        font-size: {$jewelry_accessories_font_size}px;
    }";
    wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_css);
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_copyright_font_size_css');

// Preloader Background Color
function jewelry_accessories_preloader_background_colors_css() {
    $jewelry_accessories_color = get_theme_mod('jewelry_accessories_preloader_background_color_setting', '');
    if (!empty($jewelry_accessories_color)) {
        $jewelry_accessories_css = "#loader {
            background-color: {$jewelry_accessories_color};
        }";
        wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_css);
    }
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_preloader_background_colors_css');

// Preloader Background Image
function jewelry_accessories_preloader_background_image_css() {
    $jewelry_accessories_image_url = get_theme_mod('jewelry_accessories_preloader_background_image_setting', '');
    if (!empty($jewelry_accessories_image_url)) {
        $jewelry_accessories_css = "#loader {
            background-image: url('{$jewelry_accessories_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_css);
    }
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_preloader_background_image_css');

// Footer Heading Alignment
function jewelry_accessories_footer_heading_alignment_css() {
    $jewelry_accessories_align = get_theme_mod('jewelry_accessories_footer_header_align', 'left');
    $jewelry_accessories_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$jewelry_accessories_align};
        }
    ";
    wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_css);
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_footer_heading_alignment_css');

//First Capital Letter
function jewelry_accessories_show_first_caps() {
	$jewelry_accessories_first_caps = get_theme_mod('jewelry_accessories_show_first_caps', false);
	$jewelry_accessories_css = '';
	if ( $jewelry_accessories_first_caps ) {
	$jewelry_accessories_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 {
		$jewelry_accessories_css .= '
		.mag-post-single .mag-post-detail .mag-post-excerpt p:first-of-type::first-letter {
			display: none;
		}';
	}
	wp_add_inline_style( 'jewelry-accessories-style', $jewelry_accessories_css );
}
add_action( 'wp_enqueue_scripts', 'jewelry_accessories_show_first_caps' );

// Topbar Padding Dynamic CSS
function jewelry_accessories_topbar_padding_css(){
	$padding = get_theme_mod('jewelry_accessories_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('jewelry-accessories-style',$custom_css);

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

// Banner Button Color
function jewelry_accessories_banner_button_color_css() {
    $btn_color = get_theme_mod('jewelry_accessories_banner_btn_color');
	$btn_bg_color = get_theme_mod('jewelry_accessories_banner_btn_bg_color');

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

	if ( !empty($btn_bg_color) ) {
		$custom_css .= "
		.banner-single .banner-btn a.asterthemes-button{
			background-color: {$btn_bg_color};
		}";
	}

	wp_add_inline_style('jewelry-accessories-style', $custom_css);
}
add_action('wp_enqueue_scripts','jewelry_accessories_banner_button_color_css');

// WooCommerce Product Border Radius
function jewelry_accessories_woocommerce_border_radius_css() {
	$jewelry_accessories_radius = get_theme_mod('jewelry_accessories_woocommerce_product_border_radius', 3);
    $jewelry_accessories_custom_css = "
		.woocommerce ul.products li.product {
			border-radius: {$jewelry_accessories_radius}px;
			overflow: hidden;
		}
	";
    wp_add_inline_style('jewelry-accessories-style', $jewelry_accessories_custom_css);
}
add_action('wp_enqueue_scripts', 'jewelry_accessories_woocommerce_border_radius_css');