<?php

$path_to_root = "";
include $path_to_root . '../database.php';

$db = new database();

?>

<div class="pesanan-layout">
	<div class="form-container">
		<div class="slide-controls">
			<input type="radio" name="slider" id="pesanan-baru" checked>
			<input type="radio" name="slider" id="pesanan-berlangsung">
			<input type="radio" name="slider" id="selesai">
			<label for="pesanan-baru" class="slide pesanan-baru">Pesanan Baru</label>
			<label for="pesanan-berlangsung" class="slide pesanan-berlangsung">Pesanan Berlangsung</label>
			<label for="selesai" class="slide selesai">Riwayat</label>
			<div class="slide-tab"></div>
		</div>
		<div class="form-inner">
			<div class="layout pesanan-baru-layout">
				<?php

				$sql_order_baru = "SELECT * FROM `order` WHERE status='verifikasi pembayaran sukses'";

				$result_order_baru = $db->db_query($sql_order_baru);
				$num_rows_order_baru = $db->db_num_rows($result_order_baru);

				if ($num_rows_order_baru > 0) {
					while ($rows = $db->db_fetch_array($result_order_baru)) {
						$id = $rows['id'];
						$tanggal_pesanan = $rows['tanggal_pesanan'];
						$tanggal_pengambilan = $rows['tanggal_pengambilan'];
						$id_user = $rows['id_user'];

						$sql_nama_user = "SELECT * FROM profil_user WHERE id_user=$id_user";
						$result_nama_user = $db->db_query($sql_nama_user);

						while ($rows2 = $db->db_fetch_array($result_nama_user)) {
							$nama_user = $rows2['nama'];

							list_data_pesanan_baru($id, $nama_user, $tanggal_pesanan, $tanggal_pengambilan);
						}
					}
				} else {
					echo '<div class="pesanan-kosong"><label>Tidak ada pesanan</label></div>';
				}

				?>
			</div>
			<div class="layout pesanan-berlangsung-layout">
				<?php

				$sql_order_baru = "SELECT * FROM `order` WHERE status='barang sudah diambil'";

				$result_order_baru = $db->db_query($sql_order_baru);
				$num_rows_order_baru = $db->db_num_rows($result_order_baru);

				if ($num_rows_order_baru > 0) {
					while ($rows = $db->db_fetch_array($result_order_baru)) {
						$id = $rows['id'];
						$tanggal_pesanan = $rows['tanggal_pesanan'];
						$tanggal_pengambilan = $rows['tanggal_pengambilan'];
						$id_user = $rows['id_user'];

						$sql_nama_user = "SELECT * FROM profil_user WHERE id_user=$id_user";
						$result_nama_user = $db->db_query($sql_nama_user);

						while ($rows2 = $db->db_fetch_array($result_nama_user)) {
							$nama_user = $rows2['nama'];

							list_data_pesanan_berlangsung($id, $nama_user, $tanggal_pesanan, $tanggal_pengambilan);
						}
					}
				} else {
					echo '<div class="pesanan-kosong"><label>Tidak ada pesanan</label></div>';
				}

				?>
			</div>
			<div class="layout selesai-layout">
				<?php

				$sql_order_baru = "SELECT * FROM `order` WHERE status='selesai'";

				$result_order_baru = $db->db_query($sql_order_baru);
				$num_rows_order_baru = $db->db_num_rows($result_order_baru);

				if ($num_rows_order_baru > 0) {
					while ($rows = $db->db_fetch_array($result_order_baru)) {
						$id = $rows['id'];
						$tanggal_pesanan = $rows['tanggal_pesanan'];
						$id_user = $rows['id_user'];

						$sql_nama_user = "SELECT * FROM profil_user WHERE id_user=$id_user";
						$result_nama_user = $db->db_query($sql_nama_user);

						while ($rows2 = $db->db_fetch_array($result_nama_user)) {
							$nama_user = $rows2['nama'];

							list_data_pesanan_selesai($id, $nama_user, $tanggal_pesanan);
						}
					}
				} else {
					echo '<div class="pesanan-kosong"><label>Tidak ada pesanan</label></div>';
				}

				?>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	const btnBelumBayar = document.querySelector("label.pesanan-baru");
	const btnProses = document.querySelector("label.pesanan-berlangsung");
	const btnSelesai = document.querySelector("label.selesai");
	const layoutBelumBayar = document.querySelector(".pesanan-baru-layout");
	const layoutProses = document.querySelector(".pesanan-berlangsung-layout");
	const layoutSelesai = document.querySelector(".selesai-layout");

	btnBelumBayar.onclick = (()=>{
		layoutBelumBayar.style.marginLeft = "0%";
		layoutBelumBayar.style.borderRadius = "0px 5px 5px 5px";
	});

	btnProses.onclick = (()=>{
		layoutBelumBayar.style.marginLeft = "calc(-100% / 3)";
		layoutProses.style.borderRadius = "5px 5px 5px 5px";
	});

	btnSelesai.onclick = (()=>{
		layoutBelumBayar.style.marginLeft = "calc(-200% / 3)";
		layoutSelesai.style.borderRadius = "5px 0px 5px 5px";
	});
</script>

<?php

function list_data_pesanan_baru($id, $nama_user, $tanggal_pesanan, $tanggal_pengambilan){
	echo '
		<div class="data-pesanan-baru">
			<div class="relative-layout-pesanan">
				<div>
					<div>ID Pesanan</div>
					<div>Nama </div>
					<div>Tanggal Pesanan</div>
					<div>Tanggal Pengambilan Barang</div>
				</div>
				<div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$id.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$nama_user.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pesanan.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pengambilan.'</div>
				</div>
			</div>
			<div class="layout-tombol"><a href="index.php?menu=detail pesanan baru&id='.$id.'">Detail</a></div>
		</div>
	';
}

function list_data_pesanan_berlangsung($id, $nama_user, $tanggal_pesanan, $tanggal_pengambilan){
	echo '
		<div class="data-pesanan-baru">
			<div class="relative-layout-pesanan">
				<div>
					<div>ID Pesanan</div>
					<div>Nama </div>
					<div>Tanggal Pesanan</div>
					<div>Tanggal Pengambilan Barang</div>
				</div>
				<div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$id.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$nama_user.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pesanan.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pengambilan.'</div>
				</div>
			</div>
			<div class="layout-tombol"><a href="index.php?menu=detail pesanan berlangsung&id='.$id.'">Detail</a></div>
		</div>
	';
}

function list_data_pesanan_selesai($id, $nama_user, $tanggal_pesanan){
	echo '
		<div class="data-pesanan-baru">
			<div class="relative-layout-pesanan">
				<div>
					<div>ID Pesanan</div>
					<div>Nama </div>
					<div>Tanggal Pesanan</div>
				</div>
				<div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$id.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$nama_user.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pesanan.'</div>
				</div>
			</div>
			<div class="layout-tombol"><a href="index.php?menu=riwayat pesanan&id='.$id.'">Detail</a></div>
		</div>
	';
}

?>