(function () {
    'use strict';

    const modal = document.getElementById('contractDetailsDeleteModal');
    if (!modal) {
        return;
    }

    const openBtn = document.getElementById('contractDetailsDeleteBtn');
    const backdrop = modal.querySelector('[data-modal-close]');
    const cancelButtons = modal.querySelectorAll('[data-modal-cancel]');

    function openModal() {
        modal.classList.remove('hidden');
        document.body.classList.add('admin-modal-open');
    }

    function closeModal() {
        modal.classList.add('hidden');
        document.body.classList.remove('admin-modal-open');
    }

    if (openBtn) {
        openBtn.addEventListener('click', openModal);
    }

    if (backdrop) {
        backdrop.addEventListener('click', closeModal);
    }

    cancelButtons.forEach(function (button) {
        button.addEventListener('click', closeModal);
    });

    document.addEventListener('keydown', function (event) {
        if (event.key === 'Escape' && !modal.classList.contains('hidden')) {
            closeModal();
        }
    });
})();
