<?php
require_once("../config/db.php"); //Contiene las variables de configuracion para conectar a la base de datos
require_once("../config/conexion.php"); //Contiene funcion que conecta a la base de datos
$x = 1;
$numero = $_POST['id'];

$coti = "SELECT * FROM cotizacion WHERE id_cotizacion = $numero";
$query_coti = mysqli_query($con, $coti);
$row_coti = mysqli_fetch_array($query_coti);

$doc = $row_coti['id_cliente'];
$nombres = $row_coti['nombres'];
$apellidos = $row_coti['apellidos'];
$telefono = $row_coti['telefono'];
$correo = $row_coti['correo'];
$direccion = $row_coti['direccion'];
$cant_adultos = $row_coti['cant_adultos'];
$cant_menores = $row_coti['cant_menores'];
$cant_infantes = $row_coti['cant_infantes'];
$tipo = $row_coti['tipo_cotizacion'];
$paq = $row_coti['paq_num'];

$total = $cant_adultos + $cant_menores + $cant_infantes - 1;

if ($tipo == 1) {
	$paque = "SELECT COUNT(id_viaje)AS total  FROM `viaje` WHERE estado = 0 AND codigo_viaje = $paq";
	$query_paque = mysqli_query($con, $paque);
	$row_paque = mysqli_fetch_array($query_paque);

	if (!isset($row_paque)) {
		$total_paq = 0;
	} else {
		$total_paq = $row_paque['total'];
	}
	if ($total > $total_paq) {
		echo "<script>alert('Lo sentimos, no hay cupos suficientes!!'); 
	conosole.log($total_paq);
	</script>";
	}
}
?>

<hr>
<label>Costos a M76</label>
<br>
<div class="form-group">
	<div class="row" style="padding: 0%; margin:0%; margin-top: 20px; margin-bottom: 20px;">
		<div class="col-sm-4">
			<label for="n_adultos" class="col-sm-8 control-label">Costo por Adulto</label>
			<input placeholder="costo Adultos" type="number" autocomplete="off" class="form-control" id="n_adultos" name="n_adultos" class="form-control" required>
		</div>

		<div class="col-sm-4">
			<label for="n_menores" class="col-sm-8 control-label">Costo por Menor</label>
			<input placeholder="costo Menores" type="number" autocomplete="off" class=" form-control" id="n_menores" name="n_menores" class="form-control" required>
		</div>

		<div class="col-sm-4">
			<label for="n_infantes" class="col-sm-8 control-label">Costo por Infante</label>
			<input placeholder="costo Infantes" type="number" autocomplete="off" id="n_infantes" name="n_infantes" class="form-control" required>
		</div>
	</div>
</div>
<hr>

<label>Solicitante</label>

<div class="form-group">
	<div class="row" style="padding: 0%; margin:0%;">

		<div class="col-sm-4">
			<label for="tipo_doc" class="control-label">Tipo documento</label>
			<select class="form-control col-md-2" name="tipo_doc" id="tipo_doc" required>
				<option style="text-align: center;">-Tipo Documento-</option>
				<?php
				$sql = "SELECT * FROM tipo_documentos";
				$query = mysqli_query($con, $sql);
				while ($row = mysqli_fetch_array($query)) {
					echo '<option style="text-align: center;" value="' . $row['id_tipo_doc'] . '" >' . $row['nombre_doc'] .  '</option>';
				}
				?>
			</select>
		</div>

		<div class="col-sm-4">
			<label for="n_doc" class="control-label">No. documento</label>
			<input class="col-md-2 form-control" value="<?php echo $doc ?>" disabled>
		</div>

		<div class="col-sm-4">
			<label for="edad" class="control-label">Edad</label>
			<input type="number" placeholder="edad" id="edad<?php echo $x ?>" name="edad<?php echo $x ?>" class="form-control" required>
		</div>
	</div>
</div>

<div class="form-group">
	<div class="row" style="padding: 0%; margin:0%;">
		<div class="col-sm-4">
			<label for="nombres" class="control-label">Nombres</label>
			<input class="form-control" value="<?php echo $nombres ?>" disabled>
		</div>

		<div class="col-sm-4">
			<label for="apellidos" class="control-label">Apellidos</label>
			<input class="form-control" value="<?php echo $apellidos ?>" disabled>
		</div>

		<div class="col-sm-4">
			<label for="tele" class="col-sm-4 control-label">Telefono</label>
			<input class="col-md-2 form-control" value="<?php echo $telefono ?>" disabled>
		</div>
	</div>
</div>

<div class="form-group">
	<div class="row" style="padding: 0%; margin:0%;">
		<div class="col-sm-4">
			<label for="correo" class="control-label">Correo</label>
			<input class="form-control" value="<?php echo $correo ?>" disabled>
		</div>
		<?php
		if (isset($nombre)) {
		?>
			<div class="col-sm-4">
				<label for="direccion" class="control-label">Direcci&oacute;n</label>
				<input class="orm-control" value="<?php echo $nombre ?>" disabled>
			</div>
		<?php
		} else {
		?>
			<div class="col-sm-4">
				<label for="direccion" class="control-label">Direcci&oacute;n</label>
				<input placeholder="Direccion" class="form-control" value="" required>
			</div>
		<?php
		}
		?>
		<div class="col-sm-4">
			<label for="n_cuenta" class="control-label">No. cuenta</label>
			<input class="form-control" placeholder="No. cuenta" required>
		</div>
	</div>
</div>
<hr>
<?php
while ($x <= $total) {
?>

	<h2><strong> Acompañante #<?php echo $x ?></strong></h2>

	<div class="form-group">
		<div class="row" style="padding: 0%; margin:0%;">
			<div class="col-sm-4">
				<label for="tipo_doc" class="control-label">Tipo documento</label>
				<select class="form-control" name="tipo_doc<?php echo $x ?>" id="tipo_doc<?php echo $x ?>" required>
					<option style="text-align: center;">-Tipo Documento-</option>
					<?php
					$sql = "SELECT * FROM tipo_documentos";
					$query = mysqli_query($con, $sql);
					while ($row = mysqli_fetch_array($query)) {
						echo '<option style="text-align: center;" value="' . $row['id_tipo_doc'] . '" >' . $row['nombre_doc'] .  '</option>';
					}
					?>
				</select>
			</div>
			<div class="col-sm-4">
				<label for="n_doc" class="control-label" style="width: auto;">No. documento</label>
				<input placeholder="No. personas" type="text" class="form-control" id="n_doc<?php echo $x ?>" name="n_doc<?php echo $x ?>" required>
			</div>

			<div class="col-sm-4">
				<label for="edad" class="control-label">Edad</label>
				<input type="number" placeholder="Edad" id="edad<?php echo $x ?>" name="edad<?php echo $x ?>" class="form-control" required>
			</div>
		</div>
	</div>

	<div class="form-group">
		<div class="row" style="padding: 0%; margin:0%;">
			<div class="col-sm-4">
				<label for="nombres" class="control-label">Nombres</label>
				<input placeholder="Nombre completo" type="text" class="form-control" id="nombres<?php echo $x ?>" name="nombres<?php echo $x ?>" required>
			</div>

			<div class="col-sm-4">
				<label for="apellidos" class="control-label">Apellidos</label>
				<input type="text" placeholder="Apellidos" id="apellidos<?php echo $x ?>" name="apellidos<?php echo $x ?>" class="form-control" required>
			</div>

			<div class="col-sm-4">
				<label for="tele" class="control-label">Telefono</label>
				<input type="text" placeholder="No. Telefono" id="tele<?php echo $x ?>" name="tele<?php echo $x ?>" class="form-control" required>
			</div>
		</div>
	</div>

	<div class="form-group">
		<div class="row" style="padding: 0%; margin:0%;">
			<div class="col-sm-4">
				<label for="correo" class="control-label">Correo</label>
				<input placeholder="Correo electronico" type="text" class="form-control" id="correo<?php echo $x ?>" name="correo<?php echo $x ?>" required>
			</div>

			<div class="col-sm-4">
				<label for="direccion" class="control-label">Direcci&oacute;n</label>
				<input type="text" placeholder="Direccion" id="direccion<?php echo $x ?>" name="direccion<?php echo $x ?>" class="form-control" required>
			</div>

			<div class="col-sm-4">
				<label for="n_cuenta" class="control-label">No. cuenta</label>
				<input type="text" placeholder="No. Cuenta" id="n_cuenta<?php echo $x ?>" name="n_cuenta<?php echo $x ?>" class="form-control" required>
			</div>
		</div>
	</div>
	<hr>
<?php
	$x++;
}

?>

<script>
	$(document).on('click', '.radio', function() {
		let radio = $(this).attr("data-cod_rad");
		alert(radio);
	});
</script>