<?php
$status = $_GET['status'] ?? null;
$message = $_GET['message'] ?? '';
?>
<link rel="stylesheet" href="css/modals.css">

<!-- Modal de Éxito -->
<div class="modal fade" id="successModal" tabindex="-1" role="dialog" aria-labelledby="successModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content text-white bg-dark">
      <div class="modal-body text-center">
        <div class="circle-loader">
          <div class="checkmark">✔</div>
        </div>
        <h4 class="mt-3">¡Operación exitosa!</h4>
      </div>
    </div>
  </div>
</div>

<!-- Modal de Error -->
<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content text-white bg-dark">
      <div class="modal-body text-center">
        <div class="circle-loader error">
          <div class="x-mark">✖</div>
        </div>
        <h4 class="mt-3">¡Ocurrió un error!</h4>
      </div>
    </div>
  </div>
</div>


<script>
document.addEventListener("DOMContentLoaded", function () {
    const urlParams = new URLSearchParams(window.location.search);
    const status = urlParams.get("status");
    const message = urlParams.get("message");

    if (status && message) {
        if (status === "1") {
            const successModal = new bootstrap.Modal(document.getElementById('successModal'));
            successModal.show();
        } else if (status === "0") {
            const errorModal = new bootstrap.Modal(document.getElementById('errorModal'));
            errorModal.show();
        }

        // Limpiar parámetros de la URL sin recargar
        const url = new URL(window.location);
        url.searchParams.delete('status');
        url.searchParams.delete('message');
        window.history.replaceState({}, document.title, url);
    }
});
</script>

