$(function () {
  const regexActionChange = /&action=(dozurlaubloeschen|(re)?setFilterUrlaubeUebersicht)/;
  if (regexActionChange.test(window.location.href)) {
    KuferTools.ReplaceCurrentHistory(window.location.href.replace(regexActionChange, ''));
  }

  /** @type {NodeListOf<HTMLElement>} */
  const loeschenBtns = document.querySelectorAll('.dozurlaubloeschen');
  loeschenBtns.forEach(function (btn) {
    btn.addEventListener('click', function (event) {
      event.preventDefault();

      let buttons = {
        'Ja': function () {
          document.location.href = btn.parentElement.href;
        },
        'Nein': function () {
          $(this).dialog('close');
        }
      };

      KuferTools.showMessage({
        meldung: 'Möchten Sie diesen Urlaub wirlich löschen?',
        title: 'Urlaub löschen',
        buttons: buttons
      });
    });
    btn.disabled = false;
  });

  const valTimeVon = document.getElementById('dozurlaub_zeit_beg');
  const valTimeBis = document.getElementById('dozurlaub_zeit_ende');
  if (valTimeVon !== null && valTimeBis !== null) {
    valTimeVon.classList.add('val_time_von');
    valTimeBis.classList.add('val_time_bis');
  }
});