(function ($) {
	'use strict';

	var LOC_NOTE = 'Not case-sensitive. Separate multiple values with a comma.';

	// On our method's settings page, keep the screen focused on configuring the
	// method: WooCommerce injects extension suggestions ("Recommended shipping
	// solutions") below the form; this empties them before they render.
	if (esr_vars.is_own_method_page && window.wp && wp.hooks) {
		wp.hooks.addFilter('woocommerce_admin_embedded_layout_components', 'esraw/hide-extension-suggestions', function () {
			return [];
		});
	}

	// Prevents double-init when handlers rebuild parts of a row.
	function apply_selectwoo($elements, config) {
		$elements.each(function () {
			var $el = $(this);
			if (!$el.hasClass('select2-hidden-accessible')) {
				$el.select2(config);
				// Select2 mirrors the selected text into a title attribute, which shows
				// a redundant native tooltip on hover. Strip it on render and on change.
				var clearTitle = function () {
					$el.next('.select2-container').find('.select2-selection__rendered').removeAttr('title');
				};
				clearTitle();
				$el.on('change.esrawNoTitle', clearTitle);
			}
		});
	}

	function init_selects() {
		apply_selectwoo($('#esr-woo-table select:not([multiple])'), { minimumResultsForSearch: 10, width: '100%' });
		apply_selectwoo($('#esr-woo-table select[multiple]').not('.esraw-product-select'), { minimumResultsForSearch: 2, width: '100%' });
	}

	// Uses WC's built-in AJAX endpoint so we don't need a custom handler or a full product list upfront.
	function init_product_selects() {
		apply_selectwoo($('.esraw-product-select'), {
			ajax: {
				url: esr_vars.ajax_url,
				dataType: 'json',
				delay: 250,
				data: function (params) {
					return {
						term: params.term || '',
						action: 'woocommerce_json_search_products_and_variations',
						security: esr_vars.search_products_nonce
					};
				},
				processResults: function (data) {
					return {
						results: $.map(data, function (text, id) {
							return { id: id, text: text };
						})
					};
				},
				cache: true
			},
			language: {
				noResults: function () { return 'No products found'; }
			},
			minimumInputLength: 2,
			placeholder: esr_vars.search_products_placeholder || 'Search products…',
			width: 'resolve'
		});
	}

	// Shows warnings without blocking save — WC's modal AJAX submit can't be reliably prevented.
	function validateRulesTable() {
		var $table = $('#esr-woo-table');
		if (!$table.length) { return; }

		$('#esraw-validation-banner').remove();
		$table.find('tr').removeClass('esraw-row-error');
		$table.find('input[name*="[cost]"]').removeClass('esraw-field-error');

		var errors = [];
		var validTokens = ['[qty]', '[items]', '[weight]', '[subtotal]', '[subtotal_ex]', '[volume]'];
		var $rows = $table.find('tbody tr:not(.esr-empty-state)');

		$rows.each(function (i) {
			var $row = $(this);
			var rowNum = i + 1;
			var $cond = $row.find('select[name*="[condition]"]');
			var $cost = $row.find('input[name*="[cost]"]');

			if (!$cond.val()) {
				$row.addClass('esraw-row-error');
				errors.push('Row ' + rowNum + ': no condition selected.');
			}

			if ($cost.length && $cost.val().trim() === '') {
				$cost.addClass('esraw-field-error');
				errors.push('Row ' + rowNum + ': cost field is empty.');
			} else if ($cost.length) {
				var tokenMatches = $cost.val().match(/\[[^\]]+\]/g);
				if (tokenMatches) {
					tokenMatches.forEach(function (token) {
						if (validTokens.indexOf(token.toLowerCase()) === -1) {
							$cost.addClass('esraw-field-error');
							errors.push('Row ' + rowNum + ': unrecognised token "' + token + '".');
						}
					});
				}
			}
		});

		var freeRequires = $('select[name="woocommerce_esraw_method_free_requires"]').val();
		if ($rows.length === 0 && (!freeRequires || freeRequires === '')) {
			errors.push('No rules configured and no free shipping trigger set — customers may see this method with a cost of $0.00.');
		}

		if (errors.length) {
			var html = '<div id="esraw-validation-banner" class="notice notice-warning esraw-my-3">' +
				'<p><strong>Please review before saving:</strong></p><ul class="esraw-list-disc esraw-pl-5">';
			errors.forEach(function (msg) { html += '<li>' + msg + '</li>'; });
			html += '</ul></div>';
			$table.before(html);
		}
	}

	$(function () {
		// Same intent as the filter above: the "Explore solutions" marketplace
		// link is printed straight into the page, so it is removed once loaded.
		if (esr_vars.is_own_method_page) {
			$('.wc-settings-marketplace-link').remove();
		}

		$('#esraw_shipping_export_field').select2({ minimumResultsForSearch: 2 });
		$('#esraw_shipping_zones_import').select2({ minimumResultsForSearch: 2 });

		// Use the row's data-key, not the loop index: saved keys can have gaps.
		$("select[id*='easy_rate_condition_']").each(function () {
			$(this).on('change', function () {
				let key = $(this).closest('tr').data('key');
				let condition_val = $(this).val();
				let add_for_calcul = create_operators(key, condition_val);
				$('#easy_rate_operator_content_' + key).html(add_for_calcul);
				init_selects();
				init_product_selects();
			});
		});

		$(".esr_remove_all_tr").on('change', function () {
			if (this.checked) {
				$(".esr_remove_tr").each(function () {
					$(this).prop('checked', true);
				});
			} else {
				$(".esr_remove_tr").each(function () {
					$(this).prop('checked', false);
				});
			}
		});

		$("#esr-remove-rows").on('click', function (e) {
			e.preventDefault();
			var count = $(".esr_remove_tr:checked").length;
			if (count === 0) { return; }
			if (!confirm('Delete ' + count + ' selected rule(s)? This cannot be undone.')) { return; }
			$(".esr_remove_tr").each(function () {
				if (this.checked) {
					$(this).closest('tr').remove();
					$(".esr_remove_all_tr").prop('checked', false);
				}
			});
			restore_empty_state();
		});

		// Delegated so it also covers rows added after page load.
		// Inline delete is free for a few uses, then asks for a donation.
		$("#esr-woo-table").on('click', '.esr-remove-row', function (e) {
			e.preventDefault();
			var gate = esr_vars.inline_delete || { remaining: 0 };
			if (gate.remaining <= 0) {
				showDonationNotice();
				return;
			}
			if (!confirm('Delete this rule? This cannot be undone.')) { return; }
			$(this).closest('tr').remove();
			// Predict the remaining count; the server confirms it on save.
			gate.remaining = Math.max(0, gate.remaining - 1);
			restore_empty_state();
		});

		function showDonationNotice() {
			if ($('#esraw-donate-notice').length) { return; }
			var gate = esr_vars.inline_delete || {};
			var html = '<div id="esraw-donate-notice" class="notice notice-info esraw-my-3">' +
				'<p>' + (gate.message || 'Please donate to keep using this feature.') + '</p>' +
				'<p><a href="' + (gate.donate_url || '#') + '" target="_blank" rel="noopener noreferrer" class="button button-primary">' + (gate.donate || 'Donate') + '</a></p>' +
				'</div>';
			$('#esr-woo-table').before(html);
		}

		// Brings the "No rules yet" placeholder back once every row is gone,
		// whatever the deletion path.
		function restore_empty_state() {
			var $tbody = $('#esr-woo-table tbody');
			if ($tbody.find('tr').length) { return; }
			var columns = $('#esr-woo-table thead th').length;
			$tbody.append('<tr class="esr-empty-state"><td colspan="' + columns + '" class="esraw-py-7 esraw-px-3 esraw-text-center esraw-text-gray-500">No rules yet. Click "Insert row" to add your first rule.</td></tr>');
		}

		// Duplicated rows break the "last row holds the highest key" assumption,
		// so the next free key is always computed from all rows.
		function next_row_key() {
			var max = -1;
			$('#esr-woo-table tbody tr:not(.esr-empty-state)').each(function () {
				var key = parseInt($(this).attr('data-key'), 10);
				if (!isNaN(key) && key > max) { max = key; }
			});
			return max + 1;
		}

		function bind_condition_change(key) {
			$('#easy_rate_condition_' + key).on('change', function () {
				$('#easy_rate_operator_content_' + key).html(create_operators(key, $(this).val()));
				init_selects();
				init_product_selects();
			});
		}

		$("#esr-insert-new-row").on('click', function (e) {
			e.preventDefault();

			$("#esr-woo-table tbody .esr-empty-state").remove();

			let new_key = next_row_key();
			$("#esr-woo-table tbody").append(create_content(new_key));
			init_selects();
			bind_condition_change(new_key);
		});

		// Inserts a copy right below the source row. The action is deliberately
		// reset to "Continue to next rule" so the merchant reviews the copy.
		$("#esr-woo-table").on('click', '.esr-duplicate-row', function (e) {
			e.preventDefault();
			var $row = $(this).closest('tr');
			var newKey = next_row_key();
			var $newRow = $(create_content(newKey));
			$row.after($newRow);

			var condition = $row.find('select[name*="[condition]"]').val();
			$newRow.find('select[name*="[condition]"]').val(condition);
			$('#easy_rate_operator_content_' + newKey).html(create_operators(newKey, condition));

			$newRow.find('select[name*="[operator]"]').val($row.find('select[name*="[operator]"]').val());
			$newRow.find('input[name*="[operand1]"]').val($row.find('input[name*="[operand1]"]').val());
			$newRow.find('input[name*="[operand2]"]').val($row.find('input[name*="[operand2]"]').val());
			$newRow.find('input[name*="[cost]"]').val($row.find('input[name*="[cost]"]').val());
			$newRow.find('select[name*="[action]"]').val('none');

			var $sourceChoicesInput = $row.find('input[name*="[choices]"]');
			if ($sourceChoicesInput.length) {
				$newRow.find('input[name*="[choices]"]').val($sourceChoicesInput.val());
			}
			var $sourceChoicesSelect = $row.find('select[name*="[choices]"]');
			if ($sourceChoicesSelect.length) {
				var $newChoicesSelect = $newRow.find('select[name*="[choices]"]');
				if ($newChoicesSelect.hasClass('esraw-product-select')) {
					// Product options are AJAX-loaded, so the copy needs the
					// selected ones recreated with their labels.
					$sourceChoicesSelect.find('option:selected').each(function () {
						$newChoicesSelect.append(new Option($(this).text(), this.value, true, true));
					});
				} else {
					$newChoicesSelect.val($sourceChoicesSelect.val());
				}
			}

			bind_condition_change(newKey);
			init_selects();
			init_product_selects();
		});

		$("#esr-woo-table").on('click', '.esr-delete-row', function (e) {
			e.preventDefault();
			if (!confirm('Delete this rule? This cannot be undone.')) { return; }
			$(this).closest('tr').remove();
			$(".esr_remove_all_tr").prop('checked', false);
			restore_empty_state();
		});

		$('#esraw-load-template').on('click', function (e) {
			e.preventDefault();
			var templateKey = $('#esraw-template-select').val();
			if (!templateKey) { return; }
			var template = (esr_vars.esraw_rule_templates || {})[templateKey];
			if (!template) { return; }

			var $tbody = $('#esr-woo-table tbody');
			var existingCount = $tbody.find('tr:not(.esr-empty-state)').length;
			if (existingCount > 0 && !confirm('Loading this template will replace your ' + existingCount + ' existing rule(s). Continue?')) {
				return;
			}

			$tbody.empty();
			template.rules.forEach(function (rule, key) {
				$tbody.append(create_content(key));
				var $row = $tbody.find('tr[data-key="' + key + '"]');
				$row.find('select[name*="[condition]"]').val(rule.condition);
				$('#easy_rate_operator_content_' + key).html(create_operators(key, rule.condition));
				$row.find('select[name*="[operator]"]').val(rule.operator || 'is');
				if (rule.operand1 !== undefined) { $row.find('input[name*="[operand1]"]').val(rule.operand1); }
				if (rule.operand2 !== undefined) { $row.find('input[name*="[operand2]"]').val(rule.operand2); }
				if (rule.choices !== undefined) { $row.find('input[name*="[choices]"]').val(rule.choices); }
				$row.find('input[name*="[cost]"]').val(rule.cost);
				$row.find('select[name*="[action]"]').val(rule.action);
				bind_condition_change(key);
			});
			init_selects();
			init_product_selects();
			$('#esraw-template-select').val('');
		});

		// WC's modal submit fires a button click, not a form submit event.
		$(document).on('click', '.wc-backbone-modal-action:not(.button-secondary)', function () {
			if ($('#esr-woo-table').length) { validateRulesTable(); }
		});
		$('#esr-woo-table').closest('form').on('submit', function () {
			if ($('#esr-woo-table').length) { validateRulesTable(); }
		});

		init_selects();
		init_product_selects();

		// Collapsing must come after the selects are enhanced: selectWoo measures
		// its controls at initialization, and hidden elements measure wrong.
		if (esr_vars.is_own_method_page) {
			init_section_toggles();
		}

		// The settings page is long enough for options to be missed: each section
		// collapses behind a checkbox next to its title, so the merchant sees all
		// sections at a glance and opens only what they need. Nothing is moved in
		// the DOM — elements are only shown or hidden — so the WooCommerce table
		// styling is left intact.
		function init_section_toggles() {
			var $rulesTr = $('#esr-woo-table').closest('tr');
			var sections = [];

			$('#mainform h3.wc-settings-sub-title').each(function () {
				var $title = $(this);
				var $parts = $();
				$title.nextUntil('h3.wc-settings-sub-title, p.submit').each(function () {
					var $chunk = $(this);
					if ($rulesTr.length && $chunk.has($rulesTr[0]).length) {
						// This block also hosts the rules row, which collapses
						// under its own toggle: hide only the other rows.
						$parts = $parts.add($chunk.children('tbody').children('tr').not($rulesTr));
					} else {
						$parts = $parts.add($chunk);
					}
				});
				sections.push({ $title: $title, $parts: $parts });
			});

			if ($rulesTr.length) {
				var $rulesTitle = $rulesTr.find('h2').first();
				sections.push({ $title: $rulesTitle, $parts: $rulesTitle.nextAll() });
			}

			var toggles = [];
			sections.forEach(function (section, index) {
				if (!section.$parts.length || !section.$title.length) { return; }
				// The first section (General Settings) holds the essentials and
				// starts open; the rest starts collapsed.
				var open = 0 === index;
				var $box = $('<input type="checkbox" class="esraw-section-toggle esraw-h-[18px] esraw-w-[18px] esraw-flex-none esraw-cursor-pointer esraw-m-0" aria-label="Show this section">').prop('checked', open);
				section.$title.addClass('esraw-section-title esraw-flex esraw-items-center esraw-gap-3 esraw-cursor-pointer esraw-select-none esraw-mt-7 esraw-mb-3 hover:esraw-text-[#2271b1]').prepend($box);
				// The plugin's Tailwind utilities are !important, so jQuery's
				// inline display toggling cannot beat them: hide with the
				// hidden utility, which is generated after the display ones.
				section.$parts.toggleClass('esraw-hidden', !open);
				toggles.push({ $box: $box, $parts: section.$parts });

				$box.on('change', function () {
					section.$parts.toggleClass('esraw-hidden', !this.checked);
				});
				section.$title.on('click', function (e) {
					if (e.target !== $box[0]) {
						$box.prop('checked', !$box.prop('checked')).trigger('change');
					}
				});
			});

			// A required field hidden in a closed section would silently block
			// saving: open any section holding an invalid field on save.
			$(document).on('click', '.woocommerce-save-button', function () {
				toggles.forEach(function (toggle) {
					if (toggle.$box.prop('checked')) { return; }
					var hasInvalid = toggle.$parts.toArray().some(function (el) {
						return (el.matches && el.matches(':invalid')) || el.querySelector(':invalid');
					});
					if (hasInvalid) {
						toggle.$box.prop('checked', true).trigger('change');
					}
				});
			});
		}

		function create_content(p) {
			let cond_choices = esr_vars.esraw_condition_choices;
			let cond_actions = esr_vars.esraw_condition_actions;

			let cond_choices_options = generate_select_option_for_group(cond_choices);
			let cond_actions_options = generate_select_option(cond_actions);

			var deleteCell = (esr_vars.inline_delete && esr_vars.inline_delete.enabled)
				? '<td><button type="button" class="esr-remove-row" aria-label="Delete this rule"><span class="dashicons dashicons-trash"></span></button></td>'
				: '';
			var duplicateIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>';
			var deleteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>';
			var actionsCell = '<td class="esr-row-actions esraw-whitespace-nowrap esraw-text-center">' +
				'<button type="button" class="esr-duplicate-row esraw-inline-flex esraw-items-center esraw-justify-center esraw-rounded esraw-border-0 esraw-bg-transparent esraw-p-1.5 esraw-cursor-pointer esraw-text-gray-500 hover:esraw-text-brand hover:esraw-bg-gray-100" aria-label="Duplicate this rule" title="Duplicate">' + duplicateIcon + '</button>' +
				'<button type="button" class="esr-delete-row esraw-inline-flex esraw-items-center esraw-justify-center esraw-rounded esraw-border-0 esraw-bg-transparent esraw-p-1.5 esraw-cursor-pointer esraw-text-gray-500 hover:esraw-text-red-600 hover:esraw-bg-red-50" aria-label="Delete this rule" title="Delete">' + deleteIcon + '</button></td>';
			let content = '<tr data-key="' + p + '"><td><input type="checkbox" class="esr_remove_tr"></td>' +
				'<td><div class="easy_rate_condition_content" id="easy_rate_condition_content_' + p + '"><select id="easy_rate_condition_' + p +
				'" name="easy_rate[' + p + '][condition]" required>' + cond_choices_options + '</select>' +
				'<span class="easy_rate_operator_content" id="easy_rate_operator_content_' + p + '"></span></div></td>' +
				'<td><input type="text" class="esraw-w-full" placeholder="12.50 or 5+[qty]*1.50" name="easy_rate[' + p + '][cost]" required/></td>' +
				'<td><select id="easy_rate_action_' + p + '" name="easy_rate[' + p + '][action]">' + cond_actions_options + '</select></td>' +
				deleteCell + actionsCell + '</tr>';
			return content;
		}

		function generate_select_option_for_group(select_choices) {
			let select_options = '<option></option>';

			for (const key in select_choices) {
				if (Object.hasOwnProperty.call(select_choices, key)) {
					const choices = select_choices[key];
					select_options += '<optgroup label="' + key + '">';
					for (const choices_key in choices) {
						if (Object.hasOwnProperty.call(choices, choices_key)) {
							const choice = choices[choices_key];
							select_options += '<option value="' + choice + '">' + choices_key + '</option>';
						}
					}
					select_options += '</optgroup>';
				}
			}
			return select_options;
		}

		function generate_select_option(select_choices) {
			let select_options = '';
			for (const key in select_choices) {
				if (Object.hasOwnProperty.call(select_choices, key)) {
					const choices = select_choices[key];
					select_options += '<option value="' + key + '">' + choices + '</option>';
				}
			}
			return select_options;
		}

		function create_operators(p, val) {
			let content = '';
			let unit = '';

			if (val == 'subtotal' || 'subtotal_ex' == val) {
				unit = esr_vars.esraw_currency_symbol;
			} else if ('quantity' == val || 'cart_line_item' == val) {
				unit = 'qty';
			} else if ('weight' == val || 'dim_weight' == val) {
				unit = 'kg';
			} else if ('volume' == val) {
				unit = 'cm<sup>3</sup>';
			} else if ('max_dim' == val || 'total_dim' == val) {
				unit = 'cm';
			}

			let operators = esr_vars.esraw_operator;
			let select_options = '';

			for (const key in operators) {
				if (Object.hasOwnProperty.call(operators, key)) {
					const choices = operators[key];
					select_options += '<option value="' + key + '">' + choices + '</option>';
				}
			}

			if ('subtotal' == val || 'weight' == val || 'dim_weight' == val || 'volume' == val || 'max_dim' == val || 'total_dim' == val || 'subtotal_ex' == val || 'quantity' == val || 'cart_line_item' == val) {
				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<span class="esraw-text-[11px] esraw-mr-[3px]">From</span>' +
					'<input type="number" step="0.01" placeholder="min" name="easy_rate[' + p + '][operand1]"/>' +
					'<span class="esraw-text-[11px] esraw-my-0 esraw-mx-[3px]">To</span>' +
					'<input type="number" step="0.01" placeholder="no limit" name="easy_rate[' + p + '][operand2]"/>' +
					'<div class="easy_rate_unit">' + unit + '</div>';
			} else if ('contains_shipping_class' == val) {
				let ship_classes = esr_vars.esraw_ship_classes_array;
				let ship_options = '';

				for (const key_ship in ship_classes) {
					if (Object.hasOwnProperty.call(ship_classes, key_ship)) {
						const choices = ship_classes[key_ship];
						ship_options += '<option value="' + key_ship + '">' + choices + '</option>';
					}
				}

				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<select multiple id="esraw_ship_class" name="easy_rate[' + p + '][choices][]" required>' + ship_options + '</select>';
			} else if ('contains_product' == val) {
				// Options are loaded on demand via AJAX — no static list.
				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<select multiple class="esraw-product-select" name="easy_rate[' + p + '][choices][]" required></select>';
			} else if ('user_roles' == val) {
				let user_roles = esr_vars.esraw_user_roles;
				let options = '';

				for (const key_ship in user_roles) {
					if (Object.hasOwnProperty.call(user_roles, key_ship)) {
						const choices = user_roles[key_ship];
						options += '<option value="' + key_ship + '">' + choices + '</option>';
					}
				}

				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<select multiple id="esraw_user_roles" name="easy_rate[' + p + '][choices][]" required>' + options + '</select>';
			} else if ('zipcode' == val) {
				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<input type="text" placeholder="postcode1,postcode2,etc." name="easy_rate[' + p + '][choices]"/>' +
					'<span class="description esraw-block esraw-text-[11px] esraw-mt-0.5">' + LOC_NOTE + '</span>';
			} else if ('city' == val) {
				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<input type="text" placeholder="city1,city2,etc." name="easy_rate[' + p + '][choices]"/>' +
					'<span class="description esraw-block esraw-text-[11px] esraw-mt-0.5">' + LOC_NOTE + '</span>';
			} else if ('state' == val) {
				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<input type="text" placeholder="state1,state2,etc." name="easy_rate[' + p + '][choices]"/>' +
					'<span class="description esraw-block esraw-text-[11px] esraw-mt-0.5">' + LOC_NOTE + '</span>';
			} else if ('country' == val) {
				content = '<select id="easy_rate_operator_' + p + '" name="easy_rate[' + p + '][operator]" required>' + select_options + '</select>' +
					'<input type="text" placeholder="country1,country2,etc." name="easy_rate[' + p + '][choices]"/>' +
					'<span class="description esraw-block esraw-text-[11px] esraw-mt-0.5">' + LOC_NOTE + '</span>';
			}

			return content;
		}
	});

})(jQuery);
