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


// Output inline CSS based on Customizer setting

// Breadcrumb - Enable Breadcrumb.
function events_and_celebrations_customizer_css_inline() {
	$events_and_celebrations_custom_css = '';
	$events_and_celebrations_enable_breadcrumb = get_theme_mod( 'events_and_celebrations_enable_breadcrumb', true );

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

	if ( ! empty( $events_and_celebrations_custom_css ) ) {
		wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_customizer_css_inline' );

//Global Color
function events_and_celebrations_customize_css() {
	$events_and_celebrations_primary_color = get_theme_mod( 'events_and_celebrations_primary_color', '#DB5A81' );
	$events_and_celebrations_custom_css = ":root { --primary-color: {$events_and_celebrations_primary_color}; }";

    $events_and_celebrations_secondary_color = get_theme_mod( 'events_and_celebrations_secondary_color', '#000000' );
	$events_and_celebrations_custom_css = ":root { --secondary-color: {$events_and_celebrations_secondary_color}; }";

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_customize_css' );

//Google Fonts
function events_and_celebrations_enqueue_selected_fonts() {
    $events_and_celebrations_fonts_url = events_and_celebrations_get_fonts_url();
    if (!empty($events_and_celebrations_fonts_url)) {
        wp_enqueue_style('events-and-celebrations-google-fonts', $events_and_celebrations_fonts_url, array(), null);
    }
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_enqueue_selected_fonts');

//Set Width
function events_and_celebrations_layout_customizer_css() {
	$events_and_celebrations_margin = get_theme_mod( 'events_and_celebrations_layout_width_margin', 50 );
	$events_and_celebrations_custom_css = "body.site-boxed--layout #page { margin: 0 {$events_and_celebrations_margin}px; }";

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_layout_customizer_css', 20 );

//Blog Content Alignment
function events_and_celebrations_blog_layout_customizer_css() {
	// Retrieve the blog layout option
	$events_and_celebrations_layout_option = get_theme_mod( 'events_and_celebrations_blog_layout_option_setting', 'Left' );

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

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

	// Attach CSS to theme style
	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_blog_layout_customizer_css' );

//Sidebar Width Setting
function events_and_celebrations_sidebar_width_customizer_css() {
	$events_and_celebrations_sidebar_width = get_theme_mod( 'events_and_celebrations_sidebar_width', '30' );

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

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_sidebar_width_customizer_css' );


if ( ! function_exists( 'events_and_celebrations_get_page_title' ) ) {
    function events_and_celebrations_get_page_title() {
        $events_and_celebrations_title = '';

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

        return apply_filters('events_and_celebrations_page_title', $events_and_celebrations_title);
    }
}

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

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

        // Apply filters and return
        return apply_filters('events_and_celebrations_display_page_header', $events_and_celebrations_return);
    }
}

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

//Page Title Options
function events_and_celebrations_page_title_customizer_css() {
	$events_and_celebrations_layout_option = get_theme_mod( 'events_and_celebrations_page_header_layout', 'left' );
	$events_and_celebrations_custom_css = '';

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

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_page_title_customizer_css' );

//Set Height
function events_and_celebrations_pagetitle_height_css() {
	$events_and_celebrations_height = get_theme_mod( 'events_and_celebrations_pagetitle_height', 50 );

	$events_and_celebrations_custom_css = "
		header.page-header {
			padding: {$events_and_celebrations_height}px 0;
		}
	";

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_pagetitle_height_css' );

//Adjust Site Logo Width
function events_and_celebrations_site_logo_width() {
	$events_and_celebrations_logo_width = get_theme_mod( 'events_and_celebrations_site_logo_width' );

	$events_and_celebrations_custom_css = "
		.site-logo img {
			max-width: {$events_and_celebrations_logo_width}px;
		}
	";

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_site_logo_width' );

//Menu Font Size
function events_and_celebrations_menu_font_size_css() {
	$events_and_celebrations_font_size = get_theme_mod( 'events_and_celebrations_menu_font_size', 16 );

	$events_and_celebrations_custom_css = "
		.main-navigation a {
			font-size: {$events_and_celebrations_font_size}px;
		}
	";

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_menu_font_size_css' );

//Menu Font Weight
function events_and_celebrations_menu_font_weight_css() {
	$events_and_celebrations_font_weight = get_theme_mod( 'events_and_celebrations_menu_font_weight', 400 );

	$events_and_celebrations_custom_css = "
		.main-navigation a {
		    font-weight: {$events_and_celebrations_font_weight};
		}
	";

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_menu_font_weight_css' );

//Menu text transform
function events_and_celebrations_menu_text_transform_css() {
	$events_and_celebrations_text_transform = get_theme_mod( 'events_and_celebrations_menu_text_transform', 'capitalize' );

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

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_menu_text_transform_css' );

// Featured Image Dimension
function events_and_celebrations_custom_featured_image_css() {
    $events_and_celebrations_dimension = get_theme_mod('events_and_celebrations_blog_post_featured_image_dimension', 'default');
    $events_and_celebrations_width = get_theme_mod('events_and_celebrations_blog_post_featured_image_custom_width', '');
    $events_and_celebrations_height = get_theme_mod('events_and_celebrations_blog_post_featured_image_custom_height', '');
    
    if ($events_and_celebrations_dimension === 'custom' && $events_and_celebrations_width && $events_and_celebrations_height) {
        $events_and_celebrations_custom_css = "body:not(.single-post) .mag-post-single .mag-post-img img { width: {$events_and_celebrations_width}px !important; height: {$events_and_celebrations_height}px !important; }";
        wp_add_inline_style('events-and-celebrations-style', $events_and_celebrations_custom_css);
    }
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_custom_featured_image_css');

// Featured Image Border Radius
function events_and_celebrations_featured_image_border_radius_css() {
	$events_and_celebrations_radius = get_theme_mod( 'events_and_celebrations_featured_image_border_radius', 10 );

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

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_featured_image_border_radius_css' );

//Heading Font Size
function events_and_celebrations_sidebar_widget_font_size_css() {
	$events_and_celebrations_sidebar_widget_font_size = get_theme_mod( 'events_and_celebrations_sidebar_widget_font_size', 24 );

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

	wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_sidebar_widget_font_size_css' );

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

    if ( ! $events_and_celebrations_related_product_show_hide ) {
        $events_and_celebrations_custom_css = '
            .related.products {
                display: none;
            }
        ';
        wp_add_inline_style( 'events-and-celebrations-style', $events_and_celebrations_custom_css );
    }
}
add_action( 'wp_enqueue_scripts', 'events_and_celebrations_related_product_css' );

// Product Sale Badge Position
function events_and_celebrations_product_sale_position_customizer_css() {
    $events_and_celebrations_position = get_theme_mod('events_and_celebrations_product_sale_position', 'left');
    $events_and_celebrations_css = '.woocommerce ul.products li.product .onsale {';
    if ($events_and_celebrations_position === 'left') {
        $events_and_celebrations_css .= 'right: auto; left: 0px;';
    } else {
        $events_and_celebrations_css .= 'left: auto; right: 0px;';
    }
    $events_and_celebrations_css .= '}';
    wp_add_inline_style('events-and-celebrations-style', $events_and_celebrations_css);
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_product_sale_position_customizer_css');

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

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

// Footer Copyright Alignment
function events_and_celebrations_footer_copyright_alignment_css() {
    $events_and_celebrations_align = get_theme_mod('events_and_celebrations_footer_bottom_align', 'center');
    $events_and_celebrations_css = "
        .site-footer .site-footer-bottom .site-footer-bottom-wrapper {
            justify-content: {$events_and_celebrations_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('events-and-celebrations-style', $events_and_celebrations_css);
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_footer_copyright_alignment_css');

// Footer Copyright Font Size
function events_and_celebrations_copyright_font_size_css() {
    $events_and_celebrations_font_size = get_theme_mod('events_and_celebrations_copyright_font_size', 16);
    $events_and_celebrations_css = ".site-footer-bottom .site-info span {
        font-size: {$events_and_celebrations_font_size}px;
    }";
    wp_add_inline_style('events-and-celebrations-style', $events_and_celebrations_css);
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_copyright_font_size_css');

// Preloader Background Color
function events_and_celebrations_preloader_background_colors_css() {
    $events_and_celebrations_color = get_theme_mod('events_and_celebrations_preloader_background_color_setting', '');
    if (!empty($events_and_celebrations_color)) {
        $events_and_celebrations_css = "#loader {
            background-color: {$events_and_celebrations_color};
        }";
        wp_add_inline_style('events-and-celebrations-style', $events_and_celebrations_css);
    }
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_preloader_background_colors_css');

// Preloader Background Image
function events_and_celebrations_preloader_background_image_css() {
    $events_and_celebrations_image_url = get_theme_mod('events_and_celebrations_preloader_background_image_setting', '');
    if (!empty($events_and_celebrations_image_url)) {
        $events_and_celebrations_css = "#loader {
            background-image: url('{$events_and_celebrations_image_url}');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }";
        wp_add_inline_style('events-and-celebrations-style', $events_and_celebrations_css);
    }
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_preloader_background_image_css');

// Footer Heading Alignment
function events_and_celebrations_footer_heading_alignment_css() {
    $events_and_celebrations_align = get_theme_mod('events_and_celebrations_footer_header_align', 'left');
    $events_and_celebrations_css = "
        .site-footer h4,
        footer#colophon h2.wp-block-heading,
        footer#colophon .widgettitle,
        footer#colophon .widget-title {
            text-align: {$events_and_celebrations_align};
        }
    ";
    wp_add_inline_style('events-and-celebrations-style', $events_and_celebrations_css);
}
add_action('wp_enqueue_scripts', 'events_and_celebrations_footer_heading_alignment_css');

// Topbar Padding Dynamic CSS
function events_and_celebrations_topbar_padding_css(){
	$padding = get_theme_mod('events_and_celebrations_topbar_padding');
	$custom_css = ".top-header-part{
		padding-top: {$padding}px !important;
		padding-bottom: {$padding}px !important;
	}";
	wp_add_inline_style('events-and-celebrations-style',$custom_css);

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

// Banner Button Color
function events_and_celebrations_banner_button_color_css() {
    $btn_color                    = get_theme_mod( 'events_and_celebrations_banner_btn_color' );
    $btn_bg_color                 = get_theme_mod( 'events_and_celebrations_banner_btn_bg_color' );
    $btn_border_color             = get_theme_mod( 'events_and_celebrations_banner_btn_border_color' );
    $secondary_btn_color          = get_theme_mod( 'events_and_celebrations_banner_secondary_btn_color' );
    $secondary_btn_bg_color       = get_theme_mod( 'events_and_celebrations_banner_secondary_btn_bg_color' );
    $secondary_btn_border_color   = get_theme_mod( 'events_and_celebrations_banner_secondary_btn_border_color' );

    $custom_css = '';

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

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

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

    if ( ! empty( $secondary_btn_color ) ) {
        $custom_css .= "
        #events_and_celebrations_banner_section .video-btn,
        #events_and_celebrations_banner_section .video-btn i {
            color: {$secondary_btn_color} !important;
        }";
    }

    if ( ! empty( $secondary_btn_bg_color ) ) {
        $custom_css .= "
        #events_and_celebrations_banner_section .video-btn {
            background: {$secondary_btn_bg_color} !important;
        }";
    }

    if ( ! empty( $secondary_btn_border_color ) ) {
        $custom_css .= "
        #events_and_celebrations_banner_section .video-btn {
            border-color: {$secondary_btn_border_color} !important;
        }";
    }

    if ( ! empty( $custom_css ) ) {
        wp_add_inline_style( 'events-and-celebrations-style', $custom_css );
    }
}
add_action('wp_enqueue_scripts','events_and_celebrations_banner_button_color_css');
