<?php

$message = '';

if (!empty($_SESSION['message'])) {
  $message = $_SESSION['message'];
  unset($_SESSION['message']);

  echo '
  <div id="popup_modal" class="modal popup-modal notification-modal" role="dialog" data-title="" aria-label="Popup Modal" aria-hidden="false" style="display: block;">
    <div class="modal-dialog">
      <div class="modal-content" style="--desktop-popup-alert-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/' . $config['theme'] . '/desktop/layout/popup/notification.png); --mobile-popup-alert-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/' . $config['theme'] . '/mobile/layout/popup/notification.png);">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
          <h4 class="modal-title" id="popup_modal_title"></h4>
        </div>
        <div class="modal-body" id="popup_modal_body">
          <p>' . htmlspecialchars($message, ENT_QUOTES, 'UTF-8') . '</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" data-dismiss="modal" id="popup_modal_dismiss_button">OK</button>
          <button type="button" class="btn btn-secondary" data-dismiss="modal" id="popup_modal_cancel_button" style="display: none">Batal</button>
          <button type="button" class="btn btn-primary" id="popup_modal_confirm_button" style="display: none">OK</button>
        </div>
      </div>
    </div>
  </div>';
} elseif (!empty($_SESSION['error'])) {
  $message = $_SESSION['error'];
  unset($_SESSION['error']);

  echo '
  <div id="popup_modal" class="modal popup-modal alert-modal" role="dialog" data-title="" aria-label="Popup Modal" aria-hidden="false" style="display: block;">
    <div class="modal-dialog">
      <div class="modal-content" style="--desktop-popup-alert-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/' . $config['theme'] . '/desktop/layout/popup/alert.png); --mobile-popup-alert-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/' . $config['theme'] . '/mobile/layout/popup/alert.png);">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
          <h4 class="modal-title" id="popup_modal_title"></h4>
        </div>
        <div class="modal-body" id="popup_modal_body">
          <p>' . htmlspecialchars($message, ENT_QUOTES, 'UTF-8') . '</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" data-dismiss="modal" id="popup_modal_dismiss_button">OK</button>
          <button type="button" class="btn btn-secondary" data-dismiss="modal" id="popup_modal_cancel_button" style="display: none">Batal</button>
          <button type="button" class="btn btn-primary" id="popup_modal_confirm_button" style="display: none">OK</button>
        </div>
      </div>
    </div>
  </div>';
}
?>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    document.getElementById('popup_modal_dismiss_button').addEventListener('click', function() {
      document.getElementById('popup_modal').style.display = 'none';
    });
  });
</script>
