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

	const app = window.WPMDEmailTemplatesApp;

	if (!app) {
		return;
	}

	function speak(message) {
		if (window.wp && window.wp.a11y && typeof window.wp.a11y.speak === 'function') {
			window.wp.a11y.speak(message);
		}
	}

	app.provide('notices', {
		show(message) {
			const $form = app.$form;

			if (!$form || !$form.length) {
				return;
			}

			const safe = app.utils && app.utils.escapeHtml ? app.utils.escapeHtml(message) : message;

			speak(message);
			$('.wpmd-inline-message').remove();
			$('<div class="notice notice-info wpmd-inline-message"><p>' + safe + '</p></div>').prependTo($form);
		},
		clear() {
			$('.wpmd-inline-message').remove();
		},
	});
})(window, jQuery);
