var BaseDialog = require('libresignage/ui/components/Dialog/BaseDialog');

/**
* A class representing an alert dialog.
*
* @memberof module:libresignage/ui/components/Dialog
*/
class AlertDialog extends BaseDialog {
	/**
	* Construct a new AlertDialog object.
	*
	* @param {string}              title    The title of the dialog.
	* @param {string}              body     The body of the dialog.
	* @param {BaseDialog_callback} callback A callback function.
	*/
	constructor(title, body, callback) {
		super(title, body);

		// Addd the alert dialog buttons and event listeners.
		this.dialog.querySelector('.dialog').innerHTML += `
			<div class="dialog-interaction">
				<button class="btn btn-primary btn-dialog btn-dialog-ok">
					Ok
				</button>
			</div>
		`;

		this.dialog
			.querySelector('.btn-dialog-ok')
			.addEventListener('click', () => {
				super.hide();
				if (callback) { callback(true); }
			});

		super.show();
	}

	/**
	* Set focus on the OK button.
	*/
	focus_default() {
		document.querySelector('.btn-dialog-ok').focus();
	}
}
module.exports = AlertDialog;
