<?php
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    global $kirb_page_ids, $kirb_filters_data, $kirb_filter_values_translation_mapping;
    $is_rc_view = isset($config['type']);
    $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) . '/');
?>
<tr class="diamond-list kirb-listing-item" data-id="diamond-list-<?php echo esc_attr($is_rc_view ? ($diamond['_id'] . $config['type']) : $diamond['_id']); ?>">
    <td class="product-list-view-img product__img position-relative">
        <div class="logo-list-img logo-list-img-laptop">
            <img src="<?php echo isset($diamond['imageurl']) ? esc_url($diamond['imageurl']) : '';?>" onerror="this.src='<?php echo esc_url(kirb_getShapeErrorImage($diamond['shape']));?>';this.onerror=null;" class="mobile-hide img-fluid" alt="product images" width="60" loading="lazy">
        </div>
        <div class="diamond-shape-icon <?php echo esc_attr(strtolower($diamond['shape'])); ?>"></div>
    </td>
    <td class="position-relative pointer_c">
        <div class="grid__view--viewi">
            <div class=" position-relative">
                <span class="product__list--viewi">
                <?php if(!empty($diamond['videourl'])) { ?>
                    <span data-bs-toggle="modal" data-bs-target="#view-360" class="view-360" data-video-url="<?php echo esc_url($diamond['videourl']);?>" data-title="<?php echo esc_attr(kirb_string_split_translate($diamond['title'], $kirb_filter_values_translation_mapping));?>" data-onclick="kirb_load_360(this)">
                    <div class="three-sixty_wrapper"><span class="bordered-icon-360-view-360"></span><span class="icon__text">360°</span></div>    
                <?php }else{ 
                    echo wp_kses_post('<span></span>'); //Remove the N/A when there is no 360 rotation
                } ?>
                </span>
            </div>
        </div>
    </td>
    <?php
        $rc_type = "";
        if($is_rc_view) {
            $rc_type = $config['type'];
        }
    ?>
    <td class="tbl_price">
        <span><?php echo esc_html(kirb_format_price($diamond['saleamt'], $kirb_site_config));?></span>
    </td>
    <td class="product-list-view-shape"><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['shape']] ?? $diamond['shape']);?></td>
    <td><?php echo esc_html(number_format($diamond['weight'],2));?></td>
    <td  class="product-list-view-color"><?php echo esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['color']))] ?? ucfirst(strtolower($diamond['color'])));?></td>
    <?php if (!$is_rc_view) { ?>
        <?php if ($filters['category'] == 'GEMSTONE') { ?>
            <td><?php echo esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['gemType'])] ?? ucfirst($diamond['gemType'])); ?></td>
        <?php } else { ?>
            <td class="product-list-view-clarity"><?php echo empty($diamond['clarity']) ? "-" : esc_html($diamond['clarity']); ?></td>
            <?php if ($filters['category'] != 'COLORED DIAMONDS') { ?>
                <td class="product-list-view-cut"><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['cut']] ?? $diamond['cut']);
            } ?></td>
            <?php if ($current_category == 'COLORED DIAMONDS') { ?>
                <!-- removed the class named mobile-view assigned to the td -->
                <td><?php echo esc_html($diamond['intensity']); ?></td>
            <?php } ?>
        <?php } ?>
        <td class="product-list-view-lab"><?php echo esc_html($diamond['lab']); ?></td>
        <td class="compare__icon--input">
            <div class="compare__icon 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"
                loading="lazy" alt="compare" width="30" height="30" class="kirb-dynamic-icon <?php echo esc_attr($rc_type == 'compare' ? 'kirb_highlight_img_btn' : ''); ?>">
            </div>
        </td>
    <?php } else { ?>
        <?php
        if ($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
            ?>
            <td class="product-list-view-cut"><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['cut']] ?? $diamond['cut']); ?></td>
        <?php } ?>
        <?php if ($current_category != 'GEMSTONE') { ?>
            <td class="product-list-view-clarity"><?php echo empty($diamond['clarity']) ? "-" : esc_html($diamond['clarity']); ?></td>
        <?php } ?>
        <?php if ($current_category == 'GEMSTONE') { ?>
            <td><?php echo esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['gemType'])] ?? ucfirst($diamond['gemType'])); ?></td> <?php } ?>
        <?php if ($current_category == 'COLORED DIAMONDS') { ?>
            <td class="mobile-view"><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['intensity']] ?? $diamond['intensity']); ?></td>
        <?php } ?>
        <td class="product-list-view-lab"><?php echo esc_html($diamond['lab']); ?></td>;
        <td class="compare__icon--input">
            <div class="compare__icon kirb_compare_btn" data-onclick="kirb_compare_prod(this,<?php echo $rc_type == 'compare' ? 'true' : 'false'; ?>)" data-id="<?php echo esc_attr($diamond['_id']); ?>">
                <img src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/comparizon-icon.svg"
                loading="lazy" alt="compare" width="30" height="30" class="kirb-dynamic-icon <?php echo esc_attr($rc_type == 'compare' ? 'kirb_highlight_img_btn' : ''); ?>">
            </div>
        </td>
    <?php } ?>


    <td class="kirb-product-list-table-dropdown" data-onclick="kirb_showProductDetails(this,'list')" data-target="<?php echo esc_attr($is_rc_view ? ($diamond['_id'] . $config['type']) : $diamond['_id']); ?>">
        <img class="list-arrow" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/list-expand-arrow.png" alt="">
    </td>

</tr>
<tr class="diamond-mobile-visible-only">
    <td class="diamond-mobile-visible" style="display: none;" data-id="details-accord-mob-<?php echo esc_attr($is_rc_view ? ($diamond['_id'] . $config['type']) : $diamond['_id']); ?>">
        <div class="diamond-mobile-card-body">
            <div class="diamond-mobile-card-body-image">
                <img src="<?php echo esc_url($diamond['imageurl']); ?>" onerror="this.src='<?php echo esc_url(kirb_getShapeErrorImage($diamond['shape'])); ?>';this.onerror=null;this.style.width='auto';" alt="" loading="lazy">
                <button class="details-btn">
        <a href="<?php echo esc_url($diamond_url); ?>">
                        <?php echo esc_html('View Full Detail')?>
                    </a>
                </button>
                <?php if(!$kirb_disable_byor) { ?>
                    <button class="choose-diam-btn">
                        <?php 
                            $type = isset($config['type']) ? $config['type'] : "result"; 
                        ?>
                        <a href="#" class="viewDiamond_btn" data-bs-toggle="modal" data-bs-target="#kirb-choose-diamond-modal" data-id="<?php echo esc_attr($diamond['_id']); ?>" data-img="choose-bttn" data-onclick="kirb_update_modal(this)" data-incart="false">
                            <?php echo $current_category == "GEMSTONE" ? esc_html__('Choose Gemstone', 'diamond-ring-builder-jewelry'):esc_html__('Choose Diamond', 'diamond-ring-builder-jewelry'); ?>
                        </a>
                    </button>
                <?php }else{ ?>
                    <button class="choose-diam-btn">
                        <a href="#" class="viewDiamond_btn" data-id="<?php echo esc_attr($diamond['_id']); ?>">
                            <?php echo esc_html__('Add To Cart', 'diamond-ring-builder-jewelry'); ?>
                        </a>
                    </button>
                <?php } ?>
            </div>
            
            <div class="diamond-mobile-card-body-details">
                <div class="diam-prop-100"><span><?php echo esc_html('Stock Number') ?>:</span><span><?php echo esc_html($diamond['stone_no']); ?></span></div> 
                <div class="diam-prop-100"><span><?php echo esc_html('Shape') ?>:</span><span><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['shape']] ?? $diamond['shape']);?></span></div> 
                <div class="diam-prop-100"><span><?php echo esc_html('Color') ?>:</span><span><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['color']] ?? $diamond['color']);?></span></div>
                <?php if($current_category != "GEMSTONE") {?>
                    <div class="diam-prop-100 "><span><?php echo esc_html('Clarity') ?>:</span><span><?php echo isset($diamond['clarity']) ? esc_html($diamond['clarity']) : '-'; ?></span></div>
                <?php }?>
                <div class="diam-prop-100"><span><?php echo esc_html('Cut') ?>:</span><span><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['cut']] ?? $diamond['cut']);?></span></div>
                <div class="diam-prop-100"><span><?php echo esc_html('Lab Report') ?>:</span><span><?php echo esc_html($diamond['lab']) ;?></span></div> 
                <div class="diam-prop-100"><span><?php echo esc_html('Measurements') ?>:</span><span><?php echo esc_html($diamond['measurement']);?>mm</span></div>
                <?php if ($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') { ?>
                    <div class="diam-prop-100"><span><?php echo esc_html('Depth') ?>:</span><span><?php echo esc_html($diamond['td']);?></span></div>
                <?php } ?>
                <?php if($current_category != "GEMSTONE" && $current_category != "COLORED DIAMONDS") {?>
                    <div class="diam-prop-100  "><span> <?php echo esc_html('Table') ?>:</span><span><?php echo esc_html($diamond['ta']);?></span></div>
                    <div class="diam-prop-100  "><span><?php echo esc_html('Polish') ?>:</span><span><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['polish']] ?? $diamond['polish']);?></span></div> 
                    <div class="diam-prop-100  "><span><?php echo esc_html('Symmetry') ?>:</span><span><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['symm']] ?? $diamond['symm']);?></span></div>  
                    <div class="diam-prop-100"><span><?php echo esc_html('L/W Ratio') ?>:</span><span><?php echo esc_html($diamond['lw_ratio']);?></span></div> 
                    <div class="diam-prop-100"><span><?php echo esc_html('Fluorescence') ?>:</span><span><?php echo esc_html($kirb_filter_values_translation_mapping[$diamond['fluor']] ?? $diamond['fluor']);?></span></div>
                <?php }?>
                <div class="diam-prop-100"><span><?php echo esc_html('Location') ?>:</span><span><?php echo isset($diamond['location']) && !empty($diamond['location']) ? esc_html($diamond['location']) : '-';?></span></div>  
            </div>
        </div>
    </td>
</tr>

<tr class="diamond-laptop-visible-only kirb-details-accord-pc" style="display: none;" data-id="details-accord-<?php echo esc_attr($is_rc_view ? ($diamond['_id'] . $config['type']) : $diamond['_id']); ?>">
    <td class="list-view-diamond-details-dropdown" colspan="100">
        <div class="inner-list-view-diamond-details">
            <div style="display: flex;flex-direction: column;padding: 0;margin: 30px;gap: 20px;">
                <div class="image-section" data-onmouseenter="kirb_toggle_360_video(this,true)" data-onmouseleave="kirb_toggle_360_video(this,false)" data-video="<?php echo esc_url($diamond['videourl']);?>">
                    <img src="<?php echo isset($diamond['imageurl']) ? esc_url($diamond['imageurl']) : '';?>" onerror="this.src='<?php echo esc_url(kirb_getShapeErrorImage($diamond['shape']));?>';this.onerror=null;"
                        alt="" class="kirb_vid_toggle_part">
                    <iframe src="" frameborder="0" class="kirb-item-grid-iframe" style="display:none;"></iframe>
                    <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>
                </div>
            </div>
            <div class="diamond-details-content-section">
                <div class="price-compare-section">
                    <p><?php echo esc_html(kirb_format_price($diamond['saleamt'], $kirb_site_config));?></p>
                    <div class="diamond-details-compare">
                        <div class="compare__icon kirb_compare_btn" onclick="kirb_compare_prod(this,<?php echo $rc_type == 'compare' ? 'true' : 'false'; ?>)" data-id="<?php echo esc_attr($diamond['_id']); ?>">
                            <img width="30" height="30" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/comparizon-icon.svg"
                            loading="lazy" alt="compare" class="kirb-dynamic-icon <?php echo esc_attr($rc_type == 'compare' ? 'kirb_highlight_img_btn' : ''); ?>">
                        </div>
                        <div data-onclick="kirb_showProductDetails(this,'accord')" data-target="<?php echo esc_attr($is_rc_view ? ($diamond['_id'] . $config['type']) : $diamond['_id']); ?>">
                            <img width="15px" height="15px" class="list-arrow rotate" src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/list-expand-arrow.png" >
                        </div>
                    </div>
                </div>
                <div class="diamond-details-section">
                    <?php 


                        $sku_key = esc_html__('SKU', 'diamond-ring-builder-jewelry');
                        $shape_key = esc_html__('Shape', 'diamond-ring-builder-jewelry'); 
                        $carat_key = esc_html__('Carat', 'diamond-ring-builder-jewelry'); 
                        $color_key = esc_html__('Color', 'diamond-ring-builder-jewelry'); 
                        $clarity_key = esc_html__('Clarity', 'diamond-ring-builder-jewelry'); 
                        $cut_key = esc_html__('Cut', 'diamond-ring-builder-jewelry'); 
                        $polish_key = esc_html__('Polish', 'diamond-ring-builder-jewelry'); 
                        $stock_no_key = esc_html__('Stock Number', 'diamond-ring-builder-jewelry'); 
                        $meas_key = esc_html__('Measurements (mm)', 'diamond-ring-builder-jewelry'); 
                        $symm_key = esc_html__('Symmetry', 'diamond-ring-builder-jewelry');
                        $fluor_key = esc_html__('Fluorescence', 'diamond-ring-builder-jewelry');
                        $table_key = esc_html__('Table %', 'diamond-ring-builder-jewelry');
                        $depth_key = esc_html__('Depth %', 'diamond-ring-builder-jewelry');
                        $lw_ratio_key = esc_html__('L/W Ratio', 'diamond-ring-builder-jewelry');
                        $lab_report_key = esc_html__('Lab Report', 'diamond-ring-builder-jewelry');
                        // $location_key = esc_html__('Location', 'diamond-ring-builder-jewelry');
                        $gem_key = esc_html__('Gemstone Type', 'diamond-ring-builder-jewelry'); 
                        $intensity_key = esc_html__('Intensity', 'diamond-ring-builder-jewelry'); 

                        $dlist1 = array();
                        $dlist2 = array();
                        $dlist3 = array();

                        if($current_category != 'GEMSTONE' && $current_category != 'COLORED DIAMONDS') {
                            $dlist1 = array(
                                $sku_key => $diamond['stone_no'], 
                                $stock_no_key => $diamond['sku'], 
                                $shape_key => esc_html($kirb_filter_values_translation_mapping[$diamond['shape']] ?? $diamond['shape']), 
                                $carat_key => number_format($diamond['weight'],2) . "ct", 
                                $color_key => ucfirst(strtolower($diamond['color'])), 
                                $clarity_key => $diamond['clarity']
                            );
                            $dlist2 = array(
                                $cut_key => esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['cut'])] ?? $diamond['cut']), 
                                $polish_key => esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['polish'])] ?? $diamond['polish']), 
                                $symm_key => esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['symm'])] ?? $diamond['symm']), 
                                $fluor_key => esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['fluor'])] ?? $diamond['fluor']), 
                                $meas_key => str_replace("-","*",$diamond['measurement'])
                            );
                            $dlist3 = array(
                                $table_key => number_format($diamond['ta'],1), 
                                $depth_key => number_format($diamond['td'],1), 
                                $lw_ratio_key => $diamond['lw_ratio'], 
                                $lab_report_key => $diamond['lab'], 
                                esc_html('Location') => isset($diamond['location']) && !empty($diamond['location']) ? $diamond['location'] : '-'
                            );

                        } else if($current_category == 'GEMSTONE') {
                            $dlist1 = array(
                                $sku_key => $diamond['stone_no'], 
                                $stock_no_key => $diamond['sku'], 
                                $shape_key => esc_html($kirb_filter_values_translation_mapping[$diamond['shape']] ?? $diamond['shape']), 
                                $carat_key => number_format($diamond['weight'],2) . "ct", 
                                $color_key => esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['color']))] ?? $diamond['color'])
                            );
                            $dlist2 = array(
                                $gem_key => esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['gemType']))] ?? $diamond['gemType']), 
                                $meas_key => str_replace("-","*",$diamond['measurement']), 
                                $lab_report_key => $diamond['lab'], 
                                esc_html('Location') => isset($diamond['location']) && !empty($diamond['location']) ? $diamond['location'] : '-'
                            );

                        } else if($current_category == 'COLORED DIAMONDS') {
                            $dlist2 = array(
                                $clarity_key => $diamond['clarity'], 
                                $intensity_key => esc_html($kirb_filter_values_translation_mapping[ucfirst(strtolower($diamond['intensity']))] ?? $diamond['intensity']), 
                                $meas_key => str_replace("-","*",$diamond['measurement']), 
                                $lab_report_key => $diamond['lab'], 
                                $fluor_key => esc_html($kirb_filter_values_translation_mapping[ucfirst($diamond['fluor'])] ?? $diamond['fluor']), 
                                esc_html('Location') => isset($diamond['location']) && !empty($diamond['location']) ? $diamond['location'] : '-'
                            );
                        }

                            $copy_text = "";

                            foreach($dlist1 as $key => $value) {
                            $copy_text .= $key. ": " .$value . "\n";
                            }

                            foreach($dlist2 as $key => $value) {
                                $copy_text .= $key. ": " .$value . "\n";
                            }

                             foreach($dlist3 as $key => $value) {
                                $copy_text .= $key. ": " .$value . "\n";
                            }

                    ?>
                    <div class="item-diamond">
                        <?php 
                            foreach($dlist1 as $key => $value) {
                        ?>
                            <p><span><?php echo esc_html($key);?>:</span><span><?php echo esc_html($value);?></span></p>
                        <?php
                            }
                        ?>
                    </div>
                    <div class="item-diamond">
                        <?php 
                            foreach($dlist2 as $key => $value) {
                        ?>
                            <p><span><?php echo esc_html($key);?>:</span><span><?php echo esc_html($value);?></span></p>
                        <?php
                            }
                        ?>
                    </div>
                    <div class="item-diamond">
                        <?php 
                            foreach($dlist3 as $key => $value) {
                        ?>
                            <p><span><?php echo esc_html($key);?>:</span><span><?php echo esc_html($value);?></span></p>
                        <?php
                            }
                        ?>
                    </div>
                </div>
                <div class="btn-diamond-details-section">
                     <?php 
                        $type = isset($config['type']) ? $config['type'] : "result"; 
                     ?>
                    <?php 
                        if(!$kirb_disable_byor) {
                     ?>
                        <button class="btn-add-setting" data-bs-toggle="modal" data-bs-target="#kirb-choose-diamond-modal" data-id="<?php echo esc_attr($diamond['_id']); ?>" data-onclick="kirb_update_modal(this)" data-incart="false">
                            <?php echo $current_category == "GEMSTONE" ? esc_html__('CHOOSE GEMSTONE', 'diamond-ring-builder-jewelry'):esc_html__('CHOOSE DIAMOND', 'diamond-ring-builder-jewelry'); ?>
                        </button>
                    <?php }else{ ?>
                        <button class="btn-add-setting" data-id="<?php echo esc_attr($diamond['_id']); ?>">
                            <?php echo esc_html__('ADD TO CART', 'diamond-ring-builder-jewelry');?>
                        </button>
                    <?php } ?>
                    <a class="view-details" href="<?php echo esc_url($diamond_url); ?>"><?php echo esc_html__('View Details', 'diamond-ring-builder-jewelry');?></a>
                    <span title="Copy" class="copy-button" data-copy="<?php echo esc_attr( $copy_text );?>">
                        <img src="<?php echo esc_url(KIRB_PLUGIN_DIR); ?>/assets/images/copy-icon.png" alt="copy">
                    </span>
                </div>
            </div>
        </div>
    </td>
</tr>
