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

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

		// Add the confirmation 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>
				<button class="btn btn-primary btn-dialog btn-dialog-cancel">
					Cancel
				</button>
			</div)>
		`;

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

		super.show();
	}

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