/*! Copyright (c) Safe As Milk. All rights reserved. */class SearchForm extends HTMLElement{constructor(){super(),this.form=this.querySelector("form")}connectedCallback(){this.hasAttribute("add-recent-search-on-load")&&this.addFormStateToRecentSearches()}static addRecentSearch(query,uri){if(!query||!uri)return;const getUniqueListBy=(arr,key)=>[...new Map(arr.map(item=>[item[key],item])).values()];let recentSearches=[{query,uri}];const recentSearchesStoredString=localStorage.getItem("recentSearches");if(recentSearchesStoredString){const combinedSearches=[...JSON.parse(recentSearchesStoredString),...recentSearches];recentSearches=getUniqueListBy(combinedSearches.reverse(),"query").reverse(),recentSearches.length>5&&(recentSearches=recentSearches.slice(-5))}localStorage.setItem("recentSearches",JSON.stringify(recentSearches)),document.querySelectorAll("recent-searches").forEach(el=>el.update())}addFormStateToRecentSearches(){if(!this.form)return;const form=new FormData(this.form),search=new URLSearchParams(form),formAction=new URL(`${window.location.origin}${this.form.getAttribute("action")}`),formActionOrigin=window.location.origin,formActionPath=formAction.pathname,formActionSearch=formAction.searchParams,combinedSearch=new URLSearchParams({...Object.fromEntries(formActionSearch),...Object.fromEntries(search)});SearchForm.addRecentSearch(form.get("q"),`${formActionOrigin}${formActionPath}?${combinedSearch.toString()}`)}}customElements.define("search-form",SearchForm); //# sourceMappingURL=/cdn/shop/t/100/assets/search-form.js.map?v=41728883722473605271751575325