1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["etc.clientlibs/aeh/clientlibs/dependencies/assa-abloy-aeh-frontend-dependencies/resources/chunks/leaflet-src.DVDXu7t4.js","etc.clientlibs/aeh/clientlibs/dependencies/assa-abloy-aeh-frontend-dependencies/resources/chunks/vendor.CLXKpVbq.js"])))=>i.map(i=>d[i]); 2var Ct=Object.defineProperty;var Et=(e,t,r)=>t in e?Ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Fe=(e,t,r)=>Et(e,typeof t!="symbol"?t+"":t,r);import{j as n,N as ie,ab as kt,A as _t}from"../js/app.CzHXv3OC.js";import{E as Pt}from"./ErrorBoundary.BSDeRbzo.js";import{b as be,r as o}from"./elastic.CDqqVJuy.js";import{F as Rt}from"./FetchModel.b4lX_zup.js";import{e as _e}from"./errorWebKitYavin.Ds5Zeisz.js";import{g as At}from"./productObjectTable.8lbMw21N.js";import{d as Lt}from"./Alert-CZNqBAS_.DYPDsyG3.js";import"./private-uTZ-4LsN.CmwcLtWn.js";import{o as It}from"./Badge-C3W9hNPu.BuWc6vpA.js";import{c as De}from"./Button-BiUVeREU._Zr2edyt.js";import{C as $t}from"./Pagination-BXQj4RrX.D8bTqYGp.js";import{m as Oe}from"./Input-zGj2sn63.CJAwgQn_.js";import{p as Pe}from"./Select-sICJtqll.CBpxvmlx.js";import{i as Je}from"./EmptyState-88DFHM10.eGA62kar.js";import{B as et,_ as tt,u as Ue,z as Mt,o as Ze}from"./index.DDKlRM6q.js";import{c as Dt}from"./index.Cc6U5CDM.js";import{z as re,f as Tt}from"./index.D6mVWLHx.js";import"./vendor.CLXKpVbq.js";import"./lodash.B7ss2v9R.js";import"./button.BLXcxSDr.js";import"./index.CLZZCk4j.js";import"./index.C0XwLixv.js";import"./floating-ui.react-dom.DBTGSlne.js";import"./index.BEhx-DHv.js";import"./tslib.es6.CldWHa1R.js";import"./Combination.jNkSD2lY.js";var Re={};const rt=(e,t)=>typeof e!="number"||typeof t!="number"||!Number.isFinite(e)||!Number.isFinite(t)||e===0&&t===0?!1:e>=-90&&e<=90&&t>=-180&&t<=180,at=e=>rt(e.latitude,e.longitude),zt=(e,t)=>typeof e=="number"&&typeof t=="number"&&rt(e,t)?{lat:e,lng:t}:void 0,qt=["http:","https:"],Ft=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,st=e=>e.replace(/[\u0000-\u001F\u007F]/g,""),Be=e=>{try{return new URL(e)}catch{return}},nt=e=>{let t=e?st(e).trim():"";if(!t)return;let r=Be(t)??(Ft.test(t)?void 0:Be(`https://${t}`));if(r)return qt.includes(r.protocol)?r.toString():void 0},Ot=/\s*(?:extension|ext\.?|x)\s*/i,Ne=e=>{let t=e?st(e).trim():"";if(!t)return;let r=t.split(Ot),a=r[0]??t,s=a.replace(/\D/g,"");if(!s)return;let i=(r[1]??"").replace(/\D/g,"");return`tel:${a.trimStart().startsWith("+")?"+":""}${s}${i?`;ext=${i}`:""}`},Se=e=>{var r;if(e.state_province_name)return e.state_province_name;let t=e.state_province_code;if(t)return(((r=t.match(/^[A-Za-z]{2}-(.+)$/))==null?void 0:r[1])??t).toUpperCase()},Ce=e=>{let t=(e.country_names??[]).filter(Boolean);if(t.length>0)return t.join(", ");let r=(e.country_codes??[]).filter(Boolean);return r.length>0?r.join(", "):void 0},Ut=e=>[e.address_line1,e.address_line2,e.city,Se(e),e.postal_code,Ce(e)].map(t=>t==null?void 0:t.trim()).filter(t=>!!t).join(", "),ot=e=>{let t=at(e)?`${e.latitude},${e.longitude}`:Ut(e)||e.name.trim();if(t)return`https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(t)}`},xe="flex w-max items-center gap-8 rounded-sm font-body text-paragraph-sm-regular text-action-default hover:text-action-hover hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-action",it=be.forwardRef(({distributor:e,headingLevel:t="h3",selected:r=!1,onSelect:a,onClick:s,className:i,...y},c)=>{let w=t,j=Se(e),S=Ce(e),L=[[e.city,j].filter(Boolean).join(", "),e.postal_code].filter(Boolean).join(" "),x=Ne(e.phone),I=Ne(e.phone_toll_free),P=nt(e.website),Z=ot(e),X=A=>{s==null||s(A),!(A.defaultPrevented||!a)&&(A.target.closest("a, button, input, select, textarea")||a(e))},z=e.distance_miles,B=typeof z=="number"&&Number.isFinite(z)?{visible:`${z.toFixed(1)} mi`,spoken:`${z.toFixed(1)} miles from your search location`}:void 0;return n.jsxs("div",{ref:c,"aria-current":r?"true":void 0,className:ie("flex h-full flex-col gap-8 rounded-md border border-surface-primary bg-primary p-16 transition-shadow hover:shadow-sm",a&&"cursor-pointer",r&&"border-brand-base shadow-sm",i),"data-selected":r?"true":void 0,"data-test":"distributor-card",onClick:X,...y,children:[n.jsxs("div",{className:"flex items-start justify-between gap-8",children:[n.jsx(w,{className:"font-body text-primary text-sub-heading-md-bold",children:a?n.jsx("button",{type:"button",className:"rounded-sm text-left hover:text-action-hover focus:outline-none focus-visible:ring-2 focus-visible:ring-action",onClick:()=>a(e),"data-test":"distributor-card-select",children:e.name}):e.name}),B&&n.jsxs(It,{color:"neutral",contrast:"low",size:"sm",className:"shrink-0","data-test":"distributor-card-distance",children:[n.jsx("span",{"aria-hidden":"true",children:B.visible}),n.jsx("span",{className:"sr-only",children:B.spoken})]})]}),n.jsxs("address",{className:"flex flex-col gap-2 font-body text-paragraph-sm-regular text-secondary not-italic",children:[e.address_line1&&n.jsx("span",{children:e.address_line1}),e.address_line2&&n.jsx("span",{children:e.address_line2}),L&&n.jsx("span",{children:L}),S&&n.jsx("span",{children:S})]}),(x||I)&&n.jsxs("div",{className:"flex flex-col gap-4",children:[x&&n.jsxs("a",{href:x,className:xe,"data-test":"distributor-card-phone",children:[n.jsx(Ue,{"aria-hidden":"true",className:"size-16 shrink-0 text-icon-secondary"}),n.jsx("span",{children:e.phone}),n.jsxs("span",{className:"sr-only",children:[" â phone for ",e.name]})]}),I&&n.jsxs("a",{href:I,className:xe,"data-test":"distributor-card-toll-free",children:[n.jsx(Ue,{"aria-hidden":"true",className:"size-16 shrink-0 text-icon-secondary"}),n.jsxs("span",{children:[e.phone_toll_free," (toll free)"]}),n.jsxs("span",{className:"sr-only",children:[" ","â toll-free phone for ",e.name]})]})]}),n.jsxs("div",{className:"mt-auto flex flex-col gap-4 pt-8",children:[P&&n.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:xe,"data-test":"distributor-card-website",children:[n.jsx(Mt,{"aria-hidden":"true",className:"size-16 shrink-0 text-icon-secondary"}),n.jsx("span",{children:"Website"}),n.jsxs("span",{className:"sr-only",children:[" ","for ",e.name,", opens in a new tab"]}),n.jsx(Ze,{"aria-hidden":"true",className:"size-12 shrink-0"})]}),Z&&n.jsxs("a",{href:Z,target:"_blank",rel:"noopener noreferrer",className:xe,"data-test":"distributor-card-directions",children:[n.jsx(tt,{"aria-hidden":"true",className:"size-16 shrink-0 text-icon-secondary"}),n.jsx("span",{children:"Directions"}),n.jsxs("span",{className:"sr-only",children:[" ","to ",e.name,", opens Google Maps in a new tab"]}),n.jsx(Ze,{"aria-hidden":"true",className:"size-12 shrink-0"})]})]})]})});it.displayName="DistributorCard";const lt=(()=>
2{if(typeof process<"u"&&Re){let e=Re.VITE_DISTRIBUTOR_SEARCH_API_ENDPOINT??Re.DISTRIBUTOR_SEARCH_API_ENDPOINT;if(typeof e=="string"&&e.length>0)return e}})()??"https://api.website-search-assaabloy.com",ut={lat:39.8283459,lng:-98.5794797},dt=[25,50,100,250,500],ge={IDLE:"idle",LOADING:"loading",SUCCESS:"success",ERROR:"error"},se={NAME:"name",DISTANCE:"distance"},Te=[];Object.freeze(Te);const We=Object.freeze({countries:Te,states:Te}),ue="__any__",Ae=(()=>{try{return new Intl.DisplayNames(["en"],{type:"region"})}catch{return}})(),ct=/^([A-Za-z]{2})-(.+)$/,Zt=e=>{if(!/^[A-Za-z]{2}$/.test(e))return e;let t=e.toUpperCase();try{return(Ae==null?void 0:Ae.of(t))??t}catch{return t}},Bt=e=>{var r;let t=(r=e.match(ct))==null?void 0:r[2];return t?t.toUpperCase():e},Wt=(e,t)=>{if(!t)return[];if(!e.some(a=>ct.test(a.value)))return e;let r=`${t.toUpperCase()}-`;return e.filter(a=>a.value.toUpperCase().startsWith(r))},Ht=e=>`${e} ${e===1?"distributor":"distributors"}`,He=new Intl.Collator("en",{numeric:!0,sensitivity:"base"}),Vt=e=>[[[e.city,Se(e)].filter(Boolean).join(", "),e.postal_code].filter(Boolean).join(" ")||e.address_line1,Ce(e)].filter(Boolean).join(" · "),Ve=(e,t,r)=>{let a=e.map(s=>({value:s.value,title:r(s.value),description:Ht(s.count)}));return(t&&!e.some(s=>s.value===t)?[...a,{value:t,title:r(t)}]:a).sort((s,i)=>He.compare(s.title,i.title)||He.compare(s.value,i.value))},pt=be.forwardRef(({values:e,facets:t,radiusOptions:r=dt,sort:a,isSearching:s=!1,idPrefix:i="distributor-filters",popoverZIndexClassName:y,autocompleteSuggestions:c=[],autocompleteLoading:w=!1,onChange:j,onSubmit:S,onReset:L,onSuggestionSelect:x,className:I,...P},Z)=>{let X=`${i}-name`,z=`${i}-name-hint`,B=`${i}-name-suggestions`,A=`${i}-near`,W=`${i}-near-hint`,f=`${i}-country`,K=`${i}-state`,ee=`${i}-radius`,J=o.useRef(null),[Y,D]=o.useState(!1),[O,$]=o.useState(-1),H=e.q.trim().length>=2,U=Y&&H&&(w||c.length>0);o.useEffect(()=>{$(-1),H&&document.activeElement===J.current&&(w||c.length>0)&&D(!0)},[H,w,c]);let m=(t==null?void 0:t.countries)??[],u=(t==null?void 0:t.states)??[],h=Wt(u,e.country),C=e.radius!==null&&!r.includes(e.radius)?[...r,e.radius].sort((p,q)=>p-q):r,v=Ve(m,e.country,Zt),g=Ve(h,e.state,Bt),k=m.length===0?"Country options appear once results have loaded.":void 0,E=u.length>0,b=e.country?E?h.length===0&&!e.state?"No states or provinces are listed for this country.":void 0:"State options appear once results have loaded.":"Choose a country first.",N=v.length===0,M=g.length===0,R=e.near.trim().length>0,d=(a?a===se.DISTANCE:R)?"Results are ordered by distance from this location. Use Radius to limit how far to look.":R?"Use Radius to limit how far from this location to look.":"Enter a location to order results by distance from it. Use Radius to limit how far to look.",T=p=>{j({...e,...p})},V=p=>{T({country:p===ue?"":p,state:""})},Q=p=>{p.preventDefault(),D(!1),S(e)},ne=p=>{D(!1),$(-1),x==null||x(p)},fe=p=>{if(p.key==="Escape"){D(!1),$(-1);return}if(c.length!==0){if(p.key==="ArrowDown"){p.preventDefault(),D(!0),$(q=>Math.min(q+1,c.length-1));return}if(p.key==="ArrowUp"){p.preventDefault(),D(!0),$(q=>Math.max(q-1,0));return}if(p.key==="Enter"&&O>=0){let q=c[O];q&&(p.preventDefault(),ne(q))}}};return n.jsxs("form",{ref:Z,role:"search","aria-label":"Find a distributor","aria-busy":s,onSubmit:Q,className:ie("flex w-full flex-col gap-16 rounded-md border border-surface-primary bg-primary p-16 md:p-24",I),"data-test":"distributor-filters",...P,children:[n.jsxs("div",{className:"relative flex flex-col gap-4",onBlur:p=>{p.currentTarget.contains(p.relatedTarget)||(D(!1),$(-1))},children:[n.jsx(Oe,{ref:J,id:X,type:"text",label:"Search by distributor name",placeholder:"Distributor name",value:e.q,startIcon:et,"aria-describedby":z,"aria-autocomplete":"list","aria-controls":B,"aria-expanded":U,"aria-activedescendant":U&&O>=0?`${B}-${O}`:void 0,role:"combobox",fullWidth:!0,onFocus:()=>{H&&(w||c.length>0)&&D(!0)},onKeyDown:fe,onChange:p=>{let q=p.target.value;T({q}),D(q.trim().length>=2)}}),n.jsx("p",{id:z,className:"font-body text-caption-regular text-secondary",children:"Matches all or part of the distributor name."}),U&&n.jsx("div",{id:B,className:ie("absolute top-[68px] z-50 max-h-[320px] w-full overflow-y-auto rounded-sm border border-surface-primary bg-primary shadow-md",y),"data-test":"distributor-autocomplete",children:w&&c.length===0?n.jsx("output",{className:"px-16 py-12 font-body text-paragraph-sm-regular text-secondary",children:"Finding distributorsâ¦"}):n.jsx("div",{role:"listbox",tabIndex:-1,"aria-label":"Distributor suggestions",children:c.map((p,q)=>{let me=Vt(p);return n.jsxs("div",{id:`${B}-${q}`,role:"option",tabIndex:-1,"aria-selected":O===q,className:ie("flex w-full cursor-pointer flex-col gap-2 px-16 py-12 text-left transition-colors hover:bg-action-secondary-hover focus:bg-action-secondary-hover focus:outline-none",O===q&&"bg-action-secondary-default"),onMouseDown:le=>le.preventDefault(),onMouseEnter:()=>$(q),onClick:()=>ne(p),onKeyDown:le=>{(le.key==="Enter"||le.key===" ")&&(le.preventDefault(),ne(p))},"data-test":"distributor-autocomplete-option",children:[n.jsx("span",{className:"font-body text-paragraph-sm-bold text-primary",children:p.name}),me&&n.jsx("span",{className:"font-body text-caption-regular text-secondary",children:me})]}
2,p.id)})})})]}),n.jsxs("div",{className:"flex flex-col gap-4",children:[n.jsx(Oe,{id:A,type:"text",label:"Search by City or Zip Code",placeholder:"City or ZIP / postal code",value:e.near,startIcon:tt,"aria-describedby":W,fullWidth:!0,onChange:p=>T({near:p.target.value})}),n.jsx("p",{id:W,className:"font-body text-caption-regular text-secondary","data-test":"distributor-filters-near-hint",children:d})]}),n.jsx(Pe,{id:f,label:n.jsxs(n.Fragment,{children:["Filter by Country",k&&n.jsxs("span",{className:"sr-only",children:[" â ",k]})]}),hint:k,placeholder:"All countries",disabled:N,fullWidth:!0,value:e.country||ue,onValueChange:V,contentClassName:y,items:[{value:ue,title:"All countries"},...v]}),n.jsx(Pe,{id:K,label:n.jsxs(n.Fragment,{children:["Filter by State/Province",b&&n.jsxs("span",{className:"sr-only",children:[" â ",b]})]}),hint:b,placeholder:"All states / provinces",disabled:M,fullWidth:!0,value:e.state||ue,onValueChange:p=>T({state:p===ue?"":p}),contentClassName:y,items:[{value:ue,title:"All states / provinces"},...g]}),n.jsx(Pe,{id:ee,label:"Radius",placeholder:"Any distance",fullWidth:!0,value:e.radius===null?ue:String(e.radiu
2s),onValueChange:p=>T({radius:p===ue?null:Number(p)}),contentClassName:y,items:[{value:ue,title:"Any distance"},...C.map(p=>({value:String(p),title:`${p} miles`}))]}),n.jsxs("div",{className:ie("grid gap-8",L&&"grid-cols-2"),children:[n.jsx(De,{type:"submit",tier:"primary",size:"md",fullWidth:!0,loading:s,"aria-busy":s,children:"Search"}),L&&n.jsx(De,{type:"button",tier:"secondary",size:"md",fullWidth:!0,disabled:s,onClick:()=>{D(!1),$(-1),L()},"data-test":"distributor-filters-reset",children:"Reset"})]}),n.jsx("output",{"aria-live":"polite",className:"sr-only",children:s?"Searching for distributors":""})]})});pt.displayName="DistributorFilters";let Le=null;const Gt=()=>typeof window>"u"?Promise.reject(Error("Leaflet can only be loaded in a browser environment.")):(Le||(Le=kt(()=>import("./leaflet-src.DVDXu7t4.js").then(e=>e.l),__vite__mapDeps([0,1])).then(e=>e.default??e).catch(e=>{throw Le=null,e})),Le);let Ge=!1;const Kt=e=>{Ge||!e||typeof window>"u"||window.getComputedStyle(e).position!=="absolute"&&(Ge=!0,console.warn(`[DistributorMap] Leaflet's stylesheet does not appear to be loaded, so the map will render incorrectly. Import it once at your application entry point: import "leaflet/dist/leaflet.css". See DistributorMap's docs for the AEM/americas-onecms path.`))},Yt="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",Qt='© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noreferrer noopener">OpenStreetMap</a> contributors',Ke=(e,t)=>{t.closePopup(),e.once("moveend",()=>t.openPopup()),e.flyTo(t.getLatLng(),Math.max(e.getZoom(),12),{animate:!0,duration:.5})},Ye=(e,t,r,a,s)=>{r.length>0?t.fitBounds(e.latLngBounds(r),{padding:[40,40],maxZoom:12}):t.setView([a.lat,a.lng],s);let i=t.getSize();return i.x>0&&i.y>0},Xt={default:"block size-24 rotate-45 rounded-tl-full rounded-tr-full rounded-bl-full border-2 border-surface-primary bg-action-primary-default shadow-xs",selected:"block size-24 rotate-45 rounded-tl-full rounded-tr-full rounded-bl-full border-2 border-surface-primary bg-action-primary-hover shadow-sm",origin:"block size-24 rotate-45 rounded-tl-full rounded-tr-full rounded-bl-full border-2 border-surface-primary bg-inverse-primary shadow-xs"},Jt=[24,24],er=[12,29],tr=[0,-34],Ie=(e,t)=>e.divIcon({className:t==="origin"?"distributor-map-origin-pin":"distributor-map-pin",iconSize:Jt,iconAnchor:er,popupAnchor:tr,html:`<span class="${Xt[t]}"></span>`}),rr=e=>{let{failed:t,total:r,plotted:a}=e;return t?"Map of distributor locations. The map could not be loaded, so nothing is shown on it. The distributor list below is unaffected.":r===0?"Map of distributor locations. There are no distributors to show, so the map is empty.":a===0?"Map of distributor locations. No results have coordinates to plot, so nothing is shown on the map. Every distributor is listed below.":`Map of distributor locations. ${a} of ${r} ${r===1?"distributor is":"distributors are"} plotted. Use the arrow keys to pan and the plus and minus buttons to zoom. The same distributors are listed below the map.`},ar=at,ve=(e,t,r="font-body text-caption-regular text-secondary")=>{if(!t)return;let a=document.createElement("span");a.className=r,a.textContent=t,e.appendChild(a)},we=(e,t)=>{if(!t.href)return;let r=document.createElement("a");r.className="flex items-center justify-between gap-8 rounded-sm border border-surface-primary px-12 py-8 font-body text-caption-bold text-action-default hover:border-brand-base hover:text-action-hover focus:outline-none focus-visible:ring-2 focus-visible:ring-action",r.href=t.href,r.textContent=t.label,r.dataset.test=t.test,t.external&&(r.target="_blank",r.rel="noreferrer noopener"),e.appendChild(r)},sr=e=>{let t=document.createElement("div");t.className="flex min-w-[240px] max-w-[300px] flex-col gap-12 p-4",t.dataset.test="distributor-map-popup-card";let r=document.createElement("div");r.className="flex items-start justify-between gap-8 border-surface-primary border-b pb-8",t.appendChild(r);let a=document.createElement("p");if(a.className="font-body text-paragraph-sm-bold text-primary",a.textContent=e.name,r.appendChild(a),typeof e.distance_miles=="number"&&Number.isFinite(e.distance_miles)){let c=document.createElement("span");c.className="shrink-0 rounded-full bg-secondary px-8 py-2 font-body text-caption-bold text-secondary",c.textContent=`${e.distance_miles.toFixed(1)} mi`,c.dataset.test="distributor-map-popup-distance",r.appendChild(c)}let s=document.createElement("address");s.className="flex flex-col gap-2 text-secondary not-italic",s.dataset.test="distributor-map-popup-address",ve(s,e.address_line1),ve(s,e.address_line2),ve(s,[[e.city,Se(e)].filter(
2Boolean).join(", "),e.postal_code].filter(Boolean).join(" ")),ve(s,Ce(e)),s.childElementCount>0&&t.appendChild(s);let i=document.createElement("div");i.className="flex flex-col gap-4",we(i,{label:e.phone??"",href:Ne(e.phone),test:"distributor-map-popup-phone"}),we(i,{label:e.phone_toll_free?`${e.phone_toll_free} (toll free)`:"",href:Ne(e.phone_toll_free),test:"distributor-map-popup-toll-free"}),i.childElementCount>0&&t.appendChild(i);let y=document.createElement("div");return y.className="grid grid-cols-2 gap-8",we(y,{label:"Website â",href:nt(e.website),test:"distributor-map-popup-website",external:!0}),we(y,{label:"Directions â",href:ot(e),test:"distributor-map-popup-directions",external:!0}),y.childElementCount>0&&t.appendChild(y),t},ft=be.forwardRef(({distributors:e,center:t=ut,zoom:r=4,origin:a=null,selectedId:s=null,highlightedId:i=null,onMarkerSelect:y,className:c,...w},j)=>{let S=o.useRef(null),L=`${o.useId()}-summary`,x=o.useRef(!1),I=o.useRef({center:t,zoom:r}),P=o.useRef(y),Z=o.useRef(new Map),X=o.useRef(s),z=o.useRef(i),B=o.useRef(null),[A,W]=o.useState(null),[f,K]=o.useState(!1);o.useEffect(()=>{P.current=y},[y]);let ee=o.useMemo(()=>e.filter(ar),[e]),J=t.lat,Y=t.lng,D=a?zt(a.lat,a.lng):void 0,O=D?D.lat:null,$=D?D.lng:null;o.useEffect(()=>{let m=!1,u=null,h=null,C=null,v=0,g=null,k=null;return Gt().then(E=>{let b=S.current;if(m||!b)return;let{center:N,zoom:M}=I.current,R=E.map(b,{center:[N.lat,N.lng],zoom:M,scrollWheelZoom:!1,attributionControl:!0});C=d=>{if(!d.metaKey&&!d.ctrlKey){d.stopImmediatePropagation();return}if(d.deltaY===0)return;d.preventDefault(),d.stopImmediatePropagation();let T=d.deltaMode===WheelEvent.DOM_DELTA_LINE?16:d.deltaMode===WheelEvent.DOM_DELTA_PAGE?b.clientHeight:1;v+=d.deltaY*T,g=R.mouseEventToContainerPoint(d),k!==null&&window.clearTimeout(k),k=window.setTimeout(()=>{let V=g,Q=v;if(k=null,g=null,v=0,!x.current||!V||Q===0)return;let ne=Math.min(4,Math.max(1,Math.round(Math.abs(Q)/60)));R.setZoomAround(V,R.getZoom()+(Q<0?ne:-ne))},40)},b.addEventListener("wheel",C,{capture:!0,passive:!1}),h=b,E.tileLayer(Yt,{attribution:Qt,maxZoom:19}).addTo(R),Kt(R.getPane("mapPane")??null),u=R,x.current=!0,W({L:E,map:R})}).catch(E=>
2{m||(K(!0),console.warn("[DistributorMap] Leaflet could not be loaded, so the map is not rendered. Install the optional peer dependency `leaflet` (^1.8.0) or pass showMap={false}.",E))}),()=>{m=!0,x.current=!1,W(null),C&&h&&(h.removeEventListener("wheel",C,!0),C=null,h=null),k!==null&&(window.clearTimeout(k),k=null),u&&(u=(u.remove(),null))}},[]),o.useEffect(()=>{if(!A)return;let{L:m,map:u}=A,h=m.layerGroup().addTo(u),C=Z.current,v=[],g;for(let N of ee){let M=N.id===X.current,R=N.id===z.current,d=m.marker([N.latitude,N.longitude],{icon:Ie(m,M||R?"selected":"default"),title:N.name,alt:N.name,keyboard:!0,riseOnHover:!0});d.bindPopup(sr(N),{autoPan:!0,autoPanPadding:[24,24],className:"distributor-map-popup",keepInView:!0,minWidth:260,maxWidth:320}),d.on("click",()=>{var T;(T=P.current)==null||T.call(P,N)}),d.on("keydown",T=>{var Q;let V=T.originalEvent;!V||V.repeat||V.key!=="Enter"&&V.key!==" "||(V.key===" "&&(V.preventDefault(),d.openPopup()),(Q=P.current)==null||Q.call(P,N))}),d.addTo(h),C.set(N.id,d),v.push([N.latitude,N.longitude]),M&&(g=d
2)}O!==null&&$!==null&&(m.marker([O,$],{icon:Ie(m,"origin"),title:"Your search location",alt:"Your search location",keyboard:!1,interactive:!1}).addTo(h),v.push([O,$]));let k=v.length>0?v.map(([N,M])=>`${N},${M}`).join("|"):`empty:${J},${Y},${r}`,E=B.current,b={lat:J,lng:Y};return(!E||E.map!==u||E.signature!==k||!E.sized)&&(B.current={map:u,signature:k,points:v,center:b,zoom:r,sized:Ye(m,u,v,b,r)}),g&&Ke(u,g),()=>{C.clear(),x.current&&(h.clearLayers(),u.removeLayer(h))}},[A,ee,J,Y,O,$,r]),o.useEffect(()=>{var k,E;let m=X.current,u=z.current;if(X.current=s,z.current=i,!A)return;let{L:h,map:C}=A,v=Z.current,g=new Set([m,u,s,i].filter(b=>!!b));for(let b of g){let N=b===s||b===i;(k=v.get(b))==null||k.setIcon(Ie(h,N?"selected":"default"))}if(m&&m!==s&&((E=v.get(m))==null||E.closePopup()),s&&m!==s){let b=v.get(s);b&&Ke(C,b)}},[A,s,i]),o.useEffect(()=>{if(!A||typeof ResizeObserver>"u")return;let m=S.current;if(!m)return;let u=new ResizeObserver(()=>{let{L:h,map:C}=A;C.invalidateSize();let v=B.current;v&&v.map===C&&!v.sized&&(v.sized=Ye(h,C,v.points,v.center,v.zoom))});return u.observe(m),()=>{u.disconnect()}},[A]);let H=e.length-ee.length,U=rr({failed:f,total:e.length,plotted:ee.length});return n.jsxs("div",{ref:j,className:ie("flex flex-col",c),"data-test":"distributor-map",...w,children:[n.jsx("p",{className:"sr-only",id:L,children:U}),n.jsx("div",{className:ie("relative h-360 w-full overflow-hidden rounded-sm border border-surface-primary bg-tertiary lg:h-500",!A&&!f&&"animate-pulse"),children:n.jsx("div",{ref:S,role:"region","aria-label":"Map of distributor locations","aria-describedby":L,className:"h-full w-full","data-test":"distributor-map-canvas"})}),n.jsxs("output",{"aria-live":"polite",children:[f&&n.jsx("p",{className:"mt-8 font-body text-critical text-paragraph-sm-regular","data-test":"distributor-map-error",children:"The map could not be loaded. The distributor list below is complete and unaffected."}),!f&&H>0&&n.jsxs("p",{className:"mt-8 font-body text-caption-regular text-tertiary","data-test":"distributor-map-skipped",children:[H," of ",e.length," locations could not be shown on the map because they have no coordinates. They are still listed below."]})]})]})});ft.displayName="DistributorMap";const mt=be.forwardRef(({count:e=6,className:t,...r},a)=>n.jsx("div",{ref:a,"aria-hidden":"true",className:ie("grid grid-cols-1 gap-16 md:grid-cols-2",t),"data-test":"distributor-results-skeleton",...r,children:Array.from({length:e},(s,i)=>i).map(s=>n.jsxs("div",{className:"flex animate-pulse flex-col gap-12 rounded-md border border-surface-primary bg-primary p-16",children:[n.jsx("div",{className:"h-20 w-3/4 rounded-xs bg-tertiary"}
2),n.jsx("div",{className:"h-14 w-1/2 rounded-xs bg-tertiary"}),n.jsxs("div",{className:"flex flex-col gap-8",children:[n.jsx("div",{className:"h-14 w-full rounded-xs bg-tertiary"}),n.jsx("div",{className:"h-14 w-5/6 rounded-xs bg-tertiary"})]}),n.jsxs("div",{className:"flex gap-12",children:[n.jsx("div",{className:"h-32 w-128 rounded-sm bg-tertiary"}),n.jsx("div",{className:"h-32 w-128 rounded-sm bg-tertiary"})]})]},s))}));mt.displayName="DistributorResultsSkeleton";const nr=[18,36,54,90],or=[...nr],ht=be.forwardRef(({distributors:e,total:t,page:r,perPage:a,status:s="success",error:i,perPageOptions:y=or,selectedId:c=null,hasActiveFilters:w=!1,onPageChange:j,onPerPageChange:S,onDistributorSelect:L,onDistributorHover:x,onClearFilters:I,onWidenRadius:P,onRetry:Z,className:X,...z},B)=>{let A=s==="loading",W=s==="idle"&&e.length===0,f=t>0&&e.length===0,K=Math.max(1,Math.ceil(t/Math.max(1,a))),ee=o.useId(),J=t===0?0:(r-1)*a+1,Y=e.length===0?0:Math.min(J+e.length-1,t),D=o.useMemo(()=>{if(!j)return[];let u=new Set;u.add(1),r>1&&u.add(r-1),u.add(r),r<K&&u.add(r+1),u.add(K);let h=Array.from(u).filter(g=>g>=1&&g<=K).sort((g,k)=>g-k),C=[],v;for(let g of h)v!==void 0&&g-v>1&&C.push({type:"ellipsis"}),C.push({type:"button",children:g.toString(),isActive:g===r,"aria-label":`Go to page ${g}`,onClick:()=>j(g)}),v=g;return C},[r,K,j]),O=o.useMemo(()=>Array.from(new Set([a,...y])).sort((u,h)=>u-h).map(u=>({value:u.toString(),children:u.toString()})),[a,y]),$=()=>s==="error"?n.jsxs("div",{className:"flex flex-col items-start gap-16","data-test":"distributor-results-error",children:[n.jsx(Lt,{type:"error",size:"lg",fullWidth:!0,title:"We could not load distributors",supportingText:i??"Something went wrong while contacting the distributor service. Please try again."}),Z&&n.jsx(De,{tier:"secondary",size:"md",onClick:Z,children:"Try again"})]}):A?n.jsx(mt,{count:Math.min(a,6)}):W?null:e.length===0?n.jsx("div",{className:"py-64","data-test":"distributor-results-empty",children:n.jsx(Je,{illustration:n.jsx("div",{className:"flex size-96 items-center justify-center rounded-full bg-secondary",children:n.jsx(et,{className:"size-48 text-icon-secondary"})}),title:"No distributors found",supportingText:f?"This page is past the end of the results. Go back to an earlier page to see the matches.":w?"Try widening the search radius, or clearing the country and state filters to see more locations.":"Try widening the search radius, or searching a nearby city or postal code.",primaryActionLabel:P?"Widen the radius":void 0,primaryActionProps:P?{onClick:P}:void 0,secondaryActionLabel:w&&I?"Clear filters":void 0,secondaryActionProps:w&&I?{onClick:I}:void 0})}):n.jsx("div",{"aria-live":"off",className:"grid grid-cols-1 gap-16 md:grid-cols-2","data-test":"distributor-results-grid",children:e.map(u=>n.jsx(it,{distributor:u,selected:u.id===c,onSelect:L,onFocus:()=>x==null?void 0:x(u),onBlur:h=>{h.currentTarget.contains(h.relatedTarget)||(x==null||x(null))},onMouseEnter:()=>x==null?void 0:x(u),onMouseLeave:()=>x==null?void 0:x(null)},u.id))}),H=s==="error"||W?null:A?"Loading distributors":t===0||e.length===0?"No results":`Showing ${J.toLocaleString()} - ${Y.toLocaleString()} out of ${t.toLocaleString()}`,U=!!j&&!A&&s!=="error"&&(e.length>0||t>0)&&(K>1||r>1),m=(u,h)=>({disabled:u,role:"button","aria-disabled":u||void 0,onClick:()=>{u||(j==null||j(h))},onKeyDown:C=>{u||C.key!=="Enter"&&C.key!==" "||(C.preventDefault(),j==null||j(h))}});return n.jsxs("section",{ref:B,"aria-label":"Distributor search results","aria-live":"polite","aria-atomic":"false","aria-busy":A,className:ie("flex flex-col gap-16",X),"data-test":"distributor-results",...z,children:[H&&n.jsx("p",{className:"font-body text-caption-regular text-tertiary uppercase","data-test":"distributor-results-count",children:H}),$(),U&&n.jsx($t,{capacityId:ee,capacityName:"distributor-per-page",capacityLabel:"Results per page",capacityValue:a.toString(),capacityItems:O,capacityDisabled:!S,capacityValueOnChange:u=>{let h=Number.parseInt(u,10);Number.isNaN(h)||(S==null||S(h))},previousButtonProps:m(r<=1,r-1),nextButtonProps:m(r>=K,r+1),items:D})]})});ht.displayName="DistributorResults";const ir=(e,t)=>
2!Number.isFinite(e)||!Number.isFinite(t)||e<-90||e>90||t<-180||t>180?null:`${e.toFixed(5)}, ${t.toFixed(5)}`,Qe="/api/v1/distributors/search",Xe="/api/v1/distributors/facets",je=e=>e instanceof Error&&e.name==="AbortError",pe=e=>typeof e=="object"&&!!e&&!Array.isArray(e),ae=e=>e===null?void 0:e,oe=e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,lr=e=>{var r;let t=pe(e.attributes)?e.attributes:{};return{id:String(e.id),name:t.name??"",address_line1:ae(t.address_line1),address_line2:ae(t.address_line2),city:ae(t.city),state_province_code:ae(t.state_province_code),state_province_name:ae(t.state_province_name),postal_code:ae(t.postal_code),country_codes:ae(t.country_codes),country_names:ae(t.country_names),phone:ae(t.phone),phone_toll_free:ae(t.phone_toll_free),website:ae(t.website),latitude:oe(t.latitude),longitude:oe(t.longitude),distance_miles:oe((r=e.meta)==null?void 0:r.distance_miles)}},ur=e=>pe(e)?{query:typeof e.query=="string"?e.query:"",resolved:e.resolved===!0,latitude:oe(e.latitude),longitude:oe(e.longitude)}:null,dr=e=>{let t=(Array.isArray(e==null?void 0:e.data)?e.data:[]).filter(pe).map(lr),r=pe(e==null?void 0:e.meta)?e.meta:void 0,a=oe(r==null?void 0:r.total)??t.length,s=oe(r==null?void 0:r.page_size)??t.length,i=oe(r==null?void 0:r.total_pages)??(s>0?Math.ceil(a/s):0);return{results:t,total:a,page:oe(r==null?void 0:r.page)??1,pageSize:s,totalPages:i,sort:(r==null?void 0:r.sort)===se.DISTANCE?se.DISTANCE:se.NAME,near:ur(r==null?void 0:r.near),radiusMiles:oe(r==null?void 0:r.radius_miles)??null}},cr=e=>{let t=pe(e==null?void 0:e.data)?e.data:void 0;return{countries:Array.isArray(t==null?void 0:t.countries)?t.countries:[],states:Array.isArray(t==null?void 0:t.states)?t.states:[]}},pr=new Set(["query","body","path","header","cookie"]),fr=e=>{let t=e.filter(pe).map(r=>{if(typeof r.msg!="string"||r.msg==="")return null;let a=[...Array.isArray(r.loc)?r.loc:[]].reverse().find(s=>typeof s=="string"&&!pr.has(s));return a?`${a}: ${r.msg}`:r.msg}).filter(r=>r!==null);return t.length>0?t.join("; "):null},mr=(e,t)=>{if(!pe(e))return t;let{detail:r,message:a}=e;if(typeof r=="string"&&r!=="")return r;if(Array.isArray(r)){let s=fr(r);if(s)return s}return typeof a=="string"&&a!==""?a:t};var gt=class{constructor(e){Fe(this,"baseUrl");this.baseUrl=e.replace(/\/+$/,"")}appendParam(e,t,r){r==null||r===""||e.append(t,String(r))}buildSearchQueryString(e){var r,a,s,i;let t=new URLSearchParams;this.appendParam(t,"q",e.q),this.appendParam(t,"near",e.near),this.appendParam(t,"radius",e.radius),this.appendParam(t,"filter[id]",(r=e.filter)==null?void 0:r.id);for(let y of((a=e.filter)==null?void 0:a.country)??[])this.appendParam(t,"filter[country]",y);return this.appendParam(t,"filter[state]",(s=e.filter)==null?void 0:s.state),this.appendParam(t,"filter[brand]",(i=e.filter)==null?void 0:i.brand),this.appendParam(t,"sort",e.sort),this.appendParam(t,"page",e.page),this.appendParam(t,"size",e.size),t.toString()}async makeRequest(e,t){let r=`${this.baseUrl}${e}`;try{let a=await fetch(r,{signal:t});if(!a.ok){let s=await a.json().catch(()=>null);throw Error(mr(s,`HTTP ${a.status}: ${a.statusText}`))}return await a.json()}catch(a){throw je(a)||console.error("Distributor API request failed:",a),a}}async search(e={},t){let r=this.buildSearchQueryString(e),a=r?`${Qe}?${r}`:Qe;return dr(await this.makeRequest(a,t))}async facets(e,t){let r=new URLSearchParams;this.appendParam(r,"filter[brand]",e);let a=r.toString(),s=a?`${Xe}?${a}`:Xe;return cr(await this.makeRequest(s,t))}};const hr=["q","near","radius","filter[id]","filter[country]","filter[state]","sort","page"],gr=(e,t)=>{let r=new URLSearchParams(e);for(let a of hr)r.delete(a);t.q&&r.set("q",t.q),t.near&&r.set("near",t.near),t.near&&t.radiu
2s&&r.set("radius",String(t.radius)),t.distributorId&&r.set("filter[id]",t.distributorId);for(let a of t.countries)r.append("filter[country]",a);return t.state&&r.set("filter[state]",t.state),t.sort&&t.sort!==se.NAME&&r.set("sort",t.sort),t.page>1&&r.set("page",String(t.page)),r},bt=e=>{let t={},r=e.get("q");r!==null&&(t.q=r);let a=e.get("near");a!==null&&(t.near=a);let s=e.get("radius");if(s!==null){let S=Number.parseInt(s,10);t.radius=Number.isNaN(S)||S<=0?null:S}let i=e.getAll("filter[country]").filter(Boolean);i.length>0&&(t.countries=i);let y=e.get("filter[id]");y!==null&&(t.distributorId=y);let c=e.get("filter[state]");c!==null&&(t.state=c);let w=e.get("sort");(w===se.NAME||w===se.DISTANCE)&&(t.sort=w);let j=e.get("page");if(j!==null){let S=Number.parseInt(j,10);!Number.isNaN(S)&&S>0&&(t.page=S)}return t},br=(e,t)=>{if(!t||typeof window>"u")return{state:e,explicitSort:null};let r=bt(new URLSearchParams(window.location.search));return{state:{...e,...r},explicitSort:r.sort??null}},yr=({searchState:e,onStateChange:t,enabled:r=!1})=>{let a=o.useRef(!0),s=o.useRef(!1),i=o.useRef(e),y=o.useRef(t);y.current=t,o.useEffect(()=>{let c=i.current;if(i.current=e,!r||typeof window>"u")return;if(a.current){a.current=!1;return}if(s.current)return;let w=gr(new URLSearchParams(window.location.search),e).toString(),{pathname:j,search:S,hash:L}=window.location,x=`${j}${w?`?${w}`:""}${L}`;x!==`${j}${S}${L}`&&(c.page===e.page&&c.distributorId===e.distributorId&&c.state===e.state&&c.sort===e.sort&&c.radius===e.radius&&c.countries.length===e.countries.length&&c.countries.every((I,P)=>I===e.countries[P])?window.history.replaceState({},"",x):window.history.pushState({},"",x))},[e,r]),o.useEffect(()=>{if(!r||typeof window>"u")return;let c=()=>{s.current=!0,y.current(bt(new URLSearchParams(window.location.search))),setTimeout(()=>{s.current=!1},0)};return window.addEventListener("popstate",c),()=>{window.removeEventListener("popstate",c)}},[r])},yt=[];Object.freeze(yt);const $e=()=>({q:"",distributorId:"",near:"",radius:null,countries:[],state:"",sort:se.NAME,page:1}),xr=(e,t)=>e.trim()?t??se.DISTANCE:se.NAME,Me=(e,t)=>{let r=xr(e.near,t);return r===e.sort?e:{...e,sort:r}},vr=({config:e={},data:t,deferInitialSearch:r=!1,scrollToElement:a}={})=>{var qe;let s=t!==void 0,i=e.apiEndpoint||lt,y=e.brand,c=typeof e.perPage=="number"&&Number.isFinite(e.perPage)&&e.perPage>=1?Math.trunc(e.perPage):18,[w,j]=o.useState(c),S=e.radiusOptions||dt,L=e.syncURL===!0&&!s,[x]=o.useState(()=>br($e(),L)),I=o.useRef(x.explicitSort),[P,Z]=o.useState(()=>Me(x.state,x.explicitSort)),[X,z]=o.useState([]),[B,A]=o.useState(0),[W,f]=o.useState(null),[K,ee]=o.useState(We),[J,Y]=o.useState(ge.IDLE),[D,O]=o.useState(!1),[$,H]=o.useState(null),U=o.useMemo(()=>new gt(i),[i]),m=o.useRef(null),u=o.useRef(null),h=o.useRef(0),C=o.useRef(r),v=o.useRef(c),g=o.useRef(P);g.current=P;let k=o.useRef(s);k.current=s;let E=o.useCallback(()=>{h.current+=1,u.current&&(u.current=(u.current.abort(),null))}
2,[]),b=o.useCallback(()=>{m.current&&(m.current=(clearTimeout(m.current),null)),E()},[E]);o.useEffect(()=>{if(v.current===c)return;v.current=c,b();let l={...g.current,page:1};g.current=l,Z(l),j(c)},[b,c]);let N=o.useCallback(l=>({q:l.q.trim()||void 0,near:l.near.trim()||void 0,radius:l.near.trim()&&l.radius?l.radius:void 0,filter:{id:l.distributorId||void 0,country:l.countries.length>0?l.countries:void 0,state:l.state||void 0,brand:y||void 0},sort:l.sort,page:l.page,size:w}),[y,w]),M=o.useCallback(async(l,{skipLoadingStatus:F=!1}={})=>{var ce;if(k.current||s)return;C.current=!1,m.current&&(m.current=(clearTimeout(m.current),null)),E();let G=h.current,he=new AbortController;u.current=he,O(!0),H(null),F||Y(ge.LOADING);try{let de=await U.search(N(l),he.signal);if(G!==h.current)return;z(de.results),A(de.total),f((ce=de.near)!=null&&ce.resolved?de.near:null),Y(ge.SUCCESS)}catch(de){if(je(de)||G!==h.current)return;H(de instanceof Error?de.message:"Distributor search failed"),Y(ge.ERROR)}finally{u.current===he&&(u.current=null),G===h.current&&O(!1)}},[U,N,E,s]),R=o.useCallback(l=>{k.current||(m.current&&clearTimeout(m.current),E(),m.current=setTimeout(()=>{m.current=null,M(l)},400))},[E,M]),d=o.useCallback((l,{debounce:F=!1,skipLoadingStatus:G=!1,sortPreference:he}={})=>{he!==void 0&&(I.current=he);let ce=Me({...g.current,...l},I.current);g.current=ce,Z(ce),F?R(ce):M(ce,{skipLoadingStatus:G})},[M,R]),T=o.useCallback(l=>{d({q:l,page:1},{debounce:!0})},[d]),V=o.useCallback(l=>{d({near:l,page:1},{debounce:!0})},[d]),Q=o.useCallback(l=>{d({radius:l,page:1})},[d]),ne=o.useCallback(l=>{d({countries:l,page:1})},[d]),fe=o.useCallback(l=>{let F=g.current.countries;d({countries:F.includes(l)?F.filter(G=>G!==l):[...F,l],page:1})},[d]),p=o.useCallback(l=>{d({state:l,page:1})},[d]),q=o.useCallback(l=>{d({sort:l,page:1},{sortPreference:l})},[d]),me=o.useCallback(l=>{d({page:l},{skipLoadingStatus:!0}),a?a():typeof window<"u"&&window.scrollTo({top:0,behavior:"smooth"})},[d,a]),le=o.useCallback(l=>{if(!Number.isFinite(l))return;let F=Math.trunc(l);if(F<1||F===w)return;b();let G={...g.current,page:1};g.current=G,Z(G),j(F),a?a():typeof window<"u"&&window.scrollTo({top:0,behavior:"smooth"})},[b,w,a]),Ee=o.useCallback(()=>{d($e(),{sortPreference:null})},[d]),ke=o.useCallback(l=>{d({...l,distributorId:l.distributorId??"",page:1})},[d]),_=o.useCallback(()=>{d({page:1})},[d]);yr({searchState:P,onStateChange:o.useCallback(l=>{I.current=l.sort??null;let F=Me({...$e(),...l},I.current);g.current=F,Z(F),M(F)},[M]),enabled:L}),o.useEffect(()=>{if(s)return;let l=new AbortController,F=!1;return U.facets(y,l.signal).then(G=>{F||ee(G)}).catch(G=>{je(G)||console.error("Distributor facets failed:",G)}),()=>{F=!0,l.abort()}},[U,y,s]),o.useEffect(()=>{s&&b()},[s,b]),o.useEffect(()=>{if(s)return;let l=g.current,F=l.q.length===0&&l.near.length===0&&l.countries.length===0&&l.state.length===0&&l.radius===null;C.current&&F||M(g.current)},[s,M]),o.useEffect(()=>()=>{b()},[b]);let te=s?(t==null?void 0:t.status)??ge.IDLE:J,ye=s?(t==null?void 0:t.results)??yt:X,ze=s?(t==null?void 0:t.total)??((qe=t==null?void 0:t.results)==null?void 0:qe.length)??0:B,vt=s?(t==null?void 0:t.facets)??We:K,wt=s?(t==null?void 0:t.error)??null:$,Nt=s?(t==null?void 0:t.origin)??null:W,jt=s?(t==null?void 0:t.status)===ge.LOADING:D,St=Math.max(1,Math.ceil(ze/w));return{status:te,isFetching:jt,error:wt,isControlled:s,results:ye,total:ze,facets:vt,origin:Nt,searchState:P,page:P.page,perPage:w,totalPages:St,radiusOptions:S,updateSearchQuery:T,updateNearQuery:V,updateRadius:Q,updateCountries:ne,toggleCountry:fe,updateStateFilter:p,updateSort:q,updatePage:me,updatePerPage:le,clearFilters:Ee,applyFilters:ke,search:_,api:U}},wr=({query:e,apiEndpoint:t=lt,brand:r,enabled:a=!0})=>{let[s,i]=o.useState([]),[y,c]=o.useState(!1),w=o.useMemo(()=>new gt(t),[t]);return o.useEffect(()=>{let j=e.trim();if(!a||j.length<2){i([]),c(!1);return}let S=new AbortController,L=!0,x=window.setTimeout(()=>{c(!0),w.search({q:j,filter:{brand:r||void 0},sort:se.NAME,page:1,size:6},S.signal).then(I=>{L&&i(I.results)}).catch(I=>{L&&!je(I)&&i([])}).finally(()=>{L&&c(!1)})},200);return()=>{L=!1,window.clearTimeout(x),S.abort()}},[w,r,a,e]),{suggestions:s,loading:y}},Nr=Dt({slots:{root:"w-full bg-secondary",body:"mx-auto flex max-w-container-desktop flex-col gap-24 px-16 py-24 sm:px-24 lg:flex-row lg:px-32",rail:"lg:w-[320px] lg:shrink-0",main:"flex min-w-0 flex-1 flex-col gap-24"}},{twMerge:!1}),xt=be.forwardRef(({config:e,showMap:t=!0,defaultCenter:r=ut,defaultZoom:a=4,onDistributorSelect:s,popoverZIndexClassName:i,data:y,className:c,...w},j)=>{let{root:S,body:L,rail:x,main:I}=Nr(),P=y===void 0&&(e==null?void 0:e.autoLocate)!==!1&&typeof navigator<"u"&&!!navigator.geolocation,{status:Z,error:X,results:z,total:B,facets:A,origin:W,searchState:f,page:K,perPage:ee,radiusOptions:J,updatePage:Y,updatePerPage:D,clearFilters:O,a
2pplyFilters:$,search:H,isControlled:U}=vr({config:e,data:y,deferInitialSearch:P}),m=Z==="loading",[u,h]=o.useState(null),[C,v]=o.useState(null),g=o.useRef(!1),k=o.useRef(!1),E=o.useRef(!1),b=o.useRef(P&&f.q.length===0&&f.near.length===0&&f.countries.length===0&&f.state.length===0&&f.radius===null),N=o.useCallback(()=>{b.current&&(b.current=!1,H())},[H]);o.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]);let M=o.useCallback(_=>{h(_.id),s==null||s(_)},[s]),R=o.useMemo(()=>({q:f.q,near:f.near,country:f.countries[0]??"",state:f.state,radius:f.radius}),[f.q,f.near,f.countries,f.state,f.radius]),[d,T]=o.useState(R);o.useEffect(()=>{T(R)},[R]);let V=o.useCallback(_=>{E.current=!0,N(),T(_)},[N]),Q=o.useCallback((_,te="")=>{E.current=!0,b.current=!1,h(null),v(null),$({q:_.q,distributorId:te,near:_.near,countries:_.country?[_.country]:[],state:_.state,radius:_.radius})},[$]),ne=o.useCallback(()=>{E.current=!0,b.current=!1,T({...R,radius:null}),$({q:R.q,distributorId:f.distributorId??"",near:R.near,countries:R.country?[R.country]:[],state:R.state,radius:null})},[$,R,f.distributorId]),fe=o.useCallback(()=>{E.current=!0,b.current=!1,h(null),v(null),T({q:"",near:"",country:"",state:"",radius:null}),O()},[O]),p=wr({query:d.q,apiEndpoint:e==null?void 0:e.apiEndpoint,brand:e==null?void 0:e.brand,enabled:!U}),q=o.useMemo(()=>{if(!U)return p.suggestions;let _=d.q.trim().toLocaleLowerCase();return _.length<2?[]:z.filter(te=>te.name.toLocaleLowerCase().includes(_)).slice(0,6)},[p.suggestions,d.q,U,z]),me=o.useCallback(_=>{let te={...d,q:_.name};T(te),Q(te,_.id),M(_)},[d,Q,M]),le=o.useCallback(_=>{E.current=!0,b.current=!1,Y(_)},[Y]),Ee=o.useCallback(_=>{v((_==null?void 0:_.id)??null)},[]);o.useEffect(()=>{let _=f.q.length===0&&f.near.length===0&&f.countries.length===0&&f.state.length===0&&f.radius===null;g.current||(e==null?void 0:e.autoLocate)===!1||U||!_||typeof navigator>"u"||!navigator.geolocation||(g.current=!0,navigator.geolocation.getCurrentPosition(te=>{if(!k.current)return;if(E.current){N();return}let ye=ir(te.coords.latitude,te.coords.longitude);if(!ye){N();return}b.current=!1,T({q:"",near:ye,country:"",state:"",radius:null}),$({q:"",near:ye,countries:[],state:"",radius:null})},()=>{k.current&&N()},{enableHighAccuracy:!1,timeout:8e3,maximumAge:5*6e4}))},[$,e==null?void 0:e.autoLocate,U,N,f]);let ke=f.q.length>0||f.near.length>0||f.countries.length>0||f.state.length>
20||f.radius!==null;return n.jsx("div",{ref:j,role:"region","aria-label":"Distributor search",className:ie(S(),c),"data-test":"distributor-search",...w,children:n.jsxs("div",{className:L(),children:[n.jsx("div",{className:x(),children:n.jsx(pt,{autocompleteLoading:p.loading,autocompleteSuggestions:q,facets:A,isSearching:m,onChange:V,onReset:fe,onSuggestionSelect:me,onSubmit:Q,popoverZIndexClassName:i,radiusOptions:J,sort:f.sort,values:d})}),n.jsxs("div",{className:I(),children:[t&&n.jsx("div",{"data-test":"distributor-search-map-frame",children:n.jsx(ft,{center:r,distributors:z,highlightedId:C,onMarkerSelect:M,origin:W!=null&&W.resolved&&typeof W.latitude=="number"&&typeof W.longitude=="number"?{lat:W.latitude,lng:W.longitude}:null,selectedId:u,zoom:a})}),n.jsx(ht,{distributors:z,error:X??void 0,hasActiveFilters:ke,onClearFilters:fe,onDistributorSelect:M,onDistributorHover:Ee,onPageChange:le,onPerPageChange:D,onRetry:H,onWidenRadius:ne,page:K,perPage:ee,selectedId:u,status:Z,total:B})]})]})})});xt.displayName="DistributorSearch";const jr="AEHDistributorSearch",Sr=re.object({brand:re.string().trim().min(1).default("sargent-greenleaf"),apiEndpoint:re.string().url().optional(),showMap:re.boolean().default(!0),perPage:re.number().int().min(1).max(100).default(18),autoLocate:re.boolean().default(!0),syncURL:re.boolean().default(!1),defaultLatitude:re.number().min(-90).max(90).optional(),defaultLongitude:re.number().min(-180).max(180).optional(),defaultZoom:re.number().int().min(0).max(19).optional()}).merge(At).superRefine((e,t)=>{const r=e.defaultLatitude!==void 0,a=e.defaultLongitude!==void 0;r!==a&&t.addIssue({code:re.ZodIssueCode.custom,message:"Default latitude and default longitude must either both be set or both be empty.",path:r?["defaultLongitude"]:["defaultLatitude"]})}),Cr=({pathModel:e,componentModel:t})=>{const r=Sr.safeParse(t);if(!r.success)return console.error(`${jr}: ${Tt(r.error).toString()}`),n.jsx(Je,{illustration:n.jsx(_e.illustration,{}),title:_e.title,supportingText:_e.description,className:"twp"});const{data:a}=r,s=["design","edit","preview"].includes(e.wcmmode),i=a.defaultLatitude!==void 0&&a.defaultLongitude!==void 0?{lat:a.defaultLatitude,lng:a.defaultLongitude}:void 0;return n.jsx("div",{className:"twp","data-component":"aeh-distributor-search",children:n.jsx(xt,{config:{brand:a.brand,perPage:a.perPage,autoLocate:a.autoLocate,syncURL:s?!1:a.syncURL,...a.apiEndpoint&&{apiEndpoint:a.apiEndpoint}},showMap:a.showMap,defaultCenter:i,defaultZoom:a.defaultZoom,popoverZIndexClassName:s?"z-[10000]":void 0})})},Jr=({pathModelHTLAttribute:e,componentModelHTLAttribute:t})=>n.jsx(Pt,{children:n.jsx(_t,{componentName:"aeh-distributor-search",children:n.jsx(Rt,{pathModelHTLAttribute:e,componentModelHTLAttribute:t,children:(r,a)=>n.jsx(Cr,{pathModel:r,componentModel:a})})})});export{Jr as AEHDistributorSearch};
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.