(function () {
    'use strict';

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

    document.body.classList.add('admin-modal-open');

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

    modal.querySelectorAll('[data-created-modal-close]').forEach(function (button) {
        button.addEventListener('click', closeModal);
    });

    document.addEventListener('keydown', function (event) {
        if (event.key === 'Escape') {
            closeModal();
        }
    });

    const linkInput = document.getElementById('invoiceCreatedContractLink');
    if (linkInput) {
        linkInput.focus();
        linkInput.select();
    }
})();
