<?php
if (! defined('ABSPATH')) {
  exit;
}
global $post;
global $product;
$catname = wp_get_post_terms($product->get_id(), 'product_cat', array());
$catlink = get_term_link($catname[0]->term_id, 'product_cat');
$brname = wp_get_post_terms($product->get_id(), 'brands', array());
if (isset($brname[0])) {
  $brlink = get_term_link($brname[0]->term_id, 'brands');
}
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();
$sale_price = $product->get_sale_price();
$normal_price = $product->get_regular_price();
$pr_id = get_the_ID();
$sold_individually = get_post_meta($product->get_id(), '_sold_individually', true);

?>

<div class="d-flex align-items-center justify-content-between">
  
  <ul class="icons d-flex align-items-center">
              <?php if ($options['kaveh_compare_system'] === '1'): ?>
        <li data-bs-toggle="tooltip" title="<?php esc_attr_e('Compare', 'kavehTheme'); ?>" data-bs-placement="left">
          <?php echo do_shortcode('[compare_button id=' . get_the_ID() . ' color="#b3bbc7" background_color="transparent" style="icon_only" class=""]'); ?>
        </li>
      <?php endif; ?>
      <?php if ($options['kaveh_pricechart_system'] === '1'): ?>
        <li>
          <?php echo do_shortcode('[price_chart_button style="icon_only" color="#b3bbc7" bg_color="transparent"]'); ?>
        </li>
      <?php endif; ?>

    <li>
      <a href="javascript:void(0)">
        <i class="isax isax-share5" data-bs-toggle="modal" data-bs-target="#exampleModal"></i>
      </a>
    </li>
    <?php if ($options['kaveh_wishlist_system'] === '1'): ?>
      <li>
        <?php echo do_shortcode('[wlm_button]'); ?>
      </li>
    <?php endif; ?>


  </ul>


</div>
<?php
if ($date_from = get_post_meta($pr_id, '_sale_price_dates_from', true)) {
  $sale_price_dates_from = date('Y-m-d 00:00:00', $date_from);
}
if ($date_to = get_post_meta($pr_id, '_sale_price_dates_to', true)) {
  $sale_price_dates_to = date('Y-m-d 23:59:59', $date_to);
}
if (!empty($sale_price_dates_from)):
  $deal_start_date = $sale_price_dates_from;
  $deal_start_time = strtotime($deal_start_date);
  $deal_end_date = $sale_price_dates_to;
  $deal_end_time = strtotime($deal_end_date, current_time('timestamp'));
  //$current_date = current_time( 'Y-m-d H:i:s', true );
  $current_time = strtotime('NOW', current_time('timestamp'));
  $time_diff = ($deal_end_time - $current_time);
endif;
?>
<?php if (!empty($deal_end_date)): ?>
  <div class="timear d-flex align-items-center justify-content-between">
    <div class="title">
      <?php esc_html_e('Amazing Offer', 'kavehTheme'); ?>
      <span> <?php esc_html_e('Time Remaining', 'kavehTheme'); ?> </span>
    </div>

    <ul class="d-flex align-items-center" data-time="<?php echo $deal_end_date; ?>">
      <li>
        <span class="second"> 00 </span>
        <?php esc_html_e('Seconds', 'kavehTheme'); ?>
      </li>
      <li>
        <span class="minute"> 00 </span>
        <?php esc_html_e('Minutes', 'kavehTheme'); ?>
      </li>
      <li>
        <span class="hour"> 00 </span>
        <?php esc_html_e('Hours', 'kavehTheme'); ?>
      </li>
      <li>
        <span class="day"> 00 </span>
        <?php esc_html_e('Days', 'kavehTheme'); ?>
      </li>
    </ul>
  </div>
<?php endif; ?>
<ul class="info-product d-flex align-items-center flex-wrap">
  <?php if (!empty($catname[0]->name)): ?>
    <li>
      <span> <?php esc_html_e('Category', 'kavehTheme'); ?> </span>
      <a href="<?php echo $catlink; ?>"> <?php echo $catname[0]->name; ?> </a>
    </li>
  <?php endif; ?>
  <?php
  $cus_l = get_post_meta(get_the_ID(), "cus_lab_g", true);
  $cus_v = get_post_meta(get_the_ID(), "cus_lab_g", true);
  if (!empty($cus_l) and !empty($cus_v)):
  ?>
    <li>
      <span> <?php echo $cus_l[0]['cus_lab']; ?> </span>
      <span> <?php echo $cus_v[0]['cus_val']; ?> </span>
    </li>
  <?php
  endif;
  ?>
  <?php if (!empty($brname[0]->name)): ?>
    <li>
      <span> <?php esc_html_e('Brand', 'kavehTheme'); ?> </span>
      <a href="<?php echo $brlink; ?>"> <?php echo $brname[0]->name; ?> </a>
    </li>
  <?php
  endif;
  ?>
</ul>
<br>

<div class="price-add-to-cart">
  <?php if (!$product->is_type('variable')) : ?>
    <?php if (!empty($sale_price)): ?>
      <div class="offer-product">
        <span>

          <?php
          $percentage = kavehWoo::showofferpercentage($product);
          echo $percentage;
          ?>
        </span>
        <?php esc_html_e('Discount', 'kavehTheme'); ?>
      </div>
    <?php endif; ?>
    <div class="mt-4"></div>
    <div class="price d-flex align-items-center mt-3 mb-4 mt-sm-0">
 <?php do_action('kaveh_single_price'); ?>
    </div>
    <div class="mt-4"></div>

    <?php
    woocommerce_template_single_add_to_cart();
    ?>
  <?php elseif ($product->is_type('variable')) :
  ?>
    <?php
    woocommerce_template_single_add_to_cart();
    ?>
    <div class="mt-4"></div>
    <div class="price d-flex align-items-center mt-3 mb-4 mt-sm-0">
  <?php do_action('kaveh_single_price'); ?>
    </div>

  <?php
  endif; ?>

</div>