{% set type = type|default("text") %}
{% set label = label|default("") %}
{% set value = value|default("") %}
{% set instructions = instructions|default("") %}
{% set id = id|default("text" ~ random(5000)) %}
{% set name = name|default(id) %}
{% set hideLabel = hideLabel|default %}
{% set attributes = attributes ?? {} %}
{% set placeholder = placeholder|default("") %}
{% set error = error|default("") %}
{% set isDisabled = isDisabled|default(false) %}
{% set isRequired = isRequired|default(false) %}
{% set isLocation = isLocation|default("") %}
{% set classes = classes ?? "" %}

{% import "macros" as macros %}

<div class="form-text {{ classes }} {{ hideLabel ? " form-text--hide-label" }}">
	<label class="form-text__label" for="{{ id }}">
		{{ label }}
	</label>

	<div class="relative form-text__input-container">

		{% block input %}
			<div class="relative">
				<input id="{{ id }}" class="!pr-12 form-text__input placeholder:text-blue-50 xxxl:!pr-48 searchText" type="{{ type }}" name="{{ name }}" value="{{ value }}" placeholder="{{ placeholder }}" {{ macros.addAttributes(attributes) }} {{ isDisabled ? "disabled" }} {{ isRequired ? "required" }}>

				{% if isLocation == "true" %}
					<!-- Cross -->
					<button type='button' id="searchTextClear" class="absolute -translate-y-1/2 shrink-0 top-1/2 right-12 xxxl:right-48">
						<svg class="w-6 h-6 text-white" viewbox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
							<path d="M10 22L22 10" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
							<path d="M10 10L22 22" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
						</svg>
					</button>
					<!-- Icon -->
					<button class="absolute inline-flex items-center gap-4 p-1 text-white -translate-y-1/2 rounded-full top-1/2 right-4 find-me hocus:text-grey-100 hocus:bg-blue xxxl:px-2" data-use-my-location type='button'>
						<svg class="h-[18px] w-[18px]" viewbox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
							<g clip-path="url(#clip0_1686_2370)">
								<path d="M24.9597 14.9643C24.9592 15.4565 24.9263 15.9481 24.8612 16.436C24.8612 16.3544 24.8815 16.2728 24.8951 16.1879C24.7905 16.9297 24.6129 17.6594 24.3649 18.3664C24.3038 18.5329 24.2392 18.7063 24.1746 18.8626C24.11 19.0189 24.2664 18.6417 24.1984 18.8014C24.1984 18.8422 24.1644 18.883 24.144 18.9238C24.1236 18.9646 24.0591 19.1107 24.0149 19.2025C23.8579 19.5312 23.6832 19.8511 23.4915 20.1609C23.3026 20.4718 23.0972 20.7724 22.8763 21.0615C22.771 21.1975 23.0225 20.8746 22.9171 21.0106L22.8355 21.1125L22.669 21.313C22.5467 21.4592 22.4209 21.5985 22.2918 21.7345C22.0456 22.0005 21.7846 22.2524 21.5101 22.489C21.3809 22.6045 21.2484 22.7133 21.1124 22.8288C21.058 22.8696 20.9221 22.975 21.16 22.7915L21.058 22.8696L20.8099 23.0498C20.4655 23.2971 20.1069 23.524 19.736 23.7295C19.5558 23.8281 19.3723 23.9198 19.1888 24.0082L18.9101 24.1339C18.6892 24.2325 19.0766 24.066 18.9101 24.1339L18.747 24.2019C17.9399 24.5186 17.0978 24.7377 16.2387 24.8544L16.4868 24.8205C15.508 24.953 14.5157 24.953 13.5368 24.8205L13.7849 24.8544C13.0436 24.753 12.3146 24.5753 11.6098 24.3243C11.4398 24.2665 11.2699 24.2019 11.1136 24.1339C10.9572 24.066 11.3345 24.2291 11.1713 24.1611L11.0694 24.0762L10.7907 23.947C10.4508 23.7873 10.1415 23.6071 9.82886 23.4236C9.51619 23.2401 9.2205 23.026 8.93162 22.8085C8.79227 22.7031 9.11854 22.9512 8.9826 22.8458L8.88064 22.7643L8.67672 22.5977C8.53397 22.4788 8.39463 22.353 8.25528 22.2239C7.99019 21.9758 7.74208 21.7141 7.50418 21.4422C7.38862 21.313 7.27647 21.1771 7.16431 21.0411C7.12353 20.9902 7.01817 20.8508 7.20509 21.0921C7.17715 21.0585 7.15105 21.0233 7.12692 20.9868C7.06575 20.9086 7.00457 20.8236 6.9468 20.7421C6.69953 20.3976 6.47257 20.039 6.26706 19.6681C6.1719 19.488 6.07674 19.3044 5.99177 19.1209C5.94759 19.0257 5.90341 18.934 5.86262 18.8388C5.76746 18.6213 5.93059 19.0053 5.86262 18.8592L5.79805 18.6961C5.47969 17.8881 5.25947 17.0449 5.14211 16.1845C5.14211 16.2694 5.1659 16.351 5.17609 16.4326C5.04694 15.4546 5.04694 14.4639 5.17609 13.4859C5.17609 13.5675 5.1557 13.6491 5.14211 13.734C5.24673 12.9922 5.42432 12.2624 5.6723 11.5555C5.73347 11.3889 5.79805 11.2156 5.86262 11.0593C5.9272 10.9029 5.77086 11.2802 5.83883 11.1205C5.85582 11.0797 5.87282 11.0389 5.89321 10.9981C5.93399 10.9063 5.97818 10.8112 6.02236 10.7194C6.17932 10.3907 6.35404 10.0707 6.54575 9.76099C6.73469 9.45008 6.94004 9.14944 7.16091 8.86034C7.26627 8.72439 7.01477 9.04727 7.12013 8.91132L7.2017 8.80936L7.36823 8.60884C7.49058 8.4627 7.61633 8.32335 7.74548 8.1874C7.99797 7.91735 8.26578 7.66203 8.54757 7.42271C8.67672 7.30715 8.80926 7.19839 8.94861 7.08284C8.99959 7.04205 9.13554 6.9367 8.89763 7.12022L8.99959 7.04205L9.24769 6.86193C9.59213 6.61461 9.95073 6.38764 10.3217 6.18219C10.5018 6.08363 10.6853 5.99187 10.8689 5.9035L11.1509 5.77775C11.3685 5.67919 10.981 5.84573 11.1306 5.77775L11.2937 5.70978C12.1008 5.39307 12.9428 5.174 13.8019 5.05724L13.5538 5.09122C14.5327 4.95866 15.525 4.95866 16.5038 5.09122L16.2557 5.05724C16.9981 5.15901 17.7281 5.33667 18.4343 5.58743C18.6008 5.6452 18.7741 5.70978 18.9271 5.77775C19.08 5.84573 18.7062 5.68259 18.8693 5.75396L18.9883 5.80494L19.267 5.93409C19.6068 6.09383 19.9161 6.27396 20.2288 6.46088C20.538 6.64948 20.8375 6.85367 21.126 7.07264C21.2654 7.178 20.9391 6.9299 21.075 7.03526L21.1804 7.11683L21.3809 7.28336C21.5237 7.40231 21.663 7.52806 21.8024 7.65721C22.0674 7.90532 22.3156 8.16701 22.5535 8.43891C22.669 8.57145 22.7812 8.704 22.8933 8.83995C22.9341 8.89093 23.0395 9.03027 22.8525 8.78897L22.9341 8.89433L23.1108 9.13903C23.3573 9.48401 23.5843 9.84257 23.7906 10.213C23.888 10.3943 23.9798 10.5778 24.0659 10.7636C24.11 10.8554 24.1542 10.9471 24.195 11.0423C24.2902 11.2598 24.127 10.8757 24.195 11.0219C24.2154 11.0763 24.2392 11.1306 24.2596 11.1884C24.5779 11.9952 24.7982 12.8373 24.9155 13.6966C24.9155 13.6117 24.8917 13.5301 24.8815 13.4485C24.9467 13.9375 24.9797 14.4303 24.9801 14.9236C24.9944 15.1604 25.0986 15.3828 25.2713 15.5454C25.4441 15.708 25.6724 15.7986 25.9096 15.7986C26.1469 15.7986 26.3752 15.708 26.5479 15.5454C26.7207 15.3828 26.8248 15.1604 26.8392 14.9236C26.8328 12.5349 26.101 10.2045 24.7407 8.24094C23.3804 6.27742 21.4558 4.77339 19.2217 3.92804C16.9876 3.08269 14.5494 2.93589 12.23 3.50707C9.91063 4.07826 7.81944 5.34049 6.23338 7.12661C4.64732 8.91274 3.64121 11.1385 3.34828 13.5092C3.05534 15.8798 3.48941 18.2835 4.593 20.402C5.69658 22.5205 7.41762 24.2538 9.52822 25.3724C11.6388 26.4909 14.0394 26.942 16.4121 26.6659C18.0057 26.4834 19.5446 25.975 20.9333 25.1722C22.3219 24.3694 23.5305 23.2895 24.4839 21.9996C26.0041 19.9693 26.8246 17.5007 26.8222 14.9643C26.8299 14.8375 26.8115 14.7105 26.7683 14.5911C26.725 14.4716 26.6578 14.3623 26.5707 14.2698C26.4837 14.1773 26.3786 14.1036 26.262 14.0532C26.1454 14.0029 26.0197 13.9769 25.8926 13.9769C25.7656 13.9769 25.6399 14.0029 25.5233 14.0532C25.4067 14.1036 25.3016 14.1773 25.2146 14.2698C25.1275 14.3623 25.0603 14.4716 25.017 14.5911C24.9738 14.7105 24.9554 14.8375 24.9631 14.9643H24.9597Z" fill="currentColor"/>
								<path d="M0.931313 15.892H7.08969C7.3265 15.8777 7.54892 15.7735 7.71153 15.6008C7.87414 15.428 7.96469 15.1997 7.96469 14.9625C7.96469 14.7252 7.87414 14.4969 7.71153 14.3242C7.54892 14.1514 7.3265 14.0473 7.08969 14.0329H0.931313C0.804518 14.0253 0.677493 14.0436 0.558054 14.0869C0.438614 14.1301 0.329284 14.1973 0.23679 14.2844C0.144296 14.3715 0.0705931 14.4766 0.0202146 14.5932C-0.0301638 14.7098 -0.0561523 14.8355 -0.0561523 14.9625C-0.0561523 15.0895 -0.0301638 15.2152 0.0202146 15.3318C0.0705931 15.4484 0.144296 15.5535 0.23679 15.6406C0.329284 15.7276 0.438614 15.7948 0.558054 15.8381C0.677493 15.8813 0.804518 15.8997 0.931313 15.892Z" fill="currentColor"/>
								<path d="M22.9137 15.892H29.0721C29.3089 15.8777 29.5313 15.7735 29.694 15.6008C29.8566 15.428 29.9471 15.1997 29.9471 14.9625C29.9471 14.7252 29.8566 14.4969 29.694 14.3242C29.5313 14.1514 29.3089 14.0473 29.0721 14.0329H22.9137C22.7869 14.0253 22.6599 14.0436 22.5405 14.0869C22.421 14.1301 22.3117 14.1973 22.2192 14.2844C22.1267 14.3715 22.053 14.4766 22.0026 14.5932C21.9523 14.7098 21.9263 14.8355 21.9263 14.9625C21.9263 15.0895 21.9523 15.2152 22.0026 15.3318C22.053 15.4484 22.1267 15.5535 22.2192 15.6406C22.3117 15.7276 22.421 15.7948 22.5405 15.8381C22.6599 15.8813 22.7869 15.8997 22.9137 15.892Z" fill="currentColor"/>
								<path d="M15.9565 29.0686V22.9103C15.9565 22.6642 15.8587 22.4282 15.6847 22.2542C15.5107 22.0802 15.2747 21.9824 15.0287 21.9824C14.7826 21.9824 14.5466 22.0802 14.3726 22.2542C14.1986 22.4282 14.1008 22.6642 14.1008 22.9103V29.0686C14.1008 29.3147 14.1986 29.5507 14.3726 29.7247C14.5466 29.8987 14.7826 29.9965 15.0287 29.9965C15.2747 29.9965 15.5107 29.8987 15.6847 29.7247C15.8587 29.5507 15.9565 29.3147 15.9565 29.0686Z" fill="currentColor"/>
								<path d="M15.9565 7.08281V0.927835C15.9565 0.681758 15.8587 0.445759 15.6847 0.271757C15.5107 0.0977538 15.2747 0 15.0287 0C14.7826 0 14.5466 0.0977538 14.3726 0.271757C14.1986 0.445759 14.1008 0.681758 14.1008 0.927835V7.08281C14.1008 7.32889 14.1986 7.56489 14.3726 7.73889C14.5466 7.91289 14.7826 8.01065 15.0287 8.01065C15.2747 8.01065 15.5107 7.91289 15.6847 7.73889C15.8587 7.56489 15.9565 7.32889 15.9565 7.08281Z" fill="currentColor"/>
								<path d="M17.6866 14.9643C17.6866 15.1183 17.6764 15.2713 17.656 15.4231L17.69 15.175C17.6659 15.3529 17.6295 15.5289 17.5812 15.7018C17.5574 15.7867 17.5269 15.8717 17.4963 15.9567C17.4657 16.0416 17.4657 16.0382 17.4487 16.079C17.571 15.7799 17.4861 15.9907 17.4487 16.0552C17.3668 16.2257 17.2713 16.3894 17.1632 16.5446C17.1394 16.5786 17.1122 16.6126 17.0884 16.65C17.2652 16.4087 17.1666 16.5446 17.1258 16.5956C17.085 16.6466 16.9899 16.7486 16.9219 16.8199L16.7316 17.0001L16.633 17.0816C16.5107 17.1836 16.8369 16.9321 16.633 17.0816C16.4796 17.1926 16.317 17.2904 16.147 17.3739L16.028 17.4317C15.8717 17.5065 16.2524 17.3399 16.0892 17.4079C15.9941 17.4453 15.8955 17.4793 15.7969 17.5099C15.6143 17.5609 15.428 17.5973 15.2396 17.6186L15.4877 17.5846C15.1829 17.622 14.8748 17.622 14.57 17.5846L14.8181 17.6186C14.6388 17.595 14.4615 17.5575 14.2879 17.5065C14.203 17.4827 14.118 17.4555 14.0364 17.4249L13.9141 17.3773C14.2098 17.4963 14.0024 17.4113 13.9345 17.3773C13.7653 17.2948 13.6028 17.1994 13.4485 17.0918L13.3431 17.0137C13.5844 17.1938 13.4485 17.0952 13.3941 17.051C13.3397 17.0069 13.2445 16.9185 13.1698 16.8471C13.095 16.7758 13.0508 16.7248 12.993 16.6602L12.9081 16.5582C12.8095 16.4393 13.061 16.7656 12.9081 16.5582C12.7991 16.4047 12.7014 16.2434 12.6158 16.0756C12.5954 16.0348 12.5784 15.9975 12.5614 15.9567C12.4866 15.7969 12.6498 16.1776 12.5852 16.0178C12.5462 15.9223 12.5121 15.8247 12.4832 15.7256C12.4272 15.5388 12.3863 15.3479 12.3609 15.1546L12.3949 15.4027C12.3575 15.0968 12.3575 14.7875 12.3949 14.4817C12.3949 14.5666 12.3745 14.6482 12.3609 14.7298C12.3905 14.5573 12.4314 14.387 12.4832 14.22C12.507 14.135 12.5376 14.05 12.5682 13.9685C12.5988 13.8869 12.5988 13.8835 12.6158 13.8427C12.4934 14.1418 12.5784 13.9311 12.6158 13.8665C12.6977 13.696 12.7932 13.5323 12.9013 13.3771C12.9251 13.3431 12.9523 13.3091 12.976 13.2717C12.7993 13.513 12.8979 13.3771 12.9387 13.3261C12.9794 13.2751 13.0746 13.1732 13.1426 13.1018L13.3329 12.9217L13.4315 12.8401C13.5538 12.7381 13.2275 12.9896 13.4315 12.8401C13.5849 12.7291 13.7475 12.6313 13.9175 12.5478L14.016 12.5206C14.1724 12.4493 13.7917 12.6124 13.9549 12.5444C14.0505 12.5065 14.1481 12.4736 14.2471 12.4459C14.4335 12.3882 14.6245 12.3473 14.8181 12.3235L14.57 12.3575C14.8748 12.3201 15.1829 12.3201 15.4877 12.3575L15.2396 12.3235C15.4186 12.3476 15.5957 12.384 15.7697 12.4323C15.8547 12.4561 15.9397 12.4832 16.0212 12.5138L16.1436 12.5614C15.8479 12.4425 16.0552 12.5274 16.1232 12.5614C16.2923 12.6439 16.4548 12.7393 16.6092 12.8469L16.7146 12.9251C16.4733 12.7449 16.6092 12.8435 16.6636 12.8877C16.718 12.9319 16.8131 13.0202 16.8879 13.0916C16.9627 13.163 17.0069 13.214 17.0646 13.2785L17.1496 13.3805C17.2482 13.4994 16.9967 13.1732 17.1496 13.3805C17.2586 13.534 17.3563 13.6953 17.4419 13.8631C17.4623 13.9039 17.4793 13.9413 17.4963 13.982C17.571 14.1418 17.4079 13.7611 17.4725 13.9209C17.5115 14.0165 17.5455 14.114 17.5744 14.2132C17.6253 14.3891 17.6628 14.5686 17.6866 14.7501C17.6866 14.6686 17.6628 14.587 17.6526 14.502C17.6526 14.655 17.6798 14.8079 17.6832 14.9643C17.6832 15.2103 17.781 15.4463 17.955 15.6203C18.129 15.7943 18.365 15.8921 18.611 15.8921C18.8571 15.8921 19.0931 15.7943 19.2671 15.6203C19.4411 15.4463 19.5389 15.2103 19.5389 14.9643C19.5398 14.0811 19.2809 13.2171 18.7946 12.4798C18.2752 11.7165 17.5405 11.125 16.684 10.7805C15.8637 10.459 14.9673 10.3842 14.105 10.5653C13.2428 10.7465 12.4523 11.1757 11.8307 11.8001C11.2188 12.4145 10.7995 13.194 10.6242 14.0432C10.4353 14.9866 10.5446 15.9653 10.9368 16.8437C11.363 17.7802 12.097 18.5426 13.0168 19.0038C13.9365 19.4651 14.9864 19.5975 15.9919 19.379C16.9973 19.1606 17.8977 18.6043 18.543 17.803C19.1883 17.0016 19.5398 16.0034 19.5389 14.9745C19.5389 14.7284 19.4411 14.4924 19.2671 14.3184C19.0931 14.1444 18.8571 14.0466 18.611 14.0466C18.365 14.0466 18.129 14.1444 17.955 14.3184C17.781 14.4924 17.6832 14.7284 17.6832 14.9745L17.6866 14.9643Z" fill="currentColor"/>
							</g>
						</svg>
						<span class="hidden type-base xxxl:block">
							Use my location
						</span>
					</button>
				{% endif %}
			</div>
		{% endblock %}
	</div>

	{% if instructions %}
		<div class="form-text__instructions">
			{{ instructions }}
		</div>
	{% endif %}

	{% if error %}
		<div class="form-text__error">
			{{ error }}
		</div>
	{% endif %}
</div>

{% js %}
let searchText = document.querySelector('.searchText');
	let searchTextClear = document.querySelector('#searchTextClear');
	searchTextClear.addEventListener('click', () => {
		searchText.value = '';
	})

	searchTextClear.style.display = 'none';
	if (searchText.value.length) {
		searchTextClear.style.display = 'inline-block';
	}

	searchText.addEventListener('input', () => {
		if (searchText.value.length) {
			searchTextClear.style.display = 'inline-block';
		} else {
			searchTextClear.style.display = 'none';
		}
	})
{% endjs %}
