<style>
  div.product-wrapper div.main-product div.item-product {
    position: relative;
  }

  div.product-wrapper div.main-product div.item-product div.card-body p.newPrice {
    font-size: 16px;
  }

  div.product-wrapper div.main-product div.item-product div.stars-rating {
    position: relative;
    right: 15px;
  }

  div.product-wrapper div.main-product div.item-product div.stars-rating i {
    color: orange;
    font-size: 14px;
  }

  #modalBannerPopup .fa-times {
    font-size: 20px;
    position: absolute;
    right: 15px;
    top: 15px;
    color: white;
    cursor: pointer;
  }
</style>
<?php include 'templates/star.php' ?>
<?php if ($banner_popup) { ?>
  <div class="modal fade" id="modalBannerPopup" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <i class="fa fa-times" class="close" data-dismiss="modal" aria-label="Close"></i>
        <img class="rounded" style="width: 100%" onclick="window.location.href='<?= $banner_popup['url'] ?>'" src="<?= base_url(); ?>assets/images/banner/<?= $banner_popup['img'] ?>" alt="banner popup">
      </div>
    </div>
  </div>
<?php } ?>
<div class="category-menu">
  <div class="main-category">
    <?php foreach ($categoriesLimit->result_array() as $c) : ?>
      <a href="<?= base_url(); ?>c/<?= $c['slug']; ?>">
        <div class="item">
          <img alt="icon" src="<?= base_url(); ?>assets/images/icon/<?= $c['icon']; ?>">
          <p><?= $c['name']; ?></p>
        </div>
      </a>
    <?php endforeach; ?>
  </div>
</div>

<?php if ($best->num_rows() > 0) { ?>
  <div class="product-wrapper best-product">
    <h2 class="title">Produk Terlaris</h2>
    <a href="<?= base_url(); ?>best" class="float-right mt-2">Lihat semua</a>
    <br><br>
    <div class="main-product">
      <?php foreach ($best->result_array() as $p) : ?>
        <div>
          <a href="<?= base_url(); ?>p/<?= $p['slug']; ?>">
            <div class="item-product">
              <img alt="<?= $p['title']; ?>" src="<?= $p['ex_img'] == 1 ? $p['img'] : base_url() . 'assets/images/product/' . $p['img']; ?>" class="card-img-top">
              <div class="card-body">
                <?php if ($p['discount'] == 0) { ?>
                  <p class="card-text line-3 mb-0"><?= $p['title']; ?></p>
                  <div class="d-flex justify-content-between">
                    <p class="newPrice">Rp. <?= str_replace(",", ".", number_format($p['price'])); ?></p>
                    <div class="stars-rating">
                      <?php $starsRating = $this->Products_model->rowRatingByProduct($p['id']); ?>
                      <?php if ($starsRating == 0) { ?>
                        <i class="far fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                      <?php } else { ?>
                        <i class="fa fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                      <?php } ?>
                    </div>
                  </div>
                <?php } else { ?>
                  <p class="card-text mb-0"><?= $p['title']; ?></p>
                  <p class="oldPrice mb-0">Rp. <span><?= str_replace(",", ".", number_format($p['price'])); ?></span> <small class="badge badge-danger"><?= $p['discount']; ?>%</small></p>
                  <?php $diskonnya = ($p['price'] * $p['discount']) / 100 ?>
                  <div class="d-flex justify-content-between">
                    <p class="newPrice">Rp. <?= str_replace(",", ".", number_format($p['price'] - $diskonnya)); ?></p>
                    <div class="stars-rating">
                      <?php $starsRating = $this->Products_model->rowRatingByProduct($p['id']); ?>
                      <?php if ($starsRating == 0) { ?>
                        <i class="far fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                      <?php } else { ?>
                        <i class="fa fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                      <?php } ?>
                    </div>
                  </div>
                <?php } ?>
              </div>
            </div>
          </a>
        </div>
      <?php endforeach; ?>
      <div class="clearfix"></div>
    </div>
  </div>
<?php } ?>

<div class="product-wrapper best-product">
  <h2 class="title">Produk Terbaru</h2>
  <div class="main-product mt-4">
    <div id="bodyForShowProductHome">
      <?php foreach ($recent->result_array() as $p) : ?>
        <a href="<?= base_url(); ?>p/<?= $p['slug']; ?>">
          <div class="item-product">
            <img alt="<?= $p['title']; ?>" src="<?= $p['ex_img'] == 1 ? $p['img'] : base_url() . 'assets/images/product/' . $p['img']; ?>" class="card-img-top">
            <div class="card-body">
              <?php if ($p['discount'] == 0) { ?>
                <p class="card-text line-3 mb-0"><?= $p['title']; ?></p>
                <div class="d-flex justify-content-between">
                  <p class="newPrice">Rp. <?= str_replace(",", ".", number_format($p['price'])); ?></p>
                  <div class="stars-rating">
                    <?php $starsRating = $this->Products_model->rowRatingByProduct($p['id']); ?>
                    <?php if ($starsRating == 0) { ?>
                      <i class="far fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                    <?php } else { ?>
                      <i class="fa fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                    <?php } ?>
                  </div>
                </div>
              <?php } else { ?>
                <p class="card-text mb-0"><?= $p['title']; ?></p>
                <p class="oldPrice mb-0">Rp. <span><?= str_replace(",", ".", number_format($p['price'])); ?></span> <small class="badge badge-danger"><?= $p['discount']; ?>%</small></p>
                <?php $diskonnya = ($p['price'] * $p['discount']) / 100 ?>
                <div class="d-flex justify-content-between">
                  <p class="newPrice">Rp. <?= str_replace(",", ".", number_format($p['price'] - $diskonnya)); ?></p>
                  <div class="stars-rating">
                    <?php $starsRating = $this->Products_model->rowRatingByProduct($p['id']); ?>
                    <?php if ($starsRating == 0) { ?>
                      <i class="far fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                    <?php } else { ?>
                      <i class="fa fa-star"></i> <small class="text-muted"><?= round($starsRating, 1) ?></small>
                    <?php } ?>
                  </div>
                </div>
              <?php } ?>
            </div>
          </div>
        </a>
      <?php endforeach; ?>
    </div>
    <div class="clearfix"></div>
  </div>
  <?php if ($this->db->get('products')->num_rows() > 8) { ?>
    <img src="<?= base_url(); ?>assets/images/icon/loading-v1.gif" alt="loading.." class="loading-animation-load-more">
    <?php $btncolor = $this->Settings_model->general()['btncolor']; ?>
    <button style="border: 1px solid <?= $btncolor; ?>; color: <?= $btncolor; ?>" class="more" id="btnClickLoadMoreProductHome">MUAT LEBIH BANYAK</button>
  <?php } ?>
</div>

<?php if ($this->Settings_model->general()['social_proof_status'] == 1) { ?>
  <?php $noooo = 1;
  foreach ($invoice->result_array() as $in) : ?>
    <input type="hidden" id="numberOfInvoiceTotalHomePage" value="<?= $invoice->num_rows(); ?>">
    <div class="social-proof" id="socialProofId-<?= $noooo; ?>">
      <div class="main">
        <?php $product_buy = $this->db->get_where('transaction', ['id_invoice' => $in['invoice_code']])->row_array();
        $product_real = $this->db->get_where('products', ['slug' => $product_buy['slug']])->row_array(); ?>
        <img src="<?= $product_real['ex_img'] == 1 ? $product_real['img'] : base_url() . 'assets/images/product/' . $product_real['img']; ?>" alt="img product">
        <div class="text">
          <p><span class="font-bold"><?= strlen($in['name']) > 15 ? substr($in['name'], 0, 15) . '..' : $in['name']; ?></span> membeli
          <p class="font-bold product_name"><?= $product_real['title'] ?></p>
          </p>
          <span class="verified"><img src="<?= base_url(); ?>assets/images/icon/verified.png" alt="verified icon"> Verified by <span class="app_name"><?= $this->Settings_model->general()['app_name']; ?></span></span>
        </div>
      </div>
    </div>
  <?php $noooo++;
  endforeach; ?>
<?php } ?>