(function (window, $) {
	'use strict';

	window.scWordaiShowInfoDialog = function (title, message, onConfirm, onCancel) {
		var confirmed = false;
		var dialog = $('#scWordaiGlobalInfoDialog');

		if (!dialog.length) {
			dialog = $(
				'<div id="scWordaiGlobalInfoDialog" style="display:none;">' +
					'<div class="sc-wordai-modal-message"></div>' +
				'</div>'
			).appendTo('body');
		}

		dialog.find('.sc-wordai-modal-message').html(message);
		dialog.dialog({
			modal: true,
			title: title,
			width: 480,
			resizable: false,
			draggable: true,
			closeOnEscape: true,
			closeText: 'Close dialog',
			dialogClass: 'sc-wordai-modal-default sc-wordai-provider-switch-dialog',
			buttons: [
				{
					text: 'OK',
					class: 'button button-primary',
					click: function () {
						confirmed = true;
						$(this).dialog('close');
						if (typeof onConfirm === 'function') {
							onConfirm();
						}
					}
				}
			],
			open: function () {
				var widget = $(this).dialog('widget');
				widget.css('z-index', 999999);
				widget.find('.ui-dialog-buttonpane button').focus();
			},
			close: function () {
				if (!confirmed && typeof onCancel === 'function') {
					onCancel();
				}
			}
		});
	};
})(window, jQuery);
