(function ($) {
	'use strict';

	if (typeof scwordai_seo_scan === 'undefined') {
		return;
	}

	var state = {
		postType: (scwordai_seo_scan.initial_filters && scwordai_seo_scan.initial_filters.post_type) || Object.keys(scwordai_seo_scan.post_types || {})[0] || 'post',
		page: 1,
		totalPages: 1,
		loading: false,
		job: scwordai_seo_scan.scheduled_job || null,
		jobTimer: null,
		seoIntegration: scwordai_seo_scan.seo_integration || {}
	};

	function esc(value) {
		return $('<div>').text(value == null ? '' : String(value)).html();
	}

	function strings(key) {
		return (scwordai_seo_scan.strings && scwordai_seo_scan.strings[key]) || '';
	}

	function formatLinkedText(value) {
		return esc(value).replace(
			/(https:\/\/softcoy\.com\/products\/wordai-pro(?:\/checkout)?)/g,
			'<a href="$1" target="_blank" rel="noopener">Upgrade to WordAI Pro</a>'
		);
	}

	function setFeedback(message, type) {
		var $box = $('[data-wordai-seo-feedback]');
		if (!message) {
			$box.prop('hidden', true).removeClass('is-success is-error is-info').text('');
			return;
		}

		$box
			.prop('hidden', false)
			.removeClass('is-success is-error is-info')
			.addClass(type === 'error' ? 'is-error' : (type === 'success' ? 'is-success' : 'is-info'))
			.html(formatLinkedText(message));
	}

	function updateUsage(usage) {
		if (!usage) return;
		$('[data-wordai-usage-used]').text(usage.used);
		$('[data-wordai-usage-limit]').text(usage.limit);
	}

	function setLoading() {
		$('[data-wordai-seo-list]').html(
			'<tr><td colspan="6" class="sc-wordai-seo-loading">' + esc(strings('loading') || 'Loading SEO items...') + '</td></tr>'
		);
	}

	function scoreBadge(row) {
		if (row.score === null || typeof row.score === 'undefined') {
			return '<span class="sc-wordai-seo-score is-empty">--</span>';
		}

		return '<span class="sc-wordai-seo-score is-' + esc(row.grade || 'poor') + '">' + esc(row.score) + '</span>';
	}

	function statusBadge(row) {
		var cls = row.status || 'unscanned';
		return '<span class="sc-wordai-seo-status is-' + esc(cls) + '">' + esc(row.status_label) + '</span>';
	}

	function detailsList(items) {
		if (!items || !items.length) {
			return '<span class="sc-wordai-seo-muted">No issues found from the last scan.</span>';
		}

		return '<ul>' + items.map(function (item) {
			return '<li>' + formatLinkedText(item) + '</li>';
		}).join('') + '</ul>';
	}

	function rowAdvice(row, title) {
		var upgradeUrl = scwordai_seo_scan.upgrade_url || 'https://softcoy.com/products/wordai-pro/checkout';

		if (scwordai_seo_scan.is_basic_tier) {
			return '' +
				'<div class="sc-wordai-seo-advice sc-wordai-seo-advice--upgrade">' +
					'<i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i>' +
					'<span>Use full SEO features for stronger search engine visibility and higher ranking potential. ' +
					'<a href="' + esc(upgradeUrl) + '" target="_blank" rel="noopener">Upgrade to WordAI Pro</a> to unlock full SEO generation, unlimited SEO Scan, and AI Auto Fix.</span>' +
				'</div>';
		}

		if (row.issue_count > 0) {
			return '' +
				'<div class="sc-wordai-seo-advice sc-wordai-seo-advice--edit">' +
					'<i class="fa-solid fa-circle-info" aria-hidden="true"></i>' +
					'<span>Some SEO improvements may need content changes after AI Auto Fix. Go to the ' +
					'<a href="' + esc(row.edit_url) + '" aria-label="Edit ' + title + '">Edit</a> page and rerun WordAI content or SEO generation options to make this content more SEO compatible.</span>' +
				'</div>';
		}

		return '';
	}

	function rowTemplate(row) {
		var issueSummary = row.issue_count ? row.issue_count + ' issue' + (row.issue_count > 1 ? 's' : '') : 'No issues';
		var title = esc(row.title);
		var keyword = row.focus_keyword ? esc(row.focus_keyword) : '<span class="sc-wordai-seo-muted">Not set</span>';

		var undoButton = row.change_id ?
			'<button type="button" class="button button-secondary sc-wordai-seo-undo-row" data-post-id="' + esc(row.id) + '" title="Undo last SEO change" aria-label="Undo last SEO change for ' + title + '">' +
				'<i class="fa-solid fa-rotate-left" aria-hidden="true"></i><span>Undo</span>' +
			'</button>' : '';

		return '' +
			'<tr data-post-id="' + esc(row.id) + '">' +
				'<td class="column-title">' +
					'<strong><a href="' + esc(row.edit_url) + '">' + title + '</a></strong>' +
					'<div class="sc-wordai-seo-row-meta">' + esc(row.post_status) + ' · ' + esc(issueSummary) + '</div>' +
					'<details class="sc-wordai-seo-details">' +
						'<summary>Suggestions</summary>' +
						'<div class="sc-wordai-seo-details-grid">' +
							'<div><b>Issues</b>' + detailsList(row.issues) + '</div>' +
							'<div><b>Recommended fixes</b>' + detailsList(row.suggestions) + '</div>' +
						'</div>' +
						rowAdvice(row, title) +
					'</details>' +
				'</td>' +
				'<td>' + statusBadge(row) + '</td>' +
				'<td>' + scoreBadge(row) + '</td>' +
				'<td>' + keyword + '</td>' +
				'<td>' + esc(row.modified) + '</td>' +
				'<td class="column-actions">' +
					'<button type="button" class="button button-secondary sc-wordai-seo-scan-row" data-post-id="' + esc(row.id) + '" title="Scan SEO" aria-label="Scan SEO for ' + title + '">' +
						'<i class="fa-solid fa-magnifying-glass-chart" aria-hidden="true"></i><span>Scan</span>' +
					'</button>' +
					'<button type="button" class="button button-primary sc-wordai-seo-autofix-row" data-post-id="' + esc(row.id) + '" title="AI Auto Fix" aria-label="AI Auto Fix for ' + title + '">' +
						'<i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i><span>AI Auto Fix</span>' +
					'</button>' +
					'<a class="button button-secondary sc-wordai-seo-edit-row" href="' + esc(row.edit_url) + '" title="Edit content" aria-label="Edit ' + title + '">' +
						'<i class="fa-solid fa-pen-to-square" aria-hidden="true"></i><span>Edit</span>' +
					'</a>' + undoButton +
				'</td>' +
			'</tr>';
	}

	function renderRows(items) {
		if (!items || !items.length) {
			$('[data-wordai-seo-list]').html(
				'<tr><td colspan="6" class="sc-wordai-seo-empty">' + esc(strings('empty') || 'No content found for this tab.') + '</td></tr>'
			);
			return;
		}

		$('[data-wordai-seo-list]').html(items.map(rowTemplate).join(''));
	}

	function updatePager(page, totalPages) {
		state.page = page || 1;
		state.totalPages = totalPages || 1;
		$('[data-wordai-page-label]').text('Page ' + state.page + ' of ' + state.totalPages);
		$('[data-wordai-page-prev]').prop('disabled', state.page <= 1);
		$('[data-wordai-page-next]').prop('disabled', state.page >= state.totalPages);
	}

	function loadList(page) {
		if (state.loading) return;
		state.loading = true;
		state.page = page || state.page || 1;
		setFeedback('', 'info');
		setLoading();

		$.ajax({
			type: 'POST',
			url: scwordai_seo_scan.adminajax_url,
			data: {
				action: 'sc_wordai_seo_scan_list',
				security: scwordai_seo_scan.nonce,
				post_type: state.postType,
				page_num: state.page,
				per_page: $('#sc-wordai-seo-per-page').val() || 20,
				search: $('#sc-wordai-seo-search').val() || '',
				post_status: $('#sc-wordai-seo-post-status').val() || 'publish',
				seo_filter: $('#sc-wordai-seo-filter').val() || 'all'
			}
		}).done(function (response) {
			if (!response || !response.success) {
				setFeedback(esc((response && response.data && response.data.message) || strings('scan_failed')), 'error');
				renderRows([]);
				return;
			}

			renderRows(response.data.items);
			updatePager(response.data.page, response.data.total_pages);
			updateUsage(response.data.usage);
			highlightFocusedRow();
		}).fail(function () {
			setFeedback(esc(strings('scan_failed') || 'SEO scan failed. Please try again.'), 'error');
			renderRows([]);
		}).always(function () {
			state.loading = false;
		});
	}

	function refreshSingleRow(row) {
		if (!row || !row.id) {
			loadList(state.page);
			return;
		}

		var $oldRow = $('tr[data-post-id="' + row.id + '"]');
		if ($oldRow.length) {
			$oldRow.replaceWith(rowTemplate(row));
		} else {
			loadList(state.page);
		}
	}

	function applyInitialFilters() {
		var filters = scwordai_seo_scan.initial_filters || {};
		if (filters.search) {
			$('#sc-wordai-seo-search').val(filters.search);
		}
		if (filters.post_status) {
			$('#sc-wordai-seo-post-status').val(filters.post_status);
		}
		if (filters.post_type && (scwordai_seo_scan.post_types || {})[filters.post_type]) {
			state.postType = filters.post_type;
			$('.sc-wordai-seo-tab').removeClass('is-active');
			$('.sc-wordai-seo-tab[data-post-type="' + filters.post_type + '"]').addClass('is-active');
			var label = (scwordai_seo_scan.post_types[state.postType] || {}).label || 'Posts';
			$('[data-wordai-seo-current-label]').text(label);
		}
	}

	function highlightFocusedRow() {
		var filters = scwordai_seo_scan.initial_filters || {};
		var focusPost = Number(filters.focus_post || 0);
		if (!focusPost) {
			return;
		}
		var $row = $('tr[data-post-id="' + focusPost + '"]');
		if (!$row.length) {
			return;
		}
		$row.addClass('is-wordai-focus-row');
		$row[0].scrollIntoView({ behavior: 'smooth', block: 'center' });
		setTimeout(function () {
			$row.removeClass('is-wordai-focus-row');
		}, 5000);
	}

	function runItemAction(action, postId, $button) {
		if (!postId || $button.prop('disabled')) return;

		var original = $button.html();
		$button.prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin" aria-hidden="true"></i><span>Working</span>');
		setFeedback('', 'info');

		$.ajax({
			type: 'POST',
			url: scwordai_seo_scan.adminajax_url,
			data: {
				action: action,
				security: scwordai_seo_scan.nonce,
				post_id: postId
			}
		}).done(function (response) {
			if (!response || !response.success) {
				var data = response && response.data ? response.data : {};
				updateUsage(data.usage);
				setFeedback(esc(data.message || strings('scan_failed')), 'error');
				return;
			}

			refreshSingleRow(response.data.row);
			updateUsage(response.data.usage);
			setFeedback(esc(response.data.message || 'SEO item updated.'), 'success');
		}).fail(function () {
			setFeedback(esc(action === 'sc_wordai_seo_scan_autofix' ? strings('autofix_failed') : strings('scan_failed')), 'error');
		}).always(function () {
			$button.prop('disabled', false).html(original);
		});
	}

	function proposalValue(value) {
		if (Array.isArray(value)) {
			value = value.join(', ');
		} else if (value && typeof value === 'object') {
			value = JSON.stringify(value);
		}

		return value ? esc(value) : '<span class="sc-wordai-seo-proposal-empty">Not set</span>';
	}

	function proposalRow(label, key, before, after, supported) {
		var beforeValue = before && typeof before[key] !== 'undefined' ? before[key] : '';
		var afterValue = after && typeof after[key] !== 'undefined' ? after[key] : '';
		if (supported === false) {
			afterValue = '<span class="sc-wordai-seo-proposal-empty">Not managed by this integration</span>';
		}

		return '' +
			'<div class="sc-wordai-seo-proposal-row">' +
				'<strong>' + esc(label) + '</strong>' +
				'<div><span>Before</span><p>' + proposalValue(beforeValue) + '</p></div>' +
				'<div><span>Proposed</span><p>' + (supported === false ? afterValue : proposalValue(afterValue)) + '</p></div>' +
			'</div>';
	}

	function openProposalDialog(postId, preview, $sourceButton, originalButtonHtml) {
		var fields = [
			['SEO title', 'title'],
			['Meta description', 'description'],
			['Focus keyword', 'focus_keyword'],
			['Canonical URL', 'canonical'],
			['Robots', 'robots'],
			['Schema type', 'schema_type']
		];
		var html = '<div class="sc-wordai-seo-proposal-provider"><i class="fa-solid fa-shield-halved" aria-hidden="true"></i>' +
			'<span>Changes will be published through <strong>' + esc(preview.provider || 'WordAI') + '</strong>.</span></div>';

		fields.forEach(function (field) {
			var supported = !preview.supported_fields || preview.supported_fields[field[1]] !== false;
			html += proposalRow(field[0], field[1], preview.before || {}, preview.after || {}, supported);
		});

		var $dialog = $('#sc-wordai-seo-proposal-modal');
		$dialog.html(html).dialog({
			modal: true,
			width: Math.min(920, Math.max(320, $(window).width() - 40)),
			maxHeight: Math.max(420, $(window).height() - 80),
			resizable: false,
			buttons: [
				{
					text: 'Approve and Apply',
					class: 'button button-primary',
					click: function () {
						var $approveButton = $dialog.dialog('widget').find('.ui-dialog-buttonpane .button-primary');
						$approveButton.prop('disabled', true).text('Applying...');
						$.ajax({
							type: 'POST',
							url: scwordai_seo_scan.adminajax_url,
							data: {
								action: 'sc_wordai_seo_scan_autofix',
								security: scwordai_seo_scan.nonce,
								post_id: postId,
								approval_token: preview.approval_token
							}
						}).done(function (response) {
							if (!response || !response.success) {
								var data = response && response.data ? response.data : {};
								updateUsage(data.usage);
								setFeedback(data.message || strings('autofix_failed'), 'error');
								return;
							}
							refreshSingleRow(response.data.row);
							updateUsage(response.data.usage);
							setFeedback(response.data.message || 'SEO fields were updated and rescanned.', 'success');
							$dialog.dialog('close');
						}).fail(function () {
							setFeedback(strings('autofix_failed') || 'AI auto-fix failed. Please try again.', 'error');
						}).always(function () {
							$approveButton.prop('disabled', false).text('Approve and Apply');
						});
					}
				},
				{
					text: 'Cancel',
					click: function () {
						$(this).dialog('close');
					}
				}
			],
			close: function () {
				$sourceButton.prop('disabled', false).html(originalButtonHtml);
			}
		});
	}

	function requestAutofixPreview(postId, $button) {
		if (!postId || $button.prop('disabled')) return;

		var original = $button.html();
		$button.prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin" aria-hidden="true"></i><span>Preparing</span>');
		setFeedback('', 'info');

		$.ajax({
			type: 'POST',
			url: scwordai_seo_scan.adminajax_url,
			data: {
				action: 'sc_wordai_seo_scan_autofix',
				security: scwordai_seo_scan.nonce,
				post_id: postId
			}
		}).done(function (response) {
			if (!response || !response.success || !response.data || !response.data.preview) {
				var data = response && response.data ? response.data : {};
				updateUsage(data.usage);
				setFeedback(data.message || strings('autofix_failed'), 'error');
				$button.prop('disabled', false).html(original);
				return;
			}

			openProposalDialog(postId, response.data, $button, original);
		}).fail(function () {
			setFeedback(strings('autofix_failed') || 'AI auto-fix failed. Please try again.', 'error');
			$button.prop('disabled', false).html(original);
		});
	}

	function saveSeoOwner($button) {
		var provider = $('#sc-wordai-seo-owner').val() || 'auto';
		var original = $button.html();
		$button.prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin" aria-hidden="true"></i><span>Saving</span>');

		$.ajax({
			type: 'POST',
			url: scwordai_seo_scan.adminajax_url,
			data: {
				action: 'sc_wordai_seo_integration_save',
				security: scwordai_seo_scan.nonce,
				provider: provider
			}
		}).done(function (response) {
			if (!response || !response.success) {
				setFeedback((response && response.data && response.data.message) || 'Unable to update the SEO owner.', 'error');
				return;
			}
			state.seoIntegration = response.data.status || {};
			setFeedback(response.data.message || 'SEO output owner updated.', 'success');
			window.location.reload();
		}).fail(function () {
			setFeedback('Unable to update the SEO owner.', 'error');
		}).always(function () {
			$button.prop('disabled', false).html(original);
		});
	}

	function formatLocalDateTime(date) {
		var pad = function (num) {
			num = String(num);
			return num.length < 2 ? '0' + num : num;
		};

		return date.getFullYear() + '-' +
			pad(date.getMonth() + 1) + '-' +
			pad(date.getDate()) + 'T' +
			pad(date.getHours()) + ':' +
			pad(date.getMinutes());
	}

	function setDefaultScheduleTime() {
		var $input = $('#sc-wordai-seo-schedule-time');
		if (!$input.val()) {
			$input.val(formatLocalDateTime(new Date(Date.now() + (10 * 60 * 1000))));
		}
	}

	function collectSchedulePostTypes() {
		var values = [];
		$('input[name="sc-wordai-seo-schedule-post-types"]:checked').each(function () {
			values.push($(this).val());
		});
		return values;
	}

	function renderJobSummary(job) {
		state.job = job || null;
		var $box = $('[data-wordai-seo-job-summary]');
		if (!job) {
			$box.prop('hidden', true).html('');
			return;
		}

		var isActive = job.status === 'queued' || job.status === 'running';
		var meta = [
			'<span><b>Task:</b> ' + esc(job.task_label || 'Scan') + '</span>',
			'<span><b>Scope:</b> ' + esc(job.scope_label || '') + '</span>',
			'<span><b>Types:</b> ' + esc((job.post_type_labels || []).join(', ') || 'Selected content') + '</span>'
		];
		if (job.scheduled_at_human) {
			meta.push('<span><b>Scheduled:</b> ' + esc(job.scheduled_at_human) + '</span>');
		}
		if (job.finished_at_human) {
			meta.push('<span><b>Finished:</b> ' + esc(job.finished_at_human) + '</span>');
		}

		$box.prop('hidden', false).html(
			'<div class="sc-wordai-seo-job-card is-' + esc(job.status || 'queued') + '">' +
				'<div class="sc-wordai-seo-job-main">' +
					'<span class="sc-wordai-seo-job-status">' + esc(job.status_label || 'Queued') + '</span>' +
					'<strong>Scheduled bulk SEO job</strong>' +
					'<div class="sc-wordai-seo-job-meta">' + meta.join('') + '</div>' +
					'<div class="sc-wordai-seo-job-progress"><span style="width:' + esc(job.progress || 0) + '%"></span></div>' +
					'<small>' + esc((job.processed || 0) + ' of ' + (job.total || 0) + ' processed' + (job.fixed ? ', ' + job.fixed + ' fixed' : '') + (job.failed ? ', ' + job.failed + ' failed' : '')) + '</small>' +
				'</div>' +
				(isActive ? '<button type="button" class="button sc-wordai-seo-job-cancel"><i class="fa-solid fa-ban" aria-hidden="true"></i><span>Cancel</span></button>' : '') +
			'</div>'
		);
	}

	function refreshJobStatus() {
		$.ajax({
			type: 'POST',
			url: scwordai_seo_scan.adminajax_url,
			data: {
				action: 'sc_wordai_seo_scan_job_status',
				security: scwordai_seo_scan.nonce
			}
		}).done(function (response) {
			if (response && response.success) {
				renderJobSummary(response.data.job);
				updateUsage(response.data.usage);
			}
		});
	}

	function startJobPolling() {
		if (state.jobTimer) {
			clearInterval(state.jobTimer);
		}
		state.jobTimer = setInterval(function () {
			if (state.job && (state.job.status === 'queued' || state.job.status === 'running')) {
				refreshJobStatus();
			}
		}, 30000);
	}

	function openScheduleModal() {
		setDefaultScheduleTime();
		var buttons = [];

		if (scwordai_seo_scan.is_basic_tier) {
			buttons.push({
				text: 'Close',
				click: function () {
					$(this).dialog('close');
				}
			});
		} else {
			buttons.push({
				text: 'Schedule Job',
				class: 'button button-primary',
				click: function () {
					var $dialog = $(this);
					var postTypes = collectSchedulePostTypes();
					if (!postTypes.length) {
						setFeedback('Select at least one content type to schedule.', 'error');
						return;
					}

					$.ajax({
						type: 'POST',
						url: scwordai_seo_scan.adminajax_url,
						data: {
							action: 'sc_wordai_seo_scan_schedule_job',
							security: scwordai_seo_scan.nonce,
							task: $('#sc-wordai-seo-schedule-task').val(),
							scope: $('#sc-wordai-seo-schedule-scope').val(),
							scheduled_at: $('#sc-wordai-seo-schedule-time').val(),
							post_types: postTypes
						}
					}).done(function (response) {
						if (!response || !response.success) {
							setFeedback((response && response.data && response.data.message) || 'Unable to schedule bulk SEO job.', 'error');
							renderJobSummary(response && response.data ? response.data.job : null);
							return;
						}
						renderJobSummary(response.data.job);
						setFeedback(response.data.message || 'Bulk SEO job scheduled.', 'success');
						$dialog.dialog('close');
					}).fail(function () {
						setFeedback('Unable to schedule bulk SEO job.', 'error');
					});
				}
			});
			buttons.push({
				text: 'Cancel',
				click: function () {
					$(this).dialog('close');
				}
			});
		}

		$('#sc-wordai-seo-schedule-modal').dialog({
			modal: true,
			width: Math.min(620, Math.max(320, $(window).width() - 40)),
			resizable: false,
			buttons: buttons
		});
	}

	var searchTimer = null;

	$(function () {
		applyInitialFilters();
		loadList(1);
		renderJobSummary(state.job);
		startJobPolling();

		$('body').on('click', '.sc-wordai-seo-owner-save', function () {
			saveSeoOwner($(this));
		});

		$('body').on('click', '.sc-wordai-seo-tab', function () {
			$('.sc-wordai-seo-tab').removeClass('is-active');
			$(this).addClass('is-active');
			state.postType = $(this).data('post-type') || 'post';
			state.page = 1;
			var label = (scwordai_seo_scan.post_types[state.postType] || {}).label || 'Posts';
			$('[data-wordai-seo-current-label]').text(label);
			loadList(1);
		});

		$('#sc-wordai-seo-search').on('input', function () {
			clearTimeout(searchTimer);
			searchTimer = setTimeout(function () {
				loadList(1);
			}, 300);
		});

		$('#sc-wordai-seo-filter, #sc-wordai-seo-post-status, #sc-wordai-seo-per-page').on('change', function () {
			loadList(1);
		});

		$('.sc-wordai-seo-refresh').on('click', function () {
			loadList(state.page);
		});

		$('[data-wordai-page-prev]').on('click', function () {
			if (state.page > 1) {
				loadList(state.page - 1);
			}
		});

		$('[data-wordai-page-next]').on('click', function () {
			if (state.page < state.totalPages) {
				loadList(state.page + 1);
			}
		});

		$('body').on('click', '.sc-wordai-seo-scan-row', function () {
			runItemAction('sc_wordai_seo_scan_item', $(this).data('post-id'), $(this));
		});

		$('body').on('click', '.sc-wordai-seo-autofix-row', function () {
			requestAutofixPreview($(this).data('post-id'), $(this));
		});

		$('body').on('click', '.sc-wordai-seo-undo-row', function () {
			if (window.confirm('Restore the SEO values from before the last WordAI change?')) {
				runItemAction('sc_wordai_seo_scan_undo', $(this).data('post-id'), $(this));
			}
		});

		$('.sc-wordai-seo-schedule-open').on('click', openScheduleModal);

		$('body').on('click', '.sc-wordai-seo-job-cancel', function () {
			$.ajax({
				type: 'POST',
				url: scwordai_seo_scan.adminajax_url,
				data: {
					action: 'sc_wordai_seo_scan_cancel_job',
					security: scwordai_seo_scan.nonce
				}
			}).done(function (response) {
				if (!response || !response.success) {
					setFeedback((response && response.data && response.data.message) || 'Unable to cancel scheduled job.', 'error');
					return;
				}
				renderJobSummary(response.data.job);
				setFeedback(response.data.message || 'Scheduled job cancelled.', 'success');
			}).fail(function () {
				setFeedback('Unable to cancel scheduled job.', 'error');
			});
		});
	});
})(jQuery);
