<?php if (Session::get("tipo_usuario") != "2" or Session::get("usuario_ativo") != "S"){ show_403();} ?>
<?php import_file(DIR_TEMPLATES."header.php", ["title" => "Planos", "active_page" => "planos"]); ?>
<?php import_file(DIR_MODELS."Model.class.php"); ?>
<?php import_file(DIR_LIBRARIES."functions.php"); ?>

<?php $config = obter_configuracao(); ?>

<h4 class="mb-3">
	<i class="fa-regular fa-medal"></i> Todos os Planos
</h4>

<div class="content-box">
	<div class="form-row align-items-center">
		<?php 

			$model = new Model();

			$planos = $model->query("SELECT * FROM plano WHERE status_plano = 'S' ORDER BY porcentagem_valor_plano ASC");

			foreach ($planos->fetchAll() as $dados):

		?>
			<div class="col-xl-3 col-lg-3 col-md-6 col-sm-12">
				<div class="card text-dark o-hidden h-100 my-2" style="border: 2px solid <?php echo $dados->cor_plano; ?>; border-radius: 6px;">
					<div class="card-header" style="background-color: <?php echo $dados->cor_plano; ?>; border-color: <?php echo $dados->cor_plano; ?>;">
						<div class="h5 mb-0 text-center text-white" style="text-shadow:#222 0.8px -0.8px, #222 -0.8px 0.8px, #222 0.8px 0.8px, #222 -0.8px -0.8px"><?php echo $dados->nome_plano; ?></div>
					</div>
					<div class="card-body text-dark">
						<div class="mb-0">
							<strong>Porcentagem do Valor:</strong> <?php echo floatval($dados->porcentagem_valor_plano)."%"; ?><br>
							<?php if ($config->comissao_indicacao == "S"): ?>
								<strong>Porcentagem da Comissão por Indicação:</strong> <?php echo floatval($dados->porcentagem_comissao_plano)."%"; ?><br>
							<?php endif; ?>
							<strong>Porcentagem por Níveis:</strong><br>
								<ul>
									<?php 

										$niveis = $model->query("SELECT * FROM nivel WHERE id_plano = :id ORDER BY id_nivel ASC", [":id" => $dados->id_plano]);

										foreach ($niveis->fetchAll() as $i):

									?>
										<li><?php echo $i->nome_nivel.": ".number_format($i->porcentagem_nivel, 2, ",", "")."%"; ?></li>
									<?php endforeach; ?>
								</ul>
						</div>
					</div>
				</div>
			</div>
		<?php endforeach; ?>
	</div>
</div>

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