<?php
session_start();
if (!isset($_SESSION['rol']) || !in_array($_SESSION['rol'], ['admin', 'coordinador'])) {
  header('Location: ../../index.php');
  exit;
}
require_once __DIR__ . '/../includes/valida_posiciones.php';
?>
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <title>Panel de Vacantes Mapa</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <!-- Bootstrap 5 + FontAwesome + MDB -->
  <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="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/6.4.0/mdb.min.css" rel="stylesheet" />
  <link href="../assets/css/mapa.css" rel="stylesheet" />
  <link href="../assets/css/recruiter.css" rel="stylesheet" />
  <link href="../assets/css/vacantes.css" rel="stylesheet" />
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

</head>
<body class="bg-light">
<?php include '../includes/sidebar.php'; ?>
<div class="main-content flex-grow-1 px-4 py-4">
<?php include '../includes/topbar.php'; ?>

<div class="container py-4">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h2 class="mb-0 text-primary"><i class="fas fa-map me-2"></i>Presencia Nacional</h2>
  </div>

  <!-- Filtros -->
  <div class="card mb-4">
    <div class="card-body row g-3">
      <div class="col-md-6">
        <label class="form-label"><i class="fas fa-map-marker-alt me-2 text-secondary"></i>Zona</label>
        <select id="filtroZona" class="form-select">
          <option value="">Todas las zonas</option>
        </select>
      </div>
      <div class="col-md-6">
        <label class="form-label"><i class="fas fa-store-alt me-2 text-secondary"></i>PDV</label>
        <select id="filtroPDV" class="form-select">
          <option value="">Todos los PDVs</option>
        </select>
      </div>
      <div class="col-md-6">
        <div class="form-check mt-4">
          <input class="form-check-input" type="checkbox" id="filtroSoloVacantes">
          <label class="form-check-label" for="filtroSoloVacantes">
            Mostrar solo vacantes disponibles
          </label>
        </div>
      </div>
    </div>
  </div>

  <!-- Mapa interactivo -->
  <div class="contenedor-mapa">
    <div id="map" style="width:100%; height:600px;"></div>
  </div>
</div>

<!-- Modal Detalle -->
<div class="modal fade" id="modalDetallePDV" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-scrollable">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Vacantes del PDV</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>
      <div class="modal-body" id="contenidoDetallePDV">
        <!-- Aquí se carga dinámicamente -->
      </div>
    </div>
  </div>
</div>

<!-- Scripts del mapa -->
<!-- 1. mapdata primero -->
<script src="../assets/mapa/mapdata.js"></script>

<!-- 2. luego la librería -->
<script src="../assets/mapa/countrymap.js"></script>

<!-- 3. finalmente funciones y hooks -->
<script src="../assets/mapa/mapa.js"></script>

<script>
  document.addEventListener("DOMContentLoaded", () => {
    if (typeof simplemaps_countrymap !== "undefined") {
      simplemaps_countrymap.load();
    }
  });
</script>

