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

	const app = window.WPMDEmailTemplatesApp;

	if (!app) {
		return;
	}

	app.register(() => {
		const modal = app.resolve('modal');

		if (!modal) {
			return;
		}

		$(document).on('click', '.wpmd-device-toggle', function (event) {
			event.preventDefault();
			const $button = $(this);
			const device = $button.data('device') || 'desktop';

			modal.setDevice(device);
			$button.addClass('is-active').siblings('.wpmd-device-toggle').removeClass('is-active');
		});

		$('.wpmd-device-toggle[data-device="' + (app.state.device || 'desktop') + '"]').addClass('is-active').siblings('.wpmd-device-toggle').removeClass('is-active');
	});
})(window, jQuery);
