<?php 
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    global $kirb_page_ids, $kirb_filters_data, $kirb_filter_values_translation_mapping;
    $current_category = kirb_getDiamondCategory($diamond['category_id'], $kirb_filters_data, false);
    $diamond_url = esc_url(kirb_getPageUrlById($kirb_page_ids['diamond-detail']) . kirb_prepareDiamondSlug($diamond) . '/');
?>

<div class="prod-item" id="kirb_grid_item_<?php echo esc_attr($diamond['_id']);?>">
    
    <div class="kirb-diamond-details-info-popup" style="display: none;" data-popup-id="<?php echo esc_attr($diamond['_id']);?>">
        <span class="kirb-copy-btn"><img src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/copy-icon.png" loading="lazy" data-target="<?php echo esc_attr($diamond['_id']);?>" onclick="kirb_copy_info(this);"></span>
        <img class="cross-btn" src="<?php echo esc_url(KIRB_PLUGIN_DIR . '/assets/images/cross-grey.svg'); ?>" loading="lazy" data-target="<?php echo esc_attr($diamond['_id']);?>" data-onclick="kirb_toggle_info_popup(this)">
        <?php 
            $sku_key           = esc_html__('SKU', 'diamond-ring-builder-jewelry');
            $stock_no_key      = esc_html__('Stock Number', 'diamond-ring-builder-jewelry');
            $carat_weight_key  = esc_html__('Carat Weight', 'diamond-ring-builder-jewelry');
            $color_key         = esc_html__('Color', 'diamond-ring-builder-jewelry');
            $cut_key           = esc_html__('Cut', 'diamond-ring-builder-jewelry');
            $clarity_key       = esc_html__('Clarity', 'diamond-ring-builder-jewelry');
            $polish_key        = esc_html__('Polish', 'diamond-ring-builder-jewelry');
            $symm_key          = esc_html__('Symmetry', 'diamond-ring-builder-jewelry');
            $fluor_key         = esc_html__('Fluorescence', 'diamond-ring-builder-jewelry');
            $meas_key          = esc_html__('Measure (mm)', 'diamond-ring-builder-jewelry');
            $lab_report_key    = esc_html__('Lab Report', 'diamond-ring-builder-jewelry');
            $gem_type_key      = esc_html__('Gemstone Type', 'diamond-ring-builder-jewelry');
            $intensity_key     = esc_html__('Intensity', 'diamond-ring-builder-jewelry');
            $price_key         = esc_html__('Price', 'diamond-ring-builder-jewelry');
            $location_key      = esc_html__('Location', 'diamond-ring-builder-jewelry');

            $dlist = array(
                $sku_key => $diamond['stone_no'],
                $stock_no_key => $diamond['sku'],
                $carat_weight_key => number_format($diamond['weight'], 2) . 'ct',
                $color_key => esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['color']))] ?? $diamond['color']),
                $location_key => $diamond['location'],
                $price_key => '₹'.number_format($diamond['saleamt']),
            );
            


            if ($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
                $dlist[$cut_key] = esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['cut'])] ?? $diamond['cut']);
                $dlist[$clarity_key] = $diamond['clarity'];
                $dlist[$polish_key] = esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['polish'])] ?? $diamond['polish']);
                $dlist[$symm_key] = esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['symm'])] ?? $diamond['symm']);
                $dlist[$fluor_key] = esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['fluor'])] ?? $diamond['fluor']);
                $dlist[$meas_key] = str_replace("-", "*", $diamond['measurement']);
                $dlist[$lab_report_key] = $diamond['lab'];
                $dlist[$location_key] = $diamond['location'];
                $dlist[$price_key] = '₹'.number_format($diamond['saleamt']);

            } else if ($current_category == 'GEMSTONE' || $current_category == 'COLORED DIAMONDS') {
                $dlist[$meas_key] = str_replace("-", "*", $diamond['measurement']);
                $dlist[$lab_report_key] = esc_html(__('Non-Cert', 'diamond-ring-builder-jewelry'));

                if ($current_category == 'GEMSTONE') {
                    $dlist[$gem_type_key] = esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['gemType']))] ?? $diamond['gemType']);
                } else if ($current_category == 'COLORED DIAMONDS') {
                    $dlist[$intensity_key] = esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['intensity']))] ?? $diamond['intensity']);
                    $dlist[$clarity_key] = $diamond['clarity'];
                }
            }

            
            foreach($dlist as $key => $value) {
                echo wp_kses_post('<div>');
                echo '<span>' . esc_html($key) . ':</span>';
                echo '<span>' . esc_html($value) . '</span>';
                echo wp_kses_post('</div>');
            }

        ?>
    </div>
    <div class="kirb-360-icon">
        <?php if(!empty($diamond['videourl'])) { ?>
            <div class="item-360">
                <img src="<?php echo esc_url(KIRB_PLUGIN_DIR . '/assets/images/360-icon.svg'); ?>" alt="">
            </div>
            <div class="item-360 view-360" data-bs-toggle="modal" data-bs-target="#view-360"  data-id="<?php echo esc_attr($diamond['_id']);?>" data-video-url="<?php echo esc_url($diamond['videourl']);?>" data-onclick="kirb_load_360(this)" data-title="<?php echo esc_attr(kirb_string_split_translate($diamond['title'], $kirb_filter_values_translation_mapping));?>">
                <i class="ri-search-line"></i>
            </div>
        <?php } ?>
    </div>
    
    <?php if($kirb_filters_data['sample']) { ?>
        <div class="sample-div"><?php echo esc_html('Sample');?></div>
    <?php } ?>
    <div class="image-div" id="image-div<?php echo esc_attr($diamond['_id']);?>" data-id="<?php echo esc_attr($diamond['_id']);?>" data-onmouseenter="kirb_toggle_360_video(this,true)" data-onmouseleave="kirb_toggle_360_video(this,false)" data-video="<?php echo esc_url($diamond['videourl']);?>">
        <a href="<?php echo esc_url($diamond_url);?>" class="kirb_vid_toggle_part">
            <img src="<?php echo esc_url(isset($diamond['imageurl']) ? $diamond['imageurl'] : '');?>" onerror="this.src='<?php echo esc_url(kirb_getShapeErrorImage($diamond['shape']));?>';this.onerror=null;this.classList.add('error-image');" loading="lazy">
        </a>
        <iframe src="" frameborder="0" class="kirb-item-grid-iframe" scrolling="no" width="310" height="310" style="display:none;"></iframe>
    </div>
    
    <div class="content-div text-center" data-id="<?php echo esc_attr($diamond['_id']);?>">
        <div class="kirb-content-heading">
            <a href="<?php echo esc_url($diamond_url);?>">
                <?php echo esc_html(kirb_string_split_translate($diamond['title'], $kirb_filter_values_translation_mapping));?>
            </a>
            <img class="kirb-info-icon" src="<?php echo esc_url(KIRB_PLUGIN_DIR . '/assets/images/i_icon.svg'); ?>" alt="" data-target="<?php echo esc_attr($diamond['_id']);?>" data-onclick="kirb_toggle_info_popup(this)">
        </div>
        <div class="price">
            <span><?php echo esc_html(kirb_format_price($diamond['saleamt'], $kirb_site_config));?></span>
             <?php 
                if($diamond['compPrice'] > $diamond['saleamt']) {
                    echo '<span><del>' . esc_html(kirb_format_price($diamond['compPrice'], $kirb_site_config)) . '</del></span>';
                }
             ?>
            <div class="comparizon-div kirb_compare_btn"  data-id="<?php echo esc_attr($diamond['_id']);?>">
                <img src="<?php echo esc_url(KIRB_PLUGIN_DIR . '/assets/images/comparizon-icon.svg'); ?>" alt="" class="kirb-dynamic-icon">
            </div>
        </div>
    </div>
</div>
