1import{B as h,a as m}from"./core-app-provider.BVM6T2bB.min.js";import{B as _}from"./BaseElement.OEEccP4F.min.js";import{d as b,O as T}from"./debounce.D6ZMjh7U.min.js";import{r as f,n as E,e as p,t as g}from"./vendor-lit.BnJBJiFw.min.js";import"./aria-live-region-context.BDX7CysT.min.js";import"./cart-sections.BeO_GuWv.min.js";import"./deferred-media.egc-11wO.min.js";import"./modal-context.Dshgv64S.min.js";import"./quickshop.D1RIwhZN.min.js";import"./vendor.DbyoNmQU.min.js";var y=Object.defineProperty,C=Object.getOwnPropertyDescriptor,l=(e,t,i,s)=>{for(var o=s>1?void 0:s?C(t,i):t,r=e.length-1,a;r>=0;r--)(a=e[r])&&(o=(s?a(t,i,o):a(o))||o);return s&&o&&y(t,i,o),o};let n=class extends _{constructor(){super(),this.isLoading=!1,this.mapboxAccessToken="",this.searchDistanceThresholdKm=100,this._errorTimeoutId=null,this._handleInput=this._handleInput.bind(this),this._handleUseMyLocationClick=this._handleUseMyLocationClick.bind(this),this._handleDebounceInput=b(this._handleInput,T)}connectedCallback(){var e,t;super.connectedCallback(),(e=this.searchInput)==null||e.addEventListener("input",this._handleDebounceInput),(t=this.useMyLocationButton)==null||t.addEventListener("click",this._handleUseMyLocationClick)}disconnectedCallback(){var e,t;super.disconnectedCallback(),(e=this.searchInput)==null||e.removeEventListener("input",this._handleDebounceInput),(t=this.useMyLocationButton)==null||t.removeEventListener("click",this._handleUseMyLocationClick),this._errorTimeoutId!==null&&clearTimeout(this._errorTimeoutId)}updated(e){super.updated(e),e.has("isLoading")&&(this.classList.toggle("loading",this.isLoading),this.$emit(h.LOAD_STATE_CHANGE,this.isLoading))}async _handleInput(e){var i;const t=(i=e.target)==null?void 0:i.value;t?(this.$emit(h.SEARCHED_BY,m.QUERY),this.$emit(h.SEARCH,await this.generateBopisSearchEventData(t))):this.$emit(h.SEARCHED_BY,null)}async _handleUseMyLocationClick(){var a,u,d;let e;const t=c=>{this.errorText&&(this.errorText.textContent=(c==null?void 0:c.message)||window.localeStrings.bopisSearchDefaultError||"An error occurred while fetching location.",this._errorTimeoutId!==null&&clearTimeout(this._errorTimeoutId),this._errorTimeoutId=setTimeout(()=>{this.errorText&&(this.errorText.textContent="")},5e3)),this.$emit(h.SEARCHED_BY,null)};try{e=await this.detectCoords()}catch(c){t(c);return}if(!e){t(new Error("No location available"));return}this.$emit(h.SEARCHED_BY,m.USER_LOCATION);const{latitude:i,longitude:s}=e;let o,r;try{o=await this.generateBopisSearchEventData(`${s},${i}`,!0),this.$emit(h.SEARCH,o),r=((d=(u=(a=o==null?void 0:o.mapboxData)==null?void 0:a.features)==null?void 0:u[0])==null?void 0:d.text)||""}catch(c){t(c);return}r&&(this._errorTimeoutId!==null&&clearTimeout(this._errorTimeoutId),this.errorText&&(this.errorText.textContent="")),this.searchInput.value=r||`${s},${i}`}detectCoords(){return new Promise((e,t)=>{if(!navigator.geolocation){t(new Error("Geolocation not supported"));return}navigator.geolocation.getCurrentPosition(i=>{const{latitude:s,longitude:o}=i.coords;e({latitude:s,longitude:o})},i=>{t(i)})})}async generateBopisSearchEventData(e,t){var i,s,o;try{this.isLoading=!0;const r=await this.fetchMapboxData(e,t),[a,u]=((o=(s=(i=r==null?void 0:r.features)==null?void 0:i[0])==null?void 0:s.geometry)==null?void 0:o.coordinates)||[null,null];if(u===null||a===null)throw new Error("Invalid coordinates from Mapbox result");return{coordinates:{latitude:u,longitude:a},distanceThresholdInM:this.searchDistanceThresholdKm*1e3,mapboxData:r}}catch(r){throw console.error("Error getting sorted results:",r),r}finally{this.isLoading=!1}}async fetchMapboxData(e,t){if(!this.mapboxAccessToken)throw new Error("Mapbox access token is not provided.");const s=`https://api.mapbox.com/geocoding/v5/mapbox.places/${t?e:encodeURIComponent(e)}.json?access_token=${this.mapboxAccessToken}&limit=1&language=en-us`,o=t?`${s}&types=postcode`:`${s}&types=address,district,place,region,postcode,country,locality,neighborhood`,r=await fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}});if(!r.ok)throw new Error(`(Mapbox) Error ${r.status}: ${r.statusText}`);return await r.json()}};l([f()],n.prototype,"isLoading",2);l([E({type:String,attribute:"mapbox-access-token"})],n.prototype,"mapboxAccessToken",2);l([E({type:Number,attribute:"search-distance-threshold-km"})],n.prototype,"searchDistanceThresholdKm",2);l([p("[data-search-input]")],n.prototype,"searchInput",2);l([p("[data-use-my-location-button]")],n.prototype,"useMyLocationButton",2);l([p("[data-error-text]")],n.prototype,"errorText",2);n=l([g("bopis-store-search")],n);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.