@magicx-eng/ai-autocomplete-react 0.1.40 → 0.1.41

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.mjs CHANGED
@@ -703,7 +703,7 @@ import{forwardRef as En,useCallback as G,useEffect as ve,useImperativeHandle as
703
703
  filter: brightness(0.55);
704
704
  }
705
705
  }
706
- `,document.head.appendChild(n)}var z={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh",skeletonPulse:"SuggestionItem-module_skeletonPulse_plvdD"};import{jsx as lt,jsxs as vt}from"react/jsx-runtime";function yt({option:n,isHighlighted:e,onSelect:t,onHighlight:o,id:r,loading:a}){let[i,s]=Zt(!1),d=Yt(void 0);Jt(()=>()=>clearTimeout(d.current),[]);let l=()=>{a||!n.is_tappable||i||(s(!0),t(n),clearTimeout(d.current),d.current=setTimeout(()=>s(!1),500))},p=[z.item,e&&!a?z.highlighted:"",n.is_tappable?z.tappable:z.nonTappable,i?z.pressed:""].filter(Boolean).join(" ");return vt("div",{id:r,role:"option","data-aia-option":"","data-aia-loading":a?"":void 0,"aria-selected":e,className:p,tabIndex:a||!n.is_tappable?-1:0,onClick:l,onKeyDown:u=>{!a&&n.is_tappable&&(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),l())},onMouseEnter:!a&&n.is_tappable?o:void 0,children:[lt("div",{className:z.streaks}),lt("div",{className:z.streaksVert}),vt("span",{className:z.content,children:[n.icon?`${n.icon} ${n.text}`:n.text,n.tag&&lt("span",{className:z.tag,children:n.tag})]})]})}import{jsx as dt}from"react/jsx-runtime";function wt({options:n,activeIndex:e,onSelect:t,onHighlight:o,listboxId:r,loading:a}){let i=nn(null),[s,d]=on(!1);return en(()=>{let l=i.current;if(!l)return;let p=()=>{d(l.scrollHeight-l.scrollTop-l.clientHeight>1)};l.addEventListener("scroll",p,{passive:!0});let u=new ResizeObserver(p);return u.observe(l),()=>{l.removeEventListener("scroll",p),u.disconnect()}},[]),tn(()=>{let l=i.current;l&&d(l.scrollHeight-l.scrollTop-l.clientHeight>1)},[n]),dt("div",{className:st.scrollWrapper,"data-fade":s?"":void 0,children:dt("div",{ref:i,className:st.grid,children:n.map((l,p)=>dt(yt,{option:l,isHighlighted:p===e,onSelect:t,onHighlight:()=>o(p),id:`${r}-option-${p}`,loading:a},l.text))})})}import{jsx as ee,jsxs as an}from"react/jsx-runtime";var rn=[159,119,164];function ct({suggestions:n,activeIndex:e,onSelect:t,onHighlight:o,isOpen:r,id:a,className:i,pills:s,onPillClick:d,showPills:l=!0,isLoading:p=!1}){let c=n[0]?.options??[],h=l&&s&&s.length>0&&d,b=c.length>0,v=p&&!b&&!(l&&s&&s.length>0),f=r&&(b||h||p);return an("div",{id:a,role:"listbox","data-aia-dropdown":"","data-aia-loading":p?"":void 0,className:`${Z.dropdown} ${f?Z.visible:""} ${i??""}`,onMouseDown:m=>m.preventDefault(),children:[l&&s&&s.length>0&&d&&ee("div",{className:Z.pillBar,"data-aia-pillbar":"",children:ee(fe,{pills:s,activePillIndex:0,onSelectPill:d,rounded:!0,loading:p})}),l&&(!s||s.length===0)&&p&&ee("div",{className:Z.pillBar,"data-aia-pillbar":"",children:ee(fe,{pills:[],activePillIndex:0,onSelectPill:()=>{},rounded:!0,loading:!0})}),b&&ee(wt,{options:c,activeIndex:e,onSelect:t,onHighlight:o,listboxId:a,loading:p}),v&&ee("div",{className:Z.skeletonBars,"data-aia-skeleton-bars":"",children:rn.map(m=>ee("span",{className:Z.skeletonBar,style:{width:m}},`bar-${m}`))})]})}if(typeof document<"u"&&!document.getElementById("ac-style-dc8da745")){let n=document.createElement("style");n.id="ac-style-dc8da745",n.textContent=`/*
706
+ `,document.head.appendChild(n)}var z={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh",skeletonPulse:"SuggestionItem-module_skeletonPulse_plvdD"};import{jsx as lt,jsxs as vt}from"react/jsx-runtime";function yt({option:n,isHighlighted:e,onSelect:t,onHighlight:o,id:r,loading:a}){let[i,s]=Zt(!1),d=Yt(void 0);Jt(()=>()=>clearTimeout(d.current),[]);let l=()=>{a||!n.is_tappable||i||(s(!0),t(n),clearTimeout(d.current),d.current=setTimeout(()=>s(!1),500))},p=[z.item,e&&!a?z.highlighted:"",n.is_tappable?z.tappable:z.nonTappable,i?z.pressed:""].filter(Boolean).join(" ");return vt("div",{id:r,role:"option","data-aia-option":"","data-aia-loading":a?"":void 0,"aria-selected":e,className:p,tabIndex:a||!n.is_tappable?-1:0,onClick:l,onKeyDown:u=>{!a&&n.is_tappable&&(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),l())},onMouseEnter:!a&&n.is_tappable?o:void 0,children:[lt("div",{className:z.streaks}),lt("div",{className:z.streaksVert}),vt("span",{className:z.content,children:[n.icon?`${n.icon} ${n.text}`:n.text,n.tag&&lt("span",{className:z.tag,children:n.tag})]})]})}import{jsx as dt}from"react/jsx-runtime";function wt({options:n,activeIndex:e,onSelect:t,onHighlight:o,listboxId:r,loading:a}){let i=nn(null),[s,d]=on(!1);return en(()=>{let l=i.current;if(!l)return;let p=()=>{d(l.scrollHeight-l.scrollTop-l.clientHeight>1)};l.addEventListener("scroll",p,{passive:!0});let u=new ResizeObserver(p);return u.observe(l),()=>{l.removeEventListener("scroll",p),u.disconnect()}},[]),tn(()=>{let l=i.current;l&&d(l.scrollHeight-l.scrollTop-l.clientHeight>1)},[n]),dt("div",{className:st.scrollWrapper,"data-fade":s?"":void 0,children:dt("div",{ref:i,className:st.grid,children:n.map((l,p)=>dt(yt,{option:l,isHighlighted:p===e,onSelect:t,onHighlight:()=>o(p),id:`${r}-option-${p}`,loading:a},l.text))})})}import{jsx as ee,jsxs as an}from"react/jsx-runtime";var rn=[159,119,164];function ct({suggestions:n,activeIndex:e,onSelect:t,onHighlight:o,isOpen:r,id:a,className:i,pills:s,onPillClick:d,showPills:l=!0,isLoading:p=!1}){let c=n[0]?.options??[],h=l&&s&&s.length>0&&d,b=c.length>0,v=p&&!b,f=r&&(b||h||p);return an("div",{id:a,role:"listbox","data-aia-dropdown":"","data-aia-loading":p?"":void 0,className:`${Z.dropdown} ${f?Z.visible:""} ${i??""}`,onMouseDown:m=>m.preventDefault(),children:[l&&s&&s.length>0&&d&&ee("div",{className:Z.pillBar,"data-aia-pillbar":"",children:ee(fe,{pills:s,activePillIndex:0,onSelectPill:d,rounded:!0,loading:p})}),l&&(!s||s.length===0)&&p&&ee("div",{className:Z.pillBar,"data-aia-pillbar":"",children:ee(fe,{pills:[],activePillIndex:0,onSelectPill:()=>{},rounded:!0,loading:!0})}),b&&ee(wt,{options:c,activeIndex:e,onSelect:t,onHighlight:o,listboxId:a,loading:p}),v&&ee("div",{className:Z.skeletonBars,"data-aia-skeleton-bars":"",children:rn.map(m=>ee("span",{className:Z.skeletonBar,style:{width:m}},`bar-${m}`))})]})}if(typeof document<"u"&&!document.getElementById("ac-style-dc8da745")){let n=document.createElement("style");n.id="ac-style-dc8da745",n.textContent=`/*
707
707
  * Built-in appearance defaults \u2014 zero specificity via :where().
708
708
  * Consumer CSS always wins without !important.
709
709
  *
@@ -713,6 +713,18 @@ import{forwardRef as En,useCallback as G,useEffect as ve,useImperativeHandle as
713
713
  * 3. These built-in defaults
714
714
  */
715
715
 
716
+ /*
717
+ * Library-scoped box-sizing reset. The SDK's pill / option / wrapper styles
718
+ * mix explicit dimensions with padding (e.g. .magicx-aia-pill has height:36px
719
+ * + padding:13px) and were authored assuming \`border-box\`. In consumer apps
720
+ * without a global \`* { box-sizing: border-box }\` reset the pill rendered
721
+ * ~62px tall instead of 36px. Scoping the reset to \`.magicx-aia\` descendants
722
+ * keeps the library self-contained without leaking onto consumer markup.
723
+ */
724
+ :where(.magicx-aia, .magicx-aia *, .magicx-aia *::before, .magicx-aia *::after) {
725
+ box-sizing: border-box;
726
+ }
727
+
716
728
  /* Light mode defaults (base) */
717
729
  :where(.magicx-aia),
718
730
  :where(.magicx-aia[data-mode="light"]) {
@@ -786,5 +798,5 @@ import{forwardRef as En,useCallback as G,useEffect as ve,useImperativeHandle as
786
798
  animation-duration: 0s !important;
787
799
  transition-duration: 0s !important;
788
800
  }
789
- `,document.head.appendChild(n)}var Pt='[contenteditable="false"]',ie;function sn(){if(ie!==void 0)return ie;let n=globalThis.Intl.Segmenter;if(!n)return ie=null,null;try{ie=new n(void 0,{granularity:"grapheme"})}catch{ie=null}return ie??null}function Re(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(Pt))return!0;t=t.parentNode}return!1}function Ne(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return Re(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function re(n){let e=Ne(n),t="",o=e.nextNode();for(;o;)t+=o.data,o=e.nextNode();return t}function He(n){let e=Ne(n),t=0,o=e.nextNode();for(;o;)t+=o.data.length,o=e.nextNode();return t}function H(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,o=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(Re(r,n)&&r!==n)return null;let a=0;for(let i=0;i<o&&i<r.childNodes.length;i++)a+=It(r.childNodes[i],n);return a+St(r,n)}return t.nodeType!==Node.TEXT_NODE||Re(t,n)?null:St(t,n)+o}function It(n,e){if(n.nodeType===Node.TEXT_NODE)return Re(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(Pt))return 0;let o=0;for(let r of Array.from(t.childNodes))o+=It(r,e);return o}function St(n,e){let t=Ne(e),o=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return o;o+=r.data.length,r=t.nextNode()}return o}function L(n,e){let t=n.ownerDocument??document,o=t.getSelection();if(!o)return;let r=Math.max(0,Math.min(e,He(n))),a=Ne(n),i=0,s=null,d=0,l=a.nextNode(),p=null;for(;l;){let c=l.data.length;if(r<i+c){s=l,d=r-i;break}if(r===i+c){let h=a.nextNode();h?(s=h,d=0):(s=l,d=c);break}i+=c,p=l,l=a.nextNode()}let u=t.createRange();if(s){let c=s.parentElement?.closest('strong[data-seg="completed"]');c&&c!==n&&n.contains(c)?d===0?u.setStartBefore(c):d===s.data.length?u.setStartAfter(c):u.setStart(s,d):u.setStart(s,d)}else p?u.setStart(p,p.data.length):u.setStart(n,0);u.collapse(!0),o.removeAllRanges(),o.addRange(u)}function At(n){let e=H(n);return e==null?!1:e>=He(n)}function Ct(n,e){if(e<=0)return 0;let t=sn();if(!t)return e-1;let o=n.slice(0,e),r=0;for(let{index:a}of t.segment(o))a<e&&(r=a);return r}function Be(n){let{input:e,segments:t,newParamId:o,editingParamId:r,placeholderText:a,isFocused:i}=n,s=t.length===0;e.dataset.aiaEmpty=s?"true":"false",s&&a?e.dataset.placeholder=a:delete e.dataset.placeholder;let d=t.map(f=>`${f.type}:${f.value}`).join("\0"),l=e.dataset.segKey??"",p=e.dataset.newParamId??"",u=e.dataset.editingParamId??"";if(d===l&&(o??"")===p&&(r??"")===u)return;let c=i?H(e):null;e.dataset.segKey=d,e.dataset.newParamId=o??"",e.dataset.editingParamId=r??"";let h=e.ownerDocument??document,b=h.createDocumentFragment(),v=0;for(let f of t)if(v+=f.value.length,f.type==="completed"){let m=h.createElement("strong");m.dataset.seg="completed",m.dataset.paramId=f.param.id;let g=f.param.id===o,w=f.param.id===r,A=["magicx-aia-segment","magicx-aia-segment--completed"];g&&A.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),w&&A.push("magicx-aia-segment--editing"),m.className=A.join(" "),m.textContent=f.value,b.appendChild(m)}else b.appendChild(h.createTextNode(f.value));e.replaceChildren(b),e.dataset.aiaTextLength=String(v),c!=null&&L(e,Math.max(0,Math.min(c,v)))}import{useCallback as E,useEffect as Je,useRef as W,useState as _n}from"react";function N(n,e){let t=n,o={},r=[];for(let a of e){let i=(o[a.type]??0)+1;o[a.type]=i;let d=`{{${a.type.toUpperCase().replace(/\s+/g,"_")}_${i}}}`,l=t.indexOf(a.text);l!==-1&&(t=t.slice(0,l)+d+t.slice(l+a.text.length)),r.push({...a,placeholder:d})}return{rawQuery:t,completedParams:r}}function he(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function ae(n,e,t){let o=n.slice(e);if(t||e===0||n[e-1]===" ")return o;let r=o.indexOf(" ");return r===-1?"":o.slice(r+1)}function Tt(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let o=t.split(" "),r=e.toLowerCase();for(let a=0;a<o.length;a++){let i=o.slice(a).join(" ");if(r.startsWith(i.toLowerCase())){let s=t.length-i.length;return n.length-s}}return 0}function be(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let o=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(o))}function se(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let o=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===o)??null}var le=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=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.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function _t(n,e){let t=[],o=0;for(let a of e){let i=n.indexOf(a.text,o);i!==-1&&(i>o&&t.push({type:"text",value:n.slice(o,i)}),t.push({type:"completed",value:a.text,param:a}),o=i+a.text.length)}let r=n.slice(o);return r&&t.push({type:"text",value:r}),t}function Et(n,e){let t=[],o=[],r=0;for(let a of e){let i=n.indexOf(a.text,r);i===-1?o.push(a):(t.push(a),r=i+a.text.length)}return{valid:t,invalid:o}}var Fe=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 ln="https://api.ai-autocomplete.com",Ke=`${ln}/api/suggest`,kt=new WeakMap;function xe(n){return n?.type==="accessToken"}function dn(n){if(!(!n||xe(n)))return n}function ze(n){let e=kt.get(n.getAccessToken);return e||(e=new Fe(n),kt.set(n.getAccessToken,e)),e}function We(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function $e(n){let e=dn(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}function cn(n){return(n??Ke).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function pn(n){return xe(n)?`Bearer ${await ze(n).getToken()}`:$e(n)}async function Ot(n){try{let e=cn(n.apiConfig?.endpoint),t=We(n.apiConfig),o=await pn(n.apiConfig);o&&(t.Authorization=o);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var un="0.1.40",Dt=!1;function mn(){return crypto.randomUUID()}function gn(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function fn(n,e,t,o){let r=e.find(i=>i.type==="contact"&&i.metadata?.contact_account_count)?.metadata?.contact_account_count,a=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(i=>gn(i,t)),...a!=null&&{contact_account_count:a}},meta:{request_id:mn(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:un,session_id:o}}}async function Lt(n,e,t,o,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:o,signal:r})}async function Mt(n,e,t){let o=t.apiConfig,r=!t.maskCompletedText,a=fn(n,e,r,t.sessionId),i=We(o),s=o?.endpoint??Ke,d=JSON.stringify(a);if(xe(o)){let u=ze(o),c=await u.getToken(),h=await Lt(s,i,c,d,t.signal);if(h.status===401){let b=await u.getToken(!0);h=await Lt(s,i,b,d,t.signal)}if(!h.ok)throw new Error(`API error: ${h.status} ${h.statusText}`);return h.json()}let l=$e(o);!l&&!Dt&&(Dt=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),l&&(i.Authorization=l);let p=await fetch(s,{method:"POST",headers:i,body:d,signal:t.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function Rt(n,e){return e?n.map(t=>{let o=e[t.type];if(!o)return t;let r=o("");if(r.length===0)return t;let a=new Set(r.map(s=>s.text)),i=(t.options??[]).filter(s=>!a.has(s.text));return{...t,options:[...r,...i]}}):n}var hn=100,bn=300,xn=2,qe=class{constructor(e,t,o,r,a,i,s={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=o;this.getMaskCompletedText=r;this.getOnError=a;this.getSessionId=i;this.callbacks=s;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(o=>{(o.text!==e||o.completedParams!==t)&&(e=o.text,t=o.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let o=new AbortController;this.abortController=o;let r=++this.fetchVersion,a=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let i=await Mt(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:o.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let s=Rt(i.data.suggestions??[],this.getOptionOverrides()),d=i.data.input??[],l=d[d.length-1],p=this.store.get().text,u,c;if(l?.state==="in_progress"){c=!0;let f=p.toLowerCase().lastIndexOf(l.text.toLowerCase());u=f!==-1?f:a}else c=!1,u=a;let b=s.filter(f=>f.type!=="placeholder")[0],v=null;if(b){let f=ae(p,u,c),m=se(b.options,f);m&&(v={id:crypto.randomUUID(),placeholder:"",type:b.type,text:m.text,kind:m.kind,suggestionType:b.type,suggestionPlaceholder:b.text,options:b.options??[],metadata:m.metadata},s=s.filter(g=>g!==b),this.callbacks.onAutoMatch?.({active:b,matched:m,rawQuery:e}))}this.store.set(f=>({suggestions:s,isLoading:!1,isReady:i.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:u,filterInProgress:c,...v?{completedParams:[...f.completedParams,v]}:{}}))}catch(i){if(r===this.fetchVersion){let s=i instanceof Error?i:new Error(String(i));this.store.set({error:s,isLoading:!1}),this.getOnError()?.(s)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=o=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let a=r.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),i=he(r.text,r.filterBase,a),s=ae(r.text,i,r.filterInProgress),l=r.suggestions.filter(g=>g.type!=="placeholder")[0],u=(l?be(l.options,s):[]).filter(g=>g.is_tappable),c=l?se(l.options,s)!==null:!1,h=s.trim().length>0;if(u.length>0&&!c&&h||r.completedParams.length===0&&r.text.length>0&&a.length>0&&a.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:b,completedParams:v}=N(r.text,r.completedParams),f=b.length<r.lastRawQuery.length,m=Math.abs(b.length-r.lastRawQuery.length);return f||m>=o?(this.doFetch(b,v),!0):!1};this.debounceTimer=setTimeout(()=>{t(xn)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},hn),this.slowDebounceTimer=setTimeout(()=>t(1),bn)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};function Nt(n){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?At(n):!1}function vn(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?H(n):null}var Ue=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:o,getOnSubmit:r}=this.ctx,a=this.getEffectiveColumns(),i=r(),s=this.getTappableIndices(a);switch(e.key){case"ArrowDown":{let d=Nt(e.target),l=!!t.editingParam;if(!d&&!l&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:s[0]??0});break}if(s.length===0)return;let p=s.indexOf(t.activeDropdownIndex),u=p<s.length-1?p+1:0;this.store.set({activeDropdownIndex:s[u]});break}case"ArrowUp":{if(s.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<a){this.store.set({activeDropdownIndex:-1});break}let d=s.indexOf(t.activeDropdownIndex),l=d>0?d-1:s.length-1;this.store.set({activeDropdownIndex:s[l]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%a<a-1){let p=t.activeDropdownIndex+1;p<t.filteredOptions.length&&t.filteredOptions[p]?.is_tappable&&this.store.set({activeDropdownIndex:p})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let l=e.target.closest("[data-aia-input]")??e.target,p=t.editingTail;this.ctx.exitEditMode?.(),L(l,p);break}Nt(e.target)&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%a>0){let d=t.activeDropdownIndex-1;d>=0&&t.filteredOptions[d]?.is_tappable&&this.store.set({activeDropdownIndex:d})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let d=e.target.closest("[data-aia-input]")??e.target,l=t.editingAnchor;this.ctx.exitEditMode?.(),L(d,l);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let d=vn(e.target);if(d==null)break;this.ctx.removeParamAtCaret(d)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(i){let{rawQuery:d,completedParams:l}=N(t.text,t.completedParams);i({query:t.text.trim(),raw_query:d,completed_params:l}),this.ctx.afterSubmit?.()}break}case"Tab":{let d=!t.text&&!!t.placeholderText,l=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(d&&!l){e.preventDefault();let p=t.placeholderText;if(this.store.set(u=>({text:p,filterBase:p.length,suggestions:u.suggestions.filter(c=>c.type!=="placeholder")})),e.target instanceof HTMLElement){let u=e.target.closest("[data-aia-input]")??e.target;queueMicrotask(()=>L(u,p.length))}}else if(l)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(t.isDropdownOpen){let p=t.filteredOptions.findIndex(u=>u.is_tappable);p>=0&&(e.preventDefault(),this.clickOrSelect(p,t.filteredOptions,o))}break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let d=e.target.closest("[data-aia-input]")??e.target,l=t.editingTail;this.ctx.exitEditMode?.(),L(d,l)}this.store.set({activeDropdownIndex:-1});break}}}getTappableIndices(e){let o=this.store.get().filteredOptions.map((a,i)=>a.is_tappable?i:-1).filter(a=>a!==-1),r=Array.from({length:e},()=>[]);for(let a of o)r[a%e].push(a);return r.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let o=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return o>0?o:this.ctx.columns}clickOrSelect(e,t,o){let r=document.getElementById(`${o}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),o=t.suggestions.filter(s=>s.type!=="placeholder");if(e<0||e>=o.length)return;let r=o[e],a=o.filter((s,d)=>d!==e),i=t.suggestions.filter(s=>s.type==="placeholder");this.store.set({suggestions:[...i,r,...a],pillTapped:!0,activeDropdownIndex:-1})}};var Ge=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),o=t.suggestions.filter(s=>s.type!=="placeholder");if(e<0||e>=o.length)return;let r=o[e],a=o.filter((s,d)=>d!==e),i=t.suggestions.filter(s=>s.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:s}=N(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:s,selectedPill:r.text,otherPills:a.map(d=>d.text)})}this.store.set({suggestions:[...i,r,...a],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};var Ht=[125,69];function Bt(n){return n===0?.4:n===1?.3:.15}function Qe(n,e,t,o,r=!1,a=!1){let i=n.querySelector(".magicx-aia-pill-list");if(i||(i=document.createElement("span"),i.className="magicx-aia-pill-list",n.appendChild(i)),a&&e.length===0){i.setAttribute("data-aia-pill-list-loading",""),i.innerHTML="";for(let l=0;l<Ht.length;l++){let p=Ht[l],u=document.createElement("span");u.setAttribute("data-aia-pill-skeleton",""),u.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,u.style.width=`${p}px`,u.style.opacity=String(Bt(l)),i.appendChild(u)}return}a?i.setAttribute("data-aia-pill-list-loading",""):i.removeAttribute("data-aia-pill-list-loading");for(let l of i.querySelectorAll("[data-aia-pill-skeleton]"))l.remove();let s=new Map;for(let l of i.querySelectorAll(".magicx-aia-pill"))s.set(l.dataset.pillKey??"",l);let d=new Set;for(let l=0;l<e.length;l++){let p=e[l],u=`${p.type}-${p.text}`;d.add(u);let c=s.get(u);(!c||c.tagName!=="BUTTON")&&(c?.remove(),c=document.createElement("button"),c.type="button",c.tabIndex=-1,c.dataset.pillKey=u,c.setAttribute("data-aia-pill",""),c.setAttribute("contenteditable","false"),c.textContent=p.text,c.addEventListener("mousedown",b=>b.preventDefault()));let h=["magicx-aia-pill"];r&&h.push("magicx-aia-pill--rounded"),l===t&&!a&&h.push("magicx-aia-pill--active"),a&&h.push("magicx-aia-pill--skeleton"),c.className=h.join(" "),c.style.width="",c.style.opacity=String(Bt(l)),a?(c.setAttribute("data-aia-loading",""),c.disabled=!0,c.onclick=null):(c.removeAttribute("data-aia-loading"),c.disabled=!1,c.onclick=()=>o(l)),i.children[l]!==c&&i.insertBefore(c,i.children[l]??null)}for(let[l,p]of s)d.has(l)||p.remove()}function pt(n){n.querySelector(".magicx-aia-pill-list")?.remove()}var yn=[159,119,164];function je(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function Ve(n,e){let{filteredOptions:t,activeIndex:o,isOpen:r,isLoading:a,pills:i,showPills:s,onSelect:d,onHighlight:l,onPillClick:p}=e,u=s&&i.length>0,c=t.length>0;r&&(c||u||a)?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),a?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading");let b=u||a&&s,v=n.querySelector(".magicx-aia-pill-bar");b?(v||(v=document.createElement("div"),v.className="magicx-aia-pill-bar",v.setAttribute("data-aia-pillbar",""),n.insertBefore(v,n.firstChild)),Qe(v,i,0,p,!0,a)):v&&v.remove();let f=n.querySelector(".magicx-aia-grid");c?(f||(f=document.createElement("div"),f.className="magicx-aia-grid",n.appendChild(f)),wn(f,t,o,d,l,e.listboxId,a)):f&&f.remove();let m=n.querySelector(".magicx-aia-skeleton-bars");if(a&&!c){if(!m){m=document.createElement("div"),m.className="magicx-aia-skeleton-bars",m.setAttribute("data-aia-skeleton-bars","");for(let g of yn){let w=document.createElement("span");w.className="magicx-aia-skeleton-bar",w.style.width=`${g}px`,m.appendChild(w)}n.appendChild(m)}}else m&&m.remove()}function wn(n,e,t,o,r,a,i){let s=e.map(c=>c.text).join("\0"),d=n.dataset.optionsKey??"",l=n.dataset.loading??"",p=i?"1":"0",u=s!==d||l!==p;if(n.dataset.optionsKey=s,n.dataset.loading=p,u){let c=document.createDocumentFragment();for(let h=0;h<e.length;h++){let b=e[h],v=Sn(b,h,t,o,r,a,i);c.appendChild(v)}n.innerHTML="",n.appendChild(c)}else{let c=n.querySelectorAll(".magicx-aia-option");for(let h=0;h<c.length;h++){let b=c[h],v=h===t&&!i;b.setAttribute("aria-selected",String(v)),v?b.classList.add("magicx-aia-option--highlighted"):b.classList.remove("magicx-aia-option--highlighted")}}}function Sn(n,e,t,o,r,a,i){let s=document.createElement("div");s.id=`${a}-option-${e}`,s.setAttribute("role","option"),s.setAttribute("data-aia-option",""),i&&s.setAttribute("data-aia-loading",""),s.setAttribute("aria-selected",String(e===t&&!i)),s.tabIndex=i||!n.is_tappable?-1:0;let d=["magicx-aia-option"];e===t&&!i&&d.push("magicx-aia-option--highlighted"),n.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),s.className=d.join(" ");let l=document.createElement("div");l.className="magicx-aia-streaks",s.appendChild(l);let p=document.createElement("div");p.className="magicx-aia-streaks-vert",s.appendChild(p);let u=document.createElement("span");if(u.className="magicx-aia-option-content",u.textContent=n.icon?`${n.icon} ${n.text}`:n.text,n.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=n.tag,u.appendChild(c)}return s.appendChild(u),!i&&n.is_tappable&&(s.addEventListener("click",()=>{s.classList.add("magicx-aia-option--pressed"),o(n),setTimeout(()=>s.classList.remove("magicx-aia-option--pressed"),500)}),s.addEventListener("mouseenter",()=>r(e))),s}function Ft(n,e){let t=je(e.listboxId);return n.appendChild(t),{dropdown:t}}function ut(n,e,t){Ve(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:o=>t.store.set({activeDropdownIndex:o}),onPillClick:t.setActivePill})}var Pn='<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 In(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function Kt(n,e){let{listboxId:t}=e,o=je(t);n.appendChild(o);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let a=document.createElement("div");a.className="magicx-aia-editor",a.setAttribute("data-aia-editor",""),r.appendChild(a);let i=document.createElement("div");i.className="magicx-aia-input",i.setAttribute("data-aia-input",""),i.setAttribute("contenteditable",In()?"plaintext-only":"true"),i.setAttribute("role","combobox"),i.setAttribute("aria-autocomplete","list"),i.setAttribute("aria-haspopup","listbox"),i.setAttribute("aria-controls",t),i.setAttribute("aria-expanded","false"),i.setAttribute("spellcheck","true"),i.setAttribute("enterkeyhint","send"),a.appendChild(i);let s=document.createElement("span");s.className="magicx-aia-pill-list-container",s.setAttribute("data-aia-pill-list-container",""),a.appendChild(s);let d=null,l=null;e.submitButton===void 0?(d=document.createElement("button"),d.type="button",d.className="magicx-aia-submit",d.setAttribute("aria-label","Submit"),d.setAttribute("data-aia-submit",""),d.innerHTML=Pn,r.appendChild(d),l=d):e.submitButton!==null&&(l=e.submitButton,l.hasAttribute("data-aia-submit")||l.setAttribute("data-aia-submit",""),r.appendChild(l));let p=new AbortController,{signal:u}=p,c=!1,h=0,b=()=>{let m=re(i),w=m.length>0&&m[0]!==m[0].toUpperCase()?m[0].toUpperCase()+m.slice(1):m;e.handleChange(w)},v=()=>{let m=(i.ownerDocument??document).getSelection();if(!m||m.rangeCount===0)return null;let g=m.anchorNode;return!g||!i.contains(g)?null:(g.nodeType===Node.ELEMENT_NODE?g:g.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",m=>{m.target?.closest("[data-aia-pill]")||i.focus()},{signal:u}),i.addEventListener("input",()=>{c||(h=performance.now(),b(),e.handleCaretAfterInput(H(i)))},{signal:u});let f=i.ownerDocument??document;return f.addEventListener("selectionchange",()=>{let m=f.getSelection();if(!m||m.rangeCount===0||!i.contains(m.anchorNode))return;let g=v(),w=e.store.get().editingParam?.id??null;if(g&&g!==w){e.startEditingParam(g);return}performance.now()-h<50||e.handleCaretMove(H(i))},{signal:u}),i.addEventListener("compositionstart",()=>{c=!0},{signal:u}),i.addEventListener("compositionend",()=>{c=!1,b()},{signal:u}),i.addEventListener("beforeinput",m=>{let g=m,w=g.inputType;if(w==="insertParagraph"||w==="insertLineBreak"||w==="insertFromDrop"){m.preventDefault();return}if(w.startsWith("insert")||w.startsWith("delete")){let A=w.startsWith("delete")?"":g.data??"";e.replaceEditingRange(A)&&m.preventDefault()}},{signal:u}),i.addEventListener("paste",m=>{m.preventDefault();let g=(m.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!g)return;let w=i.ownerDocument??document,A=w.getSelection();if(!A||A.rangeCount===0)return;let k=A.getRangeAt(0);if(!i.contains(k.startContainer))return;k.deleteContents();let $=w.createTextNode(g);k.insertNode($),k.setStartAfter($),k.collapse(!0),A.removeAllRanges(),A.addRange(k),b()},{signal:u}),i.addEventListener("keydown",m=>e.handleKeyDown(m),{signal:u}),i.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:u}),i.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:u}),l&&l.addEventListener("click",m=>{let g=e.store.get();if(!(!!g.text||g.completedParams.length>0)||!e.onSubmit)return;m.stopPropagation();let{rawQuery:A,completedParams:k}=N(g.text,g.completedParams);e.onSubmit({query:g.text.trim(),raw_query:A,completed_params:k}),e.afterSubmit?.()},{signal:u}),e.autoFocus!==!1&&i.focus(),{input:i,inlinePillContainer:s,dropdown:o,submitButton:d,abort:p}}function mt(n,e,t){let{input:o,inlinePillContainer:r,dropdown:a,submitButton:i}=n,{pillPlacement:s,setActivePill:d,selectOption:l,store:p}=t;o.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(u?o.setAttribute("aria-activedescendant",u):o.removeAttribute("aria-activedescendant"),i){let f=!!e.text||e.completedParams.length>0;i.disabled=!f}let c=o.dataset.newParamId??"",h=e.newParamId!==null&&e.newParamId!==c;if(Be({input:o,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),s==="inline"){let f=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;f||e.actionableSuggestions.length>0?Qe(r,e.actionableSuggestions,0,d,!1,f):pt(r)}else pt(r);h?(o.focus(),L(o,e.caretOffset??e.text.length)):e.isFocused&&re(o)!==e.text&&L(o,e.text.length);let b=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,v=b??e.actionableSuggestions[0];Ve(a,{suggestions:v?[{...v,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:b?[b]:e.actionableSuggestions,showPills:s==="dropdown",onSelect:l,onHighlight:f=>p.set({activeDropdownIndex:f}),onPillClick:d})}function zt(n){let e=n,t=new Set;return{get:()=>e,set:o=>{let r=typeof o=="function"?o(e):o,a={...e,...r},i=e;e=a;for(let s of t)s(a,i)},subscribe:o=>(t.add(o),()=>{t.delete(o)})}}var gt=!1;function Wt(){if(gt||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){gt=!0;return}gt=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=An,document.head.appendChild(n)}var An="";var Cn=0;function Tn(){return`:ac-${++Cn}:`}var $t=500;function qt(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1}}var Xe=class{constructor(e,t={}){this.store=zt(qt());this._listboxId=Tn();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.sessionId=crypto.randomUUID();this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new Ge(this.store,{onPillSelected:({rawQuery:o,selectedPill:r,otherPills:a})=>{this.fireTelemetry("pill",{raw_query:o,selected_pill:r,other_pills:a})}}),this.fetchController=new qe(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError,()=>this.sessionId,{onAutoMatch:({active:o,matched:r,rawQuery:a})=>{this.fireTelemetry("option",{raw_query:a,selected_option:r.text,other_options:(o.options??[]).filter(i=>i.text!==r.text).map(i=>i.text)})}}),this.keyboardController=new Ue(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:o=>this.selectOption(o),removeParamAtCaret:o=>this.removeParamAtCaret(o),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((o,r)=>{this.recomputeDerived(o,r)})),this.unsubscribers.push(this.store.subscribe((o,r)=>{o.text!==r.text&&this.opts.onChange?.(o.text),o.completedParams!==r.completedParams&&this.opts.onParamsChange?.(o.completedParams),o.isFocused!==r.isFocused&&(o.isFocused?this.opts.onFocus?.():this.opts.onBlur?.()),this.opts.onStateChange?.(o)})),this.renderMode!=="headless"&&(Wt(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){this.store.set({...qt(),skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.selectionAnimationTimer&&clearTimeout(this.selectionAnimationTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:o,completedParams:r}=t,a=0;for(let i=0;i<r.length;i++){let s=r[i],d=o.indexOf(s.text,a);if(d===-1)continue;let l=d,p=d+s.text.length;if(e>l&&e<=p){let u=Ct(o,e),c=o.slice(0,u)+o.slice(e),h=r.filter((b,v)=>v!==i);return this.store.set(b=>({text:c,filterBase:Math.min(b.filterBase,c.length),completedParams:h,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(u),!0}a=p}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?L(t.input,e):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){let t=this.store.get();if(t.editingParam?.id===e)return;let o=t.completedParams.find(i=>i.id===e);if(!o)return;let r=0,a=-1;for(let i of t.completedParams){let s=t.text.indexOf(i.text,r);if(s!==-1){if(i.id===e){a=s;break}r=s+i.text.length}}a<0||this.store.set({editingParam:o,editingAnchor:a,editingTail:a+o.text.length,caretOffset:a+o.text.length,activeDropdownIndex:-1})}replaceEditingRange(e){let t=this.store.get(),o=t.editingParam,r=t.editingAnchor,a=t.editingTail;if(!o||r==null||a==null||!t.completedParams.some(d=>d.id===o.id))return!1;let i=t.text.slice(0,r)+e+t.text.slice(a),s=r+e.length;return this.store.set(d=>({text:i,completedParams:d.completedParams.filter(l=>l.id!==o.id),editingTail:s,caretOffset:s,activeDropdownIndex:-1})),this.scheduleSetCursor(s),this.maybePromoteEditExactMatch(),!0}exitEditMode(){this.store.get().editingParam&&this.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}handleCaretAfterInput(e){let t=this.store.get(),o={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(o.editingParam=null,o.editingAnchor=null,o.editingTail=null,o.activeDropdownIndex=-1):t.editingTail!=null&&(o.editingTail=Math.max(t.editingTail,e))),this.store.set(o),this.maybePromoteEditExactMatch()}handleCaretMove(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.store.set({caretOffset:e})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};case"focus":return this.opts.onFocus=t,()=>{this.opts.onFocus=void 0};case"blur":return this.opts.onBlur=t,()=>{this.opts.onBlur=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),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)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.selectOptionInEditMode(e);return}let o=t.actionableSuggestions[0];if(!o)return;let{rawQuery:r}=N(t.text,t.completedParams);this.fireTelemetry("option",{raw_query:r,selected_option:e.text,other_options:t.filteredOptions.filter(m=>m.text!==e.text).map(m=>m.text)});let a=t.filterBase,i=t.text.slice(0,a),s=i.length===0&&t.text.length===0,d=i.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(s||d)&&t.placeholderText&&(i=`${t.placeholderText} `);let l=Tt(i,e.text);l>0&&(i=i.slice(0,i.length-l));let p=i.length>0&&i[i.length-1]!==" ",u=`${i}${p?" ":""}${e.text} `,c=(s||d)&&u.length>0?u[0].toUpperCase()+u.slice(1):u,h=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),b=h>=0?c.slice(h,h+e.text.length):e.text,v={id:crypto.randomUUID(),placeholder:"",type:o.type,text:b,kind:e.kind,suggestionType:o.type,suggestionPlaceholder:o.text,options:o.options??[],metadata:e.metadata},f=t.actionableSuggestions.length-1;this.store.set(m=>({text:c,filterBase:c.length,completedParams:[...m.completedParams,v],newParamId:v.id,caretOffset:c.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:f>0,inSelectionAnimation:!0})),this.startSelectionAnimationTimer(),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),f>0&&(this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(m=>({suggestions:m.suggestions.filter(g=>g!==o)}))},$t))}startSelectionAnimationTimer(){this.selectionAnimationTimer&&clearTimeout(this.selectionAnimationTimer),this.selectionAnimationTimer=window.setTimeout(()=>{this.store.set({inSelectionAnimation:!1})},$t)}selectOptionInEditMode(e){let t=this.store.get(),o=t.editingParam,r=t.editingAnchor,a=t.editingTail;if(!o||r==null||a==null)return;this.fireTelemetry("option",{raw_query:N(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:o.options.filter(m=>m.text!==e.text).map(m=>m.text)});let i=t.text.slice(0,r),s=t.text.slice(a),d=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=s.length===0||s[0]!==" ",p=l?`${d} `:d,u=i+p+s,c=r+p.length+(l?0:1),h={id:crypto.randomUUID(),placeholder:"",type:o.suggestionType,text:d,kind:e.kind,suggestionType:o.suggestionType,suggestionPlaceholder:o.suggestionPlaceholder,options:o.options,metadata:e.metadata},b=t.completedParams.findIndex(m=>m.id===o.id),v=t.completedParams.filter(m=>m.id!==o.id),f=b>=0?Math.min(b,v.length):v.length;v.splice(f,0,h),this.store.set({text:u,completedParams:v,newParamId:h.id,filterBase:c,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:c,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.startSelectionAnimationTimer(),this.scheduleSetCursor(c)}fireTelemetry(e,t){let o=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");Ot({source:o,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let o=_t(e.text,e.completedParams),r=e.suggestions.filter(g=>g.type!=="placeholder"),a=r[0],i=a?this.opts.optionOverrides?.[a.type]:void 0,s=e.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),d=he(e.text,Math.min(e.filterBase,e.text.length),s),p=e.lastRawQuery!==""||d>0?ae(e.text,d,e.filterInProgress):"",u=a?i?i(p.trim()):a.options??[]:[],c=e.editingParam!=null&&e.editingAnchor!=null,h;if(c&&e.editingParam&&e.editingAnchor!=null){let g=e.editingParam.id,w=e.completedParams.some($=>$.id===g),A=e.caretOffset??e.editingAnchor,k=w?"":e.text.slice(e.editingAnchor,A);h=be(e.editingParam.options,k)}else h=be(u,p);let b=this.opts.dropdownTrigger??"auto",v=this.opts.closeDropdownOnBlur??!0,f=!1;if(c){let g=v?e.isFocused:!0;f=h.length>0&&g}else if(b==="auto"){let g=v?e.isFocused:!0,w=e.text.replace(/\s+$/,"").length,A=e.caretOffset==null||e.caretOffset>=w;f=(h.length>0||e.isLoading)&&g&&A}else b==="manual"&&(f=(h.length>0||e.isLoading)&&e.pillTapped);this.store.set({segments:o,actionableSuggestions:r,filteredOptions:h,placeholderText:s,isDropdownOpen:f}),this.derivedInProgress=!1;let m=this.store.get();for(let g of this.externalListeners)g(m)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new le(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:o=>this.selectOption(o),setActivePill:o=>this.pillsController.setActivePill(o),handleKeyDown:o=>this.keyboardController.handleKeyDown(o),handleChange:o=>this.handleChange(o),startEditingParam:o=>this.startEditingParam(o),handleCaretAfterInput:o=>this.handleCaretAfterInput(o),handleCaretMove:o=>this.handleCaretMove(o),replaceEditingRange:o=>this.replaceEditingRange(o)};this.domRefs=Kt(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&mt(this.domRefs,this.store.get(),t)}),mt(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Ft(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&ut(this.dropdownRefs,this.store.get(),e)}),ut(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:o,invalid:r}=Et(e,t.completedParams);r.length>0&&this.store.set({completedParams:o}),this.maybePromoteExactMatch(e)}maybePromoteExactMatch(e){let t=this.store.get(),r=t.suggestions.filter(g=>g.type!=="placeholder")[0];if(!r?.options)return;let a=t.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),i=he(e,t.filterBase,a),s=ae(e,i,t.filterInProgress),d=se(r.options,s);if(!d)return;let l=d.text.toLowerCase(),p=e.toLowerCase().lastIndexOf(l),u=p>=0?p:Math.max(0,e.length-d.text.length),c=u+d.text.length,h=e.slice(u,c),b=e,f=c<e.length&&e[c]===" "?c+1:c,m={id:crypto.randomUUID(),placeholder:"",type:r.type,text:h,kind:d.kind,suggestionType:r.type,suggestionPlaceholder:r.text,options:r.options??[],metadata:d.metadata};this.store.set(g=>({text:b,completedParams:[...g.completedParams,m],suggestions:g.suggestions.filter(w=>w!==r),filterBase:f,newParamId:m.id,caretOffset:f,activeDropdownIndex:-1}))}maybePromoteEditExactMatch(){let e=this.store.get(),t=e.editingParam,o=e.editingAnchor,r=e.editingTail;if(!t||o==null||r==null||e.completedParams.some(w=>w.id===t.id))return;let a=e.text.slice(o,r),i=se(t.options,a);if(!i)return;let s=i.text.toLowerCase(),d=a.toLowerCase().lastIndexOf(s),l=o+Math.max(0,d),p=l+i.text.length,u=e.text.slice(l,p),c=e.text,b=p<e.text.length&&e.text[p]===" "?p+1:p,v={id:crypto.randomUUID(),placeholder:"",type:t.suggestionType,text:u,kind:i.kind,suggestionType:t.suggestionType,suggestionPlaceholder:t.suggestionPlaceholder,options:t.options,metadata:i.metadata},f=e.completedParams.length,m=0;for(let w=0;w<e.completedParams.length;w++){let A=c.indexOf(e.completedParams[w].text,m);if(A!==-1){if(A>=b){f=w;break}m=A+e.completedParams[w].text.length}}let g=[...e.completedParams];g.splice(f,0,v),this.store.set(()=>({text:c,completedParams:g,newParamId:v.id,filterBase:b,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:b,activeDropdownIndex:-1})),this.scheduleSetCursor(b)}};function ft({onSubmit:n,onError:e,optionOverrides:t,maskCompletedText:o,apiConfig:r,columns:a=2,dropdownTrigger:i,closeDropdownOnBlur:s,onFocus:d,onBlur:l,value:p,completedParams:u,onChange:c,onParamsChange:h,source:b,setCursor:v}){let f=W(null),[m,g]=_n(null),w=W(n);w.current=n;let A=W(e);A.current=e;let k=W(c);k.current=c;let $=W(h);$.current=h;let de=W(d);de.current=d;let _=W(l);_.current=l;let ce=W(v);ce.current=v,Je(()=>{if(typeof document>"u")return;let S=new Xe(document.createElement("div"),{renderMode:"headless",apiConfig:r,optionOverrides:t,maskCompletedText:o,columns:a,dropdownTrigger:i,closeDropdownOnBlur:s,source:b,value:p,completedParams:u,onSubmit:(...O)=>w.current?.(...O),onError:(...O)=>A.current?.(...O),onChange:(...O)=>k.current?.(...O),onParamsChange:(...O)=>$.current?.(...O),onFocus:()=>de.current?.(),onBlur:()=>_.current?.(),setCursor:O=>ce.current?.(O)});f.current=S,g(S.getState());let M=S.subscribe(O=>g(O));return()=>{M(),S.destroy(),f.current===S&&(f.current=null)}},[]);let x=f.current,C=E(()=>{},[]);Je(()=>{p!==void 0&&x?.setValue(p)},[p,x]),Je(()=>{u!==void 0&&x?.setCompletedParams(u)},[u,x]);let ye=JSON.stringify(r??null),te=W(t),pe=W(0);if(t!==te.current){let S=te.current,M=t,O=Object.keys(S??{}),q=Object.keys(M??{});(O.length!==q.length||q.some(Y=>!S?.[Y]||M[Y]!==S[Y]))&&pe.current++,te.current=t}Je(()=>{x?.update({apiConfig:r,optionOverrides:t,dropdownTrigger:i,closeDropdownOnBlur:s})},[ye,pe.current,i,s,x]);let we=E(S=>{if(!x)return;let M=S.target.value,q=M.length>0&&!S.nativeEvent?.isComposing&&M[0]!==M[0].toUpperCase()?M[0].toUpperCase()+M.slice(1):M;x.handleTextChange(q)},[x]),Ze=E(S=>{x?.handleKeyDown(S.nativeEvent)},[x]),ue=E(()=>x?.setFocused(!0),[x]),Se=E(()=>x?.setFocused(!1),[x]),et=E(S=>x?.handleTextChange(S),[x]),me=E(S=>{if(!x)return;let M="nativeEvent"in S?S.nativeEvent:S;x.handleKeyDown(M)},[x]),j=E(S=>x?.setFocused(S),[x]),Pe=E(S=>x?.startEditingParam(S),[x]),Ie=E(()=>x?.exitEditMode(),[x]),Ae=E(S=>x?.handleCaretAfterInput(S),[x]),tt=E(S=>x?.handleCaretMove(S),[x]),Ce=E(S=>x?.replaceEditingRange(S)??!1,[x]),ge=E(S=>x?.setActivePill(S),[x]),Te=E(()=>x?.removeLastParam(),[x]),_e=E(()=>x?.clearNewParamId(),[x]),Ee=E(()=>x?.reset(),[x]),ne=E(S=>x?.selectOption(S),[x]),V=E(S=>x?.setActiveDropdownIndex(S),[x]);if(!x)return{completedParams:u??[],suggestionPills:[],setActivePill:C,removeLastParam:C,segments:[],newParamId:null,clearNewParamId:C,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,isFocused:!1,isDropdownOpen:!1,placeholderText:"",listboxId:"",error:null,handleTextChange:C,handleKeyDown:C,setFocused:C,editingParam:null,editingAnchor:null,caretOffset:null,startEditingParam:C,exitEditMode:C,handleCaretAfterInput:C,handleCaretMove:C,replaceEditingRange:()=>!1,inputProps:{value:p??"",placeholder:void 0,onChange:C,onKeyDown:C,onFocus:C,onBlur:C,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:C,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:C,onHighlight:C,isOpen:!1,id:"",pills:[],onPillClick:C}};let P=m??x.getState(),nt=p!==void 0?p:P.text,ke=u!==void 0?u:P.completedParams,oe=P.actionableSuggestions,Oe=oe[0],De=P.filteredOptions,ot=P.activeDropdownIndex>=0?`${x.listboxId}-option-${P.activeDropdownIndex}`:void 0,B=P.editingParam,F=B?{type:B.suggestionType,text:B.suggestionPlaceholder,required:!0,options:B.options}:null,Le=F??Oe,it=F?[F]:oe;return{completedParams:ke,suggestionPills:oe,setActivePill:ge,removeLastParam:Te,segments:P.segments,newParamId:P.newParamId,clearNewParamId:_e,suggestions:P.suggestions,activeIndex:P.activeDropdownIndex,isReady:P.isReady,isLoading:P.isLoading&&!P.editingParam&&!P.inSelectionAnimation,isFocused:P.isFocused,isDropdownOpen:P.isDropdownOpen,placeholderText:P.placeholderText,listboxId:x.listboxId,error:P.error,handleTextChange:et,handleKeyDown:me,setFocused:j,editingParam:B,editingAnchor:P.editingAnchor,caretOffset:P.caretOffset,startEditingParam:Pe,exitEditMode:Ie,handleCaretAfterInput:Ae,handleCaretMove:tt,replaceEditingRange:Ce,inputProps:{value:nt,placeholder:P.placeholderText||void 0,onChange:we,onKeyDown:Ze,onFocus:ue,onBlur:Se,role:"combobox","aria-expanded":P.isDropdownOpen,"aria-activedescendant":ot,"aria-autocomplete":"list","aria-controls":x.listboxId},reset:Ee,dropdownProps:{suggestions:Le?[{...Le,options:De}]:[],activeIndex:P.activeDropdownIndex,onSelect:ne,onHighlight:V,isOpen:P.isDropdownOpen,id:x.listboxId,pills:it,onPillClick:ge,isLoading:P.isLoading&&!P.editingParam&&!P.inSelectionAnimation}}}import{jsx as J,jsxs as bt}from"react/jsx-runtime";function On(n){return n!=="auto"?n:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var Ye;function Dn(){if(Ye!==void 0)return Ye;if(typeof document>"u")return!1;let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),Ye=n.contentEditable==="plaintext-only",Ye}var Ln=En(function({onSubmit:e,onError:t,optionOverrides:o,maskCompletedText:r,className:a,apiConfig:i,columns:s,pillPlacement:d="inline",mode:l="auto",optionsPosition:p="below",animations:u=!0,dropdownTrigger:c,closeDropdownOnBlur:h,autoFocus:b=!0,onFocus:v,onBlur:f,value:m,completedParams:g,onChange:w,onParamsChange:A,submitButton:k},$){let de=Q(null),_=Q(null),ce=Q(()=>{}),x=Q(null),C=Q(!1),ye=Q(""),te=Q(""),pe=Q(null),we=Q(0);ve(()=>{let y=de.current;if(y)return x.current?x.current.setMode(l):x.current=new le(y,l),()=>{x.current?.destroy(),x.current=null}},[l]);let Ze=G(y=>{let I=_.current;I&&L(I,y)},[]),{completedParams:ue,suggestionPills:Se,setActivePill:et,segments:me,newParamId:j,clearNewParamId:Pe,placeholderText:Ie,isFocused:Ae,isDropdownOpen:tt,isLoading:Ce,activeIndex:ge,listboxId:Te,handleTextChange:_e,handleKeyDown:Ee,setFocused:ne,editingParam:V,editingAnchor:P,caretOffset:nt,startEditingParam:ke,handleCaretAfterInput:oe,handleCaretMove:Oe,replaceEditingRange:De,dropdownProps:ot,reset:B}=ft({onSubmit:y=>ce.current(y),onError:t,optionOverrides:o,maskCompletedText:r,apiConfig:i,columns:s,dropdownTrigger:c,closeDropdownOnBlur:h,onFocus:v,onBlur:f,value:m,completedParams:g,onChange:w,onParamsChange:A,source:"full-sdk",setCursor:Ze});pe.current=nt,ve(()=>{if(!b)return;let y=_.current;y&&(document.activeElement===y?ne(!0):y.focus())},[b,ne]),ve(()=>{if(!j)return;let y=window.setTimeout(()=>Pe(),650);return()=>window.clearTimeout(y)},[j,Pe]),ve(()=>{let y=_.current;if(!y)return;let I=y.ownerDocument??document,T=()=>{let R=I.getSelection();if(!R||R.rangeCount===0||!R.anchorNode||!y.contains(R.anchorNode))return;let D=R.anchorNode,at=(D.nodeType===Node.ELEMENT_NODE?D:D.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if(at&&at!==V?.id){ke(at);return}performance.now()-we.current<50||Oe(H(y))};return I.addEventListener("selectionchange",T),()=>I.removeEventListener("selectionchange",T)},[V,ke,Oe]),ht(()=>{let y=_.current;y&&Be({input:y,segments:me,newParamId:j,editingParamId:V?.id??null,placeholderText:Ie??"",isFocused:Ae})},[me,j,V,Ie,Ae]),ht(()=>{let y=ye.current,I=j??"";if(ye.current=I,!I||I===y)return;let T=_.current;if(!T)return;T.focus();let R=pe.current??He(T);L(T,R)},[j]),ht(()=>{let y=te.current,I=V?.id??"";if(te.current=I,!I||I===y||P==null)return;let T=_.current;T&&L(T,P)},[V,P]),kn($,()=>({focus:()=>_.current?.focus(),blur:()=>_.current?.blur(),reset:B,setMode:y=>x.current?.setMode(y)}),[B]);let F=G(()=>{if(C.current)return;let y=_.current;if(!y)return;let I=re(y),R=I.length>0&&I[0]!==I[0].toUpperCase()?I[0].toUpperCase()+I.slice(1):I;_e(R)},[_e]),Le=G(()=>{we.current=performance.now(),F();let y=_.current;y&&oe(H(y))},[F,oe]);ve(()=>{let y=_.current;if(!y)return;let I=T=>{let R=T,D=R.inputType;if(D==="insertParagraph"||D==="insertLineBreak"||D==="insertFromDrop"){T.preventDefault();return}if(D.startsWith("insert")||D.startsWith("delete")){let U=D.startsWith("delete")?"":R.data??"";De(U)&&T.preventDefault()}};return y.addEventListener("beforeinput",I),()=>y.removeEventListener("beforeinput",I)},[De]);let it=G(()=>{C.current=!0},[]),S=G(()=>{C.current=!1,F()},[F]),M=G(y=>{y.preventDefault();let I=_.current;if(!I)return;let T=(y.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!T)return;let R=I.ownerDocument??document,D=R.getSelection();if(!D||D.rangeCount===0)return;let U=D.getRangeAt(0);if(!I.contains(U.startContainer))return;U.deleteContents();let rt=R.createTextNode(T);U.insertNode(rt),U.setStartAfter(rt),U.collapse(!0),D.removeAllRanges(),D.addRange(U),F()},[F]),O=G(y=>Ee(y),[Ee]),q=!!me.length||ue.length>0,Y=G(()=>{if(!q)return;let y=_.current?re(_.current):"",{rawQuery:I,completedParams:T}=N(y,ue);e({query:y.trim(),raw_query:I,completed_params:T}),B()},[q,ue,e,B]);ce.current=Y;let Ut=G(y=>{y.target?.closest("[data-aia-pill]")||_.current?.focus()},[]),Gt=d==="inline",Qt=d==="dropdown",jt=ge>=0?`${Te}-option-${ge}`:void 0,Vt=Dn()?"plaintext-only":"true";return bt("div",{ref:de,className:`magicx-aia ${X.container} ${a??""}`,"data-pill-placement":d,"data-options-position":p,"data-animations":u?"on":"off","data-mode":On(l),children:[J(ct,{...ot,showPills:Qt}),bt("div",{className:X.inputWrapper,onClick:Ut,children:[bt("div",{className:X.editorArea,"data-aia-editor":"",children:[J("div",{ref:_,className:X.input,"data-aia-input":"",contentEditable:Vt,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":Te,"aria-expanded":tt,"aria-activedescendant":jt,spellCheck:!0,enterKeyHint:"send",onInput:Le,onKeyDown:O,onCompositionStart:it,onCompositionEnd:S,onPaste:M,onFocus:()=>ne(!0),onBlur:()=>ne(!1)}),Gt&&(Ce||Se.length>0)&&J("span",{className:X.pillListContainer,"data-aia-pill-list-container":"",children:J(fe,{pills:Se,activePillIndex:0,onSelectPill:et,loading:Ce})})]}),k===null?null:k===void 0?J("button",{type:"button","data-aia-submit":"",className:X.submitButton,disabled:!q,onClick:y=>{y.stopPropagation(),Y()},"aria-label":"Submit",children:J("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:J("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):J("span",{"data-aia-submit":"",className:X.submitSlot,onClick:y=>{q&&(y.stopPropagation(),Y())},children:k})]})]})});export{Ln as AIAutocomplete,ct as AIAutocompleteDropdown,ft as useAIAutocomplete};
801
+ `,document.head.appendChild(n)}var Pt='[contenteditable="false"]',ie;function sn(){if(ie!==void 0)return ie;let n=globalThis.Intl.Segmenter;if(!n)return ie=null,null;try{ie=new n(void 0,{granularity:"grapheme"})}catch{ie=null}return ie??null}function Re(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(Pt))return!0;t=t.parentNode}return!1}function Ne(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return Re(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function re(n){let e=Ne(n),t="",o=e.nextNode();for(;o;)t+=o.data,o=e.nextNode();return t}function He(n){let e=Ne(n),t=0,o=e.nextNode();for(;o;)t+=o.data.length,o=e.nextNode();return t}function H(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,o=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(Re(r,n)&&r!==n)return null;let a=0;for(let i=0;i<o&&i<r.childNodes.length;i++)a+=It(r.childNodes[i],n);return a+St(r,n)}return t.nodeType!==Node.TEXT_NODE||Re(t,n)?null:St(t,n)+o}function It(n,e){if(n.nodeType===Node.TEXT_NODE)return Re(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(Pt))return 0;let o=0;for(let r of Array.from(t.childNodes))o+=It(r,e);return o}function St(n,e){let t=Ne(e),o=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return o;o+=r.data.length,r=t.nextNode()}return o}function L(n,e){let t=n.ownerDocument??document,o=t.getSelection();if(!o)return;let r=Math.max(0,Math.min(e,He(n))),a=Ne(n),i=0,s=null,d=0,l=a.nextNode(),p=null;for(;l;){let c=l.data.length;if(r<i+c){s=l,d=r-i;break}if(r===i+c){let h=a.nextNode();h?(s=h,d=0):(s=l,d=c);break}i+=c,p=l,l=a.nextNode()}let u=t.createRange();if(s){let c=s.parentElement?.closest('strong[data-seg="completed"]');c&&c!==n&&n.contains(c)?d===0?u.setStartBefore(c):d===s.data.length?u.setStartAfter(c):u.setStart(s,d):u.setStart(s,d)}else p?u.setStart(p,p.data.length):u.setStart(n,0);u.collapse(!0),o.removeAllRanges(),o.addRange(u)}function At(n){let e=H(n);return e==null?!1:e>=He(n)}function Ct(n,e){if(e<=0)return 0;let t=sn();if(!t)return e-1;let o=n.slice(0,e),r=0;for(let{index:a}of t.segment(o))a<e&&(r=a);return r}function Be(n){let{input:e,segments:t,newParamId:o,editingParamId:r,placeholderText:a,isFocused:i}=n,s=t.length===0;e.dataset.aiaEmpty=s?"true":"false",s&&a?e.dataset.placeholder=a:delete e.dataset.placeholder;let d=t.map(f=>`${f.type}:${f.value}`).join("\0"),l=e.dataset.segKey??"",p=e.dataset.newParamId??"",u=e.dataset.editingParamId??"";if(d===l&&(o??"")===p&&(r??"")===u)return;let c=i?H(e):null;e.dataset.segKey=d,e.dataset.newParamId=o??"",e.dataset.editingParamId=r??"";let h=e.ownerDocument??document,b=h.createDocumentFragment(),v=0;for(let f of t)if(v+=f.value.length,f.type==="completed"){let m=h.createElement("strong");m.dataset.seg="completed",m.dataset.paramId=f.param.id;let g=f.param.id===o,w=f.param.id===r,A=["magicx-aia-segment","magicx-aia-segment--completed"];g&&A.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),w&&A.push("magicx-aia-segment--editing"),m.className=A.join(" "),m.textContent=f.value,b.appendChild(m)}else b.appendChild(h.createTextNode(f.value));e.replaceChildren(b),e.dataset.aiaTextLength=String(v),c!=null&&L(e,Math.max(0,Math.min(c,v)))}import{useCallback as E,useEffect as Je,useRef as W,useState as _n}from"react";function N(n,e){let t=n,o={},r=[];for(let a of e){let i=(o[a.type]??0)+1;o[a.type]=i;let d=`{{${a.type.toUpperCase().replace(/\s+/g,"_")}_${i}}}`,l=t.indexOf(a.text);l!==-1&&(t=t.slice(0,l)+d+t.slice(l+a.text.length)),r.push({...a,placeholder:d})}return{rawQuery:t,completedParams:r}}function he(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function ae(n,e,t){let o=n.slice(e);if(t||e===0||n[e-1]===" ")return o;let r=o.indexOf(" ");return r===-1?"":o.slice(r+1)}function Tt(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let o=t.split(" "),r=e.toLowerCase();for(let a=0;a<o.length;a++){let i=o.slice(a).join(" ");if(r.startsWith(i.toLowerCase())){let s=t.length-i.length;return n.length-s}}return 0}function be(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let o=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(o))}function se(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let o=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===o)??null}var le=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=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.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function _t(n,e){let t=[],o=0;for(let a of e){let i=n.indexOf(a.text,o);i!==-1&&(i>o&&t.push({type:"text",value:n.slice(o,i)}),t.push({type:"completed",value:a.text,param:a}),o=i+a.text.length)}let r=n.slice(o);return r&&t.push({type:"text",value:r}),t}function Et(n,e){let t=[],o=[],r=0;for(let a of e){let i=n.indexOf(a.text,r);i===-1?o.push(a):(t.push(a),r=i+a.text.length)}return{valid:t,invalid:o}}var Fe=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 ln="https://api.ai-autocomplete.com",Ke=`${ln}/api/suggest`,kt=new WeakMap;function xe(n){return n?.type==="accessToken"}function dn(n){if(!(!n||xe(n)))return n}function ze(n){let e=kt.get(n.getAccessToken);return e||(e=new Fe(n),kt.set(n.getAccessToken,e)),e}function We(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function $e(n){let e=dn(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}function cn(n){return(n??Ke).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function pn(n){return xe(n)?`Bearer ${await ze(n).getToken()}`:$e(n)}async function Ot(n){try{let e=cn(n.apiConfig?.endpoint),t=We(n.apiConfig),o=await pn(n.apiConfig);o&&(t.Authorization=o);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var un="0.1.41",Dt=!1;function mn(){return crypto.randomUUID()}function gn(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function fn(n,e,t,o){let r=e.find(i=>i.type==="contact"&&i.metadata?.contact_account_count)?.metadata?.contact_account_count,a=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(i=>gn(i,t)),...a!=null&&{contact_account_count:a}},meta:{request_id:mn(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:un,session_id:o}}}async function Lt(n,e,t,o,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:o,signal:r})}async function Mt(n,e,t){let o=t.apiConfig,r=!t.maskCompletedText,a=fn(n,e,r,t.sessionId),i=We(o),s=o?.endpoint??Ke,d=JSON.stringify(a);if(xe(o)){let u=ze(o),c=await u.getToken(),h=await Lt(s,i,c,d,t.signal);if(h.status===401){let b=await u.getToken(!0);h=await Lt(s,i,b,d,t.signal)}if(!h.ok)throw new Error(`API error: ${h.status} ${h.statusText}`);return h.json()}let l=$e(o);!l&&!Dt&&(Dt=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),l&&(i.Authorization=l);let p=await fetch(s,{method:"POST",headers:i,body:d,signal:t.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function Rt(n,e){return e?n.map(t=>{let o=e[t.type];if(!o)return t;let r=o("");if(r.length===0)return t;let a=new Set(r.map(s=>s.text)),i=(t.options??[]).filter(s=>!a.has(s.text));return{...t,options:[...r,...i]}}):n}var hn=100,bn=300,xn=2,qe=class{constructor(e,t,o,r,a,i,s={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=o;this.getMaskCompletedText=r;this.getOnError=a;this.getSessionId=i;this.callbacks=s;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(o=>{(o.text!==e||o.completedParams!==t)&&(e=o.text,t=o.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let o=new AbortController;this.abortController=o;let r=++this.fetchVersion,a=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let i=await Mt(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:o.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let s=Rt(i.data.suggestions??[],this.getOptionOverrides()),d=i.data.input??[],l=d[d.length-1],p=this.store.get().text,u,c;if(l?.state==="in_progress"){c=!0;let f=p.toLowerCase().lastIndexOf(l.text.toLowerCase());u=f!==-1?f:a}else c=!1,u=a;let b=s.filter(f=>f.type!=="placeholder")[0],v=null;if(b){let f=ae(p,u,c),m=se(b.options,f);m&&(v={id:crypto.randomUUID(),placeholder:"",type:b.type,text:m.text,kind:m.kind,suggestionType:b.type,suggestionPlaceholder:b.text,options:b.options??[],metadata:m.metadata},s=s.filter(g=>g!==b),this.callbacks.onAutoMatch?.({active:b,matched:m,rawQuery:e}))}this.store.set(f=>({suggestions:s,isLoading:!1,isReady:i.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:u,filterInProgress:c,...v?{completedParams:[...f.completedParams,v]}:{}}))}catch(i){if(r===this.fetchVersion){let s=i instanceof Error?i:new Error(String(i));this.store.set({error:s,isLoading:!1}),this.getOnError()?.(s)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=o=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let a=r.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),i=he(r.text,r.filterBase,a),s=ae(r.text,i,r.filterInProgress),l=r.suggestions.filter(g=>g.type!=="placeholder")[0],u=(l?be(l.options,s):[]).filter(g=>g.is_tappable),c=l?se(l.options,s)!==null:!1,h=s.trim().length>0;if(u.length>0&&!c&&h||r.completedParams.length===0&&r.text.length>0&&a.length>0&&a.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:b,completedParams:v}=N(r.text,r.completedParams),f=b.length<r.lastRawQuery.length,m=Math.abs(b.length-r.lastRawQuery.length);return f||m>=o?(this.doFetch(b,v),!0):!1};this.debounceTimer=setTimeout(()=>{t(xn)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},hn),this.slowDebounceTimer=setTimeout(()=>t(1),bn)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};function Nt(n){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?At(n):!1}function vn(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?H(n):null}var Ue=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:o,getOnSubmit:r}=this.ctx,a=this.getEffectiveColumns(),i=r(),s=this.getTappableIndices(a);switch(e.key){case"ArrowDown":{let d=Nt(e.target),l=!!t.editingParam;if(!d&&!l&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:s[0]??0});break}if(s.length===0)return;let p=s.indexOf(t.activeDropdownIndex),u=p<s.length-1?p+1:0;this.store.set({activeDropdownIndex:s[u]});break}case"ArrowUp":{if(s.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<a){this.store.set({activeDropdownIndex:-1});break}let d=s.indexOf(t.activeDropdownIndex),l=d>0?d-1:s.length-1;this.store.set({activeDropdownIndex:s[l]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%a<a-1){let p=t.activeDropdownIndex+1;p<t.filteredOptions.length&&t.filteredOptions[p]?.is_tappable&&this.store.set({activeDropdownIndex:p})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let l=e.target.closest("[data-aia-input]")??e.target,p=t.editingTail;this.ctx.exitEditMode?.(),L(l,p);break}Nt(e.target)&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%a>0){let d=t.activeDropdownIndex-1;d>=0&&t.filteredOptions[d]?.is_tappable&&this.store.set({activeDropdownIndex:d})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let d=e.target.closest("[data-aia-input]")??e.target,l=t.editingAnchor;this.ctx.exitEditMode?.(),L(d,l);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let d=vn(e.target);if(d==null)break;this.ctx.removeParamAtCaret(d)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(i){let{rawQuery:d,completedParams:l}=N(t.text,t.completedParams);i({query:t.text.trim(),raw_query:d,completed_params:l}),this.ctx.afterSubmit?.()}break}case"Tab":{let d=!t.text&&!!t.placeholderText,l=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(d&&!l){e.preventDefault();let p=t.placeholderText;if(this.store.set(u=>({text:p,filterBase:p.length,suggestions:u.suggestions.filter(c=>c.type!=="placeholder")})),e.target instanceof HTMLElement){let u=e.target.closest("[data-aia-input]")??e.target;queueMicrotask(()=>L(u,p.length))}}else if(l)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(t.isDropdownOpen){let p=t.filteredOptions.findIndex(u=>u.is_tappable);p>=0&&(e.preventDefault(),this.clickOrSelect(p,t.filteredOptions,o))}break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let d=e.target.closest("[data-aia-input]")??e.target,l=t.editingTail;this.ctx.exitEditMode?.(),L(d,l)}this.store.set({activeDropdownIndex:-1});break}}}getTappableIndices(e){let o=this.store.get().filteredOptions.map((a,i)=>a.is_tappable?i:-1).filter(a=>a!==-1),r=Array.from({length:e},()=>[]);for(let a of o)r[a%e].push(a);return r.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let o=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return o>0?o:this.ctx.columns}clickOrSelect(e,t,o){let r=document.getElementById(`${o}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),o=t.suggestions.filter(s=>s.type!=="placeholder");if(e<0||e>=o.length)return;let r=o[e],a=o.filter((s,d)=>d!==e),i=t.suggestions.filter(s=>s.type==="placeholder");this.store.set({suggestions:[...i,r,...a],pillTapped:!0,activeDropdownIndex:-1})}};var Ge=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),o=t.suggestions.filter(s=>s.type!=="placeholder");if(e<0||e>=o.length)return;let r=o[e],a=o.filter((s,d)=>d!==e),i=t.suggestions.filter(s=>s.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:s}=N(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:s,selectedPill:r.text,otherPills:a.map(d=>d.text)})}this.store.set({suggestions:[...i,r,...a],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};var Ht=[125,69];function Bt(n){return n===0?.4:n===1?.3:.15}function Qe(n,e,t,o,r=!1,a=!1){let i=n.querySelector(".magicx-aia-pill-list");if(i||(i=document.createElement("span"),i.className="magicx-aia-pill-list",n.appendChild(i)),a&&e.length===0){i.setAttribute("data-aia-pill-list-loading",""),i.innerHTML="";for(let l=0;l<Ht.length;l++){let p=Ht[l],u=document.createElement("span");u.setAttribute("data-aia-pill-skeleton",""),u.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,u.style.width=`${p}px`,u.style.opacity=String(Bt(l)),i.appendChild(u)}return}a?i.setAttribute("data-aia-pill-list-loading",""):i.removeAttribute("data-aia-pill-list-loading");for(let l of i.querySelectorAll("[data-aia-pill-skeleton]"))l.remove();let s=new Map;for(let l of i.querySelectorAll(".magicx-aia-pill"))s.set(l.dataset.pillKey??"",l);let d=new Set;for(let l=0;l<e.length;l++){let p=e[l],u=`${p.type}-${p.text}`;d.add(u);let c=s.get(u);(!c||c.tagName!=="BUTTON")&&(c?.remove(),c=document.createElement("button"),c.type="button",c.tabIndex=-1,c.dataset.pillKey=u,c.setAttribute("data-aia-pill",""),c.setAttribute("contenteditable","false"),c.textContent=p.text,c.addEventListener("mousedown",b=>b.preventDefault()));let h=["magicx-aia-pill"];r&&h.push("magicx-aia-pill--rounded"),l===t&&!a&&h.push("magicx-aia-pill--active"),a&&h.push("magicx-aia-pill--skeleton"),c.className=h.join(" "),c.style.width="",c.style.opacity=String(Bt(l)),a?(c.setAttribute("data-aia-loading",""),c.disabled=!0,c.onclick=null):(c.removeAttribute("data-aia-loading"),c.disabled=!1,c.onclick=()=>o(l)),i.children[l]!==c&&i.insertBefore(c,i.children[l]??null)}for(let[l,p]of s)d.has(l)||p.remove()}function pt(n){n.querySelector(".magicx-aia-pill-list")?.remove()}var yn=[159,119,164];function je(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function Ve(n,e){let{filteredOptions:t,activeIndex:o,isOpen:r,isLoading:a,pills:i,showPills:s,onSelect:d,onHighlight:l,onPillClick:p}=e,u=s&&i.length>0,c=t.length>0;r&&(c||u||a)?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),a?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading");let b=u||a&&s,v=n.querySelector(".magicx-aia-pill-bar");b?(v||(v=document.createElement("div"),v.className="magicx-aia-pill-bar",v.setAttribute("data-aia-pillbar",""),n.insertBefore(v,n.firstChild)),Qe(v,i,0,p,!0,a)):v&&v.remove();let f=n.querySelector(".magicx-aia-grid");c?(f||(f=document.createElement("div"),f.className="magicx-aia-grid",n.appendChild(f)),wn(f,t,o,d,l,e.listboxId,a)):f&&f.remove();let m=n.querySelector(".magicx-aia-skeleton-bars");if(a&&!c){if(!m){m=document.createElement("div"),m.className="magicx-aia-skeleton-bars",m.setAttribute("data-aia-skeleton-bars","");for(let g of yn){let w=document.createElement("span");w.className="magicx-aia-skeleton-bar",w.style.width=`${g}px`,m.appendChild(w)}n.appendChild(m)}}else m&&m.remove()}function wn(n,e,t,o,r,a,i){let s=e.map(c=>c.text).join("\0"),d=n.dataset.optionsKey??"",l=n.dataset.loading??"",p=i?"1":"0",u=s!==d||l!==p;if(n.dataset.optionsKey=s,n.dataset.loading=p,u){let c=document.createDocumentFragment();for(let h=0;h<e.length;h++){let b=e[h],v=Sn(b,h,t,o,r,a,i);c.appendChild(v)}n.innerHTML="",n.appendChild(c)}else{let c=n.querySelectorAll(".magicx-aia-option");for(let h=0;h<c.length;h++){let b=c[h],v=h===t&&!i;b.setAttribute("aria-selected",String(v)),v?b.classList.add("magicx-aia-option--highlighted"):b.classList.remove("magicx-aia-option--highlighted")}}}function Sn(n,e,t,o,r,a,i){let s=document.createElement("div");s.id=`${a}-option-${e}`,s.setAttribute("role","option"),s.setAttribute("data-aia-option",""),i&&s.setAttribute("data-aia-loading",""),s.setAttribute("aria-selected",String(e===t&&!i)),s.tabIndex=i||!n.is_tappable?-1:0;let d=["magicx-aia-option"];e===t&&!i&&d.push("magicx-aia-option--highlighted"),n.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),s.className=d.join(" ");let l=document.createElement("div");l.className="magicx-aia-streaks",s.appendChild(l);let p=document.createElement("div");p.className="magicx-aia-streaks-vert",s.appendChild(p);let u=document.createElement("span");if(u.className="magicx-aia-option-content",u.textContent=n.icon?`${n.icon} ${n.text}`:n.text,n.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=n.tag,u.appendChild(c)}return s.appendChild(u),!i&&n.is_tappable&&(s.addEventListener("click",()=>{s.classList.add("magicx-aia-option--pressed"),o(n),setTimeout(()=>s.classList.remove("magicx-aia-option--pressed"),500)}),s.addEventListener("mouseenter",()=>r(e))),s}function Ft(n,e){let t=je(e.listboxId);return n.appendChild(t),{dropdown:t}}function ut(n,e,t){Ve(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:o=>t.store.set({activeDropdownIndex:o}),onPillClick:t.setActivePill})}var Pn='<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 In(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function Kt(n,e){let{listboxId:t}=e,o=je(t);n.appendChild(o);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let a=document.createElement("div");a.className="magicx-aia-editor",a.setAttribute("data-aia-editor",""),r.appendChild(a);let i=document.createElement("div");i.className="magicx-aia-input",i.setAttribute("data-aia-input",""),i.setAttribute("contenteditable",In()?"plaintext-only":"true"),i.setAttribute("role","combobox"),i.setAttribute("aria-autocomplete","list"),i.setAttribute("aria-haspopup","listbox"),i.setAttribute("aria-controls",t),i.setAttribute("aria-expanded","false"),i.setAttribute("spellcheck","true"),i.setAttribute("enterkeyhint","send"),a.appendChild(i);let s=document.createElement("span");s.className="magicx-aia-pill-list-container",s.setAttribute("data-aia-pill-list-container",""),a.appendChild(s);let d=null,l=null;e.submitButton===void 0?(d=document.createElement("button"),d.type="button",d.className="magicx-aia-submit",d.setAttribute("aria-label","Submit"),d.setAttribute("data-aia-submit",""),d.innerHTML=Pn,r.appendChild(d),l=d):e.submitButton!==null&&(l=e.submitButton,l.hasAttribute("data-aia-submit")||l.setAttribute("data-aia-submit",""),r.appendChild(l));let p=new AbortController,{signal:u}=p,c=!1,h=0,b=()=>{let m=re(i),w=m.length>0&&m[0]!==m[0].toUpperCase()?m[0].toUpperCase()+m.slice(1):m;e.handleChange(w)},v=()=>{let m=(i.ownerDocument??document).getSelection();if(!m||m.rangeCount===0)return null;let g=m.anchorNode;return!g||!i.contains(g)?null:(g.nodeType===Node.ELEMENT_NODE?g:g.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",m=>{m.target?.closest("[data-aia-pill]")||i.focus()},{signal:u}),i.addEventListener("input",()=>{c||(h=performance.now(),b(),e.handleCaretAfterInput(H(i)))},{signal:u});let f=i.ownerDocument??document;return f.addEventListener("selectionchange",()=>{let m=f.getSelection();if(!m||m.rangeCount===0||!i.contains(m.anchorNode))return;let g=v(),w=e.store.get().editingParam?.id??null;if(g&&g!==w){e.startEditingParam(g);return}performance.now()-h<50||e.handleCaretMove(H(i))},{signal:u}),i.addEventListener("compositionstart",()=>{c=!0},{signal:u}),i.addEventListener("compositionend",()=>{c=!1,b()},{signal:u}),i.addEventListener("beforeinput",m=>{let g=m,w=g.inputType;if(w==="insertParagraph"||w==="insertLineBreak"||w==="insertFromDrop"){m.preventDefault();return}if(w.startsWith("insert")||w.startsWith("delete")){let A=w.startsWith("delete")?"":g.data??"";e.replaceEditingRange(A)&&m.preventDefault()}},{signal:u}),i.addEventListener("paste",m=>{m.preventDefault();let g=(m.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!g)return;let w=i.ownerDocument??document,A=w.getSelection();if(!A||A.rangeCount===0)return;let k=A.getRangeAt(0);if(!i.contains(k.startContainer))return;k.deleteContents();let $=w.createTextNode(g);k.insertNode($),k.setStartAfter($),k.collapse(!0),A.removeAllRanges(),A.addRange(k),b()},{signal:u}),i.addEventListener("keydown",m=>e.handleKeyDown(m),{signal:u}),i.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:u}),i.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:u}),l&&l.addEventListener("click",m=>{let g=e.store.get();if(!(!!g.text||g.completedParams.length>0)||!e.onSubmit)return;m.stopPropagation();let{rawQuery:A,completedParams:k}=N(g.text,g.completedParams);e.onSubmit({query:g.text.trim(),raw_query:A,completed_params:k}),e.afterSubmit?.()},{signal:u}),e.autoFocus!==!1&&i.focus(),{input:i,inlinePillContainer:s,dropdown:o,submitButton:d,abort:p}}function mt(n,e,t){let{input:o,inlinePillContainer:r,dropdown:a,submitButton:i}=n,{pillPlacement:s,setActivePill:d,selectOption:l,store:p}=t;o.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(u?o.setAttribute("aria-activedescendant",u):o.removeAttribute("aria-activedescendant"),i){let f=!!e.text||e.completedParams.length>0;i.disabled=!f}let c=o.dataset.newParamId??"",h=e.newParamId!==null&&e.newParamId!==c;if(Be({input:o,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),s==="inline"){let f=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;f||e.actionableSuggestions.length>0?Qe(r,e.actionableSuggestions,0,d,!1,f):pt(r)}else pt(r);h?(o.focus(),L(o,e.caretOffset??e.text.length)):e.isFocused&&re(o)!==e.text&&L(o,e.text.length);let b=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,v=b??e.actionableSuggestions[0];Ve(a,{suggestions:v?[{...v,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:b?[b]:e.actionableSuggestions,showPills:s==="dropdown",onSelect:l,onHighlight:f=>p.set({activeDropdownIndex:f}),onPillClick:d})}function zt(n){let e=n,t=new Set;return{get:()=>e,set:o=>{let r=typeof o=="function"?o(e):o,a={...e,...r},i=e;e=a;for(let s of t)s(a,i)},subscribe:o=>(t.add(o),()=>{t.delete(o)})}}var gt=!1;function Wt(){if(gt||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){gt=!0;return}gt=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=An,document.head.appendChild(n)}var An="";var Cn=0;function Tn(){return`:ac-${++Cn}:`}var $t=500;function qt(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1}}var Xe=class{constructor(e,t={}){this.store=zt(qt());this._listboxId=Tn();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.sessionId=crypto.randomUUID();this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new Ge(this.store,{onPillSelected:({rawQuery:o,selectedPill:r,otherPills:a})=>{this.fireTelemetry("pill",{raw_query:o,selected_pill:r,other_pills:a})}}),this.fetchController=new qe(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError,()=>this.sessionId,{onAutoMatch:({active:o,matched:r,rawQuery:a})=>{this.fireTelemetry("option",{raw_query:a,selected_option:r.text,other_options:(o.options??[]).filter(i=>i.text!==r.text).map(i=>i.text)})}}),this.keyboardController=new Ue(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:o=>this.selectOption(o),removeParamAtCaret:o=>this.removeParamAtCaret(o),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((o,r)=>{this.recomputeDerived(o,r)})),this.unsubscribers.push(this.store.subscribe((o,r)=>{o.text!==r.text&&this.opts.onChange?.(o.text),o.completedParams!==r.completedParams&&this.opts.onParamsChange?.(o.completedParams),o.isFocused!==r.isFocused&&(o.isFocused?this.opts.onFocus?.():this.opts.onBlur?.()),this.opts.onStateChange?.(o)})),this.renderMode!=="headless"&&(Wt(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){this.store.set({...qt(),skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.selectionAnimationTimer&&clearTimeout(this.selectionAnimationTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:o,completedParams:r}=t,a=0;for(let i=0;i<r.length;i++){let s=r[i],d=o.indexOf(s.text,a);if(d===-1)continue;let l=d,p=d+s.text.length;if(e>l&&e<=p){let u=Ct(o,e),c=o.slice(0,u)+o.slice(e),h=r.filter((b,v)=>v!==i);return this.store.set(b=>({text:c,filterBase:Math.min(b.filterBase,c.length),completedParams:h,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(u),!0}a=p}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?L(t.input,e):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){let t=this.store.get();if(t.editingParam?.id===e)return;let o=t.completedParams.find(i=>i.id===e);if(!o)return;let r=0,a=-1;for(let i of t.completedParams){let s=t.text.indexOf(i.text,r);if(s!==-1){if(i.id===e){a=s;break}r=s+i.text.length}}a<0||this.store.set({editingParam:o,editingAnchor:a,editingTail:a+o.text.length,caretOffset:a+o.text.length,activeDropdownIndex:-1})}replaceEditingRange(e){let t=this.store.get(),o=t.editingParam,r=t.editingAnchor,a=t.editingTail;if(!o||r==null||a==null||!t.completedParams.some(d=>d.id===o.id))return!1;let i=t.text.slice(0,r)+e+t.text.slice(a),s=r+e.length;return this.store.set(d=>({text:i,completedParams:d.completedParams.filter(l=>l.id!==o.id),editingTail:s,caretOffset:s,activeDropdownIndex:-1})),this.scheduleSetCursor(s),this.maybePromoteEditExactMatch(),!0}exitEditMode(){this.store.get().editingParam&&this.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}handleCaretAfterInput(e){let t=this.store.get(),o={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(o.editingParam=null,o.editingAnchor=null,o.editingTail=null,o.activeDropdownIndex=-1):t.editingTail!=null&&(o.editingTail=Math.max(t.editingTail,e))),this.store.set(o),this.maybePromoteEditExactMatch()}handleCaretMove(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.store.set({caretOffset:e})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};case"focus":return this.opts.onFocus=t,()=>{this.opts.onFocus=void 0};case"blur":return this.opts.onBlur=t,()=>{this.opts.onBlur=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),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)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.selectOptionInEditMode(e);return}let o=t.actionableSuggestions[0];if(!o)return;let{rawQuery:r}=N(t.text,t.completedParams);this.fireTelemetry("option",{raw_query:r,selected_option:e.text,other_options:t.filteredOptions.filter(m=>m.text!==e.text).map(m=>m.text)});let a=t.filterBase,i=t.text.slice(0,a),s=i.length===0&&t.text.length===0,d=i.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(s||d)&&t.placeholderText&&(i=`${t.placeholderText} `);let l=Tt(i,e.text);l>0&&(i=i.slice(0,i.length-l));let p=i.length>0&&i[i.length-1]!==" ",u=`${i}${p?" ":""}${e.text} `,c=(s||d)&&u.length>0?u[0].toUpperCase()+u.slice(1):u,h=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),b=h>=0?c.slice(h,h+e.text.length):e.text,v={id:crypto.randomUUID(),placeholder:"",type:o.type,text:b,kind:e.kind,suggestionType:o.type,suggestionPlaceholder:o.text,options:o.options??[],metadata:e.metadata},f=t.actionableSuggestions.length-1;this.store.set(m=>({text:c,filterBase:c.length,completedParams:[...m.completedParams,v],newParamId:v.id,caretOffset:c.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:f>0,inSelectionAnimation:!0})),this.startSelectionAnimationTimer(),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),f>0&&(this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(m=>({suggestions:m.suggestions.filter(g=>g!==o)}))},$t))}startSelectionAnimationTimer(){this.selectionAnimationTimer&&clearTimeout(this.selectionAnimationTimer),this.selectionAnimationTimer=window.setTimeout(()=>{this.store.set({inSelectionAnimation:!1})},$t)}selectOptionInEditMode(e){let t=this.store.get(),o=t.editingParam,r=t.editingAnchor,a=t.editingTail;if(!o||r==null||a==null)return;this.fireTelemetry("option",{raw_query:N(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:o.options.filter(m=>m.text!==e.text).map(m=>m.text)});let i=t.text.slice(0,r),s=t.text.slice(a),d=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=s.length===0||s[0]!==" ",p=l?`${d} `:d,u=i+p+s,c=r+p.length+(l?0:1),h={id:crypto.randomUUID(),placeholder:"",type:o.suggestionType,text:d,kind:e.kind,suggestionType:o.suggestionType,suggestionPlaceholder:o.suggestionPlaceholder,options:o.options,metadata:e.metadata},b=t.completedParams.findIndex(m=>m.id===o.id),v=t.completedParams.filter(m=>m.id!==o.id),f=b>=0?Math.min(b,v.length):v.length;v.splice(f,0,h),this.store.set({text:u,completedParams:v,newParamId:h.id,filterBase:c,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:c,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.startSelectionAnimationTimer(),this.scheduleSetCursor(c)}fireTelemetry(e,t){let o=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");Ot({source:o,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let o=_t(e.text,e.completedParams),r=e.suggestions.filter(g=>g.type!=="placeholder"),a=r[0],i=a?this.opts.optionOverrides?.[a.type]:void 0,s=e.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),d=he(e.text,Math.min(e.filterBase,e.text.length),s),p=e.lastRawQuery!==""||d>0?ae(e.text,d,e.filterInProgress):"",u=a?i?i(p.trim()):a.options??[]:[],c=e.editingParam!=null&&e.editingAnchor!=null,h;if(c&&e.editingParam&&e.editingAnchor!=null){let g=e.editingParam.id,w=e.completedParams.some($=>$.id===g),A=e.caretOffset??e.editingAnchor,k=w?"":e.text.slice(e.editingAnchor,A);h=be(e.editingParam.options,k)}else h=be(u,p);let b=this.opts.dropdownTrigger??"auto",v=this.opts.closeDropdownOnBlur??!0,f=!1;if(c){let g=v?e.isFocused:!0;f=h.length>0&&g}else if(b==="auto"){let g=v?e.isFocused:!0,w=e.text.replace(/\s+$/,"").length,A=e.caretOffset==null||e.caretOffset>=w;f=(h.length>0||e.isLoading)&&g&&A}else b==="manual"&&(f=(h.length>0||e.isLoading)&&e.pillTapped);this.store.set({segments:o,actionableSuggestions:r,filteredOptions:h,placeholderText:s,isDropdownOpen:f}),this.derivedInProgress=!1;let m=this.store.get();for(let g of this.externalListeners)g(m)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new le(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:o=>this.selectOption(o),setActivePill:o=>this.pillsController.setActivePill(o),handleKeyDown:o=>this.keyboardController.handleKeyDown(o),handleChange:o=>this.handleChange(o),startEditingParam:o=>this.startEditingParam(o),handleCaretAfterInput:o=>this.handleCaretAfterInput(o),handleCaretMove:o=>this.handleCaretMove(o),replaceEditingRange:o=>this.replaceEditingRange(o)};this.domRefs=Kt(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&mt(this.domRefs,this.store.get(),t)}),mt(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Ft(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&ut(this.dropdownRefs,this.store.get(),e)}),ut(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:o,invalid:r}=Et(e,t.completedParams);r.length>0&&this.store.set({completedParams:o}),this.maybePromoteExactMatch(e)}maybePromoteExactMatch(e){let t=this.store.get(),r=t.suggestions.filter(g=>g.type!=="placeholder")[0];if(!r?.options)return;let a=t.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),i=he(e,t.filterBase,a),s=ae(e,i,t.filterInProgress),d=se(r.options,s);if(!d)return;let l=d.text.toLowerCase(),p=e.toLowerCase().lastIndexOf(l),u=p>=0?p:Math.max(0,e.length-d.text.length),c=u+d.text.length,h=e.slice(u,c),b=e,f=c<e.length&&e[c]===" "?c+1:c,m={id:crypto.randomUUID(),placeholder:"",type:r.type,text:h,kind:d.kind,suggestionType:r.type,suggestionPlaceholder:r.text,options:r.options??[],metadata:d.metadata};this.store.set(g=>({text:b,completedParams:[...g.completedParams,m],suggestions:g.suggestions.filter(w=>w!==r),filterBase:f,newParamId:m.id,caretOffset:f,activeDropdownIndex:-1}))}maybePromoteEditExactMatch(){let e=this.store.get(),t=e.editingParam,o=e.editingAnchor,r=e.editingTail;if(!t||o==null||r==null||e.completedParams.some(w=>w.id===t.id))return;let a=e.text.slice(o,r),i=se(t.options,a);if(!i)return;let s=i.text.toLowerCase(),d=a.toLowerCase().lastIndexOf(s),l=o+Math.max(0,d),p=l+i.text.length,u=e.text.slice(l,p),c=e.text,b=p<e.text.length&&e.text[p]===" "?p+1:p,v={id:crypto.randomUUID(),placeholder:"",type:t.suggestionType,text:u,kind:i.kind,suggestionType:t.suggestionType,suggestionPlaceholder:t.suggestionPlaceholder,options:t.options,metadata:i.metadata},f=e.completedParams.length,m=0;for(let w=0;w<e.completedParams.length;w++){let A=c.indexOf(e.completedParams[w].text,m);if(A!==-1){if(A>=b){f=w;break}m=A+e.completedParams[w].text.length}}let g=[...e.completedParams];g.splice(f,0,v),this.store.set(()=>({text:c,completedParams:g,newParamId:v.id,filterBase:b,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:b,activeDropdownIndex:-1})),this.scheduleSetCursor(b)}};function ft({onSubmit:n,onError:e,optionOverrides:t,maskCompletedText:o,apiConfig:r,columns:a=2,dropdownTrigger:i,closeDropdownOnBlur:s,onFocus:d,onBlur:l,value:p,completedParams:u,onChange:c,onParamsChange:h,source:b,setCursor:v}){let f=W(null),[m,g]=_n(null),w=W(n);w.current=n;let A=W(e);A.current=e;let k=W(c);k.current=c;let $=W(h);$.current=h;let de=W(d);de.current=d;let _=W(l);_.current=l;let ce=W(v);ce.current=v,Je(()=>{if(typeof document>"u")return;let S=new Xe(document.createElement("div"),{renderMode:"headless",apiConfig:r,optionOverrides:t,maskCompletedText:o,columns:a,dropdownTrigger:i,closeDropdownOnBlur:s,source:b,value:p,completedParams:u,onSubmit:(...O)=>w.current?.(...O),onError:(...O)=>A.current?.(...O),onChange:(...O)=>k.current?.(...O),onParamsChange:(...O)=>$.current?.(...O),onFocus:()=>de.current?.(),onBlur:()=>_.current?.(),setCursor:O=>ce.current?.(O)});f.current=S,g(S.getState());let M=S.subscribe(O=>g(O));return()=>{M(),S.destroy(),f.current===S&&(f.current=null)}},[]);let x=f.current,C=E(()=>{},[]);Je(()=>{p!==void 0&&x?.setValue(p)},[p,x]),Je(()=>{u!==void 0&&x?.setCompletedParams(u)},[u,x]);let ye=JSON.stringify(r??null),te=W(t),pe=W(0);if(t!==te.current){let S=te.current,M=t,O=Object.keys(S??{}),q=Object.keys(M??{});(O.length!==q.length||q.some(Y=>!S?.[Y]||M[Y]!==S[Y]))&&pe.current++,te.current=t}Je(()=>{x?.update({apiConfig:r,optionOverrides:t,dropdownTrigger:i,closeDropdownOnBlur:s})},[ye,pe.current,i,s,x]);let we=E(S=>{if(!x)return;let M=S.target.value,q=M.length>0&&!S.nativeEvent?.isComposing&&M[0]!==M[0].toUpperCase()?M[0].toUpperCase()+M.slice(1):M;x.handleTextChange(q)},[x]),Ze=E(S=>{x?.handleKeyDown(S.nativeEvent)},[x]),ue=E(()=>x?.setFocused(!0),[x]),Se=E(()=>x?.setFocused(!1),[x]),et=E(S=>x?.handleTextChange(S),[x]),me=E(S=>{if(!x)return;let M="nativeEvent"in S?S.nativeEvent:S;x.handleKeyDown(M)},[x]),j=E(S=>x?.setFocused(S),[x]),Pe=E(S=>x?.startEditingParam(S),[x]),Ie=E(()=>x?.exitEditMode(),[x]),Ae=E(S=>x?.handleCaretAfterInput(S),[x]),tt=E(S=>x?.handleCaretMove(S),[x]),Ce=E(S=>x?.replaceEditingRange(S)??!1,[x]),ge=E(S=>x?.setActivePill(S),[x]),Te=E(()=>x?.removeLastParam(),[x]),_e=E(()=>x?.clearNewParamId(),[x]),Ee=E(()=>x?.reset(),[x]),ne=E(S=>x?.selectOption(S),[x]),V=E(S=>x?.setActiveDropdownIndex(S),[x]);if(!x)return{completedParams:u??[],suggestionPills:[],setActivePill:C,removeLastParam:C,segments:[],newParamId:null,clearNewParamId:C,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,isFocused:!1,isDropdownOpen:!1,placeholderText:"",listboxId:"",error:null,handleTextChange:C,handleKeyDown:C,setFocused:C,editingParam:null,editingAnchor:null,caretOffset:null,startEditingParam:C,exitEditMode:C,handleCaretAfterInput:C,handleCaretMove:C,replaceEditingRange:()=>!1,inputProps:{value:p??"",placeholder:void 0,onChange:C,onKeyDown:C,onFocus:C,onBlur:C,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:C,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:C,onHighlight:C,isOpen:!1,id:"",pills:[],onPillClick:C}};let P=m??x.getState(),nt=p!==void 0?p:P.text,ke=u!==void 0?u:P.completedParams,oe=P.actionableSuggestions,Oe=oe[0],De=P.filteredOptions,ot=P.activeDropdownIndex>=0?`${x.listboxId}-option-${P.activeDropdownIndex}`:void 0,B=P.editingParam,F=B?{type:B.suggestionType,text:B.suggestionPlaceholder,required:!0,options:B.options}:null,Le=F??Oe,it=F?[F]:oe;return{completedParams:ke,suggestionPills:oe,setActivePill:ge,removeLastParam:Te,segments:P.segments,newParamId:P.newParamId,clearNewParamId:_e,suggestions:P.suggestions,activeIndex:P.activeDropdownIndex,isReady:P.isReady,isLoading:P.isLoading&&!P.editingParam&&!P.inSelectionAnimation,isFocused:P.isFocused,isDropdownOpen:P.isDropdownOpen,placeholderText:P.placeholderText,listboxId:x.listboxId,error:P.error,handleTextChange:et,handleKeyDown:me,setFocused:j,editingParam:B,editingAnchor:P.editingAnchor,caretOffset:P.caretOffset,startEditingParam:Pe,exitEditMode:Ie,handleCaretAfterInput:Ae,handleCaretMove:tt,replaceEditingRange:Ce,inputProps:{value:nt,placeholder:P.placeholderText||void 0,onChange:we,onKeyDown:Ze,onFocus:ue,onBlur:Se,role:"combobox","aria-expanded":P.isDropdownOpen,"aria-activedescendant":ot,"aria-autocomplete":"list","aria-controls":x.listboxId},reset:Ee,dropdownProps:{suggestions:Le?[{...Le,options:De}]:[],activeIndex:P.activeDropdownIndex,onSelect:ne,onHighlight:V,isOpen:P.isDropdownOpen,id:x.listboxId,pills:it,onPillClick:ge,isLoading:P.isLoading&&!P.editingParam&&!P.inSelectionAnimation}}}import{jsx as J,jsxs as bt}from"react/jsx-runtime";function On(n){return n!=="auto"?n:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var Ye;function Dn(){if(Ye!==void 0)return Ye;if(typeof document>"u")return!1;let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),Ye=n.contentEditable==="plaintext-only",Ye}var Ln=En(function({onSubmit:e,onError:t,optionOverrides:o,maskCompletedText:r,className:a,apiConfig:i,columns:s,pillPlacement:d="inline",mode:l="auto",optionsPosition:p="below",animations:u=!0,dropdownTrigger:c,closeDropdownOnBlur:h,autoFocus:b=!0,onFocus:v,onBlur:f,value:m,completedParams:g,onChange:w,onParamsChange:A,submitButton:k},$){let de=Q(null),_=Q(null),ce=Q(()=>{}),x=Q(null),C=Q(!1),ye=Q(""),te=Q(""),pe=Q(null),we=Q(0);ve(()=>{let y=de.current;if(y)return x.current?x.current.setMode(l):x.current=new le(y,l),()=>{x.current?.destroy(),x.current=null}},[l]);let Ze=G(y=>{let I=_.current;I&&L(I,y)},[]),{completedParams:ue,suggestionPills:Se,setActivePill:et,segments:me,newParamId:j,clearNewParamId:Pe,placeholderText:Ie,isFocused:Ae,isDropdownOpen:tt,isLoading:Ce,activeIndex:ge,listboxId:Te,handleTextChange:_e,handleKeyDown:Ee,setFocused:ne,editingParam:V,editingAnchor:P,caretOffset:nt,startEditingParam:ke,handleCaretAfterInput:oe,handleCaretMove:Oe,replaceEditingRange:De,dropdownProps:ot,reset:B}=ft({onSubmit:y=>ce.current(y),onError:t,optionOverrides:o,maskCompletedText:r,apiConfig:i,columns:s,dropdownTrigger:c,closeDropdownOnBlur:h,onFocus:v,onBlur:f,value:m,completedParams:g,onChange:w,onParamsChange:A,source:"full-sdk",setCursor:Ze});pe.current=nt,ve(()=>{if(!b)return;let y=_.current;y&&(document.activeElement===y?ne(!0):y.focus())},[b,ne]),ve(()=>{if(!j)return;let y=window.setTimeout(()=>Pe(),650);return()=>window.clearTimeout(y)},[j,Pe]),ve(()=>{let y=_.current;if(!y)return;let I=y.ownerDocument??document,T=()=>{let R=I.getSelection();if(!R||R.rangeCount===0||!R.anchorNode||!y.contains(R.anchorNode))return;let D=R.anchorNode,at=(D.nodeType===Node.ELEMENT_NODE?D:D.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if(at&&at!==V?.id){ke(at);return}performance.now()-we.current<50||Oe(H(y))};return I.addEventListener("selectionchange",T),()=>I.removeEventListener("selectionchange",T)},[V,ke,Oe]),ht(()=>{let y=_.current;y&&Be({input:y,segments:me,newParamId:j,editingParamId:V?.id??null,placeholderText:Ie??"",isFocused:Ae})},[me,j,V,Ie,Ae]),ht(()=>{let y=ye.current,I=j??"";if(ye.current=I,!I||I===y)return;let T=_.current;if(!T)return;T.focus();let R=pe.current??He(T);L(T,R)},[j]),ht(()=>{let y=te.current,I=V?.id??"";if(te.current=I,!I||I===y||P==null)return;let T=_.current;T&&L(T,P)},[V,P]),kn($,()=>({focus:()=>_.current?.focus(),blur:()=>_.current?.blur(),reset:B,setMode:y=>x.current?.setMode(y)}),[B]);let F=G(()=>{if(C.current)return;let y=_.current;if(!y)return;let I=re(y),R=I.length>0&&I[0]!==I[0].toUpperCase()?I[0].toUpperCase()+I.slice(1):I;_e(R)},[_e]),Le=G(()=>{we.current=performance.now(),F();let y=_.current;y&&oe(H(y))},[F,oe]);ve(()=>{let y=_.current;if(!y)return;let I=T=>{let R=T,D=R.inputType;if(D==="insertParagraph"||D==="insertLineBreak"||D==="insertFromDrop"){T.preventDefault();return}if(D.startsWith("insert")||D.startsWith("delete")){let U=D.startsWith("delete")?"":R.data??"";De(U)&&T.preventDefault()}};return y.addEventListener("beforeinput",I),()=>y.removeEventListener("beforeinput",I)},[De]);let it=G(()=>{C.current=!0},[]),S=G(()=>{C.current=!1,F()},[F]),M=G(y=>{y.preventDefault();let I=_.current;if(!I)return;let T=(y.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!T)return;let R=I.ownerDocument??document,D=R.getSelection();if(!D||D.rangeCount===0)return;let U=D.getRangeAt(0);if(!I.contains(U.startContainer))return;U.deleteContents();let rt=R.createTextNode(T);U.insertNode(rt),U.setStartAfter(rt),U.collapse(!0),D.removeAllRanges(),D.addRange(U),F()},[F]),O=G(y=>Ee(y),[Ee]),q=!!me.length||ue.length>0,Y=G(()=>{if(!q)return;let y=_.current?re(_.current):"",{rawQuery:I,completedParams:T}=N(y,ue);e({query:y.trim(),raw_query:I,completed_params:T}),B()},[q,ue,e,B]);ce.current=Y;let Ut=G(y=>{y.target?.closest("[data-aia-pill]")||_.current?.focus()},[]),Gt=d==="inline",Qt=d==="dropdown",jt=ge>=0?`${Te}-option-${ge}`:void 0,Vt=Dn()?"plaintext-only":"true";return bt("div",{ref:de,className:`magicx-aia ${X.container} ${a??""}`,"data-pill-placement":d,"data-options-position":p,"data-animations":u?"on":"off","data-mode":On(l),children:[J(ct,{...ot,showPills:Qt}),bt("div",{className:X.inputWrapper,onClick:Ut,children:[bt("div",{className:X.editorArea,"data-aia-editor":"",children:[J("div",{ref:_,className:X.input,"data-aia-input":"",contentEditable:Vt,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":Te,"aria-expanded":tt,"aria-activedescendant":jt,spellCheck:!0,enterKeyHint:"send",onInput:Le,onKeyDown:O,onCompositionStart:it,onCompositionEnd:S,onPaste:M,onFocus:()=>ne(!0),onBlur:()=>ne(!1)}),Gt&&(Ce||Se.length>0)&&J("span",{className:X.pillListContainer,"data-aia-pill-list-container":"",children:J(fe,{pills:Se,activePillIndex:0,onSelectPill:et,loading:Ce})})]}),k===null?null:k===void 0?J("button",{type:"button","data-aia-submit":"",className:X.submitButton,disabled:!q,onClick:y=>{y.stopPropagation(),Y()},"aria-label":"Submit",children:J("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:J("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):J("span",{"data-aia-submit":"",className:X.submitSlot,onClick:y=>{q&&(y.stopPropagation(),Y())},children:k})]})]})});export{Ln as AIAutocomplete,ct as AIAutocompleteDropdown,ft as useAIAutocomplete};
790
802
  //# sourceMappingURL=index.mjs.map