<?php

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

$db = new database();

$user_id = $_SESSION['user_id'];

$sql = "SELECT * FROM `profil_user` WHERE id_user=$user_id";
$result = $db->db_query($sql);

while ($rows = $db->db_fetch_array($result)) {
	$nama = $rows['nama'];
	$HP = $rows['hp'];
	$email = $rows['email'];
	$alamat = $rows['alamat'];
	$foto = $rows['foto'];
}

if ($HP == 'kosong') {
	$HP = "";
}

if ($alamat == 'kosong') {
	$alamat = "";
}

if ($foto == 'kosong') {
	$foto = "user.svg";
}

if (isset($_GET['alert']) && $_GET['alert']!="") {
	$alert = $_GET['alert'];

	if ($alert == '1') {
		alert_profil_layout('red', '<i class="fas fa-exclamation-triangle"></i>', 'Silahkan lengkapi data user terlebih dahulu sebelum melakukan checkout pesanan');
	} elseif ($alert == '2') {
		alert_profil_layout('green', '<i class="fas fa-check-circle"></i>', 'Berhasil mengubah data profil anda');
	} elseif ($alert == '3') {
		alert_profil_layout('red', '<i class="fas fa-exclamation-triangle"></i>', 'Gagal mengubah data profil anda');
	}
}

?>

<div class="profil-layout">
	<div class="title-profil">Profil</div>
	<div class="relative-profil">
		<img src="img-profil/<?php echo $foto; ?>">
		<div class="layout-data-profil">
			<div class="relative-profil">
				<div>
					<div>Nama</div>
					<div>Nomor HP</div>
					<div>Email</div>
					<div>Alamat</div>
				</div>
				<div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $nama; ?></div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $HP; ?></div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $email; ?></div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $alamat; ?></div>
				</div>
			</div>
		</div>
	</div>
	<div class="btn-edit-profil"><a href="index.php?menu=edit_profil">Edit Profil</a></div>
</div>

<?php

function alert_profil_layout($color, $icon, $text){
	echo '
		<div class="alert-profil" style="background: '.$color.';">
			'.$icon.'
			<div>'.$text.'</div>
		</div>
	';
}

?>