<?php
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

    global $kirb_filters_data, $kirb_disable_byor;
    if(!$kirb_filters_data) {
        $kirb_filters_data = kirb_get_filters_data();
    }
    $filter_options = array();

    $url_shape_preset = get_query_var('kirb_param');
    $url_shape_param = $url_shape_preset;
    $shape_slug_config = kirb_get_config("listing_shape_slugs");
    if($shape_slug_config && isset($shape_slug_config[$url_shape_preset])) {
        $url_shape_preset = $shape_slug_config[$url_shape_preset];
    }else{
        $url_shape_preset = "";
    }

    $kirb_ud_localization = kirb_get_user_defined_localization();

    $api_error = true;

    if(isset($kirb_filters_data['filterdata']) && $kirb_filters_data['categories']) {
        foreach($kirb_filters_data['filterdata'] as $filter) {
            $filter_options[$filter['category']] = $filter;
        }

        $shapes = $filter_options[$current_category]['shape'];
        $carat_range = array_map('floatval',$filter_options[$current_category]['caratRange']);
        $colors = explode(",", $filter_options[$current_category]['color']);
        $cuts = explode(",", $filter_options[$current_category]['cut']);
        $clarity = explode(",", $filter_options[$current_category]['clarity']);
        $price_range = array_map('intval',$filter_options[$current_category]['priceRange']);
        $table_range = array_map('floatval',$filter_options[$current_category]['taRange']);
        $depth_range = array_map('floatval',$filter_options[$current_category]['tdRange']);
        $lw_ratio_range = array_map('floatval',$filter_options[$current_category]['Ratio']);

        $gem_colors = explode(",", $filter_options[$current_category]['gem_color']);
        $gem_types = explode(",", $filter_options[$current_category]['gem_type']);
        $intensities = explode(",", $filter_options[$current_category]['intensity']);
        
        $polish = explode(",", $filter_options[$current_category]['polish']);
        $symmetry = explode(",", $filter_options[$current_category]['symmetry']);
        $fluor = explode(",", $filter_options[$current_category]['fluor']);
        if(isset($filter_options[$current_category]['labFilter'])) {
            $labs = explode(",", $filter_options[$current_category]['labFilter']);
        }else{
            $labs = array();
        }

        $categories = $kirb_filters_data['categories'];

        $api_error = false;

        $is_gemstone = $current_category == 'GEMSTONE';
    }

    global $kirb_page_ids;
    $kirb_page_ids = json_decode(kirbGetMeta("_page_ids"), true);

    $addons_data = json_decode(kirbGetMeta('_setting_addon_data'), true);

    global $kirb_disable_byor;
    $kirb_disable_byor = !kirbGetMeta('_setting_ring_setting_catg');

    $kirb_mob_grid = kirb_get_addon_value('gridView');

    if(!$api_error) {
        // Enqueue Diamond Listing Page Script
        wp_enqueue_script('kirb-diamond-listing-page-script', KIRB_PLUGIN_DIR . "/scripts/diamond-listing.js", array('jquery', 'kirb-custom-common-script', 'jquery-ui-slider','kirb-numeral-lang','kirb-numeral-js'), KIRB_VERSION_CONTROL['diamond-listing-page-js'], true);

        wp_localize_script( 'kirb-diamond-listing-page-script', 'DListing', [
                'current_catg' => $current_category,
                'primary_color' => sanitize_hex_color(kirbGetMeta('_setting_primary_color')),
                'primary_text_color' => sanitize_hex_color(kirbGetMeta('_setting_text_primary_color')) ?? '#ffffff',
                'logged_in' => is_user_logged_in(),
                'is_gemstone' => $is_gemstone,
                'currency_locale' => str_replace("_", "-",determine_locale()),
                'currency_code' => get_woocommerce_currency(),
                'url_shape_preset' => $url_shape_param,
                'shape_slug_config' => $shape_slug_config,
                'grid_view_mob' => $kirb_mob_grid,
            ]
        );

        wp_localize_script( 'kirb-diamond-listing-page-script', 'DFilters', [
                'filter_carat_range' => $carat_range,
                'filter_colors' => $colors,
                'filter_cuts' => $cuts,
                'filter_clarity' => $clarity,
                'filter_price_range' => $price_range,
                'filter_polish' => $polish,
                'filter_symmetry' => $symmetry,
                'filter_fluor' => $fluor,
                'filter_table_range' => $table_range,
                'filter_depth_range' => $depth_range,
                'filter_lw_ratio_range' => $lw_ratio_range,
                'filter_gem_color' => $gem_colors,
                'filter_gem_type' => $gem_types,
            ]
        );

        $language_group = "";
        if($current_category == 'NATURAL') {
            $language_group = "natural-diamond-listing";
        }else if($current_category == 'LAB CREATED') {
            $language_group = "lab-diamond-listing";
        } else if($current_category == 'GEMSTONE') {
            $language_group = "gemstone-listing";
        } else if($current_category == 'COLORED DIAMONDS') {
            $language_group = "colored-diamond-listing";
        }

        // Translation Lookup
        require_once(KIRB_BASE_DIR . '/translations_lookup.php');

        global $kirb_filter_values_translation_mapping;
        if (!is_array($kirb_filter_values_translation_mapping)) {
            $kirb_filter_values_translation_mapping = [];
        }
        
        $kirb_filter_values_translation_mapping = array_merge($kirb_filter_values_translation_mapping, array(
            'fast_shipping' => esc_html(kirb_get_string($language_group,"string_fast_shipping", $kirb_ud_localization))
        ));

        wp_localize_script( 'kirb-diamond-listing-page-script', 'DTranslations', [
                'all_results' => esc_html__('All Results', 'diamond-ring-builder-jewelry'),
                'clear_filter' => esc_html__('CLEAR FILTER', 'diamond-ring-builder-jewelry'),
                'more_filters' => esc_html__('MORE FILTERS', 'diamond-ring-builder-jewelry'),
                'result' => esc_html__('Result', 'diamond-ring-builder-jewelry'),
                'results' => esc_html__('Results', 'diamond-ring-builder-jewelry'),
                'showing' => esc_html__('Showing', 'diamond-ring-builder-jewelry'),
                'closest_match' => esc_html__('These results are the closest match to your search, use the filters at the top of the page to refine your results.', 'diamond-ring-builder-jewelry'),
                'compare' => esc_html__('Compare', 'diamond-ring-builder-jewelry'),
                'no_product_to_show' => esc_html__('No products to show here', 'diamond-ring-builder-jewelry'),
                'recently_viewed' => esc_html__('Recently Viewed', 'diamond-ring-builder-jewelry'),
                'filter_values' => $kirb_filter_values_translation_mapping
            ]
        );
    }

    $all_shapes = array('Round', 'Princess', 'Cushion', 'Emerald', 'Marquise', 'Oval', 'Radiant', 'Pear','Asscher', 'Heart', 'Old Miner', 'European');

    $kirb_translations_lookup = array(
        'diamond' => __('Diamond', 'diamond-ring-builder-jewelry'),
        'gemstone' => __('Gemstone', 'diamond-ring-builder-jewelry'),
        'NATURAL' => __('NATURAL', 'diamond-ring-builder-jewelry'),
        'LAB CREATED' => __('LAB CREATED', 'diamond-ring-builder-jewelry')
    );
?>
<?php include_once('common.php'); ?>
<section>
    <div class="container diamond-list-padding">
        <?php 
            if(!$api_error) {
        ?>
        <?php kirbLoadByorStrip(); ?>
        <?php 
            if($current_category == "NATURAL" || $current_category == "LAB CREATED") {
        ?>
        <div class="head-round-cut w-100">
            <div class="filter__btn">
                    <?php 
                        $q_string = "";
                        if(!empty($_SERVER['QUERY_STRING'])) {
                            $q_string = '?' . str_replace(array("http://","https://"),"",sanitize_url(wp_unslash($_SERVER['QUERY_STRING'])));
                        }
                        $show_categories = array("NATURAL", "LAB CREATED");
                        foreach($show_categories as $category) {
                            if(!$kirb_catg_control[$category]) {
                                continue;
                            }
                            $active = $category == $current_category ? 'active' : '';
                    ?>
                    <div class="inner-filter-btn <?php echo esc_attr($active) ?> kirb_mjr_catg  listing-tab-font-size">
                        <a href="<?php echo esc_url(kirb_getPageUrlById($kirb_page_ids[KIRB_ALL_PAGES_MAP[$category]]) . (!empty($url_shape_param) ? $url_shape_param . '/' : '') . $q_string) ?>"
                            data-catg="<?php echo esc_attr($category)?>" id="tab_data_<?php echo esc_attr(str_replace(' ','_',strtolower($category)));?>" data-base-url="<?php echo esc_url(kirb_getPageUrlById($kirb_page_ids[KIRB_ALL_PAGES_MAP[$category]]))?>">
                            <?php 
                                echo esc_html($kirb_translations_lookup[$category]);
                            ?>
                        </a>
                    </div>
                    <?php
                        }
                    ?>
            </div>
        </div>
        <?php 
            } 
        ?>

        <div class="text-center pera-natural-lab w-100">
            <span id="kirb_shape_subtitle" class="col-lg-6 col-md-8 col-12">
                <?php
                        $kirb_shape_preset_url = isset($_GET['shape']) ? sanitize_text_field($_GET['shape']) : '';
                        if(empty($kirb_shape_preset_url)) {
                            $catwithoutSpace = strtolower(str_replace(' ', '', $current_category));
                            echo esc_html(kirb_get_string($language_group,"string_".$catwithoutSpace."_subtitle", $kirb_ud_localization));
                    }else{
                        echo esc_html(kirb_get_string($language_group,"string_".$kirb_shape_preset_url."_subtitle", $kirb_ud_localization));
                    }
                ?>
            </span>
        </div>

        <button class="kirb_mobile__filter kirb_openFilter">
            <span>FILTER</span>
            <img class="" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/filter-app1.svg" loading="lazy" alt="Filter" width="20" height="20" >
        </button>

        <!-- Mobile Filter Popup -->
        <div class="kirb_mobile-filter-popup" id="kirb_filterPopup">
            <div class="filter-sticky">
                <p>FILTERS</p>
                <div class="search-sticky">
                    <!-- product-search moved here via jQuery on mobile -->
                </div>
            </div>
            <div class="kirb_popup-content">
                <!-- Filter content will be moved here via jQuery on mobile -->
            </div>
            <div class="view--results"><button id="kirb_closeFilter">VIEW RESULTS</button></div>
        </div>


        <div class="filter-div-ab">
            <div class="row filter--section">
                <div class="col-lg-8 col-md-6 inner_filter--section">
                    <?php 
                        if($current_category == 'GEMSTONE' || $current_category == 'COLORED DIAMONDS') {
                    ?>
                    <div class="color_Diamonds">
                        <div class="d-flex">
                            <div class="filter-heading"><?php echo esc_html__('Color','diamond-ring-builder-jewelry');?></div>
                        </div>
                        <?php 
                            $preset_gem_index = 0;
                            $gems_per_page = 10;
                            $preset_gem_color = esc_html(isset($_GET['color']) ? wp_unslash($_GET['color']) : '');
                            if(!empty($preset_gem_color)) {
                                $preset_gem_index = array_search(strtolower(str_replace(' ', '', $preset_gem_color)), array_map(fn($gem) => strtolower(str_replace(' ', '', $gem)), $gem_colors));
                                if(!$preset_gem_index) {
                                    $preset_gem_index = 0;
                                }
                            }
                        ?>
                        <div class="gem_color__inner <?php echo esc_attr(!wp_is_mobile() ? 'kirb_scrollable_div' : '');?>" data-max-items="<?php echo esc_attr($gems_per_page); ?>" data-current-page="<?php echo esc_attr(min(ceil(($preset_gem_index + 1) / $gems_per_page),ceil(count($gem_colors) / $gems_per_page))); ?>">
                        <?php 
                            foreach($gem_colors as $gem_color) {
                        ?>
                            <div class="gem_color-box kirb_gem_color <?php echo esc_attr((isset($_GET['color']) && strtolower($gem_color) == strtolower(sanitize_text_field(wp_unslash($_GET['color'])))) ? 'active' : ''); ?>"
                                data-gem-color="<?php echo esc_attr($gem_color);?>" title="<?php echo esc_attr(ucfirst(strtolower($gem_color)));?>">
                                <div class="inner-gem-section">
                                    <div class="gemstone-img <?php echo esc_attr(strtolower($gem_color));?>-gem-color"> </div>
                                </div>
                                <div>
                                    <div class="gem-color-name">
                                        <?php 
                                            $gem_color = ucfirst(strtolower($gem_color));
                                            echo esc_html($kirb_filter_values_translation_mapping[$gem_color] ?? $gem_color);
                                        ?>
                                    </div>
                                </div>
                            </div>
                        <?php
                            }
                        ?>
                        </div>
                    </div>
                    <?php } ?>

                    <div class="filter_div shape__filter shape-filter-mobile">
                        <?php 
                            // translators: %s will be replaced by diamond or gemstone
                            $shape_info_string = __("Shape refers to a %s's geometric outline and physical form, which affects its appearance and is defined by specific cut attributes.", 'diamond-ring-builder-jewelry');
                        ?>
                        <div class="d-flex">
                            <div class="filter-heading shape-text-padding"><?php echo esc_html__('Shape', 'diamond-ring-builder-jewelry');?>
                            <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr(sprintf($shape_info_string, strtolower($is_gemstone ? $kirb_translations_lookup['gemstone'] : $kirb_translations_lookup['diamond']))); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                            </span>
                            </div>
                        </div>
                        <?php
                            $shapes = array_map('strtolower', array_column($shapes, 'name'));

                            $all_shapes = array_filter($all_shapes, function($shape) use ($shapes) {
                                return in_array(strtolower(str_replace(' ', '', $shape)), $shapes);
                            });

                            $preset_shape = isset($_GET['shape']) ? sanitize_text_field(wp_unslash($_GET['shape'])) : '';
                            if(empty($preset_shape) && !empty($url_shape_preset)) {
                                $preset_shape = $url_shape_preset;
                            }

                            $preset_shape_index = 0;
                            $shapes_per_page = 10;
                            if(!empty($preset_shape)) {
                                $preset_shape_index = array_search(strtolower(str_replace(' ', '',$preset_shape)), array_map(fn($shape) => strtolower(str_replace(' ', '', $shape)), $all_shapes));
                                if(!$preset_shape_index) {
                                    $preset_shape_index = 0;
                                }
                            }
                        ?>
                        <div class="filter_inner shape__inner kirb-diamond-shapes bg-gray shapes-section-padding <?php echo esc_attr(!wp_is_mobile() ? 'kirb_scrollable_div' : '');?>" data-max-items="<?php echo esc_attr($shapes_per_page); ?>" data-current-page="<?php echo esc_attr(min(ceil(($preset_shape_index + 1) / $shapes_per_page),ceil(count($all_shapes) / $shapes_per_page))); ?>">
                            <?php
                                foreach($all_shapes as $idx => $shape) {
                            ?>
                                <div class="shape_item" <?php if($idx >= $shapes_per_page){ printf('style="%s"', esc_attr('display:none;')); } ?>>
                                    <div class="shape-box <?php echo esc_attr(strtolower(str_replace(' ', '', $shape)));?> <?php echo (strtolower(str_replace(' ', '', $shape)) == strtolower($preset_shape)) ? 'active' : ''; ?>"
                                        data-shape="<?php echo esc_attr(strtolower(str_replace(' ', '', $shape)));?>">
                                            <div class="shape-img <?php echo esc_attr(strtolower(str_replace(' ', '', $shape)));?>-shape" title="<?php echo esc_html($kirb_filter_values_translation_mapping[$shape] ?? $shape);?>" data-subtitle="<?php echo esc_attr(kirb_get_string($language_group,"string_".strtolower(str_replace(' ', '', $shape))."_subtitle",$kirb_ud_localization)); ?>"></div>
                                    </div>
                                    <div class="shape_heading">
                                        <?php echo esc_html($kirb_filter_values_translation_mapping[$shape] ?? $shape);?>
                                    </div>
                                </div>
                            <?php
                                }
                            ?>
                        </div>
                    </div> 

                </div>



                <div class="col-lg-4 col-md-6 ">
                    <div class="filter_div filter__slider price__filter filter-price-fast-section">
                        <div class="filter-heading"><?php echo esc_html__('Price', 'diamond-ring-builder-jewelry');?></div>
                        <div class="slider-section input-width-full filter_inner">
                            <div id="price-range" class="slider"></div>
                            <div class="input-div price_inp_div">
                                <input type="text" class="price_inp" name="min_price" id="min_price" value="" />
                                <input type="text" class="price_inp" name="max_price" id="max_price" value="" />
                            </div>
                        </div>
                    </div>
                    <div class="price_checkbox">
                        <div>
                            <label class="360-view-gem checkbox__container">
                                <input type="checkbox" class="kirb_extra_filter" data-filter="videoAvailable"
                                    <?php echo esc_attr(isset($_GET['videoAvailable']) && sanitize_text_field(wp_unslash($_GET['videoAvailable'])) == 'true' ? 'checked' : '');?> >
                                <div class="checkmark"></div>
                                <?php echo esc_html__('360 View Available', 'diamond-ring-builder-jewelry');?>
                            </label>
                        </div>
                        <?php if($addons_data['fast_shipping']['enabled']) { ?>
                        <div>
                            <label class="360-view-gem checkbox__container">
                                <input type="checkbox" class="kirb_extra_filter" data-filter="includeShippingDaysFilter"
                                    <?php echo esc_attr(isset($_GET['includeShippingDaysFilter']) && sanitize_text_field(wp_unslash($_GET['includeShippingDaysFilter'])) == 'true' ? 'checked' : '');?>>
                                    <div class="checkmark"></div>
                                      <?php echo esc_html(kirb_get_string($language_group,"string_fast_shipping", $kirb_ud_localization)); ?>
                                </label>
                                <?php if(!empty($addons_data['fast_shipping']['string'])) { ?>
                                    <div class="vector-icon">
                                        <div class="vector-content-popup">
                                            <?php 
                                                // echo esc_html(
                                                //     esc_html($current_category == 'GEMSTONE' ? 'Gemstone' : 'Diamond').' Available in '.esc_html($addons_data['fast_shipping']['string']).' Days'); 
                                                echo esc_html(sprintf(__("%1\$s Available in %2\$s Days", "diamond-ring-builder-jewelry"), ($current_category == 'GEMSTONE' ? $kirb_translations_lookup['gemstone'] : $kirb_translations_lookup['diamond']), ($addons_data['fast_shipping']['string'])));
                                            ?>
                                        </div>
                                        <img src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="">
                                    </div>
                                <?php } ?>
                        </div>
                        <?php } ?>
                    </div>
                    <?php 
                if($current_category == 'GEMSTONE') {
            ?>
                    <div class="filter_div filter__slider carat__filter">
                        <div class="filter-heading"><?php echo esc_html__('Carat', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__('The international unit of weight, used for measuring diamonds and gemstones. 1 carat is equal to 200 milligrams, or 0.2 grams.', 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span>
                        </div>
                        <div class="slider-section input-width-full filter_inner">
                            <div id="carat-range" class="slider"></div>
                            <div class="input-div">
                                <input type="number" class="carat_inp" name="min_carat" id="min_carat" value=""
                                    step="0.01" />
                                <input type="number" class="carat_inp" name="max_carat" id="max_carat" value=""
                                    step="0.01" />
                            </div>
                        </div>
                    </div>

                    <?php } ?>
                    <?php 
                if($current_category == 'GEMSTONE') {
            ?>

                    <div class="filter_div gem_type__filter gemstone-div">
                        <div class="filter-heading"><?php echo esc_html__('Gemstone Type', 'diamond-ring-builder-jewelry');?></div>
                        <div class="gem_type__inner filter_inner input-width-full">
                            <?php 
                            foreach($gem_types as $gem_type) {
                                $active = isset($_GET['gemType']) && strtolower($gem_type) == strtolower(sanitize_text_field(wp_unslash($_GET['gemType']))) ? 'active' : '';
                        ?>
                            <div class="gem_type-box kirb_gem_type <?php echo esc_attr($active)?>" data-gem-type="<?php echo esc_attr($gem_type)?>">
                                <div class="gem_type-name w-full "><?php echo esc_html($kirb_filter_values_translation_mapping[$gem_type] ?? $gem_type);?></div>
                            </div>
                            <?php
                            }
                        ?>
                        </div>
                    </div>

                    <?php } ?>


                    <?php 
                        if($current_category == 'COLORED DIAMONDS') {
                    ?>
                    <!-- <div class="col-lg-4 col-md-6"> -->
                        <div class="filter_div filter__slider carat__filter">
                            <div class="filter-heading"><?php echo esc_html__('Carat', 'diamond-ring-builder-jewelry');?>
                            <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__('The international unit of weight, used for measuring diamonds and gemstones. 1 carat is equal to 200 milligrams, or 0.2 grams.', 'diamond-ring-builder-jewelry'); ?>">
                                    <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                            </span>
                            </div>
                            <div class="slider-section input-width-full filter_inner">
                                <div id="carat-range" class="slider"></div>
                                <div class="input-div">
                                    <input type="number" class="carat_inp" name="min_carat" id="min_carat" value=""
                                        step="0.01" />
                                    <input type="number" class="carat_inp" name="max_carat" id="max_carat" value=""
                                        step="0.01" />
                                </div>
                            </div>
                        </div>
                    <!-- </div> -->
                    <?php } ?>
                    
                    <!-- INTENSITY WAS HERE -->



                    <?php if($current_category == 'COLORED DIAMONDS') { ?>
                        <div class="kirb-filter-advance-block">
                            <label class="kirb_reset_filters"><?php echo esc_html__('CLEAR FILTER', 'diamond-ring-builder-jewelry');?></label>
                            <div class="moreless__div">
                                <button class="advanced-filter moreless__btn more-filter-span"><?php echo esc_html__('MORE FILTERS', 'diamond-ring-builder-jewelry');?>&nbsp;+</button>
                            </div>
                        </div>
                    <?php } ?>
                </div>

                <?php 
                 if($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
            ?>
                <div class="col-lg-4 col-md-6">
                    <div class="filter_div filter__slider carat__filter">
                        <div class="filter-heading"><?php echo esc_html__('Carat', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__('The international unit of weight, used for measuring diamonds and gemstones. 1 carat is equal to 200 milligrams, or 0.2 grams.', 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span>
                        </div>
                        <div class="slider-section input-width-full filter_inner">
                            <div id="carat-range" class="slider"></div>
                            <div class="input-div">
                                <input type="number" class="carat_inp" name="min_carat" id="min_carat" value=""
                                    step="0.01" />
                                <input type="number" class="carat_inp" name="max_carat" id="max_carat" value=""
                                    step="0.01" />
                            </div>
                        </div>
                    </div>
                </div>
                <?php } ?>


                <?php 
                if($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
            ?>
                <div class="col-lg-4 col-md-6">
                    <div class="filter_div filter__slider color__filter">
                        <div class="filter-heading"><?php echo esc_html__('Color', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("Diamond color grades describe the absence of color, with less color enhancing brilliance and increasing value.", 'diamond-ring-builder-jewelry'); ?>"
                        >
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span>
                    </div>
                        <div class="slider-section filter_inner">
                            <div class="slider-dots"></div>
                            <div id="colors-range" class="slider"></div>
                            <div class="angebar-custom-label d-flex justify-content-evenly kirb-color-labels">
                                <?php 
                                foreach($colors as $color) {
                            ?>
                                <div><?php echo esc_html($color);?></div>
                                <?php
                                }
                            ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 col-md-6">
                    <div class="filter_div filter__slider cut__filter">
                        <div class="filter-heading"><?php echo esc_html__('Cut', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("The diamond's cut affects its brilliance and sparkle, making it essential for its beauty and value.", 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section filter_inner">
                            <input type="hidden" id="cut__filterss" filter_name="cut" readonly>
                            <div class="slider-dots"></div>
                            <div id="cut-range" class="slider"></div>
                            <div class="angebar-custom-label d-flex justify-content-evenly kirb-cut-labels">
                                <?php 
                                foreach($cuts as $cut) {
                            ?>
                                <div>
                                    <?php echo esc_html($kirb_filter_values_translation_mapping[$cut] ?? $cut);?>
                                </div>
                                <?php
                                }
                            ?>
                            </div>
                        </div>
                    </div>
                </div>
                <?php
                }
            ?>
            <?php 
                 if($current_category != 'GEMSTONE') {
            ?>
                <div class="col-lg-4 col-md-6">
                    <div class="filter_div filter__slider clarity__filter <?php echo esc_attr($current_category == 'COLORED DIAMONDS' ? 'more-filters' : '');?>">
                        <div class="filter-heading"><?php echo esc_html__('Clarity', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("Diamond clarity measures surface and internal imperfections. Fewer and smaller imperfections mean higher clarity and cost.", 'diamond-ring-builder-jewelry'); ?>">
                            <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section filter_inner">
                            <!-- Slider container -->
                            <input type="hidden" id="clarity__filterss" filter_name="clarity" readonly>
                            <div class="slider-dots"></div>
                            <div id="clarity-range" class="slider"></div>
                            <!-- Labels for each step on the slider -->
                            <div class="angebar-custom-label d-flex justify-content-evenly kirb-clarity-labels">
                                <?php 
                                foreach($clarity as $val) {
                            ?>
                                <div><?php echo esc_html($val);?></div>
                                <?php
                                }
                            ?>
                            </div>
                        </div>
                    </div>
                </div>




                <?php 
                    if($current_category == 'COLORED DIAMONDS') {
                ?>
                <div class="col-lg-4 col-md-6">
                    <div class="filter_div gem_type__filter more-filters" style="margin-top:0;">
                        <div style="display: flex;align-items: center;">
                            <div class="filter-heading"><?php echo esc_html__('Intensity', 'diamond-ring-builder-jewelry');?>
                                <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("The intensity of a colored diamond refers to the strength and vividness of its color. Ranging from Faint to Fancy Vivid, higher intensity levels indicate a richer, more vibrant hue.", 'diamond-ring-builder-jewelry'); ?>">
                                    <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                                </span> 
                            </div>
                        </div>
                        <div class="gem_type__inner filter_inner">
                            <?php 
                            foreach($intensities as $intensity) {
                                $active = isset($_GET['intensity']) && strtolower($intensity) == strtolower(sanitize_text_field(wp_unslash($_GET['intensity']))) ? 'active' : '';
                        ?>
                            <div class="gem_type-box kirb_diamond_intensity <?php echo esc_attr($active)?>"
                                data-intensity="<?php echo esc_attr($intensity)?>">
                                <div class="gem_type-name w-full "><?php echo esc_html($kirb_filter_values_translation_mapping[$intensity] ?? $intensity);?></div>
                            </div>
                            <?php
                            }
                        ?>
                        </div>
                    </div>
                </div>
                <?php } ?>

                <?php
                }
                if($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
                ?>
                    <div class="col-lg-4 col-md-6">
                        <div class="filter_div filter__slider polish__filter">
                            <div class="filter-heading"><?php echo esc_html__('Polish', 'diamond-ring-builder-jewelry');?>
                            <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("The polish of a diamond affects its sparkle, with smooth, well-defined facets being crucial for optimal light performance.", 'diamond-ring-builder-jewelry'); ?>">
                                    <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                            </span></div>
                            <div class="slider-section filter_inner">
                                <input type="hidden" id="polish__filterss" filter_name="polish" readonly>
                                <div class="slider-dots"></div>
                                <div id="polish-range" class="slider"></div>
                                <div class="angebar-custom-label d-flex justify-content-evenly kirb-polish-labels">
                                    <?php 
                                        foreach($polish as $val) {
                                    ?>
                                    <div>
                                        <?php echo esc_html($kirb_filter_values_translation_mapping[$val] ?? $val);?>
                                    </div>
                                    <?php
                                        }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php
                }
                ?>
                <?php 
                if($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
            ?>
                <div class="col-lg-4 col-md-6 symmetry-filter-padding">
                    <div class="filter_div filter__slider symmetry__filter">
                        <div class="filter-heading"><?php echo esc_html__('Symmetry', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("The precision and alignment of a diamond's facets impact its brilliance. Well-cut facets enhance sparkle.", 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section filter_inner">
                            <input type="hidden" id="symmetry__filterss" filter_name="symmetry" readonly>
                            <div class="slider-dots"></div>
                            <div id="symmetry-range" class="slider"></div>
                            <div class="angebar-custom-label d-flex justify-content-evenly kirb-symm-labels">
                                <?php 
                                    foreach($symmetry as $val) {
                                ?>
                                    <div>
                                        <?php 
                                            echo esc_html($kirb_filter_values_translation_mapping[$val] ?? $val);
                                        ?>
                                    </div>
                                <?php
                                    }
                                ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 col-md-6 more-filters">
                    <div class="filter_div filter__slider fluor__filter">
                        <div class="filter-heading"><?php echo esc_html__('Fluorescence', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("Fluorescence measures how diamonds glow under UV light. Strong fluorescence can lower the price but rarely affects appearance.", 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section filter_inner">
                            <input type="hidden" id="fluor__filterss" filter_name="fluor" readonly>
                            <div class="slider-dots"></div>
                            <div id="fluor-range" class="slider"></div>
                            <div class="angebar-custom-label d-flex justify-content-evenly kirb-fluor-labels">
                                <?php 
                                    foreach($fluor as $val) {
                                ?>
                                    <div>
                                        <?php 
                                            echo esc_html($kirb_filter_values_translation_mapping[$val] ?? $val);
                                        ?>
                                    </div>
                                <?php
                                    }
                                ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 col-md-6 more-filters">
                    <div class="filter_div filter__slider price__filter">
                        <div class="filter-heading"><?php echo esc_html__('Table', 'diamond-ring-builder-jewelry');?> %
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("The table width, a percentage of the diamond's diameter, is key to its light performance and overall cut grade.", 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section input-width-full filter_inner">
                            <div id="table-range" class="slider"></div>
                            <div class="input-div">
                                <input type="number" class="table_inp" name="min_table" id="min_table" value=""
                                    step="0.01" />
                                <input type="number" class="table_inp" name="max_table" id="max_table" value=""
                                    step="0.01" />
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 col-md-6 more-filters">
                    <div class="filter_div filter__slider depth__filter">
                        <div class="filter-heading"><?php echo esc_html__('Depth', 'diamond-ring-builder-jewelry');?> %
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title="<?php echo esc_attr__("The height-to-diameter ratio measures a diamond's height from culet to table, impacting its brilliance and fire.", 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section input-width-full filter_inner">
                            <div id="depth-range" class="slider"></div>
                            <div class="input-div">
                                <input type="number" class="depth_inp" name="min_depth" id="min_depth" value=""
                                    step="0.01" />
                                <input type="number" class="depth_inp" name="max_depth" id="max_depth" value=""
                                    step="0.01" />
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 col-md-6 more-filters">
                    <div class="filter_div filter__slider lw-ratio__filter">
                        <div class="filter-heading"><?php echo esc_html__('L/W Ratio', 'diamond-ring-builder-jewelry');?>
                        <span href="javascript:void(0);" class="info-box" onclick="event.preventDefault();" data-toggle="tooltip" data-placement="top" data-title= "<?php echo esc_attr__("The length-to-width ratio shows how elongated a fancy-shaped diamond appears from above, varying by personal preference.", 'diamond-ring-builder-jewelry'); ?>">
                                <img class="info-icon pointer-image" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/info.png" alt="info-icon">
                        </span></div>
                        <div class="slider-section  input-width-full filter_inner">
                            <div id="lw-ratio-range" class="slider"></div>
                            <div class="input-div">
                                <input type="number" class="lw_ratio_inp" name="min_lw-ratio" id="min_lw-ratio" value=""
                                    step="0.01" />
                                <input type="number" class="lw_ratio_inp" name="max_lw-ratio" id="max_lw-ratio" value=""
                                    step="0.01" />
                            </div>
                        </div>
                    </div>
                </div>

                
                <div class="col-lg-4 col-md-6 more-filters">
                    <?php if(count($labs) > 1) { ?>
                        <div class="filter_div filter__slider lw-ratio__filter">
                            <div class="filter-heading"><?php echo esc_html__('Lab', 'diamond-ring-builder-jewelry');?></div>

                            <?php
                                    $preSelectedLabs = array();
                                    if (isset($_GET['labFilter'])) {
                                        $preSelectedLabs = explode(',', sanitize_text_field(wp_unslash($_GET['labFilter'])));
                                    }
                                ?>
                            <div class="lab_checkbox">
                                <?php foreach($labs as $lab) { ?>
                                <div> 
                                    <label class="360-view-gem checkbox__container">
                                        <input type="checkbox"class="labclass" value="<?php echo esc_attr($lab)?>"
                                            <?php echo esc_attr(in_array($lab, $preSelectedLabs) ? 'checked' : '');?>>
                                            <div class="checkmark"></div>
                                        <?php echo esc_html($lab);?>
                                    </label>
                                </div>
                                <?php } ?>
                            </div>
                        </div>
                    <?php } ?>
                </div>
                <?php
                }
            ?>
                <div class="col-lg-4 col-md-6">
                    <div class="kirb-filter-advance-block" style="<?php echo esc_attr($current_category == 'COLORED DIAMONDS' ? 'display:none;' : '');?>">
                        <label class="kirb_reset_filters"><?php echo esc_html__('CLEAR FILTER', 'diamond-ring-builder-jewelry');?></label>
                        <?php 
                        if($current_category != 'GEMSTONE') { ?>
                        <div class="moreless__div">
                            <button class="advanced-filter moreless__btn more-filter-span"><?php echo esc_html__('MORE FILTERS', 'diamond-ring-builder-jewelry');?> +</button>
                        </div>
                        <?php }else{
                            echo wp_kses_post('<div></div>');
                        } ?>

                    </div>
                </div>

                <div class="moreless__div">
                    <div class="keyideas-logo" id="keyideas-logo-main"></div>      
                </div>

            </div>

        </div>

        <div class="main-section-img mt-5">
            <div class="Product-tab_main">
                <div class="nav nav-tabs tab-section kirb-mobile-listing-tabs" id="main_tabs">
                    <div class="tab-section-btn nav-link active" data-bs-toggle="tab" data-bs-target="#all_diamond"
                            id="all_diamond_label" aria-selected="true"><?php echo esc_html__('All Results', 'diamond-ring-builder-jewelry');?></div>
                    <div class="tab-section-btn nav-link " data-bs-toggle="tab" data-bs-target="#recently-view" aria-selected="false"
                            id="kirb_recently_view_tab"><span id="recently_view_label"><?php echo esc_html__('Recently Viewed', 'diamond-ring-builder-jewelry');?></span><span class="tab_notify_popup"><?php echo esc_html__('This space is waiting for your favorite picks. Browse now to fill it up with treasures!', 'diamond-ring-builder-jewelry');?></span></div>
                    <div class="tab-section-btn nav-link " data-bs-toggle="tab" data-bs-target="#comparison" aria-selected="false"
                            id="kirb_comparison_tab"><span id="comparison_label"><?php echo esc_html__('Compare', 'diamond-ring-builder-jewelry');?></span><span class="tab_notify_popup tab_notify_popup_cmp">
                                <?php 
                                    $cmp_img_tag = '<img width="20px" src="'.esc_url(KIRB_PLUGIN_DIR . '/assets/images/comparizon-icon.svg') . '" alt="">';
                                    $compare_lbl_text = esc_html('Click the {{KIRBD}} icon next to your favorite stones to compare.');
                                    $compare_lbl_text = str_replace('{{KIRBD}}', $cmp_img_tag, $compare_lbl_text);
                                    echo wp_kses_post($compare_lbl_text);
                                ?>
                        </span></div>
                </div>

                <div class="kirb-select-filter-show kirb-select-filter--mobile" style="display:none;"></div>

                <div class="show__short short-margin-show kirb_search_bar_strip">
                    <div class="short">
                        <div class="d-flex search-section">
                            <div class="input-wraper diam-listing-search-btn">
                                <input type="search" class="w-full search-input-txt"
                                    placeholder="<?php echo esc_html__('Search', 'diamond-ring-builder-jewelry')?> <?php echo esc_html__('Stock', 'diamond-ring-builder-jewelry')?>"
                                    id="kirb_search_txt">
                                <button class="btn btn-search w-full" id="kirb_search_btn"><i
                                        class="ri-search-line"></i></button>
                            </div>
                        </div>


                        <div class="grid-list-tab Product-List__tab nav nav-tabs">
                            <button class="kirb_mobile__filter fill__image kirb_openFilter">
                                <img class="" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/filter-app1.svg" loading="lazy" alt="Filter" width="20" height="20" >
                            </button>
                            <?php if(!wp_is_mobile() || (wp_is_mobile() && $kirb_mob_grid && $kirb_mob_grid['enabled'])) { ?>
                                <div class="grid-list-btn nav-link active grid-view-options" data-bs-toggle="tab"
                                    data-bs-target="#griddesign" aria-selected="true">
                                    <img src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/grid-view-icon.svg" width="30"
                                        height="30" class="image " loading="lazy">
                                </div>
                            <?php } ?>
                            <div class="grid-list-btn list_btn nav-link list-view-options" data-bs-toggle="tab"
                                data-bs-target="#listdesign" aria-selected="false">
                                <img src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/list-view-icon.svg" width="30"
                                    height="30" class="image" loading="lazy">
                            </div>
                        </div>

                        <div class="d-flex align-items-center">
                            <div class="sort-width"><?php echo esc_html__('Sort By', 'diamond-ring-builder-jewelry');?>:</div>
                            <select class="sortby" filter_name="orderby" name="sortby" id="kirb_prods_sort">
                                <?php     
                                    if($current_category == 'GEMSTONE') {
                                        $sort_by_values = array('popular', 'Orderbyprice-asc', 'Orderbyprice-desc', 'Orderbycarat-asc', 'Orderbycarat-desc');
                                        $sort_by_labels = array(esc_html__('Popular', 'diamond-ring-builder-jewelry'), esc_html__('Price: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Price: High to Low', 'diamond-ring-builder-jewelry'), esc_html__('Carat: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Carat: High to Low', 'diamond-ring-builder-jewelry'));
                                    }else if($current_category == 'COLORED DIAMONDS') {
                                        $sort_by_values = array('popular', 'Orderbyprice-asc', 'Orderbyprice-desc', 'Orderbycarat-asc', 'Orderbycarat-desc','Orderbyclarity-asc', 'Orderbyclarity-desc');
                                        $sort_by_labels = array(esc_html__('Popular', 'diamond-ring-builder-jewelry'), esc_html__('Price: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Price: High to Low', 'diamond-ring-builder-jewelry'), esc_html__('Carat: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Carat: High to Low', 'diamond-ring-builder-jewelry'),esc_html__('Clarity: Low to High', 'diamond-ring-builder-jewelry'), 
                                        esc_html__('Clarity: High to Low', 'diamond-ring-builder-jewelry'));
                                    } else {
                                        $sort_by_values = array('popular', 'Orderbyprice-asc', 'Orderbyprice-desc', 'Orderbycarat-asc', 'Orderbycarat-desc', 'Orderbycolor-asc', 'Orderbycolor-desc', 'Orderbyclarity-asc', 'Orderbyclarity-desc', 'Orderbycut-asc', 'Orderbycut-desc');

                                        $sort_by_labels = array( esc_html__('Popular', 'diamond-ring-builder-jewelry'), esc_html__('Price: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Price: High to Low', 'diamond-ring-builder-jewelry'), esc_html__('Carat: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Carat: High to Low', 'diamond-ring-builder-jewelry'), esc_html__('Color: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Color: High to Low', 'diamond-ring-builder-jewelry'), esc_html__('Clarity: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Clarity: High to Low', 'diamond-ring-builder-jewelry'), esc_html__('Cut: Low to High', 'diamond-ring-builder-jewelry'), esc_html__('Cut: High to Low', 'diamond-ring-builder-jewelry'));
                                    }

                                    $default_sort = isset($addons_data['default_sort']['select']) ? $addons_data['default_sort']['select'] : 'popular' ;   
                                    
                                    if (!in_array($default_sort, $sort_by_values, true)) {
                                        $default_sort = 'popular';
                                    }
                                    
                                    $i = 0;
                                    foreach($sort_by_values as $sort) {
                                        $selected = '';
                                        if(!isset($_GET['sort']) && $default_sort == $sort) {
                                            $selected = 'selected';
                                        } else {
                                            $selected = isset($_GET['sort']) && sanitize_text_field(wp_unslash($_GET['sort'])) == $sort ? 'selected' : '';
                                        }

                                ?>
                                        <option value="<?php echo esc_attr($sort)?>" <?php echo esc_attr($selected)?>><?php echo esc_html($sort_by_labels[$i]);?></option>
                                <?php 
                                        $i++;
                                    }
                                ?>
                                <input id="default_sort_val" type="hidden" value="<?php echo esc_attr($default_sort) ?>">
                            </select>
                        </div>
                    </div>
                </div>

            </div>
            <div class="kirb-select-filter-show  kirb-select-filter--laptop" style="display:none;"></div>
            <div class="kirb_listing_loader_top loading-overlay__spinner listing_loader" style="display:none;">
                <div class="kirb_dots_loader">
                    <div class="loader3">
                        <span class="circle1"></span>
                        <span class="circle1"></span>
                        <span class="circle1"></span>
                    </div>
                </div>
            </div>

            <div class="kirb-main-tab-section tab-content ">
                <div id="all_diamond" class="tab-pane show active">
                    <div class="tab-content" id="diamond_content">
                        <div id="griddesign" class="tab-pane active" >
                            <div class="diamond-section">
                                <div class="kirb-diamond-grid list-gap-pad" id="kirb_product_grid">
                                    <?php
                                        $grid_data = kirb_initial_diamond_listing('grid',  $current_category, $filter_options[$current_category]);
                                        echo wp_kses($grid_data['html'], 'kirb_ui', ['http','https']);
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div id="listdesign" class="tab-pane">
                            <div class="kirb-diamond-list" id="kirb_product_list_wrapper">
                                <?php
                                    $list_data = kirb_initial_diamond_listing('list', $current_category, $filter_options[$current_category]);
                                    echo wp_kses($list_data['html'], 'kirb_ui', ['http','https']);
                                ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="recently-view" class="tab-pane">
                    <div class="kirb-diamond-list" id="">
                        <table id="kirb_recent_table">
                            <thead>
                                <tr class="heading">
                                    <?php echo wp_kses(kirb_getDiamondListingHeaders('rc',$current_category), 'kirb_ui', ['http','https']);?>
                                </tr>
                            </thead>
                            <tbody id="kirb_recent_prods">
                            </tbody>
                        </table>
                        <div class="kirb_empty_msg" style="display:none;" id="kirb_recent_empty_msg">
                        <?php echo esc_html('Sorry, you do not have any recent view ' .($is_gemstone?'gemstones':'diamonds').".");?>
                        </div>
                    </div>
                </div>

                <div id="comparison" class="tab-pane">
                    <div class="kirb-diamond-list" id="">
                        <table id="kirb_compare_table">
                            <thead>
                                <tr class="heading">
                                    <?php echo wp_kses(kirb_getDiamondListingHeaders('rc',$current_category), 'kirb_ui', ['http','https']);?>
                                </tr>
                            </thead>
                            <tbody id="kirb_compare_prods">
                            </tbody>
                        </table>
                        <?php
                            $dia_type = $is_gemstone ? 'gemstones':'diamonds';
                            $data_not_found = esc_html('Sorry, you do not have any '.$dia_type.' to compare.');
                            
                        ?>
                        <div class="kirb_empty_msg" style="display:none;" id="kirb_compare_empty_msg">
                            <?php echo esc_html($data_not_found);?>
                        </div>
                    </div>
                </div>
            </div>
            <div class="kirb_listing_loader_below loading-overlay__spinner listing_loader" style="display:none;">
                <div class="kirb_dots_loader">
                    <div class="loader3">
                        <span class="circle1"></span>
                        <span class="circle1"></span>
                        <span class="circle1"></span>
                    </div>
                </div>
            </div>
        </div>
        <?php }else{ ?>
        <div class="alert alert-danger" role="alert">
            <strong><?php echo esc_html__('API Error!', 'diamond-ring-builder-jewelry');?></strong> <?php echo esc_html__('Please check the API settings.', 'diamond-ring-builder-jewelry');?>
        </div>
        <?php } ?>
    </div>

    <div class="kirb-diamond-modal">
        <div class="choose-bttn-popup modal-static modal fade" id="kirb-choose-diamond-modal" tabindex="-1" aria-hidden="true" data-backdrop="static" data-keyboard="true">
            <?php
                if(!$kirb_disable_byor) {
            ?>
                <div class="modal-dialog modal-dialog-centered">
                    <div class="kirb-modal-content" >
                        <div class="pera-popup modal-title styleHeadingTag"><?php echo esc_html__('How would you like to proceed?', 'diamond-ring-builder-jewelry');?></div>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

                        <?php 
                            global $byor_data;
                            if($byor_data && $byor_data['diamond_uid'] == "0") {
                        ?>
                                <span class="btn btn__blue choose--btn kirb_diamond_byor mt-2 choose_setting_btn diamond-popup-btn-width kirb_modal_dynamic_btn_id" onclick="kirb_diamond_byor(this);" data-type="ring"><?php echo esc_html__('ADD TO SETTING', 'diamond-ring-builder-jewelry');?></span>
                        <?php
                            }else{
                        ?>
                            <span class="btn btn__blue choose--btn kirb_diamond_byor mt-2 choose_setting_btn diamond-popup-btn-width kirb_modal_dynamic_btn_id" onclick="kirb_diamond_byor(this);" data-type="ring"><?php echo esc_html__('ADD TO RING', 'diamond-ring-builder-jewelry');?></span>
                        <?php } ?>
                        <span class="btn btn__blue choose--btn kirb_diamond_choose add_cart_btn diamond-popup-btn-width kirb_modal_dynamic_btn_id kirb_modal_add_cart_btn disabled">ADD <?php echo $current_category == 'GEMSTONE'?'GEMSTONE':'DIAMOND';?> <?php echo esc_html__('TO THE CART', 'diamond-ring-builder-jewelry');?></span>
                        <a href="<?php echo esc_url(site_url('/cart')); ?>" class="kirb_modal_go_cart_btn"><span class="btn btn__blue choose--btn"><?php echo esc_html__('GO TO CART', 'diamond-ring-builder-jewelry');?></span></a>
                    </div>
                </div>
            <?php } ?>
        </div>
    </div>
</section>
<?php 
    if(!$api_error) {
        wp_localize_script( 'kirb-diamond-listing-page-script', 'DStat', [
                'diamond_listing_global' => $grid_data['stats']
            ]
        );
        
        ob_start();
        include_once('listing-page-modals/view-360-popup.php');
        $view_360_popup = ob_get_clean();

        wp_localize_script( 'kirb-diamond-listing-page-script', 'DViewModals', [
            'popup_360_code' => $view_360_popup
        ]
    );
} 
?>
