<!DOCTYPE html>
<html lang="pt-br">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link href="<?php echo show_file_link(SYS_ICONE); ?>" rel="icon" type="image/png">
		<link rel="manifest" href="<?php echo show_file_link("/manifest.json"); ?>">

		<title><?php echo (!empty($title) ? $title." | ".SYS_NAME : SYS_NAME); ?></title>
		
		<link href="<?php echo show_file_link("/assets/fonts/fonts.css"); ?>" rel="stylesheet">
		<link href="<?php echo show_file_link("/assets/custom/css/styles.css"); ?>" rel="stylesheet">
		<link href="<?php echo show_file_link("/assets/custom/css/custom.css"); ?>" rel="stylesheet">
		<link href="<?php echo show_file_link("/assets/fontawesome/releases/v6.2.0/css/all.css"); ?>" rel="stylesheet" type="text/css">
		<link href="<?php echo show_file_link("/assets/fontawesome/releases/v6.2.0/css/sharp-solid.css"); ?>" rel="stylesheet" type="text/css">
		<link href="<?php echo show_file_link("/assets/jquery-toast/css/jquery.toast.css"); ?>" rel="stylesheet">

		<!-- Owl Carousel CSS -->
		<link rel="stylesheet" href="<?php echo show_file_link("/assets/owl-carousel/owl.carousel.css"); ?>">
		<link rel="stylesheet" href="<?php echo show_file_link("/assets/owl-carousel/owl.theme.css"); ?>">

		<?php import_file(DIR_TEMPLATES."style.php"); ?>

		<script src="<?php echo show_file_link("/assets/jquery/jquery.min.js"); ?>"></script>
		<script src="<?php echo show_file_link("/assets/bootstrap/js/bootstrap.bundle.min.js"); ?>"></script>
		<script src="<?php echo show_file_link("/assets/jquery-toast/js/jquery.toast.js"); ?>"></script>
		<script src="<?php echo show_file_link("/assets/jquery-mask/jquery.mask.js"); ?>"></script>

		<!-- CKEditor JS -->
		<script src="<?php echo show_file_link("/assets/ckeditor/ckeditor.js"); ?>"></script>

		<!-- Owl Carousel JS -->
		<script src="<?php echo show_file_link("/assets/owl-carousel/owl.carousel.min.js"); ?>"></script>

		<script src="<?php echo show_file_link("/assets/custom/js/functions.js"); ?>"></script>

		<script>
			window.active_page = "<?php echo $active_page; ?>";
			window.url_base = "<?php echo URL_BASE; ?>";
		</script>
	</head>

	<body class="sb-nav-fixed" style="background-color: <?php echo BACKGROUND_COLOR; ?>;">
		<nav class="sb-topnav navbar navbar-expand navbar-dark navbar-degrade" style="height: 60px;">
			<?php if (PRESENTATION_STANDARD == 1): ?>
				<div class="logo-container">
					<a href="<?php echo show_link("/"); ?>">
						<img src="<?php echo show_file_link(SYS_LOGO); ?>" class="logo">
					</a>
				</div>
		
				<span class="navbar-brand d-md-block d-none">
					<?php echo SYS_NAME; ?>
				</span>
			<?php elseif (PRESENTATION_STANDARD == 2): ?>
				<div class="logo-container">
					<a href="<?php echo show_link("/"); ?>">
						<img src="<?php echo show_file_link(SYS_LOGO); ?>" class="logo">
					</a>
				</div>
			<?php else: ?>
				<a href="<?php echo show_link("/"); ?>" class="navbar-brand">
					<?php echo SYS_NAME; ?>
				</a>
			<?php endif; ?>

			<div class="ml-auto"></div>

			<div class="d-inline-flex ml-auto">
				<ul class="navbar-nav" style="flex-direction: row; align-items: center;">
					<li class="nav-item dropdown">
						<button 
							type="button" 
							id="btn-dropdown-user" 
							class="btn btn-dropdown-user nav-link dropdown-toggle" 
							data-toggle="dropdown" 
							aria-expanded="false"
						>
							<i class="fa-solid fa-circle-user d-none d-md-inline mr-1"></i> 
							<?php echo first_name(Session::get("nome_usuario")); ?>
						</button>

						<div class="dropdown-menu dropdown-menu-right" style="z-index: 1000; position: absolute;">
							<a href="<?php echo show_link("/perfil/"); ?>" class="dropdown-item">
								<i class="fa-regular fa-address-card mr-1"></i> Meu Perfil
							</a>

							<div class="dropdown-divider"></div>

							<?php if (Session::get("tipo_usuario") == "6"): ?>
								<?php 

									$id_usuario = Session::get("id_usuario");
									$result = Connection::query("
										SELECT * FROM loja
										WHERE
											id_usuario = {$id_usuario}
									");

									if ($result->rowCount() == 1):
										$id_loja = $result->fetch()->id_loja;

								?>
									<a href="<?php echo show_link("/visualizar-loja/?loja=".urlencode(encrypt_encode($id_loja))); ?>" class="dropdown-item">
										<i class="fa-regular fa-store mr-1"></i> Minha Loja
									</a>
								<?php endif; ?>

								<a href="<?php echo show_link("/configuracoes-loja/"); ?>" class="dropdown-item">
									<i class="fa-regular fa-sliders-v-square mr-1"></i> Configurações da Loja
								</a>

								<div class="dropdown-divider"></div>
							<?php endif; ?>
							
							<a href="<?php echo show_link("/logout/"); ?>" class="dropdown-item">
								<i class="fa-regular fa-sign-out mr-1"></i> Sair
							</a>
						</div>
					</li>
				</ul>

				<ul class="navbar-nav ml-2">
					<?php if (Session::get("tipo_usuario") == 2): ?>
						<li class="nav-item" id="btnShoppingCart">
							<a href="<?php echo show_link("/meu-carrinho-compra/"); ?>" class="nav-link">
								<div style="display: inline-flex;">
									<i class="fa-regular fa-shopping-cart"></i>
									
									<?php 

										$id_usuario = Session::get("id_usuario");
										$total = Connection::query("
											SELECT
												COUNT(*) AS total
											FROM carrinho_compra a
											INNER JOIN produto b ON (a.id_produto = b.id_produto)
											WHERE 
												a.id_usuario = {$id_usuario}
											ORDER BY 
												a.id_carrinho_compra ASC 
										")->fetch()->total;

									?>
									<?php if ($total > 0): ?>
										<span class="badge badge-pill badge-danger">
											<?php echo $total; ?>
										</span>
									<?php endif ?>
								</div>
							</a>
						</li>
					<?php endif; ?>

					<li class="nav-item">
						<a href="#" id="sidebarToggle" class="nav-link">
							<i class="fa-regular fa-bars"></i>
						</a>
					</li>
				</ul>
			</div>
		</nav>	
		<?php import_file(DIR_TEMPLATES."sidebar.php"); ?>