<?php
/**
 * Custom Functions.
 *
 * @package Board Games
 */

if( !function_exists( 'board_games_fonts_url' ) ) :

    //Google Fonts URL
    function board_games_fonts_url(){

        $board_games_font_families = array(
            'Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800',
            'Play:wght@400;700',
        );

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

        return esc_url_raw($board_games_fonts_url);
    }

endif;

if ( ! function_exists( 'board_games_sub_menu_toggle_button' ) ) :

    function board_games_sub_menu_toggle_button( $board_games_args, $board_games_item, $depth ) {

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

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

                $board_games_toggle_target_string = '.menu-item.menu-item-' . $board_games_item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $board_games_args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $board_games_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', 'board-games' ) . '</span>' . board_games_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

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

        }elseif( $board_games_args->theme_location == 'board-games-primary-menu' ) {

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

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

            } else {

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

            }

        }

        return $board_games_args;

    }

endif;

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

if ( ! function_exists( 'board_games_the_theme_svg' ) ):
    
    function board_games_the_theme_svg( $board_games_svg_name, $board_games_return = false ) {

        if( $board_games_return ){

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

        }else{

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

        }
    }

endif;

if ( ! function_exists( 'board_games_get_theme_svg' ) ):

    function board_games_get_theme_svg( $board_games_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $board_games_svg = wp_kses(
            Board_Games_SVG_Icons::get_svg( $board_games_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 ( ! $board_games_svg ) {
            return false;
        }
        return $board_games_svg;

    }

endif;

if( !function_exists( 'board_games_post_category_list' ) ) :

    // Post Category List.
    function board_games_post_category_list( $board_games_select_cat = true ){

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

        $board_games_post_cat_cat_array = array();
        if( $board_games_select_cat ){

            $board_games_post_cat_cat_array[''] = esc_html__( '-- Select Category --','board-games' );

        }

        foreach ( $board_games_post_cat_lists as $board_games_post_cat_list ) {

            $board_games_post_cat_cat_array[$board_games_post_cat_list->slug] = $board_games_post_cat_list->name;

        }

        return $board_games_post_cat_cat_array;
    }

endif;

if( !function_exists('board_games_single_post_navigation') ):

    function board_games_single_post_navigation(){

        $board_games_default = board_games_get_default_theme_options();
        $board_games_twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'board_games_twp_disable_ajax_load_next_post', true ) );
        $board_games_current_id = '';
        $article_wrap_class = '';
        global $post;
        $board_games_current_id = $post->ID;
        if( $board_games_twp_navigation_type == '' || $board_games_twp_navigation_type == 'global-layout' ){
            $board_games_twp_navigation_type = get_theme_mod('board_games_twp_navigation_type', $board_games_default['board_games_twp_navigation_type']);
        }

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

            if( $board_games_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">' . board_games_the_theme_svg('arrow-left',$board_games_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'board-games') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . board_games_the_theme_svg('arrow-right',$board_games_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'board-games') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

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

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

                }
            }

        }

    }

endif;

add_action( 'board_games_navigation_action','board_games_single_post_navigation',30 );

if( !function_exists('board_games_content_offcanvas') ):

    // Offcanvas Contents
    function board_games_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', 'board-games'); ?>
                            </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', 'board-games'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('board-games-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'board-games-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 Board_Games_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( 'board_games_before_footer_content_action','board_games_content_offcanvas',30 );

if( !function_exists('board_games_footer_content_widget') ):

    function board_games_footer_content_widget(){
        
        $board_games_default = board_games_get_default_theme_options();
        
        $board_games_footer_column_layout = absint(get_theme_mod('board_games_footer_column_layout', $board_games_default['board_games_footer_column_layout']));
        $board_games_footer_sidebar_class = 12;
        
        if($board_games_footer_column_layout == 2) {
            $board_games_footer_sidebar_class = 6;
        }
        
        if($board_games_footer_column_layout == 3) {
            $board_games_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('board_games_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $board_games_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($board_games_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'board-games-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', 'board-games' ); ?>" 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('The Board Games is a multipurpose, elegant, and sophisticated solution tailored for board game enthusiasts, game developers, gaming agencies, Kids Game, Kids Store, Kindergarten Playstore, Preschool Games, Family Games, Strategy Games, Classic Games, Party Games, Educational Games, and entertainment websites.', 'board-games'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'board-games'); ?></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', 'board-games'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('board-games-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

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

    <?php
    }

endif;

add_action( 'board_games_footer_content_action', 'board_games_footer_content_widget', 10 );

if( !function_exists('board_games_footer_content_info') ):

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

        $board_games_default = board_games_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
                                    $board_games_footer_copyright_text = wp_kses_post( get_theme_mod( 'board_games_footer_copyright_text', $board_games_default['board_games_footer_copyright_text'] ) );
                                    echo esc_html( $board_games_footer_copyright_text );
                                    echo '<br>';
                                    echo esc_html__('Theme: ', 'board-games') . '<a href="' . esc_url('https://www.omegathemes.com/products/board-games') . '" title="' . esc_attr__('Board Games', 'board-games') . '" target="_blank"><span>' . esc_html__('Board Games ', 'board-games') . '</span></a>' . esc_html__(' By ', 'board-games') . '  <span>' . esc_html__('OMEGA ', 'board-games') . '</span>';
                                    echo esc_html__('Powered by ', 'board-games') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'board-games') . '" target="_blank"><span>' . esc_html__('WordPress.', 'board-games') . '</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('board_games_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $board_games_to_the_top_text = get_theme_mod( 'board_games_to_the_top_text', __( 'To the Top', 'board-games' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $board_games_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }

endif;

add_action( 'board_games_footer_content_action','board_games_footer_content_info',20 );


if( !function_exists( 'board_games_main_slider' ) ) :

    function board_games_main_slider() {
        $output = '';
        $board_games_defaults = board_games_get_default_theme_options();
        $board_games_header_slider = get_theme_mod( 'board_games_header_slider', $board_games_defaults['board_games_header_slider'] );

        $board_games_banner_section_heading_1 = esc_html( get_theme_mod( 'board_games_banner_section_heading_1',
        $board_games_defaults['board_games_banner_section_heading_1'] ) );

        $board_games_banner_section_heading_2 = esc_html( get_theme_mod( 'board_games_banner_section_heading_2',
        $board_games_defaults['board_games_banner_section_heading_2'] ) );

        $board_games_banner_section_content = esc_html( get_theme_mod( 'board_games_banner_section_content',
        $board_games_defaults['board_games_banner_section_content'] ) );

        $board_games_banner_section_button_text = esc_html( get_theme_mod( 'board_games_banner_section_button_text',
        $board_games_defaults['board_games_banner_section_button_text'] ) );

        $board_games_banner_section_button_url = esc_url( get_theme_mod( 'board_games_banner_section_button_url',
        $board_games_defaults['board_games_banner_section_button_url'] ) );

        $board_games_banner_section_post_1_image = esc_url( get_theme_mod( 'board_games_banner_section_post_1_image',
        $board_games_defaults['board_games_banner_section_post_1_image'] ) );

        $board_games_banner_section_post_1_heading = esc_html( get_theme_mod( 'board_games_banner_section_post_1_heading',
        $board_games_defaults['board_games_banner_section_post_1_heading'] ) );

        $board_games_banner_section_post_1_button_text = esc_html( get_theme_mod( 'board_games_banner_section_post_1_button_text',
        $board_games_defaults['board_games_banner_section_post_1_button_text'] ) );

        $board_games_banner_section_post_1_button_url = esc_url( get_theme_mod( 'board_games_banner_section_post_1_button_url',
        $board_games_defaults['board_games_banner_section_post_1_button_url'] ) );

        $board_games_banner_section_post_2_image = esc_url( get_theme_mod( 'board_games_banner_section_post_2_image',
        $board_games_defaults['board_games_banner_section_post_2_image'] ) );

        $board_games_banner_section_post_2_heading = esc_html( get_theme_mod( 'board_games_banner_section_post_2_heading',
        $board_games_defaults['board_games_banner_section_post_2_heading'] ) );

        $board_games_banner_section_post_2_button_text = esc_html( get_theme_mod( 'board_games_banner_section_post_2_button_text',
        $board_games_defaults['board_games_banner_section_post_2_button_text'] ) );

        $board_games_banner_section_post_2_button_url = esc_url( get_theme_mod( 'board_games_banner_section_post_2_button_url',
        $board_games_defaults['board_games_banner_section_post_2_button_url'] ) );

        $board_games_banner_section_post_3_image = esc_url( get_theme_mod( 'board_games_banner_section_post_3_image',
        $board_games_defaults['board_games_banner_section_post_3_image'] ) );

        $board_games_banner_section_post_3_heading = esc_html( get_theme_mod( 'board_games_banner_section_post_3_heading',
        $board_games_defaults['board_games_banner_section_post_3_heading'] ) );

        $board_games_banner_section_post_3_button_text = esc_html( get_theme_mod( 'board_games_banner_section_post_3_button_text',
        $board_games_defaults['board_games_banner_section_post_3_button_text'] ) );

        $board_games_banner_section_post_3_button_url = esc_url( get_theme_mod( 'board_games_banner_section_post_3_button_url',
        $board_games_defaults['board_games_banner_section_post_3_button_url'] ) );

        $board_games_banner_section_post_4_image = esc_url( get_theme_mod( 'board_games_banner_section_post_4_image',
        $board_games_defaults['board_games_banner_section_post_4_image'] ) );

        $board_games_banner_section_post_4_heading = esc_html( get_theme_mod( 'board_games_banner_section_post_4_heading',
        $board_games_defaults['board_games_banner_section_post_4_heading'] ) );

        $board_games_banner_section_post_4_button_text = esc_html( get_theme_mod( 'board_games_banner_section_post_4_button_text',
        $board_games_defaults['board_games_banner_section_post_4_button_text'] ) );

        $board_games_banner_section_post_4_button_url = esc_url( get_theme_mod( 'board_games_banner_section_post_4_button_url',
        $board_games_defaults['board_games_banner_section_post_4_button_url'] ) );

        if ( $board_games_header_slider ) {
        ?>

        <div id="site-content" class="main-banner">
            <div class="wrapper">
                <div class="main-slider">
                    <div class="slider-content">
                        <?php if( $board_games_banner_section_heading_1 ){ ?>
                            <h3 class="banner-heading"><?php echo esc_html( $board_games_banner_section_heading_1); ?></h3>
                        <?php } ?>
                        <?php if( $board_games_banner_section_heading_2 ){ ?>
                            <h4 class="banner-heading"><?php echo esc_html( $board_games_banner_section_heading_2); ?></h4>
                        <?php } ?>
                        <?php if( $board_games_banner_section_content ){ ?>
                            <p class="banner-text"><?php echo esc_html( $board_games_banner_section_content); ?></p>
                        <?php } ?>
                        <?php if( $board_games_banner_section_button_text || $board_games_banner_section_button_url ){ ?>
                            <div class="banner-button">
                                <a class="banner-btn" href="<?php echo esc_url( $board_games_banner_section_button_url ); ?>"><?php echo esc_html( $board_games_banner_section_button_text ); ?></a>
                            </div>
                        <?php } ?>
                    </div>
                    <div class="banner-post-box">
                        <div class="post-box-1">
                            <?php if( $board_games_banner_section_post_1_heading ){ ?>
                                <h3 class="post-heading"><?php echo esc_html( $board_games_banner_section_post_1_heading); ?></h3>
                            <?php } ?>
                            <?php if( $board_games_banner_section_post_1_button_text || $board_games_banner_section_post_1_button_url ){ ?>
                                <a class="about-btn" href="<?php echo esc_url( $board_games_banner_section_post_1_button_url ); ?>"><?php echo esc_html( $board_games_banner_section_post_1_button_text ); ?></a>
                            <?php } ?>
                            <?php if( $board_games_banner_section_post_1_image ){ ?>
                                <img class="team-images" src="<?php echo esc_url( $board_games_banner_section_post_1_image ); ?>">
                            <?php } ?>
                        </div>
                        <div class="post-box-2">
                            <div class="post-box-heading">
                                <?php if( $board_games_banner_section_post_2_heading ){ ?>
                                <h3 class="post-heading"><?php echo esc_html( $board_games_banner_section_post_2_heading); ?></h3>
                                <?php } ?>
                                <?php if( $board_games_banner_section_post_2_button_text || $board_games_banner_section_post_2_button_url ){ ?>
                                    <a class="about-btn" href="<?php echo esc_url( $board_games_banner_section_post_2_button_url ); ?>"><?php echo esc_html( $board_games_banner_section_post_2_button_text ); ?></a>
                                <?php } ?>
                            </div>
                            <div class="post-image">
                                <?php if( $board_games_banner_section_post_2_image ){ ?>
                                    <img class="team-images" src="<?php echo esc_url( $board_games_banner_section_post_2_image ); ?>">
                                <?php } ?>
                            </div>
                        </div>
                        <div class="post-box-3">
                            <div class="post-box-heading">
                                <?php if( $board_games_banner_section_post_3_heading ){ ?>
                                    <h3 class="post-heading"><?php echo esc_html( $board_games_banner_section_post_3_heading); ?></h3>
                                <?php } ?>
                                <?php if( $board_games_banner_section_post_3_button_text || $board_games_banner_section_post_3_button_url ){ ?>
                                    <a class="about-btn" href="<?php echo esc_url( $board_games_banner_section_post_3_button_url ); ?>"><?php echo esc_html( $board_games_banner_section_post_3_button_text ); ?></a>
                                <?php } ?>
                            </div>
                            <div class="post-image">
                                <?php if( $board_games_banner_section_post_3_image ){ ?>
                                    <img class="team-images" src="<?php echo esc_url( $board_games_banner_section_post_3_image ); ?>">
                                <?php } ?>
                            </div>
                        </div>
                        <div class="post-box-4">
                            <?php if( $board_games_banner_section_post_4_heading ){ ?>
                                <h3 class="post-heading"><?php echo esc_html( $board_games_banner_section_post_4_heading); ?></h3>
                            <?php } ?>
                            <?php if( $board_games_banner_section_post_4_button_text || $board_games_banner_section_post_4_button_url ){ ?>
                                <a class="about-btn" href="<?php echo esc_url( $board_games_banner_section_post_4_button_url ); ?>"><?php echo esc_html( $board_games_banner_section_post_4_button_text ); ?></a>
                            <?php } ?>
                            <?php if( $board_games_banner_section_post_4_image ){ ?>
                                <img class="team-images" src="<?php echo esc_url( $board_games_banner_section_post_4_image ); ?>">
                            <?php } ?>
                        </div>
                    </div>
                    
                </div>
            </div>
        </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( 'board_games_about_section' ) ) :

    function board_games_about_section(){

        $board_games_defaults = board_games_get_default_theme_options();

        $board_games_product_section_short_title = esc_html( get_theme_mod( 'board_games_product_section_short_title',
        $board_games_defaults['board_games_product_section_short_title'] ) );

        $board_games_product_section_heading = esc_html( get_theme_mod( 'board_games_product_section_heading',
        $board_games_defaults['board_games_product_section_heading'] ) );

        $board_games_catData = get_theme_mod('board_games_featured_product_category','');
        
        ?>
            <div class="theme-product-block">
                <div class="">
                    <div class="product-box">
                        <div class="product-content-box">
                            <div class="product-content">
                                <?php if( $board_games_product_section_short_title ){ ?>
                                    <h6><?php echo esc_html( $board_games_product_section_short_title ); ?></h6>
                                <?php } ?>
                                <?php if( $board_games_product_section_heading ){ ?>
                                    <h3><?php echo esc_html( $board_games_product_section_heading ); ?></h3>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="product-loop">
                            <?php if ( class_exists( 'WooCommerce' ) ) {
                                $board_games_args = array(
                                    'post_type' => 'product',
                                    'posts_per_page' => 100,
                                    'product_cat' => $board_games_catData,
                                    'order' => 'ASC'
                                ); ?>
                            
                                <div class="owl-carousel" role="listbox">
                                    <?php 
                                    $board_games_loop = new WP_Query( $board_games_args );
                                        while ( $board_games_loop->have_posts() ) : $board_games_loop->the_post(); 
                                            global $product; 
                                            $product_id = $product->get_id(); // Get product ID dynamically
                                    ?>
                                        <div class="grid-product">
                                            <div class="image-box">
                                                <figure>
                                                    <?php if (has_post_thumbnail( $board_games_loop->post->ID )) echo get_the_post_thumbnail($board_games_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(  $board_games_loop->post, $product );} ?>
                                                    </div>
                                                </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( $board_games_loop->post->ID )); ?>"><?php the_title(); ?></a></h5>
                                                <h6 class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?> "><?php echo $product->get_price_html(); ?></h6>
                                            </div>
                                        </div>
                                    <?php 
                                        endwhile; 
                                    wp_reset_postdata(); // Reset after the loop ends
                                    ?>
                                </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>
    <?php }

endif;


if (!function_exists('board_games_post_format_icon')):

    // Post Format Icon.
    function board_games_post_format_icon() {

        $board_games_format = get_post_format(get_the_ID()) ?: 'standard';
        $board_games_icon = '';
        $board_games_title = '';
        if( $board_games_format == 'video' ){
            $board_games_icon = board_games_get_theme_svg( 'video' );
            $board_games_title = esc_html__('Video','board-games');
        }elseif( $board_games_format == 'audio' ){
            $board_games_icon = board_games_get_theme_svg( 'audio' );
            $board_games_title = esc_html__('Audio','board-games');
        }elseif( $board_games_format == 'gallery' ){
            $board_games_icon = board_games_get_theme_svg( 'gallery' );
            $board_games_title = esc_html__('Gallery','board-games');
        }elseif( $board_games_format == 'quote' ){
            $board_games_icon = board_games_get_theme_svg( 'quote' );
            $board_games_title = esc_html__('Quote','board-games');
        }elseif( $board_games_format == 'image' ){
            $board_games_icon = board_games_get_theme_svg( 'image' );
            $board_games_title = esc_html__('Image','board-games');
        } elseif( $board_games_format == 'link' ){
            $board_games_icon = board_games_get_theme_svg( 'link' );
            $board_games_title = esc_html__('Link','board-games');
        } elseif( $board_games_format == 'status' ){
            $board_games_icon = board_games_get_theme_svg( 'status' );
            $board_games_title = esc_html__('Status','board-games');
        } elseif( $board_games_format == 'aside' ){
            $board_games_icon = board_games_get_theme_svg( 'aside' );
            $board_games_title = esc_html__('Aside','board-games');
        } elseif( $board_games_format == 'chat' ){
            $board_games_icon = board_games_get_theme_svg( 'chat' );
            $board_games_title = esc_html__('Chat','board-games');
        }
        
        if (!empty($board_games_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo board_games_svg_escape($board_games_icon); ?></span>
                <?php if( $board_games_title ){ echo '<span class="post-format-label">'.esc_html( $board_games_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'board_games_svg_escape' ) ):

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

        // Make sure that only our allowed tags and attributes are included.
        $board_games_svg = wp_kses(
            $board_games_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 ( ! $board_games_svg ) {
            return false;
        }

        return $board_games_svg;

    }

endif;

if( !function_exists( 'board_games_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function board_games_sanitize_sidebar_option_meta( $board_games_input ){

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

            return $board_games_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'board_games_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function board_games_sanitize_pagination_meta( $board_games_input ){

        $board_games_metabox_options = array( 'Center','Right','Left');
        if( in_array( $board_games_input,$board_games_metabox_options ) ){

            return $board_games_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'board_games_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function board_games_sanitize_menu_transform( $board_games_input ){

        $board_games_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $board_games_input,$board_games_metabox_options ) ){

            return $board_games_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'board_games_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function board_games_sanitize_page_content_alignment( $board_games_input ){

        $board_games_metabox_options = array( 'left','center','right');
        if( in_array( $board_games_input,$board_games_metabox_options ) ){

            return $board_games_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'board_games_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function board_games_sanitize_footer_widget_title_alignment( $board_games_input ){

        $board_games_metabox_options = array( 'left','center','right');
        if( in_array( $board_games_input,$board_games_metabox_options ) ){

            return $board_games_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'board_games_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $board_games_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function board_games_sanitize_pagination_type( $board_games_input ) {
        // Define valid options for the pagination type.
        $board_games_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( $board_games_input, $board_games_valid_options, true ) ) {
            return $board_games_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('board_games_sanitize_enable_pagination') ) :
    function board_games_sanitize_enable_pagination( $board_games_input ) {
        return (bool) $board_games_input;
    }
endif;

if( !function_exists( 'board_games_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function board_games_sanitize_copyright_alignment_meta( $board_games_input ){

        $board_games_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $board_games_input,$board_games_metabox_options ) ){

            return $board_games_input;

        }else{

            return '';

        }
    }

endif;

/**
 * Sidebar Layout Function
 */
function board_games_get_final_sidebar_layout() {
	$board_games_defaults       = board_games_get_default_theme_options();
	$board_games_global_layout  = get_theme_mod('board_games_global_sidebar_layout', $board_games_defaults['board_games_global_sidebar_layout']);
	$board_games_page_layout    = get_theme_mod('board_games_page_sidebar_layout', $board_games_global_layout);
	$board_games_post_layout    = get_theme_mod('board_games_post_sidebar_layout', $board_games_global_layout);
	$board_games_meta_layout    = get_post_meta(get_the_ID(), 'board_games_post_sidebar_option', true);

	if (!empty($board_games_meta_layout) && $board_games_meta_layout !== 'default') {
		return $board_games_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $board_games_page_layout;
	}
	if (is_single()) {
		return $board_games_post_layout;
	}
	return $board_games_global_layout;
}