<?php
/**
 * Custom Functions.
 *
 * @package Event Decorations
 */

if( !function_exists( 'event_decorations_fonts_url' ) ) :

    //Google Fonts URL
    function event_decorations_fonts_url(){

        $event_decorations_font_families = array(
            'Be+Vietnam+Pro:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
            'Montserrat:ital,wght@0,100..900;1,100..900',
        );

        $event_decorations_fonts_url = add_query_arg( array(
            'family' => implode( '&family=', $event_decorations_font_families ),
            'display' => 'swap',
        ), 'https://fonts.googleapis.com/css2' );

        return esc_url_raw($event_decorations_fonts_url);
    }

endif;

if ( ! function_exists( 'event_decorations_sub_menu_toggle_button' ) ) :

    function event_decorations_sub_menu_toggle_button( $event_decorations_args, $event_decorations_item, $depth ) {

        // Add sub menu toggles to the main menu with toggles
        if ( $event_decorations_args->theme_location == 'event-decorations-primary-menu' && isset( $event_decorations_args->show_toggles ) ) {
            
            // Wrap the menu item link contents in a div, used for positioning
            $event_decorations_args->before = '<div class="submenu-wrapper">';
            $event_decorations_args->after  = '';

            // Add a toggle to items with children
            if ( in_array( 'menu-item-has-children', $event_decorations_item->classes ) ) {

                $event_decorations_toggle_target_string = '.menu-item.menu-item-' . $event_decorations_item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $event_decorations_args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $event_decorations_toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="250" aria-expanded="false"><span class="btn__content" tabindex="-1"><span class="screen-reader-text">' . esc_html__( 'Show sub menu', 'event-decorations' ) . '</span>' . event_decorations_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

            // Close the wrapper
            $event_decorations_args->after .= '</div><!-- .submenu-wrapper -->';
            // Add sub menu icons to the main menu without toggles (the fallback menu)

        }elseif( $event_decorations_args->theme_location == 'event-decorations-primary-menu' ) {

            if ( in_array( 'menu-item-has-children', $event_decorations_item->classes ) ) {

                $event_decorations_args->before = '<div class="link-icon-wrapper">';
                $event_decorations_args->after  = event_decorations_get_theme_svg( 'chevron-down' ) . '</div>';

            } else {

                $event_decorations_args->before = '';
                $event_decorations_args->after  = '';

            }

        }

        return $event_decorations_args;

    }

endif;

add_filter( 'nav_menu_item_args', 'event_decorations_sub_menu_toggle_button', 10, 3 );

if ( ! function_exists( 'event_decorations_the_theme_svg' ) ):
    
    function event_decorations_the_theme_svg( $event_decorations_svg_name, $event_decorations_return = false ) {

        if( $event_decorations_return ){

            return event_decorations_get_theme_svg( $event_decorations_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in event_decorations_get_theme_svg();.

        }else{

            echo event_decorations_get_theme_svg( $event_decorations_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in event_decorations_get_theme_svg();.

        }
    }

endif;

if ( ! function_exists( 'event_decorations_get_theme_svg' ) ):

    function event_decorations_get_theme_svg( $event_decorations_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $event_decorations_svg = wp_kses(
            Event_Decorations_SVG_Icons::get_svg( $event_decorations_svg_name ),
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
                'polyline' => array(
                    'fill'      => true,
                    'points'    => true,
                ),
                'line' => array(
                    'fill'      => true,
                    'x1'      => true,
                    'x2' => true,
                    'y1'    => true,
                    'y2' => true,
                ),
            )
        );
        if ( ! $event_decorations_svg ) {
            return false;
        }
        return $event_decorations_svg;

    }

endif;

if( !function_exists( 'event_decorations_post_category_list' ) ) :

    // Post Category List.
    function event_decorations_post_category_list( $event_decorations_select_cat = true ){

        $event_decorations_post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );

        $event_decorations_post_cat_cat_array = array();
        if( $event_decorations_select_cat ){

            $event_decorations_post_cat_cat_array[''] = esc_html__( '-- Select Category --','event-decorations' );

        }

        foreach ( $event_decorations_post_cat_lists as $event_decorations_post_cat_list ) {

            $event_decorations_post_cat_cat_array[$event_decorations_post_cat_list->slug] = $event_decorations_post_cat_list->name;

        }

        return $event_decorations_post_cat_cat_array;
    }

endif;

if( !function_exists('event_decorations_single_post_navigation') ):

    function event_decorations_single_post_navigation(){

        $event_decorations_default = event_decorations_get_default_theme_options();
        $event_decorations_twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'event_decorations_twp_disable_ajax_load_next_post', true ) );
        $event_decorations_current_id = '';
        $article_wrap_class = '';
        global $post;
        $event_decorations_current_id = $post->ID;
        if( $event_decorations_twp_navigation_type == '' || $event_decorations_twp_navigation_type == 'global-layout' ){
            $event_decorations_twp_navigation_type = get_theme_mod('event_decorations_twp_navigation_type', $event_decorations_default['event_decorations_twp_navigation_type']);
        }

        if( $event_decorations_twp_navigation_type != 'no-navigation' && 'post' === get_post_type() ){

            if( $event_decorations_twp_navigation_type == 'theme-normal-navigation' ){ ?>

                <div class="navigation-wrapper">
                    <?php
                    // Previous/next post navigation.
                    the_post_navigation(array(
                        'prev_text' => '<span class="arrow" aria-hidden="true">' . event_decorations_the_theme_svg('arrow-left',$event_decorations_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'event-decorations') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . event_decorations_the_theme_svg('arrow-right',$event_decorations_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'event-decorations') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

                $event_decorations_next_post = get_next_post();
                if( isset( $event_decorations_next_post->ID ) ){

                    $event_decorations_next_post_id = $event_decorations_next_post->ID;
                    echo '<div loop-count="1" next-post="' . absint( $event_decorations_next_post_id ) . '" class="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'event_decorations_navigation_action','event_decorations_single_post_navigation',30 );

if( !function_exists('event_decorations_content_offcanvas') ):

    // Offcanvas Contents
    function event_decorations_content_offcanvas(){ ?>

        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">
                <div class="close-offcanvas-menu">
                    <div class="offcanvas-close">
                        <a href="javascript:void(0)" class="skip-link-menu-start"></a>
                        <button type="button" class="button-offcanvas-close">
                            <span class="offcanvas-close-label">
                                <?php echo esc_html('Close', 'event-decorations'); ?>
                            </span>
                        </button>
                    </div>
                </div>
                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'event-decorations'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('event-decorations-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'event-decorations-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            }else{

                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_sub_menu_icons' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new Event_Decorations_Walker_Page(),
                                    )
                                );
                            }
                            ?>
                        </ul>
                    </nav><!-- .primary-menu-wrapper -->
                </div>
                <a href="javascript:void(0)" class="skip-link-menu-end"></a>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'event_decorations_before_footer_content_action','event_decorations_content_offcanvas',30 );

if( !function_exists('event_decorations_footer_content_widget') ):

    function event_decorations_footer_content_widget(){
        
        $event_decorations_default = event_decorations_get_default_theme_options();
        
        $event_decorations_footer_column_layout = absint(get_theme_mod('event_decorations_footer_column_layout', $event_decorations_default['event_decorations_footer_column_layout']));
        $event_decorations_footer_sidebar_class = 12;
        
        if($event_decorations_footer_column_layout == 2) {
            $event_decorations_footer_sidebar_class = 6;
        }
        
        if($event_decorations_footer_column_layout == 3) {
            $event_decorations_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('event_decorations_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $event_decorations_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($event_decorations_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'event-decorations-footer-widget-' . $i ) ) : 

                                    if ($i === 0) : ?>
                                        <div id="media_image-3" class="widget widget_media_image">
                                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/logo.png'); ?>" alt="<?php echo esc_attr__( 'Footer Image', 'event-decorations' ); ?>" style="max-width: 100%; height: auto;">
                                        </div>
                                        <div id="text-3" class="widget widget_text">
                                            <div class="textwidget">
                                                <p class="widget_text">
                                                    <?php esc_html_e('Event Decorations is a beautifully crafted free theme tailored to cater to businesses in the niche Event Decorations, Wedding Decor, Party Decor, Birthday Setup, Floral Arrangements, Balloon Decoration, Event Styling, Venue Decor, Event Planners, Themed Events, Elegant Setup, Corporate Events, Rustic Decor, Stage Decoration, Backdrop Design, Table Centerpieces, Event Lighting, Ceremony Decor, Reception Styling, Customized Decor, Luxury Events, Event Designers, Outdoor Events, DIY Event Ideas, Event Coordination, Event Organizers, etc...', 'event-decorations'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'event-decorations'); ?></h2>
                                            <?php get_calendar(); ?>
                                        </div>

                                    <?php elseif ($i === 2) : ?>
                                        <div id="search-2" class="widget widget_search">
                                            <h2 class="widget-title"><?php esc_html_e('Enter Keywords Here', 'event-decorations'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('event-decorations-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

                    </div>
                </div>
            </div>
        <?php endif; ?> 

    <?php
    }

endif;

add_action( 'event_decorations_footer_content_action', 'event_decorations_footer_content_widget', 10 );

if( !function_exists('event_decorations_footer_content_info') ):

    /**
     * Footer Copyright Area
    **/
    function event_decorations_footer_content_info(){

        $event_decorations_default = event_decorations_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <div class="column-row">
                    <div class="column column-9">
                        <div class="footer-credits">
                            <div class="footer-copyright">
                                <?php
                                    $event_decorations_footer_copyright_text = wp_kses_post( get_theme_mod( 'event_decorations_footer_copyright_text', $event_decorations_default['event_decorations_footer_copyright_text'] ) );
                                    echo esc_html( $event_decorations_footer_copyright_text );
                                    echo '<br>';
                                    echo esc_html__('Theme: ', 'event-decorations') . '<a href="' . esc_url('https://www.omegathemes.com/products/event-decorations') . '" title="' . esc_attr__('Event Decorations', 'event-decorations') . '" target="_blank"><span>' . esc_html__('Event Decorations ', 'event-decorations') . '</span></a>' . esc_html__(' By ', 'event-decorations') . '  <span>' . esc_html__('OMEGA ', 'event-decorations') . '</span>';
                                    echo esc_html__('Powered by ', 'event-decorations') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'event-decorations') . '" target="_blank"><span>' . esc_html__('WordPress.', 'event-decorations') . '</span></a>';
                                ?>
                            </div>
                        </div>
                    </div>
                    <div class="column column-3 align-text-right">
                        <a class="to-the-top" href="#site-header">
                            <span class="to-the-top-long">
                                <?php if ( get_theme_mod('event_decorations_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $event_decorations_to_the_top_text = get_theme_mod( 'event_decorations_to_the_top_text', __( 'To the Top', 'event-decorations' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $event_decorations_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }

endif;

add_action( 'event_decorations_footer_content_action','event_decorations_footer_content_info',20 );


if( !function_exists( 'event_decorations_main_slider' ) ) :

    function event_decorations_main_slider() {
        $output = '';
        $event_decorations_defaults = event_decorations_get_default_theme_options();
        $event_decorations_header_slider = get_theme_mod( 'event_decorations_header_slider', $event_decorations_defaults['event_decorations_header_slider'] );

        $event_decorations_slider_section_short_title = esc_html( get_theme_mod( 'event_decorations_slider_section_short_title',
        $event_decorations_defaults['event_decorations_slider_section_short_title'] ) );

        $event_decorations_header_banner_cat = get_theme_mod( 'event_decorations_header_banner_cat' );

        $event_decorations_slider_section_bottom_text = esc_html( get_theme_mod( 'event_decorations_slider_section_bottom_text',
        $event_decorations_defaults['event_decorations_slider_section_bottom_text'] ) );

        $event_decorations_slider_section_button_text = esc_html( get_theme_mod( 'event_decorations_slider_section_button_text',
        $event_decorations_defaults['event_decorations_slider_section_button_text'] ) );

        $event_decorations_slider_section_button_url = esc_url( get_theme_mod( 'event_decorations_slider_section_button_url',
        $event_decorations_defaults['event_decorations_slider_section_button_url'] ) );

        $banner_query = new WP_Query( array(
            'post_type' => 'post',
            'posts_per_page' => 4,
            'post__not_in' => get_option( 'sticky_posts' ),
            'category_name' => esc_html( $event_decorations_header_banner_cat ),
        ) );

        ob_start();  // Start output buffering
         if ( $event_decorations_header_slider ) {
        ?>

        <div id="site-content" class="main-banner">
            <div class="slider-box">
                <div class="main-slider">
                    <div class="swiper-container theme-main-carousel" <?php echo is_rtl() ? 'dir="rtl"' : ''; ?>>
                        <div class="swiper-wrapper">
                            <?php while ( $banner_query->have_posts() ) : $banner_query->the_post();
                                $event_decorations_featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' )[0] ?? get_template_directory_uri() . '/assets/images/default.png';
                                ?>
                                <div class="swiper-slide main-carousel-item">
                                    <div class="slider-main">
                                        <div class="data-bg banner-img" data-background="<?php echo esc_url( $event_decorations_featured_image ); ?>">
                                            <a href="<?php the_permalink(); ?>" class="theme-image-responsive"></a>
                                        </div>
                                        <?php event_decorations_post_format_icon(); ?>
                                        <div class="main-carousel-caption">
                                            <div class="post-content">
                                                <header class="entry-header">
                                                    <?php if( $event_decorations_slider_section_short_title ){ ?>
                                                        <h6 class="slider-short"><?php echo esc_html( $event_decorations_slider_section_short_title ); ?></h6>
                                                    <?php } ?>
                                                    <h2 class="slider-heading">
                                                        <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php echo esc_html( get_the_title() ); ?></span></a>
                                                    </h2>
                                                </header>
                                                <div class="entry-content">
                                                    <?php
                                                        if (has_excerpt()) { the_excerpt(); } 
                                                        else {
                                                        echo esc_html(wp_trim_words(get_the_content(), 25, '...'));
                                                    } ?>
                                                </div>
                                                <div class="slide-btn">
                                                    <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary">
                                                        <?php echo esc_html__( 'Shop Now', 'event-decorations' ); ?>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endwhile; ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php if( $event_decorations_slider_section_bottom_text || $event_decorations_slider_section_button_text || $event_decorations_slider_section_button_url ){ ?>
                <div class="contact-box">
                    <?php if( $event_decorations_slider_section_bottom_text ){ ?>
                        <div class="contact-text">
                            <?php echo esc_html( $event_decorations_slider_section_bottom_text); ?>
                        </div>
                    <?php } ?>
                    <?php if( $event_decorations_slider_section_button_text || $event_decorations_slider_section_button_url ){ ?>
                        <div class="contact-button">
                            <a class="contact-btn" href="<?php echo esc_url( $event_decorations_slider_section_button_url ); ?>"><?php echo esc_html( $event_decorations_slider_section_button_text ); ?></a>
                        </div>
                    <?php } ?>
                </div>
            <?php } ?>
        </div>

        <?php }
        wp_reset_postdata();
        $output = ob_get_clean(); // Get buffered output and clean buffer
        return $output; // Return the output instead of echoing
    }

endif;

if( !function_exists( 'event_decorations_about_section' ) ) :

    function event_decorations_about_section(){

        $event_decorations_defaults = event_decorations_get_default_theme_options();

        $event_decorations_about_us_section_title = esc_html( get_theme_mod( 'event_decorations_about_us_section_title',
        $event_decorations_defaults['event_decorations_about_us_section_title'] ) );

        $event_decorations_team_section_subtitle = esc_html( get_theme_mod( 'event_decorations_team_section_subtitle',
        $event_decorations_defaults['event_decorations_team_section_subtitle'] ) );

        $event_decorations_team_section_button_text = esc_html( get_theme_mod( 'event_decorations_team_section_button_text',
        $event_decorations_defaults['event_decorations_team_section_button_text'] ) );

        $event_decorations_team_section_button_url = esc_url( get_theme_mod( 'event_decorations_team_section_button_url',
        $event_decorations_defaults['event_decorations_team_section_button_url'] ) );

        $event_decorations_catData = get_theme_mod('event_decorations_featured_product_category','');
        
        ?>
            <div class="theme-product-block">
                <div class="wrapper">
                    <div class="product-content-box">
                        <div class="product-content">
                            <?php if( $event_decorations_about_us_section_title ){ ?>
                                <h4><?php echo esc_html( $event_decorations_about_us_section_title ); ?></h4>
                            <?php } ?>
                            <?php if( $event_decorations_team_section_subtitle ){ ?>
                                <p><?php echo esc_html( $event_decorations_team_section_subtitle ); ?></p>
                            <?php } ?>
                        </div>
                        <div class="product-button">
                            <?php if( $event_decorations_team_section_button_text || $event_decorations_team_section_button_url ){ ?>
                                <div class="package-button">
                                    <a class="package-btn" href="<?php echo esc_url( $event_decorations_team_section_button_url ); ?>"><?php echo esc_html( $event_decorations_team_section_button_text ); ?></a>
                                </div>
                            <?php } ?>
                        </div>
                    </div>
                    <?php if ( class_exists( 'WooCommerce' ) ) {
                        $event_decorations_args = array(
                            'post_type' => 'product',
                            'posts_per_page' => 100,
                            'product_cat' => $event_decorations_catData,
                            'order' => 'ASC'
                        ); ?>
                    
                        <div class="owl-carousel" role="listbox">
                            <?php 
                            $event_decorations_loop = new WP_Query( $event_decorations_args );
                                while ( $event_decorations_loop->have_posts() ) : $event_decorations_loop->the_post(); 
                                    global $product; 
                                    $product_id = $product->get_id(); // Get product ID dynamically
                            ?>
                                <div class="grid-product">
                                    <div class="image-box">
                                        <?php if(class_exists('YITH_WCWL')){ ?>
                                            <span class="wish-list">
                                                <?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?>
                                            </span>
                                        <?php } ?>
                                        <figure>
                                            <?php if (has_post_thumbnail( $event_decorations_loop->post->ID )) echo get_the_post_thumbnail($event_decorations_loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(wc_placeholder_img_src()).'" />'; ?>
                                        </figure>
                                        <div class="cart-box">
                                            <div class="product-cart">
                                                <?php if( $product->is_type( 'simple' ) ) { woocommerce_template_loop_add_to_cart(  $event_decorations_loop->post, $product );} ?>
                                            </div>
                                            <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?> "><?php echo $product->get_price_html(); ?></p>
                                        </div>
                                    </div>
                                    <div class="product-text-box">
                                        <span class="shop-cat">
                                            <?php
                                            $terms = wp_get_post_terms( $product->get_id(), 'product_cat' );
                                            if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
                                                $first_term = $terms[0];
                                                echo '<a href="' . esc_url( get_term_link( $first_term ) ) . '">' . esc_html( $first_term->name ) . '</a>';
                                            }
                                            ?>
                                        </span>
                                        <h5 class="product-text"><a href="<?php echo esc_url(get_permalink( $event_decorations_loop->post->ID )); ?>"><?php the_title(); ?></a></h5>
                                    </div>
                                </div>
                            <?php 
                                endwhile; 
                            wp_reset_postdata(); // Reset after the loop ends
                            ?>
                        </div>
                    <?php } ?>
                </div>
            </div>
    <?php }

endif;


if (!function_exists('event_decorations_post_format_icon')):

    // Post Format Icon.
    function event_decorations_post_format_icon() {

        $event_decorations_format = get_post_format(get_the_ID()) ?: 'standard';
        $event_decorations_icon = '';
        $event_decorations_title = '';
        if( $event_decorations_format == 'video' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'video' );
            $event_decorations_title = esc_html__('Video','event-decorations');
        }elseif( $event_decorations_format == 'audio' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'audio' );
            $event_decorations_title = esc_html__('Audio','event-decorations');
        }elseif( $event_decorations_format == 'gallery' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'gallery' );
            $event_decorations_title = esc_html__('Gallery','event-decorations');
        }elseif( $event_decorations_format == 'quote' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'quote' );
            $event_decorations_title = esc_html__('Quote','event-decorations');
        }elseif( $event_decorations_format == 'image' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'image' );
            $event_decorations_title = esc_html__('Image','event-decorations');
        } elseif( $event_decorations_format == 'link' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'link' );
            $event_decorations_title = esc_html__('Link','event-decorations');
        } elseif( $event_decorations_format == 'status' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'status' );
            $event_decorations_title = esc_html__('Status','event-decorations');
        } elseif( $event_decorations_format == 'aside' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'aside' );
            $event_decorations_title = esc_html__('Aside','event-decorations');
        } elseif( $event_decorations_format == 'chat' ){
            $event_decorations_icon = event_decorations_get_theme_svg( 'chat' );
            $event_decorations_title = esc_html__('Chat','event-decorations');
        }
        
        if (!empty($event_decorations_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo event_decorations_svg_escape($event_decorations_icon); ?></span>
                <?php if( $event_decorations_title ){ echo '<span class="post-format-label">'.esc_html( $event_decorations_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'event_decorations_svg_escape' ) ):

    /**
     * Get information about the SVG icon.
     *
     * @param string $event_decorations_svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function event_decorations_svg_escape( $event_decorations_input ) {

        // Make sure that only our allowed tags and attributes are included.
        $event_decorations_svg = wp_kses(
            $event_decorations_input,
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
            )
        );

        if ( ! $event_decorations_svg ) {
            return false;
        }

        return $event_decorations_svg;

    }

endif;

if( !function_exists( 'event_decorations_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function event_decorations_sanitize_sidebar_option_meta( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'event_decorations_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function event_decorations_sanitize_pagination_meta( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'Center','Right','Left');
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'event_decorations_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function event_decorations_sanitize_menu_transform( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'event_decorations_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function event_decorations_sanitize_page_content_alignment( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'left','center','right');
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'event_decorations_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function event_decorations_sanitize_footer_widget_title_alignment( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'left','center','right');
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'event_decorations_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $event_decorations_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function event_decorations_sanitize_pagination_type( $event_decorations_input ) {
        // Define valid options for the pagination type.
        $event_decorations_valid_options = array( 'numeric', 'newer_older' ); // Update valid options to include 'newer_older'

        // If the input is one of the valid options, return it. Otherwise, return the default option ('numeric').
        if ( in_array( $event_decorations_input, $event_decorations_valid_options, true ) ) {
            return $event_decorations_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;


// Sanitize the enable/disable setting for pagination
if( !function_exists('event_decorations_sanitize_enable_pagination') ) :
    function event_decorations_sanitize_enable_pagination( $event_decorations_input ) {
        return (bool) $event_decorations_input;
    }
endif;

if( !function_exists( 'event_decorations_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function event_decorations_sanitize_copyright_alignment_meta( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }else{

            return '';

        }
    }

endif;

/**
 * Sidebar Layout Function
 */
function event_decorations_get_final_sidebar_layout() {
	$event_decorations_defaults       = event_decorations_get_default_theme_options();
	$event_decorations_global_layout  = get_theme_mod('event_decorations_global_sidebar_layout', $event_decorations_defaults['event_decorations_global_sidebar_layout']);
	$event_decorations_page_layout    = get_theme_mod('event_decorations_page_sidebar_layout', $event_decorations_global_layout);
	$event_decorations_post_layout    = get_theme_mod('event_decorations_post_sidebar_layout', $event_decorations_global_layout);
	$event_decorations_meta_layout    = get_post_meta(get_the_ID(), 'event_decorations_post_sidebar_option', true);

	if (!empty($event_decorations_meta_layout) && $event_decorations_meta_layout !== 'default') {
		return $event_decorations_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $event_decorations_page_layout;
	}
	if (is_single()) {
		return $event_decorations_post_layout;
	}
	return $event_decorations_global_layout;
}