<?php 
function isAdmin($userId) {
	if(isset($userId)){
		require("db.php");
		$stmt=$pdo->prepare("SELECT isAdmin FROM users WHERE id = ?");
		$stmt->execute([$userId]);
		$res = $stmt->fetch();
		return $res["isAdmin"];
	} else if (isset($_SESSION["bootstrapAdmin"]) && $_SESSION["bootstrapAdmin"] === true){
		return true;
	}
	return false;
}
function head($title, $bodyClasses = "") { ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title><?= $title ?></title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="/storage/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" href="/storage/bootstrap-icons.min.css">
	<link href="/storage/style.css" rel="stylesheet">
</head>
<body class="<?= $bodyClasses ?>">
<?php 
}
function footer() { ?>
	</main>
	<script src="/storage/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php }
function nav() {
	?>
	<main class="d-flex nowrap" data-bs-theme="dark">
	<div class="flex-shrink-0 p-3" style="width: 280px;">
	<a href="/storage/" class="d-flex align-items-center pb-3 mb-3 link-body-emphasis text-decoration-none border-bottom">
		<svg class="bi pe-none me-2" width="30" height="24" aria-hidden="true"><use xlink:href="#bootstrap"></use></svg>
		<span class="fs-5 fw-semibold">Storage</span>
	</a>
	<?php if(!isset($_SESSION["bootstrapAdmin"])): ?>
	<ul class="list-unstyled ps-0">
		<li class="mb-1">
			<button class="btn btn-toggle d-inline-flex align-items-center rounded border-0" data-bs-toggle="collapse" data-bs-target="#items-collapse" aria-expanded="true">
				Items
			</button>
			<div class="collapse show" id="items-collapse" style="">
				<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
					<li><a href="/storage/" class="link-body-emphasis d-inline-flex text-decoration-none rounded">List</a></li>
					<li><a href="/storage/lent.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Lend</a></li>
					<li><a href="/storage/item/add.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Add</a></li>
					<li><a href="/storage/shelf/list.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Shelves</a></li>
					<li><a href="/storage/warehouse/list.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Warehouses</a></li>
				</ul>
			</div>
		</li>
		<?php if(isAdmin($_SESSION['userId'])):?>
		<li class="mb-1">
			<button class="btn btn-toggle d-inline-flex align-items-center rounded border-0 collapsed" data-bs-toggle="collapse" data-bs-target="#people-collapse" aria-expanded="false">
				People
			</button>
			<div class="collapse" id="people-collapse" style="">
				<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
					<li><a href="/storage/people/list.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">List</a></li>
					<li><a href="/storage/people/add.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Add</a></li>
				</ul>
			</div>
		</li>
		<?php endif; ?>
		<li class="border-top my-3"></li>
		<li class="mb-1">
			<button class="btn btn-toggle d-inline-flex align-items-center rounded border-0 collapsed" data-bs-toggle="collapse" data-bs-target="#account-collapse" aria-expanded="false">
				Account
			</button>
			<div class="collapse" id="account-collapse" style="">
				<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
					<?php if(isAdmin($_SESSION["userId"])){ ?><li><a href="/storage/admin/" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Admin</a></li><?php } ?>
					<li><a href="/storage/logout.php" class="link-body-emphasis d-inline-flex text-decoration-none rounded">Sign out</a></li>
				</ul>
			</div>
		</li>
	</ul>
	<?php else: ?>
	<p style="color: red; text-align: center; width: 100%">SETUP MODE</p>
	<?php endif; ?>
</div>
	<?php
}
