+
+
+ ${dialog.icon !== DialogIcon.NONE ? `
` : ''}
+
${dialog.message}
+
+
+ ${dialog.buttons.map(button =>
+ ``
+ ).join('')}
+
+
+ `;
+
+ // add click handlers for buttons
+ const buttons = dialogElement.querySelectorAll('.dialog-button');
+ buttons.forEach(button => {
+ button.addEventListener('click', () => this.handleButtonClick(button.dataset.button));
+ });
+
+ // add keyboard support
+ const keyHandler = (e) => {
+ if (e.key === 'Escape' && dialog.buttons.includes(DialogButton.CANCEL))
+ this.handleButtonClick(DialogButton.CANCEL);
+ if (e.key === 'Enter' && dialog.buttons.includes(DialogButton.OK))
+ this.handleButtonClick(DialogButton.OK);
+ };
+ document.addEventListener('keydown', keyHandler);
+
+ this.container.appendChild(dialogElement);
+ }
+
+ /**
+ * Handles button clicks and resolves the dialog promise.
+ * @private
+ * @param {DialogButton} buttonType - The type of button clicked.
+ */
+ handleButtonClick(buttonType) {
+ const currentDialog = this.dialogQueue.shift();
+ const dialogElement = this.container.querySelector('.dialog');
+
+ if (dialogElement)
+ dialogElement.remove();
+
+ if (this.dialogQueue.length === 0) {
+ const modalBackground = document.getElementById('modal-background-article');
+ modalBackground.style.display = 'none';
+ this.container.style.display = 'none';
+ }
+
+ currentDialog.resolve(buttonType);
+ this.showNextDialog();
+ }
+
+ /**
+ * Gets the localized text for a button type.
+ * @private
+ * @param {DialogButton} buttonType - The button type.
+ * @returns {string} The localized button text.
+ */
+ getLocalizedButtonText(buttonType) {
+ return jsLocalizedDialogs[buttonType.toLowerCase()] || buttonType;
+ }
+}
+
+// create a global instance of the DialogService
+const dialogService = new DialogService();