<?php require_once("includes/topo.php");

//TOTAL DE VAGAS
$query = $pdo->query("SELECT COUNT(*) as total FROM vagas");
$resultadoVagas = $query->fetch(PDO::FETCH_ASSOC);
$total_registrosVagas = $resultadoVagas['total'];



//TOTAL DE CANDIDATOS
$query = $pdo->query("SELECT COUNT(*) as total FROM candidatos");
$resultadocandidatos = $query->fetch(PDO::FETCH_ASSOC);
$total_registros_candidatos = $resultadocandidatos['total'];

//TOTAL DE CANDIDATURAS
$query = $pdo->query("SELECT COUNT(*) as total FROM candidaturas");
$resultadocandidaturas = $query->fetch(PDO::FETCH_ASSOC);
$total_registros_candidaturas = $resultadocandidaturas['total'];



?>
<?php // require_once ("includes/boas_vindas.php"); 
?>
<div class="content-body">

	<!-- row -->
	<div class="container-fluid">
		<div class="row">
			<div class="col-xl-12">
				<div class="row">
					<div class="col-xl-12">
						<div class="card bubles">
							<div class="card-body">
								<div class="buy-coin  bubles-down">
									<div>
										<h2><span style="color:#f49821"><?php echo $usuario_visu[0]['nome'] ?></span>,
											<br>seja bem vindo(a)!
										</h2>
										<p>Seu nível é administrador!</p>
									</div>
									<div class="coin-img">
										<img src="images/coin.png" class="img-fluid" alt="">
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>


			<div class="col-xl-3  col-lg-6 col-sm-6">
				<a href="vagas.php">
					<div class="widget-stat card">
						<div class="card-body p-4">
							<div class="media ai-icon">
								<span class="me-3 bgl-primary text-primary">
									<!-- <i class="ti-user"></i> -->
									<i class="bi bi-inboxes"></i>
								</span>
								<div class="media-body">
									<p class="mb-1">Vagas</p>
									<h4 class="mb-0"><?php echo $total_registrosVagas; ?></h4>

								</div>
							</div>
						</div>
					</div>
				</a>
			</div>

			<div class="col-xl-3  col-lg-6 col-sm-6">
				<a href="candidatos.php">
					<div class="widget-stat card">
						<div class="card-body p-4">
							<div class="media ai-icon">
								<span class="me-3 bgl-primary text-primary">
									<!-- <i class="ti-user"></i> -->
									<i class="bi bi-file-earmark-person"></i>
								</span>
								<div class="media-body">
									<p class="mb-1">Candidatos</p>
									<h4 class="mb-0"><?php echo $total_registros_candidatos; ?></h4>

								</div>
							</div>
						</div>
					</div>
				</a>
			</div>

			<div class="col-xl-3  col-lg-6 col-sm-6">
				<a href="candidaturas.php">
					<div class="widget-stat card">
						<div class="card-body p-4">
							<div class="media ai-icon">
								<span class="me-3 bgl-primary text-primary">
									<!-- <i class="ti-user"></i> -->
									<i class="bi bi-journal-medical"></i>
								</span>
								<div class="media-body">
									<p class="mb-1">Candidaturas</p>
									<h4 class="mb-0"><?php echo $total_registros_candidaturas; ?></h4>

								</div>
							</div>
						</div>
					</div>
				</a>
			</div>



			<div class="col-xl-3  col-lg-6 col-sm-6">
				<div class="widget-stat card">
					<div class="card-body p-4">
						<div class="media ai-icon">
							<span class="me-3 bgl-primary text-primary">
								<!-- <i class="ti-user"></i> -->
								<i class="bi bi-people"></i>
							</span>
							<div class="media-body">
								<p class="mb-1">Total de visitas <a href="#" class="badge badge-sm light badge-danger ms-1" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Para métricas mais precisas é aconselhado utilizar outros gerenciadores exemplo: Google Analytics." aria-describedby="popover500285">info</a></p>
								<h4 class="mb-0"><?php echo $total_visitas; ?></h4>

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

			<?php

			// Sua query para obter o status e o total
			$query = "SELECT status, COUNT(*) as total FROM candidaturas GROUP BY status";
			$result = $pdo->query($query);

			// Verifique se há resultados
			if ($result->rowCount() > 0) {
			?>

				<div class="col-xl-4 market-previews col-sm-6">
					<div class="card">
						<div class="card-header border-0 pb-0">
							<div>
								<h2 class="heading">Totais por status</h2>
							</div>
						</div>
						<div class="card-body pt-0 px-0">

							<?php
							// Loop para exibir cada status e total
							foreach ($result as $row) {

								$statusCandidatura = $row['status'];

								$query = $pdo->query("SELECT * FROM status_candidatura WHERE id = $statusCandidatura");
								$StatusVisu = $query->fetchAll(PDO::FETCH_ASSOC);

								$corStatus = "";
								$icone = "";
								if ($statusCandidatura == 1) {
									$corStatus = "#f49821";
									$icone = "fa-eye";
								}
								if ($statusCandidatura == 2) {
									$corStatus = "#9568ff";
									$icone = "fa-tag";
								}
								if ($statusCandidatura == 3) {
									$corStatus = "#00b8ef";
									$icone = "fa-suitcase";
								}
								if ($statusCandidatura == 4) {
									$corStatus = "#00a389";
									$icone = "fa-thumbs-up";
								}
								if ($statusCandidatura == 5) {
									$corStatus = "#eb5757";
									$icone = "fa-thumbs-down";
								}
							?>
								<div class="previews-info-list">
									<div class="pre-icon">
										<span class="icon-box icon-box-sm bg-success" style="background-color: <?php echo $corStatus; ?>!important;">
											<i class="fa <?php echo $icone ?>" style="color:#ffffff" aria-hidden="true"></i>
										</span>
										<div class="ms-2">
											<h6><?php echo $StatusVisu[0]['nome'] ?></h6>
										</div>
									</div>
									<div class="count">
										<h3><?php echo htmlspecialchars($row['total']); ?> <span style="color: #a5a5a5; font-size: 12px; font-weight: 500;">candidaturas</span></h3>
									</div>
								</div>
							<?php
							}
							?>
						</div>
					</div>
				</div>

			<?php
			} else {
				echo "<p>Nenhum status encontrado.</p>";
			}
			?>





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


<?php require_once("includes/rodape.php"); ?>