<div class="text-center">
	<button class="btn btn-sm btn-default btn-rounded mt-3">produk terkait</button>
</div>
<div class="row mt-3">
	<!-- Swiper -->

	<?php
	$dbst = $db->table("produk")
		->where("idcat", $kategori->id)
		->where("id!=", $data->id)
		->orderBy("id", "RANDOM")
		->limit(6)
		->get();
	foreach ($dbst->getResult() as $re) {
		$levelt = session()->get("lvl") ?? 0;
		if ($levelt == 5) {
			$resultt = $re->hargadistri;
		} elseif ($levelt == 4) {
			$resultt = $re->hargaagensp;
		} elseif ($levelt == 3) {
			$resultt = $re->hargaagen;
		} elseif ($levelt == 2) {
			$resultt = $re->hargareseller;
		} else {
			$resultt = $re->harga;
		}
		$ulasan = $func->getReviewProduk($re->id);
		$diskon2 = 0;
		if ($re->diskon > 0) {
			$diskon2 = $re->diskon;
		}

		$dbvt = $db->table("produkvariasi")->where("idproduk", $re->id)->get();
		$totalstokt = ($dbvt->getNumRows() > 0) ? 0 : $re->stok;
		$hargst = 0;
		$hargat = array();
		foreach ($dbvt->getResult() as $rv) {
			$totalstokt += $rv->stok;
			if ($levelt == 5) {
				$hargat[] = $rv->hargadistri;
			} elseif ($levelt == 4) {
				$hargat[] = $rv->hargaagensp;
			} elseif ($levelt == 3) {
				$hargat[] = $rv->hargaagen;
			} elseif ($levelt == 2) {
				$hargat[] = $rv->hargareseller;
			} else {
				$hargat[] = $rv->harga;
			}
			$hargst += $rv->harga;
		}

		if ($hargst > 0) {
			$hargaawal2 = "Rp. " . $func->formUang(min($hargat)) . " - " . $func->formUang(max($hargat));
		} else {
			$hargaawal2 = "Rp. " . $func->formUang($resultt);
		}

	?>
		<div class="swiper-slide col-6 col-md-4 col-lg-3 col-xl-2">
			<div class="card cardproduk shadow-sm border-0 mb-4">
				<div class="produklist">
					<span class="badge badge-warning bdg-1"><?= $ulasan['nilai'] ?></span>
					<i class="stars" data-rating="<?= $ulasan['nilai'] ?>" data-num-stars="5"></i>

					<figure class="product-image"><a href="<?php echo site_url('produk/' . $re->url); ?>"><img src="<?php echo $func->getFoto($re->id, 'utama'); ?>" alt="<?php echo $re->nama; ?>"></a></figure>
					<?php if ($diskon2 > 0) { ?><div class="badge badge-danger float-right mt-1"><?= $diskon2 ?>%</div><?php } ?>
					<?php if ($re->flash == 1) { ?><img src="<?= base_url('/assets/images/flashsale.png') ?>" alt="flashsale" class="flashsale">
						<span class="text-secondary small"> flashsale</span> <?php } ?>
					<a href="<?php echo site_url('produk/' . $re->url); ?>" class="text-dark mb-1 mt-2 h6 tulisan-card"><?php echo $re->nama; ?></a>
					<?php if ($diskon2 > 0) { ?>
						<p class="text-secondary small text-mute mb-0"><s> <?= $hargaawal2 ?></s></p>
					<?php } ?>
					<h5 class="text-success font-weight-normal mb-0">

						<div class="newPrice">
							<?php
							if ($hargst > 0) {
								echo "Rp. " . $func->formUang(min($hargat) - (min($hargat) * $diskon2 / 100)) . " - " . $func->formUang(max($hargat) - (max($hargat) * $diskon2 / 100));
							} else {
								echo "Rp. " . $func->formUang($resultt - ($resultt * $diskon2 / 100));
							}
							?>

						</div>
					</h5>
					<p class="text-secondary small text-mute mb-0"><?= $ulasan['ulasan'] ?> Ulasan</p>
				</div>
			</div>
		</div>

	<?php } ?>


</div>
