<?php
session_start();
if (!isset($_SESSION['attuid']) || ($_SESSION['rol'] ?? '') !== 'subdistribuidor') {
    header('Location: ../../index.php');
    exit;
}

require_once __DIR__ . '/../../backend/db/conexion.php';
require_once __DIR__ . '/../includes/valida_posiciones.php';

$attuid = $_SESSION['attuid'] ?? '';
$sector = '';

if ($attuid) {
    $stmt = $conn->prepare("SELECT Sector FROM sectoresdPDVs WHERE ATTUIDEncargado = ?");
    $stmt->bind_param("s", $attuid);
    $stmt->execute();
    $stmt->bind_result($sector);
    $stmt->fetch();
    $stmt->close();
    $_SESSION['sector'] = $sector; // Si quieres, para otras vistas
}
$id = intval($_GET['id'] ?? 0);
?>
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <title>Detalle Aspirante</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
  <link href="../assets/css/recruiter.css" rel="stylesheet">
</head>
<!-- ...el código PHP de sesión e includes... -->
<body class="bg-light">
  <!-- Inyecta rol y sector a JS -->
  <script>
    const rolUsuario = "<?= $_SESSION['rol'] ?? ''; ?>";
    const sectorUsuario = "<?= addslashes($sector); ?>";
  </script>

  <div class="d-flex">
    <?php include '../includes/sidebar.php'; ?>
    <div class="main-content" id="mainContent">
      <?php include '../includes/topbar.php'; ?>
      <div class="container-fluid p-4" id="detalle-candidato-container">
        <div class="text-center my-5"><div class="spinner-border text-primary"></div> Cargando datos...</div>
      </div>
    </div>
  </div>

  <!-- Incluye modales y componentes solo una vez -->
  <?php include '../includes/detail/vacantes.php'; ?>
  <?php include_once(__DIR__ . '/../includes/modals/modal-datos-rocasa.php'); ?>
  <?php include '../includes/detail/modal-detalle-empleado.php'; ?>
  <?php include '../includes/modals/modal-solicitar-prm.php'; ?>
  <?php include '../includes/detail/modal-detalle-empleado.php'; ?>
  <?php include '../includes/detail/modal-comentario.php'; ?>

  <!-- Scripts -->
  <script src="../assets/js/llenar-detalle-empleado.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  <script src="../assets/js/subdistribuidor/detalle-candidato.js"></script>
  <script src="../assets/js/subdistribuidor/solicitud-PRM-subd.js"></script>

</body>
</html>
