@magicx-eng/ai-autocomplete-vanilla 0.54.0 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Sn=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var uo=Object.getOwnPropertyNames;var po=Object.prototype.hasOwnProperty;var mo=(t,e)=>{for(var n in e)Sn(t,n,{get:e[n],enumerable:!0})},go=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of uo(e))!po.call(t,i)&&i!==n&&Sn(t,i,{get:()=>e[i],enumerable:!(r=co(e,i))||r.enumerable});return t};var fo=t=>go(Sn({},"__esModule",{value:!0}),t);var ha={};mo(ha,{AIAutocomplete:()=>fn,ATTRIBUTION_URL:()=>Bn,DATE_RANGE_META_END:()=>At,DATE_RANGE_META_START:()=>It,DEFAULT_OPTION_COUNT_UNIT:()=>Yn,ModeController:()=>Pe,OPTIONS_GRID_MOBILE_QUERY:()=>_e,OPTION_ENTER_DELAY_VAR:()=>Jt,OPTION_ENTER_FADE_MS:()=>Mi,OPTION_ENTER_RISE_MS:()=>Ri,OPTION_ENTER_RISE_PX:()=>Di,OPTION_ENTER_STAGGER_MS:()=>Li,OPTION_IMAGE_WIDTH:()=>Yt,PLACEHOLDER_FADE_OUT_MS:()=>oi,PLACEHOLDER_LEAVING_ATTR:()=>de,PLACEHOLDER_SWAP_GAP_MS:()=>si,PLACEHOLDER_TYPE_MS:()=>ri,PLACEHOLDER_WORD_PAUSE_MS:()=>ii,PRODUCT_IMAGE_WIDTH:()=>wi,PRODUCT_PATH_PREFIX:()=>kn,PRODUCT_ROW_PX_PER_LINE:()=>Pi,RANGE_SEPARATOR:()=>Rn,SCHEMA_VERSION:()=>xn,SCROLL_ARROW_ATTR:()=>er,SCROLL_ARROW_BOTTOM_VAR:()=>rr,SCROLL_ARROW_CLASS:()=>Zn,SCROLL_ARROW_FADE_MS:()=>tr,SCROLL_ARROW_LABEL:()=>$i,SCROLL_ARROW_SCROLL_IDLE_MS:()=>nr,SCROLL_ARROW_VISIBLE_ATTR:()=>ce,SKIPPED_PARAM_TEXT:()=>yn,SMART_SUGGESTION_SPARKLE_SVG:()=>Ze,VIEWPORT_FIT_ATTR:()=>ue,VIEWPORT_FIT_HEIGHT_VAR:()=>Ue,WEEKDAY_LABELS:()=>Oe,addMonths:()=>ot,attachProductRowWheel:()=>zt,attachScrollArrow:()=>rn,attachViewportFit:()=>on,buildAttributionUrl:()=>Ut,buildDateOptions:()=>st,buildQuery:()=>R,buildSubmitResult:()=>Y,cellDay:()=>lt,cellIso:()=>G,chipIdFromTap:()=>ht,computeOptionsGridLayout:()=>Nn,containScroll:()=>Gt,createStore:()=>un,cursorIsAtEnd:()=>St,dateCellMarks:()=>qt,dateSelectionFor:()=>xe,extractPlainText:()=>Me,formatAbsoluteDate:()=>se,formatDate:()=>Pn,formatDateRange:()=>Dn,formatOptionCount:()=>ve,getCursorOffset:()=>F,getFooterHint:()=>$t,hasSkippablePill:()=>et,highlightParts:()=>Nt,identifiedParamLabel:()=>U,isCalendarFormat:()=>T,isOptionsGridMobileViewport:()=>Rt,isSmartSuggestion:()=>Ie,isTraditionalAutocompleteSuggestion:()=>E,isoDate:()=>H,keepCaretOnChip:()=>bt,labelTraditionalAutocomplete:()=>Je,matchTypedPhrase:()=>He,measureOptionsGrid:()=>Mt,monthLabel:()=>it,needsOptionsGridMeasurement:()=>kt,optionCountLabel:()=>Hi,optionEnterDelayMs:()=>Zt,optionHasImage:()=>Qn,optionImageSources:()=>Be,optionImageSrc:()=>te,optionLabel:()=>We,optionsEntranceDurationMs:()=>en,optionsGridTemplateColumns:()=>Ot,optionsShowLeadingVisuals:()=>nn,parseDate:()=>ke,parseLooseDate:()=>be,parseLooseDateRange:()=>De,plainTextLength:()=>ft,planOptionsGrid:()=>Lt,previousGraphemeBoundary:()=>yt,productFromMatchedItem:()=>Ln,productImageSources:()=>Fe,productImageSrc:()=>Ci,productInitial:()=>jt,productPhotoFill:()=>Qt,productRowWheelTarget:()=>Gn,productsFromCustomFields:()=>Tt,renderEditableContent:()=>cn,resolveFormatType:()=>B,resolveIdentifiedDate:()=>Ct,sameOptionRows:()=>Dt,sanitizeOptionIconSvg:()=>ee,scrollCaretIntoView:()=>pt,selectedIsoFromText:()=>at,selectedRangeFor:()=>Se,setCursorOffset:()=>D,shopifyImageSrc:()=>Vn,toWireIdentifiedParams:()=>pe,typedFragment:()=>Fn,uiStringsFor:()=>k,visibleDateRange:()=>Vt,withSkippedParams:()=>me,withoutTraditionalAutocomplete:()=>Xe});module.exports=fo(ha);function T(t){return t==="date"||t==="date-range"}function B(t){return t?.type?.kind==="date"?"date":t?.type?.kind==="date_range"?"date-range":"options"}var $e=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var ho="https://api.ai-autocomplete.com",K=`${ho}/api/suggest`,Ge=new Map([["api.ai-autocomplete.com","cdn.ai-autocomplete.com"],["dev-api.ai-autocomplete.com","dev-cdn.ai-autocomplete.com"]]),ur=new WeakMap;function Te(t){return t?.type==="accessToken"}function bo(t){if(!(!t||Te(t)))return t}function Ve(t){let e=ur.get(t.getAccessToken);return e||(e=new $e(t),ur.set(t.getAccessToken,e)),e}function qe(t){return{"Content-Type":"application/json",...t?.appIdentifier&&{"X-App-Identifier":t.appIdentifier},...t?.headers}}function Ke(t){let e=bo(t),n=e?.apiKey;return n?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`:null}function pe(t){return t.map(e=>({parameter:e.parameter,text:e.text}))}var yn="skipped";function me(t,e){if(e.length===0)return t;let n=new Set(t.map(i=>i.parameter)),r=e.filter(i=>!n.has(i.parameter)).map(i=>({placeholder:"",parameter:i.parameter,text:yn,kind:null}));return r.length>0?[...t,...r]:t}var So="0.54.0",xn="1.0",pr=!1;function yo(t,e){return{placeholder:t.placeholder,parameter:t.parameter,...e&&{text:t.value??t.text},kind:t.kind}}function ie(t){return t??(typeof navigator<"u"?navigator.language:"en-US")}function xo(t,e,n,r,i,s,o,a,l,d,c,u,m){let p=e.find(h=>h.parameter==="contact"&&h.metadata?.contact_account_count)?.metadata?.contact_account_count,g=typeof p=="number"?p:void 0;return{data:{raw_query:t,accepts_traditional_autocomplete:!0,client_option_parameters:m??[],completed_params:me(e.map(h=>yo(h,n)),l??[]),...o&&o.length>0&&{identified_params:pe(o)},...a&&a.length>0&&{recently_suggested:a},...g!=null&&{contact_account_count:g},...d!==void 0&&{additional_context:d}},meta:{request_id:i,request_at:new Date().toISOString(),language:ie(c),...u?.code&&Number.isFinite(u.rate)&&u.rate>0&&{currency:u.code,currency_rate:u.rate,...u.country!==void 0&&{country:u.country}},client_version:So,session_id:r,source:s,schema_version:xn}}}async function mr(t,e,n,r,i){return fetch(t,{method:"POST",headers:{...e,Authorization:`Bearer ${n}`},body:r,signal:i})}async function gr(t,e,n){let r=n.apiConfig,i=!n.maskCompletedText,s=xo(t,e,i,n.sessionId,n.requestId??crypto.randomUUID(),n.source,n.identifiedParams,n.recentlySuggested,n.skippedParams,n.additionalContext,n.language,n.currency,n.clientOptionParameters),o=qe(r),a=r?.endpoint??K,l=JSON.stringify(s);if(Te(r)){let u=Ve(r),m=await u.getToken(),p=await mr(a,o,m,l,n.signal);if(p.status===401){let g=await u.getToken(!0);p=await mr(a,o,g,l,n.signal)}if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}let d=Ke(r);!d&&!pr&&(pr=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(o.Authorization=d);let c=await fetch(a,{method:"POST",headers:o,body:l,signal:n.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}var ze=/[\p{L}\p{N}]/u,vo=/['\u2019-]/;function fr(t,e,n){let r=t[e];if(r===void 0)return!1;if(ze.test(r))return!0;let i=t[e+n];return vo.test(r)&&i!==void 0&&ze.test(i)}function Po(t,e,n){let r=e+n.length;return!(ze.test(n[0])&&fr(t,e-1,-1)||ze.test(n[n.length-1])&&fr(t,r,1))}function V(t,e,n=0,r=()=>!0){if(e.length===0)return t.indexOf(e,n);let i=-1,s=t.indexOf(e,n);for(;s!==-1;){if(r(s)){if(Po(t,s,e))return s;i===-1&&(i=s)}s=t.indexOf(e,s+1)}return i}function R(t,e){let n=t,r={},i=[],s=[],o=0;for(let a of e){let l=(r[a.parameter]??0)+1;r[a.parameter]=l;let c=`{{${a.parameter.toUpperCase().replace(/\s+/g,"_")}_${l}}}`,u=p=>V(n,a.text,p,g=>!s.some(h=>g<h.end&&g+a.text.length>h.start)),m=u(o);if(m===-1&&(m=u(0)),m!==-1){n=n.slice(0,m)+c+n.slice(m+a.text.length);let p=c.length-a.text.length;for(let g of s)g.start>=m+a.text.length&&(g.start+=p,g.end+=p);s.push({start:m,end:m+c.length}),o=m>=o?m+c.length:o+p}i.push({...a,placeholder:c})}return{rawQuery:n,completedParams:i}}function z(t,e,n){return e>0||!n?e:t.toLowerCase().startsWith(n.toLowerCase())?n.length:e}function Ye(t,e,n){return e===0&&t.length>0&&n.length>0&&n.toLowerCase().startsWith(t.toLowerCase())}function Ee(t,e,n){let r=t.slice(e);if(n||e===0||t[e-1]===" ")return r;let i=r.indexOf(" ");return i===-1?"":r.slice(i+1)}function hr(t,e){let n=t.trimEnd().replace(/\s+/g," ");if(n.length===0||e.length===0)return 0;let r=n.split(" "),i=e.toLowerCase();for(let s=0;s<r.length;s++){let o=r.slice(s).join(" ");if(i.startsWith(o.toLowerCase())){let a=n.length-o.length;return t.length-a}}return 0}function br(t){return t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase().replace(/[_\-\s]+/g," ")}function To(t,e){let n=br(t).trim();return n.startsWith(e)||n.includes(` ${e}`)}function oe(t,e,n=!1){if(!t)return[];let r=e.trimStart();if(!r)return t;let i=n?br(r).trimStart():"";if(i)return t.filter(o=>!o.is_tappable||To(o.text,i));let s=r.toLowerCase();return t.filter(o=>!o.is_tappable||o.text.toLowerCase().includes(s))}function je(t,e){if(!t)return null;let n=e.trim();if(!n)return null;let r=n.toLowerCase();return t.find(i=>i.is_tappable&&i.text.toLowerCase()===r)??null}function we(t,e,n,r,i){let s=Ee(e,n,r),o=je(t,s);if(o||!i||!s.trim())return o;if(s===e.slice(n))return null;let a=e.lastIndexOf(" ",n-1)+1;return je(t,e.slice(a))}function Sr(t,e){return e?t.map(n=>e[n.parameter]?{...n,options:[]}:n):t}function Eo(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.toLowerCase())}function U(t){let e=Eo(t);return e.length>0?e.join(" "):t}function $(t,e){return t.parameter||e}function Ce(t){return{parameter:t,suggestionParameter:t,suggestionValueType:{kind:"traditional_autocomplete"},suggestionPlaceholder:U(t)}}function Qe(t,e){let n=$(e,t.suggestionParameter);return t.suggestionValueType?.kind==="traditional_autocomplete"?Ce(n):{parameter:n,suggestionParameter:t.suggestionParameter,suggestionValueType:t.suggestionValueType,suggestionPlaceholder:t.suggestionPlaceholder}}function E(t){return t?.type?.kind==="traditional_autocomplete"}function yr(t){let e=t?.replace(/[_\-\s]+/g," ").trim();return e?e.charAt(0).toUpperCase()+e.slice(1):void 0}function Ie(t){return E(t)||t?.smart_suggestion===!0}function Xe(t){return t.some(E)?t.filter(e=>!E(e)):t}function Je(t,e){return t.some(n=>E(n)&&!n.text)?t.map(n=>E(n)&&!n.text?{...n,text:e}:n):t}var Ze='<svg viewBox="0 0 20 20" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false"><path class="aia-sparkle-large" d="M8 5C8.5 9.5 10.5 11.5 15 12C10.5 12.5 8.5 14.5 8 19C7.5 14.5 5.5 12.5 1 12C5.5 11.5 7.5 9.5 8 5Z"/><path class="aia-sparkle-small" d="M16 1C16.2 3 17 3.8 19 4C17 4.2 16.2 5 16 7C15.8 5 15 4.2 13 4C15 3.8 15.8 3 16 1Z"/></svg>';function et(t){return t.some(e=>!E(e))}function xr(t,e){let n=0,r=e;for(let i of t)n+=i.value.length,i.type!=="text"&&(r=Math.max(r,n));return r}function vr(t,e){let n=0;for(let r of t){let i=n+r.value.length;if(r.type==="text"&&i>e&&r.value.slice(Math.max(e-n,0)).trim().length>0)return!1;n=i}return!0}function Pr(t,e){let n=[],r=new Set;for(let i of[...t,...e])i.parameter==="placeholder"||E(i)||r.has(i.parameter)||(r.add(i.parameter),n.push({parameter:i.parameter,text:i.text}));return n}function Tr(t,e,n){if(t===e)return n;let r=Math.min(t.length,e.length),i=0;for(;i<r&&t[i]===e[i];)i++;if(i>=n)return n;let s=0;for(;s<r-i&&t[t.length-1-s]===e[e.length-1-s];)s++;return t.length-s<=n?n+(e.length-t.length):null}function tt(t,e){let n=[],r=[],i=0;for(let s of e){let o=V(t,s.text,i);if(o===-1){r.push(s);continue}n.push({start:o,end:o+s.text.length,param:s}),i=o+s.text.length}return{located:n,missing:r}}function ge(t,e){let{located:n}=tt(t,e);return n.length>0?n[n.length-1].end:0}function Er(t,e,n){let r=[],i=[],s=0;for(let o of n){let a=V(t,o.text,s,l=>!e.some(d=>l<d.end&&l+o.text.length>d.start));if(a===-1){i.push(o);continue}r.push({start:a,end:a+o.text.length,param:o}),s=a+o.text.length}return{located:r,missing:i}}function wr(t,e,n=[]){let r=tt(t,e).located,i=Er(t,r,n).located,s=[...r.map(d=>({start:d.start,end:d.end,segment:{type:"completed",value:d.param.text,param:d.param}})),...i.map(d=>({start:d.start,end:d.end,segment:{type:"identified",value:d.param.text,param:d.param}}))].sort((d,c)=>d.start-c.start),o=[],a=0;for(let d of s)d.start>a&&o.push({type:"text",value:t.slice(a,d.start)}),o.push(d.segment),a=d.end;let l=t.slice(a);return l&&o.push({type:"text",value:l}),o}function Cr(t,e){let{located:n,missing:r}=tt(t,e);return{valid:n.map(i=>i.param),invalid:r}}function Ae(t,e,n){let r=tt(t,e).located,{located:i,missing:s}=Er(t,r,n);return{valid:i.map(o=>o.param),invalid:s}}function Ir(t,e,n){let r=e?.endpoint??K,i=r.replace(/\/suggest(?=[?#]|$)/,`/starting-state/${encodeURIComponent(t)}${wo(n)}`);if(i!==r)return i.replace(/^https:\/\/([^/?#]+)/,(s,o)=>{let a=Ge.get(o);return a?`https://${a}`:s})}function wo(t){let e=t?.replace(/_/g,"-").toLowerCase()??"",[n,r=""]=e.split("-");return n!=="zh"?/^[a-z]{2,3}$/.test(n)?`/${n}`:"":/^[a-z]{4}$/.test(r)?r==="hant"?"/zh-TW":"/zh":["tw","hk","mo"].includes(r)?"/zh-TW":"/zh"}async function Ar(t){try{let e=await t;if(!e.ok)return null;let n=await e.json();return Array.isArray(n?.data?.suggestions)?n:null}catch{return null}}function Co(t){if(t instanceof Error)return t;try{return new Error(String(t))}catch{return new Error("Unknown error")}}var Io=100,Ao=300,Oo=2,nt=class{constructor(e,n,r,i,s,o,a,l,d,c={}){this.store=e;this.getApiConfig=n;this.getOptionOverrides=r;this.getMaskCompletedText=i;this.getOnError=s;this.getSessionId=o;this.getSource=a;this.getAdditionalContext=l;this.getLanguage=d;this.callbacks=c;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null;this.phraseExactMatch=!1}start(){this.doFetch("",[]);let e=this.store.get().text,n=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(r=>{(r.text!==e||r.completedParams!==n)&&(e=r.text,n=r.completedParams,this.scheduleFetch())})}isPhraseExactMatch(){return this.phraseExactMatch}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,n){this.abortController?.abort();let r=new AbortController;this.abortController=r;let i=++this.fetchVersion,s=this.store.get().text.length;try{this.callbacks.onRequest?.({query:this.store.get().text,signal:r.signal,isCurrent:()=>i===this.fetchVersion})}catch{}try{this.store.set({isLoading:!0,error:null});let o=this.store.get(),a=o.pendingSpan?Pr(o.pendingSpan.snapshot,o.actionableSuggestions):void 0,l=crypto.randomUUID(),d=e===""&&n.length===0&&o.skippedParams.length===0&&o.identifiedParams.length===0?this.startingStateUrl():void 0,c=d?await Ar(fetch(d,{signal:r.signal})):null;if(i!==this.fetchVersion)return;let u=c??await gr(e,n,{sessionId:this.getSessionId(),requestId:l,source:this.getSource(),maskCompletedText:this.getMaskCompletedText(),signal:r.signal,apiConfig:this.getApiConfig(),identifiedParams:o.identifiedParams,recentlySuggested:a,skippedParams:o.skippedParams,additionalContext:this.getAdditionalContext(),language:this.getLanguage(),currency:this.callbacks.getCurrency?.(),clientOptionParameters:Object.keys(this.getOptionOverrides()??{})});if(i!==this.fetchVersion)return;this.phraseExactMatch=u.meta?.phrase_exact_match===!0;let m=(u.data.suggestions??[]).find(E),p=m?[]:u.data.input??[],g=p.filter(P=>P.source==="identified").map(P=>({id:crypto.randomUUID(),parameter:P.parameter,text:P.text,...P.type?{type:P.type}:{}})),h=this.callbacks.isWordOpen?.()??!1,y=this.store.get().text.toLowerCase(),b=P=>h&&y.endsWith(P.text.toLowerCase()),f=g.filter(P=>!b(P));h&&this.callbacks.holdIdentified?.(g.filter(b));let S=m?[m]:Sr(u.data.suggestions??[],this.getOptionOverrides()),x=p,I=x[x.length-1],v=this.store.get().text,w,M;if(I?.state==="in_progress"){M=!0;let P=v.toLowerCase().lastIndexOf(I.text.toLowerCase());w=P!==-1?P:s}else M=!1,w=s;let O=S.filter(P=>P.parameter!=="placeholder")[0],L=null;if(O&&!E(O)&&!h&&!T(B(O))){let P=we(O.options,v,w,M,this.phraseExactMatch);P&&(L={id:crypto.randomUUID(),placeholder:"",parameter:$(P,O.parameter),text:P.text,value:P.value,kind:P.kind,suggestionParameter:O.parameter,suggestionValueType:O.type,suggestionPlaceholder:O.text,options:O.options??[],metadata:P.metadata,icon:P.icon,icon_svg:P.icon_svg,image_url:P.image_url},S=S.filter(W=>W!==O),this.callbacks.onAutoMatch?.({active:O,matched:P,rawQuery:e}))}let q=u.data.custom_fields??null,ne=this.callbacks.productsForResponse?.(q);this.store.set(P=>{let W=L?[...P.completedParams,L]:P.completedParams,hn=Ae(P.text,W,f).valid,bn=new Set(o.skippedParams.map(_=>_.id)),C=new Set(P.skippedParams.filter(_=>!bn.has(_.id)).map(_=>_.parameter));return{suggestions:C.size>0?S.filter(_=>_.parameter==="placeholder"||!C.has(_.parameter)):S,isLoading:!1,isReady:u.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:w,filterInProgress:M,identifiedParams:hn,customFields:q,traditionalAutocomplete:u.meta?.traditional_autocomplete===!0,...ne!==void 0?{products:ne}:{},...L?{completedParams:W}:{}}}),this.callbacks.onResponse?.({requestId:l,funnelTelemetry:u.meta?.funnel_telemetry===!0,visibleImpression:u.meta?.visible_impression===!0})}catch(o){let a=Co(o);i===this.fetchVersion&&(this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a))}finally{if(i===this.fetchVersion&&this.store.get().isLoading)try{this.store.set({isLoading:!1})}catch{}}}startingStateUrl(){let e=this.callbacks.getProductId?.();return e?Ir(e,this.getApiConfig(),ie(this.getLanguage())):void 0}attemptNow(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.attemptFetch(1,!0)}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.debounceTimer=setTimeout(()=>{this.attemptFetch(Oo)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},Io),this.slowDebounceTimer=setTimeout(()=>this.attemptFetch(1,!0,!0),Ao)}attemptFetch(e,n=!1,r=!1){let i=this.store.get();if(!i.text&&i.completedParams.length===0)return this.doFetch("",[]),!0;let s=this.callbacks.consumerTick?.(i,e)??"no";if(s==="asked")return!0;if(s==="owns")return!1;let o=i.suggestions.filter(v=>v.parameter==="placeholder").map(v=>v.text).join(" "),a=z(i.text,i.filterBase,o),l=Ee(i.text,a,i.filterInProgress),d=i.suggestions.filter(v=>v.parameter!=="placeholder"),c=E(d[0])?void 0:d[0],u=T(i.activeFormatType),p=(c&&!u?oe(c.options,l,i.traditionalAutocomplete):[]).filter(v=>v.is_tappable),g=c&&!u&&!this.callbacks.isWordOpen?.()?we(c.options,i.text,a,i.filterInProgress,this.phraseExactMatch)!==null:!1,h=l.trim().length>0,y=r&&i.products.length>0;if(p.length>0&&!g&&h&&!y||Ye(i.text,i.completedParams.length,o))return!1;let{rawQuery:b,completedParams:f}=R(i.text,i.completedParams),S=b.length<i.lastRawQuery.length,x=Math.abs(b.length-i.lastRawQuery.length),I=n&&b!==i.lastRawQuery;return S||x>=e||I?(this.doFetch(b,f),!0):!1}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ko="(hover: none) and (pointer: coarse)";var Lo="[data-aia-dropdown], [data-aia-input-wrapper]",Mo=["a[href]","button","input","select","textarea","label","summary","[contenteditable]:not([contenteditable='false'])","[role='button']","[role='link']","[tabindex]:not([tabindex='-1'])"].join(", "),rt=class{constructor(e,n){this.store=e;this.container=n;this.listening=!1;this.declined=!1;this.pressOutside=!1;this.pressWhileFocused=!1;this.recheckTimer=null;this.releaseTimer=null;this.onPointerDown=e=>{let n=e.composedPath(),r=this.isInside(n);this.pressOutside=!r;let i=this.store.get();this.pressWhileFocused=i.isFocused,!(r||!i.isFocused)&&(this.declined=n.some(s=>s instanceof Element&&s.matches(Mo)),this.declined&&i.dropdownHeld?this.store.set({dropdownHeld:!1}):!this.declined&&!i.dropdownHeld&&i.isDropdownOpen&&this.store.set({dropdownHeld:!0}))};this.onPointerCancel=()=>{this.pressOutside=!1,this.pressWhileFocused&&this.declined&&this.scheduleRecheck(),this.pressWhileFocused=!1};this.onPointerUp=e=>{let n=this.pressOutside&&!this.isInside(e.composedPath()),r=this.pressWhileFocused;if(this.pressOutside=!1,this.pressWhileFocused=!1,r){this.declined&&this.scheduleRecheck();return}!n||this.store.get().isFocused||(this.cancelRelease(),this.releaseTimer=setTimeout(()=>{this.releaseTimer=null;let i=this.store.get();i.dropdownHeld&&!i.isFocused&&this.store.set({dropdownHeld:!1})},150))};this.touchPrimary=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(ko):null,this.unsubscribe=e.subscribe(()=>this.sync())}dispose(){this.unsubscribe(),this.listen(!1),this.cancelRelease(),this.recheckTimer!==null&&clearTimeout(this.recheckTimer),this.recheckTimer=null}sync(){let e=this.store.get(),n=this.touchPrimary?.matches??!1;e.isFocused||(this.declined=!1),e.isDropdownOpen?e.isFocused&&!e.dropdownHeld&&!this.declined&&n&&this.store.set({dropdownHeld:!0}):e.dropdownHeld&&this.store.set({dropdownHeld:!1});let r=this.store.get();this.listen(n&&r.isDropdownOpen),r.isFocused&&this.cancelRelease()}listen(e){if(!(e===this.listening||typeof document>"u")){if(this.listening=e,e){document.addEventListener("pointerdown",this.onPointerDown,!0),document.addEventListener("pointerup",this.onPointerUp,!0),document.addEventListener("pointercancel",this.onPointerCancel,!0);return}document.removeEventListener("pointerdown",this.onPointerDown,!0),document.removeEventListener("pointerup",this.onPointerUp,!0),document.removeEventListener("pointercancel",this.onPointerCancel,!0),this.pressOutside=!1}}scheduleRecheck(){this.recheckTimer!==null&&clearTimeout(this.recheckTimer),this.recheckTimer=setTimeout(()=>{this.recheckTimer=null,!(!this.declined||!this.store.get().isFocused)&&(this.declined=!1,this.sync())},150)}cancelRelease(){this.releaseTimer!==null&&(clearTimeout(this.releaseTimer),this.releaseTimer=null)}isInside(e){let n=this.container,r=n?.getRootNode(),i=typeof ShadowRoot<"u"&&r instanceof ShadowRoot?r.host:null;for(let s of e)if(s===n||s===i||s instanceof Element&&s.matches(Lo))return!0;return!1}};var fe=["January","February","March","April","May","June","July","August","September","October","November","December"],Oe=["S","M","T","W","T","F","S"],Lr=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Mr="aiaDate",Rr="aiaDay",Or=t=>String(t).padStart(2,"0");function H(t){return`${t.getFullYear()}-${Or(t.getMonth()+1)}-${Or(t.getDate())}`}function vn(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}function Ro(t){let e=vn(t).getTime()-vn(new Date).getTime();return Math.round(e/864e5)}function Pn(t){let e=Ro(t);return e>=0&&e<7?Lr[t.getDay()]:se(t)}function se(t){return t.getFullYear()===new Date().getFullYear()?`${fe[t.getMonth()]} ${t.getDate()}`:`${fe[t.getMonth()]} ${t.getDate()} ${t.getFullYear()}`}function ke(t){if(!t)return null;let e=Lr.findIndex(a=>a.toLowerCase()===t.trim().toLowerCase());if(e>=0){let a=vn(new Date),l=(e-a.getDay()+7)%7;return new Date(a.getFullYear(),a.getMonth(),a.getDate()+l)}let n=/^\s*([A-Za-z]+)\s+(\d{1,2})(?:\s+(\d{4}))?\s*$/.exec(t);if(!n)return null;let r=fe.findIndex(a=>a.toLowerCase()===n[1].toLowerCase());if(r<0)return null;let i=Number(n[2]),s=n[3]?Number(n[3]):new Date().getFullYear(),o=new Date(s,r,i);return o.getMonth()!==r||o.getDate()!==i?null:o}function it(t){return`${fe[t.month]} ${t.year}`}function Tn(){let t=new Date;return{year:t.getFullYear(),month:t.getMonth()}}function Dr(t){return{year:t.getFullYear(),month:t.getMonth()}}function ot(t,e){let n=new Date(t.year,t.month+e,1);return{year:n.getFullYear(),month:n.getMonth()}}function kr(){return{text:"",is_tappable:!1,kind:null}}function st(t){let e=new Date(t.year,t.month,1).getDay(),n=new Date(t.year,t.month+1,0).getDate(),r=[];for(let i=0;i<e;i++)r.push(kr());for(let i=1;i<=n;i++){let s=new Date(t.year,t.month,i);r.push({text:Pn(s),is_tappable:!0,kind:null,metadata:{[Mr]:H(s),[Rr]:i}})}for(;r.length%Oe.length!==0;)r.push(kr());return r}function at(t){let e=ke(t);return e?H(e):null}function G(t){let e=t?.metadata?.[Mr];return typeof e=="string"?e:null}function lt(t){let e=t?.metadata?.[Rr];return typeof e=="number"?e:null}function Do(t){return t.nodeType===Node.DOCUMENT_NODE?!0:t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in t}function ae(t){let e=typeof t.getRootNode=="function"?t.getRootNode():null;return e&&Do(e)?e:t.ownerDocument??t}function N(t){return t.ownerDocument??t}function _o(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function _r(t){let e=ae(t);return!_o(e)||typeof e.getSelection=="function"?null:e}function Nr(t){let e=_r(t);if(!e)return null;let n=N(t).getSelection?.();return!n||typeof n.getComposedRanges!="function"?null:e}function Hr(t,e){let n=t,r;try{r=n.getComposedRanges({shadowRoots:[e]})}catch{r=n.getComposedRanges(e)}return r.length>0?r[0]:null}function En(t){let n=ae(t).getSelection?.();return n||(N(t).getSelection?.()??null)}function j(t){let e=En(t);if(!e||e.rangeCount===0)return null;let n=Nr(t);if(n){let r=Hr(e,n);return r?{node:r.startContainer,offset:r.startOffset,collapsed:r.startContainer===r.endContainer&&r.startOffset===r.endOffset}:null}return e.anchorNode?{node:e.anchorNode,offset:e.anchorOffset,collapsed:e.isCollapsed}:null}function dt(t){let e=En(t);if(!e||e.rangeCount===0)return null;let n=Nr(t);if(!n)return e.getRangeAt(0);let r=Hr(e,n);if(!r)return null;let i=N(t).createRange();return i.setStart(r.startContainer,r.startOffset),i.setEnd(r.endContainer,r.endOffset),i}function Le(t,e,n){let r=En(t);if(!r)return null;if(_r(t))return r.collapse(e,n),r;let i=N(t).createRange();return i.setStart(e,n),i.collapse(!0),r.removeAllRanges(),r.addRange(i),r}function ct(t,e){let n=t?ae(t):typeof document<"u"?document:null;return n?typeof n.getElementById=="function"?n.getElementById(e):typeof document<"u"?document.getElementById(e):null:null}var ut=2,No="magicx-aia";function Fr(t){return t==="auto"||t==="scroll"||t==="hidden"||t==="overlay"}function Ho(t){let e=N(t),n=e.defaultView;if(!n?.getComputedStyle)return null;let r=t;for(;r&&r!==e.body&&r!==e.documentElement;){let i=r.scrollWidth>r.clientWidth,s=r.scrollHeight>r.clientHeight;if(i||s){let o=n.getComputedStyle(r);if(i&&Fr(o.overflowX)||s&&Fr(o.overflowY))return r}if(r.classList.contains(No))return null;r=r.parentElement}return null}function pt(t){let e=dt(t);if(!e||!e.collapsed||!t.contains(e.startContainer))return;let n=Ho(t);if(!n||typeof e.getBoundingClientRect!="function")return;let r=e.getBoundingClientRect();if(r.height===0)return;let i=n.getBoundingClientRect();if(n.scrollWidth>n.clientWidth){let s=i.left+n.clientLeft,o=s+n.clientWidth;r.right>o?n.scrollLeft+=r.right-o+ut:r.left<s&&(n.scrollLeft-=s-r.left+ut)}if(n.scrollHeight>n.clientHeight){let s=i.top+n.clientTop,o=s+n.clientHeight;r.bottom>o?n.scrollTop+=r.bottom-o+ut:r.top<s&&(n.scrollTop-=s-r.top+ut)}}var Br='[contenteditable="false"]',Cn="strong[data-param-id]",he;function Fo(){if(he!==void 0)return he;let t=globalThis.Intl.Segmenter;if(!t)return he=null,null;try{he=new t(void 0,{granularity:"grapheme"})}catch{he=null}return he??null}function mt(t,e){let n=t;for(;n&&n!==e;){if(n.nodeType===Node.ELEMENT_NODE&&n.matches(Br))return!0;n=n.parentNode}return!1}function gt(t){return N(t).createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(e){return mt(e,t)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function Me(t){let e=gt(t),n="",r=e.nextNode();for(;r;)n+=r.data,r=e.nextNode();return n}function ft(t){let e=gt(t),n=0,r=e.nextNode();for(;r;)n+=r.data.length,r=e.nextNode();return n}function F(t){let e=j(t);if(!e)return null;let n=e.node,r=e.offset;if(!t.contains(n))return null;if(n.nodeType===Node.ELEMENT_NODE){let i=n;if(mt(i,t)&&i!==t)return null;let s=0;for(let o=0;o<r&&o<i.childNodes.length;o++)s+=In(i.childNodes[o],t);return s+wn(i,t)}return n.nodeType!==Node.TEXT_NODE||mt(n,t)?null:wn(n,t)+r}function In(t,e){if(t.nodeType===Node.TEXT_NODE)return mt(t,e)?0:t.data.length;if(t.nodeType!==Node.ELEMENT_NODE)return 0;let n=t;if(n.matches(Br))return 0;let r=0;for(let i of Array.from(n.childNodes))r+=In(i,e);return r}function wn(t,e){let n=gt(e),r=0,i=n.nextNode();for(;i;){if(i===t||t.nodeType===Node.ELEMENT_NODE&&t.contains(i))return r;r+=i.data.length,i=n.nextNode()}return r}function D(t,e){let n=N(t),r=Math.max(0,Math.min(e,ft(t))),i=gt(t),s=0,o=null,a=0,l=i.nextNode(),d=null;for(;l;){let u=l.data.length;if(r<s+u){o=l,a=r-s;break}if(r===s+u){let m=i.nextNode();m?(o=m,a=0):(o=l,a=u);break}s+=u,d=l,l=i.nextNode()}let c=n.createRange();if(o){let u=o.parentElement?.closest('strong[data-seg="completed"]');u&&u!==t&&t.contains(u)?a===0?c.setStartBefore(u):a===o.data.length?c.setStartAfter(u):c.setStart(o,a):c.setStart(o,a)}else d?c.setStart(d,d.data.length):c.setStart(t,0);c.collapse(!0),Le(t,c.startContainer,c.startOffset)&&(Wo(t,c,r),pt(t))}function Wr(t,e){if(!t||!e.contains(t))return null;let r=(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(Cn)??null;return r&&e.contains(r)?r:null}function Wo(t,e,n){let r=Wr(j(t)?.node??null,t);if(r&&r!==Wr(e.startContainer,t)){t.dataset.aiaCaretEscapedChip=`${n}:${r.dataset.paramId}`;return}delete t.dataset.aiaCaretEscapedChip}function Ur(t,e){let n=t.dataset.aiaCaretEscapedChip;if(!n)return!1;let r=F(t);return r!==null&&n===`${r}:${e}`}function $r(t){return ae(t).activeElement===t}function ht(t,e){if(!e||e.nodeType===void 0)return null;let n=e,i=(n.nodeType===Node.ELEMENT_NODE?n:n.parentElement)?.closest(Cn);if(!i||!t.contains(i))return null;let s=j(t);return s&&!s.collapsed?null:i.dataset.paramId??null}function bt(t,e){let n=null;for(let o of t.querySelectorAll(Cn))if(o.dataset.paramId===e){n=o;break}if(!n)return;let r=wn(n,t),i=r+In(n,t),s=F(t);s!=null&&s>=r&&s<=i||D(t,r)}function St(t){let e=F(t);return e==null?!1:e>=ft(t)}function yt(t,e){if(e<=0)return 0;let n=Fo();if(!n)return e-1;let r=t.slice(0,e),i=0;for(let{index:s}of n.segment(r))s<e&&(i=s);return i}function Y(t,e,n=[],r={}){let{rawQuery:i,completedParams:s}=R(t,e);return{query:t.trim(),raw_query:i,completed_params:me(s,n),identified_params:pe(r.identifiedParams??[]),is_ready:r.isReady??!1,...r.customFields?{custom_fields:r.customFields}:{}}}function An(t,e){return t instanceof HTMLTextAreaElement||t instanceof HTMLInputElement?t.selectionStart!=null&&t.selectionStart===t.value.length:t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?St(t):e?.caretOffset!=null?e.caretOffset>=e.text.length:!1}function On(t){return t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?F(t):null}var xt=class{constructor(e,n){this.store=e;this.ctx=n}handleKeyDown(e){if(e.isComposing||e.keyCode===229)return;let n=this.store.get(),{listboxId:r,getOnSubmit:i}=this.ctx,s=e.target instanceof Node?e.target:null,o=this.getEffectiveColumns(s),a=i(),l=this.getTappableIndices(o);if((e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)&&(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return;let d=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let c=An(e.target,n),u=!!n.editingParam;if(!c&&!u&&n.activeDropdownIndex<0)break;if(n.activeDropdownIndex<0){if(d)break;e.preventDefault();let g=T(n.activeFormatType)?this.dateEntryIndex(n,!1):l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:g});break}if(l.length===0)return;this.store.set({activeDropdownIndex:g});break}if(e.preventDefault(),l.length===0)return;if(T(n.activeFormatType)){this.stepDateWeek(n,7);break}if(n.filteredOptions.length>0){let g=Math.floor((n.filteredOptions.length-1)/o);if(Math.floor(n.activeDropdownIndex/o)===g){this.store.set({activeDropdownIndex:-1});break}}let m=l.indexOf(n.activeDropdownIndex),p=m<l.length-1?m+1:0;this.store.set({activeDropdownIndex:l[p]});break}case"ArrowUp":{if(n.activeDropdownIndex<0){if(!d)break;let m=An(e.target,n),p=!!n.editingParam;if(!m&&!p)break;e.preventDefault();let g=T(n.activeFormatType)?this.dateEntryIndex(n,!0):this.firstTappableInBottomRow(o)??l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:g});break}if(l.length===0)return;this.store.set({activeDropdownIndex:g});break}if(l.length===0)break;if(e.preventDefault(),T(n.activeFormatType)){this.stepDateWeek(n,-7);break}if(n.activeDropdownIndex<o){this.store.set({activeDropdownIndex:-1});break}let c=l.indexOf(n.activeDropdownIndex),u=c>0?c-1:l.length-1;this.store.set({activeDropdownIndex:l[u]});break}case"ArrowRight":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),T(n.activeFormatType)){this.stepDateDay(n,1);break}if(n.activeDropdownIndex%o<o-1){let m=n.activeDropdownIndex+1;m<n.filteredOptions.length&&n.filteredOptions[m]?.is_tappable&&this.store.set({activeDropdownIndex:m})}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){e.preventDefault();let u=e.target.closest("[data-aia-input]")??e.target,m=n.editingTail;this.ctx.exitEditMode?.(),D(u,m);break}An(e.target,n)&&n.actionableSuggestions.length>=1&&(e.preventDefault(),this.ctx.skipActivePill());break}case"ArrowLeft":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),T(n.activeFormatType)){this.stepDateDay(n,-1);break}if(n.activeDropdownIndex%o>0){let c=n.activeDropdownIndex-1;c>=0&&n.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c});break}if(!n.editingParam&&this.ctx.startEditingParamAtCaret){let c=On(e.target);c!=null&&this.ctx.startEditingParamAtCaret(c)}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingAnchor!=null){e.preventDefault();let c=e.target.closest("[data-aia-input]")??e.target,u=n.editingAnchor;this.ctx.exitEditMode?.(),D(c,u);break}if(this.ctx.startEditingParamAtCaret){let c=On(e.target);c!=null&&this.ctx.startEditingParamAtCaret(c)&&e.preventDefault()}break}case"Backspace":{if(n.editingParam||!this.ctx.removeParamAtCaret)break;let c=On(e.target);if(c==null)break;this.ctx.removeParamAtCaret(c)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),n.activeDropdownIndex>=0&&n.filteredOptions[n.activeDropdownIndex]?.is_tappable)this.clickOrSelect(n.activeDropdownIndex,n.filteredOptions,r,s);else if(a){this.ctx.endTypedWord?.(!0);let c=this.store.get();a(Y(c.text,c.completedParams,c.skippedParams,{identifiedParams:c.identifiedParams,isReady:c.isReady,customFields:c.customFields}))&&this.ctx.afterSubmit?.()}break}case"Tab":{if(this.ctx.endTypedWord?.()){e.preventDefault();break}let c=n.filteredOptions.map((p,g)=>p.is_tappable?g:-1).filter(p=>p!==-1);if(c.length===0)break;if(!n.isDropdownOpen){if(n.actionableSuggestions.length===0)break;e.preventDefault();let p=e.shiftKey?c[c.length-1]:c[0];this.store.set({pillTapped:!0,activeDropdownIndex:p});break}e.preventDefault();let u=c.indexOf(n.activeDropdownIndex),m;if(u<0)m=e.shiftKey?c.length-1:0;else{let p=e.shiftKey?-1:1;m=(u+p+c.length)%c.length}this.store.set({activeDropdownIndex:c[m]});break}case"Escape":{if(n.dateRangeStart){this.store.set({pendingRangeStart:null});break}if(n.editingIdentified){this.ctx.exitEditingIdentified?.(),this.store.set({activeDropdownIndex:-1});break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){let c=e.target.closest("[data-aia-input]")??e.target,u=n.editingTail;this.ctx.exitEditMode?.(),D(c,u)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let n=this.store.get();if(n.filteredOptions.length===0)return null;let i=Math.floor((n.filteredOptions.length-1)/e)*e;for(let s=i;s<n.filteredOptions.length;s++)if(n.filteredOptions[s]?.is_tappable)return s;return null}dateEntryIndex(e,n){let r=H(new Date),i=e.filteredOptions.findIndex(o=>G(o)===r);if(i>=0)return i;let s=e.filteredOptions.map((o,a)=>o.is_tappable?a:-1).filter(o=>o!==-1);return(n?s[s.length-1]:s[0])??0}stepDateDay(e,n){for(let r=e.activeDropdownIndex+n;r>=0&&r<e.filteredOptions.length;r+=n)if(e.filteredOptions[r]?.is_tappable){this.store.set({activeDropdownIndex:r});return}}stepDateWeek(e,n){let r=e.activeDropdownIndex+n;this.store.set({activeDropdownIndex:e.filteredOptions[r]?.is_tappable?r:-1})}getTappableIndices(e){let r=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),i=Array.from({length:e},()=>[]);for(let s of r)i[s%e].push(s);return i.flat()}getEffectiveColumns(e){let n=ct(e,this.ctx.listboxId);if(!n)return this.ctx.columns;let i=ct(e,`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let s=getComputedStyle(i).gridTemplateColumns;if(s&&s!=="none"){let o=s.split(" ").filter(Boolean).length;if(o>0)return o}if(i===n)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,n,r,i){let s=ct(i,`${r}-option-${e}`);s?s.click():this.ctx.selectOption(n[e])}};var vt=class{constructor(e,n,r={}){this.store=e;this.getOverrides=n;this.callbacks=r;this.unsubscribe=null;this.current=null;this.version=0;this.lastMiss=null;this.hasLoggedError=!1}start(){this.unsubscribe=this.store.subscribe(e=>this.sync(e)),this.sync(this.store.get())}dispose(){this.unsubscribe?.(),this.unsubscribe=null,this.cancel(),this.current=null}reset(){this.cancel(),this.current=null,this.lastMiss=null}refresh(){this.reset(),this.sync(this.store.get())}hasOverride(e){return!!this.getOverrides()?.[e]}owns(e,n){return this.hasOverride(e)&&!this.missCovers(e,n)}tick(e,n){let r=this.resolveTarget(e);if(!r||this.missCovers(r.parameter,r.query))return"no";let i=this.current;if(i&&i.key===r.key){if(i.query===r.query)return"owns";let s=Math.abs(r.query.length-i.query.length),o=r.query.length<i.query.length;if(n>1&&!o&&s<n)return"owns"}return this.ask(r),"asked"}sync(e){let n=this.resolveTarget(e);if(!n){this.current&&(this.cancel(),this.current=null),e.optionSearch&&this.store.set({optionSearch:null});return}this.current&&this.current.key===n.key||this.ask(n)}resolveTarget(e){if(T(e.activeFormatType)||e.editingIdentified)return null;let n=e.editingParam;if(n&&e.editingAnchor!=null)return this.hasOverride(n.suggestionParameter)?{mode:"edit",key:n.id,parameter:n.suggestionParameter,suggestion:{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options},query:e.optionQuery}:null;let r=e.actionableSuggestions[0];return!r||!this.hasOverride(r.parameter)?null:{mode:"pill",key:r,parameter:r.parameter,suggestion:r,query:e.optionQuery}}missCovers(e,n){return this.lastMiss!=null&&this.lastMiss.parameter===e&&this.lastMiss.query===n}ask(e){this.cancel();let n=this.getOverrides()?.[e.parameter],r=++this.version;if(!n||this.missCovers(e.parameter,e.query)){this.current={key:e.key,parameter:e.parameter,query:e.query,abort:null},this.setSearch(e,"done");return}let i=new AbortController;this.current={key:e.key,parameter:e.parameter,query:e.query,abort:i};let s;try{s=n(e.query,i.signal,e.suggestion)}catch(o){this.logOnce(o),this.commit(e,[],r);return}if(Array.isArray(s)){this.commit(e,s,r);return}this.setSearch(e,"loading"),this.await(e,s,i.signal,r)}async await(e,n,r,i){let s;try{let o=await n;if(r.aborted||i!==this.version)return;s=Array.isArray(o)?o:[]}catch(o){if(r.aborted||i!==this.version||Bo(o))return;this.logOnce(o),s=[]}this.commit(e,s,i)}commit(e,n,r){if(r!==this.version)return;let i=this.resolveTarget(this.store.get());if(!i||i.key!==e.key)return;n.length===0?this.lastMiss={parameter:e.parameter,query:e.query}:this.lastMiss?.parameter===e.parameter&&(this.lastMiss=null);let s={parameter:e.parameter,query:e.query,status:"done"};if(e.mode==="edit")this.store.set(o=>({editingParam:o.editingParam&&o.editingParam.id===e.key?{...o.editingParam,options:n}:o.editingParam,optionSearch:s}));else{let o={...e.suggestion,options:n};this.current&&this.current.key===e.key&&(this.current.key=o),this.store.set(a=>({suggestions:a.suggestions.map(l=>l===e.suggestion?o:l),optionSearch:s}))}n.length===0?this.callbacks.onMiss?.(e.mode,e.query):this.callbacks.onAnswer?.(e.mode,e.query)}setSearch(e,n){let r=this.store.get().optionSearch;r&&r.parameter===e.parameter&&r.query===e.query&&r.status===n||this.store.set({optionSearch:{parameter:e.parameter,query:e.query,status:n}})}cancel(){this.current?.abort?.abort(),this.version++}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] an optionOverrides entry threw or rejected \u2014 treated as no options. Later failures on this instance are not logged.",e))}};function Bo(t){return t instanceof Error&&t.name==="AbortError"}var Pt=class{constructor(e,n={}){this.store=e;this.callbacks=n}setActivePill(e){let n=this.store.get(),r=n.suggestions.filter(d=>d.parameter!=="placeholder");if(e<0||e>=r.length)return;let i=r[e];if(E(i))return;let s=r.filter((d,c)=>c!==e),o=n.suggestions.filter(d=>d.parameter==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:d}=R(n.text,n.completedParams);this.callbacks.onPillSelected({rawQuery:d,selectedPill:i.text,otherPills:s.map(c=>c.text)})}let a=[...o,i,...s],l=this.store.peek({suggestions:a}).filteredOptions.findIndex(d=>d.is_tappable);this.store.set({suggestions:a,pillTapped:!0,activeDropdownIndex:l})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(n=>({completedParams:n.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};var kn="/products/",Gr="https://relative.invalid";function Uo(t){if(!t)return;let e;try{e=new URL(t,`${Gr}/`)}catch{return}if(!(e.protocol!=="http:"&&e.protocol!=="https:"))return t.startsWith("/")?e.origin===Gr?t:void 0:/^https?:\/\//i.test(t)?t:void 0}function Ln(t,e){let n=Uo(t.item_url)??Go(t);return{id:t.source_id,title:t.title,...n&&{url:n},imageUrl:t.image_url||null,...t.price&&{price:$o(t.price,t.currency,e)},...t.vendor&&{vendor:t.vendor},...typeof t.available=="boolean"&&{available:t.available}}}function $o(t,e,n){if(n===void 0||!e||!/^\d+(\.\d+)?$/.test(t))return t;try{return new Intl.NumberFormat(n,{style:"currency",currency:e}).format(Number(t))}catch{return t}}function Go(t){if(!t.handle)return;let e=`${kn}${encodeURIComponent(t.handle)}`;return t.variant_id?`${e}?variant=${encodeURIComponent(t.variant_id)}`:e}function Tt(t,e){return(t?.items.matched??[]).map(n=>Ln(n,e))}var Et=class{constructor(e,n,r=()=>!0,i=()=>{},s=()=>{}){this.store=e;this.getConfig=n;this.isEnabled=r;this.getLanguage=i;this.getMapper=s;this.hasLoggedError=!1;this.hasLoggedMapperError=!1}forResponse(e){if(!this.isEnabled())return[];if(this.getConfig())return;let n=Tt(e,ie(this.getLanguage())),r=this.getMapper();if(!r)return n;try{let i=r(n,e?.items.matched??[]);if(Array.isArray(i))return i}catch(i){this.hasLoggedMapperError||(this.hasLoggedMapperError=!0,console.warn("[AIAutocomplete] mapProducts failed. The original cards are shown.",i))}return n}async run(e,n,r){if(!this.isEnabled())return;let i=this.getConfig();if(!i)return;if(e.trim().length===0){this.clear(r);return}let s=()=>n.aborted||!r()||!this.owns(i);try{let o=await i.fetch(e,n);if(s())return;let a=i.transform(o),l=Array.isArray(a)?a:[],d=i.limit!=null?l.slice(0,i.limit):l;if(s())return;this.commit(d)}catch(o){if(n.aborted||Vo(o)||(this.logOnce(o),s()))return;this.clear(r)}}owns(e){return this.isEnabled()&&this.getConfig()===e}resync(){let e=this.forResponse(this.store.get().customFields);this.commit(e??[])}refresh(){if(this.getConfig())return;let e=this.forResponse(this.store.get().customFields);e!==void 0&&this.commit(e)}clear(e){e()&&this.commit([])}commit(e){e.length===0&&this.store.get().products.length===0||this.store.set({products:e})}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] products.fetch/transform failed \u2014 the product strip is hidden. Later failures on this instance are not logged.",e))}};function Vo(t){return t instanceof Error&&t.name==="AbortError"}function qo(t){return t.replace(/(\d+)(?:st|nd|rd|th)\b/g,"$1")}function Vr(t){let e=t.toLowerCase().replace(/\.$/,"");return e.length<3?-1:fe.findIndex(n=>n.toLowerCase().startsWith(e))}function Ko(t,e,n){let r=new Date(n.getFullYear(),t,e);if(r.getMonth()!==t||r.getDate()!==e)return null;let i=new Date(n.getFullYear(),n.getMonth(),n.getDate());if(r>=i)return r;let s=new Date(n.getFullYear()+1,t,e);return s.getMonth()===t&&s.getDate()===e?s:null}function qr(t,e,n){let r=new Date(t,e,n);return r.getMonth()===e&&r.getDate()===n?r:null}function be(t,e={}){if(!t)return null;let n=e.today??new Date,r=qo(t.trim().toLowerCase()).replace(/\s+/g," "),i=/^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(r);if(i){let l=qr(Number(i[1]),Number(i[2])-1,Number(i[3]));return l?H(l):null}let s=/^([a-z]+)\.? (\d{1,2})(?:,? (\d{4}))?$/.exec(r);if(s){let l=Vr(s[1]);if(l>=0)return wt(l,Number(s[2]),s[3],n)}let o=/^(\d{1,2}) (?:of )?([a-z]+)\.?(?:,? (\d{4}))?$/.exec(r);if(o){let l=Vr(o[2]);if(l>=0)return wt(l,Number(o[1]),o[3],n)}let a=/^(\d{1,2})[/\-.](\d{1,2})(?:[/\-.](\d{2,4}))?$/.exec(r);if(a){let l=Number(a[1]),d=Number(a[2]);return l>12&&d<=12?wt(d-1,l,a[3],n):d>12&&l<=12?wt(l-1,d,a[3],n):null}return null}function wt(t,e,n,r){if(n){if(n.length!==4)return null;let s=qr(Number(n),t,e);return s?H(s):null}let i=Ko(t,e,r);return i?H(i):null}function Ct(t,e={}){let n=t.isoDate;return typeof n=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(n)?n:be(t.text,e)}var Rn=" - ",It="aiaDateRangeStart",At="aiaDateRangeEnd";function Re(t,e){return t<=e?{start:t,end:e}:{start:e,end:t}}var Mn=/^\d{4}-\d{2}-\d{2}$/;function Kr(t){if(!Mn.test(t))return null;let[e,n,r]=t.split("-").map(Number),i=new Date(e,n-1,r);return i.getMonth()===n-1&&i.getDate()===r?i:null}var zo=/\s+(?:to|through|thru|until|til|till)\s+/g,jo=/[-–—]/g;function Yo(t){let e=[];for(let n of[zo,jo]){n.lastIndex=0;let r=n.exec(t);for(;r!==null;)e.push([t.slice(0,r.index),t.slice(r.index+r[0].length)]),r=n.exec(t)}return e}function De(t,e={}){if(!t)return null;let n=new Set,r=null;for(let[i,s]of Yo(t.trim())){let o=be(i.trim(),e);if(!o)continue;let a=be(s.trim(),e);!a||a<o||(n.add(`${o}|${a}`),r={start:o,end:a})}return n.size===1?r:null}function Dn(t){let e=Kr(t.start),n=Kr(t.end);return!e||!n?"":t.start===t.end?se(e):`${se(e)}${Rn}${se(n)}`}function zr(t,e){let n=Re(t,e);return{text:Dn(n),is_tappable:!0,kind:null,metadata:{[It]:n.start,[At]:n.end}}}function Se(t,e={}){let n=t?.metadata?.[It],r=t?.metadata?.[At];return typeof n=="string"&&typeof r=="string"&&Mn.test(n)&&Mn.test(r)?Re(n,r):De(t?.text,e)}var _e="(max-width: 768px)";var Qo="var(--aia-option-row-height, 37px)",Xo="var(--aia-grid-scroll-top, 0px) + var(--aia-grid-scroll-bottom, 0px)";function Nn(t,e){return e?_n(1,Math.min(t,5)):_n(1,Math.min(t,4))}function _n(t,e){return{cols:t,rows:e,maxHeight:`calc(${e} * ${Qo} + ${Xo})`}}function kt(t,e){return!e&&t>=5}function Lt(t,e,n,r){if(!(!e&&t>=5&&Jo(n,r))){let o=Nn(t,e);return{...o,template:Ot(o.cols),scrollHintIndices:!e&&t>o.rows?[o.rows-1]:[]}}let s=6;return{..._n(2,3),template:Ot(2),scrollHintIndices:t>s?[s-2,s-1]:[]}}function Jo(t,e){return!t||t.length===0||e==null||e<=0||t.some(r=>r<=0)?!1:Math.ceil(Math.max(...t))*2<=e}function Mt(t){if(typeof document>"u")return null;let e=Array.from(t.querySelectorAll("[data-aia-option]"));if(e.length===0)return null;let n=document.createElement("div");n.style.cssText="position:absolute;visibility:hidden;left:-9999px;top:0;";for(let o of e){let a=o.cloneNode(!0);a.removeAttribute("id"),a.removeAttribute("role"),a.removeAttribute("aria-selected"),a.style.whiteSpace="nowrap",a.style.width="max-content",n.appendChild(a)}t.appendChild(n);let r=Array.from(n.children).map(o=>o.offsetWidth);n.remove();let i=getComputedStyle(t),s=t.clientWidth-(Number.parseFloat(i.paddingLeft)||0)-(Number.parseFloat(i.paddingRight)||0)-(Number.parseFloat(i.columnGap)||0);return{rowWidths:r,gridWidth:s}}function Ot(t){return Array.from({length:t},()=>"minmax(0,1fr)").join(" ")}function Rt(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia(_e).matches}function Dt(t,e){return!t||t.length!==e.length?!1:t.every((n,r)=>n.text===e[r].text)}function jr(t,e){let n=e.dropdownTrigger??"auto",r=e.closeDropdownOnBlur??!0,o=t.filteredOptionsLength>0||t.activePillHasNoOptions||t.hasProducts;if(t.inEditMode){let a=r?t.isFocused||t.dropdownHeld:!0;return o&&a}if(n==="auto"){let a=r?t.isFocused||t.dropdownHeld:!0,l=t.text.replace(/\s+$/,"").length,d=t.caretOffset==null||t.caretOffset>=l;return(o||t.isLoading)&&a&&d}return n==="manual"?(o||t.isLoading)&&t.pillTapped:!1}function Ne(t){if(t.editingIdentified){let{parameter:n,anchor:r}=t.editingIdentified;return`identified:${n}@${r}`}return t.editingParam!=null&&t.editingAnchor!=null?`edit:${t.editingParam?.id}`:`pill:${t.actionableSuggestions[0]?.parameter??""}`}function Yr(t){if(!t)return Tn();let[e,n]=t.split("-").map(Number);return{year:e,month:n-1}}function Zo(t){let e=ke(t);return e?Dr(e):Tn()}function Qr(t,e){let n=wr(t.text,t.completedParams,t.identifiedParams),r=t.suggestions.filter(C=>C.parameter!=="placeholder"),i=r[0],s=t.suggestions.filter(C=>C.parameter==="placeholder").map(C=>C.text).join(" "),o=z(t.text,Math.min(t.filterBase,t.text.length),s),l=o===0&&Ye(t.text,t.completedParams.length,s)?"":Ee(t.text,o,t.filterInProgress),d=i?.options??[],c=t.editingParam!=null&&t.editingAnchor!=null,u,m,p,g;if(c&&t.editingParam&&t.editingAnchor!=null){let C=t.editingParam.id,re=t.completedParams.some(lo=>lo.id===C),_=t.caretOffset??t.editingAnchor,cr=re?"":t.text.slice(t.editingAnchor,_);m=cr.trim(),p=t.editingParam.options,g=t.editingParam.suggestionParameter,u=oe(t.editingParam.options,cr)}else m=l.trim(),p=d,g=i?.parameter,u=E(i)?d.map(C=>({...C,matchedText:t.text.slice(ge(t.text,t.completedParams)),parameterLabel:yr(C.parameter)})):oe(d,l,t.traditionalAutocomplete);let h=t.optionSearch,y=h!=null&&g!=null&&h.parameter===g;y&&h.status==="done"&&h.query===m&&(u=p);let b=y&&h.status==="loading",f=e.showNonTappableOptions===!1;f&&(u=u.filter(C=>C.is_tappable));let S=t.editingIdentified,x=c?t.editingParam&&{type:t.editingParam.suggestionValueType}:i,I=S?S.format:B(x),v=c&&I==="date-range"?Se(t.editingParam):null,w=null,M=null;if(T(I)){let C=Ne({...t,actionableSuggestions:r}),re=t.dateViewMonth;w=re&&re.key===C?{year:re.year,month:re.month}:S?Yr(S.iso):v?Yr(v.start):Zo(t.editingParam?.text),u=st(w);let _=t.pendingRangeStart;I==="date-range"&&_&&_.key===C&&(M=_.iso)}let A=C=>f?C.is_tappable:!0,O;if(c){let C=t.editingParam?.options??[];O=t.editingParam!=null&&C.filter(A).length===0}else O=i!=null&&d.filter(A).length===0;let L=jr({inEditMode:c||S!=null,filteredOptionsLength:u.length,isFocused:t.isFocused,dropdownHeld:t.dropdownHeld,text:t.text,caretOffset:t.caretOffset,isLoading:t.isLoading||b,pillTapped:t.pillTapped,activePillHasNoOptions:O,hasProducts:t.products.length>0},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur}),q=L&&t.activeDropdownIndex>=0&&!!u[t.activeDropdownIndex]?.is_tappable,ne=t.skeletonOptions!==null&&t.skeletonRequested&&!t.isLoading&&!t.editingParam&&!t.inSelectionAnimation,P=t.isLoading&&!t.editingParam&&!t.inSelectionAnimation||b||ne,W=P&&t.skeletonOptions!==null,hn=W&&t.skeletonOptions?t.skeletonOptions:u,bn=W?t.skeletonSuggestion:null;return{segments:n,actionableSuggestions:r,filteredOptions:u,dropdownLoading:P,dropdownOptions:hn,dropdownSuggestion:bn,skeletonExiting:ne,activeFormatType:I,dateView:w,dateRangeStart:M,placeholderText:s,optionQuery:m,isSearchingOptions:b,isDropdownOpen:L,isActivePillSelected:q}}function _t(t){return t.mode!=="edit"?ts(t):ns(t)}function es(t,e,n){let r=t.find(E);if(!r?.options)return null;let i=e.slice(ge(e,n)).trim().toLowerCase();if(!i)return null;let s=r.options.filter(l=>l.is_tappable&&l.text.trim().toLowerCase()===i);if(new Set(s.map(l=>$(l,r.parameter))).size!==1)return null;let a=s[0];return{suggestion:r,option:a,matchText:a.text.trim()}}function Xr(t){let{text:e,suggestions:n,filterBase:r,filterInProgress:i,phraseExactMatch:s}=t,o=n.find(c=>c.parameter!=="placeholder"&&!E(c));if(!o?.options)return null;let a=n.filter(c=>c.parameter==="placeholder").map(c=>c.text).join(" "),l=z(e,r,a),d=we(o.options,e,l,i,s===!0);return d?{suggestion:o,option:d,matchText:d.text}:null}function ts(t){let{text:e,completedParams:n,suggestions:r}=t,i=t.mode==="submit"?(t.finishWord?Xr(t):null)??es(r,e,n):Xr(t);if(!i)return null;let{suggestion:s,option:o,matchText:a}=i,l=a.toLowerCase(),d=e.toLowerCase().lastIndexOf(l),c=d>=0?d:Math.max(0,e.length-o.text.length),u=c+a.length,m=e.slice(c,u),g=u<e.length&&e[u]===" "?u+1:u,h={id:crypto.randomUUID(),placeholder:"",parameter:$(o,s.parameter),text:m,value:o.value,kind:o.kind,suggestionParameter:s.parameter,suggestionValueType:s.type,suggestionPlaceholder:s.text,...t.mode==="submit"&&E(s)?Ce($(o,s.parameter)):{},options:s.options??[],metadata:o.metadata,icon:o.icon,icon_svg:o.icon_svg,image_url:o.image_url};return{patch:{text:e,completedParams:[...n,h],suggestions:r.filter(y=>y!==s),filterBase:g,newParamId:h.id,caretOffset:g,activeDropdownIndex:-1},caretPos:g,option:o,suggestion:s}}function ns(t){let{text:e,completedParams:n,editingParam:r,editingAnchor:i,editingTail:s}=t;if(n.some(S=>S.id===r.id))return null;let o=e.slice(i,s),a=je(r.options,o);if(!a)return null;let l=a.text.toLowerCase(),d=o.toLowerCase().lastIndexOf(l),c=i+Math.max(0,d),u=c+a.text.length,m=e.slice(c,u),p=u<e.length&&e[u]===" "?u+1:u,g=e.length,h={id:crypto.randomUUID(),placeholder:"",...Qe(r,a),text:m,value:a.value,kind:a.kind,options:r.options,metadata:a.metadata,icon:a.icon,icon_svg:a.icon_svg,image_url:a.image_url},y=n.length,b=0;for(let S=0;S<n.length;S++){let x=V(e,n[S].text,b);if(x!==-1){if(x>=p){y=S;break}b=x+n[S].text.length}}let f=[...n];return f.splice(y,0,h),{patch:{text:e,completedParams:f,newParamId:h.id,filterBase:g,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:g,activeDropdownIndex:-1},caretPos:g,option:a}}function Fn(t){return t.slice(t.search(/\S*$/))}function Jr(t){return t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase()}function Zr(t,e){let n="",r=0;for(let i of t){if(n+=Jr(i),r+=i.length,n.length>=e.length)return n.startsWith(e)?r+(t.slice(r).match(/^\p{M}*/u)?.[0].length??0):0;if(!e.startsWith(n))return 0}return 0}function Hn(t){return[...t].map(Jr).join("")}function He(t,e){if(/\s$/.test(e))return null;let n=e.split(/\s+/).filter(Boolean).map(Hn),r=[...t.matchAll(/\S+/g)].map(i=>({index:i.index??0,text:i[0],folded:Hn(i[0])}));for(let i=n.length;i>=1;i--){let s=n.slice(n.length-i),o=s[i-1];for(let a=0;a+i<=r.length;a++){if(!s.slice(0,-1).every((u,m)=>r[a+m].folded===u))continue;let d=r[a+i-1],c=Zr(d.text,o);if(c>0)return{typedWords:i,start:r[a].index,end:d.index+c}}}return null}function Nt(t,e){let n=e?He(t,e):null;if(n&&n.typedWords>1)return[{text:t.slice(0,n.start),bold:!1},{text:t.slice(n.start,n.end),bold:!0},{text:t.slice(n.end),bold:!1}].filter(o=>o.text!=="");let r=e?Fn(e):"",i=Hn(r);if(!i)return[{text:t,bold:!1}];let s=[];for(let o of t.split(/(\s+)/)){if(o==="")continue;let a=/^\s/.test(o)?0:Zr(o,i);a>0&&s.push({text:o.slice(0,a),bold:!0});let l=a>0?o.slice(a):o;l&&s.push({text:l,bold:!1})}return s}var rs=6e4;function is(t){return typeof TextEncoder>"u"?t.length*3:new TextEncoder().encode(t).length}function os(t){return(t??K).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function ss(t){return Te(t)?`Bearer ${await Ve(t).getToken()}`:Ke(t)}async function ei(t){try{let e=os(t.apiConfig?.endpoint),n=qe(t.apiConfig),r=await ss(t.apiConfig);r&&(n.Authorization=r);let i=JSON.stringify({source:t.source,session_id:t.sessionId,...t.visitorId&&{visitor_id:t.visitorId},...t.requestId&&{request_id:t.requestId},type:t.type,...t.language&&{language:t.language},at:new Date().toISOString(),query_data:t.queryData});await fetch(e,{method:"POST",headers:n,body:i,...t.keepalive&&is(i)<=rs&&{keepalive:!0}})}catch{}}function le(t,e){let n=t.findIndex(r=>r.text===e);return n>=0?n+1:null}var Wn=t=>t.toLowerCase().split(/\s+/).filter(Boolean);function as(t,e,n){let r=Wn(t??"");if(r.length===0)return"";let s=Wn(e).slice(-r.length),o=Wn(n).slice(0,r.length);return s.join(" ")===r.join(" ")||o.join(" ")===r.join(" ")?"":(t??"").trim().split(/\s+/).join(" ")}function ti(t,e){let n=t.actionableSuggestions[0];if(!n)return null;let r=E(n),i=e.parameter;if(r&&!i)return null;let s=r&&i?i:$(e,n.parameter),o=r?t.text.length:t.filterBase,a=t.text.slice(0,o),l=a.length===0&&t.text.length===0,d=a.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(l||d)&&t.placeholderText&&(a=`${t.placeholderText} `);let c=Math.min(ge(t.text,t.completedParams),a.length);if(r){let v=[...a.slice(c).matchAll(/\S+/g)],w=He(e.text,a.slice(c)),M=v[v.length-(w?.typedWords??1)];a=a.slice(0,M?c+(M.index??0):Math.max(a.lastIndexOf(" ")+1,c))}else if(n.completes_word===!0){let v=[...a.slice(c).matchAll(/\S+/g)],w=v[v.length-1];a=a.slice(0,w?c+(w.index??0):Math.max(a.lastIndexOf(" ")+1,c))}else if(n.completes_word!==!1){let v=hr(a.slice(c),e.text);v>0&&(a=a.slice(0,a.length-v))}let u=a.length>0&&a[a.length-1]!==" ",p=T(B(n))?as(n.lead_in,a,e.text):"",g=`${a}${u?" ":""}${p?`${p} `:""}${e.text} `,y=(l||d||r&&a.length===0)&&g.length>0?g[0].toUpperCase()+g.slice(1):g,b=y.toLowerCase().lastIndexOf(e.text.toLowerCase()),f=b>=0?y.slice(b,b+e.text.length):e.text,S=r?Ce(s):{parameter:s,suggestionParameter:n.parameter,suggestionValueType:n.type,suggestionPlaceholder:n.text},x={id:crypto.randomUUID(),placeholder:"",...S,text:f,value:e.value,kind:e.kind,options:n.options??[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},I=t.actionableSuggestions.length-1;return{patch:{text:y,filterBase:y.length,completedParams:[...t.completedParams,x],newParamId:x.id,caretOffset:y.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:!0,inSelectionAnimation:!0,pendingSpan:null},telemetry:{selectedOption:e.text,otherOptions:t.filteredOptions.filter(v=>v.text!==e.text).map(v=>v.text),key:r?s:n.parameter,position:le(n.options??[],e.text)},consumedSuggestion:n,remainingActionable:I}}function Ht(t){let e=T(t.activeFormatType)||t.filteredOptions.length===0?null:t.filteredOptions,n=t.editingParam,r=n?{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options}:t.actionableSuggestions[0]??null;return{skeletonOptions:e,skeletonSuggestion:e?r:null,skeletonRequested:!1}}function Ft(t,e,n){let r=t.slice(0,e),i=t.slice(n),s=(r===""||r.endsWith(" "))&&i.startsWith(" ");return s&&(i=i.slice(1)),{text:r+i,removed:n-e+(s?1:0)}}var Wt=class{constructor(e){this.deps=e}start(e){let n=this.deps.store.get();if(n.editingParam?.id===e)return;let r=n.completedParams.find(o=>o.id===e);if(!r)return;let i=0,s=-1;for(let o of n.completedParams){let a=V(n.text,o.text,i);if(a!==-1){if(o.id===e){s=a;break}i=a+o.text.length}}s<0||this.deps.store.set({editingParam:r,editingAnchor:s,editingTail:s+r.text.length,caretOffset:s+r.text.length,activeDropdownIndex:-1,editingIdentified:null})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,s=n.editingTail;if(!r||i==null||s==null||!n.completedParams.some(l=>l.id===r.id))return!1;let{text:o}=e===""?Ft(n.text,i,s):{text:n.text.slice(0,i)+e+n.text.slice(s)},a=i+e.length;return this.deps.store.set(l=>({text:o,completedParams:l.completedParams.filter(d=>d.id!==r.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.promoteIfExact(),!0}caretAfterInput(e){let n=this.deps.store.get(),r={caretOffset:e};n.editingParam&&n.editingAnchor!=null&&e!=null&&(e<n.editingAnchor?(r.editingParam=null,r.editingAnchor=null,r.editingTail=null,r.activeDropdownIndex=-1):n.editingTail!=null&&(r.editingTail=Math.max(n.editingTail,e))),this.deps.store.set(r),this.promoteIfExact()}caretMove(e){let n=this.deps.store.get();if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null&&e!=null&&(e<n.editingAnchor||e>n.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,s=n.editingTail;if(!r||i==null||s==null)return;let o=Qe(r,e);this.deps.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:r.options.filter(f=>f.text!==e.text).map(f=>f.text),key:o.suggestionParameter,position:le(r.options,e.text),chip_origin:"tap"});let a=n.text.slice(0,i),l=n.text.slice(s),d=i===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,u=l.length===0||l[0]!==" "?`${d} `:d,m=a+u+l,p=m.length,g={id:crypto.randomUUID(),placeholder:"",...o,text:d,value:e.value,kind:e.kind,options:r.options,metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},h=n.completedParams.findIndex(f=>f.id===r.id),y=n.completedParams.filter(f=>f.id!==r.id),b=h>=0?Math.min(h,y.length):y.length;y.splice(b,0,g),this.deps.store.set({text:m,completedParams:y,newParamId:g.id,filterBase:p,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:p,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0,...Ht(n)}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(p),this.deps.fetchNow()}promoteIfExact(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let n=_t({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});n&&(this.deps.store.set(n.patch),this.deps.scheduleSetCursor(n.caretPos))}};var ri=33,ii=70,oi=120,si=50,de="data-aia-placeholder-leaving",ye=new WeakMap;function Bt(t){t.timer!==null&&(clearTimeout(t.timer),t.timer=null)}function ls(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function ai(t,e,n){e.shown=n,t.dataset.placeholder=e.target.slice(0,n)}function li(t,e){if(e.timer=null,!t.isConnected||e.shown>=e.target.length||(ai(t,e,e.shown+1),e.shown>=e.target.length))return;let n=e.target[e.shown-1],r=n===" "||n==="-"?70:0;e.timer=setTimeout(()=>li(t,e),33+r)}function ni(t,e){ai(t,e,0),e.timer=setTimeout(()=>li(t,e),33)}function di(t,e){let n=ye.get(t);if(e===""){n&&(Bt(n),ye.delete(t)),t.removeAttribute(de),delete t.dataset.placeholder;return}if(n?.target===e)return;if(ls(t)){n&&Bt(n),t.removeAttribute(de),ye.set(t,{target:e,shown:e.length,timer:null}),t.dataset.placeholder=e;return}let r={target:e,shown:0,timer:null},i=n&&n.shown>0?n:null;if(n&&Bt(n),ye.set(t,r),i){t.setAttribute(de,""),r.timer=setTimeout(()=>{r.timer=null,t.removeAttribute(de),t.isConnected&&ni(t,r)},170);return}t.removeAttribute(de),ni(t,r)}function ci(t){let e=ye.get(t);e&&(Bt(e),ye.delete(t))}var Bn="https://ai-autocomplete.com";function Ut(t=Bn){try{if(typeof window>"u"||!window.location)return t;let e=window.location.hostname;if(!e)return t;let n=new URL(t);return n.searchParams.set("utm_source",e),n.toString()}catch{return t}}var ui={language:"en",proceed:"to proceed",select:"to select",skipHint:"to skip",skip:"skip",skipLabel:"Skip",products:"Products",soldOut:"Sold out",addToCart:"Add to cart",submit:"Submit",scrollArrow:"Scroll down for more options",keepTyping:"Keep typing"},ds={language:"es",proceed:"para continuar",select:"para seleccionar",skipHint:"para omitir",skip:"omitir",skipLabel:"Omitir",products:"Productos",soldOut:"Agotado",addToCart:"A\xF1adir al carrito",submit:"Buscar",scrollArrow:"Despl\xE1zate para ver m\xE1s opciones",keepTyping:"Sigue escribiendo"},Un={en:ui,es:ds,fr:{language:"fr",proceed:"pour continuer",select:"pour s\xE9lectionner",skipHint:"pour passer",skip:"passer",skipLabel:"Passer",products:"Produits",soldOut:"\xC9puis\xE9",addToCart:"Ajouter au panier",submit:"Rechercher",scrollArrow:"Faites d\xE9filer pour voir plus d\u2019options",keepTyping:"Continuez \xE0 taper"},"pt-BR":{language:"pt-BR",proceed:"para continuar",select:"para selecionar",skipHint:"para pular",skip:"pular",skipLabel:"Pular",products:"Produtos",soldOut:"Esgotado",addToCart:"Adicionar ao carrinho",submit:"Buscar",scrollArrow:"Role para ver mais op\xE7\xF5es",keepTyping:"Continue digitando"},it:{language:"it",proceed:"per continuare",select:"per selezionare",skipHint:"per saltare",skip:"salta",skipLabel:"Salta",products:"Prodotti",soldOut:"Esaurito",addToCart:"Aggiungi al carrello",submit:"Cerca",scrollArrow:"Scorri per vedere altre opzioni",keepTyping:"Continua a scrivere"},tr:{language:"tr",proceed:"devam etmek i\xE7in",select:"se\xE7mek i\xE7in",skipHint:"atlamak i\xE7in",skip:"atla",skipLabel:"Atla",products:"\xDCr\xFCnler",soldOut:"T\xFCkendi",addToCart:"Sepete ekle",submit:"Ara",scrollArrow:"Daha fazla se\xE7enek i\xE7in kayd\u0131r",keepTyping:"Yazmaya devam et"},id:{language:"id",proceed:"untuk melanjutkan",select:"untuk memilih",skipHint:"untuk melewati",skip:"lewati",skipLabel:"Lewati",products:"Produk",soldOut:"Habis",addToCart:"Tambah ke keranjang",submit:"Cari",scrollArrow:"Gulir untuk melihat opsi lainnya",keepTyping:"Teruskan mengetik"},pl:{language:"pl",proceed:"aby kontynuowa\u0107",select:"aby wybra\u0107",skipHint:"aby pomin\u0105\u0107",skip:"pomi\u0144",skipLabel:"Pomi\u0144",products:"Produkty",soldOut:"Wyprzedane",addToCart:"Dodaj do koszyka",submit:"Szukaj",scrollArrow:"Przewi\u0144, aby zobaczy\u0107 wi\u0119cej opcji",keepTyping:"Pisz dalej"},de:{language:"de",proceed:"zum Fortfahren",select:"zum Ausw\xE4hlen",skipHint:"zum \xDCberspringen",skip:"\xFCberspringen",skipLabel:"\xDCberspringen",products:"Produkte",soldOut:"Ausverkauft",addToCart:"In den Warenkorb",submit:"Suchen",scrollArrow:"Scrolle f\xFCr weitere Optionen",keepTyping:"Weitertippen"},nl:{language:"nl",proceed:"om door te gaan",select:"om te selecteren",skipHint:"om over te slaan",skip:"overslaan",skipLabel:"Overslaan",products:"Producten",soldOut:"Uitverkocht",addToCart:"In winkelwagen",submit:"Zoeken",scrollArrow:"Scrol voor meer opties",keepTyping:"Blijf typen"},sv:{language:"sv",proceed:"f\xF6r att forts\xE4tta",select:"f\xF6r att v\xE4lja",skipHint:"f\xF6r att hoppa \xF6ver",skip:"hoppa \xF6ver",skipLabel:"Hoppa \xF6ver",products:"Produkter",soldOut:"Sluts\xE5ld",addToCart:"L\xE4gg i varukorgen",submit:"S\xF6k",scrollArrow:"Skrolla f\xF6r fler alternativ",keepTyping:"Forts\xE4tt skriva"},nb:{language:"nb",proceed:"for \xE5 fortsette",select:"for \xE5 velge",skipHint:"for \xE5 hoppe over",skip:"hopp over",skipLabel:"Hopp over",products:"Produkter",soldOut:"Utsolgt",addToCart:"Legg i handlekurven",submit:"S\xF8k",scrollArrow:"Rull ned for \xE5 se flere alternativer",keepTyping:"Fortsett \xE5 skrive"},da:{language:"da",proceed:"for at forts\xE6tte",select:"for at v\xE6lge",skipHint:"for at springe over",skip:"spring over",skipLabel:"Spring over",products:"Produkter",soldOut:"Udsolgt",addToCart:"L\xE6g i kurv",submit:"S\xF8g",scrollArrow:"Rul for flere muligheder",keepTyping:"Forts\xE6t med at skrive"},fi:{language:"fi",proceed:"jatkaaksesi",select:"valitaksesi",skipHint:"ohittaaksesi",skip:"ohita",skipLabel:"Ohita",products:"Tuotteet",soldOut:"Loppuunmyyty",addToCart:"Lis\xE4\xE4 ostoskoriin",submit:"Hae",scrollArrow:"Vierit\xE4 n\xE4hd\xE4ksesi lis\xE4\xE4 vaihtoehtoja",keepTyping:"Jatka kirjoittamista"},ja:{language:"ja",proceed:"\u3067\u6B21\u3078",select:"\u3067\u9078\u629E",skipHint:"\u3067\u30B9\u30AD\u30C3\u30D7",skip:"\u30B9\u30AD\u30C3\u30D7",skipLabel:"\u30B9\u30AD\u30C3\u30D7",products:"\u5546\u54C1",soldOut:"\u58F2\u308A\u5207\u308C",addToCart:"\u30AB\u30FC\u30C8\u306B\u8FFD\u52A0",submit:"\u691C\u7D22",scrollArrow:"\u30B9\u30AF\u30ED\u30FC\u30EB\u3057\u3066\u4ED6\u306E\u5019\u88DC\u3092\u898B\u308B",keepTyping:"\u5165\u529B\u3092\u7D9A\u3051\u308B"},ko:{language:"ko",proceed:"\uACC4\uC18D",select:"\uC120\uD0DD",skipHint:"\uAC74\uB108\uB6F0\uAE30",skip:"\uAC74\uB108\uB6F0\uAE30",skipLabel:"\uAC74\uB108\uB6F0\uAE30",products:"\uC0C1\uD488",soldOut:"\uD488\uC808",addToCart:"\uC7A5\uBC14\uAD6C\uB2C8\uC5D0 \uB2F4\uAE30",submit:"\uAC80\uC0C9",scrollArrow:"\uB354 \uB9CE\uC740 \uC635\uC158\uC744 \uBCF4\uB824\uBA74 \uC2A4\uD06C\uB864\uD558\uC138\uC694",keepTyping:"\uACC4\uC18D \uC785\uB825\uD558\uC138\uC694"},"zh-CN":{language:"zh-CN",proceed:"\u7EE7\u7EED",select:"\u9009\u62E9",skipHint:"\u8DF3\u8FC7",skip:"\u8DF3\u8FC7",skipLabel:"\u8DF3\u8FC7",products:"\u5546\u54C1",soldOut:"\u552E\u7F44",addToCart:"\u52A0\u5165\u8D2D\u7269\u8F66",submit:"\u641C\u7D22",scrollArrow:"\u5411\u4E0B\u6EDA\u52A8\u67E5\u770B\u66F4\u591A\u9009\u9879",keepTyping:"\u7EE7\u7EED\u8F93\u5165"},"zh-TW":{language:"zh-TW",proceed:"\u7E7C\u7E8C",select:"\u9078\u64C7",skipHint:"\u7565\u904E",skip:"\u7565\u904E",skipLabel:"\u7565\u904E",products:"\u5546\u54C1",soldOut:"\u552E\u5B8C",addToCart:"\u52A0\u5165\u8CFC\u7269\u8ECA",submit:"\u641C\u5C0B",scrollArrow:"\u5411\u4E0B\u6372\u52D5\u67E5\u770B\u66F4\u591A\u9078\u9805",keepTyping:"\u7E7C\u7E8C\u8F38\u5165"}},cs={pt:"pt-BR",no:"nb",nn:"nb"};function k(t){let[e,...n]=t?.toLowerCase().split("-")??[];if(e==="zh"){let i=n.some(s=>["hant","tw","hk","mo"].includes(s));return Un[i?"zh-TW":"zh-CN"]}let r=cs[e]??e;return Object.prototype.hasOwnProperty.call(Un,r)?Un[r]:ui}function $t(t,e,n=k()){return t?{key:"enter",hint:n.proceed}:e?{key:"tab",hint:n.select}:{key:"\u2192",hint:n.skipHint}}function Gt(t){let e=o=>{o.ctrlKey||pi(o.target,t,o.deltaX,o.deltaY)||o.preventDefault()},n=0,r=0,i=o=>{let a=o.touches[0];a&&(n=a.clientX,r=a.clientY)},s=o=>{if(o.touches.length!==1)return;let a=o.touches[0],l=n-a.clientX,d=r-a.clientY;n=a.clientX,r=a.clientY,o.cancelable&&!pi(o.target,t,l,d)&&o.preventDefault()};return t.addEventListener("wheel",e,{passive:!1}),t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchmove",s,{passive:!1}),()=>{t.removeEventListener("wheel",e),t.removeEventListener("touchstart",i),t.removeEventListener("touchmove",s)}}function pi(t,e,n,r){let i=t instanceof Element?t:null;for(;i;){if(r!==0&&us(i,r)||n!==0&&ps(i,n))return!0;if(i===e)break;i=i.parentElement}return!1}var mi=/^(auto|scroll|overlay)$/;function us(t,e){return t.scrollHeight<=t.clientHeight||!mi.test(getComputedStyle(t).overflowY)?!1:e>0?t.scrollTop+t.clientHeight<t.scrollHeight-1:t.scrollTop>0}function ps(t,e){if(t.scrollWidth<=t.clientWidth)return!1;let n=getComputedStyle(t);if(!mi.test(n.overflowX))return!1;let r=Math.abs(t.scrollLeft),i=t.scrollWidth-t.clientWidth;return(n.direction==="rtl"?e<0:e>0)?r<i-1:r>0}var gi=new WeakMap,fi=new WeakSet;function Q(t,e,n){if(gi.set(t,n),fi.has(t))return;fi.add(t);let r=()=>gi.get(t),i=s=>{if(!(s instanceof Element))return null;let o=s.closest(e.itemSelector);return o&&t.contains(o)?o:null};e.onClick&&t.addEventListener("click",s=>{let o=i(s.target);o&&e.onClick?.(o,r(),s)}),e.onEnter&&t.addEventListener("mouseenter",s=>{let o=s.target;o instanceof HTMLElement&&o.matches(e.itemSelector)&&e.onEnter?.(o,r())},!0),e.onLeave&&t.addEventListener("mouseleave",s=>{let o=s.target;o instanceof HTMLElement&&o.matches(e.itemSelector)&&e.onLeave?.(o,r())},!0),e.preventMousedown&&t.addEventListener("mousedown",s=>s.preventDefault())}function X(t){return Number.parseInt(t.dataset.aiaIndex??"-1",10)}function J(t){t.offsetWidth}var ms={selectedIso:null,selectedRange:null,rangeStart:null};function xe(t){if(!T(t.activeFormatType))return ms;let e=t.editingIdentified;if(e){let{iso:r,isoEnd:i}=e;return{selectedIso:i?null:r,selectedRange:r&&i?Re(r,i):null,rangeStart:t.dateRangeStart}}let n=Se(t.editingParam);return{selectedIso:n?null:at(t.editingParam?.text),selectedRange:n,rangeStart:t.dateRangeStart}}function Vt(t){return t.pendingStart?Re(t.pendingStart,t.highlightedIso??t.pendingStart):t.selected}function qt(t,e){if(t==null)return{selected:!1,inRange:!1};let{selectedIso:n,range:r}=e,i=t===n||r!=null&&(t===r.start||t===r.end),s=r!=null&&t>r.start&&t<r.end;return{selected:i,inRange:s}}var hi="data-aia-key";function Z(t,e,n){let r=new Map;for(let o of Array.from(t.children)){let a=o.getAttribute(hi);a!=null&&r.set(a,o)}let i=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],l=n.keyOf(a,o);i.add(l);let d=r.get(l);d||(d=n.create(a,o),d.setAttribute(hi,l)),n.update?.(d,a,o),t.children[o]!==d&&t.insertBefore(d,t.children[o]??null),s.push(d)}for(let[o,a]of r)i.has(o)||a.remove();return s}function bi(t,e){if(!e.interactive)return null;let n=e.options[X(t)];return n?.is_tappable?n:null}var gs={itemSelector:"[data-aia-date-cell], [data-aia-date-prev], [data-aia-date-next]",onClick:(t,e)=>{if(t.hasAttribute("data-aia-date-prev")){e.callbacks.onPreviousMonth();return}if(t.hasAttribute("data-aia-date-next")){e.callbacks.onNextMonth();return}let n=bi(t,e);n&&(t.classList.add("magicx-aia-date-cell--pressed"),e.callbacks.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-date-cell--pressed"),170))},onEnter:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&bi(t,e)&&e.callbacks.onHighlight(X(t))},onLeave:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&e.callbacks.onHighlight(-1,X(t))}};function yi(t,e,n,r,i,s,o,a=!0){let l=t.querySelector(".magicx-aia-datepicker");if(!i||e.length===0){l?.remove();return}if(!l){l=bs(),t.appendChild(l),J(l);for(let u of l.querySelectorAll(".magicx-aia-datepicker-nav"))u.disabled=!1}Q(l,gs,{options:e,callbacks:o,interactive:a});let d=l.querySelector(".magicx-aia-datepicker-month");d&&(d.textContent=it(i));let c=l.querySelector(".magicx-aia-datepicker-grid");c&&fs(c,e,n,r,s)}function fs(t,e,n,r,i){let s=H(new Date),o=Vt({pendingStart:i.rangeStart,highlightedIso:G(e[n]),selected:i.selectedRange});Z(t,e,{keyOf:(a,l)=>G(a)??`pad-${l}`,create:a=>hs(a),update:(a,l,d)=>{let c=G(l),u=qt(c,{selectedIso:i.selectedIso,range:o}),m=d===n&&l.is_tappable;a.id=`${r}-option-${d}`,a.dataset.aiaIndex=String(d),a.setAttribute("aria-selected",String(m)),a.classList.toggle("magicx-aia-date-cell--past",c!=null&&c<s),a.classList.toggle("magicx-aia-date-cell--highlighted",m),a.classList.toggle("magicx-aia-date-cell--today",c!=null&&c===s),a.classList.toggle("magicx-aia-date-cell--selected",u.selected),a.classList.toggle("magicx-aia-date-cell--in-range",u.inRange)}})}function hs(t){let e=document.createElement("div");e.setAttribute("role","option"),e.setAttribute("data-aia-option",""),e.setAttribute("data-aia-date-cell","");let n=lt(t);if(n==null)return e.className="magicx-aia-date-cell magicx-aia-date-cell--blank",e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e;e.className="magicx-aia-date-cell magicx-aia-date-cell--day",e.tabIndex=0,e.setAttribute("aria-label",t.text);let r=document.createElement("span");return r.className="magicx-aia-date-cell-number",r.textContent=String(n),e.appendChild(r),e}function bs(){let t=document.createElement("div");t.className="magicx-aia-datepicker",t.setAttribute("data-aia-datepicker","");let e=document.createElement("div");e.className="magicx-aia-datepicker-header";let n=document.createElement("span");n.className="magicx-aia-datepicker-month",n.setAttribute("data-aia-date-month",""),n.setAttribute("aria-live","polite"),e.append(Si("prev","Previous month","\u2039"),n,Si("next","Next month","\u203A"));let r=document.createElement("div");r.className="magicx-aia-datepicker-weekdays",r.setAttribute("aria-hidden","true");for(let s of Oe){let o=document.createElement("span");o.className="magicx-aia-datepicker-weekday",o.textContent=s,r.appendChild(o)}let i=document.createElement("div");return i.className="magicx-aia-datepicker-grid",i.setAttribute("data-aia-date-grid",""),t.append(e,r,i),t}function Si(t,e,n){let r=document.createElement("button");return r.type="button",r.tabIndex=-1,r.className="magicx-aia-datepicker-nav",r.setAttribute(`data-aia-date-${t}`,""),r.setAttribute("aria-label",e),r.textContent=n,r.disabled=!0,r}var Ss={itemSelector:"[data-aia-pill]",onClick:(t,e)=>{if(e.loading||t.disabled)return;let n=Number.parseInt(t.dataset.aiaPillIndex??"-1",10);n>=0&&e.onSelectPill(n)},preventMousedown:!0},xi=[125,69];function vi(t,e){return e?1:t===0?.7:t===1?.4:.2}function Kt(t,e,n,r,i=!1,s=!1,o=!1){let a=t.querySelector(".magicx-aia-pill-list");if(a||(a=document.createElement("span"),a.className="magicx-aia-pill-list",t.appendChild(a)),Q(a,Ss,{onSelectPill:r,loading:s}),s&&e.length===0){a.setAttribute("data-aia-pill-list-loading",""),a.innerHTML="";for(let l=0;l<xi.length;l++){let d=xi[l],c=document.createElement("span");c.setAttribute("data-aia-pill-skeleton",""),c.className=`magicx-aia-pill magicx-aia-pill--skeleton${i?" magicx-aia-pill--rounded":""}`,c.style.width=`${d}px`,c.style.opacity=String(vi(l,!1)),a.appendChild(c)}return}s?a.setAttribute("data-aia-pill-list-loading",""):a.removeAttribute("data-aia-pill-list-loading");for(let l of a.querySelectorAll("[data-aia-pill-skeleton]"))l.remove();Z(a,e,{keyOf:l=>`${l.type?.kind??""}|${Ie(l)?1:0}|${l.parameter}|${l.text}`,create:l=>{let d=document.createElement("button");if(d.type="button",d.tabIndex=-1,d.setAttribute("data-aia-pill",""),d.setAttribute("contenteditable","false"),Ie(l)){d.setAttribute("data-aia-smart-suggestion",E(l)?"header":"");let c=document.createElement("span");c.className="magicx-aia-smart-suggestion-text",c.textContent=l.text;let u=document.createElement("span");u.className="magicx-aia-smart-suggestion-sparkle",u.innerHTML=Ze,d.append(c,u)}else d.textContent=l.text;return d.disabled=!0,d},update:(l,d,c)=>{let u=l,m=o&&c===n&&!s,p=["magicx-aia-pill"];i&&p.push("magicx-aia-pill--rounded"),s&&p.push("magicx-aia-pill--skeleton"),u.className=p.join(" "),u.style.width="",u.style.opacity=String(vi(c,m)),u.dataset.aiaPillIndex=String(c),s?u.setAttribute("data-aia-loading",""):u.removeAttribute("data-aia-loading")}}),J(a);for(let l of a.querySelectorAll("[data-aia-pill]"))l.disabled=s}function $n(t){t.querySelector(".magicx-aia-pill-list")?.remove()}var Pi=32;function Gn(t,e){if(e.ctrlKey)return null;let n=e.deltaY||0,r=e.deltaX||0;if(!n||Math.abs(r)>=Math.abs(n))return null;let i=t.scrollWidth-t.clientWidth;if(i<=1)return null;let s=t.scrollLeft,o=n;return e.deltaMode===1?o*=32:e.deltaMode===2&&(o*=t.clientWidth),Math.max(0,Math.min(i,s+o))}function zt(t){let e=n=>{let r=Gn(t,n);r!==null&&(n.preventDefault(),t.scrollLeft=r)};return t.addEventListener("wheel",e,{passive:!1}),()=>t.removeEventListener("wheel",e)}var Ti=Intl.Segmenter,Ei=Ti?new Ti(void 0,{granularity:"grapheme"}):null;function jt(t){let e=t.trim().normalize("NFC").toUpperCase();if(Ei)for(let n of Ei.segment(e))return n.segment;return Array.from(e)[0]??"?"}var Yt=120,wi=360;function ys(t){let e=t.pathname;return t.hostname==="cdn.shopify.com"&&e.startsWith("/s/files/")||e.startsWith("/cdn/shop/")?/\.png$/i.test(e)?{format:"pjpg"}:/\.webp$/i.test(e)?{format:null}:null:null}function Vn(t,e){let n;try{n=new URL(t,typeof document>"u"?void 0:document.baseURI)}catch{return t}let r=ys(n);return r?(n.searchParams.set("width",String(e)),r.format&&n.searchParams.set("format",r.format),t.startsWith("/")&&!t.startsWith("//")?`${n.pathname}${n.search}${n.hash}`:n.href):t}function qn(t,e){let n=Vn(t,e);return n===t?[t]:[n,t]}function Qt(t,e){if(!(t>0)||!(e>0))return null;let n=t/e,r=i=>Math.round(i*1e3)/1e3;return{x:r(Math.min(n,1)),y:r(Math.min(1/n,1))}}function Fe(t){let e=t?.trim();return e?qn(e,360):[]}function Ci(t){return Fe(t)[0]}var Xt=new WeakMap,zn=new WeakMap,Ai=new WeakMap;function Oi(t,e,n,r,i,s="row",o="image",a=k(),l){let d=t.querySelector(".magicx-aia-products");if(e.length===0){d?.remove();return}if(!d){d=document.createElement("section"),d.className="magicx-aia-products",d.setAttribute("data-aia-products",""),d.setAttribute("role","group"),d.setAttribute("aria-labelledby",`${n}-products-label`);let m=document.createElement("div");m.className="magicx-aia-products-label",m.id=`${n}-products-label`,m.setAttribute("data-aia-products-label",""),m.textContent=a.products;let p=document.createElement("div");p.className="magicx-aia-products-row",p.setAttribute("data-aia-products-row",""),zt(p),d.append(m,p),t.appendChild(d)}d.setAttribute("data-aia-products-layout",s);let c=d.querySelector(".magicx-aia-products-label");c&&c.textContent!==a.products&&(c.textContent=a.products);let u=d.querySelector(".magicx-aia-products-row");if(u){Z(u,e,{keyOf:m=>Es(m,!!l),create:m=>ws(m,r,i,o,a,l),update:(m,p,g)=>{Xt.set(m,p),xs(m,p.price),m.id=`${n}-product-${g}`,m.dataset.aiaIndex=String(g),Ai.get(m)?.(o);let h=m.querySelector(".magicx-aia-product-badge");h&&h.textContent!==a.soldOut&&(h.textContent=a.soldOut);let y=m.querySelector(".magicx-aia-product-cart");y&&y.setAttribute("aria-label",ki(p,a))}}),J(u);for(let m of u.querySelectorAll("[data-aia-product]")){let p=zn.get(m);p&&(zn.delete(m),p())}}}function jn(t,e){let n=t.querySelectorAll("[data-aia-product], [data-aia-product-cart]");for(let r of n)r.tabIndex=e?0:-1}function xs(t,e){let n=t.querySelector(".magicx-aia-product-price");if(!e){n?.remove();return}n||(n=document.createElement("span"),n.className="magicx-aia-product-price",t.querySelector(".magicx-aia-product-title")?.after(n)),n.textContent!==e&&(n.textContent=e)}function Ii(t,e){e?(t.style.setProperty("--aia-product-photo-fill-x",String(e.x)),t.style.setProperty("--aia-product-photo-fill-y",String(e.y))):(t.style.removeProperty("--aia-product-photo-fill-x"),t.style.removeProperty("--aia-product-photo-fill-y"))}function ki(t,e){return`${e.addToCart}: ${t.title}`}var Kn="http://www.w3.org/2000/svg";function vs(){let t=document.createElementNS(Kn,"svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.setAttribute("focusable","false");let e=[["magicx-aia-product-cart-glyph","M2 3h2.2l2.4 11.2a2 2 0 0 0 2 1.6h8.9a2 2 0 0 0 1.9-1.5L21 8H6"],["magicx-aia-product-cart-glyph","M13.5 6.5v-4M11.5 4.5h4"],["magicx-aia-product-cart-check","M5 12.5l4.5 4.5L19 7.5"]];for(let[n,r]of e){let i=document.createElementNS(Kn,"path");i.setAttribute("class",n),i.setAttribute("d",r),t.appendChild(i)}for(let n of["9","17.5"]){let r=document.createElementNS(Kn,"circle");r.setAttribute("class","magicx-aia-product-cart-glyph"),r.setAttribute("cx",n),r.setAttribute("cy","20"),r.setAttribute("r","1.3"),t.appendChild(r)}return t}var Ps=1500;function Ts(t,e,n,r,i){let s=document.createElement("span");s.className="magicx-aia-product-cart",s.setAttribute("data-aia-product-cart",""),s.setAttribute("role","button"),s.setAttribute("aria-label",ki(e,i)),s.tabIndex=0,s.appendChild(vs());let o,a=l=>{l.preventDefault(),l.stopPropagation(),s.getAttribute("data-aia-cart-state")!=="adding"&&(clearTimeout(o),s.setAttribute("data-aia-cart-state","adding"),s.setAttribute("aria-busy","true"),n(Xt.get(t)??e).then(()=>{s.removeAttribute("aria-busy"),s.setAttribute("data-aia-cart-state","added"),o=setTimeout(()=>s.removeAttribute("data-aia-cart-state"),Ps)},()=>{s.removeAttribute("aria-busy"),s.removeAttribute("data-aia-cart-state")}))};return s.addEventListener("keydown",l=>{l.key!=="Enter"&&l.key!==" "||a(l)}),s.addEventListener("focus",()=>r(!0)),s.addEventListener("blur",l=>{l.relatedTarget?.closest("[data-aia-dropdown]")||r(!1)}),{el:s,arm:()=>s.addEventListener("click",a)}}function Es(t,e){return[e?"cart":"",t.id,t.title,t.url,t.imageUrl,t.vendor,t.available===!1?"sold-out":""].map(n=>n??"").join("\0")}function ws(t,e,n,r,i,s){let o=document.createElement("a");o.className="magicx-aia-product",o.setAttribute("data-aia-product",""),o.setAttribute("role","option"),o.setAttribute("aria-selected","false"),o.tabIndex=0;let a=document.createElement("span");a.className="magicx-aia-product-media",a.setAttribute("aria-hidden","true");let l=Fe(t.imageUrl),d=l[0],c=!!d,u=()=>{a.replaceChildren(),a.removeAttribute("data-aia-image-loaded"),a.toggleAttribute("data-aia-product-placeholder",r==="image"),a.toggleAttribute("data-aia-product-initial",r==="initial"),r==="initial"&&(a.textContent=jt(t.title))};if(Ai.set(o,h=>{h!==r&&(r=h,c||u())}),d){let h=document.createElement("img"),y=0;h.onload=()=>{a.setAttribute("data-aia-image-loaded",""),Ii(o,Qt(h.naturalWidth,h.naturalHeight))},h.onerror=()=>{let b=l[++y];if(b){h.src=b;return}c=!1,Ii(o,null),u()},h.className="magicx-aia-product-image",h.src=d,h.alt="",h.loading="lazy",h.decoding="async",a.appendChild(h)}else u();o.appendChild(a);let m=document.createElement("span");if(m.className="magicx-aia-product-body",t.vendor){let h=document.createElement("span");h.className="magicx-aia-product-vendor",h.textContent=t.vendor,m.appendChild(h)}let p=document.createElement("span");if(p.className="magicx-aia-product-title",p.textContent=t.title,m.appendChild(p),t.available===!1){o.setAttribute("data-aia-product-sold-out","");let h=document.createElement("span");h.className="magicx-aia-product-badge",h.textContent=i.soldOut,m.appendChild(h)}o.appendChild(m);let g=s&&t.available!==!1?Ts(o,t,s,n,i):null;return g&&(o.setAttribute("data-aia-product-has-cart",""),o.appendChild(g.el)),zn.set(o,()=>{g?.arm(),t.url&&(o.href=t.url),o.addEventListener("click",h=>{h.metaKey||h.ctrlKey||h.shiftKey||h.altKey||h.button!==0||(h.preventDefault(),e(Xt.get(o)??t))})}),o.addEventListener("keydown",h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),e(Xt.get(o)??t))}),o.addEventListener("focus",()=>n(!0)),o.addEventListener("blur",h=>{h.relatedTarget?.closest("[data-aia-dropdown]")||n(!1)}),o}var Li=80,Mi=150,Ri=280,Di=16,Jt="--aia-option-enter-delay";function Zt(t,e,n,r="below"){let i=Math.max(1,Math.floor(e)),s=Math.floor(Math.max(0,t)/i);if(r!=="above")return s*80;let o=Math.max(1,Math.ceil(Math.max(0,n)/i));return Math.max(0,o-1-s)*80}function en(t,e){let n=Math.max(1,Math.floor(e));return(Math.max(1,Math.ceil(Math.max(0,t)/n))-1)*80+280}var _i="http://www.w3.org/2000/svg",Cs=new Set(["svg","g","path","circle","ellipse","line","polyline","polygon","rect"]);function Is(t,e){let n=t.toLowerCase();return n.startsWith("on")||n.includes("href")||n==="style"||n==="xml:base"||n==="id"||n==="name"||/^\s*javascript:/i.test(e)||/url\s*\(\s*['"]?\s*[^#'"\s)]/i.test(e)}var As=["fill","stroke","stroke-width","stroke-linecap","stroke-linejoin","fill-rule","clip-rule","opacity","fill-opacity","stroke-opacity"],Os=/^[a-zA-Z0-9#.,%\s()-]+$/;function ks(t){let e=[];for(let n of As){let r=t.getAttribute(n);r===null||!Os.test(r)||/url\s*\(/i.test(r)||e.push(`${n}: ${r.trim()}`)}e.length>0&&t.setAttribute("style",e.join("; "))}function Ni(t){for(let e of Array.from(t.attributes))Is(e.name,e.value)&&t.removeAttribute(e.name);ks(t);for(let e of Array.from(t.childNodes))if(e.nodeType===Node.ELEMENT_NODE){let n=e;!Cs.has(n.localName)||n.namespaceURI!==_i?n.remove():Ni(n)}else e.remove()}function ee(t){if(typeof DOMParser>"u"||typeof XMLSerializer>"u")return null;let e=new DOMParser().parseFromString(t,"image/svg+xml"),n=e.documentElement;return!n||n.localName!=="svg"||n.namespaceURI!==_i||e.getElementsByTagName("parsererror").length>0?null:(Ni(n),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false"),new XMLSerializer().serializeToString(n))}function We(t){return t.text}function te(t){return Be(t)[0]??null}function Be(t){let e=Ls(t);return e?qn(e,120):[]}function Ls(t){if(!t)return null;let e=t.trim();if(e==="")return null;let n;try{n=new URL(e,typeof document>"u"?void 0:document.baseURI)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}function ve(t){return t===void 0||!Number.isInteger(t)||t<0?null:t.toLocaleString()}var Yn={one:"item",other:"items"};function Hi(t,e=Yn){let n=ve(t);if(n===null)return null;let r=typeof e=="string"?e:t===1?e.one:e.other;return r===""?n:`${n} ${r}`}function Qn(t){return te(t.image_url)!==null}var tn=new Map;function Ms(t){let e=t.icon_svg;if(!e)return!1;let n=tn.get(e);return n===void 0&&(n=ee(e)!==null,tn.size>=256&&tn.clear(),tn.set(e,n)),n}function nn(t,e,n){return!e&&!n?!1:t.every(r=>!r.is_tappable||n&&Qn(r)||e&&Ms(r))}var Fi=new WeakMap;function Rs(t,e,n){let r=e.length,i=Rt(),s=Fi.get(t),o=n&&s&&Dt(s.options,e)?s.plan:null,a=!o&&!n&&kt(r,i)?Mt(t):null,l=o??Lt(r,i,a?.rowWidths??null,a?.gridWidth??null);return n||Fi.set(t,{options:e,plan:l}),t.style.gridTemplateColumns=l.template,t.style.setProperty("--aia-grid-max-height",l.maxHeight),t.querySelectorAll("[data-aia-option]").forEach((d,c)=>{d.classList.toggle("magicx-aia-option--scroll-hint",!n&&l.scrollHintIndices.includes(c))}),l.cols}function Wi(t,e){if(e.loading||!e.interactive)return null;let n=e.options[X(t)];return n?.is_tappable?n:null}var Ds={itemSelector:"[data-aia-option]",onClick:(t,e)=>{let n=Wi(t,e);n&&(t.classList.add("magicx-aia-option--pressed"),e.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-option--pressed"),170))},onEnter:(t,e)=>{Wi(t,e)&&e.onHighlight(X(t))},onLeave:(t,e)=>e.onHighlight(-1,X(t))};function Bi(t,e,n,r,i,s,o,a="",l="below",d=!0,c=!0,u=!0,m=!0){let p=t.querySelector(".aia-grid");if(e.length===0){p?.remove();return}p||(p=document.createElement("div"),p.className="aia-grid magicx-aia-grid",p.setAttribute("data-scroll",""),p.style.setProperty("--aia-grid-min","250px"),p.style.setProperty("--aia-grid-max","1fr"),p.style.setProperty("--aia-grid-gap","0"),t.appendChild(p)),Q(p,Ds,{options:e,onSelect:r,onHighlight:i,loading:o,interactive:m});let g=p.dataset.aiaGroup!==a;p.dataset.aiaGroup=a;let h=nn(e,d,c);_s(p,e,n,s,o,{showIcons:d&&h,showImages:c&&h,showCounts:u});let y=Rs(p,e,o);Ns(p,e.length,y,o,l),g&&(p.scrollTop=0)}function _s(t,e,n,r,i,s){let o=i?"1":"0",a=t.dataset.aiaGroup??"",{showIcons:l,showImages:d,showCounts:c}=s,u=l?g=>g.icon??g.icon_svg??"":()=>"",m=d?g=>te(g.image_url)??"":()=>"",p=c?g=>ve(g.item_count)??"":()=>"";Z(t,e,{keyOf:g=>`${g.text}\0${g.parameterLabel??""}\0${u(g)}\0${m(g)}\0${p(g)}\0${o}\0${a}`,create:(g,h)=>{let y=Hs(g,i,s);return i||(y.dataset.aiaEntering=""),y},update:(g,h,y)=>{if(Xn.get(g)!==(h.matchedText??"")){let f=g.querySelector(".magicx-aia-option-text");f&&Ui(f,h),Xn.set(g,h.matchedText??"")}let b=y===n&&!i;g.id=`${r}-option-${y}`,g.dataset.aiaIndex=String(y),g.setAttribute("aria-selected",String(b)),g.classList.toggle("magicx-aia-option--highlighted",b)}})}function Ns(t,e,n,r,i){for(let s of t.querySelectorAll("[data-aia-entering]")){if(!r){let o=Number.parseInt(s.dataset.aiaIndex??"-1",10);o>=0&&s.style.setProperty(Jt,`${Zt(o,n,e,i)}ms`)}delete s.dataset.aiaEntering}}var Xn=new WeakMap;function Ui(t,e){if(t.replaceChildren(),e.matchedText)for(let n of Nt(We(e),e.matchedText))if(n.bold){let r=document.createElement("strong");r.className="magicx-aia-option-match",r.textContent=n.text,t.appendChild(r)}else t.appendChild(document.createTextNode(n.text));else t.appendChild(document.createTextNode(We(e)));if(e.parameterLabel){t.appendChild(document.createTextNode(" "));let n=document.createElement("span");n.className="magicx-aia-option-parameter",n.textContent=e.parameterLabel,t.appendChild(n)}}function Hs(t,e,{showIcons:n,showImages:r,showCounts:i}){let s=document.createElement("div");s.setAttribute("role","option"),s.setAttribute("data-aia-option",""),e&&s.setAttribute("data-aia-loading",""),s.tabIndex=e||!t.is_tappable?-1:0;let o=["magicx-aia-option"];t.is_tappable?o.push("magicx-aia-option--tappable"):o.push("magicx-aia-option--non-tappable"),s.className=o.join(" ");let a=document.createElement("span");a.className="magicx-aia-option-content";let l=r?Be(t.image_url):[],d=l[0];if(d){let p=document.createElement("span");p.className="magicx-aia-option-image",p.setAttribute("aria-hidden","true");let g=document.createElement("img");g.setAttribute("alt",""),g.setAttribute("loading","lazy"),g.setAttribute("decoding","async"),g.setAttribute("referrerpolicy","no-referrer"),g.setAttribute("draggable","false");let h=0;g.onload=()=>p.setAttribute("data-aia-image-loaded",""),g.onerror=()=>{let y=l[++h];y?g.src=y:g.hidden=!0},g.src=d,p.appendChild(g),a.appendChild(p),s.dataset.aiaImage=""}let c=!d&&n&&t.icon_svg?ee(t.icon_svg):null;if(c){let p=document.createElement("span");p.className="magicx-aia-option-icon",p.setAttribute("aria-hidden","true"),p.innerHTML=c,a.appendChild(p),t.icon&&(s.dataset.aiaIcon=t.icon)}let u=document.createElement("span");if(u.className="magicx-aia-option-text",Ui(u,t),Xn.set(s,t.matchedText??""),a.appendChild(u),t.tag){let p=document.createElement("span");p.className="magicx-aia-option-tag",p.textContent=t.tag,a.appendChild(p)}let m=i?ve(t.item_count):null;if(m!==null){let p=document.createElement("span");p.className="magicx-aia-option-count",p.textContent=m,a.appendChild(p),s.dataset.aiaItemCount=String(t.item_count)}return s.appendChild(a),s}var Zn="magicx-aia-scroll-arrow",er="data-aia-scroll-arrow",ce="data-aia-visible",tr=1e3,nr=160,rr="--aia-scroll-arrow-bottom",$i="Scroll down for more options",Fs="[data-aia-products-label]",Ws=4,Bs=8,Us=240;function $s(t,e,n,r){let i=t.scrollTop,s=n?.requestAnimationFrame,o=t.ownerDocument?.visibilityState==="hidden";if(!s||o||Jn(t)){t.scrollTop=i+e,r();return}let a=n.performance?.now?.()??Date.now(),l=()=>n.performance?.now?.()??Date.now(),d=()=>{let c=Math.min(1,(l()-a)/Us),u=1-(1-c)*(1-c);t.scrollTop=i+e*u,c<1?s.call(n,d):r()};s.call(n,d)}function Gs(t=document){let e="http://www.w3.org/2000/svg",n=t.createElementNS(e,"svg");n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("width","18"),n.setAttribute("height","18"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.75"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false");let r=t.createElementNS(e,"path");return r.setAttribute("d","M4 6.5 8 10.5l4-4"),n.appendChild(r),n}function Gi(t=document,e=k()){let n=t.createElement("button");return n.type="button",n.tabIndex=-1,n.className=Zn,n.setAttribute(er,""),n.setAttribute("aria-label",e.scrollArrow),n.setAttribute("aria-hidden","true"),n.disabled=!0,n.appendChild(Gs(t)),n}function Vs(t){let e=t.style.gridTemplateColumns.trim();return e?Math.max(1,e.split(/\s+/).length):1}function Jn(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function rn({dropdown:t,grid:e,button:n}){let r=e.ownerDocument?.defaultView??(typeof window<"u"?window:null),i=!1;n.disabled=!0;let s=null,o=null,a=null,l=null,d=f=>{if(f){if(n.hasAttribute(ce))return;if(n.setAttribute(ce,""),n.setAttribute("aria-hidden","false"),l!==null&&clearTimeout(l),Jn(e)){n.disabled=!1;return}l=setTimeout(()=>{l=null,!i&&n.hasAttribute(ce)&&(n.disabled=!1)},tr)}else n.removeAttribute(ce),n.setAttribute("aria-hidden","true"),l!==null&&clearTimeout(l),l=null,n.disabled=!0},c=f=>{let S=0,x=f;for(;x&&x!==t;)S+=x.offsetTop,x=x.offsetParent instanceof HTMLElement?x.offsetParent:null;return S},u=()=>{let f=t.querySelector(Fs),S;if(f){let x=c(f)+f.offsetHeight/2;S=t.clientHeight-x-n.offsetHeight/2}else{let x=c(e),I=r&&Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0;S=t.clientHeight-(x+e.offsetHeight)+(I>0?0:Bs)}n.style.setProperty(rr,`${Math.max(0,Math.round(S))}px`)},m=()=>{if(i||o!==null||a!==null)return;let f=e.querySelector("[data-aia-option][data-aia-loading]")!==null,S=e.scrollHeight-e.clientHeight-e.scrollTop;d(!f&&S>Ws)},p=()=>{if(i)return;u();let f=e.getAttribute("data-aia-group")??"";if(f!==s){s=f,d(!1),o!==null&&clearTimeout(o);let S=e.querySelectorAll("[data-aia-option]").length,x=Jn(e)?0:en(S,Vs(e));o=setTimeout(()=>{o=null,m()},x);return}m()},g=()=>{i||o!==null||(d(!1),a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,m()},nr))};e.addEventListener("scroll",g,{passive:!0});let h=f=>f.preventDefault(),y=()=>{let f=r?(Number.parseFloat(r.getComputedStyle(e).paddingTop)||0)+(Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0):0,S=Math.max(1,e.clientHeight-f);$s(e,S,r,g)};n.addEventListener("mousedown",h),n.addEventListener("click",y);let b=null;return r&&typeof r.ResizeObserver=="function"&&(b=new r.ResizeObserver(()=>{u(),m()}),b.observe(e)),p(),{update:p,destroy(){i||(i=!0,o!==null&&clearTimeout(o),o=null,a!==null&&clearTimeout(a),a=null,l!==null&&clearTimeout(l),l=null,n.disabled=!0,e.removeEventListener("scroll",g),n.removeEventListener("mousedown",h),n.removeEventListener("click",y),b?.disconnect(),n.removeAttribute(ce),n.setAttribute("aria-hidden","true"))}}}var ue="data-aia-fit",Ue="--aia-dropdown-fit-height";function on({dropdown:t,isOpen:e}){let n=t.ownerDocument?.defaultView??null,r=!1,i=!1,s=null,o=null,a=null,l=()=>{t.removeAttribute(ue),t.style.removeProperty(Ue)},d=p=>{let h=`${s}|${(p??t).scrollHeight}|${t.offsetWidth}`;if(a?.key===h)return a.height;let y=p?.scrollTop??0;t.removeAttribute(ue);let b=t.offsetHeight;return t.setAttribute(ue,""),p&&y&&(p.scrollTop=y),a={key:h,height:b},b},c=()=>{if(r)return;if(!e()){i=!1;return}i||(i=!0,l());let p=t.hasAttribute(ue),g=t.querySelector(".aia-grid")?.getAttribute("data-aia-group")??null,h=g!==s;s=g;let y=Ks(t,n);if(y===null)return;let b=qs(t);if(p){if(d(b)<=y){l();return}}else if(t.offsetHeight<=y)return;let f=`${Math.max(160,Math.floor(y))}px`;t.style.getPropertyValue(Ue)!==f&&t.style.setProperty(Ue,f),p?h&&b&&(b.scrollTop=0):t.setAttribute(ue,"")},u=()=>{r||o!==null||!n||(o=n.requestAnimationFrame(()=>{o=null,c()}))},m=n?.visualViewport??null;return m?.addEventListener("resize",u),m?.addEventListener("scroll",u),n?.addEventListener("resize",u),n?.addEventListener("scroll",u,{capture:!0,passive:!0}),c(),{update:c,destroy(){r||(r=!0,o!==null&&n?.cancelAnimationFrame(o),m?.removeEventListener("resize",u),m?.removeEventListener("scroll",u),n?.removeEventListener("resize",u),n?.removeEventListener("scroll",u,{capture:!0}))}}}function qs(t){for(let e of Array.from(t.children))if(e.classList.contains("aia-stack"))return e;return null}function Ks(t,e){if(!e)return null;let n=e.visualViewport,r=n?n.offsetTop:0,i=n?n.height:e.innerHeight;if(!i)return null;let s=t.offsetParent,o=s?s.getBoundingClientRect().top:0,a=s?o+t.offsetTop:t.getBoundingClientRect().top;return t.closest("[data-options-position]")?.getAttribute("data-options-position")==="above"?(s?a+t.offsetHeight:t.getBoundingClientRect().bottom)-r-8:r+i-a-8}var zs=[159,119,164];function ln(t){let e=document.createElement("div");return e.id=t,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",n=>n.preventDefault()),Gt(e),e}var sn=new WeakMap;function js(t,e,n){let r=sn.get(t);if(r||(r={button:Gi(t.ownerDocument,n),grid:null,controller:null},t.appendChild(r.button),sn.set(t,r)),r.button.getAttribute("aria-label")!==n.scrollArrow&&r.button.setAttribute("aria-label",n.scrollArrow),r.grid!==e&&(r.controller?.destroy(),r.controller=null,r.grid=e,e)){r.controller=rn({dropdown:t,grid:e,button:r.button});return}r.controller?.update()}var an=new WeakMap;function Vi(t){let e=an.get(t);if(e){e.update();return}an.set(t,on({dropdown:t,isOpen:()=>t.classList.contains("magicx-aia-dropdown--visible")}))}function ir(t){an.get(t)?.destroy(),an.delete(t);let e=sn.get(t);e&&(e.controller?.destroy(),sn.delete(t))}function dn(t,e){let n=e.strings??k(),{filteredOptions:r,activeIndex:i,isOpen:s,isLoading:o,showPills:a,isActivePillSelected:l,onSelect:d,onHighlight:c,onPillClick:u,onSkip:m}=e,p=Je(e.pills,n.keepTyping),g=et(p),h=a&&p.length>0,y=r.length>0,b=e.products.length>0,f=s&&(y||h||o||b);if(f?t.classList.add("magicx-aia-dropdown--visible"):t.classList.remove("magicx-aia-dropdown--visible"),o?t.setAttribute("data-aia-loading",""):t.removeAttribute("data-aia-loading"),!f){jn(t,!1),Vi(t);return}b?t.setAttribute("data-aia-has-products",""):t.removeAttribute("data-aia-has-products"),t.toggleAttribute("data-aia-skeleton-exiting",!!e.skeletonExiting);let S=t.querySelector(".aia-stack");S||(S=document.createElement("div"),S.className="aia-stack",S.style.setProperty("--aia-stack-space","8px"),t.appendChild(S));let x=e.showSkipButton&&g&&!e.isInputEmpty,I=h||o&&a||x,v=S.querySelector(".magicx-aia-pill-bar");if(I){v||(v=document.createElement("div"),v.className="magicx-aia-pill-bar aia-cluster",v.setAttribute("data-nowrap",""),v.setAttribute("data-aia-pillbar",""),S.insertBefore(v,S.firstChild));let P=v.querySelector(".magicx-aia-pill-scroll");P||(P=document.createElement("span"),P.className="magicx-aia-pill-scroll",P.setAttribute("data-aia-pill-scroll",""),v.insertBefore(P,v.firstChild)),Kt(P,a?p:[],0,u,!0,o&&a,l),Xs(v,x,o||e.skipDisabled,p[0],m,n)}else v&&v.remove();let w=e.suggestions[0],M=w?`${w.parameter} ${w.text}`:"",A=T(e.formatType),O=A&&!o;Bi(S,A?[]:r,i,d,c,e.listboxId,o,M,e.optionsPosition??"below",e.showOptionIcons??!0,e.showOptionImages??!0,e.showOptionCounts??!0,!e.skipDisabled),js(t,S.querySelector(".aia-grid"),n),yi(S,O?r:[],i,e.listboxId,O?e.dateView:null,{selectedIso:e.selectedDateIso,selectedRange:e.selectedDateRange,rangeStart:e.dateRangeStart},{onSelect:d,onHighlight:c,onPreviousMonth:e.onPreviousMonth,onNextMonth:e.onNextMonth},!e.skipDisabled);let L=S.querySelector(".magicx-aia-skeleton-bars");if(o&&(!y||A)){if(!L){L=document.createElement("div"),L.className="magicx-aia-skeleton-bars",L.setAttribute("data-aia-skeleton-bars","");for(let P of zs){let W=document.createElement("span");W.className="magicx-aia-skeleton-bar",W.style.width=`${P}px`,L.appendChild(W)}S.appendChild(L)}}else L&&L.remove();Oi(S,e.products,e.listboxId,e.onProductSelect,e.onProductFocusChange,e.productsLayout??"row",e.productImageFallback??"image",n,e.onProductAddToCart),jn(t,!0);let q=S.querySelector(".magicx-aia-footer")??Zs(n),ne=i>=0&&!!r[i]?.is_tappable;Js(q,$t(ne,e.isInputEmpty,n)),q.isConnected||S.appendChild(q),Ys(S,[".magicx-aia-pill-bar",".aia-grid",".magicx-aia-datepicker",".magicx-aia-skeleton-bars",".magicx-aia-products",".magicx-aia-footer"]),Vi(t)}function Ys(t,e){let n=e.map(r=>t.querySelector(`:scope > ${r}`)).filter(r=>r!==null);for(let r=0;r<n.length;r++)t.children[r]!==n[r]&&t.insertBefore(n[r],t.children[r]??null)}var Qs={itemSelector:".magicx-aia-skip",onClick:(t,e)=>{e.loading||e.onSkip()}};function Xs(t,e,n,r,i,s){Q(t,Qs,{onSkip:i,loading:n});let o=t.querySelector(".magicx-aia-skip");if(!e){o?.remove();return}o||(o=document.createElement("button"),o.type="button",o.tabIndex=-1,o.className="magicx-aia-skip",o.setAttribute("data-aia-skip",""),o.textContent=s.skip,o.disabled=!0,t.appendChild(o),J(o)),o.textContent!==s.skip&&(o.textContent=s.skip),o.setAttribute("aria-label",r?`${s.skipLabel} ${r.text}`:s.skipLabel),o.disabled=n}function Js(t,{key:e,hint:n}){let r=t.querySelector(".magicx-aia-footer-key"),i=t.querySelector(".magicx-aia-footer-hint");!r||!i||(r.textContent!==e&&(r.textContent=e),i.textContent!==n&&(i.textContent=n))}function Zs(t){let e=document.createElement("footer");e.className="magicx-aia-footer",e.setAttribute("data-aia-footer","");let n=document.createElement("div");n.className="aia-cluster magicx-aia-footer-row",n.setAttribute("data-align","center"),n.setAttribute("data-justify","between"),n.setAttribute("data-nowrap","");let r=document.createElement("div");r.className="aia-cluster magicx-aia-footer-hint-group",r.setAttribute("data-align","center"),r.style.setProperty("--aia-cluster-gap","5px");let i=document.createElement("kbd");i.className="magicx-aia-footer-key",i.textContent="tab";let s=document.createElement("span");s.className="magicx-aia-footer-hint",s.textContent=t.select,r.append(i,s);let o=document.createElement("a");o.className="aia-cluster magicx-aia-footer-brand-link",o.setAttribute("data-align","center"),o.href=Ut(),o.target="_blank",o.rel="noopener noreferrer",o.style.setProperty("--aia-cluster-gap","2px");let a=document.createElement("span");a.className="magicx-aia-footer-brand",a.textContent="AI";let l=document.createElement("span");return l.className="magicx-aia-footer-badge",l.textContent="Autocomplete",o.append(a,l),n.append(r,o),e.append(n),e}function qi(t,e){let n=ln(e.listboxId);return t.appendChild(n),{dropdown:n}}function or(t,e,n){let r=xe(e);dn(t.dropdown,{strings:n.strings,suggestions:e.editingIdentified?[{parameter:e.editingIdentified.parameter,text:U(e.editingIdentified.parameter),required:!0,options:e.filteredOptions}]:e.dropdownSuggestion??e.actionableSuggestions[0]?[{...e.dropdownSuggestion??e.actionableSuggestions[0],options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:e.actionableSuggestions,showPills:!0,showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",onProductAddToCart:n.addProductToCart,formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:r.selectedIso,selectedDateRange:r.selectedRange,dateRangeStart:r.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:n.selectOption,onHighlight:(i,s)=>{s!==void 0&&n.store.get().activeDropdownIndex!==s||n.store.set({activeDropdownIndex:i})},onPillClick:n.setActivePill,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:i=>n.store.set({isFocused:i})})}var ea=6,ta=.3;function Ki(t){return t<=0?"0px":`${(-Math.min(ta,2*ea/t)).toFixed(3)}px`}var zi=new Map;function na(t,e,n){let r=zi.get(e);if(r!==void 0){t.style.setProperty("--aia-chip-image-fit",r),t.setAttribute("data-aia-image-loaded","");return}let i=n.createElement("img");i.setAttribute("referrerpolicy","no-referrer"),i.onload=()=>{if(!t.isConnected)return;t.setAttribute("data-aia-image-loaded","");let s=t.getBoundingClientRect().height,o=Number.parseFloat(getComputedStyle(t).fontSize);if(!(s>0&&o>0&&i.naturalWidth>0&&i.naturalHeight>0))return;let a=`${(s/o*(i.naturalWidth/i.naturalHeight)).toFixed(3)}em`;zi.set(e,a),t.style.setProperty("--aia-chip-image-fit",a)},i.src=e}function cn(t){let{input:e,segments:n,newParamId:r,editingParamId:i,placeholderText:s,isFocused:o}=t,a=t.showChipIcons??!0,l=t.showChipImages??!0,d=n.length===0;e.dataset.aiaEmpty=d?"true":"false",di(e,d?s:"");let c=n.map(f=>f.type==="completed"?`${f.type}:${f.value}${a?f.param.icon??f.param.icon_svg??"":""}${l?te(f.param.image_url)??"":""}`:`${f.type}:${f.value}`).join("\0"),u=e.dataset.segKey??"",m=e.dataset.newParamId??"",p=e.dataset.editingParamId??"";if(c===u&&(r??"")===m&&(i??"")===p)return;if(c===u){e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";for(let f of e.querySelectorAll("strong[data-param-id]")){let S=f.dataset.paramId,x=f.dataset.seg==="completed"&&S===r;f.classList.toggle("magicx-aia-shimmer-revealed",x),f.classList.toggle("magicx-aia-shimmer-sweep",x),f.classList.toggle("magicx-aia-segment--editing",S===i)}return}let g=o?F(e):null;e.dataset.segKey=c,e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";let h=N(e),y=h.createDocumentFragment(),b=0;for(let f of n)if(b+=f.value.length,f.type==="completed"){let S=h.createElement("strong");S.dataset.seg="completed",S.dataset.paramId=f.param.id;let x=f.param.id===r,I=f.param.id===i,v=["magicx-aia-segment","magicx-aia-segment--completed"];x&&v.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),I&&v.push("magicx-aia-segment--editing"),S.className=v.join(" "),S.style.letterSpacing=Ki(f.value.length);let w=l?te(f.param.image_url):null;if(w){let A=h.createElement("span");A.className="magicx-aia-segment-image",A.setAttribute("contenteditable","false"),A.setAttribute("aria-hidden","true"),A.style.setProperty("--aia-chip-image",`url("${w}")`),na(A,w,h),S.appendChild(A),S.dataset.aiaImage=""}let M=!w&&a&&f.param.icon_svg?ee(f.param.icon_svg):null;if(M){let A=h.createElement("span");A.className="magicx-aia-segment-icon",A.setAttribute("contenteditable","false"),A.setAttribute("aria-hidden","true"),A.innerHTML=M,S.appendChild(A),f.param.icon&&(S.dataset.aiaIcon=f.param.icon)}S.appendChild(h.createTextNode(f.value)),y.appendChild(S)}else if(f.type==="identified"){let S=h.createElement("strong");S.dataset.seg="identified",S.dataset.paramId=f.param.id;let x=["magicx-aia-segment","magicx-aia-segment--completed"];f.param.id===i&&x.push("magicx-aia-segment--editing"),S.className=x.join(" "),S.style.letterSpacing=Ki(f.value.length),S.textContent=f.value,y.appendChild(S)}else y.appendChild(h.createTextNode(f.value));e.replaceChildren(y),e.dataset.aiaTextLength=String(b),g!=null?D(e,Math.max(0,Math.min(g,b))):o&&$r(e)&&D(e,b)}var ra='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ji(t=k()){let e=document.createElement("button");return e.type="button",e.className="magicx-aia-submit",e.setAttribute("aria-label",t.submit),e.setAttribute("data-aia-submit",""),e.innerHTML=ra.replace('aria-label="Submit"',`aria-label="${t.submit}"`),e}function ia(){let t=document.createElement("div");return t.setAttribute("contenteditable","plaintext-only"),t.contentEditable==="plaintext-only"}function Yi(t,e){let n=e.firstElementChild;if(!n){e.removeAttribute("data-aia-pill-wrapped");return}let r=n.getBoundingClientRect(),i=t.getBoundingClientRect();r.top>=i.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function Qi(t,e){let{listboxId:n}=e,r=ln(n);t.appendChild(r);let i=document.createElement("div");i.className="magicx-aia-input-wrapper",i.setAttribute("data-aia-input-wrapper",""),t.appendChild(i);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),i.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",ia()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",n),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=ji(e.strings),i.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),d.setAttribute("data-aia-submit-slot",""),i.appendChild(d));let c=new AbortController,{signal:u}=c,m=!1,p=0,g=()=>{let b=Me(o),S=b.length>0&&b[0]!==b[0].toUpperCase()?b[0].toUpperCase()+b.slice(1):b;e.handleChange(S)},h=()=>{let b=j(o)?.node??null;if(!b||!o.contains(b))return null;let x=(b.nodeType===Node.ELEMENT_NODE?b:b.parentElement)?.closest("strong[data-param-id]")?.dataset.paramId??null;return x&&Ur(o,x)?null:x};if(i.addEventListener("click",b=>{b.target?.closest("[data-aia-pill]")||o.focus()},{signal:u}),o.addEventListener("input",()=>{m||(p=performance.now(),g(),e.handleCaretAfterInput(F(o)))},{signal:u}),N(o).addEventListener("selectionchange",()=>{let b=j(o);if(!b||!o.contains(b.node))return;let f=b.collapsed?h():null,S=e.store.get(),x=S.editingParam?.id??S.editingIdentified?.id??null;if(f&&f!==x){e.startEditingParam(f);return}performance.now()-p<50||e.handleCaretMove(F(o))},{signal:u}),o.addEventListener("click",b=>{let f=ht(o,b.target);f&&(e.startEditingParam(f),bt(o,f))},{signal:u}),o.addEventListener("compositionstart",()=>{m=!0,o.setAttribute("data-aia-composing","true")},{signal:u}),o.addEventListener("compositionend",()=>{m=!1,o.removeAttribute("data-aia-composing"),g()},{signal:u}),o.addEventListener("beforeinput",b=>{let f=b,S=f.inputType;if(S==="insertParagraph"||S==="insertLineBreak"||S==="insertFromDrop"){b.preventDefault();return}if(S.startsWith("insert")||S.startsWith("delete")){let x=S.startsWith("delete")?"":f.data??"";e.replaceEditingRange(x)&&b.preventDefault()}},{signal:u}),o.addEventListener("paste",b=>{b.preventDefault();let f=(b.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!f)return;let S=N(o),x=dt(o);if(!x||!o.contains(x.startContainer))return;x.deleteContents();let I=S.createTextNode(f);x.insertNode(I),x.setStartAfter(I),Le(o,x.startContainer,x.startOffset),g()},{signal:u}),o.addEventListener("keydown",b=>e.handleKeyDown(b),{signal:u}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:u}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:u}),d&&d.addEventListener("click",b=>{let f=e.store.get();if(!(!!f.text||f.completedParams.length>0)||!e.onSubmit)return;b.stopPropagation(),e.endTypedWord?.();let x=e.store.get();e.onSubmit(Y(x.text,x.completedParams,x.skippedParams,{identifiedParams:x.identifiedParams,isReady:x.isReady,customFields:x.customFields}))&&e.afterSubmit?.()},{signal:u}),e.autoFocus!==!1){o.focus();let b=j(o);(!b||!o.contains(b.node))&&Le(o,o,0)}if(typeof ResizeObserver<"u"){let b=new ResizeObserver(()=>Yi(o,a));b.observe(o),c.signal.addEventListener("abort",()=>b.disconnect(),{once:!0})}return{input:o,inlinePillContainer:a,dropdown:r,submitButton:l,abort:c}}function sr(t,e,n){let{input:r,inlinePillContainer:i,dropdown:s,submitButton:o}=t,{pillPlacement:a,setActivePill:l,selectOption:d,store:c}=n;r.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${n.listboxId}-option-${e.activeDropdownIndex}`:"";if(u?r.setAttribute("aria-activedescendant",u):r.removeAttribute("aria-activedescendant"),o){let b=n.strings??k();o.getAttribute("aria-label")!==b.submit&&o.setAttribute("aria-label",b.submit);let f=o.querySelector("svg");f&&f.getAttribute("aria-label")!==b.submit&&f.setAttribute("aria-label",b.submit);let S=!!e.text||e.completedParams.length>0;o.disabled=!S}let m=r.dataset.newParamId??"",p=e.newParamId!==null&&e.newParamId!==m;if(cn({input:r,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused,showChipIcons:n.showChipIcons??!0,showChipImages:n.showChipImages??!0}),a==="inline"){let b=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,f=Xe(e.actionableSuggestions);b||f.length>0?Kt(i,f,0,l,!1,b,e.isActivePillSelected):$n(i)}else $n(i);Yi(r,i),p?(r.focus(),D(r,e.caretOffset??e.text.length)):e.isFocused&&Me(r)!==e.text&&D(r,e.text.length);let g=e.editingParam?{parameter:e.editingParam.suggestionParameter,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:e.editingIdentified?{parameter:e.editingIdentified.parameter,text:U(e.editingIdentified.parameter),required:!0,options:[]}:null,h=e.dropdownSuggestion??g??e.actionableSuggestions[0],y=xe(e);dn(s,{strings:n.strings,suggestions:h?[{...h,options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:g?[g]:e.actionableSuggestions,showPills:a==="dropdown",showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",onProductAddToCart:n.addProductToCart,formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:y.selectedIso,selectedDateRange:y.selectedRange,dateRangeStart:y.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:d,onHighlight:(b,f)=>{f!==void 0&&c.get().activeDropdownIndex!==f||c.set({activeDropdownIndex:b})},onPillClick:l,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:b=>c.set({isFocused:b})})}function un(t){let e=t,n=new Set,r=[],i=!1;return{get:()=>e,set:s=>{let o=typeof s=="function"?s(e):s,a=e;if(e={...e,...o},r.push([e,a]),!i){i=!0;try{let l=0;for(let d=r.shift();d;d=r.shift()){if(++l>1e4)throw r.length=0,new Error("createStore: notifications did not settle after 10000 deliveries \u2014 a listener is likely calling set() on every notification");let[c,u]=d;for(let m of n)m(c,u)}}catch(l){throw r.length=0,l}finally{i=!1}}},subscribe:s=>(n.add(s),()=>{n.delete(s)})}}function Xi(t,e){let n,r,i=s=>(s!==n&&(n=s,r=e(s)),r);return{get:()=>{let s=t.get();return{...s,...i(s)}},set:s=>{typeof s=="function"?t.set(o=>{let a={...o,...i(o)};return s(a)}):t.set(s)},peek:s=>{let o={...t.get(),...s};return{...o,...e(o)}},subscribe:s=>t.subscribe((o,a)=>{let l={...a,...i(a)},d={...o,...i(o)};s(d,l)})}}var ar=new WeakSet,Ji=new WeakMap;function eo(t){return t.nodeType===Node.DOCUMENT_NODE}function oa(t){return eo(t)?t:t.ownerDocument}function sa(t){let e=Ji.get(t);if(e)return e;let n=t.defaultView?.CSSStyleSheet;if(typeof n!="function")return null;try{let r=new n;return typeof r.replaceSync!="function"?null:(r.replaceSync(no),Ji.set(t,r),r)}catch{return null}}function Zi(t,e){if(e.querySelector("style[data-magicx-aia]"))return;let n=t.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=no,e.appendChild(n)}function to(t){if(typeof document>"u")return;let e=t??document;if(ar.has(e))return;let n=oa(e);if(eo(e)){let s=e.head??e.documentElement;if(!s)return;Zi(n,s),ar.add(e);return}let r=sa(n),i=e.adoptedStyleSheets;r&&Array.isArray(i)?i.includes(r)||(e.adoptedStyleSheets=[...i,r]):Zi(n,e),ar.add(e)}var no=`.aia-stack {
1
+ "use strict";var Sn=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var uo=Object.getOwnPropertyNames;var po=Object.prototype.hasOwnProperty;var mo=(t,e)=>{for(var n in e)Sn(t,n,{get:e[n],enumerable:!0})},go=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of uo(e))!po.call(t,i)&&i!==n&&Sn(t,i,{get:()=>e[i],enumerable:!(r=co(e,i))||r.enumerable});return t};var fo=t=>go(Sn({},"__esModule",{value:!0}),t);var fa={};mo(fa,{AIAutocomplete:()=>fn,ATTRIBUTION_URL:()=>Bn,DATE_RANGE_META_END:()=>At,DATE_RANGE_META_START:()=>It,DEFAULT_OPTION_COUNT_UNIT:()=>Yn,ModeController:()=>Pe,OPTIONS_GRID_MOBILE_QUERY:()=>_e,OPTION_ENTER_DELAY_VAR:()=>Jt,OPTION_ENTER_FADE_MS:()=>Mi,OPTION_ENTER_RISE_MS:()=>Ri,OPTION_ENTER_RISE_PX:()=>Di,OPTION_ENTER_STAGGER_MS:()=>Li,OPTION_IMAGE_WIDTH:()=>Yt,PLACEHOLDER_FADE_OUT_MS:()=>oi,PLACEHOLDER_LEAVING_ATTR:()=>de,PLACEHOLDER_SWAP_GAP_MS:()=>si,PLACEHOLDER_TYPE_MS:()=>ri,PLACEHOLDER_WORD_PAUSE_MS:()=>ii,PRODUCT_IMAGE_WIDTH:()=>wi,PRODUCT_PATH_PREFIX:()=>kn,PRODUCT_ROW_PX_PER_LINE:()=>Pi,RANGE_SEPARATOR:()=>Rn,SCHEMA_VERSION:()=>xn,SCROLL_ARROW_ATTR:()=>er,SCROLL_ARROW_BOTTOM_VAR:()=>rr,SCROLL_ARROW_CLASS:()=>Zn,SCROLL_ARROW_FADE_MS:()=>tr,SCROLL_ARROW_LABEL:()=>$i,SCROLL_ARROW_SCROLL_IDLE_MS:()=>nr,SCROLL_ARROW_VISIBLE_ATTR:()=>ce,SKIPPED_PARAM_TEXT:()=>yn,SMART_SUGGESTION_SPARKLE_SVG:()=>Ze,VIEWPORT_FIT_ATTR:()=>ue,VIEWPORT_FIT_HEIGHT_VAR:()=>Ue,WEEKDAY_LABELS:()=>Oe,addMonths:()=>ot,attachProductRowWheel:()=>zt,attachScrollArrow:()=>rn,attachViewportFit:()=>on,buildAttributionUrl:()=>Ut,buildDateOptions:()=>st,buildQuery:()=>R,buildSubmitResult:()=>Y,cellDay:()=>lt,cellIso:()=>G,chipIdFromTap:()=>ht,computeOptionsGridLayout:()=>Nn,containScroll:()=>Gt,createStore:()=>un,cursorIsAtEnd:()=>St,dateCellMarks:()=>qt,dateSelectionFor:()=>xe,extractPlainText:()=>Me,formatAbsoluteDate:()=>se,formatDate:()=>Pn,formatDateRange:()=>Dn,formatOptionCount:()=>ve,getCursorOffset:()=>F,getFooterHint:()=>$t,hasSkippablePill:()=>et,highlightParts:()=>Nt,identifiedParamLabel:()=>U,isCalendarFormat:()=>T,isOptionsGridMobileViewport:()=>Rt,isSmartSuggestion:()=>Ie,isTraditionalAutocompleteSuggestion:()=>E,isoDate:()=>H,keepCaretOnChip:()=>bt,labelTraditionalAutocomplete:()=>Je,matchTypedPhrase:()=>He,measureOptionsGrid:()=>Mt,monthLabel:()=>it,needsOptionsGridMeasurement:()=>kt,optionCountLabel:()=>Hi,optionEnterDelayMs:()=>Zt,optionHasImage:()=>Qn,optionImageSources:()=>Be,optionImageSrc:()=>te,optionLabel:()=>We,optionsEntranceDurationMs:()=>en,optionsGridTemplateColumns:()=>Ot,optionsShowLeadingVisuals:()=>nn,parseDate:()=>ke,parseLooseDate:()=>be,parseLooseDateRange:()=>De,plainTextLength:()=>ft,planOptionsGrid:()=>Lt,previousGraphemeBoundary:()=>yt,productFromMatchedItem:()=>Ln,productImageSources:()=>Fe,productImageSrc:()=>Ci,productInitial:()=>jt,productPhotoFill:()=>Qt,productRowWheelTarget:()=>Gn,productsFromCustomFields:()=>Tt,renderEditableContent:()=>cn,resolveFormatType:()=>B,resolveIdentifiedDate:()=>Ct,sameOptionRows:()=>Dt,sanitizeOptionIconSvg:()=>ee,scrollCaretIntoView:()=>pt,selectedIsoFromText:()=>at,selectedRangeFor:()=>Se,setCursorOffset:()=>D,shopifyImageSrc:()=>Vn,toWireIdentifiedParams:()=>pe,typedFragment:()=>Fn,uiStringsFor:()=>k,visibleDateRange:()=>Vt,withSkippedParams:()=>me,withoutTraditionalAutocomplete:()=>Xe});module.exports=fo(fa);function T(t){return t==="date"||t==="date-range"}function B(t){return t?.type?.kind==="date"?"date":t?.type?.kind==="date_range"?"date-range":"options"}var $e=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var ho="https://api.ai-autocomplete.com",K=`${ho}/api/suggest`,Ge=new Map([["api.ai-autocomplete.com","cdn.ai-autocomplete.com"],["dev-api.ai-autocomplete.com","dev-cdn.ai-autocomplete.com"]]),ur=new WeakMap;function Te(t){return t?.type==="accessToken"}function bo(t){if(!(!t||Te(t)))return t}function Ve(t){let e=ur.get(t.getAccessToken);return e||(e=new $e(t),ur.set(t.getAccessToken,e)),e}function qe(t){return{"Content-Type":"application/json",...t?.appIdentifier&&{"X-App-Identifier":t.appIdentifier},...t?.headers}}function Ke(t){let e=bo(t),n=e?.apiKey;return n?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`:null}function pe(t){return t.map(e=>({parameter:e.parameter,text:e.text}))}var yn="skipped";function me(t,e){if(e.length===0)return t;let n=new Set(t.map(i=>i.parameter)),r=e.filter(i=>!n.has(i.parameter)).map(i=>({placeholder:"",parameter:i.parameter,text:yn,kind:null}));return r.length>0?[...t,...r]:t}var So="0.55.0",xn="1.0",pr=!1;function yo(t,e){return{placeholder:t.placeholder,parameter:t.parameter,...e&&{text:t.value??t.text},kind:t.kind}}function ie(t){return t??(typeof navigator<"u"?navigator.language:"en-US")}function xo(t,e,n,r,i,s,o,a,l,d,c,u,m){let p=e.find(h=>h.parameter==="contact"&&h.metadata?.contact_account_count)?.metadata?.contact_account_count,g=typeof p=="number"?p:void 0;return{data:{raw_query:t,accepts_traditional_autocomplete:!0,client_option_parameters:m??[],completed_params:me(e.map(h=>yo(h,n)),l??[]),...o&&o.length>0&&{identified_params:pe(o)},...a&&a.length>0&&{recently_suggested:a},...g!=null&&{contact_account_count:g},...d!==void 0&&{additional_context:d}},meta:{request_id:i,request_at:new Date().toISOString(),language:ie(c),...u?.code&&Number.isFinite(u.rate)&&u.rate>0&&{currency:u.code,currency_rate:u.rate,...u.country!==void 0&&{country:u.country}},client_version:So,session_id:r,source:s,schema_version:xn}}}async function mr(t,e,n,r,i){return fetch(t,{method:"POST",headers:{...e,Authorization:`Bearer ${n}`},body:r,signal:i})}async function gr(t,e,n){let r=n.apiConfig,i=!n.maskCompletedText,s=xo(t,e,i,n.sessionId,n.requestId??crypto.randomUUID(),n.source,n.identifiedParams,n.recentlySuggested,n.skippedParams,n.additionalContext,n.language,n.currency,n.clientOptionParameters),o=qe(r),a=r?.endpoint??K,l=JSON.stringify(s);if(Te(r)){let u=Ve(r),m=await u.getToken(),p=await mr(a,o,m,l,n.signal);if(p.status===401){let g=await u.getToken(!0);p=await mr(a,o,g,l,n.signal)}if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}let d=Ke(r);!d&&!pr&&(pr=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(o.Authorization=d);let c=await fetch(a,{method:"POST",headers:o,body:l,signal:n.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}var ze=/[\p{L}\p{N}]/u,vo=/['\u2019-]/;function fr(t,e,n){let r=t[e];if(r===void 0)return!1;if(ze.test(r))return!0;let i=t[e+n];return vo.test(r)&&i!==void 0&&ze.test(i)}function Po(t,e,n){let r=e+n.length;return!(ze.test(n[0])&&fr(t,e-1,-1)||ze.test(n[n.length-1])&&fr(t,r,1))}function V(t,e,n=0,r=()=>!0){if(e.length===0)return t.indexOf(e,n);let i=-1,s=t.indexOf(e,n);for(;s!==-1;){if(r(s)){if(Po(t,s,e))return s;i===-1&&(i=s)}s=t.indexOf(e,s+1)}return i}function R(t,e){let n=t,r={},i=[],s=[],o=0;for(let a of e){let l=(r[a.parameter]??0)+1;r[a.parameter]=l;let c=`{{${a.parameter.toUpperCase().replace(/\s+/g,"_")}_${l}}}`,u=p=>V(n,a.text,p,g=>!s.some(h=>g<h.end&&g+a.text.length>h.start)),m=u(o);if(m===-1&&(m=u(0)),m!==-1){n=n.slice(0,m)+c+n.slice(m+a.text.length);let p=c.length-a.text.length;for(let g of s)g.start>=m+a.text.length&&(g.start+=p,g.end+=p);s.push({start:m,end:m+c.length}),o=m>=o?m+c.length:o+p}i.push({...a,placeholder:c})}return{rawQuery:n,completedParams:i}}function z(t,e,n){return e>0||!n?e:t.toLowerCase().startsWith(n.toLowerCase())?n.length:e}function Ye(t,e,n){return e===0&&t.length>0&&n.length>0&&n.toLowerCase().startsWith(t.toLowerCase())}function Ee(t,e,n){let r=t.slice(e);if(n||e===0||t[e-1]===" ")return r;let i=r.indexOf(" ");return i===-1?"":r.slice(i+1)}function hr(t,e){let n=t.trimEnd().replace(/\s+/g," ");if(n.length===0||e.length===0)return 0;let r=n.split(" "),i=e.toLowerCase();for(let s=0;s<r.length;s++){let o=r.slice(s).join(" ");if(i.startsWith(o.toLowerCase())){let a=n.length-o.length;return t.length-a}}return 0}function br(t){return t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase().replace(/[_\-\s]+/g," ")}function To(t,e){let n=br(t).trim();return n.startsWith(e)||n.includes(` ${e}`)}function oe(t,e,n=!1){if(!t)return[];let r=e.trimStart();if(!r)return t;let i=n?br(r).trimStart():"";if(i)return t.filter(o=>!o.is_tappable||To(o.text,i));let s=r.toLowerCase();return t.filter(o=>!o.is_tappable||o.text.toLowerCase().includes(s))}function je(t,e){if(!t)return null;let n=e.trim();if(!n)return null;let r=n.toLowerCase();return t.find(i=>i.is_tappable&&i.text.toLowerCase()===r)??null}function we(t,e,n,r,i){let s=Ee(e,n,r),o=je(t,s);if(o||!i||!s.trim())return o;if(s===e.slice(n))return null;let a=e.lastIndexOf(" ",n-1)+1;return je(t,e.slice(a))}function Sr(t,e){return e?t.map(n=>e[n.parameter]?{...n,options:[]}:n):t}function Eo(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.toLowerCase())}function U(t){let e=Eo(t);return e.length>0?e.join(" "):t}function $(t,e){return t.parameter||e}function Ce(t){return{parameter:t,suggestionParameter:t,suggestionValueType:{kind:"traditional_autocomplete"},suggestionPlaceholder:U(t)}}function Qe(t,e){let n=$(e,t.suggestionParameter);return t.suggestionValueType?.kind==="traditional_autocomplete"?Ce(n):{parameter:n,suggestionParameter:t.suggestionParameter,suggestionValueType:t.suggestionValueType,suggestionPlaceholder:t.suggestionPlaceholder}}function E(t){return t?.type?.kind==="traditional_autocomplete"}function yr(t){let e=t?.replace(/[_\-\s]+/g," ").trim();return e?e.charAt(0).toUpperCase()+e.slice(1):void 0}function Ie(t){return E(t)||t?.smart_suggestion===!0}function Xe(t){return t.some(E)?t.filter(e=>!E(e)):t}function Je(t,e){return t.some(n=>E(n)&&!n.text)?t.map(n=>E(n)&&!n.text?{...n,text:e}:n):t}var Ze='<svg viewBox="0 0 20 20" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false"><path class="aia-sparkle-large" d="M8 5C8.5 9.5 10.5 11.5 15 12C10.5 12.5 8.5 14.5 8 19C7.5 14.5 5.5 12.5 1 12C5.5 11.5 7.5 9.5 8 5Z"/><path class="aia-sparkle-small" d="M16 1C16.2 3 17 3.8 19 4C17 4.2 16.2 5 16 7C15.8 5 15 4.2 13 4C15 3.8 15.8 3 16 1Z"/></svg>';function et(t){return t.some(e=>!E(e))}function xr(t,e){let n=0,r=e;for(let i of t)n+=i.value.length,i.type!=="text"&&(r=Math.max(r,n));return r}function vr(t,e){let n=0;for(let r of t){let i=n+r.value.length;if(r.type==="text"&&i>e&&r.value.slice(Math.max(e-n,0)).trim().length>0)return!1;n=i}return!0}function Pr(t,e){let n=[],r=new Set;for(let i of[...t,...e])i.parameter==="placeholder"||E(i)||r.has(i.parameter)||(r.add(i.parameter),n.push({parameter:i.parameter,text:i.text}));return n}function Tr(t,e,n){if(t===e)return n;let r=Math.min(t.length,e.length),i=0;for(;i<r&&t[i]===e[i];)i++;if(i>=n)return n;let s=0;for(;s<r-i&&t[t.length-1-s]===e[e.length-1-s];)s++;return t.length-s<=n?n+(e.length-t.length):null}function tt(t,e){let n=[],r=[],i=0;for(let s of e){let o=V(t,s.text,i);if(o===-1){r.push(s);continue}n.push({start:o,end:o+s.text.length,param:s}),i=o+s.text.length}return{located:n,missing:r}}function ge(t,e){let{located:n}=tt(t,e);return n.length>0?n[n.length-1].end:0}function Er(t,e,n){let r=[],i=[],s=0;for(let o of n){let a=V(t,o.text,s,l=>!e.some(d=>l<d.end&&l+o.text.length>d.start));if(a===-1){i.push(o);continue}r.push({start:a,end:a+o.text.length,param:o}),s=a+o.text.length}return{located:r,missing:i}}function wr(t,e,n=[]){let r=tt(t,e).located,i=Er(t,r,n).located,s=[...r.map(d=>({start:d.start,end:d.end,segment:{type:"completed",value:d.param.text,param:d.param}})),...i.map(d=>({start:d.start,end:d.end,segment:{type:"identified",value:d.param.text,param:d.param}}))].sort((d,c)=>d.start-c.start),o=[],a=0;for(let d of s)d.start>a&&o.push({type:"text",value:t.slice(a,d.start)}),o.push(d.segment),a=d.end;let l=t.slice(a);return l&&o.push({type:"text",value:l}),o}function Cr(t,e){let{located:n,missing:r}=tt(t,e);return{valid:n.map(i=>i.param),invalid:r}}function Ae(t,e,n){let r=tt(t,e).located,{located:i,missing:s}=Er(t,r,n);return{valid:i.map(o=>o.param),invalid:s}}function Ir(t,e,n){let r=e?.endpoint??K,i=r.replace(/\/suggest(?=[?#]|$)/,`/starting-state/${encodeURIComponent(t)}${wo(n)}`);if(i!==r)return i.replace(/^https:\/\/([^/?#]+)/,(s,o)=>{let a=Ge.get(o);return a?`https://${a}`:s})}function wo(t){let e=t?.replace(/_/g,"-").toLowerCase()??"",[n,r=""]=e.split("-");return n!=="zh"?/^[a-z]{2,3}$/.test(n)?`/${n}`:"":/^[a-z]{4}$/.test(r)?r==="hant"?"/zh-TW":"/zh":["tw","hk","mo"].includes(r)?"/zh-TW":"/zh"}async function Ar(t){try{let e=await t;if(!e.ok)return null;let n=await e.json();return Array.isArray(n?.data?.suggestions)?n:null}catch{return null}}function Co(t){if(t instanceof Error)return t;try{return new Error(String(t))}catch{return new Error("Unknown error")}}var Io=100,Ao=300,Oo=2,nt=class{constructor(e,n,r,i,s,o,a,l,d,c={}){this.store=e;this.getApiConfig=n;this.getOptionOverrides=r;this.getMaskCompletedText=i;this.getOnError=s;this.getSessionId=o;this.getSource=a;this.getAdditionalContext=l;this.getLanguage=d;this.callbacks=c;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null;this.phraseExactMatch=!1}start(){this.doFetch("",[]);let e=this.store.get().text,n=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(r=>{(r.text!==e||r.completedParams!==n)&&(e=r.text,n=r.completedParams,this.scheduleFetch())})}isPhraseExactMatch(){return this.phraseExactMatch}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,n){this.abortController?.abort();let r=new AbortController;this.abortController=r;let i=++this.fetchVersion,s=this.store.get().text.length;try{this.callbacks.onRequest?.({query:this.store.get().text,signal:r.signal,isCurrent:()=>i===this.fetchVersion})}catch{}try{this.store.set({isLoading:!0,error:null});let o=this.store.get(),a=o.pendingSpan?Pr(o.pendingSpan.snapshot,o.actionableSuggestions):void 0,l=crypto.randomUUID(),d=e===""&&n.length===0&&o.skippedParams.length===0&&o.identifiedParams.length===0?this.startingStateUrl():void 0,c=d?await Ar(fetch(d,{signal:r.signal})):null;if(i!==this.fetchVersion)return;let u=c??await gr(e,n,{sessionId:this.getSessionId(),requestId:l,source:this.getSource(),maskCompletedText:this.getMaskCompletedText(),signal:r.signal,apiConfig:this.getApiConfig(),identifiedParams:o.identifiedParams,recentlySuggested:a,skippedParams:o.skippedParams,additionalContext:this.getAdditionalContext(),language:this.getLanguage(),currency:this.callbacks.getCurrency?.(),clientOptionParameters:Object.keys(this.getOptionOverrides()??{})});if(i!==this.fetchVersion)return;this.phraseExactMatch=u.meta?.phrase_exact_match===!0;let m=(u.data.suggestions??[]).find(E),p=m?[]:u.data.input??[],g=p.filter(P=>P.source==="identified").map(P=>({id:crypto.randomUUID(),parameter:P.parameter,text:P.text,...P.type?{type:P.type}:{}})),h=this.callbacks.isWordOpen?.()??!1,y=this.store.get().text.toLowerCase(),b=P=>h&&y.endsWith(P.text.toLowerCase()),f=g.filter(P=>!b(P));h&&this.callbacks.holdIdentified?.(g.filter(b));let S=m?[m]:Sr(u.data.suggestions??[],this.getOptionOverrides()),x=p,I=x[x.length-1],v=this.store.get().text,w,M;if(I?.state==="in_progress"){M=!0;let P=v.toLowerCase().lastIndexOf(I.text.toLowerCase());w=P!==-1?P:s}else M=!1,w=s;let O=S.filter(P=>P.parameter!=="placeholder")[0],L=null;if(O&&!E(O)&&!h&&!T(B(O))){let P=we(O.options,v,w,M,this.phraseExactMatch);P&&(L={id:crypto.randomUUID(),placeholder:"",parameter:$(P,O.parameter),text:P.text,value:P.value,kind:P.kind,suggestionParameter:O.parameter,suggestionValueType:O.type,suggestionPlaceholder:O.text,options:O.options??[],metadata:P.metadata,icon:P.icon,icon_svg:P.icon_svg,image_url:P.image_url},S=S.filter(W=>W!==O),this.callbacks.onAutoMatch?.({active:O,matched:P,rawQuery:e}))}let q=u.data.custom_fields??null,ne=this.callbacks.productsForResponse?.(q);this.store.set(P=>{let W=L?[...P.completedParams,L]:P.completedParams,hn=Ae(P.text,W,f).valid,bn=new Set(o.skippedParams.map(_=>_.id)),C=new Set(P.skippedParams.filter(_=>!bn.has(_.id)).map(_=>_.parameter));return{suggestions:C.size>0?S.filter(_=>_.parameter==="placeholder"||!C.has(_.parameter)):S,isLoading:!1,isReady:u.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:w,filterInProgress:M,identifiedParams:hn,customFields:q,traditionalAutocomplete:u.meta?.traditional_autocomplete===!0,...ne!==void 0?{products:ne}:{},...L?{completedParams:W}:{}}}),this.callbacks.onResponse?.({requestId:l,funnelTelemetry:u.meta?.funnel_telemetry===!0,visibleImpression:u.meta?.visible_impression===!0})}catch(o){let a=Co(o);i===this.fetchVersion&&(this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a))}finally{if(i===this.fetchVersion&&this.store.get().isLoading)try{this.store.set({isLoading:!1})}catch{}}}startingStateUrl(){let e=this.callbacks.getProductId?.();return e?Ir(e,this.getApiConfig(),ie(this.getLanguage())):void 0}attemptNow(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.attemptFetch(1,!0)}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.debounceTimer=setTimeout(()=>{this.attemptFetch(Oo)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},Io),this.slowDebounceTimer=setTimeout(()=>this.attemptFetch(1,!0,!0),Ao)}attemptFetch(e,n=!1,r=!1){let i=this.store.get();if(!i.text&&i.completedParams.length===0)return this.doFetch("",[]),!0;let s=this.callbacks.consumerTick?.(i,e)??"no";if(s==="asked")return!0;if(s==="owns")return!1;let o=i.suggestions.filter(v=>v.parameter==="placeholder").map(v=>v.text).join(" "),a=z(i.text,i.filterBase,o),l=Ee(i.text,a,i.filterInProgress),d=i.suggestions.filter(v=>v.parameter!=="placeholder"),c=E(d[0])?void 0:d[0],u=T(i.activeFormatType),p=(c&&!u?oe(c.options,l,i.traditionalAutocomplete):[]).filter(v=>v.is_tappable),g=c&&!u&&!this.callbacks.isWordOpen?.()?we(c.options,i.text,a,i.filterInProgress,this.phraseExactMatch)!==null:!1,h=l.trim().length>0,y=r&&i.products.length>0;if(p.length>0&&!g&&h&&!y||Ye(i.text,i.completedParams.length,o))return!1;let{rawQuery:b,completedParams:f}=R(i.text,i.completedParams),S=b.length<i.lastRawQuery.length,x=Math.abs(b.length-i.lastRawQuery.length),I=n&&b!==i.lastRawQuery;return S||x>=e||I?(this.doFetch(b,f),!0):!1}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ko="(hover: none) and (pointer: coarse)";var Lo="[data-aia-dropdown], [data-aia-input-wrapper]",Mo=["a[href]","button","input","select","textarea","label","summary","[contenteditable]:not([contenteditable='false'])","[role='button']","[role='link']","[tabindex]:not([tabindex='-1'])"].join(", "),rt=class{constructor(e,n){this.store=e;this.container=n;this.listening=!1;this.declined=!1;this.pressOutside=!1;this.pressWhileFocused=!1;this.recheckTimer=null;this.releaseTimer=null;this.onPointerDown=e=>{let n=e.composedPath(),r=this.isInside(n);this.pressOutside=!r;let i=this.store.get();this.pressWhileFocused=i.isFocused,!(r||!i.isFocused)&&(this.declined=n.some(s=>s instanceof Element&&s.matches(Mo)),this.declined&&i.dropdownHeld?this.store.set({dropdownHeld:!1}):!this.declined&&!i.dropdownHeld&&i.isDropdownOpen&&this.store.set({dropdownHeld:!0}))};this.onPointerCancel=()=>{this.pressOutside=!1,this.pressWhileFocused&&this.declined&&this.scheduleRecheck(),this.pressWhileFocused=!1};this.onPointerUp=e=>{let n=this.pressOutside&&!this.isInside(e.composedPath()),r=this.pressWhileFocused;if(this.pressOutside=!1,this.pressWhileFocused=!1,r){this.declined&&this.scheduleRecheck();return}!n||this.store.get().isFocused||(this.cancelRelease(),this.releaseTimer=setTimeout(()=>{this.releaseTimer=null;let i=this.store.get();i.dropdownHeld&&!i.isFocused&&this.store.set({dropdownHeld:!1})},150))};this.touchPrimary=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(ko):null,this.unsubscribe=e.subscribe(()=>this.sync())}dispose(){this.unsubscribe(),this.listen(!1),this.cancelRelease(),this.recheckTimer!==null&&clearTimeout(this.recheckTimer),this.recheckTimer=null}sync(){let e=this.store.get(),n=this.touchPrimary?.matches??!1;e.isFocused||(this.declined=!1),e.isDropdownOpen?e.isFocused&&!e.dropdownHeld&&!this.declined&&n&&this.store.set({dropdownHeld:!0}):e.dropdownHeld&&this.store.set({dropdownHeld:!1});let r=this.store.get();this.listen(n&&r.isDropdownOpen),r.isFocused&&this.cancelRelease()}listen(e){if(!(e===this.listening||typeof document>"u")){if(this.listening=e,e){document.addEventListener("pointerdown",this.onPointerDown,!0),document.addEventListener("pointerup",this.onPointerUp,!0),document.addEventListener("pointercancel",this.onPointerCancel,!0);return}document.removeEventListener("pointerdown",this.onPointerDown,!0),document.removeEventListener("pointerup",this.onPointerUp,!0),document.removeEventListener("pointercancel",this.onPointerCancel,!0),this.pressOutside=!1}}scheduleRecheck(){this.recheckTimer!==null&&clearTimeout(this.recheckTimer),this.recheckTimer=setTimeout(()=>{this.recheckTimer=null,!(!this.declined||!this.store.get().isFocused)&&(this.declined=!1,this.sync())},150)}cancelRelease(){this.releaseTimer!==null&&(clearTimeout(this.releaseTimer),this.releaseTimer=null)}isInside(e){let n=this.container,r=n?.getRootNode(),i=typeof ShadowRoot<"u"&&r instanceof ShadowRoot?r.host:null;for(let s of e)if(s===n||s===i||s instanceof Element&&s.matches(Lo))return!0;return!1}};var fe=["January","February","March","April","May","June","July","August","September","October","November","December"],Oe=["S","M","T","W","T","F","S"],Lr=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Mr="aiaDate",Rr="aiaDay",Or=t=>String(t).padStart(2,"0");function H(t){return`${t.getFullYear()}-${Or(t.getMonth()+1)}-${Or(t.getDate())}`}function vn(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}function Ro(t){let e=vn(t).getTime()-vn(new Date).getTime();return Math.round(e/864e5)}function Pn(t){let e=Ro(t);return e>=0&&e<7?Lr[t.getDay()]:se(t)}function se(t){return t.getFullYear()===new Date().getFullYear()?`${fe[t.getMonth()]} ${t.getDate()}`:`${fe[t.getMonth()]} ${t.getDate()} ${t.getFullYear()}`}function ke(t){if(!t)return null;let e=Lr.findIndex(a=>a.toLowerCase()===t.trim().toLowerCase());if(e>=0){let a=vn(new Date),l=(e-a.getDay()+7)%7;return new Date(a.getFullYear(),a.getMonth(),a.getDate()+l)}let n=/^\s*([A-Za-z]+)\s+(\d{1,2})(?:\s+(\d{4}))?\s*$/.exec(t);if(!n)return null;let r=fe.findIndex(a=>a.toLowerCase()===n[1].toLowerCase());if(r<0)return null;let i=Number(n[2]),s=n[3]?Number(n[3]):new Date().getFullYear(),o=new Date(s,r,i);return o.getMonth()!==r||o.getDate()!==i?null:o}function it(t){return`${fe[t.month]} ${t.year}`}function Tn(){let t=new Date;return{year:t.getFullYear(),month:t.getMonth()}}function Dr(t){return{year:t.getFullYear(),month:t.getMonth()}}function ot(t,e){let n=new Date(t.year,t.month+e,1);return{year:n.getFullYear(),month:n.getMonth()}}function kr(){return{text:"",is_tappable:!1,kind:null}}function st(t){let e=new Date(t.year,t.month,1).getDay(),n=new Date(t.year,t.month+1,0).getDate(),r=[];for(let i=0;i<e;i++)r.push(kr());for(let i=1;i<=n;i++){let s=new Date(t.year,t.month,i);r.push({text:Pn(s),is_tappable:!0,kind:null,metadata:{[Mr]:H(s),[Rr]:i}})}for(;r.length%Oe.length!==0;)r.push(kr());return r}function at(t){let e=ke(t);return e?H(e):null}function G(t){let e=t?.metadata?.[Mr];return typeof e=="string"?e:null}function lt(t){let e=t?.metadata?.[Rr];return typeof e=="number"?e:null}function Do(t){return t.nodeType===Node.DOCUMENT_NODE?!0:t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in t}function ae(t){let e=typeof t.getRootNode=="function"?t.getRootNode():null;return e&&Do(e)?e:t.ownerDocument??t}function N(t){return t.ownerDocument??t}function _o(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function _r(t){let e=ae(t);return!_o(e)||typeof e.getSelection=="function"?null:e}function Nr(t){let e=_r(t);if(!e)return null;let n=N(t).getSelection?.();return!n||typeof n.getComposedRanges!="function"?null:e}function Hr(t,e){let n=t,r;try{r=n.getComposedRanges({shadowRoots:[e]})}catch{r=n.getComposedRanges(e)}return r.length>0?r[0]:null}function En(t){let n=ae(t).getSelection?.();return n||(N(t).getSelection?.()??null)}function j(t){let e=En(t);if(!e||e.rangeCount===0)return null;let n=Nr(t);if(n){let r=Hr(e,n);return r?{node:r.startContainer,offset:r.startOffset,collapsed:r.startContainer===r.endContainer&&r.startOffset===r.endOffset}:null}return e.anchorNode?{node:e.anchorNode,offset:e.anchorOffset,collapsed:e.isCollapsed}:null}function dt(t){let e=En(t);if(!e||e.rangeCount===0)return null;let n=Nr(t);if(!n)return e.getRangeAt(0);let r=Hr(e,n);if(!r)return null;let i=N(t).createRange();return i.setStart(r.startContainer,r.startOffset),i.setEnd(r.endContainer,r.endOffset),i}function Le(t,e,n){let r=En(t);if(!r)return null;if(_r(t))return r.collapse(e,n),r;let i=N(t).createRange();return i.setStart(e,n),i.collapse(!0),r.removeAllRanges(),r.addRange(i),r}function ct(t,e){let n=t?ae(t):typeof document<"u"?document:null;return n?typeof n.getElementById=="function"?n.getElementById(e):typeof document<"u"?document.getElementById(e):null:null}var ut=2,No="magicx-aia";function Fr(t){return t==="auto"||t==="scroll"||t==="hidden"||t==="overlay"}function Ho(t){let e=N(t),n=e.defaultView;if(!n?.getComputedStyle)return null;let r=t;for(;r&&r!==e.body&&r!==e.documentElement;){let i=r.scrollWidth>r.clientWidth,s=r.scrollHeight>r.clientHeight;if(i||s){let o=n.getComputedStyle(r);if(i&&Fr(o.overflowX)||s&&Fr(o.overflowY))return r}if(r.classList.contains(No))return null;r=r.parentElement}return null}function pt(t){let e=dt(t);if(!e||!e.collapsed||!t.contains(e.startContainer))return;let n=Ho(t);if(!n||typeof e.getBoundingClientRect!="function")return;let r=e.getBoundingClientRect();if(r.height===0)return;let i=n.getBoundingClientRect();if(n.scrollWidth>n.clientWidth){let s=i.left+n.clientLeft,o=s+n.clientWidth;r.right>o?n.scrollLeft+=r.right-o+ut:r.left<s&&(n.scrollLeft-=s-r.left+ut)}if(n.scrollHeight>n.clientHeight){let s=i.top+n.clientTop,o=s+n.clientHeight;r.bottom>o?n.scrollTop+=r.bottom-o+ut:r.top<s&&(n.scrollTop-=s-r.top+ut)}}var Br='[contenteditable="false"]',Cn="strong[data-param-id]",he;function Fo(){if(he!==void 0)return he;let t=globalThis.Intl.Segmenter;if(!t)return he=null,null;try{he=new t(void 0,{granularity:"grapheme"})}catch{he=null}return he??null}function mt(t,e){let n=t;for(;n&&n!==e;){if(n.nodeType===Node.ELEMENT_NODE&&n.matches(Br))return!0;n=n.parentNode}return!1}function gt(t){return N(t).createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(e){return mt(e,t)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function Me(t){let e=gt(t),n="",r=e.nextNode();for(;r;)n+=r.data,r=e.nextNode();return n}function ft(t){let e=gt(t),n=0,r=e.nextNode();for(;r;)n+=r.data.length,r=e.nextNode();return n}function F(t){let e=j(t);if(!e)return null;let n=e.node,r=e.offset;if(!t.contains(n))return null;if(n.nodeType===Node.ELEMENT_NODE){let i=n;if(mt(i,t)&&i!==t)return null;let s=0;for(let o=0;o<r&&o<i.childNodes.length;o++)s+=In(i.childNodes[o],t);return s+wn(i,t)}return n.nodeType!==Node.TEXT_NODE||mt(n,t)?null:wn(n,t)+r}function In(t,e){if(t.nodeType===Node.TEXT_NODE)return mt(t,e)?0:t.data.length;if(t.nodeType!==Node.ELEMENT_NODE)return 0;let n=t;if(n.matches(Br))return 0;let r=0;for(let i of Array.from(n.childNodes))r+=In(i,e);return r}function wn(t,e){let n=gt(e),r=0,i=n.nextNode();for(;i;){if(i===t||t.nodeType===Node.ELEMENT_NODE&&t.contains(i))return r;r+=i.data.length,i=n.nextNode()}return r}function D(t,e){let n=N(t),r=Math.max(0,Math.min(e,ft(t))),i=gt(t),s=0,o=null,a=0,l=i.nextNode(),d=null;for(;l;){let u=l.data.length;if(r<s+u){o=l,a=r-s;break}if(r===s+u){let m=i.nextNode();m?(o=m,a=0):(o=l,a=u);break}s+=u,d=l,l=i.nextNode()}let c=n.createRange();if(o){let u=o.parentElement?.closest('strong[data-seg="completed"]');u&&u!==t&&t.contains(u)?a===0?c.setStartBefore(u):a===o.data.length?c.setStartAfter(u):c.setStart(o,a):c.setStart(o,a)}else d?c.setStart(d,d.data.length):c.setStart(t,0);c.collapse(!0),Le(t,c.startContainer,c.startOffset)&&(Wo(t,c,r),pt(t))}function Wr(t,e){if(!t||!e.contains(t))return null;let r=(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(Cn)??null;return r&&e.contains(r)?r:null}function Wo(t,e,n){let r=Wr(j(t)?.node??null,t);if(r&&r!==Wr(e.startContainer,t)){t.dataset.aiaCaretEscapedChip=`${n}:${r.dataset.paramId}`;return}delete t.dataset.aiaCaretEscapedChip}function Ur(t,e){let n=t.dataset.aiaCaretEscapedChip;if(!n)return!1;let r=F(t);return r!==null&&n===`${r}:${e}`}function $r(t){return ae(t).activeElement===t}function ht(t,e){if(!e||e.nodeType===void 0)return null;let n=e,i=(n.nodeType===Node.ELEMENT_NODE?n:n.parentElement)?.closest(Cn);if(!i||!t.contains(i))return null;let s=j(t);return s&&!s.collapsed?null:i.dataset.paramId??null}function bt(t,e){let n=null;for(let o of t.querySelectorAll(Cn))if(o.dataset.paramId===e){n=o;break}if(!n)return;let r=wn(n,t),i=r+In(n,t),s=F(t);s!=null&&s>=r&&s<=i||D(t,r)}function St(t){let e=F(t);return e==null?!1:e>=ft(t)}function yt(t,e){if(e<=0)return 0;let n=Fo();if(!n)return e-1;let r=t.slice(0,e),i=0;for(let{index:s}of n.segment(r))s<e&&(i=s);return i}function Y(t,e,n=[],r={}){let{rawQuery:i,completedParams:s}=R(t,e);return{query:t.trim(),raw_query:i,completed_params:me(s,n),identified_params:pe(r.identifiedParams??[]),is_ready:r.isReady??!1,...r.customFields?{custom_fields:r.customFields}:{}}}function An(t,e){return t instanceof HTMLTextAreaElement||t instanceof HTMLInputElement?t.selectionStart!=null&&t.selectionStart===t.value.length:t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?St(t):e?.caretOffset!=null?e.caretOffset>=e.text.length:!1}function On(t){return t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?F(t):null}var xt=class{constructor(e,n){this.store=e;this.ctx=n}handleKeyDown(e){if(e.isComposing||e.keyCode===229)return;let n=this.store.get(),{listboxId:r,getOnSubmit:i}=this.ctx,s=e.target instanceof Node?e.target:null,o=this.getEffectiveColumns(s),a=i(),l=this.getTappableIndices(o);if((e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)&&(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return;let d=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let c=An(e.target,n),u=!!n.editingParam;if(!c&&!u&&n.activeDropdownIndex<0)break;if(n.activeDropdownIndex<0){if(d)break;e.preventDefault();let g=T(n.activeFormatType)?this.dateEntryIndex(n,!1):l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:g});break}if(l.length===0)return;this.store.set({activeDropdownIndex:g});break}if(e.preventDefault(),l.length===0)return;if(T(n.activeFormatType)){this.stepDateWeek(n,7);break}if(n.filteredOptions.length>0){let g=Math.floor((n.filteredOptions.length-1)/o);if(Math.floor(n.activeDropdownIndex/o)===g){this.store.set({activeDropdownIndex:-1});break}}let m=l.indexOf(n.activeDropdownIndex),p=m<l.length-1?m+1:0;this.store.set({activeDropdownIndex:l[p]});break}case"ArrowUp":{if(n.activeDropdownIndex<0){if(!d)break;let m=An(e.target,n),p=!!n.editingParam;if(!m&&!p)break;e.preventDefault();let g=T(n.activeFormatType)?this.dateEntryIndex(n,!0):this.firstTappableInBottomRow(o)??l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:g});break}if(l.length===0)return;this.store.set({activeDropdownIndex:g});break}if(l.length===0)break;if(e.preventDefault(),T(n.activeFormatType)){this.stepDateWeek(n,-7);break}if(n.activeDropdownIndex<o){this.store.set({activeDropdownIndex:-1});break}let c=l.indexOf(n.activeDropdownIndex),u=c>0?c-1:l.length-1;this.store.set({activeDropdownIndex:l[u]});break}case"ArrowRight":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),T(n.activeFormatType)){this.stepDateDay(n,1);break}if(n.activeDropdownIndex%o<o-1){let m=n.activeDropdownIndex+1;m<n.filteredOptions.length&&n.filteredOptions[m]?.is_tappable&&this.store.set({activeDropdownIndex:m})}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){e.preventDefault();let u=e.target.closest("[data-aia-input]")??e.target,m=n.editingTail;this.ctx.exitEditMode?.(),D(u,m);break}An(e.target,n)&&n.actionableSuggestions.length>=1&&(e.preventDefault(),this.ctx.skipActivePill());break}case"ArrowLeft":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),T(n.activeFormatType)){this.stepDateDay(n,-1);break}if(n.activeDropdownIndex%o>0){let c=n.activeDropdownIndex-1;c>=0&&n.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c});break}if(!n.editingParam&&this.ctx.startEditingParamAtCaret){let c=On(e.target);c!=null&&this.ctx.startEditingParamAtCaret(c)}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingAnchor!=null){e.preventDefault();let c=e.target.closest("[data-aia-input]")??e.target,u=n.editingAnchor;this.ctx.exitEditMode?.(),D(c,u);break}if(this.ctx.startEditingParamAtCaret){let c=On(e.target);c!=null&&this.ctx.startEditingParamAtCaret(c)&&e.preventDefault()}break}case"Backspace":{if(n.editingParam||!this.ctx.removeParamAtCaret)break;let c=On(e.target);if(c==null)break;this.ctx.removeParamAtCaret(c)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),n.activeDropdownIndex>=0&&n.filteredOptions[n.activeDropdownIndex]?.is_tappable)this.clickOrSelect(n.activeDropdownIndex,n.filteredOptions,r,s);else if(a){this.ctx.endTypedWord?.(!0);let c=this.store.get();a(Y(c.text,c.completedParams,c.skippedParams,{identifiedParams:c.identifiedParams,isReady:c.isReady,customFields:c.customFields}))&&this.ctx.afterSubmit?.()}break}case"Tab":{if(this.ctx.endTypedWord?.()){e.preventDefault();break}let c=n.filteredOptions.map((p,g)=>p.is_tappable?g:-1).filter(p=>p!==-1);if(c.length===0)break;if(!n.isDropdownOpen){if(n.actionableSuggestions.length===0)break;e.preventDefault();let p=e.shiftKey?c[c.length-1]:c[0];this.store.set({pillTapped:!0,activeDropdownIndex:p});break}e.preventDefault();let u=c.indexOf(n.activeDropdownIndex),m;if(u<0)m=e.shiftKey?c.length-1:0;else{let p=e.shiftKey?-1:1;m=(u+p+c.length)%c.length}this.store.set({activeDropdownIndex:c[m]});break}case"Escape":{if(n.dateRangeStart){this.store.set({pendingRangeStart:null});break}if(n.editingIdentified){this.ctx.exitEditingIdentified?.(),this.store.set({activeDropdownIndex:-1});break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){let c=e.target.closest("[data-aia-input]")??e.target,u=n.editingTail;this.ctx.exitEditMode?.(),D(c,u)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let n=this.store.get();if(n.filteredOptions.length===0)return null;let i=Math.floor((n.filteredOptions.length-1)/e)*e;for(let s=i;s<n.filteredOptions.length;s++)if(n.filteredOptions[s]?.is_tappable)return s;return null}dateEntryIndex(e,n){let r=H(new Date),i=e.filteredOptions.findIndex(o=>G(o)===r);if(i>=0)return i;let s=e.filteredOptions.map((o,a)=>o.is_tappable?a:-1).filter(o=>o!==-1);return(n?s[s.length-1]:s[0])??0}stepDateDay(e,n){for(let r=e.activeDropdownIndex+n;r>=0&&r<e.filteredOptions.length;r+=n)if(e.filteredOptions[r]?.is_tappable){this.store.set({activeDropdownIndex:r});return}}stepDateWeek(e,n){let r=e.activeDropdownIndex+n;this.store.set({activeDropdownIndex:e.filteredOptions[r]?.is_tappable?r:-1})}getTappableIndices(e){let r=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),i=Array.from({length:e},()=>[]);for(let s of r)i[s%e].push(s);return i.flat()}getEffectiveColumns(e){let n=ct(e,this.ctx.listboxId);if(!n)return this.ctx.columns;let i=ct(e,`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let s=getComputedStyle(i).gridTemplateColumns;if(s&&s!=="none"){let o=s.split(" ").filter(Boolean).length;if(o>0)return o}if(i===n)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,n,r,i){let s=ct(i,`${r}-option-${e}`);s?s.click():this.ctx.selectOption(n[e])}};var vt=class{constructor(e,n,r={}){this.store=e;this.getOverrides=n;this.callbacks=r;this.unsubscribe=null;this.current=null;this.version=0;this.lastMiss=null;this.hasLoggedError=!1}start(){this.unsubscribe=this.store.subscribe(e=>this.sync(e)),this.sync(this.store.get())}dispose(){this.unsubscribe?.(),this.unsubscribe=null,this.cancel(),this.current=null}reset(){this.cancel(),this.current=null,this.lastMiss=null}refresh(){this.reset(),this.sync(this.store.get())}hasOverride(e){return!!this.getOverrides()?.[e]}owns(e,n){return this.hasOverride(e)&&!this.missCovers(e,n)}tick(e,n){let r=this.resolveTarget(e);if(!r||this.missCovers(r.parameter,r.query))return"no";let i=this.current;if(i&&i.key===r.key){if(i.query===r.query)return"owns";let s=Math.abs(r.query.length-i.query.length),o=r.query.length<i.query.length;if(n>1&&!o&&s<n)return"owns"}return this.ask(r),"asked"}sync(e){let n=this.resolveTarget(e);if(!n){this.current&&(this.cancel(),this.current=null),e.optionSearch&&this.store.set({optionSearch:null});return}this.current&&this.current.key===n.key||this.ask(n)}resolveTarget(e){if(T(e.activeFormatType)||e.editingIdentified)return null;let n=e.editingParam;if(n&&e.editingAnchor!=null)return this.hasOverride(n.suggestionParameter)?{mode:"edit",key:n.id,parameter:n.suggestionParameter,suggestion:{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options},query:e.optionQuery}:null;let r=e.actionableSuggestions[0];return!r||!this.hasOverride(r.parameter)?null:{mode:"pill",key:r,parameter:r.parameter,suggestion:r,query:e.optionQuery}}missCovers(e,n){return this.lastMiss!=null&&this.lastMiss.parameter===e&&this.lastMiss.query===n}ask(e){this.cancel();let n=this.getOverrides()?.[e.parameter],r=++this.version;if(!n||this.missCovers(e.parameter,e.query)){this.current={key:e.key,parameter:e.parameter,query:e.query,abort:null},this.setSearch(e,"done");return}let i=new AbortController;this.current={key:e.key,parameter:e.parameter,query:e.query,abort:i};let s;try{s=n(e.query,i.signal,e.suggestion)}catch(o){this.logOnce(o),this.commit(e,[],r);return}if(Array.isArray(s)){this.commit(e,s,r);return}this.setSearch(e,"loading"),this.await(e,s,i.signal,r)}async await(e,n,r,i){let s;try{let o=await n;if(r.aborted||i!==this.version)return;s=Array.isArray(o)?o:[]}catch(o){if(r.aborted||i!==this.version||Bo(o))return;this.logOnce(o),s=[]}this.commit(e,s,i)}commit(e,n,r){if(r!==this.version)return;let i=this.resolveTarget(this.store.get());if(!i||i.key!==e.key)return;n.length===0?this.lastMiss={parameter:e.parameter,query:e.query}:this.lastMiss?.parameter===e.parameter&&(this.lastMiss=null);let s={parameter:e.parameter,query:e.query,status:"done"};if(e.mode==="edit")this.store.set(o=>({editingParam:o.editingParam&&o.editingParam.id===e.key?{...o.editingParam,options:n}:o.editingParam,optionSearch:s}));else{let o={...e.suggestion,options:n};this.current&&this.current.key===e.key&&(this.current.key=o),this.store.set(a=>({suggestions:a.suggestions.map(l=>l===e.suggestion?o:l),optionSearch:s}))}n.length===0?this.callbacks.onMiss?.(e.mode,e.query):this.callbacks.onAnswer?.(e.mode,e.query)}setSearch(e,n){let r=this.store.get().optionSearch;r&&r.parameter===e.parameter&&r.query===e.query&&r.status===n||this.store.set({optionSearch:{parameter:e.parameter,query:e.query,status:n}})}cancel(){this.current?.abort?.abort(),this.version++}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] an optionOverrides entry threw or rejected \u2014 treated as no options. Later failures on this instance are not logged.",e))}};function Bo(t){return t instanceof Error&&t.name==="AbortError"}var Pt=class{constructor(e,n={}){this.store=e;this.callbacks=n}setActivePill(e){let n=this.store.get(),r=n.suggestions.filter(d=>d.parameter!=="placeholder");if(e<0||e>=r.length)return;let i=r[e];if(E(i))return;let s=r.filter((d,c)=>c!==e),o=n.suggestions.filter(d=>d.parameter==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:d}=R(n.text,n.completedParams);this.callbacks.onPillSelected({rawQuery:d,selectedPill:i.text,otherPills:s.map(c=>c.text)})}let a=[...o,i,...s],l=this.store.peek({suggestions:a}).filteredOptions.findIndex(d=>d.is_tappable);this.store.set({suggestions:a,pillTapped:!0,activeDropdownIndex:l})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(n=>({completedParams:n.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};var kn="/products/",Gr="https://relative.invalid";function Uo(t){if(!t)return;let e;try{e=new URL(t,`${Gr}/`)}catch{return}if(!(e.protocol!=="http:"&&e.protocol!=="https:"))return t.startsWith("/")?e.origin===Gr?t:void 0:/^https?:\/\//i.test(t)?t:void 0}function Ln(t,e){let n=Uo(t.item_url)??Go(t);return{id:t.source_id,title:t.title,...n&&{url:n},imageUrl:t.image_url||null,...t.price&&{price:$o(t.price,t.currency,e)},...t.vendor&&{vendor:t.vendor},...typeof t.available=="boolean"&&{available:t.available}}}function $o(t,e,n){if(n===void 0||!e||!/^\d+(\.\d+)?$/.test(t))return t;try{return new Intl.NumberFormat(n,{style:"currency",currency:e}).format(Number(t))}catch{return t}}function Go(t){if(!t.handle)return;let e=`${kn}${encodeURIComponent(t.handle)}`;return t.variant_id?`${e}?variant=${encodeURIComponent(t.variant_id)}`:e}function Tt(t,e){return(t?.items.matched??[]).map(n=>Ln(n,e))}var Et=class{constructor(e,n,r=()=>!0,i=()=>{},s=()=>{}){this.store=e;this.getConfig=n;this.isEnabled=r;this.getLanguage=i;this.getMapper=s;this.hasLoggedError=!1;this.hasLoggedMapperError=!1}forResponse(e){if(!this.isEnabled())return[];if(this.getConfig())return;let n=Tt(e,ie(this.getLanguage())),r=this.getMapper();if(!r)return n;try{let i=r(n,e?.items.matched??[]);if(Array.isArray(i))return i}catch(i){this.hasLoggedMapperError||(this.hasLoggedMapperError=!0,console.warn("[AIAutocomplete] mapProducts failed. The original cards are shown.",i))}return n}async run(e,n,r){if(!this.isEnabled())return;let i=this.getConfig();if(!i)return;if(e.trim().length===0){this.clear(r);return}let s=()=>n.aborted||!r()||!this.owns(i);try{let o=await i.fetch(e,n);if(s())return;let a=i.transform(o),l=Array.isArray(a)?a:[],d=i.limit!=null?l.slice(0,i.limit):l;if(s())return;this.commit(d)}catch(o){if(n.aborted||Vo(o)||(this.logOnce(o),s()))return;this.clear(r)}}owns(e){return this.isEnabled()&&this.getConfig()===e}resync(){let e=this.forResponse(this.store.get().customFields);this.commit(e??[])}refresh(){if(this.getConfig())return;let e=this.forResponse(this.store.get().customFields);e!==void 0&&this.commit(e)}clear(e){e()&&this.commit([])}commit(e){e.length===0&&this.store.get().products.length===0||this.store.set({products:e})}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] products.fetch/transform failed \u2014 the product strip is hidden. Later failures on this instance are not logged.",e))}};function Vo(t){return t instanceof Error&&t.name==="AbortError"}function qo(t){return t.replace(/(\d+)(?:st|nd|rd|th)\b/g,"$1")}function Vr(t){let e=t.toLowerCase().replace(/\.$/,"");return e.length<3?-1:fe.findIndex(n=>n.toLowerCase().startsWith(e))}function Ko(t,e,n){let r=new Date(n.getFullYear(),t,e);if(r.getMonth()!==t||r.getDate()!==e)return null;let i=new Date(n.getFullYear(),n.getMonth(),n.getDate());if(r>=i)return r;let s=new Date(n.getFullYear()+1,t,e);return s.getMonth()===t&&s.getDate()===e?s:null}function qr(t,e,n){let r=new Date(t,e,n);return r.getMonth()===e&&r.getDate()===n?r:null}function be(t,e={}){if(!t)return null;let n=e.today??new Date,r=qo(t.trim().toLowerCase()).replace(/\s+/g," "),i=/^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(r);if(i){let l=qr(Number(i[1]),Number(i[2])-1,Number(i[3]));return l?H(l):null}let s=/^([a-z]+)\.? (\d{1,2})(?:,? (\d{4}))?$/.exec(r);if(s){let l=Vr(s[1]);if(l>=0)return wt(l,Number(s[2]),s[3],n)}let o=/^(\d{1,2}) (?:of )?([a-z]+)\.?(?:,? (\d{4}))?$/.exec(r);if(o){let l=Vr(o[2]);if(l>=0)return wt(l,Number(o[1]),o[3],n)}let a=/^(\d{1,2})[/\-.](\d{1,2})(?:[/\-.](\d{2,4}))?$/.exec(r);if(a){let l=Number(a[1]),d=Number(a[2]);return l>12&&d<=12?wt(d-1,l,a[3],n):d>12&&l<=12?wt(l-1,d,a[3],n):null}return null}function wt(t,e,n,r){if(n){if(n.length!==4)return null;let s=qr(Number(n),t,e);return s?H(s):null}let i=Ko(t,e,r);return i?H(i):null}function Ct(t,e={}){let n=t.isoDate;return typeof n=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(n)?n:be(t.text,e)}var Rn=" - ",It="aiaDateRangeStart",At="aiaDateRangeEnd";function Re(t,e){return t<=e?{start:t,end:e}:{start:e,end:t}}var Mn=/^\d{4}-\d{2}-\d{2}$/;function Kr(t){if(!Mn.test(t))return null;let[e,n,r]=t.split("-").map(Number),i=new Date(e,n-1,r);return i.getMonth()===n-1&&i.getDate()===r?i:null}var zo=/\s+(?:to|through|thru|until|til|till)\s+/g,jo=/[-–—]/g;function Yo(t){let e=[];for(let n of[zo,jo]){n.lastIndex=0;let r=n.exec(t);for(;r!==null;)e.push([t.slice(0,r.index),t.slice(r.index+r[0].length)]),r=n.exec(t)}return e}function De(t,e={}){if(!t)return null;let n=new Set,r=null;for(let[i,s]of Yo(t.trim())){let o=be(i.trim(),e);if(!o)continue;let a=be(s.trim(),e);!a||a<o||(n.add(`${o}|${a}`),r={start:o,end:a})}return n.size===1?r:null}function Dn(t){let e=Kr(t.start),n=Kr(t.end);return!e||!n?"":t.start===t.end?se(e):`${se(e)}${Rn}${se(n)}`}function zr(t,e){let n=Re(t,e);return{text:Dn(n),is_tappable:!0,kind:null,metadata:{[It]:n.start,[At]:n.end}}}function Se(t,e={}){let n=t?.metadata?.[It],r=t?.metadata?.[At];return typeof n=="string"&&typeof r=="string"&&Mn.test(n)&&Mn.test(r)?Re(n,r):De(t?.text,e)}var _e="(max-width: 768px)";var Qo="var(--aia-option-row-height, 37px)",Xo="var(--aia-grid-scroll-top, 0px) + var(--aia-grid-scroll-bottom, 0px)";function Nn(t,e){return e?_n(1,Math.min(t,5)):_n(1,Math.min(t,4))}function _n(t,e){return{cols:t,rows:e,maxHeight:`calc(${e} * ${Qo} + ${Xo})`}}function kt(t,e){return!e&&t>=5}function Lt(t,e,n,r){if(!(!e&&t>=5&&Jo(n,r))){let o=Nn(t,e);return{...o,template:Ot(o.cols),scrollHintIndices:!e&&t>o.rows?[o.rows-1]:[]}}let s=6;return{..._n(2,3),template:Ot(2),scrollHintIndices:t>s?[s-2,s-1]:[]}}function Jo(t,e){return!t||t.length===0||e==null||e<=0||t.some(r=>r<=0)?!1:Math.ceil(Math.max(...t))*2<=e}function Mt(t){if(typeof document>"u")return null;let e=Array.from(t.querySelectorAll("[data-aia-option]"));if(e.length===0)return null;let n=document.createElement("div");n.style.cssText="position:absolute;visibility:hidden;left:-9999px;top:0;";for(let o of e){let a=o.cloneNode(!0);a.removeAttribute("id"),a.removeAttribute("role"),a.removeAttribute("aria-selected"),a.style.whiteSpace="nowrap",a.style.width="max-content",n.appendChild(a)}t.appendChild(n);let r=Array.from(n.children).map(o=>o.offsetWidth);n.remove();let i=getComputedStyle(t),s=t.clientWidth-(Number.parseFloat(i.paddingLeft)||0)-(Number.parseFloat(i.paddingRight)||0)-(Number.parseFloat(i.columnGap)||0);return{rowWidths:r,gridWidth:s}}function Ot(t){return Array.from({length:t},()=>"minmax(0,1fr)").join(" ")}function Rt(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia(_e).matches}function Dt(t,e){return!t||t.length!==e.length?!1:t.every((n,r)=>n.text===e[r].text)}function jr(t,e){let n=e.dropdownTrigger??"auto",r=e.closeDropdownOnBlur??!0,o=t.filteredOptionsLength>0||t.activePillHasNoOptions||t.hasProducts;if(t.inEditMode){let a=r?t.isFocused||t.dropdownHeld:!0;return o&&a}if(n==="auto"){let a=r?t.isFocused||t.dropdownHeld:!0,l=t.text.replace(/\s+$/,"").length,d=t.caretOffset==null||t.caretOffset>=l;return(o||t.isLoading)&&a&&d}return n==="manual"?(o||t.isLoading)&&t.pillTapped:!1}function Ne(t){if(t.editingIdentified){let{parameter:n,anchor:r}=t.editingIdentified;return`identified:${n}@${r}`}return t.editingParam!=null&&t.editingAnchor!=null?`edit:${t.editingParam?.id}`:`pill:${t.actionableSuggestions[0]?.parameter??""}`}function Yr(t){if(!t)return Tn();let[e,n]=t.split("-").map(Number);return{year:e,month:n-1}}function Zo(t){let e=ke(t);return e?Dr(e):Tn()}function Qr(t,e){let n=wr(t.text,t.completedParams,t.identifiedParams),r=t.suggestions.filter(C=>C.parameter!=="placeholder"),i=r[0],s=t.suggestions.filter(C=>C.parameter==="placeholder").map(C=>C.text).join(" "),o=z(t.text,Math.min(t.filterBase,t.text.length),s),l=o===0&&Ye(t.text,t.completedParams.length,s)?"":Ee(t.text,o,t.filterInProgress),d=i?.options??[],c=t.editingParam!=null&&t.editingAnchor!=null,u,m,p,g;if(c&&t.editingParam&&t.editingAnchor!=null){let C=t.editingParam.id,re=t.completedParams.some(lo=>lo.id===C),_=t.caretOffset??t.editingAnchor,cr=re?"":t.text.slice(t.editingAnchor,_);m=cr.trim(),p=t.editingParam.options,g=t.editingParam.suggestionParameter,u=oe(t.editingParam.options,cr)}else m=l.trim(),p=d,g=i?.parameter,u=E(i)?d.map(C=>({...C,matchedText:t.text.slice(ge(t.text,t.completedParams)),parameterLabel:yr(C.parameter)})):oe(d,l,t.traditionalAutocomplete);let h=t.optionSearch,y=h!=null&&g!=null&&h.parameter===g;y&&h.status==="done"&&h.query===m&&(u=p);let b=y&&h.status==="loading",f=e.showNonTappableOptions===!1;f&&(u=u.filter(C=>C.is_tappable));let S=t.editingIdentified,x=c?t.editingParam&&{type:t.editingParam.suggestionValueType}:i,I=S?S.format:B(x),v=c&&I==="date-range"?Se(t.editingParam):null,w=null,M=null;if(T(I)){let C=Ne({...t,actionableSuggestions:r}),re=t.dateViewMonth;w=re&&re.key===C?{year:re.year,month:re.month}:S?Yr(S.iso):v?Yr(v.start):Zo(t.editingParam?.text),u=st(w);let _=t.pendingRangeStart;I==="date-range"&&_&&_.key===C&&(M=_.iso)}let A=C=>f?C.is_tappable:!0,O;if(c){let C=t.editingParam?.options??[];O=t.editingParam!=null&&C.filter(A).length===0}else O=i!=null&&d.filter(A).length===0;let L=jr({inEditMode:c||S!=null,filteredOptionsLength:u.length,isFocused:t.isFocused,dropdownHeld:t.dropdownHeld,text:t.text,caretOffset:t.caretOffset,isLoading:t.isLoading||b,pillTapped:t.pillTapped,activePillHasNoOptions:O,hasProducts:t.products.length>0},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur}),q=L&&t.activeDropdownIndex>=0&&!!u[t.activeDropdownIndex]?.is_tappable,ne=t.skeletonOptions!==null&&t.skeletonRequested&&!t.isLoading&&!t.editingParam&&!t.inSelectionAnimation,P=t.isLoading&&!t.editingParam&&!t.inSelectionAnimation||b||ne,W=P&&t.skeletonOptions!==null,hn=W&&t.skeletonOptions?t.skeletonOptions:u,bn=W?t.skeletonSuggestion:null;return{segments:n,actionableSuggestions:r,filteredOptions:u,dropdownLoading:P,dropdownOptions:hn,dropdownSuggestion:bn,skeletonExiting:ne,activeFormatType:I,dateView:w,dateRangeStart:M,placeholderText:s,optionQuery:m,isSearchingOptions:b,isDropdownOpen:L,isActivePillSelected:q}}function _t(t){return t.mode!=="edit"?ts(t):ns(t)}function es(t,e,n){let r=t.find(E);if(!r?.options)return null;let i=e.slice(ge(e,n)).trim().toLowerCase();if(!i)return null;let s=r.options.filter(l=>l.is_tappable&&l.text.trim().toLowerCase()===i);if(new Set(s.map(l=>$(l,r.parameter))).size!==1)return null;let a=s[0];return{suggestion:r,option:a,matchText:a.text.trim()}}function Xr(t){let{text:e,suggestions:n,filterBase:r,filterInProgress:i,phraseExactMatch:s}=t,o=n.find(c=>c.parameter!=="placeholder"&&!E(c));if(!o?.options)return null;let a=n.filter(c=>c.parameter==="placeholder").map(c=>c.text).join(" "),l=z(e,r,a),d=we(o.options,e,l,i,s===!0);return d?{suggestion:o,option:d,matchText:d.text}:null}function ts(t){let{text:e,completedParams:n,suggestions:r}=t,i=t.mode==="submit"?(t.finishWord?Xr(t):null)??es(r,e,n):Xr(t);if(!i)return null;let{suggestion:s,option:o,matchText:a}=i,l=a.toLowerCase(),d=e.toLowerCase().lastIndexOf(l),c=d>=0?d:Math.max(0,e.length-o.text.length),u=c+a.length,m=e.slice(c,u),g=u<e.length&&e[u]===" "?u+1:u,h={id:crypto.randomUUID(),placeholder:"",parameter:$(o,s.parameter),text:m,value:o.value,kind:o.kind,suggestionParameter:s.parameter,suggestionValueType:s.type,suggestionPlaceholder:s.text,...t.mode==="submit"&&E(s)?Ce($(o,s.parameter)):{},options:s.options??[],metadata:o.metadata,icon:o.icon,icon_svg:o.icon_svg,image_url:o.image_url};return{patch:{text:e,completedParams:[...n,h],suggestions:r.filter(y=>y!==s),filterBase:g,newParamId:h.id,caretOffset:g,activeDropdownIndex:-1},caretPos:g,option:o,suggestion:s}}function ns(t){let{text:e,completedParams:n,editingParam:r,editingAnchor:i,editingTail:s}=t;if(n.some(S=>S.id===r.id))return null;let o=e.slice(i,s),a=je(r.options,o);if(!a)return null;let l=a.text.toLowerCase(),d=o.toLowerCase().lastIndexOf(l),c=i+Math.max(0,d),u=c+a.text.length,m=e.slice(c,u),p=u<e.length&&e[u]===" "?u+1:u,g=e.length,h={id:crypto.randomUUID(),placeholder:"",...Qe(r,a),text:m,value:a.value,kind:a.kind,options:r.options,metadata:a.metadata,icon:a.icon,icon_svg:a.icon_svg,image_url:a.image_url},y=n.length,b=0;for(let S=0;S<n.length;S++){let x=V(e,n[S].text,b);if(x!==-1){if(x>=p){y=S;break}b=x+n[S].text.length}}let f=[...n];return f.splice(y,0,h),{patch:{text:e,completedParams:f,newParamId:h.id,filterBase:g,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:g,activeDropdownIndex:-1},caretPos:g,option:a}}function Fn(t){return t.slice(t.search(/\S*$/))}function Jr(t){return t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase()}function Zr(t,e){let n="",r=0;for(let i of t){if(n+=Jr(i),r+=i.length,n.length>=e.length)return n.startsWith(e)?r+(t.slice(r).match(/^\p{M}*/u)?.[0].length??0):0;if(!e.startsWith(n))return 0}return 0}function Hn(t){return[...t].map(Jr).join("")}function He(t,e){if(/\s$/.test(e))return null;let n=e.split(/\s+/).filter(Boolean).map(Hn),r=[...t.matchAll(/\S+/g)].map(i=>({index:i.index??0,text:i[0],folded:Hn(i[0])}));for(let i=n.length;i>=1;i--){let s=n.slice(n.length-i),o=s[i-1];for(let a=0;a+i<=r.length;a++){if(!s.slice(0,-1).every((u,m)=>r[a+m].folded===u))continue;let d=r[a+i-1],c=Zr(d.text,o);if(c>0)return{typedWords:i,start:r[a].index,end:d.index+c}}}return null}function Nt(t,e){let n=e?He(t,e):null;if(n&&n.typedWords>1)return[{text:t.slice(0,n.start),bold:!1},{text:t.slice(n.start,n.end),bold:!0},{text:t.slice(n.end),bold:!1}].filter(o=>o.text!=="");let r=e?Fn(e):"",i=Hn(r);if(!i)return[{text:t,bold:!1}];let s=[];for(let o of t.split(/(\s+)/)){if(o==="")continue;let a=/^\s/.test(o)?0:Zr(o,i);a>0&&s.push({text:o.slice(0,a),bold:!0});let l=a>0?o.slice(a):o;l&&s.push({text:l,bold:!1})}return s}var rs=6e4;function is(t){return typeof TextEncoder>"u"?t.length*3:new TextEncoder().encode(t).length}function os(t){return(t??K).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function ss(t){return Te(t)?`Bearer ${await Ve(t).getToken()}`:Ke(t)}async function ei(t){try{let e=os(t.apiConfig?.endpoint),n=qe(t.apiConfig),r=await ss(t.apiConfig);r&&(n.Authorization=r);let i=JSON.stringify({source:t.source,session_id:t.sessionId,...t.visitorId&&{visitor_id:t.visitorId},...t.requestId&&{request_id:t.requestId},type:t.type,...t.language&&{language:t.language},at:new Date().toISOString(),query_data:t.queryData});await fetch(e,{method:"POST",headers:n,body:i,...t.keepalive&&is(i)<=rs&&{keepalive:!0}})}catch{}}function le(t,e){let n=t.findIndex(r=>r.text===e);return n>=0?n+1:null}var Wn=t=>t.toLowerCase().split(/\s+/).filter(Boolean);function as(t,e,n){let r=Wn(t??"");if(r.length===0)return"";let s=Wn(e).slice(-r.length),o=Wn(n).slice(0,r.length);return s.join(" ")===r.join(" ")||o.join(" ")===r.join(" ")?"":(t??"").trim().split(/\s+/).join(" ")}function ti(t,e){let n=t.actionableSuggestions[0];if(!n)return null;let r=E(n),i=e.parameter;if(r&&!i)return null;let s=r&&i?i:$(e,n.parameter),o=r?t.text.length:t.filterBase,a=t.text.slice(0,o),l=a.length===0&&t.text.length===0,d=a.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(l||d)&&t.placeholderText&&(a=`${t.placeholderText} `);let c=Math.min(ge(t.text,t.completedParams),a.length);if(r){let v=[...a.slice(c).matchAll(/\S+/g)],w=He(e.text,a.slice(c)),M=v[v.length-(w?.typedWords??1)];a=a.slice(0,M?c+(M.index??0):Math.max(a.lastIndexOf(" ")+1,c))}else if(n.completes_word===!0){let v=[...a.slice(c).matchAll(/\S+/g)],w=v[v.length-1];a=a.slice(0,w?c+(w.index??0):Math.max(a.lastIndexOf(" ")+1,c))}else if(n.completes_word!==!1){let v=hr(a.slice(c),e.text);v>0&&(a=a.slice(0,a.length-v))}let u=a.length>0&&a[a.length-1]!==" ",p=T(B(n))?as(n.lead_in,a,e.text):"",g=`${a}${u?" ":""}${p?`${p} `:""}${e.text} `,y=(l||d||r&&a.length===0)&&g.length>0?g[0].toUpperCase()+g.slice(1):g,b=y.toLowerCase().lastIndexOf(e.text.toLowerCase()),f=b>=0?y.slice(b,b+e.text.length):e.text,S=r?Ce(s):{parameter:s,suggestionParameter:n.parameter,suggestionValueType:n.type,suggestionPlaceholder:n.text},x={id:crypto.randomUUID(),placeholder:"",...S,text:f,value:e.value,kind:e.kind,options:n.options??[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},I=t.actionableSuggestions.length-1;return{patch:{text:y,filterBase:y.length,completedParams:[...t.completedParams,x],newParamId:x.id,caretOffset:y.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:!0,inSelectionAnimation:!0,pendingSpan:null},telemetry:{selectedOption:e.text,otherOptions:t.filteredOptions.filter(v=>v.text!==e.text).map(v=>v.text),key:r?s:n.parameter,position:le(n.options??[],e.text)},consumedSuggestion:n,remainingActionable:I}}function Ht(t){let e=T(t.activeFormatType)||t.filteredOptions.length===0?null:t.filteredOptions,n=t.editingParam,r=n?{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options}:t.actionableSuggestions[0]??null;return{skeletonOptions:e,skeletonSuggestion:e?r:null,skeletonRequested:!1}}function Ft(t,e,n){let r=t.slice(0,e),i=t.slice(n),s=(r===""||r.endsWith(" "))&&i.startsWith(" ");return s&&(i=i.slice(1)),{text:r+i,removed:n-e+(s?1:0)}}var Wt=class{constructor(e){this.deps=e}start(e){let n=this.deps.store.get();if(n.editingParam?.id===e)return;let r=n.completedParams.find(o=>o.id===e);if(!r)return;let i=0,s=-1;for(let o of n.completedParams){let a=V(n.text,o.text,i);if(a!==-1){if(o.id===e){s=a;break}i=a+o.text.length}}s<0||this.deps.store.set({editingParam:r,editingAnchor:s,editingTail:s+r.text.length,caretOffset:s+r.text.length,activeDropdownIndex:-1,editingIdentified:null})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,s=n.editingTail;if(!r||i==null||s==null||!n.completedParams.some(l=>l.id===r.id))return!1;let{text:o}=e===""?Ft(n.text,i,s):{text:n.text.slice(0,i)+e+n.text.slice(s)},a=i+e.length;return this.deps.store.set(l=>({text:o,completedParams:l.completedParams.filter(d=>d.id!==r.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.promoteIfExact(),!0}caretAfterInput(e){let n=this.deps.store.get(),r={caretOffset:e};n.editingParam&&n.editingAnchor!=null&&e!=null&&(e<n.editingAnchor?(r.editingParam=null,r.editingAnchor=null,r.editingTail=null,r.activeDropdownIndex=-1):n.editingTail!=null&&(r.editingTail=Math.max(n.editingTail,e))),this.deps.store.set(r),this.promoteIfExact()}caretMove(e){let n=this.deps.store.get();if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null&&e!=null&&(e<n.editingAnchor||e>n.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,s=n.editingTail;if(!r||i==null||s==null)return;let o=Qe(r,e);this.deps.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:r.options.filter(f=>f.text!==e.text).map(f=>f.text),key:o.suggestionParameter,position:le(r.options,e.text),chip_origin:"tap"});let a=n.text.slice(0,i),l=n.text.slice(s),d=i===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,u=l.length===0||l[0]!==" "?`${d} `:d,m=a+u+l,p=m.length,g={id:crypto.randomUUID(),placeholder:"",...o,text:d,value:e.value,kind:e.kind,options:r.options,metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},h=n.completedParams.findIndex(f=>f.id===r.id),y=n.completedParams.filter(f=>f.id!==r.id),b=h>=0?Math.min(h,y.length):y.length;y.splice(b,0,g),this.deps.store.set({text:m,completedParams:y,newParamId:g.id,filterBase:p,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:p,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0,...Ht(n)}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(p),this.deps.fetchNow()}promoteIfExact(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let n=_t({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});n&&(this.deps.store.set(n.patch),this.deps.scheduleSetCursor(n.caretPos))}};var ri=33,ii=70,oi=120,si=50,de="data-aia-placeholder-leaving",ye=new WeakMap;function Bt(t){t.timer!==null&&(clearTimeout(t.timer),t.timer=null)}function ls(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function ai(t,e,n){e.shown=n,t.dataset.placeholder=e.target.slice(0,n)}function li(t,e){if(e.timer=null,!t.isConnected||e.shown>=e.target.length||(ai(t,e,e.shown+1),e.shown>=e.target.length))return;let n=e.target[e.shown-1],r=n===" "||n==="-"?70:0;e.timer=setTimeout(()=>li(t,e),33+r)}function ni(t,e){ai(t,e,0),e.timer=setTimeout(()=>li(t,e),33)}function di(t,e){let n=ye.get(t);if(e===""){n&&(Bt(n),ye.delete(t)),t.removeAttribute(de),delete t.dataset.placeholder;return}if(n?.target===e)return;if(ls(t)){n&&Bt(n),t.removeAttribute(de),ye.set(t,{target:e,shown:e.length,timer:null}),t.dataset.placeholder=e;return}let r={target:e,shown:0,timer:null},i=n&&n.shown>0?n:null;if(n&&Bt(n),ye.set(t,r),i){t.setAttribute(de,""),r.timer=setTimeout(()=>{r.timer=null,t.removeAttribute(de),t.isConnected&&ni(t,r)},170);return}t.removeAttribute(de),ni(t,r)}function ci(t){let e=ye.get(t);e&&(Bt(e),ye.delete(t))}var Bn="https://ai-autocomplete.com";function Ut(t=Bn){try{if(typeof window>"u"||!window.location)return t;let e=window.location.hostname;if(!e)return t;let n=new URL(t);return n.searchParams.set("utm_source",e),n.toString()}catch{return t}}var ui={language:"en",proceed:"to proceed",select:"to select",skipHint:"to skip",skip:"skip",skipLabel:"Skip",products:"Products",soldOut:"Sold out",addToCart:"Add to cart",submit:"Submit",scrollArrow:"Scroll down for more options",keepTyping:"Keep typing"},ds={language:"es",proceed:"para continuar",select:"para seleccionar",skipHint:"para omitir",skip:"omitir",skipLabel:"Omitir",products:"Productos",soldOut:"Agotado",addToCart:"A\xF1adir al carrito",submit:"Buscar",scrollArrow:"Despl\xE1zate para ver m\xE1s opciones",keepTyping:"Sigue escribiendo"},Un={en:ui,es:ds,fr:{language:"fr",proceed:"pour continuer",select:"pour s\xE9lectionner",skipHint:"pour passer",skip:"passer",skipLabel:"Passer",products:"Produits",soldOut:"\xC9puis\xE9",addToCart:"Ajouter au panier",submit:"Rechercher",scrollArrow:"Faites d\xE9filer pour voir plus d\u2019options",keepTyping:"Continuez \xE0 taper"},"pt-BR":{language:"pt-BR",proceed:"para continuar",select:"para selecionar",skipHint:"para pular",skip:"pular",skipLabel:"Pular",products:"Produtos",soldOut:"Esgotado",addToCart:"Adicionar ao carrinho",submit:"Buscar",scrollArrow:"Role para ver mais op\xE7\xF5es",keepTyping:"Continue digitando"},it:{language:"it",proceed:"per continuare",select:"per selezionare",skipHint:"per saltare",skip:"salta",skipLabel:"Salta",products:"Prodotti",soldOut:"Esaurito",addToCart:"Aggiungi al carrello",submit:"Cerca",scrollArrow:"Scorri per vedere altre opzioni",keepTyping:"Continua a scrivere"},tr:{language:"tr",proceed:"devam etmek i\xE7in",select:"se\xE7mek i\xE7in",skipHint:"atlamak i\xE7in",skip:"atla",skipLabel:"Atla",products:"\xDCr\xFCnler",soldOut:"T\xFCkendi",addToCart:"Sepete ekle",submit:"Ara",scrollArrow:"Daha fazla se\xE7enek i\xE7in kayd\u0131r",keepTyping:"Yazmaya devam et"},id:{language:"id",proceed:"untuk melanjutkan",select:"untuk memilih",skipHint:"untuk melewati",skip:"lewati",skipLabel:"Lewati",products:"Produk",soldOut:"Habis",addToCart:"Tambah ke keranjang",submit:"Cari",scrollArrow:"Gulir untuk melihat opsi lainnya",keepTyping:"Teruskan mengetik"},pl:{language:"pl",proceed:"aby kontynuowa\u0107",select:"aby wybra\u0107",skipHint:"aby pomin\u0105\u0107",skip:"pomi\u0144",skipLabel:"Pomi\u0144",products:"Produkty",soldOut:"Wyprzedane",addToCart:"Dodaj do koszyka",submit:"Szukaj",scrollArrow:"Przewi\u0144, aby zobaczy\u0107 wi\u0119cej opcji",keepTyping:"Pisz dalej"},de:{language:"de",proceed:"zum Fortfahren",select:"zum Ausw\xE4hlen",skipHint:"zum \xDCberspringen",skip:"\xFCberspringen",skipLabel:"\xDCberspringen",products:"Produkte",soldOut:"Ausverkauft",addToCart:"In den Warenkorb",submit:"Suchen",scrollArrow:"Scrolle f\xFCr weitere Optionen",keepTyping:"Weitertippen"},nl:{language:"nl",proceed:"om door te gaan",select:"om te selecteren",skipHint:"om over te slaan",skip:"overslaan",skipLabel:"Overslaan",products:"Producten",soldOut:"Uitverkocht",addToCart:"In winkelwagen",submit:"Zoeken",scrollArrow:"Scrol voor meer opties",keepTyping:"Blijf typen"},sv:{language:"sv",proceed:"f\xF6r att forts\xE4tta",select:"f\xF6r att v\xE4lja",skipHint:"f\xF6r att hoppa \xF6ver",skip:"hoppa \xF6ver",skipLabel:"Hoppa \xF6ver",products:"Produkter",soldOut:"Sluts\xE5ld",addToCart:"L\xE4gg i varukorgen",submit:"S\xF6k",scrollArrow:"Skrolla f\xF6r fler alternativ",keepTyping:"Forts\xE4tt skriva"},nb:{language:"nb",proceed:"for \xE5 fortsette",select:"for \xE5 velge",skipHint:"for \xE5 hoppe over",skip:"hopp over",skipLabel:"Hopp over",products:"Produkter",soldOut:"Utsolgt",addToCart:"Legg i handlekurven",submit:"S\xF8k",scrollArrow:"Rull ned for \xE5 se flere alternativer",keepTyping:"Fortsett \xE5 skrive"},da:{language:"da",proceed:"for at forts\xE6tte",select:"for at v\xE6lge",skipHint:"for at springe over",skip:"spring over",skipLabel:"Spring over",products:"Produkter",soldOut:"Udsolgt",addToCart:"L\xE6g i kurv",submit:"S\xF8g",scrollArrow:"Rul for flere muligheder",keepTyping:"Forts\xE6t med at skrive"},fi:{language:"fi",proceed:"jatkaaksesi",select:"valitaksesi",skipHint:"ohittaaksesi",skip:"ohita",skipLabel:"Ohita",products:"Tuotteet",soldOut:"Loppuunmyyty",addToCart:"Lis\xE4\xE4 ostoskoriin",submit:"Hae",scrollArrow:"Vierit\xE4 n\xE4hd\xE4ksesi lis\xE4\xE4 vaihtoehtoja",keepTyping:"Jatka kirjoittamista"},ja:{language:"ja",proceed:"\u3067\u6B21\u3078",select:"\u3067\u9078\u629E",skipHint:"\u3067\u30B9\u30AD\u30C3\u30D7",skip:"\u30B9\u30AD\u30C3\u30D7",skipLabel:"\u30B9\u30AD\u30C3\u30D7",products:"\u5546\u54C1",soldOut:"\u58F2\u308A\u5207\u308C",addToCart:"\u30AB\u30FC\u30C8\u306B\u8FFD\u52A0",submit:"\u691C\u7D22",scrollArrow:"\u30B9\u30AF\u30ED\u30FC\u30EB\u3057\u3066\u4ED6\u306E\u5019\u88DC\u3092\u898B\u308B",keepTyping:"\u5165\u529B\u3092\u7D9A\u3051\u308B"},ko:{language:"ko",proceed:"\uACC4\uC18D",select:"\uC120\uD0DD",skipHint:"\uAC74\uB108\uB6F0\uAE30",skip:"\uAC74\uB108\uB6F0\uAE30",skipLabel:"\uAC74\uB108\uB6F0\uAE30",products:"\uC0C1\uD488",soldOut:"\uD488\uC808",addToCart:"\uC7A5\uBC14\uAD6C\uB2C8\uC5D0 \uB2F4\uAE30",submit:"\uAC80\uC0C9",scrollArrow:"\uB354 \uB9CE\uC740 \uC635\uC158\uC744 \uBCF4\uB824\uBA74 \uC2A4\uD06C\uB864\uD558\uC138\uC694",keepTyping:"\uACC4\uC18D \uC785\uB825\uD558\uC138\uC694"},"zh-CN":{language:"zh-CN",proceed:"\u7EE7\u7EED",select:"\u9009\u62E9",skipHint:"\u8DF3\u8FC7",skip:"\u8DF3\u8FC7",skipLabel:"\u8DF3\u8FC7",products:"\u5546\u54C1",soldOut:"\u552E\u7F44",addToCart:"\u52A0\u5165\u8D2D\u7269\u8F66",submit:"\u641C\u7D22",scrollArrow:"\u5411\u4E0B\u6EDA\u52A8\u67E5\u770B\u66F4\u591A\u9009\u9879",keepTyping:"\u7EE7\u7EED\u8F93\u5165"},"zh-TW":{language:"zh-TW",proceed:"\u7E7C\u7E8C",select:"\u9078\u64C7",skipHint:"\u7565\u904E",skip:"\u7565\u904E",skipLabel:"\u7565\u904E",products:"\u5546\u54C1",soldOut:"\u552E\u5B8C",addToCart:"\u52A0\u5165\u8CFC\u7269\u8ECA",submit:"\u641C\u5C0B",scrollArrow:"\u5411\u4E0B\u6372\u52D5\u67E5\u770B\u66F4\u591A\u9078\u9805",keepTyping:"\u7E7C\u7E8C\u8F38\u5165"}},cs={pt:"pt-BR",no:"nb",nn:"nb"};function k(t){let[e,...n]=t?.toLowerCase().split("-")??[];if(e==="zh"){let i=n.some(s=>["hant","tw","hk","mo"].includes(s));return Un[i?"zh-TW":"zh-CN"]}let r=cs[e]??e;return Object.prototype.hasOwnProperty.call(Un,r)?Un[r]:ui}function $t(t,e,n=k()){return t?{key:"enter",hint:n.proceed}:e?{key:"tab",hint:n.select}:{key:"\u2192",hint:n.skipHint}}function Gt(t){let e=o=>{o.ctrlKey||pi(o.target,t,o.deltaX,o.deltaY)||o.preventDefault()},n=0,r=0,i=o=>{let a=o.touches[0];a&&(n=a.clientX,r=a.clientY)},s=o=>{if(o.touches.length!==1)return;let a=o.touches[0],l=n-a.clientX,d=r-a.clientY;n=a.clientX,r=a.clientY,o.cancelable&&!pi(o.target,t,l,d)&&o.preventDefault()};return t.addEventListener("wheel",e,{passive:!1}),t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchmove",s,{passive:!1}),()=>{t.removeEventListener("wheel",e),t.removeEventListener("touchstart",i),t.removeEventListener("touchmove",s)}}function pi(t,e,n,r){let i=t instanceof Element?t:null;for(;i;){if(r!==0&&us(i,r)||n!==0&&ps(i,n))return!0;if(i===e)break;i=i.parentElement}return!1}var mi=/^(auto|scroll|overlay)$/;function us(t,e){return t.scrollHeight<=t.clientHeight||!mi.test(getComputedStyle(t).overflowY)?!1:e>0?t.scrollTop+t.clientHeight<t.scrollHeight-1:t.scrollTop>0}function ps(t,e){if(t.scrollWidth<=t.clientWidth)return!1;let n=getComputedStyle(t);if(!mi.test(n.overflowX))return!1;let r=Math.abs(t.scrollLeft),i=t.scrollWidth-t.clientWidth;return(n.direction==="rtl"?e<0:e>0)?r<i-1:r>0}var gi=new WeakMap,fi=new WeakSet;function Q(t,e,n){if(gi.set(t,n),fi.has(t))return;fi.add(t);let r=()=>gi.get(t),i=s=>{if(!(s instanceof Element))return null;let o=s.closest(e.itemSelector);return o&&t.contains(o)?o:null};e.onClick&&t.addEventListener("click",s=>{let o=i(s.target);o&&e.onClick?.(o,r(),s)}),e.onEnter&&t.addEventListener("mouseenter",s=>{let o=s.target;o instanceof HTMLElement&&o.matches(e.itemSelector)&&e.onEnter?.(o,r())},!0),e.onLeave&&t.addEventListener("mouseleave",s=>{let o=s.target;o instanceof HTMLElement&&o.matches(e.itemSelector)&&e.onLeave?.(o,r())},!0),e.preventMousedown&&t.addEventListener("mousedown",s=>s.preventDefault())}function X(t){return Number.parseInt(t.dataset.aiaIndex??"-1",10)}function J(t){t.offsetWidth}var ms={selectedIso:null,selectedRange:null,rangeStart:null};function xe(t){if(!T(t.activeFormatType))return ms;let e=t.editingIdentified;if(e){let{iso:r,isoEnd:i}=e;return{selectedIso:i?null:r,selectedRange:r&&i?Re(r,i):null,rangeStart:t.dateRangeStart}}let n=Se(t.editingParam);return{selectedIso:n?null:at(t.editingParam?.text),selectedRange:n,rangeStart:t.dateRangeStart}}function Vt(t){return t.pendingStart?Re(t.pendingStart,t.highlightedIso??t.pendingStart):t.selected}function qt(t,e){if(t==null)return{selected:!1,inRange:!1};let{selectedIso:n,range:r}=e,i=t===n||r!=null&&(t===r.start||t===r.end),s=r!=null&&t>r.start&&t<r.end;return{selected:i,inRange:s}}var hi="data-aia-key";function Z(t,e,n){let r=new Map;for(let o of Array.from(t.children)){let a=o.getAttribute(hi);a!=null&&r.set(a,o)}let i=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],l=n.keyOf(a,o);i.add(l);let d=r.get(l);d||(d=n.create(a,o),d.setAttribute(hi,l)),n.update?.(d,a,o),t.children[o]!==d&&t.insertBefore(d,t.children[o]??null),s.push(d)}for(let[o,a]of r)i.has(o)||a.remove();return s}function bi(t,e){if(!e.interactive)return null;let n=e.options[X(t)];return n?.is_tappable?n:null}var gs={itemSelector:"[data-aia-date-cell], [data-aia-date-prev], [data-aia-date-next]",onClick:(t,e)=>{if(t.hasAttribute("data-aia-date-prev")){e.callbacks.onPreviousMonth();return}if(t.hasAttribute("data-aia-date-next")){e.callbacks.onNextMonth();return}let n=bi(t,e);n&&(t.classList.add("magicx-aia-date-cell--pressed"),e.callbacks.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-date-cell--pressed"),170))},onEnter:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&bi(t,e)&&e.callbacks.onHighlight(X(t))},onLeave:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&e.callbacks.onHighlight(-1,X(t))}};function yi(t,e,n,r,i,s,o,a=!0){let l=t.querySelector(".magicx-aia-datepicker");if(!i||e.length===0){l?.remove();return}if(!l){l=bs(),t.appendChild(l),J(l);for(let u of l.querySelectorAll(".magicx-aia-datepicker-nav"))u.disabled=!1}Q(l,gs,{options:e,callbacks:o,interactive:a});let d=l.querySelector(".magicx-aia-datepicker-month");d&&(d.textContent=it(i));let c=l.querySelector(".magicx-aia-datepicker-grid");c&&fs(c,e,n,r,s)}function fs(t,e,n,r,i){let s=H(new Date),o=Vt({pendingStart:i.rangeStart,highlightedIso:G(e[n]),selected:i.selectedRange});Z(t,e,{keyOf:(a,l)=>G(a)??`pad-${l}`,create:a=>hs(a),update:(a,l,d)=>{let c=G(l),u=qt(c,{selectedIso:i.selectedIso,range:o}),m=d===n&&l.is_tappable;a.id=`${r}-option-${d}`,a.dataset.aiaIndex=String(d),a.setAttribute("aria-selected",String(m)),a.classList.toggle("magicx-aia-date-cell--past",c!=null&&c<s),a.classList.toggle("magicx-aia-date-cell--highlighted",m),a.classList.toggle("magicx-aia-date-cell--today",c!=null&&c===s),a.classList.toggle("magicx-aia-date-cell--selected",u.selected),a.classList.toggle("magicx-aia-date-cell--in-range",u.inRange)}})}function hs(t){let e=document.createElement("div");e.setAttribute("role","option"),e.setAttribute("data-aia-option",""),e.setAttribute("data-aia-date-cell","");let n=lt(t);if(n==null)return e.className="magicx-aia-date-cell magicx-aia-date-cell--blank",e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e;e.className="magicx-aia-date-cell magicx-aia-date-cell--day",e.tabIndex=0,e.setAttribute("aria-label",t.text);let r=document.createElement("span");return r.className="magicx-aia-date-cell-number",r.textContent=String(n),e.appendChild(r),e}function bs(){let t=document.createElement("div");t.className="magicx-aia-datepicker",t.setAttribute("data-aia-datepicker","");let e=document.createElement("div");e.className="magicx-aia-datepicker-header";let n=document.createElement("span");n.className="magicx-aia-datepicker-month",n.setAttribute("data-aia-date-month",""),n.setAttribute("aria-live","polite"),e.append(Si("prev","Previous month","\u2039"),n,Si("next","Next month","\u203A"));let r=document.createElement("div");r.className="magicx-aia-datepicker-weekdays",r.setAttribute("aria-hidden","true");for(let s of Oe){let o=document.createElement("span");o.className="magicx-aia-datepicker-weekday",o.textContent=s,r.appendChild(o)}let i=document.createElement("div");return i.className="magicx-aia-datepicker-grid",i.setAttribute("data-aia-date-grid",""),t.append(e,r,i),t}function Si(t,e,n){let r=document.createElement("button");return r.type="button",r.tabIndex=-1,r.className="magicx-aia-datepicker-nav",r.setAttribute(`data-aia-date-${t}`,""),r.setAttribute("aria-label",e),r.textContent=n,r.disabled=!0,r}var Ss={itemSelector:"[data-aia-pill]",onClick:(t,e)=>{if(e.loading||t.disabled)return;let n=Number.parseInt(t.dataset.aiaPillIndex??"-1",10);n>=0&&e.onSelectPill(n)},preventMousedown:!0},xi=[125,69];function vi(t,e){return e?1:t===0?.7:t===1?.4:.2}function Kt(t,e,n,r,i=!1,s=!1,o=!1){let a=t.querySelector(".magicx-aia-pill-list");if(a||(a=document.createElement("span"),a.className="magicx-aia-pill-list",t.appendChild(a)),Q(a,Ss,{onSelectPill:r,loading:s}),s&&e.length===0){a.setAttribute("data-aia-pill-list-loading",""),a.innerHTML="";for(let l=0;l<xi.length;l++){let d=xi[l],c=document.createElement("span");c.setAttribute("data-aia-pill-skeleton",""),c.className=`magicx-aia-pill magicx-aia-pill--skeleton${i?" magicx-aia-pill--rounded":""}`,c.style.width=`${d}px`,c.style.opacity=String(vi(l,!1)),a.appendChild(c)}return}s?a.setAttribute("data-aia-pill-list-loading",""):a.removeAttribute("data-aia-pill-list-loading");for(let l of a.querySelectorAll("[data-aia-pill-skeleton]"))l.remove();Z(a,e,{keyOf:l=>`${l.type?.kind??""}|${Ie(l)?1:0}|${l.parameter}|${l.text}`,create:l=>{let d=document.createElement("button");if(d.type="button",d.tabIndex=-1,d.setAttribute("data-aia-pill",""),d.setAttribute("contenteditable","false"),Ie(l)){d.setAttribute("data-aia-smart-suggestion",E(l)?"header":"");let c=document.createElement("span");c.className="magicx-aia-smart-suggestion-text",c.textContent=l.text;let u=document.createElement("span");u.className="magicx-aia-smart-suggestion-sparkle",u.innerHTML=Ze,d.append(c,u)}else d.textContent=l.text;return d.disabled=!0,d},update:(l,d,c)=>{let u=l,m=o&&c===n&&!s,p=["magicx-aia-pill"];i&&p.push("magicx-aia-pill--rounded"),s&&p.push("magicx-aia-pill--skeleton"),u.className=p.join(" "),u.style.width="",u.style.opacity=String(vi(c,m)),u.dataset.aiaPillIndex=String(c),s?u.setAttribute("data-aia-loading",""):u.removeAttribute("data-aia-loading")}}),J(a);for(let l of a.querySelectorAll("[data-aia-pill]"))l.disabled=s}function $n(t){t.querySelector(".magicx-aia-pill-list")?.remove()}var Pi=32;function Gn(t,e){if(e.ctrlKey)return null;let n=e.deltaY||0,r=e.deltaX||0;if(!n||Math.abs(r)>=Math.abs(n))return null;let i=t.scrollWidth-t.clientWidth;if(i<=1)return null;let s=t.scrollLeft,o=n;return e.deltaMode===1?o*=32:e.deltaMode===2&&(o*=t.clientWidth),Math.max(0,Math.min(i,s+o))}function zt(t){let e=n=>{let r=Gn(t,n);r!==null&&(n.preventDefault(),t.scrollLeft=r)};return t.addEventListener("wheel",e,{passive:!1}),()=>t.removeEventListener("wheel",e)}var Ti=Intl.Segmenter,Ei=Ti?new Ti(void 0,{granularity:"grapheme"}):null;function jt(t){let e=t.trim().normalize("NFC").toUpperCase();if(Ei)for(let n of Ei.segment(e))return n.segment;return Array.from(e)[0]??"?"}var Yt=120,wi=360;function ys(t){let e=t.pathname;return t.hostname==="cdn.shopify.com"&&e.startsWith("/s/files/")||e.startsWith("/cdn/shop/")?/\.png$/i.test(e)?{format:"pjpg"}:/\.webp$/i.test(e)?{format:null}:null:null}function Vn(t,e){let n;try{n=new URL(t,typeof document>"u"?void 0:document.baseURI)}catch{return t}let r=ys(n);return r?(n.searchParams.set("width",String(e)),r.format&&n.searchParams.set("format",r.format),t.startsWith("/")&&!t.startsWith("//")?`${n.pathname}${n.search}${n.hash}`:n.href):t}function qn(t,e){let n=Vn(t,e);return n===t?[t]:[n,t]}function Qt(t,e){if(!(t>0)||!(e>0))return null;let n=t/e,r=i=>Math.round(i*1e3)/1e3;return{x:r(Math.min(n,1)),y:r(Math.min(1/n,1))}}function Fe(t){let e=t?.trim();return e?qn(e,360):[]}function Ci(t){return Fe(t)[0]}var Xt=new WeakMap,zn=new WeakMap,Ai=new WeakMap;function Oi(t,e,n,r,i,s="row",o="image",a=k(),l){let d=t.querySelector(".magicx-aia-products");if(e.length===0){d?.remove();return}if(!d){d=document.createElement("section"),d.className="magicx-aia-products",d.setAttribute("data-aia-products",""),d.setAttribute("role","group"),d.setAttribute("aria-labelledby",`${n}-products-label`);let m=document.createElement("div");m.className="magicx-aia-products-label",m.id=`${n}-products-label`,m.setAttribute("data-aia-products-label",""),m.textContent=a.products;let p=document.createElement("div");p.className="magicx-aia-products-row",p.setAttribute("data-aia-products-row",""),zt(p),d.append(m,p),t.appendChild(d)}d.setAttribute("data-aia-products-layout",s);let c=d.querySelector(".magicx-aia-products-label");c&&c.textContent!==a.products&&(c.textContent=a.products);let u=d.querySelector(".magicx-aia-products-row");if(u){Z(u,e,{keyOf:m=>Ts(m,!!l),create:m=>Es(m,r,i,o,a,l),update:(m,p,g)=>{Xt.set(m,p),xs(m,p.price),m.id=`${n}-product-${g}`,m.dataset.aiaIndex=String(g),Ai.get(m)?.(o);let h=m.querySelector(".magicx-aia-product-badge");h&&h.textContent!==a.soldOut&&(h.textContent=a.soldOut);let y=m.querySelector(".magicx-aia-product-cart");y&&y.setAttribute("aria-label",ki(p,a))}}),J(u);for(let m of u.querySelectorAll("[data-aia-product]")){let p=zn.get(m);p&&(zn.delete(m),p())}}}function jn(t,e){let n=t.querySelectorAll("[data-aia-product], [data-aia-product-cart]");for(let r of n)r.tabIndex=e?0:-1}function xs(t,e){let n=t.querySelector(".magicx-aia-product-price");if(!e){n?.remove();return}n||(n=document.createElement("span"),n.className="magicx-aia-product-price",t.querySelector(".magicx-aia-product-title")?.after(n)),n.textContent!==e&&(n.textContent=e)}function Ii(t,e){e?(t.style.setProperty("--aia-product-photo-fill-x",String(e.x)),t.style.setProperty("--aia-product-photo-fill-y",String(e.y))):(t.style.removeProperty("--aia-product-photo-fill-x"),t.style.removeProperty("--aia-product-photo-fill-y"))}function ki(t,e){return`${e.addToCart}: ${t.title}`}var Kn="http://www.w3.org/2000/svg";function vs(){let t=document.createElementNS(Kn,"svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.setAttribute("focusable","false");let e=[["magicx-aia-product-cart-glyph","M2 3h2.2l2.4 11.2a2 2 0 0 0 2 1.6h8.9a2 2 0 0 0 1.9-1.5L21 8H6"],["magicx-aia-product-cart-glyph","M13.5 6.5v-4M11.5 4.5h4"],["magicx-aia-product-cart-check","M5 12.5l4.5 4.5L19 7.5"],["magicx-aia-product-cart-spinner","M12 4a8 8 0 1 0 8 8"]];for(let[n,r]of e){let i=document.createElementNS(Kn,"path");i.setAttribute("class",n),i.setAttribute("d",r),t.appendChild(i)}for(let n of["9","17.5"]){let r=document.createElementNS(Kn,"circle");r.setAttribute("class","magicx-aia-product-cart-glyph"),r.setAttribute("cx",n),r.setAttribute("cy","20"),r.setAttribute("r","1.3"),t.appendChild(r)}return t}function Ps(t,e,n,r,i){let s=document.createElement("span");s.className="magicx-aia-product-cart",s.setAttribute("data-aia-product-cart",""),s.setAttribute("role","button"),s.setAttribute("aria-label",ki(e,i)),s.tabIndex=0,s.appendChild(vs());let o=a=>{a.preventDefault(),a.stopPropagation(),s.getAttribute("data-aia-cart-state")!=="adding"&&(s.setAttribute("data-aia-cart-state","adding"),s.setAttribute("aria-busy","true"),n(Xt.get(t)??e).then(()=>{s.removeAttribute("aria-busy"),s.setAttribute("data-aia-cart-state","added")},()=>{s.removeAttribute("aria-busy"),s.removeAttribute("data-aia-cart-state")}))};return s.addEventListener("keydown",a=>{a.key!=="Enter"&&a.key!==" "||o(a)}),s.addEventListener("focus",()=>r(!0)),s.addEventListener("blur",a=>{a.relatedTarget?.closest("[data-aia-dropdown]")||r(!1)}),{el:s,arm:()=>s.addEventListener("click",o)}}function Ts(t,e){return[e?"cart":"",t.id,t.title,t.url,t.imageUrl,t.vendor,t.available===!1?"sold-out":""].map(n=>n??"").join("\0")}function Es(t,e,n,r,i,s){let o=document.createElement("a");o.className="magicx-aia-product",o.setAttribute("data-aia-product",""),o.setAttribute("role","option"),o.setAttribute("aria-selected","false"),o.tabIndex=0;let a=document.createElement("span");a.className="magicx-aia-product-media",a.setAttribute("aria-hidden","true");let l=Fe(t.imageUrl),d=l[0],c=!!d,u=()=>{a.replaceChildren(),a.removeAttribute("data-aia-image-loaded"),a.toggleAttribute("data-aia-product-placeholder",r==="image"),a.toggleAttribute("data-aia-product-initial",r==="initial"),r==="initial"&&(a.textContent=jt(t.title))};if(Ai.set(o,h=>{h!==r&&(r=h,c||u())}),d){let h=document.createElement("img"),y=0;h.onload=()=>{a.setAttribute("data-aia-image-loaded",""),Ii(o,Qt(h.naturalWidth,h.naturalHeight))},h.onerror=()=>{let b=l[++y];if(b){h.src=b;return}c=!1,Ii(o,null),u()},h.className="magicx-aia-product-image",h.src=d,h.alt="",h.loading="lazy",h.decoding="async",a.appendChild(h)}else u();o.appendChild(a);let m=document.createElement("span");if(m.className="magicx-aia-product-body",t.vendor){let h=document.createElement("span");h.className="magicx-aia-product-vendor",h.textContent=t.vendor,m.appendChild(h)}let p=document.createElement("span");if(p.className="magicx-aia-product-title",p.textContent=t.title,m.appendChild(p),t.available===!1){o.setAttribute("data-aia-product-sold-out","");let h=document.createElement("span");h.className="magicx-aia-product-badge",h.textContent=i.soldOut,m.appendChild(h)}o.appendChild(m);let g=s&&t.available!==!1?Ps(o,t,s,n,i):null;return g&&(o.setAttribute("data-aia-product-has-cart",""),o.appendChild(g.el)),zn.set(o,()=>{g?.arm(),t.url&&(o.href=t.url),o.addEventListener("click",h=>{h.metaKey||h.ctrlKey||h.shiftKey||h.altKey||h.button!==0||(h.preventDefault(),e(Xt.get(o)??t))})}),o.addEventListener("keydown",h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),e(Xt.get(o)??t))}),o.addEventListener("focus",()=>n(!0)),o.addEventListener("blur",h=>{h.relatedTarget?.closest("[data-aia-dropdown]")||n(!1)}),o}var Li=80,Mi=150,Ri=280,Di=16,Jt="--aia-option-enter-delay";function Zt(t,e,n,r="below"){let i=Math.max(1,Math.floor(e)),s=Math.floor(Math.max(0,t)/i);if(r!=="above")return s*80;let o=Math.max(1,Math.ceil(Math.max(0,n)/i));return Math.max(0,o-1-s)*80}function en(t,e){let n=Math.max(1,Math.floor(e));return(Math.max(1,Math.ceil(Math.max(0,t)/n))-1)*80+280}var _i="http://www.w3.org/2000/svg",ws=new Set(["svg","g","path","circle","ellipse","line","polyline","polygon","rect"]);function Cs(t,e){let n=t.toLowerCase();return n.startsWith("on")||n.includes("href")||n==="style"||n==="xml:base"||n==="id"||n==="name"||/^\s*javascript:/i.test(e)||/url\s*\(\s*['"]?\s*[^#'"\s)]/i.test(e)}var Is=["fill","stroke","stroke-width","stroke-linecap","stroke-linejoin","fill-rule","clip-rule","opacity","fill-opacity","stroke-opacity"],As=/^[a-zA-Z0-9#.,%\s()-]+$/;function Os(t){let e=[];for(let n of Is){let r=t.getAttribute(n);r===null||!As.test(r)||/url\s*\(/i.test(r)||e.push(`${n}: ${r.trim()}`)}e.length>0&&t.setAttribute("style",e.join("; "))}function Ni(t){for(let e of Array.from(t.attributes))Cs(e.name,e.value)&&t.removeAttribute(e.name);Os(t);for(let e of Array.from(t.childNodes))if(e.nodeType===Node.ELEMENT_NODE){let n=e;!ws.has(n.localName)||n.namespaceURI!==_i?n.remove():Ni(n)}else e.remove()}function ee(t){if(typeof DOMParser>"u"||typeof XMLSerializer>"u")return null;let e=new DOMParser().parseFromString(t,"image/svg+xml"),n=e.documentElement;return!n||n.localName!=="svg"||n.namespaceURI!==_i||e.getElementsByTagName("parsererror").length>0?null:(Ni(n),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false"),new XMLSerializer().serializeToString(n))}function We(t){return t.text}function te(t){return Be(t)[0]??null}function Be(t){let e=ks(t);return e?qn(e,120):[]}function ks(t){if(!t)return null;let e=t.trim();if(e==="")return null;let n;try{n=new URL(e,typeof document>"u"?void 0:document.baseURI)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}function ve(t){return t===void 0||!Number.isInteger(t)||t<0?null:t.toLocaleString()}var Yn={one:"item",other:"items"};function Hi(t,e=Yn){let n=ve(t);if(n===null)return null;let r=typeof e=="string"?e:t===1?e.one:e.other;return r===""?n:`${n} ${r}`}function Qn(t){return te(t.image_url)!==null}var tn=new Map;function Ls(t){let e=t.icon_svg;if(!e)return!1;let n=tn.get(e);return n===void 0&&(n=ee(e)!==null,tn.size>=256&&tn.clear(),tn.set(e,n)),n}function nn(t,e,n){return!e&&!n?!1:t.every(r=>!r.is_tappable||n&&Qn(r)||e&&Ls(r))}var Fi=new WeakMap;function Ms(t,e,n){let r=e.length,i=Rt(),s=Fi.get(t),o=n&&s&&Dt(s.options,e)?s.plan:null,a=!o&&!n&&kt(r,i)?Mt(t):null,l=o??Lt(r,i,a?.rowWidths??null,a?.gridWidth??null);return n||Fi.set(t,{options:e,plan:l}),t.style.gridTemplateColumns=l.template,t.style.setProperty("--aia-grid-max-height",l.maxHeight),t.querySelectorAll("[data-aia-option]").forEach((d,c)=>{d.classList.toggle("magicx-aia-option--scroll-hint",!n&&l.scrollHintIndices.includes(c))}),l.cols}function Wi(t,e){if(e.loading||!e.interactive)return null;let n=e.options[X(t)];return n?.is_tappable?n:null}var Rs={itemSelector:"[data-aia-option]",onClick:(t,e)=>{let n=Wi(t,e);n&&(t.classList.add("magicx-aia-option--pressed"),e.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-option--pressed"),170))},onEnter:(t,e)=>{Wi(t,e)&&e.onHighlight(X(t))},onLeave:(t,e)=>e.onHighlight(-1,X(t))};function Bi(t,e,n,r,i,s,o,a="",l="below",d=!0,c=!0,u=!0,m=!0){let p=t.querySelector(".aia-grid");if(e.length===0){p?.remove();return}p||(p=document.createElement("div"),p.className="aia-grid magicx-aia-grid",p.setAttribute("data-scroll",""),p.style.setProperty("--aia-grid-min","250px"),p.style.setProperty("--aia-grid-max","1fr"),p.style.setProperty("--aia-grid-gap","0"),t.appendChild(p)),Q(p,Rs,{options:e,onSelect:r,onHighlight:i,loading:o,interactive:m});let g=p.dataset.aiaGroup!==a;p.dataset.aiaGroup=a;let h=nn(e,d,c);Ds(p,e,n,s,o,{showIcons:d&&h,showImages:c&&h,showCounts:u});let y=Ms(p,e,o);_s(p,e.length,y,o,l),g&&(p.scrollTop=0)}function Ds(t,e,n,r,i,s){let o=i?"1":"0",a=t.dataset.aiaGroup??"",{showIcons:l,showImages:d,showCounts:c}=s,u=l?g=>g.icon??g.icon_svg??"":()=>"",m=d?g=>te(g.image_url)??"":()=>"",p=c?g=>ve(g.item_count)??"":()=>"";Z(t,e,{keyOf:g=>`${g.text}\0${g.parameterLabel??""}\0${u(g)}\0${m(g)}\0${p(g)}\0${o}\0${a}`,create:(g,h)=>{let y=Ns(g,i,s);return i||(y.dataset.aiaEntering=""),y},update:(g,h,y)=>{if(Xn.get(g)!==(h.matchedText??"")){let f=g.querySelector(".magicx-aia-option-text");f&&Ui(f,h),Xn.set(g,h.matchedText??"")}let b=y===n&&!i;g.id=`${r}-option-${y}`,g.dataset.aiaIndex=String(y),g.setAttribute("aria-selected",String(b)),g.classList.toggle("magicx-aia-option--highlighted",b)}})}function _s(t,e,n,r,i){for(let s of t.querySelectorAll("[data-aia-entering]")){if(!r){let o=Number.parseInt(s.dataset.aiaIndex??"-1",10);o>=0&&s.style.setProperty(Jt,`${Zt(o,n,e,i)}ms`)}delete s.dataset.aiaEntering}}var Xn=new WeakMap;function Ui(t,e){if(t.replaceChildren(),e.matchedText)for(let n of Nt(We(e),e.matchedText))if(n.bold){let r=document.createElement("strong");r.className="magicx-aia-option-match",r.textContent=n.text,t.appendChild(r)}else t.appendChild(document.createTextNode(n.text));else t.appendChild(document.createTextNode(We(e)));if(e.parameterLabel){t.appendChild(document.createTextNode(" "));let n=document.createElement("span");n.className="magicx-aia-option-parameter",n.textContent=e.parameterLabel,t.appendChild(n)}}function Ns(t,e,{showIcons:n,showImages:r,showCounts:i}){let s=document.createElement("div");s.setAttribute("role","option"),s.setAttribute("data-aia-option",""),e&&s.setAttribute("data-aia-loading",""),s.tabIndex=e||!t.is_tappable?-1:0;let o=["magicx-aia-option"];t.is_tappable?o.push("magicx-aia-option--tappable"):o.push("magicx-aia-option--non-tappable"),s.className=o.join(" ");let a=document.createElement("span");a.className="magicx-aia-option-content";let l=r?Be(t.image_url):[],d=l[0];if(d){let p=document.createElement("span");p.className="magicx-aia-option-image",p.setAttribute("aria-hidden","true");let g=document.createElement("img");g.setAttribute("alt",""),g.setAttribute("loading","lazy"),g.setAttribute("decoding","async"),g.setAttribute("referrerpolicy","no-referrer"),g.setAttribute("draggable","false");let h=0;g.onload=()=>p.setAttribute("data-aia-image-loaded",""),g.onerror=()=>{let y=l[++h];y?g.src=y:g.hidden=!0},g.src=d,p.appendChild(g),a.appendChild(p),s.dataset.aiaImage=""}let c=!d&&n&&t.icon_svg?ee(t.icon_svg):null;if(c){let p=document.createElement("span");p.className="magicx-aia-option-icon",p.setAttribute("aria-hidden","true"),p.innerHTML=c,a.appendChild(p),t.icon&&(s.dataset.aiaIcon=t.icon)}let u=document.createElement("span");if(u.className="magicx-aia-option-text",Ui(u,t),Xn.set(s,t.matchedText??""),a.appendChild(u),t.tag){let p=document.createElement("span");p.className="magicx-aia-option-tag",p.textContent=t.tag,a.appendChild(p)}let m=i?ve(t.item_count):null;if(m!==null){let p=document.createElement("span");p.className="magicx-aia-option-count",p.textContent=m,a.appendChild(p),s.dataset.aiaItemCount=String(t.item_count)}return s.appendChild(a),s}var Zn="magicx-aia-scroll-arrow",er="data-aia-scroll-arrow",ce="data-aia-visible",tr=1e3,nr=160,rr="--aia-scroll-arrow-bottom",$i="Scroll down for more options",Hs="[data-aia-products-label]",Fs=4,Ws=8,Bs=240;function Us(t,e,n,r){let i=t.scrollTop,s=n?.requestAnimationFrame,o=t.ownerDocument?.visibilityState==="hidden";if(!s||o||Jn(t)){t.scrollTop=i+e,r();return}let a=n.performance?.now?.()??Date.now(),l=()=>n.performance?.now?.()??Date.now(),d=()=>{let c=Math.min(1,(l()-a)/Bs),u=1-(1-c)*(1-c);t.scrollTop=i+e*u,c<1?s.call(n,d):r()};s.call(n,d)}function $s(t=document){let e="http://www.w3.org/2000/svg",n=t.createElementNS(e,"svg");n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("width","18"),n.setAttribute("height","18"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.75"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false");let r=t.createElementNS(e,"path");return r.setAttribute("d","M4 6.5 8 10.5l4-4"),n.appendChild(r),n}function Gi(t=document,e=k()){let n=t.createElement("button");return n.type="button",n.tabIndex=-1,n.className=Zn,n.setAttribute(er,""),n.setAttribute("aria-label",e.scrollArrow),n.setAttribute("aria-hidden","true"),n.disabled=!0,n.appendChild($s(t)),n}function Gs(t){let e=t.style.gridTemplateColumns.trim();return e?Math.max(1,e.split(/\s+/).length):1}function Jn(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function rn({dropdown:t,grid:e,button:n}){let r=e.ownerDocument?.defaultView??(typeof window<"u"?window:null),i=!1;n.disabled=!0;let s=null,o=null,a=null,l=null,d=f=>{if(f){if(n.hasAttribute(ce))return;if(n.setAttribute(ce,""),n.setAttribute("aria-hidden","false"),l!==null&&clearTimeout(l),Jn(e)){n.disabled=!1;return}l=setTimeout(()=>{l=null,!i&&n.hasAttribute(ce)&&(n.disabled=!1)},tr)}else n.removeAttribute(ce),n.setAttribute("aria-hidden","true"),l!==null&&clearTimeout(l),l=null,n.disabled=!0},c=f=>{let S=0,x=f;for(;x&&x!==t;)S+=x.offsetTop,x=x.offsetParent instanceof HTMLElement?x.offsetParent:null;return S},u=()=>{let f=t.querySelector(Hs),S;if(f){let x=c(f)+f.offsetHeight/2;S=t.clientHeight-x-n.offsetHeight/2}else{let x=c(e),I=r&&Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0;S=t.clientHeight-(x+e.offsetHeight)+(I>0?0:Ws)}n.style.setProperty(rr,`${Math.max(0,Math.round(S))}px`)},m=()=>{if(i||o!==null||a!==null)return;let f=e.querySelector("[data-aia-option][data-aia-loading]")!==null,S=e.scrollHeight-e.clientHeight-e.scrollTop;d(!f&&S>Fs)},p=()=>{if(i)return;u();let f=e.getAttribute("data-aia-group")??"";if(f!==s){s=f,d(!1),o!==null&&clearTimeout(o);let S=e.querySelectorAll("[data-aia-option]").length,x=Jn(e)?0:en(S,Gs(e));o=setTimeout(()=>{o=null,m()},x);return}m()},g=()=>{i||o!==null||(d(!1),a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,m()},nr))};e.addEventListener("scroll",g,{passive:!0});let h=f=>f.preventDefault(),y=()=>{let f=r?(Number.parseFloat(r.getComputedStyle(e).paddingTop)||0)+(Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0):0,S=Math.max(1,e.clientHeight-f);Us(e,S,r,g)};n.addEventListener("mousedown",h),n.addEventListener("click",y);let b=null;return r&&typeof r.ResizeObserver=="function"&&(b=new r.ResizeObserver(()=>{u(),m()}),b.observe(e)),p(),{update:p,destroy(){i||(i=!0,o!==null&&clearTimeout(o),o=null,a!==null&&clearTimeout(a),a=null,l!==null&&clearTimeout(l),l=null,n.disabled=!0,e.removeEventListener("scroll",g),n.removeEventListener("mousedown",h),n.removeEventListener("click",y),b?.disconnect(),n.removeAttribute(ce),n.setAttribute("aria-hidden","true"))}}}var ue="data-aia-fit",Ue="--aia-dropdown-fit-height";function on({dropdown:t,isOpen:e}){let n=t.ownerDocument?.defaultView??null,r=!1,i=!1,s=null,o=null,a=null,l=()=>{t.removeAttribute(ue),t.style.removeProperty(Ue)},d=p=>{let h=`${s}|${(p??t).scrollHeight}|${t.offsetWidth}`;if(a?.key===h)return a.height;let y=p?.scrollTop??0;t.removeAttribute(ue);let b=t.offsetHeight;return t.setAttribute(ue,""),p&&y&&(p.scrollTop=y),a={key:h,height:b},b},c=()=>{if(r)return;if(!e()){i=!1;return}i||(i=!0,l());let p=t.hasAttribute(ue),g=t.querySelector(".aia-grid")?.getAttribute("data-aia-group")??null,h=g!==s;s=g;let y=qs(t,n);if(y===null)return;let b=Vs(t);if(p){if(d(b)<=y){l();return}}else if(t.offsetHeight<=y)return;let f=`${Math.max(160,Math.floor(y))}px`;t.style.getPropertyValue(Ue)!==f&&t.style.setProperty(Ue,f),p?h&&b&&(b.scrollTop=0):t.setAttribute(ue,"")},u=()=>{r||o!==null||!n||(o=n.requestAnimationFrame(()=>{o=null,c()}))},m=n?.visualViewport??null;return m?.addEventListener("resize",u),m?.addEventListener("scroll",u),n?.addEventListener("resize",u),n?.addEventListener("scroll",u,{capture:!0,passive:!0}),c(),{update:c,destroy(){r||(r=!0,o!==null&&n?.cancelAnimationFrame(o),m?.removeEventListener("resize",u),m?.removeEventListener("scroll",u),n?.removeEventListener("resize",u),n?.removeEventListener("scroll",u,{capture:!0}))}}}function Vs(t){for(let e of Array.from(t.children))if(e.classList.contains("aia-stack"))return e;return null}function qs(t,e){if(!e)return null;let n=e.visualViewport,r=n?n.offsetTop:0,i=n?n.height:e.innerHeight;if(!i)return null;let s=t.offsetParent,o=s?s.getBoundingClientRect().top:0,a=s?o+t.offsetTop:t.getBoundingClientRect().top;return t.closest("[data-options-position]")?.getAttribute("data-options-position")==="above"?(s?a+t.offsetHeight:t.getBoundingClientRect().bottom)-r-8:r+i-a-8}var Ks=[159,119,164];function ln(t){let e=document.createElement("div");return e.id=t,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",n=>n.preventDefault()),Gt(e),e}var sn=new WeakMap;function zs(t,e,n){let r=sn.get(t);if(r||(r={button:Gi(t.ownerDocument,n),grid:null,controller:null},t.appendChild(r.button),sn.set(t,r)),r.button.getAttribute("aria-label")!==n.scrollArrow&&r.button.setAttribute("aria-label",n.scrollArrow),r.grid!==e&&(r.controller?.destroy(),r.controller=null,r.grid=e,e)){r.controller=rn({dropdown:t,grid:e,button:r.button});return}r.controller?.update()}var an=new WeakMap;function Vi(t){let e=an.get(t);if(e){e.update();return}an.set(t,on({dropdown:t,isOpen:()=>t.classList.contains("magicx-aia-dropdown--visible")}))}function ir(t){an.get(t)?.destroy(),an.delete(t);let e=sn.get(t);e&&(e.controller?.destroy(),sn.delete(t))}function dn(t,e){let n=e.strings??k(),{filteredOptions:r,activeIndex:i,isOpen:s,isLoading:o,showPills:a,isActivePillSelected:l,onSelect:d,onHighlight:c,onPillClick:u,onSkip:m}=e,p=Je(e.pills,n.keepTyping),g=et(p),h=a&&p.length>0,y=r.length>0,b=e.products.length>0,f=s&&(y||h||o||b);if(f?t.classList.add("magicx-aia-dropdown--visible"):t.classList.remove("magicx-aia-dropdown--visible"),o?t.setAttribute("data-aia-loading",""):t.removeAttribute("data-aia-loading"),!f){jn(t,!1),Vi(t);return}b?t.setAttribute("data-aia-has-products",""):t.removeAttribute("data-aia-has-products"),t.toggleAttribute("data-aia-skeleton-exiting",!!e.skeletonExiting);let S=t.querySelector(".aia-stack");S||(S=document.createElement("div"),S.className="aia-stack",S.style.setProperty("--aia-stack-space","8px"),t.appendChild(S));let x=e.showSkipButton&&g&&!e.isInputEmpty,I=h||o&&a||x,v=S.querySelector(".magicx-aia-pill-bar");if(I){v||(v=document.createElement("div"),v.className="magicx-aia-pill-bar aia-cluster",v.setAttribute("data-nowrap",""),v.setAttribute("data-aia-pillbar",""),S.insertBefore(v,S.firstChild));let P=v.querySelector(".magicx-aia-pill-scroll");P||(P=document.createElement("span"),P.className="magicx-aia-pill-scroll",P.setAttribute("data-aia-pill-scroll",""),v.insertBefore(P,v.firstChild)),Kt(P,a?p:[],0,u,!0,o&&a,l),Qs(v,x,o||e.skipDisabled,p[0],m,n)}else v&&v.remove();let w=e.suggestions[0],M=w?`${w.parameter} ${w.text}`:"",A=T(e.formatType),O=A&&!o;Bi(S,A?[]:r,i,d,c,e.listboxId,o,M,e.optionsPosition??"below",e.showOptionIcons??!0,e.showOptionImages??!0,e.showOptionCounts??!0,!e.skipDisabled),zs(t,S.querySelector(".aia-grid"),n),yi(S,O?r:[],i,e.listboxId,O?e.dateView:null,{selectedIso:e.selectedDateIso,selectedRange:e.selectedDateRange,rangeStart:e.dateRangeStart},{onSelect:d,onHighlight:c,onPreviousMonth:e.onPreviousMonth,onNextMonth:e.onNextMonth},!e.skipDisabled);let L=S.querySelector(".magicx-aia-skeleton-bars");if(o&&(!y||A)){if(!L){L=document.createElement("div"),L.className="magicx-aia-skeleton-bars",L.setAttribute("data-aia-skeleton-bars","");for(let P of Ks){let W=document.createElement("span");W.className="magicx-aia-skeleton-bar",W.style.width=`${P}px`,L.appendChild(W)}S.appendChild(L)}}else L&&L.remove();Oi(S,e.products,e.listboxId,e.onProductSelect,e.onProductFocusChange,e.productsLayout??"row",e.productImageFallback??"image",n,e.onProductAddToCart),jn(t,!0);let q=S.querySelector(".magicx-aia-footer")??Js(n),ne=i>=0&&!!r[i]?.is_tappable;Xs(q,$t(ne,e.isInputEmpty,n)),q.isConnected||S.appendChild(q),js(S,[".magicx-aia-pill-bar",".aia-grid",".magicx-aia-datepicker",".magicx-aia-skeleton-bars",".magicx-aia-products",".magicx-aia-footer"]),Vi(t)}function js(t,e){let n=e.map(r=>t.querySelector(`:scope > ${r}`)).filter(r=>r!==null);for(let r=0;r<n.length;r++)t.children[r]!==n[r]&&t.insertBefore(n[r],t.children[r]??null)}var Ys={itemSelector:".magicx-aia-skip",onClick:(t,e)=>{e.loading||e.onSkip()}};function Qs(t,e,n,r,i,s){Q(t,Ys,{onSkip:i,loading:n});let o=t.querySelector(".magicx-aia-skip");if(!e){o?.remove();return}o||(o=document.createElement("button"),o.type="button",o.tabIndex=-1,o.className="magicx-aia-skip",o.setAttribute("data-aia-skip",""),o.textContent=s.skip,o.disabled=!0,t.appendChild(o),J(o)),o.textContent!==s.skip&&(o.textContent=s.skip),o.setAttribute("aria-label",r?`${s.skipLabel} ${r.text}`:s.skipLabel),o.disabled=n}function Xs(t,{key:e,hint:n}){let r=t.querySelector(".magicx-aia-footer-key"),i=t.querySelector(".magicx-aia-footer-hint");!r||!i||(r.textContent!==e&&(r.textContent=e),i.textContent!==n&&(i.textContent=n))}function Js(t){let e=document.createElement("footer");e.className="magicx-aia-footer",e.setAttribute("data-aia-footer","");let n=document.createElement("div");n.className="aia-cluster magicx-aia-footer-row",n.setAttribute("data-align","center"),n.setAttribute("data-justify","between"),n.setAttribute("data-nowrap","");let r=document.createElement("div");r.className="aia-cluster magicx-aia-footer-hint-group",r.setAttribute("data-align","center"),r.style.setProperty("--aia-cluster-gap","5px");let i=document.createElement("kbd");i.className="magicx-aia-footer-key",i.textContent="tab";let s=document.createElement("span");s.className="magicx-aia-footer-hint",s.textContent=t.select,r.append(i,s);let o=document.createElement("a");o.className="aia-cluster magicx-aia-footer-brand-link",o.setAttribute("data-align","center"),o.href=Ut(),o.target="_blank",o.rel="noopener noreferrer",o.style.setProperty("--aia-cluster-gap","2px");let a=document.createElement("span");a.className="magicx-aia-footer-brand",a.textContent="AI";let l=document.createElement("span");return l.className="magicx-aia-footer-badge",l.textContent="Autocomplete",o.append(a,l),n.append(r,o),e.append(n),e}function qi(t,e){let n=ln(e.listboxId);return t.appendChild(n),{dropdown:n}}function or(t,e,n){let r=xe(e);dn(t.dropdown,{strings:n.strings,suggestions:e.editingIdentified?[{parameter:e.editingIdentified.parameter,text:U(e.editingIdentified.parameter),required:!0,options:e.filteredOptions}]:e.dropdownSuggestion??e.actionableSuggestions[0]?[{...e.dropdownSuggestion??e.actionableSuggestions[0],options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:e.actionableSuggestions,showPills:!0,showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",onProductAddToCart:n.addProductToCart,formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:r.selectedIso,selectedDateRange:r.selectedRange,dateRangeStart:r.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:n.selectOption,onHighlight:(i,s)=>{s!==void 0&&n.store.get().activeDropdownIndex!==s||n.store.set({activeDropdownIndex:i})},onPillClick:n.setActivePill,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:i=>n.store.set({isFocused:i})})}var Zs=6,ea=.3;function Ki(t){return t<=0?"0px":`${(-Math.min(ea,2*Zs/t)).toFixed(3)}px`}var zi=new Map;function ta(t,e,n){let r=zi.get(e);if(r!==void 0){t.style.setProperty("--aia-chip-image-fit",r),t.setAttribute("data-aia-image-loaded","");return}let i=n.createElement("img");i.setAttribute("referrerpolicy","no-referrer"),i.onload=()=>{if(!t.isConnected)return;t.setAttribute("data-aia-image-loaded","");let s=t.getBoundingClientRect().height,o=Number.parseFloat(getComputedStyle(t).fontSize);if(!(s>0&&o>0&&i.naturalWidth>0&&i.naturalHeight>0))return;let a=`${(s/o*(i.naturalWidth/i.naturalHeight)).toFixed(3)}em`;zi.set(e,a),t.style.setProperty("--aia-chip-image-fit",a)},i.src=e}function cn(t){let{input:e,segments:n,newParamId:r,editingParamId:i,placeholderText:s,isFocused:o}=t,a=t.showChipIcons??!0,l=t.showChipImages??!0,d=n.length===0;e.dataset.aiaEmpty=d?"true":"false",di(e,d?s:"");let c=n.map(f=>f.type==="completed"?`${f.type}:${f.value}${a?f.param.icon??f.param.icon_svg??"":""}${l?te(f.param.image_url)??"":""}`:`${f.type}:${f.value}`).join("\0"),u=e.dataset.segKey??"",m=e.dataset.newParamId??"",p=e.dataset.editingParamId??"";if(c===u&&(r??"")===m&&(i??"")===p)return;if(c===u){e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";for(let f of e.querySelectorAll("strong[data-param-id]")){let S=f.dataset.paramId,x=f.dataset.seg==="completed"&&S===r;f.classList.toggle("magicx-aia-shimmer-revealed",x),f.classList.toggle("magicx-aia-shimmer-sweep",x),f.classList.toggle("magicx-aia-segment--editing",S===i)}return}let g=o?F(e):null;e.dataset.segKey=c,e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";let h=N(e),y=h.createDocumentFragment(),b=0;for(let f of n)if(b+=f.value.length,f.type==="completed"){let S=h.createElement("strong");S.dataset.seg="completed",S.dataset.paramId=f.param.id;let x=f.param.id===r,I=f.param.id===i,v=["magicx-aia-segment","magicx-aia-segment--completed"];x&&v.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),I&&v.push("magicx-aia-segment--editing"),S.className=v.join(" "),S.style.letterSpacing=Ki(f.value.length);let w=l?te(f.param.image_url):null;if(w){let A=h.createElement("span");A.className="magicx-aia-segment-image",A.setAttribute("contenteditable","false"),A.setAttribute("aria-hidden","true"),A.style.setProperty("--aia-chip-image",`url("${w}")`),ta(A,w,h),S.appendChild(A),S.dataset.aiaImage=""}let M=!w&&a&&f.param.icon_svg?ee(f.param.icon_svg):null;if(M){let A=h.createElement("span");A.className="magicx-aia-segment-icon",A.setAttribute("contenteditable","false"),A.setAttribute("aria-hidden","true"),A.innerHTML=M,S.appendChild(A),f.param.icon&&(S.dataset.aiaIcon=f.param.icon)}S.appendChild(h.createTextNode(f.value)),y.appendChild(S)}else if(f.type==="identified"){let S=h.createElement("strong");S.dataset.seg="identified",S.dataset.paramId=f.param.id;let x=["magicx-aia-segment","magicx-aia-segment--completed"];f.param.id===i&&x.push("magicx-aia-segment--editing"),S.className=x.join(" "),S.style.letterSpacing=Ki(f.value.length),S.textContent=f.value,y.appendChild(S)}else y.appendChild(h.createTextNode(f.value));e.replaceChildren(y),e.dataset.aiaTextLength=String(b),g!=null?D(e,Math.max(0,Math.min(g,b))):o&&$r(e)&&D(e,b)}var na='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ji(t=k()){let e=document.createElement("button");return e.type="button",e.className="magicx-aia-submit",e.setAttribute("aria-label",t.submit),e.setAttribute("data-aia-submit",""),e.innerHTML=na.replace('aria-label="Submit"',`aria-label="${t.submit}"`),e}function ra(){let t=document.createElement("div");return t.setAttribute("contenteditable","plaintext-only"),t.contentEditable==="plaintext-only"}function Yi(t,e){let n=e.firstElementChild;if(!n){e.removeAttribute("data-aia-pill-wrapped");return}let r=n.getBoundingClientRect(),i=t.getBoundingClientRect();r.top>=i.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function Qi(t,e){let{listboxId:n}=e,r=ln(n);t.appendChild(r);let i=document.createElement("div");i.className="magicx-aia-input-wrapper",i.setAttribute("data-aia-input-wrapper",""),t.appendChild(i);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),i.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",ra()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",n),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=ji(e.strings),i.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),d.setAttribute("data-aia-submit-slot",""),i.appendChild(d));let c=new AbortController,{signal:u}=c,m=!1,p=0,g=()=>{let b=Me(o),S=b.length>0&&b[0]!==b[0].toUpperCase()?b[0].toUpperCase()+b.slice(1):b;e.handleChange(S)},h=()=>{let b=j(o)?.node??null;if(!b||!o.contains(b))return null;let x=(b.nodeType===Node.ELEMENT_NODE?b:b.parentElement)?.closest("strong[data-param-id]")?.dataset.paramId??null;return x&&Ur(o,x)?null:x};if(i.addEventListener("click",b=>{b.target?.closest("[data-aia-pill]")||o.focus()},{signal:u}),o.addEventListener("input",()=>{m||(p=performance.now(),g(),e.handleCaretAfterInput(F(o)))},{signal:u}),N(o).addEventListener("selectionchange",()=>{let b=j(o);if(!b||!o.contains(b.node))return;let f=b.collapsed?h():null,S=e.store.get(),x=S.editingParam?.id??S.editingIdentified?.id??null;if(f&&f!==x){e.startEditingParam(f);return}performance.now()-p<50||e.handleCaretMove(F(o))},{signal:u}),o.addEventListener("click",b=>{let f=ht(o,b.target);f&&(e.startEditingParam(f),bt(o,f))},{signal:u}),o.addEventListener("compositionstart",()=>{m=!0,o.setAttribute("data-aia-composing","true")},{signal:u}),o.addEventListener("compositionend",()=>{m=!1,o.removeAttribute("data-aia-composing"),g()},{signal:u}),o.addEventListener("beforeinput",b=>{let f=b,S=f.inputType;if(S==="insertParagraph"||S==="insertLineBreak"||S==="insertFromDrop"){b.preventDefault();return}if(S.startsWith("insert")||S.startsWith("delete")){let x=S.startsWith("delete")?"":f.data??"";e.replaceEditingRange(x)&&b.preventDefault()}},{signal:u}),o.addEventListener("paste",b=>{b.preventDefault();let f=(b.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!f)return;let S=N(o),x=dt(o);if(!x||!o.contains(x.startContainer))return;x.deleteContents();let I=S.createTextNode(f);x.insertNode(I),x.setStartAfter(I),Le(o,x.startContainer,x.startOffset),g()},{signal:u}),o.addEventListener("keydown",b=>e.handleKeyDown(b),{signal:u}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:u}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:u}),d&&d.addEventListener("click",b=>{let f=e.store.get();if(!(!!f.text||f.completedParams.length>0)||!e.onSubmit)return;b.stopPropagation(),e.endTypedWord?.();let x=e.store.get();e.onSubmit(Y(x.text,x.completedParams,x.skippedParams,{identifiedParams:x.identifiedParams,isReady:x.isReady,customFields:x.customFields}))&&e.afterSubmit?.()},{signal:u}),e.autoFocus!==!1){o.focus();let b=j(o);(!b||!o.contains(b.node))&&Le(o,o,0)}if(typeof ResizeObserver<"u"){let b=new ResizeObserver(()=>Yi(o,a));b.observe(o),c.signal.addEventListener("abort",()=>b.disconnect(),{once:!0})}return{input:o,inlinePillContainer:a,dropdown:r,submitButton:l,abort:c}}function sr(t,e,n){let{input:r,inlinePillContainer:i,dropdown:s,submitButton:o}=t,{pillPlacement:a,setActivePill:l,selectOption:d,store:c}=n;r.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${n.listboxId}-option-${e.activeDropdownIndex}`:"";if(u?r.setAttribute("aria-activedescendant",u):r.removeAttribute("aria-activedescendant"),o){let b=n.strings??k();o.getAttribute("aria-label")!==b.submit&&o.setAttribute("aria-label",b.submit);let f=o.querySelector("svg");f&&f.getAttribute("aria-label")!==b.submit&&f.setAttribute("aria-label",b.submit);let S=!!e.text||e.completedParams.length>0;o.disabled=!S}let m=r.dataset.newParamId??"",p=e.newParamId!==null&&e.newParamId!==m;if(cn({input:r,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused,showChipIcons:n.showChipIcons??!0,showChipImages:n.showChipImages??!0}),a==="inline"){let b=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,f=Xe(e.actionableSuggestions);b||f.length>0?Kt(i,f,0,l,!1,b,e.isActivePillSelected):$n(i)}else $n(i);Yi(r,i),p?(r.focus(),D(r,e.caretOffset??e.text.length)):e.isFocused&&Me(r)!==e.text&&D(r,e.text.length);let g=e.editingParam?{parameter:e.editingParam.suggestionParameter,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:e.editingIdentified?{parameter:e.editingIdentified.parameter,text:U(e.editingIdentified.parameter),required:!0,options:[]}:null,h=e.dropdownSuggestion??g??e.actionableSuggestions[0],y=xe(e);dn(s,{strings:n.strings,suggestions:h?[{...h,options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:g?[g]:e.actionableSuggestions,showPills:a==="dropdown",showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",onProductAddToCart:n.addProductToCart,formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:y.selectedIso,selectedDateRange:y.selectedRange,dateRangeStart:y.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:d,onHighlight:(b,f)=>{f!==void 0&&c.get().activeDropdownIndex!==f||c.set({activeDropdownIndex:b})},onPillClick:l,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:b=>c.set({isFocused:b})})}function un(t){let e=t,n=new Set,r=[],i=!1;return{get:()=>e,set:s=>{let o=typeof s=="function"?s(e):s,a=e;if(e={...e,...o},r.push([e,a]),!i){i=!0;try{let l=0;for(let d=r.shift();d;d=r.shift()){if(++l>1e4)throw r.length=0,new Error("createStore: notifications did not settle after 10000 deliveries \u2014 a listener is likely calling set() on every notification");let[c,u]=d;for(let m of n)m(c,u)}}catch(l){throw r.length=0,l}finally{i=!1}}},subscribe:s=>(n.add(s),()=>{n.delete(s)})}}function Xi(t,e){let n,r,i=s=>(s!==n&&(n=s,r=e(s)),r);return{get:()=>{let s=t.get();return{...s,...i(s)}},set:s=>{typeof s=="function"?t.set(o=>{let a={...o,...i(o)};return s(a)}):t.set(s)},peek:s=>{let o={...t.get(),...s};return{...o,...e(o)}},subscribe:s=>t.subscribe((o,a)=>{let l={...a,...i(a)},d={...o,...i(o)};s(d,l)})}}var ar=new WeakSet,Ji=new WeakMap;function eo(t){return t.nodeType===Node.DOCUMENT_NODE}function ia(t){return eo(t)?t:t.ownerDocument}function oa(t){let e=Ji.get(t);if(e)return e;let n=t.defaultView?.CSSStyleSheet;if(typeof n!="function")return null;try{let r=new n;return typeof r.replaceSync!="function"?null:(r.replaceSync(no),Ji.set(t,r),r)}catch{return null}}function Zi(t,e){if(e.querySelector("style[data-magicx-aia]"))return;let n=t.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=no,e.appendChild(n)}function to(t){if(typeof document>"u")return;let e=t??document;if(ar.has(e))return;let n=ia(e);if(eo(e)){let s=e.head??e.documentElement;if(!s)return;Zi(n,s),ar.add(e);return}let r=oa(n),i=e.adoptedStyleSheets;r&&Array.isArray(i)?i.includes(r)||(e.adoptedStyleSheets=[...i,r]):Zi(n,e),ar.add(e)}var no=`.aia-stack {
2
2
  display: flex;
3
3
  flex-direction: column;
4
4
  gap: var(--aia-stack-space, 0.5rem);
@@ -927,10 +927,10 @@
927
927
  display: none;
928
928
  }
929
929
 
930
- /* While the integration's promise is in flight the button dims and ignores
931
- presses; once it resolves the cart turns into a check for a moment. */
930
+ /* While the integration's promise is in flight the button ignores presses
931
+ and shows a spinner (below); once it resolves the cart turns into a check,
932
+ which stays. */
932
933
  .magicx-aia-product-cart[data-aia-cart-state="adding"] {
933
- opacity: 0.6;
934
934
  cursor: progress;
935
935
  }
936
936
 
@@ -942,6 +942,36 @@
942
942
  display: inline;
943
943
  }
944
944
 
945
+ /* While the add is in flight the cart gives way to a spinning arc. A slower
946
+ turn under reduced motion: it is the only sign the press took. */
947
+ .magicx-aia-product-cart-spinner {
948
+ display: none;
949
+ }
950
+
951
+ .magicx-aia-product-cart[data-aia-cart-state="adding"] .magicx-aia-product-cart-glyph {
952
+ display: none;
953
+ }
954
+
955
+ .magicx-aia-product-cart[data-aia-cart-state="adding"] .magicx-aia-product-cart-spinner {
956
+ display: inline;
957
+ }
958
+
959
+ .magicx-aia-product-cart[data-aia-cart-state="adding"] svg {
960
+ animation: magicx-aia-product-cart-spin 0.8s linear infinite;
961
+ }
962
+
963
+ @keyframes magicx-aia-product-cart-spin {
964
+ to {
965
+ transform: rotate(360deg);
966
+ }
967
+ }
968
+
969
+ @media (prefers-reduced-motion: reduce) {
970
+ .magicx-aia-product-cart[data-aia-cart-state="adding"] svg {
971
+ animation-duration: 2s;
972
+ }
973
+ }
974
+
945
975
  /* A sold-out product's image steps back, so the badge is not the only cue.
946
976
  Desaturated rather than faded: opacity lets the panel show through, which
947
977
  muddies a photo on a dark surface. */
@@ -2793,5 +2823,5 @@
2793
2823
  max-height: none;
2794
2824
  overflow: visible;
2795
2825
  }
2796
- `;var pn=class{constructor(){this.reported=new Set}run(e,n){try{return n()}catch(r){this.report(e,r,e);return}}runListener(e,n,r=e){try{return n(),!0}catch(i){return this.report(e,i,r),!1}}report(e,n,r){this.reported.has(r)||(this.reported.add(r),console.error(`[AIAutocomplete] "${e}" threw. The error is contained \u2014 SDK state is unaffected. Later failures of "${e}" on this instance are not logged.`,n))}};var mn=class{constructor(e){this.boundary=e;this.listeners={};this.keys=new WeakMap;this.registrationCount=0}on(e,n){let r=`${String(e)}#${++this.registrationCount}`,i=(...o)=>n(...o);this.keys.set(i,r);let s=this.listeners[e];return s||(s=new Set,this.listeners[e]=s),s.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...n){let r=this.listeners[e];if(!r)return!0;let i=!0;for(let s of r)this.boundary.runListener(String(e),()=>s(...n),this.keys.get(s)??String(e))||(i=!1);return i}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var gn=class{constructor(){this.timers=new Map}schedule(e,n,r){this.clear(e);let i=setTimeout(()=>{this.timers.delete(e),n()},r);this.timers.set(e,i)}clear(e){let n=this.timers.get(e);n!==void 0&&(clearTimeout(n),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};function aa(t){let e;try{e=new URL(t??K).host}catch{return null}let n=Ge.get(e);return n?`https://${n}`:null}var ro=new WeakMap;function io(t,e){if(!t.head)return;let n=aa(e);if(!n)return;let r=ro.get(t);r||(r=new Map,ro.set(t,r));let i=r.get(n);i||(i=t.createElement("link"),i.rel="preconnect",i.href=n,r.set(n,i)),t.head.append(i)}var Pe=class{constructor(e,n="auto",r){this.container=e;this.mode=n;this.onResolve=r;this.mediaQuery=null;this.onSystemChange=e=>{this.setResolved(e.matches?"dark":"light")};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.setResolved(this.mediaQuery.matches?"dark":"light")):this.setResolved(this.mode)}setResolved(e){this.container.dataset.mode=e,this.onResolve?.(e)}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function lr(t){return t.isDropdownOpen&&!t.isLoading}var la=50,da=new Set(["search_started","submit","product_click","impression"]),ca="newParam",oo="suggestionRemoval",ua="selectionAnimation",dr="skeletonExit",pa=650,ma=0;function ga(){return`:ac-${++ma}:`}var so=170,fa=100;function ao(){return{text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],traditionalAutocomplete:!1,customFields:null,optionSearch:null,activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,dropdownHeld:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1,dateViewMonth:null,pendingRangeStart:null,editingIdentified:null}}var fn=class{constructor(e,n={}){this.inputStore=un(ao());this._listboxId=ga();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new gn;this.boundary=new pn;this.subscriberCount=0;this.emitter=new mn(this.boundary);this.sessionId=crypto.randomUUID();this.lastRequestId=null;this.searchStartedSessionId=null;this.funnelTelemetry=null;this.pendingSearchStarted=!1;this.openWordText=null;this.heldIdentified=null;this.lastImpressionKey="";this.visibleImpression=!1;this.destroyed=!1;this.emitSubmit=e=>(this.recordSubmit(e),this.emitter.emit("submit",e));this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=n,this.renderMode=n.renderMode??"full",this.store=Xi(this.inputStore,r=>Qr(r,this.opts)),n.onSubmit&&this.emitter.on("submit",n.onSubmit),n.onResult&&this.emitter.on("result",n.onResult),n.onError&&this.emitter.on("error",n.onError),n.onChange&&this.emitter.on("change",n.onChange),n.onParamsChange&&this.emitter.on("paramsChange",n.onParamsChange),n.onStateChange&&this.emitter.on("stateChange",n.onStateChange),n.onFocus&&this.emitter.on("focus",n.onFocus),n.onBlur&&this.emitter.on("blur",n.onBlur),n.onProductSelect&&this.emitter.on("productSelect",n.onProductSelect),n.value!==void 0&&this.store.set({text:n.value}),n.completedParams!==void 0&&this.store.set({completedParams:n.completedParams}),this.holdOpen=new rt(this.store,e),this.pillsController=new Pt(this.store,{onPillSelected:({rawQuery:r,selectedPill:i,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:r,selected_pill:i,other_pills:s})}}),this.reEdit=new Wt({store:this.store,scheduleSetCursor:r=>this.scheduleSetCursor(r),fireTelemetry:(r,i)=>this.fireTelemetry(r,i),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer(),fetchNow:()=>this.fetchNow()}),this.productsController=new Et(this.store,()=>this.opts.products,()=>this.opts.showProducts!==!1,()=>this.opts.language,()=>this.opts.mapProducts),this.optionSource=new vt(this.store,()=>this.opts.optionOverrides,{onAnswer:r=>{r==="edit"?this.reEdit.promoteIfExact():this.maybePromoteExactMatch(this.store.get().text)},onMiss:(r,i)=>{r==="pill"&&i.length>0&&this.fetchController.attemptNow()}}),this.fetchController=new nt(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,()=>this.resolveSource(),()=>this.opts.additionalContext,()=>this.opts.language,{getProductId:()=>this.opts.productId,getCurrency:()=>this.opts.currency,onRequest:({query:r,signal:i,isCurrent:s})=>{io(this.container.ownerDocument,this.opts.apiConfig?.endpoint),this.productsController.run(r,i,s).catch(()=>{})},onAutoMatch:({active:r,matched:i,rawQuery:s})=>{let o=r.options??[];this.fireTelemetry("option",{raw_query:s,selected_option:i.text,other_options:o.filter(a=>a.text!==i.text).map(a=>a.text),key:r.parameter,position:le(o,i.text),chip_origin:"typed"})},onResponse:({requestId:r,funnelTelemetry:i,visibleImpression:s})=>{this.lastRequestId=r,this.funnelTelemetry=i,this.visibleImpression=s,this.pendingSearchStarted&&(this.pendingSearchStarted=!1,this.fireTelemetry("search_started",{})),this.fireImpression(),this.emitter.hasListeners("result")&&this.emitter.emit("result",this.buildResult())},productsForResponse:r=>this.productsController.forResponse(r),consumerTick:(r,i)=>this.optionSource.tick(r,i),isWordOpen:()=>this.isWordOpen(),holdIdentified:r=>{this.heldIdentified={text:this.store.get().text,candidates:r}}}),this.keyboardController=new xt(this.store,{columns:n.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.resetAfterSubmit():void 0,selectOption:r=>this.selectOption(r),removeParamAtCaret:r=>this.removeParamAtCaret(r),startEditingParamAtCaret:r=>this.startEditingParamAtCaret(r),exitEditMode:()=>this.exitEditMode(),exitEditingIdentified:()=>this.exitEditingIdentified(),skipActivePill:()=>this.skipActivePill(),endTypedWord:r=>this.endTypedWord(r)}),this.unsubscribers.push(this.store.subscribe((r,i)=>{r.text!==i.text&&this.emitter.emit("change",r.text),r.completedParams!==i.completedParams&&this.emitter.emit("paramsChange",r.completedParams),r.isFocused!==i.isFocused&&(r.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",r)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.subscribeSkeletonMirror(),this.subscribeVisibleImpression(),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.text===i.text&&r.completedParams===i.completedParams||r.identifiedParams.length===0)return;let{valid:s,invalid:o}=Ae(r.text,r.completedParams,r.identifiedParams);o.length>0&&this.store.set({identifiedParams:s})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.identifiedParams===i.identifiedParams)return;let s=r.editingIdentified;if(!s||r.identifiedParams.some(l=>l.id===s.id))return;let o=0,a;for(let l of r.segments){if(l.type==="identified"&&o===s.anchor&&l.value===s.text){a=l.param;break}o+=l.value.length}if(a){this.store.set({editingIdentified:{...s,id:a.id}});return}this.store.set({editingIdentified:null,activeDropdownIndex:-1})})),this.unsubscribers.push(this.store.subscribe(r=>{let i=r.pendingRangeStart;!i||i.key===Ne(r)||this.store.set({pendingRangeStart:null})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{let s=r.pendingSpan;if(!s||r.text===i.text&&r.completedParams===i.completedParams&&r.identifiedParams===i.identifiedParams)return;let o=s.anchor;if(r.text!==i.text){let l=Tr(i.text,r.text,o);if(l===null){this.store.set({pendingSpan:null});return}o=l}r.text.slice(o).trim().length===0||vr(r.segments,o)?this.store.set({pendingSpan:null}):o!==s.anchor&&this.store.set({pendingSpan:{anchor:o,snapshot:s.snapshot}})})),this.renderMode!=="headless"&&(to(this.opts.styleRoot??ae(this.container)),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.optionSource.start(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let{isFocused:e,dropdownHeld:n}=this.store.get();this.optionSource.reset(),this.store.set({...ao(),isFocused:e,dropdownHeld:n,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.lastRequestId=null,this.lastImpressionKey="",this.pendingSearchStarted=!1,this.fetchController.doFetch("",[])}resetAfterSubmit(){this.opts.resetOnSubmit!==!1&&this.reset()}destroy(){this.destroyed=!0,this.fetchController.dispose(),this.optionSource.dispose(),this.holdOpen.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs&&(ci(this.domRefs.input),ir(this.domRefs.dropdown)),this.dropdownRefs&&ir(this.dropdownRefs.dropdown),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}prefillText(e){this.applyTextChange(e,!1)}noteSearchStarted(){this.searchStartedSessionId!==this.sessionId&&(this.searchStartedSessionId=this.sessionId,this.funnelTelemetry===null?this.pendingSearchStarted=!0:this.fireTelemetry("search_started",{}))}setValue(e){let n=this.store.get();if(n.editingIdentified&&e!==n.text){this.store.set({text:e,editingIdentified:null,activeDropdownIndex:-1});return}this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let n=this.store.get().text.length;this.store.set({caretOffset:n,isFocused:!0}),this.scheduleSetCursor(n)}removeLastParam(){this.pillsController.removeLastParam()}findChipSpanAt(e){let n=0;for(let r of this.store.get().segments){let i=n;if(n+=r.value.length,r.type!=="text"&&e>i&&e<=n)return{kind:r.type,param:r.param,start:i,end:n}}return null}withoutChip(e,n){return n.kind==="completed"?{completedParams:e.completedParams.filter(r=>r.id!==n.param.id)}:{identifiedParams:e.identifiedParams.filter(r=>r.id!==n.param.id)}}removeParamAtCaret(e){let n=this.findChipSpanAt(e);if(!n)return!1;let{text:r}=this.store.get(),{start:i,end:s}=n;if(e===s){let{text:l,removed:d}=Ft(r,i,s);return this.store.set(c=>({text:l,filterBase:Math.min(c.filterBase>i?Math.max(i,c.filterBase-d):c.filterBase,l.length),...this.withoutChip(c,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(i),!0}let o=yt(r,e),a=r.slice(0,o)+r.slice(e);return this.store.set(l=>({text:a,filterBase:Math.min(l.filterBase,a.length),...this.withoutChip(l,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(o),!0}startEditingParamAtCaret(e){let n=this.findChipSpanAt(e);return!n||n.kind!=="completed"||n.end!==e?!1:(this.reEdit.start(n.param.id),this.store.get().editingParam?.id===n.param.id)}scheduleSetCursor(e){queueMicrotask(()=>{let n=this.domRefs;if(n)n.input.focus(),D(n.input,e);else{let r=this.opts.setCursor;r&&this.boundary.runListener("setCursor",()=>r(e))}})}clearNewParamId(){this.store.set({newParamId:null})}startEditingIdentified(e){let n=this.store.get();if(n.editingIdentified?.id===e)return!0;let r=n.identifiedParams.find(d=>d.id===e);if(!r)return!1;let i=B(r);if(!T(i))return!1;let s=i==="date-range"?De(r.text):null,o=0,a=-1;for(let d of n.segments){if(d.type!=="text"&&d.param.id===e){a=o;break}o+=d.value.length}if(a<0)return!1;let l=a+r.text.length;return this.store.set({editingIdentified:{id:e,parameter:r.parameter,anchor:a,tail:l,text:r.text,iso:s?s.start:Ct(r),isoEnd:s?s.end:null,format:i},editingParam:null,editingAnchor:null,editingTail:null,caretOffset:l,activeDropdownIndex:-1,pillTapped:!0}),!0}exitEditingIdentified(){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1})}startEditingParam(e){this.reEdit.start(e),this.store.get().editingParam?.id!==e&&this.startEditingIdentified(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){let n=this.store.get().editingIdentified;n&&e!=null&&(e<n.anchor||e>n.tail)&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}clearHighlight(e){this.store.get().activeDropdownIndex===e&&this.store.set({activeDropdownIndex:-1})}prepareSubmit(){this.endTypedWord(!0)}recordSubmit(e){this.fireTelemetry("submit",{query:e.query,completed_pills:e.completed_params.filter(n=>n.placeholder).map(n=>({key:n.parameter,value:n.text??""}))})}selectProduct(e){let n=this.store.get(),r=n.products.findIndex(s=>s.id===e.id),i=n.customFields?.items?.matched?.find(s=>s.source_id===e.id)?.origin_id;this.fireTelemetry("product_click",{query:n.text,product_id:e.id,...i&&{origin_id:i},position:r>=0?r+1:null}),this.emitter.emit("productSelect",e)}addProductToCart(e){let n=this.opts.onProductAddToCart;if(!n)return Promise.resolve();try{return Promise.resolve(n(e)).then(()=>{})}catch(r){return Promise.reject(r)}}hasProductAddToCart(){return typeof this.opts.onProductAddToCart=="function"}handleTextChange(e){this.applyTextChange(e,!0)}applyTextChange(e,n){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.handleChange(e,n)}showPreviousMonth(){this.pageDateView(-1)}showNextMonth(){this.pageDateView(1)}pageDateView(e){let n=this.store.get();if(!T(n.activeFormatType)||!n.dateView)return;let r=ot(n.dateView,e);this.store.set({dateViewMonth:{...r,key:Ne(n)},activeDropdownIndex:-1})}skipActivePill(){let e=this.store.get();if(e.editingParam||e.inSelectionAnimation)return;let n=e.suggestions.filter(a=>a.parameter==="placeholder"),r=e.suggestions.filter(a=>a.parameter!=="placeholder");if(r.length===0||E(r[0]))return;let i=r[0],s=r.slice(1),o=e.skippedParams.some(a=>a.parameter===i.parameter);this.store.set({suggestions:[...n,...s],pillTapped:s.length>0,activeDropdownIndex:-1,...o?{}:{skippedParams:[...e.skippedParams,{id:crypto.randomUUID(),parameter:i.parameter,suggestionPlaceholder:i.text}]}}),s.length===0&&this.fetchNow()}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){let n=`subscribe#${++this.subscriberCount}`;return this.store.subscribe(r=>{this.boundary.runListener("subscribe",()=>e(r),n)})}getState(){return this.store.get()}getResult(){return this.buildResult()}getRequestId(){return this.lastRequestId}buildResult(){let e=this.store.get();return Y(e.text,e.completedParams,e.skippedParams,{identifiedParams:e.identifiedParams,isReady:e.isReady,customFields:e.customFields})}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,n){return this.emitter.on(e,n)}refreshProducts(){this.opts.mapProducts&&this.productsController.refresh()}update(e){let n=this.opts.products,r=this.opts.mapProducts,i=this.opts.showProducts,s=this.opts.optionOverrides;Object.assign(this.opts,e),"language"in e&&this.updateLanguageAttribute(),"optionOverrides"in e&&e.optionOverrides!==s&&this.optionSource.refresh(),"products"in e&&e.products!==n||"showProducts"in e&&e.showProducts!==i?this.productsController.resync():"mapProducts"in e&&e.mapProducts!==r&&this.productsController.refresh(),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0||e.showSkipButton!==void 0||e.showOptionIcons!==void 0||e.showOptionImages!==void 0||e.showOptionCounts!==void 0||e.productsLayout!==void 0||e.productImageFallback!==void 0||e.showChipIcons!==void 0||e.showChipImages!==void 0||"language"in e)&&this.store.set({}),e.value!==void 0&&this.setValue(e.value),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let n=!this.store.get().text;this.applyOption(e),n&&this.store.get().text&&this.noteSearchStarted()}applyOption(e){let n=this.store.get();if(n.activeFormatType==="date-range"){let i=G(e);if(i){let s=n.dateRangeStart;if(!s){this.store.set({pendingRangeStart:{iso:i,key:Ne(n)}});return}this.store.set({pendingRangeStart:null}),this.selectOption(zr(s,i));return}}if(n.editingIdentified){this.commitIdentifiedDate(e);return}if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null){this.timers.clear(dr),this.reEdit.selectOption(e);return}let r=ti(n,e);if(r){if(this.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:r.telemetry.selectedOption,other_options:T(n.activeFormatType)?[]:r.telemetry.otherOptions,key:r.telemetry.key,position:T(n.activeFormatType)?null:r.telemetry.position,chip_origin:"tap"}),this.timers.clear(dr),this.store.set({...r.patch,...Ht(n)}),this.startSelectionAnimationTimer(),this.timers.clear(oo),r.remainingActionable>0){let i=r.consumedSuggestion;this.timers.schedule(oo,()=>{this.store.get().suggestions.includes(i)&&this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==i)}))},so)}this.fetchNow()}}startSelectionAnimationTimer(){this.timers.schedule(ua,()=>this.store.set({inSelectionAnimation:!1}),so)}resolveVisitorId(){let e=this.opts.visitorId;if(typeof e!="function")return e;try{return e()}catch{return}}resolveSource(){return this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk")}subscribeVisibleImpression(){this.unsubscribers.push(this.store.subscribe((e,n)=>{this.visibleImpression&&(!e.isDropdownOpen&&n.isDropdownOpen&&(this.lastImpressionKey=""),lr(e)&&!lr(n)&&queueMicrotask(()=>this.fireImpression()))}))}fireImpression(){if(this.funnelTelemetry!==!0||this.destroyed)return;let e=this.store.get();if(this.visibleImpression&&!lr(e))return;let n=e.suggestions.filter(s=>s.parameter!=="placeholder"&&!E(s)).map(s=>({key:s.parameter,options:(s.options??[]).slice(0,la).map(o=>o.text)})),r=e.products.map(s=>s.id);if(n.length===0&&r.length===0)return;let i=JSON.stringify([n,r]);i!==this.lastImpressionKey&&(this.lastImpressionKey=i,this.fireTelemetry("impression",{query:e.text,pills:n,product_ids:r}))}fireTelemetry(e,n){let r=this.funnelTelemetry===!0;if(!r&&da.has(e))return;if(!r&&e==="option"){let{key:s,position:o,chip_origin:a,...l}=n;n=l}let i=this.resolveSource();ei({source:i,sessionId:this.sessionId,visitorId:r?this.resolveVisitorId():void 0,requestId:r?this.lastRequestId:null,keepalive:r,type:e,language:ie(this.opts.language),queryData:n,apiConfig:this.opts.apiConfig})}updateLanguageAttribute(){let{language:e}=k(this.opts.language);e!=="en"?this.container.dataset.aiaLanguage=e:delete this.container.dataset.aiaLanguage}setupContainer(){this.container.classList.add("magicx-aia"),this.updateLanguageAttribute(),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"dropdown",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new Pe(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,n={store:this.store,listboxId:this.listboxId,get strings(){return k(e.opts.language)},get pillPlacement(){return e.opts.pillPlacement??"dropdown"},get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get addProductToCart(){return e.hasProductAddToCart()?i=>e.addProductToCart(i):void 0},get showChipIcons(){return e.opts.showChipIcons??!0},get showChipImages(){return e.opts.showChipImages??!0},get optionsPosition(){return e.opts.optionsPosition??"below"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.resetAfterSubmit(),endTypedWord:()=>e.endTypedWord(!0),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth(),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i,!0),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Qi(this.container,n);let r=()=>{this.domRefs&&sr(this.domRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),sr(this.domRefs,this.store.get(),n),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e=this,n={store:this.store,listboxId:this.listboxId,get strings(){return k(e.opts.language)},get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get addProductToCart(){return e.hasProductAddToCart()?i=>e.addProductToCart(i):void 0},get optionsPosition(){return e.opts.optionsPosition??"below"},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth()};this.dropdownRefs=qi(this.container,n);let r=()=>{this.dropdownRefs&&or(this.dropdownRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),or(this.dropdownRefs,this.store.get(),n),this.subscribeNewParamTimer()}subscribeViewportBreakpoint(e){if(typeof window>"u"||typeof window.matchMedia!="function")return;let n=window.matchMedia(_e),r=()=>e();n.addEventListener("change",r),this.unsubscribers.push(()=>n.removeEventListener("change",r))}subscribeBatchedRender(e){let n=!1;this.unsubscribers.push(this.store.subscribe(()=>{n||(n=!0,queueMicrotask(()=>{n=!1,e()}))}))}subscribeSkeletonMirror(){this.unsubscribers.push(this.store.subscribe((e,n)=>{if(!e.skeletonOptions)return;if(!n.isLoading&&e.isLoading){e.skeletonRequested||this.store.set({skeletonRequested:!0});return}if(!n.isLoading||e.isLoading)return;let r={skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1};if(!e.skeletonExiting){this.store.set(r);return}this.timers.schedule(dr,()=>this.store.set(r),fa)}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,n)=>{e.newParamId&&e.newParamId!==n.newParamId&&this.timers.schedule(ca,()=>this.store.set({newParamId:null}),pa)}))}handleChange(e,n){let r=this.store.get();n&&e&&!r.text&&this.noteSearchStarted(),this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:s}=Cr(e,r.completedParams);s.length>0&&this.store.set({completedParams:i});let o=this.heldIdentified;this.heldIdentified=null,this.openWordText=n&&/\S$/.test(e)?e:null,this.maybePromoteExactMatch(e),o&&/^\s+$/.test(e.slice(o.text.length))&&e.startsWith(o.text)&&this.admitIdentified(o.candidates),this.maybeOpenPendingSpan()}isWordOpen(){return this.opts.commitOnWordEnd===!0&&this.openWordText===this.store.get().text}admitIdentified(e){let n=this.store.get(),{valid:r}=Ae(n.text,n.completedParams,e);r.length!==0&&this.store.set({identifiedParams:[...n.identifiedParams,...r]})}endTypedWord(e=!1){let n=this.isWordOpen();if(!n&&!e)return!1;let r=this.heldIdentified;this.heldIdentified=null,this.openWordText=null;let i=this.store.get();this.maybePromoteExactMatch(i.text,e?"submit":"fresh",n),r?.text===i.text&&this.admitIdentified(r.candidates);let s=this.store.get();return s.completedParams!==i.completedParams||s.identifiedParams!==i.identifiedParams}maybeOpenPendingSpan(){let e=this.store.get();if(e.pendingSpan||e.actionableSuggestions.length===0)return;let n=z(e.text,Math.min(e.filterBase,e.text.length),e.placeholderText),r=xr(e.segments,n);e.text.slice(r).trim().length!==0&&this.store.set({pendingSpan:{anchor:r,snapshot:e.actionableSuggestions}})}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(s=>s.id===e.editingParam?.id)||this.optionSource.owns(e.editingParam.suggestionParameter,e.optionQuery))return;let n=e.caretOffset??e.editingAnchor,r=e.text.slice(e.editingAnchor,n);oe(e.editingParam.options,r).some(s=>s.is_tappable)||(this.reEdit.exit(),this.fetchNow())}fetchNow(){let e=this.store.get(),{rawQuery:n,completedParams:r}=R(e.text,e.completedParams);this.fetchController.doFetch(n,r)}commitIdentifiedDate(e){let n=this.store.get(),r=n.editingIdentified;if(!r)return;if(n.text.slice(r.anchor,r.tail)!==r.text){this.store.set({editingIdentified:null,activeDropdownIndex:-1});return}let i=n.text.slice(0,r.anchor),s=n.text.slice(r.tail),o=r.anchor===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=s.length===0||s[0]!==" "?`${o} `:o,d=i+l+s,c=d.length,u={id:crypto.randomUUID(),placeholder:"",parameter:r.parameter,text:o,value:e.value,kind:e.kind,suggestionParameter:r.parameter,suggestionPlaceholder:U(r.parameter),options:[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url};this.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:[],key:r.parameter,position:null,chip_origin:"tap"}),this.store.set({text:d,completedParams:[...n.completedParams,u],identifiedParams:n.identifiedParams.filter(m=>m.id!==r.id),newParamId:u.id,filterBase:c,caretOffset:c,editingIdentified:null,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.startSelectionAnimationTimer(),this.scheduleSetCursor(c),this.fetchNow()}maybePromoteExactMatch(e,n="fresh",r=!1){let i=this.store.get();if(T(i.activeFormatType)||this.isWordOpen())return;let s=_t({mode:n,finishWord:r,text:e,completedParams:i.completedParams,suggestions:i.suggestions,filterBase:i.filterBase,filterInProgress:i.filterInProgress,phraseExactMatch:this.fetchController.isPhraseExactMatch()});if(s){if(this.funnelTelemetry===!0){let o=n==="submit"&&s.suggestion?s.suggestion:i.actionableSuggestions[0],a=o.options??[];this.fireTelemetry("option",{raw_query:R(e,i.completedParams).rawQuery,selected_option:s.option.text,other_options:a.filter(l=>l.text!==s.option.text).map(l=>l.text),key:o.parameter,position:le(a,s.option.text),chip_origin:"typed"})}this.store.set(s.patch)}}};0&&(module.exports={AIAutocomplete,ATTRIBUTION_URL,DATE_RANGE_META_END,DATE_RANGE_META_START,DEFAULT_OPTION_COUNT_UNIT,ModeController,OPTIONS_GRID_MOBILE_QUERY,OPTION_ENTER_DELAY_VAR,OPTION_ENTER_FADE_MS,OPTION_ENTER_RISE_MS,OPTION_ENTER_RISE_PX,OPTION_ENTER_STAGGER_MS,OPTION_IMAGE_WIDTH,PLACEHOLDER_FADE_OUT_MS,PLACEHOLDER_LEAVING_ATTR,PLACEHOLDER_SWAP_GAP_MS,PLACEHOLDER_TYPE_MS,PLACEHOLDER_WORD_PAUSE_MS,PRODUCT_IMAGE_WIDTH,PRODUCT_PATH_PREFIX,PRODUCT_ROW_PX_PER_LINE,RANGE_SEPARATOR,SCHEMA_VERSION,SCROLL_ARROW_ATTR,SCROLL_ARROW_BOTTOM_VAR,SCROLL_ARROW_CLASS,SCROLL_ARROW_FADE_MS,SCROLL_ARROW_LABEL,SCROLL_ARROW_SCROLL_IDLE_MS,SCROLL_ARROW_VISIBLE_ATTR,SKIPPED_PARAM_TEXT,SMART_SUGGESTION_SPARKLE_SVG,VIEWPORT_FIT_ATTR,VIEWPORT_FIT_HEIGHT_VAR,WEEKDAY_LABELS,addMonths,attachProductRowWheel,attachScrollArrow,attachViewportFit,buildAttributionUrl,buildDateOptions,buildQuery,buildSubmitResult,cellDay,cellIso,chipIdFromTap,computeOptionsGridLayout,containScroll,createStore,cursorIsAtEnd,dateCellMarks,dateSelectionFor,extractPlainText,formatAbsoluteDate,formatDate,formatDateRange,formatOptionCount,getCursorOffset,getFooterHint,hasSkippablePill,highlightParts,identifiedParamLabel,isCalendarFormat,isOptionsGridMobileViewport,isSmartSuggestion,isTraditionalAutocompleteSuggestion,isoDate,keepCaretOnChip,labelTraditionalAutocomplete,matchTypedPhrase,measureOptionsGrid,monthLabel,needsOptionsGridMeasurement,optionCountLabel,optionEnterDelayMs,optionHasImage,optionImageSources,optionImageSrc,optionLabel,optionsEntranceDurationMs,optionsGridTemplateColumns,optionsShowLeadingVisuals,parseDate,parseLooseDate,parseLooseDateRange,plainTextLength,planOptionsGrid,previousGraphemeBoundary,productFromMatchedItem,productImageSources,productImageSrc,productInitial,productPhotoFill,productRowWheelTarget,productsFromCustomFields,renderEditableContent,resolveFormatType,resolveIdentifiedDate,sameOptionRows,sanitizeOptionIconSvg,scrollCaretIntoView,selectedIsoFromText,selectedRangeFor,setCursorOffset,shopifyImageSrc,toWireIdentifiedParams,typedFragment,uiStringsFor,visibleDateRange,withSkippedParams,withoutTraditionalAutocomplete});
2826
+ `;var pn=class{constructor(){this.reported=new Set}run(e,n){try{return n()}catch(r){this.report(e,r,e);return}}runListener(e,n,r=e){try{return n(),!0}catch(i){return this.report(e,i,r),!1}}report(e,n,r){this.reported.has(r)||(this.reported.add(r),console.error(`[AIAutocomplete] "${e}" threw. The error is contained \u2014 SDK state is unaffected. Later failures of "${e}" on this instance are not logged.`,n))}};var mn=class{constructor(e){this.boundary=e;this.listeners={};this.keys=new WeakMap;this.registrationCount=0}on(e,n){let r=`${String(e)}#${++this.registrationCount}`,i=(...o)=>n(...o);this.keys.set(i,r);let s=this.listeners[e];return s||(s=new Set,this.listeners[e]=s),s.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...n){let r=this.listeners[e];if(!r)return!0;let i=!0;for(let s of r)this.boundary.runListener(String(e),()=>s(...n),this.keys.get(s)??String(e))||(i=!1);return i}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var gn=class{constructor(){this.timers=new Map}schedule(e,n,r){this.clear(e);let i=setTimeout(()=>{this.timers.delete(e),n()},r);this.timers.set(e,i)}clear(e){let n=this.timers.get(e);n!==void 0&&(clearTimeout(n),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};function sa(t){let e;try{e=new URL(t??K).host}catch{return null}let n=Ge.get(e);return n?`https://${n}`:null}var ro=new WeakMap;function io(t,e){if(!t.head)return;let n=sa(e);if(!n)return;let r=ro.get(t);r||(r=new Map,ro.set(t,r));let i=r.get(n);i||(i=t.createElement("link"),i.rel="preconnect",i.href=n,r.set(n,i)),t.head.append(i)}var Pe=class{constructor(e,n="auto",r){this.container=e;this.mode=n;this.onResolve=r;this.mediaQuery=null;this.onSystemChange=e=>{this.setResolved(e.matches?"dark":"light")};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.setResolved(this.mediaQuery.matches?"dark":"light")):this.setResolved(this.mode)}setResolved(e){this.container.dataset.mode=e,this.onResolve?.(e)}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function lr(t){return t.isDropdownOpen&&!t.isLoading}var aa=50,la=new Set(["search_started","submit","product_click","impression"]),da="newParam",oo="suggestionRemoval",ca="selectionAnimation",dr="skeletonExit",ua=650,pa=0;function ma(){return`:ac-${++pa}:`}var so=170,ga=100;function ao(){return{text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],traditionalAutocomplete:!1,customFields:null,optionSearch:null,activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,dropdownHeld:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1,dateViewMonth:null,pendingRangeStart:null,editingIdentified:null}}var fn=class{constructor(e,n={}){this.inputStore=un(ao());this._listboxId=ma();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new gn;this.boundary=new pn;this.subscriberCount=0;this.emitter=new mn(this.boundary);this.sessionId=crypto.randomUUID();this.lastRequestId=null;this.searchStartedSessionId=null;this.funnelTelemetry=null;this.pendingSearchStarted=!1;this.openWordText=null;this.heldIdentified=null;this.lastImpressionKey="";this.visibleImpression=!1;this.destroyed=!1;this.emitSubmit=e=>(this.recordSubmit(e),this.emitter.emit("submit",e));this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=n,this.renderMode=n.renderMode??"full",this.store=Xi(this.inputStore,r=>Qr(r,this.opts)),n.onSubmit&&this.emitter.on("submit",n.onSubmit),n.onResult&&this.emitter.on("result",n.onResult),n.onError&&this.emitter.on("error",n.onError),n.onChange&&this.emitter.on("change",n.onChange),n.onParamsChange&&this.emitter.on("paramsChange",n.onParamsChange),n.onStateChange&&this.emitter.on("stateChange",n.onStateChange),n.onFocus&&this.emitter.on("focus",n.onFocus),n.onBlur&&this.emitter.on("blur",n.onBlur),n.onProductSelect&&this.emitter.on("productSelect",n.onProductSelect),n.value!==void 0&&this.store.set({text:n.value}),n.completedParams!==void 0&&this.store.set({completedParams:n.completedParams}),this.holdOpen=new rt(this.store,e),this.pillsController=new Pt(this.store,{onPillSelected:({rawQuery:r,selectedPill:i,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:r,selected_pill:i,other_pills:s})}}),this.reEdit=new Wt({store:this.store,scheduleSetCursor:r=>this.scheduleSetCursor(r),fireTelemetry:(r,i)=>this.fireTelemetry(r,i),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer(),fetchNow:()=>this.fetchNow()}),this.productsController=new Et(this.store,()=>this.opts.products,()=>this.opts.showProducts!==!1,()=>this.opts.language,()=>this.opts.mapProducts),this.optionSource=new vt(this.store,()=>this.opts.optionOverrides,{onAnswer:r=>{r==="edit"?this.reEdit.promoteIfExact():this.maybePromoteExactMatch(this.store.get().text)},onMiss:(r,i)=>{r==="pill"&&i.length>0&&this.fetchController.attemptNow()}}),this.fetchController=new nt(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,()=>this.resolveSource(),()=>this.opts.additionalContext,()=>this.opts.language,{getProductId:()=>this.opts.productId,getCurrency:()=>this.opts.currency,onRequest:({query:r,signal:i,isCurrent:s})=>{io(this.container.ownerDocument,this.opts.apiConfig?.endpoint),this.productsController.run(r,i,s).catch(()=>{})},onAutoMatch:({active:r,matched:i,rawQuery:s})=>{let o=r.options??[];this.fireTelemetry("option",{raw_query:s,selected_option:i.text,other_options:o.filter(a=>a.text!==i.text).map(a=>a.text),key:r.parameter,position:le(o,i.text),chip_origin:"typed"})},onResponse:({requestId:r,funnelTelemetry:i,visibleImpression:s})=>{this.lastRequestId=r,this.funnelTelemetry=i,this.visibleImpression=s,this.pendingSearchStarted&&(this.pendingSearchStarted=!1,this.fireTelemetry("search_started",{})),this.fireImpression(),this.emitter.hasListeners("result")&&this.emitter.emit("result",this.buildResult())},productsForResponse:r=>this.productsController.forResponse(r),consumerTick:(r,i)=>this.optionSource.tick(r,i),isWordOpen:()=>this.isWordOpen(),holdIdentified:r=>{this.heldIdentified={text:this.store.get().text,candidates:r}}}),this.keyboardController=new xt(this.store,{columns:n.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.resetAfterSubmit():void 0,selectOption:r=>this.selectOption(r),removeParamAtCaret:r=>this.removeParamAtCaret(r),startEditingParamAtCaret:r=>this.startEditingParamAtCaret(r),exitEditMode:()=>this.exitEditMode(),exitEditingIdentified:()=>this.exitEditingIdentified(),skipActivePill:()=>this.skipActivePill(),endTypedWord:r=>this.endTypedWord(r)}),this.unsubscribers.push(this.store.subscribe((r,i)=>{r.text!==i.text&&this.emitter.emit("change",r.text),r.completedParams!==i.completedParams&&this.emitter.emit("paramsChange",r.completedParams),r.isFocused!==i.isFocused&&(r.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",r)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.subscribeSkeletonMirror(),this.subscribeVisibleImpression(),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.text===i.text&&r.completedParams===i.completedParams||r.identifiedParams.length===0)return;let{valid:s,invalid:o}=Ae(r.text,r.completedParams,r.identifiedParams);o.length>0&&this.store.set({identifiedParams:s})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.identifiedParams===i.identifiedParams)return;let s=r.editingIdentified;if(!s||r.identifiedParams.some(l=>l.id===s.id))return;let o=0,a;for(let l of r.segments){if(l.type==="identified"&&o===s.anchor&&l.value===s.text){a=l.param;break}o+=l.value.length}if(a){this.store.set({editingIdentified:{...s,id:a.id}});return}this.store.set({editingIdentified:null,activeDropdownIndex:-1})})),this.unsubscribers.push(this.store.subscribe(r=>{let i=r.pendingRangeStart;!i||i.key===Ne(r)||this.store.set({pendingRangeStart:null})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{let s=r.pendingSpan;if(!s||r.text===i.text&&r.completedParams===i.completedParams&&r.identifiedParams===i.identifiedParams)return;let o=s.anchor;if(r.text!==i.text){let l=Tr(i.text,r.text,o);if(l===null){this.store.set({pendingSpan:null});return}o=l}r.text.slice(o).trim().length===0||vr(r.segments,o)?this.store.set({pendingSpan:null}):o!==s.anchor&&this.store.set({pendingSpan:{anchor:o,snapshot:s.snapshot}})})),this.renderMode!=="headless"&&(to(this.opts.styleRoot??ae(this.container)),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.optionSource.start(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let{isFocused:e,dropdownHeld:n}=this.store.get();this.optionSource.reset(),this.store.set({...ao(),isFocused:e,dropdownHeld:n,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.lastRequestId=null,this.lastImpressionKey="",this.pendingSearchStarted=!1,this.fetchController.doFetch("",[])}resetAfterSubmit(){this.opts.resetOnSubmit!==!1&&this.reset()}destroy(){this.destroyed=!0,this.fetchController.dispose(),this.optionSource.dispose(),this.holdOpen.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs&&(ci(this.domRefs.input),ir(this.domRefs.dropdown)),this.dropdownRefs&&ir(this.dropdownRefs.dropdown),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}prefillText(e){this.applyTextChange(e,!1)}noteSearchStarted(){this.searchStartedSessionId!==this.sessionId&&(this.searchStartedSessionId=this.sessionId,this.funnelTelemetry===null?this.pendingSearchStarted=!0:this.fireTelemetry("search_started",{}))}setValue(e){let n=this.store.get();if(n.editingIdentified&&e!==n.text){this.store.set({text:e,editingIdentified:null,activeDropdownIndex:-1});return}this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let n=this.store.get().text.length;this.store.set({caretOffset:n,isFocused:!0}),this.scheduleSetCursor(n)}removeLastParam(){this.pillsController.removeLastParam()}findChipSpanAt(e){let n=0;for(let r of this.store.get().segments){let i=n;if(n+=r.value.length,r.type!=="text"&&e>i&&e<=n)return{kind:r.type,param:r.param,start:i,end:n}}return null}withoutChip(e,n){return n.kind==="completed"?{completedParams:e.completedParams.filter(r=>r.id!==n.param.id)}:{identifiedParams:e.identifiedParams.filter(r=>r.id!==n.param.id)}}removeParamAtCaret(e){let n=this.findChipSpanAt(e);if(!n)return!1;let{text:r}=this.store.get(),{start:i,end:s}=n;if(e===s){let{text:l,removed:d}=Ft(r,i,s);return this.store.set(c=>({text:l,filterBase:Math.min(c.filterBase>i?Math.max(i,c.filterBase-d):c.filterBase,l.length),...this.withoutChip(c,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(i),!0}let o=yt(r,e),a=r.slice(0,o)+r.slice(e);return this.store.set(l=>({text:a,filterBase:Math.min(l.filterBase,a.length),...this.withoutChip(l,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(o),!0}startEditingParamAtCaret(e){let n=this.findChipSpanAt(e);return!n||n.kind!=="completed"||n.end!==e?!1:(this.reEdit.start(n.param.id),this.store.get().editingParam?.id===n.param.id)}scheduleSetCursor(e){queueMicrotask(()=>{let n=this.domRefs;if(n)n.input.focus(),D(n.input,e);else{let r=this.opts.setCursor;r&&this.boundary.runListener("setCursor",()=>r(e))}})}clearNewParamId(){this.store.set({newParamId:null})}startEditingIdentified(e){let n=this.store.get();if(n.editingIdentified?.id===e)return!0;let r=n.identifiedParams.find(d=>d.id===e);if(!r)return!1;let i=B(r);if(!T(i))return!1;let s=i==="date-range"?De(r.text):null,o=0,a=-1;for(let d of n.segments){if(d.type!=="text"&&d.param.id===e){a=o;break}o+=d.value.length}if(a<0)return!1;let l=a+r.text.length;return this.store.set({editingIdentified:{id:e,parameter:r.parameter,anchor:a,tail:l,text:r.text,iso:s?s.start:Ct(r),isoEnd:s?s.end:null,format:i},editingParam:null,editingAnchor:null,editingTail:null,caretOffset:l,activeDropdownIndex:-1,pillTapped:!0}),!0}exitEditingIdentified(){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1})}startEditingParam(e){this.reEdit.start(e),this.store.get().editingParam?.id!==e&&this.startEditingIdentified(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){let n=this.store.get().editingIdentified;n&&e!=null&&(e<n.anchor||e>n.tail)&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}clearHighlight(e){this.store.get().activeDropdownIndex===e&&this.store.set({activeDropdownIndex:-1})}prepareSubmit(){this.endTypedWord(!0)}recordSubmit(e){this.fireTelemetry("submit",{query:e.query,completed_pills:e.completed_params.filter(n=>n.placeholder).map(n=>({key:n.parameter,value:n.text??""}))})}selectProduct(e){let n=this.store.get(),r=n.products.findIndex(s=>s.id===e.id),i=n.customFields?.items?.matched?.find(s=>s.source_id===e.id)?.origin_id;this.fireTelemetry("product_click",{query:n.text,product_id:e.id,...i&&{origin_id:i},position:r>=0?r+1:null}),this.emitter.emit("productSelect",e)}addProductToCart(e){let n=this.opts.onProductAddToCart;if(!n)return Promise.resolve();try{return Promise.resolve(n(e)).then(()=>{})}catch(r){return Promise.reject(r)}}hasProductAddToCart(){return typeof this.opts.onProductAddToCart=="function"}handleTextChange(e){this.applyTextChange(e,!0)}applyTextChange(e,n){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.handleChange(e,n)}showPreviousMonth(){this.pageDateView(-1)}showNextMonth(){this.pageDateView(1)}pageDateView(e){let n=this.store.get();if(!T(n.activeFormatType)||!n.dateView)return;let r=ot(n.dateView,e);this.store.set({dateViewMonth:{...r,key:Ne(n)},activeDropdownIndex:-1})}skipActivePill(){let e=this.store.get();if(e.editingParam||e.inSelectionAnimation)return;let n=e.suggestions.filter(a=>a.parameter==="placeholder"),r=e.suggestions.filter(a=>a.parameter!=="placeholder");if(r.length===0||E(r[0]))return;let i=r[0],s=r.slice(1),o=e.skippedParams.some(a=>a.parameter===i.parameter);this.store.set({suggestions:[...n,...s],pillTapped:s.length>0,activeDropdownIndex:-1,...o?{}:{skippedParams:[...e.skippedParams,{id:crypto.randomUUID(),parameter:i.parameter,suggestionPlaceholder:i.text}]}}),s.length===0&&this.fetchNow()}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){let n=`subscribe#${++this.subscriberCount}`;return this.store.subscribe(r=>{this.boundary.runListener("subscribe",()=>e(r),n)})}getState(){return this.store.get()}getResult(){return this.buildResult()}getRequestId(){return this.lastRequestId}buildResult(){let e=this.store.get();return Y(e.text,e.completedParams,e.skippedParams,{identifiedParams:e.identifiedParams,isReady:e.isReady,customFields:e.customFields})}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,n){return this.emitter.on(e,n)}refreshProducts(){this.opts.mapProducts&&this.productsController.refresh()}update(e){let n=this.opts.products,r=this.opts.mapProducts,i=this.opts.showProducts,s=this.opts.optionOverrides;Object.assign(this.opts,e),"language"in e&&this.updateLanguageAttribute(),"optionOverrides"in e&&e.optionOverrides!==s&&this.optionSource.refresh(),"products"in e&&e.products!==n||"showProducts"in e&&e.showProducts!==i?this.productsController.resync():"mapProducts"in e&&e.mapProducts!==r&&this.productsController.refresh(),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0||e.showSkipButton!==void 0||e.showOptionIcons!==void 0||e.showOptionImages!==void 0||e.showOptionCounts!==void 0||e.productsLayout!==void 0||e.productImageFallback!==void 0||e.showChipIcons!==void 0||e.showChipImages!==void 0||"language"in e)&&this.store.set({}),e.value!==void 0&&this.setValue(e.value),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let n=!this.store.get().text;this.applyOption(e),n&&this.store.get().text&&this.noteSearchStarted()}applyOption(e){let n=this.store.get();if(n.activeFormatType==="date-range"){let i=G(e);if(i){let s=n.dateRangeStart;if(!s){this.store.set({pendingRangeStart:{iso:i,key:Ne(n)}});return}this.store.set({pendingRangeStart:null}),this.selectOption(zr(s,i));return}}if(n.editingIdentified){this.commitIdentifiedDate(e);return}if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null){this.timers.clear(dr),this.reEdit.selectOption(e);return}let r=ti(n,e);if(r){if(this.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:r.telemetry.selectedOption,other_options:T(n.activeFormatType)?[]:r.telemetry.otherOptions,key:r.telemetry.key,position:T(n.activeFormatType)?null:r.telemetry.position,chip_origin:"tap"}),this.timers.clear(dr),this.store.set({...r.patch,...Ht(n)}),this.startSelectionAnimationTimer(),this.timers.clear(oo),r.remainingActionable>0){let i=r.consumedSuggestion;this.timers.schedule(oo,()=>{this.store.get().suggestions.includes(i)&&this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==i)}))},so)}this.fetchNow()}}startSelectionAnimationTimer(){this.timers.schedule(ca,()=>this.store.set({inSelectionAnimation:!1}),so)}resolveVisitorId(){let e=this.opts.visitorId;if(typeof e!="function")return e;try{return e()}catch{return}}resolveSource(){return this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk")}subscribeVisibleImpression(){this.unsubscribers.push(this.store.subscribe((e,n)=>{this.visibleImpression&&(!e.isDropdownOpen&&n.isDropdownOpen&&(this.lastImpressionKey=""),lr(e)&&!lr(n)&&queueMicrotask(()=>this.fireImpression()))}))}fireImpression(){if(this.funnelTelemetry!==!0||this.destroyed)return;let e=this.store.get();if(this.visibleImpression&&!lr(e))return;let n=e.suggestions.filter(s=>s.parameter!=="placeholder"&&!E(s)).map(s=>({key:s.parameter,options:(s.options??[]).slice(0,aa).map(o=>o.text)})),r=e.products.map(s=>s.id);if(n.length===0&&r.length===0)return;let i=JSON.stringify([n,r]);i!==this.lastImpressionKey&&(this.lastImpressionKey=i,this.fireTelemetry("impression",{query:e.text,pills:n,product_ids:r}))}fireTelemetry(e,n){let r=this.funnelTelemetry===!0;if(!r&&la.has(e))return;if(!r&&e==="option"){let{key:s,position:o,chip_origin:a,...l}=n;n=l}let i=this.resolveSource();ei({source:i,sessionId:this.sessionId,visitorId:r?this.resolveVisitorId():void 0,requestId:r?this.lastRequestId:null,keepalive:r,type:e,language:ie(this.opts.language),queryData:n,apiConfig:this.opts.apiConfig})}updateLanguageAttribute(){let{language:e}=k(this.opts.language);e!=="en"?this.container.dataset.aiaLanguage=e:delete this.container.dataset.aiaLanguage}setupContainer(){this.container.classList.add("magicx-aia"),this.updateLanguageAttribute(),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"dropdown",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new Pe(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,n={store:this.store,listboxId:this.listboxId,get strings(){return k(e.opts.language)},get pillPlacement(){return e.opts.pillPlacement??"dropdown"},get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get addProductToCart(){return e.hasProductAddToCart()?i=>e.addProductToCart(i):void 0},get showChipIcons(){return e.opts.showChipIcons??!0},get showChipImages(){return e.opts.showChipImages??!0},get optionsPosition(){return e.opts.optionsPosition??"below"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.resetAfterSubmit(),endTypedWord:()=>e.endTypedWord(!0),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth(),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i,!0),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Qi(this.container,n);let r=()=>{this.domRefs&&sr(this.domRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),sr(this.domRefs,this.store.get(),n),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e=this,n={store:this.store,listboxId:this.listboxId,get strings(){return k(e.opts.language)},get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get addProductToCart(){return e.hasProductAddToCart()?i=>e.addProductToCart(i):void 0},get optionsPosition(){return e.opts.optionsPosition??"below"},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth()};this.dropdownRefs=qi(this.container,n);let r=()=>{this.dropdownRefs&&or(this.dropdownRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),or(this.dropdownRefs,this.store.get(),n),this.subscribeNewParamTimer()}subscribeViewportBreakpoint(e){if(typeof window>"u"||typeof window.matchMedia!="function")return;let n=window.matchMedia(_e),r=()=>e();n.addEventListener("change",r),this.unsubscribers.push(()=>n.removeEventListener("change",r))}subscribeBatchedRender(e){let n=!1;this.unsubscribers.push(this.store.subscribe(()=>{n||(n=!0,queueMicrotask(()=>{n=!1,e()}))}))}subscribeSkeletonMirror(){this.unsubscribers.push(this.store.subscribe((e,n)=>{if(!e.skeletonOptions)return;if(!n.isLoading&&e.isLoading){e.skeletonRequested||this.store.set({skeletonRequested:!0});return}if(!n.isLoading||e.isLoading)return;let r={skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1};if(!e.skeletonExiting){this.store.set(r);return}this.timers.schedule(dr,()=>this.store.set(r),ga)}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,n)=>{e.newParamId&&e.newParamId!==n.newParamId&&this.timers.schedule(da,()=>this.store.set({newParamId:null}),ua)}))}handleChange(e,n){let r=this.store.get();n&&e&&!r.text&&this.noteSearchStarted(),this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:s}=Cr(e,r.completedParams);s.length>0&&this.store.set({completedParams:i});let o=this.heldIdentified;this.heldIdentified=null,this.openWordText=n&&/\S$/.test(e)?e:null,this.maybePromoteExactMatch(e),o&&/^\s+$/.test(e.slice(o.text.length))&&e.startsWith(o.text)&&this.admitIdentified(o.candidates),this.maybeOpenPendingSpan()}isWordOpen(){return this.opts.commitOnWordEnd===!0&&this.openWordText===this.store.get().text}admitIdentified(e){let n=this.store.get(),{valid:r}=Ae(n.text,n.completedParams,e);r.length!==0&&this.store.set({identifiedParams:[...n.identifiedParams,...r]})}endTypedWord(e=!1){let n=this.isWordOpen();if(!n&&!e)return!1;let r=this.heldIdentified;this.heldIdentified=null,this.openWordText=null;let i=this.store.get();this.maybePromoteExactMatch(i.text,e?"submit":"fresh",n),r?.text===i.text&&this.admitIdentified(r.candidates);let s=this.store.get();return s.completedParams!==i.completedParams||s.identifiedParams!==i.identifiedParams}maybeOpenPendingSpan(){let e=this.store.get();if(e.pendingSpan||e.actionableSuggestions.length===0)return;let n=z(e.text,Math.min(e.filterBase,e.text.length),e.placeholderText),r=xr(e.segments,n);e.text.slice(r).trim().length!==0&&this.store.set({pendingSpan:{anchor:r,snapshot:e.actionableSuggestions}})}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(s=>s.id===e.editingParam?.id)||this.optionSource.owns(e.editingParam.suggestionParameter,e.optionQuery))return;let n=e.caretOffset??e.editingAnchor,r=e.text.slice(e.editingAnchor,n);oe(e.editingParam.options,r).some(s=>s.is_tappable)||(this.reEdit.exit(),this.fetchNow())}fetchNow(){let e=this.store.get(),{rawQuery:n,completedParams:r}=R(e.text,e.completedParams);this.fetchController.doFetch(n,r)}commitIdentifiedDate(e){let n=this.store.get(),r=n.editingIdentified;if(!r)return;if(n.text.slice(r.anchor,r.tail)!==r.text){this.store.set({editingIdentified:null,activeDropdownIndex:-1});return}let i=n.text.slice(0,r.anchor),s=n.text.slice(r.tail),o=r.anchor===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=s.length===0||s[0]!==" "?`${o} `:o,d=i+l+s,c=d.length,u={id:crypto.randomUUID(),placeholder:"",parameter:r.parameter,text:o,value:e.value,kind:e.kind,suggestionParameter:r.parameter,suggestionPlaceholder:U(r.parameter),options:[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url};this.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:[],key:r.parameter,position:null,chip_origin:"tap"}),this.store.set({text:d,completedParams:[...n.completedParams,u],identifiedParams:n.identifiedParams.filter(m=>m.id!==r.id),newParamId:u.id,filterBase:c,caretOffset:c,editingIdentified:null,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.startSelectionAnimationTimer(),this.scheduleSetCursor(c),this.fetchNow()}maybePromoteExactMatch(e,n="fresh",r=!1){let i=this.store.get();if(T(i.activeFormatType)||this.isWordOpen())return;let s=_t({mode:n,finishWord:r,text:e,completedParams:i.completedParams,suggestions:i.suggestions,filterBase:i.filterBase,filterInProgress:i.filterInProgress,phraseExactMatch:this.fetchController.isPhraseExactMatch()});if(s){if(this.funnelTelemetry===!0){let o=n==="submit"&&s.suggestion?s.suggestion:i.actionableSuggestions[0],a=o.options??[];this.fireTelemetry("option",{raw_query:R(e,i.completedParams).rawQuery,selected_option:s.option.text,other_options:a.filter(l=>l.text!==s.option.text).map(l=>l.text),key:o.parameter,position:le(a,s.option.text),chip_origin:"typed"})}this.store.set(s.patch)}}};0&&(module.exports={AIAutocomplete,ATTRIBUTION_URL,DATE_RANGE_META_END,DATE_RANGE_META_START,DEFAULT_OPTION_COUNT_UNIT,ModeController,OPTIONS_GRID_MOBILE_QUERY,OPTION_ENTER_DELAY_VAR,OPTION_ENTER_FADE_MS,OPTION_ENTER_RISE_MS,OPTION_ENTER_RISE_PX,OPTION_ENTER_STAGGER_MS,OPTION_IMAGE_WIDTH,PLACEHOLDER_FADE_OUT_MS,PLACEHOLDER_LEAVING_ATTR,PLACEHOLDER_SWAP_GAP_MS,PLACEHOLDER_TYPE_MS,PLACEHOLDER_WORD_PAUSE_MS,PRODUCT_IMAGE_WIDTH,PRODUCT_PATH_PREFIX,PRODUCT_ROW_PX_PER_LINE,RANGE_SEPARATOR,SCHEMA_VERSION,SCROLL_ARROW_ATTR,SCROLL_ARROW_BOTTOM_VAR,SCROLL_ARROW_CLASS,SCROLL_ARROW_FADE_MS,SCROLL_ARROW_LABEL,SCROLL_ARROW_SCROLL_IDLE_MS,SCROLL_ARROW_VISIBLE_ATTR,SKIPPED_PARAM_TEXT,SMART_SUGGESTION_SPARKLE_SVG,VIEWPORT_FIT_ATTR,VIEWPORT_FIT_HEIGHT_VAR,WEEKDAY_LABELS,addMonths,attachProductRowWheel,attachScrollArrow,attachViewportFit,buildAttributionUrl,buildDateOptions,buildQuery,buildSubmitResult,cellDay,cellIso,chipIdFromTap,computeOptionsGridLayout,containScroll,createStore,cursorIsAtEnd,dateCellMarks,dateSelectionFor,extractPlainText,formatAbsoluteDate,formatDate,formatDateRange,formatOptionCount,getCursorOffset,getFooterHint,hasSkippablePill,highlightParts,identifiedParamLabel,isCalendarFormat,isOptionsGridMobileViewport,isSmartSuggestion,isTraditionalAutocompleteSuggestion,isoDate,keepCaretOnChip,labelTraditionalAutocomplete,matchTypedPhrase,measureOptionsGrid,monthLabel,needsOptionsGridMeasurement,optionCountLabel,optionEnterDelayMs,optionHasImage,optionImageSources,optionImageSrc,optionLabel,optionsEntranceDurationMs,optionsGridTemplateColumns,optionsShowLeadingVisuals,parseDate,parseLooseDate,parseLooseDateRange,plainTextLength,planOptionsGrid,previousGraphemeBoundary,productFromMatchedItem,productImageSources,productImageSrc,productInitial,productPhotoFill,productRowWheelTarget,productsFromCustomFields,renderEditableContent,resolveFormatType,resolveIdentifiedDate,sameOptionRows,sanitizeOptionIconSvg,scrollCaretIntoView,selectedIsoFromText,selectedRangeFor,setCursorOffset,shopifyImageSrc,toWireIdentifiedParams,typedFragment,uiStringsFor,visibleDateRange,withSkippedParams,withoutTraditionalAutocomplete});
2797
2827
  //# sourceMappingURL=index.js.map