<?php 
require_once("../conexao.php");

$totalDizimos = 0;
$membrosCadastrados = 0;
$totalOfertas = 0;
$totalGastos = 0;

$query = $pdo->query("SELECT * FROM membros where igreja = '$id_igreja' and ativo = 'Sim'");
$res = $query->fetchAll(PDO::FETCH_ASSOC);
$membrosCadastrados = @count($res);


?>


<div class="container-fluid " >
	<section id="minimal-statistics" style="margin-right:20px">
		<div class="row mb-2">
			<div class="col-12 mt-3 mb-1">
				<h4 class="text-uppercase textocinzaescuro"><small><small><?php echo $nome_igreja ?></small></small></h4>

			</div>
		</div>




		<div class="row mb-4">


			<div class="col-xl-3 col-sm-6 col-12 linkcard"> 
				<a href="index.php?pag=membros">
					<div class="card">
						<div class="card-content">
							<div class="card-body">
								<div class="row">
									<div class="align-self-center col-3">
										<i class="bi bi-people-fill text-secondary fs-1 float-start"></i>
									</div>
									<div class="col-9 text-end">
										<h3> <span class="text-secondary"><?php echo @$membrosCadastrados ?></span></h3>
										<span class="textocinzaescuro">Total de Membros</span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</a>
			</div>

			<div class="col-xl-3 col-sm-6 col-12 linkcard"> 
				<a href="index.php?pag=igrejas">
					<div class="card">
						<div class="card-content">
							<div class="card-body">
								<div class="row">
									<div class="align-self-center col-3">
										<i class="bi bi-piggy-bank text-success fs-1 float-start"></i>
									</div>
									<div class="col-9 text-end">
										<h3> <span class="text-success">R$ <?php echo @$totalDizimos ?></span></h3>
										<span class="textocinzaescuro">Dízimos do Mês</span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</a>
			</div>

			


			<div class="col-xl-3 col-sm-6 col-12 linkcard"> 
				<a href="index.php?pag=pastores">
					<div class="card">
						<div class="card-content">
							<div class="card-body">
								<div class="row">
									<div class="align-self-center col-3">
										<i class="bi bi-cash text-primary fs-1 float-start"></i>
									</div>
									<div class="col-9 text-end">
										<h3> <span class="text-primary">R$ <?php echo @$totalOfertas ?></span></h3>
										<span class="textocinzaescuro">Ofertas do Mês</span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</a>
			</div>


			<div class="col-xl-3 col-sm-6 col-12 linkcard"> 
				<a href="index.php?pag=membros">
					<div class="card">
						<div class="card-content">
							<div class="card-body">
								<div class="row">
									<div class="align-self-center col-3">
										<i class="bi bi-currency-dollar text-danger fs-1 float-start"></i>
									</div>
									<div class="col-9 text-end">
										<h3> <span class="text-danger">R$ <?php echo @$totalGastos ?></span></h3>
										<span class="textocinzaescuro">Gastos do Mês</span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</a>
			</div>




		</div>

	</section>

	<?php 
	$query = $pdo->query("SELECT * FROM tarefas where status = 'Agendada' and igreja = '$id_igreja' order by status asc, data asc, hora asc LIMIT $quantidade_tarefas");
	$res = $query->fetchAll(PDO::FETCH_ASSOC);
	$total_reg = count($res);
	?>

	<div class="text-xs font-weight-bold text-secondary text-uppercase mt-4"><small>AGENDA / <?php echo $total_reg ?> TAREFAS PENDENTES</small></div>
	<hr> 

	<div class="row" style="margin-right:10px">

		<?php 


		if($total_reg > 0){
			for($i=0; $i < $total_reg; $i++){
				foreach ($res[$i] as $key => $value){} 

					$titulo = $res[$i]['titulo'];	
				$data = $res[$i]['data'];
				$hora = $res[$i]['hora'];
				$descricao = $res[$i]['descricao'];
				$status = $res[$i]['status'];

				$id = $res[$i]['id'];

				$dataF = implode('/', array_reverse(explode('-', $data)));


				if($data < $data_atual || $hora < $hora_atual){
					$classe_icon = 'text-danger';
					$borda_card = 'bordacardsede';
				}else{
					$classe_icon = 'text-primary';
					$borda_card = 'bordacardtarefa';
				}


				?>

				<div class="col-xl-3 col-md-6 col-12 mb-4 linkcard">
					<a href="index.php?pag=tarefas">
						<div class="card text-danger shadow h-100 <?php echo $borda_card ?>">
							<div class="card-body">
								<div class="row no-gutters align-items-center">
									<div class="col mr-2">
										<div class="text-xs font-weight-bold text-primary text-uppercase titulocard"><?php echo $dataF ?></div>
										<div class="text-xs font-weight-bold text-danger text-uppercase titulocard"><?php echo $titulo ?></div>
										<div class="text-xs text-secondary subtitulocard"><?php echo$descricao ?> </div>
									</div>
									<div class="col-auto" align="center">
										<h2 style="margin:1px" class="bi bi-calendar2-check <?php echo $classe_icon ?>"></h2>
										<span class="text-xs totaiscard text-danger"><?php echo $hora ?></span>
									</div>
								</div>
							</div>
						</div>
					</a>
				</div>



			<?php } }else{
				echo '<small>Não existem tarefas Pendentes!!</small>';
			} ?>

		</div>
	</div>