@magicx-eng/ai-autocomplete-react 0.1.9 → 0.1.11

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.d.mts CHANGED
@@ -21,7 +21,7 @@ interface Suggestion {
21
21
  type: string;
22
22
  text: string;
23
23
  required: boolean;
24
- options: SuggestionOption[];
24
+ options?: SuggestionOption[];
25
25
  }
26
26
  interface CompletedParamState extends CompletedParam {
27
27
  id: string;
@@ -47,6 +47,7 @@ interface APIConfig {
47
47
  endpoint?: string;
48
48
  apiKey?: string;
49
49
  authScheme?: "Bearer" | "Basic";
50
+ appIdentifier?: string;
50
51
  headers?: Record<string, string>;
51
52
  }
52
53
  type OptionOverrides = Record<string, (query: string) => SuggestionOption[]>;
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ interface Suggestion {
21
21
  type: string;
22
22
  text: string;
23
23
  required: boolean;
24
- options: SuggestionOption[];
24
+ options?: SuggestionOption[];
25
25
  }
26
26
  interface CompletedParamState extends CompletedParam {
27
27
  id: string;
@@ -47,6 +47,7 @@ interface APIConfig {
47
47
  endpoint?: string;
48
48
  apiKey?: string;
49
49
  authScheme?: "Bearer" | "Basic";
50
+ appIdentifier?: string;
50
51
  headers?: Record<string, string>;
51
52
  }
52
53
  type OptionOverrides = Record<string, (query: string) => SuggestionOption[]>;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ye=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var ot=(e,o)=>{for(var t in o)ye(e,t,{get:o[t],enumerable:!0})},nt=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of et(o))!tt.call(e,n)&&n!==t&&ye(e,n,{get:()=>o[n],enumerable:!(r=Je(o,n))||r.enumerable});return e};var rt=e=>nt(ye({},"__esModule",{value:!0}),e);var bt={};ot(bt,{AIAutocomplete:()=>$e,AIAutocompleteDropdown:()=>re,useAIAutocomplete:()=>le});module.exports=rt(bt);var K=require("react");if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.AIAutocomplete-module_container_KKjFU {
1
+ "use strict";var ye=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(e,r)=>{for(var t in r)ye(e,t,{get:r[t],enumerable:!0})},ot=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Je(r))!et.call(e,n)&&n!==t&&ye(e,n,{get:()=>r[n],enumerable:!(o=Ze(r,n))||o.enumerable});return e};var nt=e=>ot(ye({},"__esModule",{value:!0}),e);var dt={};tt(dt,{AIAutocomplete:()=>Ne,AIAutocompleteDropdown:()=>re,useAIAutocomplete:()=>le});module.exports=nt(dt);var j=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-AIAutocomplete")){let e=document.createElement("style");e.id="ac-style-AIAutocomplete",e.textContent=`.AIAutocomplete-module_container_KKjFU {
2
2
  position: relative;
3
3
  font-family: "IBM Plex Sans", sans-serif;
4
4
  }
@@ -135,7 +135,7 @@
135
135
  .AIAutocomplete-module_submitButton_sl1Mi:hover {
136
136
  opacity: 0.85;
137
137
  }
138
- `,document.head.appendChild(e)}var z={container:"AIAutocomplete-module_container_KKjFU",checkmark:"AIAutocomplete-module_checkmark_CVE0Z",checkmarkVisible:"AIAutocomplete-module_checkmarkVisible_DWYbI",checkmarkFadeInOut:"AIAutocomplete-module_checkmarkFadeInOut_U1Oof",checkmarkPath:"AIAutocomplete-module_checkmarkPath_BJRUs",drawCheck:"AIAutocomplete-module_drawCheck_je-B3",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",sizerContent:"AIAutocomplete-module_sizerContent_DQgmV",sizerText:"AIAutocomplete-module_sizerText_iZIMK",placeholderText:"AIAutocomplete-module_placeholderText_K3ayy",textarea:"AIAutocomplete-module_textarea_eyn6A",submitButton:"AIAutocomplete-module_submitButton_sl1Mi"};if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
138
+ `,document.head.appendChild(e)}var K={container:"AIAutocomplete-module_container_KKjFU",checkmark:"AIAutocomplete-module_checkmark_CVE0Z",checkmarkVisible:"AIAutocomplete-module_checkmarkVisible_DWYbI",checkmarkFadeInOut:"AIAutocomplete-module_checkmarkFadeInOut_U1Oof",checkmarkPath:"AIAutocomplete-module_checkmarkPath_BJRUs",drawCheck:"AIAutocomplete-module_drawCheck_je-B3",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",sizerContent:"AIAutocomplete-module_sizerContent_DQgmV",sizerText:"AIAutocomplete-module_sizerText_iZIMK",placeholderText:"AIAutocomplete-module_placeholderText_K3ayy",textarea:"AIAutocomplete-module_textarea_eyn6A",submitButton:"AIAutocomplete-module_submitButton_sl1Mi"};if(typeof document<"u"&&!document.getElementById("ac-style-AIAutocompleteDropdown")){let e=document.createElement("style");e.id="ac-style-AIAutocompleteDropdown",e.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
139
139
  position: absolute;
140
140
  left: 0;
141
141
  right: 0;
@@ -154,7 +154,7 @@
154
154
  opacity: 1;
155
155
  pointer-events: auto;
156
156
  }
157
- `,document.head.appendChild(e)}var Ae={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj"};if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.SuggestionGrid-module_grid_jvaPb {
157
+ `,document.head.appendChild(e)}var Ae={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj"};if(typeof document<"u"&&!document.getElementById("ac-style-SuggestionGrid")){let e=document.createElement("style");e.id="ac-style-SuggestionGrid",e.textContent=`.SuggestionGrid-module_grid_jvaPb {
158
158
  display: grid;
159
159
  grid-template-columns: 1fr 1fr;
160
160
  gap: 12px 18px;
@@ -177,7 +177,7 @@
177
177
  background: rgba(255, 255, 255, 0.3);
178
178
  border-radius: 3px;
179
179
  }
180
- `,document.head.appendChild(e)}var Re={grid:"SuggestionGrid-module_grid_jvaPb"};if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.SuggestionItem-module_item_d4vpD {
180
+ `,document.head.appendChild(e)}var Re={grid:"SuggestionGrid-module_grid_jvaPb"};if(typeof document<"u"&&!document.getElementById("ac-style-SuggestionItem")){let e=document.createElement("style");e.id="ac-style-SuggestionItem",e.textContent=`.SuggestionItem-module_item_d4vpD {
181
181
  display: flex;
182
182
  align-items: center;
183
183
  font-family: "IBM Plex Sans", sans-serif;
@@ -218,7 +218,7 @@
218
218
  margin-left: 6px;
219
219
  opacity: 0.5;
220
220
  }
221
- `,document.head.appendChild(e)}var Y={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe"};var ne=require("react/jsx-runtime");function Te({option:e,isHighlighted:o,onSelect:t,onHighlight:r,id:n}){let i=[Y.item,o?Y.highlighted:"",e.is_tappable?Y.tappable:Y.nonTappable].filter(Boolean).join(" ");return(0,ne.jsxs)("div",{id:n,role:"option","aria-selected":o,className:i,tabIndex:e.is_tappable?0:-1,onClick:()=>e.is_tappable&&t(e),onKeyDown:s=>{e.is_tappable&&(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),t(e))},onMouseEnter:r,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,ne.jsx)("span",{className:Y.tag,children:e.tag})]})}var _e=require("react/jsx-runtime");function Ee({options:e,activeIndex:o,onSelect:t,onHighlight:r,listboxId:n}){return(0,_e.jsx)("div",{className:Re.grid,children:e.map((i,s)=>(0,_e.jsx)(Te,{option:i,isHighlighted:s===o,onSelect:t,onHighlight:()=>r(s),id:`${n}-option-${s}`},i.text))})}var Se=require("react/jsx-runtime");function re({suggestions:e,activeIndex:o,onSelect:t,onHighlight:r,isOpen:n,id:i,className:s}){let m=e[0],f=n&&m&&m.options.length>0;return(0,Se.jsx)("div",{id:i,role:"listbox",className:`${Ae.dropdown} ${f?Ae.visible:""} ${s??""}`,onMouseDown:h=>h.preventDefault(),children:m&&m.options.length>0&&(0,Se.jsx)(Ee,{options:m.options,activeIndex:o,onSelect:t,onHighlight:r,listboxId:i})})}if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.PillList-module_list_qvLqO {
221
+ `,document.head.appendChild(e)}var Y={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe"};var ne=require("react/jsx-runtime");function Te({option:e,isHighlighted:r,onSelect:t,onHighlight:o,id:n}){let i=[Y.item,r?Y.highlighted:"",e.is_tappable?Y.tappable:Y.nonTappable].filter(Boolean).join(" ");return(0,ne.jsxs)("div",{id:n,role:"option","aria-selected":r,className:i,tabIndex:e.is_tappable?0:-1,onClick:()=>e.is_tappable&&t(e),onKeyDown:s=>{e.is_tappable&&(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),t(e))},onMouseEnter:o,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,ne.jsx)("span",{className:Y.tag,children:e.tag})]})}var Se=require("react/jsx-runtime");function Ee({options:e,activeIndex:r,onSelect:t,onHighlight:o,listboxId:n}){return(0,Se.jsx)("div",{className:Re.grid,children:e.map((i,s)=>(0,Se.jsx)(Te,{option:i,isHighlighted:s===r,onSelect:t,onHighlight:()=>o(s),id:`${n}-option-${s}`},i.text))})}var _e=require("react/jsx-runtime");function re({suggestions:e,activeIndex:r,onSelect:t,onHighlight:o,isOpen:n,id:i,className:s}){let d=e[0]?.options??[],f=n&&d.length>0;return(0,_e.jsx)("div",{id:i,role:"listbox",className:`${Ae.dropdown} ${f?Ae.visible:""} ${s??""}`,onMouseDown:l=>l.preventDefault(),children:d.length>0&&(0,_e.jsx)(Ee,{options:d,activeIndex:r,onSelect:t,onHighlight:o,listboxId:i})})}if(typeof document<"u"&&!document.getElementById("ac-style-PillList")){let e=document.createElement("style");e.id="ac-style-PillList",e.textContent=`.PillList-module_list_qvLqO {
222
222
  position: relative;
223
223
  z-index: 1;
224
224
  pointer-events: auto;
@@ -260,5 +260,5 @@
260
260
  opacity: 0;
261
261
  }
262
262
  }
263
- `,document.head.appendChild(e)}var ie={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",active:"PillList-module_active_Oll--"};var xe=require("react/jsx-runtime");function it(e){return e===0?.4:e===1?.3:.15}function Me({pills:e,activePillIndex:o,onSelectPill:t}){return(0,xe.jsx)("span",{className:ie.list,children:e.map((r,n)=>(0,xe.jsx)("button",{type:"button",className:`${ie.pill} ${n===o?ie.active:""}`,style:{opacity:it(n)},onClick:()=>t(n),children:r.text},`${r.type}-${r.text}`))})}var p=require("react");function ae(e,o){let t=o.trimStart();if(!t)return e;let r=t.toLowerCase();return e.filter(n=>!n.is_tappable||n.text.toLowerCase().includes(r))}function J(e,o){let t=o.trim();if(!t)return null;let r=t.toLowerCase();return e.find(n=>n.is_tappable&&n.text.toLowerCase()===r)??null}function Le(e,o){let t=[],r=0;for(let i of o){let s=e.indexOf(i.text,r);s!==-1&&(s>r&&t.push({type:"text",value:e.slice(r,s)}),t.push({type:"completed",value:i.text,param:i}),r=s+i.text.length)}let n=e.slice(r);return n&&t.push({type:"text",value:n}),t}function Ue(e,o){let t=[],r=[],n=0;for(let i of o){let s=e.indexOf(i.text,n);s===-1?r.push(i):(t.push(i),n=s+i.text.length)}return{valid:t,invalid:r}}var E=require("react");var at="0.1.9",st="/ac/suggest",De=!1;function lt(e){let o=e?.apiKey||""||"";return!o&&!De&&(De=!0,console.warn("[AIAutocomplete] No API key set (MAGICX_AI_AUTOCOMPLETE_API_KEY). Requests will be sent without an Authorization header.")),o}function ct(e){return e?.authScheme?e.authScheme:""==="Basic"?"Basic":"Bearer"}function ut(){return crypto.randomUUID()}function pt(e,o){return{placeholder:e.placeholder,type:e.type,...o&&{text:e.text},kind:e.kind}}async function Ke(e,o,t){let r=t?.apiConfig,n=lt(r),i=ct(r),s=!t?.maskCompletedText,m=o.find(l=>l.type==="contact"&&l.metadata?.contact_account_count)?.metadata?.contact_account_count,f=typeof m=="number"?m:void 0,h={data:{raw_query:e,completed_params:o.map(l=>pt(l,s)),...f!=null&&{contact_account_count:f}},meta:{request_id:ut(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:at}},d={"Content-Type":"application/json","X-App-Identifier":"active-campaign-demo",...r?.headers};n&&(d.Authorization=i==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`);let b=await fetch(r?.endpoint||st,{method:"POST",headers:d,body:JSON.stringify(h),signal:t?.signal});if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}function Z(e,o){let t=e,r={},n=[];for(let i of o){let s=(r[i.type]??0)+1;r[i.type]=s;let f=`{{${i.type.toUpperCase().replace(/\s+/g,"_")}_${s}}}`,h=t.indexOf(i.text);h!==-1&&(t=t.slice(0,h)+f+t.slice(h+i.text.length)),n.push({...i,placeholder:f})}return{rawQuery:t,completedParams:n}}function je(e,o){return o?e.map(t=>{let r=o[t.type];if(!r)return t;let n=r("");if(n.length===0)return t;let i=new Set(n.map(m=>m.text)),s=(t.options??[]).filter(m=>!i.has(m.text));return{...t,options:[...n,...s]}}):e}var mt=100,dt=300,gt=2;function Fe({textRef:e,suggestionsRef:o,filterBaseRef:t,maskCompletedTextRef:r,apiConfigRef:n,optionOverridesRef:i,onErrorRef:s,setCompletedParams:m,setSuggestions:f,setActiveDropdownIndex:h}){let[d,b]=(0,E.useState)(!1),[l,A]=(0,E.useState)(null),[k,y]=(0,E.useState)(!1),v=(0,E.useRef)(0),U=(0,E.useRef)(null),g=(0,E.useRef)(""),c=(0,E.useCallback)(async(a,u)=>{U.current?.abort();let S=new AbortController;U.current=S;let w=++v.current,O=e.current.length;o.current.some(I=>I.type!=="placeholder")||b(!0),A(null);try{let I=await Ke(a,u,{maskCompletedText:r.current,signal:S.signal,apiConfig:n.current});if(w!==v.current)return;let j=je(I.data.suggestions??[],i.current);y(I.data.is_ready??!1),g.current=a;let q=I.data.input??[],M=q[q.length-1],L=e.current;if(M?.state==="in_progress"){let N=L.toLowerCase().lastIndexOf(M.text.toLowerCase());N!==-1?t.current=N:t.current=O}else t.current=O;let F=j.filter(N=>N.type!=="placeholder")[0];if(F){let N=L.slice(t.current),R=J(F.options,N);R&&(m(B=>[...B,{id:crypto.randomUUID(),placeholder:"",type:F.type,text:R.text,kind:R.kind,suggestionType:F.type,suggestionPlaceholder:F.text,options:F.options,metadata:R.metadata}]),j=j.filter(B=>B!==F))}f(j),b(!1),h(-1)}catch(I){if(w===v.current){let j=I instanceof Error?I:new Error(String(I));A(j),b(!1),s.current?.(j)}}},[e,o,t,r,n,i,s,m,f,h]);return(0,E.useEffect)(()=>(c("",[]),()=>{U.current?.abort()}),[c]),{doFetch:c,isLoading:d,error:l,isReady:k,lastRawQueryRef:g}}function ze({text:e,completedParams:o,doFetch:t,filterBaseRef:r,skipNextFetchRef:n,suggestionsRef:i,lastRawQueryRef:s}){let m=(0,E.useRef)(null),f=(0,E.useRef)(null),h=(0,E.useRef)(!0);(0,E.useEffect)(()=>{m.current&&clearTimeout(m.current),f.current&&clearTimeout(f.current);let d=b=>{if(n.current)return n.current=!1,!1;if(!e&&o.length===0)return h.current?(t("",[]),!0):(h.current=!0,!1);let l=e.slice(r.current),y=i.current.filter(O=>O.type!=="placeholder")[0],U=(y?ae(y.options,l):[]).filter(O=>O.is_tappable),g=y?J(y.options,l)!==null:!1,c=l.trim().length>0;if(U.length>0&&!g&&c)return!1;let{rawQuery:a,completedParams:u}=Z(e,o),S=a.length<s.current.length,w=Math.abs(a.length-s.current.length);return S||w>=b?(t(a,u),!0):!1};return m.current=setTimeout(()=>{d(gt)&&f.current&&clearTimeout(f.current)},mt),f.current=setTimeout(()=>d(1),dt),()=>{m.current&&clearTimeout(m.current),f.current&&clearTimeout(f.current)}},[e,o,t,r,n,i,s])}var Pe=require("react");function Ne({activeDropdownIndex:e,setActiveDropdownIndex:o,filteredOptions:t,selectOption:r,onSubmitRef:n,text:i,completedParams:s,isDropdownOpen:m,hasPlaceholder:f,placeholderText:h,suggestions:d,filterBaseRef:b,columns:l,setText:A,setCompletedParams:k,setSuggestions:y}){let v=(0,Pe.useCallback)(()=>{let g=t.map((a,u)=>a.is_tappable?u:-1).filter(a=>a!==-1),c=Array.from({length:l},()=>[]);for(let a of g)c[a%l].push(a);return c.flat()},[t,l]);return{handleKeyDown:(0,Pe.useCallback)(g=>{let c=v();switch(g.key){case"ArrowDown":{if(g.preventDefault(),c.length===0)return;let a=c.indexOf(e),u=a<c.length-1?a+1:0;o(c[u]);break}case"ArrowUp":{if(g.preventDefault(),c.length===0)return;let a=c.indexOf(e),u=a>0?a-1:c.length-1;o(c[u]);break}case"ArrowRight":{if(e<0)break;if(e%l<l-1){let u=e+1;u<t.length&&t[u]?.is_tappable&&(g.preventDefault(),o(u))}break}case"ArrowLeft":{if(e<0)break;if(e%l>0){let a=e-1;a>=0&&t[a]?.is_tappable&&(g.preventDefault(),o(a))}break}case"Enter":{if(g.preventDefault(),e>=0&&t[e]?.is_tappable)r(t[e]);else if(n.current){let{rawQuery:a,completedParams:u}=Z(i,s),S={query:i.trim(),raw_query:a,completed_params:u};n.current(S)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)g.preventDefault(),r(t[e]);else if(m){let a=t.find(u=>u.is_tappable);a&&(g.preventDefault(),r(a))}else if(!i&&f){g.preventDefault();let a=d.find(u=>u.type==="placeholder");a?(A(h),b.current=h.length,k(u=>[...u,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:h,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options}]),y(u=>u.filter(S=>S!==a))):(A(h),b.current=h.length)}break}case"Escape":o(-1);break}},[e,l,s,t,b,v,f,m,n,h,r,o,k,y,A,d,i]),getTappableIndices:v}}var se=require("react");function Be({completedParams:e,suggestions:o,setCompletedParams:t,setSuggestions:r,setActiveDropdownIndex:n,filterBaseRef:i,pillTappedRef:s}){let m=(0,se.useCallback)(d=>{let b=o.filter(y=>y.type!=="placeholder");if(d<0||d>=b.length)return;let l=b[d],A=b.filter((y,v)=>v!==d),k=o.filter(y=>y.type==="placeholder");r([...k,l,...A]),s.current=!0,n(-1)},[o,r,n,s]),f=(0,se.useCallback)(()=>{if(e.length===0)return;let d=e[e.length-1],b={type:d.suggestionType,text:d.suggestionPlaceholder,required:!0,options:d.options};t(l=>l.slice(0,-1)),r(l=>[b,...l]),n(-1)},[e,t,r,n]),h=(0,se.useCallback)(d=>{let b={type:d.suggestionType,text:d.suggestionPlaceholder,required:!0,options:d.options};return{apply:l=>{l(A=>{let k=0;for(let y of e){let v=A.indexOf(y.text,k);if(v!==-1){if(y.id===d.id){let U=A.slice(0,v),g=A.slice(v+d.text.length),c=(U+g).replace(/ {2,}/g," ");return i.current=Math.min(i.current,c.length),c}k=v+y.text.length}}return A}),t(A=>A.filter(k=>k.id!==d.id)),r(A=>[b,...A]),n(-1),s.current=!0}}},[e,t,r,n,i,s]);return{setActivePill:m,removeLastParam:f,reEditParam:h}}var ft=0;function ht(){let e=(0,p.useRef)(null);return e.current===null&&(e.current=`:ac-${++ft}:`),e.current}function le({onSubmit:e,onError:o,optionOverrides:t,maskCompletedText:r,placeholder:n,apiConfig:i,columns:s=2,eagerSuggestions:m=!0,value:f,completedParams:h,onChange:d,onParamsChange:b}){let l=f!==void 0,A=h!==void 0,[k,y]=(0,p.useState)(""),[v,U]=(0,p.useState)([]),[g,c]=(0,p.useState)([]),[a,u]=(0,p.useState)(-1),S=l?f:k,w=A?h:v,O=(0,p.useRef)(e);O.current=e;let H=(0,p.useRef)(d);H.current=d;let I=(0,p.useRef)(b);I.current=b;let j=(0,p.useRef)(f);j.current=f;let q=(0,p.useRef)(h);q.current=h;let M=(0,p.useCallback)(_=>{if(typeof _=="function")if(l){let P=_(j.current??"");H.current?.(P)}else y(P=>{let Q=_(P);return H.current?.(Q),Q});else l||y(_),H.current?.(_)},[l]),L=(0,p.useCallback)(_=>{if(typeof _=="function")if(A){let P=_(q.current??[]);I.current?.(P)}else U(P=>{let Q=_(P);return I.current?.(Q),Q});else A||U(_),I.current?.(_)},[A]),X=(0,p.useRef)(o);X.current=o;let F=(0,p.useRef)(t);F.current=t;let N=(0,p.useRef)(r);N.current=r;let R=(0,p.useRef)(i);R.current=i;let B=(0,p.useRef)(S);B.current=S;let ce=(0,p.useRef)(g);ce.current=g;let $=(0,p.useRef)(0),ee=(0,p.useRef)(!1),ve=(0,p.useRef)(!1),ue=ht(),{doFetch:pe,isLoading:Ie,error:qe,isReady:Qe,lastRawQueryRef:me}=Fe({textRef:B,suggestionsRef:ce,filterBaseRef:$,maskCompletedTextRef:N,apiConfigRef:R,optionOverridesRef:F,onErrorRef:X,setCompletedParams:L,setSuggestions:c,setActiveDropdownIndex:u});ze({text:S,completedParams:w,doFetch:pe,filterBaseRef:$,skipNextFetchRef:ve,suggestionsRef:ce,lastRawQueryRef:me});let He=(0,p.useMemo)(()=>Le(S,w),[S,w]);$.current=Math.min($.current,S.length);let de=S.slice($.current),ge=(0,p.useMemo)(()=>g.filter(P=>P.type==="placeholder").map(P=>P.text).join(" ")||n||"",[g,n]),te=(0,p.useMemo)(()=>g.filter(_=>_.type!=="placeholder"),[g]),x=te[0],Ce=x?t?.[x.type]:void 0,ke=x?Ce?Ce(de.trim()):x.options??[]:[],fe=(0,p.useMemo)(()=>ae(ke,de),[ke,de]),we=ge.length>0,he=!Ie&&fe.length>0&&(!!S||ee.current||!we),Oe=(0,p.useCallback)(_=>{if(!x)return;let P={id:crypto.randomUUID(),placeholder:"",type:x.type,text:_.text,kind:_.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options,metadata:_.metadata},Q=$.current,D=B.current.slice(0,Q);if(D.length>0&&!D.endsWith(" ")){let T=D.split(/\s+/).pop()??"";T&&_.text.toLowerCase().startsWith(T.toLowerCase())&&(D=D.slice(0,D.length-T.length))}let be=D.length>0&&D[D.length-1]!==" ",G=D+(be?" ":"")+_.text+" ";M(G),$.current=G.length,L(T=>[...T,P]),ee.current=!1,u(-1);let V=te.length-1;m&&V>0?(c(T=>T.filter(W=>W!==x)),ve.current=!0):c(T=>T.filter(W=>W.type==="placeholder"))},[x,te,m,M,L]),Ve=(0,p.useCallback)(_=>{let P=_.target.value,D=P.length>0&&!_.nativeEvent?.isComposing&&P[0]!==P[0].toUpperCase()?P[0].toUpperCase()+P.slice(1):P;M(D),ee.current=!1,u(-1);let{valid:be,invalid:G}=Ue(D,w);if(G.length>0){L(()=>be);for(let V of G)c(T=>[{type:V.suggestionType,text:V.suggestionPlaceholder,required:!0,options:V.options},...T])}if(x&&G.length===0){let V=D.slice($.current),T=J(x.options,V);T&&(L(W=>[...W,{id:crypto.randomUUID(),placeholder:"",type:x.type,text:T.text,kind:T.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options,metadata:T.metadata}]),c(W=>W.filter(Ze=>Ze!==x)))}},[w,x,M,L]),{handleKeyDown:We}=Ne({activeDropdownIndex:a,setActiveDropdownIndex:u,filteredOptions:fe,selectOption:Oe,onSubmitRef:O,text:S,completedParams:w,isDropdownOpen:he,hasPlaceholder:we,placeholderText:ge,suggestions:g,filterBaseRef:$,columns:s,setText:M,setCompletedParams:L,setSuggestions:c}),oe=Be({completedParams:w,suggestions:g,setCompletedParams:L,setSuggestions:c,setActiveDropdownIndex:u,filterBaseRef:$,pillTappedRef:ee}),Xe=(0,p.useCallback)(_=>{oe.reEditParam(_).apply(M)},[oe,M]),Ge=(0,p.useCallback)(()=>{M(""),L(()=>[]),c([]),u(-1),$.current=0,me.current="",pe("",[])},[pe,M,L,me]),Ye=a>=0?`${ue}-option-${a}`:void 0;return{completedParams:w,suggestionPills:te,setActivePill:oe.setActivePill,removeLastParam:oe.removeLastParam,reEditParam:Xe,segments:He,suggestions:g,activeIndex:a,isReady:Qe,isLoading:Ie,error:qe,inputProps:{value:S,placeholder:ge||void 0,onChange:Ve,onKeyDown:We,role:"combobox","aria-expanded":he,"aria-activedescendant":Ye,"aria-autocomplete":"list","aria-controls":ue},reset:Ge,dropdownProps:{suggestions:x?[{...x,options:fe}]:[],activeIndex:a,onSelect:Oe,onHighlight:u,isOpen:he,id:ue}}}var C=require("react/jsx-runtime"),$e=(0,K.forwardRef)(function({onSubmit:o,onError:t,optionOverrides:r,maskCompletedText:n,placeholder:i,className:s,apiConfig:m,columns:f,eagerSuggestions:h,value:d,completedParams:b,onChange:l,onParamsChange:A},k){let y=(0,K.useRef)(null),[v,U]=(0,K.useState)(!1),g=(0,K.useRef)(()=>{}),c=(0,K.useRef)(void 0);(0,K.useEffect)(()=>(y.current?.focus(),()=>clearTimeout(c.current)),[]);let{completedParams:a,suggestionPills:u,setActivePill:S,segments:w,inputProps:O,dropdownProps:H,reset:I}=le({onSubmit:R=>g.current(R),onError:t,optionOverrides:r,maskCompletedText:n,placeholder:i,apiConfig:m,columns:f,eagerSuggestions:h,value:d,completedParams:b,onChange:l,onParamsChange:A});(0,K.useImperativeHandle)(k,()=>({focus:()=>y.current?.focus(),reset:I}),[I]);let j=()=>{y.current?.focus()},q=!!O.value||a.length>0,M=(0,K.useCallback)(()=>{if(!q)return;let{rawQuery:R,completedParams:B}=Z(O.value,a);o({query:O.value.trim(),raw_query:R,completed_params:B}),I(),U(!0),clearTimeout(c.current),c.current=setTimeout(()=>U(!1),3e3)},[q,O.value,a,o,I]);g.current=M;let{onChange:L,placeholder:X,...F}=O,N=!O.value;return(0,C.jsxs)("div",{className:`${z.container} ${s??""}`,children:[(0,C.jsx)("div",{className:`${z.checkmark} ${v?z.checkmarkVisible:""}`,children:(0,C.jsxs)("svg",{width:"72",height:"72",viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Success",children:[(0,C.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"#34C759"}),(0,C.jsx)("path",{d:"M7 12.5l3.5 3.5L17 9",stroke:"#000",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:z.checkmarkPath})]})}),(0,C.jsx)(re,{...H}),(0,C.jsxs)("div",{className:z.inputWrapper,onClick:j,children:[(0,C.jsxs)("div",{className:z.editorArea,children:[(0,C.jsxs)("div",{className:z.sizerContent,"aria-hidden":"true",children:[N&&X?(0,C.jsxs)("span",{className:z.placeholderText,children:[X," "]}):(0,C.jsxs)("span",{className:z.sizerText,children:[w.map((R,B)=>(0,C.jsx)("span",{children:R.value},`${B}-${R.type}`)),w.length===0&&"\xA0"]})," ",(0,C.jsx)(Me,{pills:u,activePillIndex:0,onSelectPill:S})]}),(0,C.jsx)("textarea",{ref:y,className:z.textarea,rows:1,onChange:L,...F})]}),(0,C.jsx)("button",{type:"button",className:z.submitButton,disabled:!q,onClick:R=>{R.stopPropagation(),M()},"aria-label":"Submit",children:(0,C.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,C.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
263
+ `,document.head.appendChild(e)}var ie={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",active:"PillList-module_active_Oll--"};var xe=require("react/jsx-runtime");function rt(e){return e===0?.4:e===1?.3:.15}function Me({pills:e,activePillIndex:r,onSelectPill:t}){return(0,xe.jsx)("span",{className:ie.list,children:e.map((o,n)=>(0,xe.jsx)("button",{type:"button",className:`${ie.pill} ${n===r?ie.active:""}`,style:{opacity:rt(n)},onClick:()=>t(n),children:o.text},`${o.type}-${o.text}`))})}var m=require("react");function ae(e,r){if(!e)return[];let t=r.trimStart();if(!t)return e;let o=t.toLowerCase();return e.filter(n=>!n.is_tappable||n.text.toLowerCase().includes(o))}function J(e,r){if(!e)return null;let t=r.trim();if(!t)return null;let o=t.toLowerCase();return e.find(n=>n.is_tappable&&n.text.toLowerCase()===o)??null}function Le(e,r){let t=[],o=0;for(let i of r){let s=e.indexOf(i.text,o);s!==-1&&(s>o&&t.push({type:"text",value:e.slice(o,s)}),t.push({type:"completed",value:i.text,param:i}),o=s+i.text.length)}let n=e.slice(o);return n&&t.push({type:"text",value:n}),t}function Ue(e,r){let t=[],o=[],n=0;for(let i of r){let s=e.indexOf(i.text,n);s===-1?o.push(i):(t.push(i),n=s+i.text.length)}return{valid:t,invalid:o}}var E=require("react");var it="0.1.11";function at(){return crypto.randomUUID()}function st(e,r){return{placeholder:e.placeholder,type:e.type,...r&&{text:e.text},kind:e.kind}}async function De(e,r,t){let o=t?.apiConfig,n=o?.apiKey??"",i=o?.authScheme??"Bearer",s=!t?.maskCompletedText,h=r.find(c=>c.type==="contact"&&c.metadata?.contact_account_count)?.metadata?.contact_account_count,d=typeof h=="number"?h:void 0,f={data:{raw_query:e,completed_params:r.map(c=>st(c,s)),...d!=null&&{contact_account_count:d}},meta:{request_id:at(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:it}},l={"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers};n&&(l.Authorization=i==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`);let b=await fetch(o?.endpoint??"/ac/suggest",{method:"POST",headers:l,body:JSON.stringify(f),signal:t?.signal});if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}function Z(e,r){let t=e,o={},n=[];for(let i of r){let s=(o[i.type]??0)+1;o[i.type]=s;let d=`{{${i.type.toUpperCase().replace(/\s+/g,"_")}_${s}}}`,f=t.indexOf(i.text);f!==-1&&(t=t.slice(0,f)+d+t.slice(f+i.text.length)),n.push({...i,placeholder:d})}return{rawQuery:t,completedParams:n}}function je(e,r){return r?e.map(t=>{let o=r[t.type];if(!o)return t;let n=o("");if(n.length===0)return t;let i=new Set(n.map(h=>h.text)),s=(t.options??[]).filter(h=>!i.has(h.text));return{...t,options:[...n,...s]}}):e}var lt=100,ct=300,ut=2;function ze({textRef:e,suggestionsRef:r,filterBaseRef:t,maskCompletedTextRef:o,apiConfigRef:n,optionOverridesRef:i,onErrorRef:s,setCompletedParams:h,setSuggestions:d,setActiveDropdownIndex:f}){let[l,b]=(0,E.useState)(!1),[c,A]=(0,E.useState)(null),[k,y]=(0,E.useState)(!1),v=(0,E.useRef)(0),U=(0,E.useRef)(null),g=(0,E.useRef)(""),u=(0,E.useCallback)(async(a,p)=>{U.current?.abort();let _=new AbortController;U.current=_;let w=++v.current,O=e.current.length;r.current.some(I=>I.type!=="placeholder")||b(!0),A(null);try{let I=await De(a,p,{maskCompletedText:o.current,signal:_.signal,apiConfig:n.current});if(w!==v.current)return;let z=je(I.data.suggestions??[],i.current);y(I.data.is_ready??!1),g.current=a;let q=I.data.input??[],M=q[q.length-1],L=e.current;if(M?.state==="in_progress"){let B=L.toLowerCase().lastIndexOf(M.text.toLowerCase());B!==-1?t.current=B:t.current=O}else t.current=O;let F=z.filter(B=>B.type!=="placeholder")[0];if(F){let B=L.slice(t.current),R=J(F.options,B);R&&(h(N=>[...N,{id:crypto.randomUUID(),placeholder:"",type:F.type,text:R.text,kind:R.kind,suggestionType:F.type,suggestionPlaceholder:F.text,options:F.options??[],metadata:R.metadata}]),z=z.filter(N=>N!==F))}d(z),b(!1),f(-1)}catch(I){if(w===v.current){let z=I instanceof Error?I:new Error(String(I));A(z),b(!1),s.current?.(z)}}},[e,r,t,o,n,i,s,h,d,f]);return(0,E.useEffect)(()=>(u("",[]),()=>{U.current?.abort()}),[u]),{doFetch:u,isLoading:l,error:c,isReady:k,lastRawQueryRef:g}}function Fe({text:e,completedParams:r,doFetch:t,filterBaseRef:o,skipNextFetchRef:n,suggestionsRef:i,lastRawQueryRef:s}){let h=(0,E.useRef)(null),d=(0,E.useRef)(null),f=(0,E.useRef)(!0);(0,E.useEffect)(()=>{h.current&&clearTimeout(h.current),d.current&&clearTimeout(d.current);let l=b=>{if(n.current)return n.current=!1,!1;if(!e&&r.length===0)return f.current?(t("",[]),!0):(f.current=!0,!1);let c=e.slice(o.current),y=i.current.filter(O=>O.type!=="placeholder")[0],U=(y?ae(y.options,c):[]).filter(O=>O.is_tappable),g=y?J(y.options,c)!==null:!1,u=c.trim().length>0;if(U.length>0&&!g&&u)return!1;let{rawQuery:a,completedParams:p}=Z(e,r),_=a.length<s.current.length,w=Math.abs(a.length-s.current.length);return _||w>=b?(t(a,p),!0):!1};return h.current=setTimeout(()=>{l(ut)&&d.current&&clearTimeout(d.current)},lt),d.current=setTimeout(()=>l(1),ct),()=>{h.current&&clearTimeout(h.current),d.current&&clearTimeout(d.current)}},[e,r,t,o,n,i,s])}var Pe=require("react");function Ke({activeDropdownIndex:e,setActiveDropdownIndex:r,filteredOptions:t,selectOption:o,onSubmitRef:n,text:i,completedParams:s,isDropdownOpen:h,hasPlaceholder:d,placeholderText:f,suggestions:l,filterBaseRef:b,columns:c,setText:A,setCompletedParams:k,setSuggestions:y}){let v=(0,Pe.useCallback)(()=>{let g=t.map((a,p)=>a.is_tappable?p:-1).filter(a=>a!==-1),u=Array.from({length:c},()=>[]);for(let a of g)u[a%c].push(a);return u.flat()},[t,c]);return{handleKeyDown:(0,Pe.useCallback)(g=>{let u=v();switch(g.key){case"ArrowDown":{if(g.preventDefault(),u.length===0)return;let a=u.indexOf(e),p=a<u.length-1?a+1:0;r(u[p]);break}case"ArrowUp":{if(g.preventDefault(),u.length===0)return;let a=u.indexOf(e),p=a>0?a-1:u.length-1;r(u[p]);break}case"ArrowRight":{if(e<0)break;if(e%c<c-1){let p=e+1;p<t.length&&t[p]?.is_tappable&&(g.preventDefault(),r(p))}break}case"ArrowLeft":{if(e<0)break;if(e%c>0){let a=e-1;a>=0&&t[a]?.is_tappable&&(g.preventDefault(),r(a))}break}case"Enter":{if(g.preventDefault(),e>=0&&t[e]?.is_tappable)o(t[e]);else if(n.current){let{rawQuery:a,completedParams:p}=Z(i,s),_={query:i.trim(),raw_query:a,completed_params:p};n.current(_)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)g.preventDefault(),o(t[e]);else if(h){let a=t.find(p=>p.is_tappable);a&&(g.preventDefault(),o(a))}else if(!i&&d){g.preventDefault();let a=l.find(p=>p.type==="placeholder");a?(A(f),b.current=f.length,k(p=>[...p,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[]}]),y(p=>p.filter(_=>_!==a))):(A(f),b.current=f.length)}break}case"Escape":r(-1);break}},[e,c,s,t,b,v,d,h,n,f,o,r,k,y,A,l,i]),getTappableIndices:v}}var se=require("react");function Be({completedParams:e,suggestions:r,setCompletedParams:t,setSuggestions:o,setActiveDropdownIndex:n,filterBaseRef:i,pillTappedRef:s}){let h=(0,se.useCallback)(l=>{let b=r.filter(y=>y.type!=="placeholder");if(l<0||l>=b.length)return;let c=b[l],A=b.filter((y,v)=>v!==l),k=r.filter(y=>y.type==="placeholder");o([...k,c,...A]),s.current=!0,n(-1)},[r,o,n,s]),d=(0,se.useCallback)(()=>{if(e.length===0)return;let l=e[e.length-1],b={type:l.suggestionType,text:l.suggestionPlaceholder,required:!0,options:l.options};t(c=>c.slice(0,-1)),o(c=>[b,...c]),n(-1)},[e,t,o,n]),f=(0,se.useCallback)(l=>{let b={type:l.suggestionType,text:l.suggestionPlaceholder,required:!0,options:l.options};return{apply:c=>{c(A=>{let k=0;for(let y of e){let v=A.indexOf(y.text,k);if(v!==-1){if(y.id===l.id){let U=A.slice(0,v),g=A.slice(v+l.text.length),u=(U+g).replace(/ {2,}/g," ");return i.current=Math.min(i.current,u.length),u}k=v+y.text.length}}return A}),t(A=>A.filter(k=>k.id!==l.id)),o(A=>[b,...A]),n(-1),s.current=!0}}},[e,t,o,n,i,s]);return{setActivePill:h,removeLastParam:d,reEditParam:f}}var pt=0;function mt(){let e=(0,m.useRef)(null);return e.current===null&&(e.current=`:ac-${++pt}:`),e.current}function le({onSubmit:e,onError:r,optionOverrides:t,maskCompletedText:o,placeholder:n,apiConfig:i,columns:s=2,eagerSuggestions:h=!0,value:d,completedParams:f,onChange:l,onParamsChange:b}){let c=d!==void 0,A=f!==void 0,[k,y]=(0,m.useState)(""),[v,U]=(0,m.useState)([]),[g,u]=(0,m.useState)([]),[a,p]=(0,m.useState)(-1),_=c?d:k,w=A?f:v,O=(0,m.useRef)(e);O.current=e;let V=(0,m.useRef)(l);V.current=l;let I=(0,m.useRef)(b);I.current=b;let z=(0,m.useRef)(d);z.current=d;let q=(0,m.useRef)(f);q.current=f;let M=(0,m.useCallback)(S=>{if(typeof S=="function")if(c){let P=S(z.current??"");V.current?.(P)}else y(P=>{let Q=S(P);return V.current?.(Q),Q});else c||y(S),V.current?.(S)},[c]),L=(0,m.useCallback)(S=>{if(typeof S=="function")if(A){let P=S(q.current??[]);I.current?.(P)}else U(P=>{let Q=S(P);return I.current?.(Q),Q});else A||U(S),I.current?.(S)},[A]),G=(0,m.useRef)(r);G.current=r;let F=(0,m.useRef)(t);F.current=t;let B=(0,m.useRef)(o);B.current=o;let R=(0,m.useRef)(i);R.current=i;let N=(0,m.useRef)(_);N.current=_;let ce=(0,m.useRef)(g);ce.current=g;let $=(0,m.useRef)(0),ee=(0,m.useRef)(!1),ve=(0,m.useRef)(!1),ue=mt(),{doFetch:pe,isLoading:Ie,error:$e,isReady:qe,lastRawQueryRef:me}=ze({textRef:N,suggestionsRef:ce,filterBaseRef:$,maskCompletedTextRef:B,apiConfigRef:R,optionOverridesRef:F,onErrorRef:G,setCompletedParams:L,setSuggestions:u,setActiveDropdownIndex:p});Fe({text:_,completedParams:w,doFetch:pe,filterBaseRef:$,skipNextFetchRef:ve,suggestionsRef:ce,lastRawQueryRef:me});let Qe=(0,m.useMemo)(()=>Le(_,w),[_,w]);$.current=Math.min($.current,_.length);let de=_.slice($.current),ge=(0,m.useMemo)(()=>g.filter(P=>P.type==="placeholder").map(P=>P.text).join(" ")||n||"",[g,n]),te=(0,m.useMemo)(()=>g.filter(S=>S.type!=="placeholder"),[g]),x=te[0],Ce=x?t?.[x.type]:void 0,ke=x?Ce?Ce(de.trim()):x.options??[]:[],fe=(0,m.useMemo)(()=>ae(ke,de),[ke,de]),we=ge.length>0,he=!Ie&&fe.length>0&&(!!_||ee.current||!we),Oe=(0,m.useCallback)(S=>{if(!x)return;let P={id:crypto.randomUUID(),placeholder:"",type:x.type,text:S.text,kind:S.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:S.metadata},Q=$.current,D=N.current.slice(0,Q);if(D.length>0&&!D.endsWith(" ")){let T=D.split(/\s+/).pop()??"";T&&S.text.toLowerCase().startsWith(T.toLowerCase())&&(D=D.slice(0,D.length-T.length))}let be=D.length>0&&D[D.length-1]!==" ",X=D+(be?" ":"")+S.text+" ";M(X),$.current=X.length,L(T=>[...T,P]),ee.current=!1,p(-1);let H=te.length-1;h&&H>0?(u(T=>T.filter(W=>W!==x)),ve.current=!0):u(T=>T.filter(W=>W.type==="placeholder"))},[x,te,h,M,L]),Ve=(0,m.useCallback)(S=>{let P=S.target.value,D=P.length>0&&!S.nativeEvent?.isComposing&&P[0]!==P[0].toUpperCase()?P[0].toUpperCase()+P.slice(1):P;M(D),ee.current=!1,p(-1);let{valid:be,invalid:X}=Ue(D,w);if(X.length>0){L(()=>be);for(let H of X)u(T=>[{type:H.suggestionType,text:H.suggestionPlaceholder,required:!0,options:H.options},...T])}if(x&&X.length===0){let H=D.slice($.current),T=J(x.options,H);T&&(L(W=>[...W,{id:crypto.randomUUID(),placeholder:"",type:x.type,text:T.text,kind:T.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:T.metadata}]),u(W=>W.filter(Ye=>Ye!==x)))}},[w,x,M,L]),{handleKeyDown:He}=Ke({activeDropdownIndex:a,setActiveDropdownIndex:p,filteredOptions:fe,selectOption:Oe,onSubmitRef:O,text:_,completedParams:w,isDropdownOpen:he,hasPlaceholder:we,placeholderText:ge,suggestions:g,filterBaseRef:$,columns:s,setText:M,setCompletedParams:L,setSuggestions:u}),oe=Be({completedParams:w,suggestions:g,setCompletedParams:L,setSuggestions:u,setActiveDropdownIndex:p,filterBaseRef:$,pillTappedRef:ee}),We=(0,m.useCallback)(S=>{oe.reEditParam(S).apply(M)},[oe,M]),Ge=(0,m.useCallback)(()=>{M(""),L(()=>[]),u([]),p(-1),$.current=0,me.current="",pe("",[])},[pe,M,L,me]),Xe=a>=0?`${ue}-option-${a}`:void 0;return{completedParams:w,suggestionPills:te,setActivePill:oe.setActivePill,removeLastParam:oe.removeLastParam,reEditParam:We,segments:Qe,suggestions:g,activeIndex:a,isReady:qe,isLoading:Ie,error:$e,inputProps:{value:_,placeholder:ge||void 0,onChange:Ve,onKeyDown:He,role:"combobox","aria-expanded":he,"aria-activedescendant":Xe,"aria-autocomplete":"list","aria-controls":ue},reset:Ge,dropdownProps:{suggestions:x?[{...x,options:fe}]:[],activeIndex:a,onSelect:Oe,onHighlight:p,isOpen:he,id:ue}}}var C=require("react/jsx-runtime"),Ne=(0,j.forwardRef)(function({onSubmit:r,onError:t,optionOverrides:o,maskCompletedText:n,placeholder:i,className:s,apiConfig:h,columns:d,eagerSuggestions:f,value:l,completedParams:b,onChange:c,onParamsChange:A},k){let y=(0,j.useRef)(null),[v,U]=(0,j.useState)(!1),g=(0,j.useRef)(()=>{}),u=(0,j.useRef)(void 0);(0,j.useEffect)(()=>(y.current?.focus(),()=>clearTimeout(u.current)),[]);let{completedParams:a,suggestionPills:p,setActivePill:_,segments:w,inputProps:O,dropdownProps:V,reset:I}=le({onSubmit:R=>g.current(R),onError:t,optionOverrides:o,maskCompletedText:n,placeholder:i,apiConfig:h,columns:d,eagerSuggestions:f,value:l,completedParams:b,onChange:c,onParamsChange:A});(0,j.useImperativeHandle)(k,()=>({focus:()=>y.current?.focus(),reset:I}),[I]);let z=()=>{y.current?.focus()},q=!!O.value||a.length>0,M=(0,j.useCallback)(()=>{if(!q)return;let{rawQuery:R,completedParams:N}=Z(O.value,a);r({query:O.value.trim(),raw_query:R,completed_params:N}),I(),U(!0),clearTimeout(u.current),u.current=setTimeout(()=>U(!1),3e3)},[q,O.value,a,r,I]);g.current=M;let{onChange:L,placeholder:G,...F}=O,B=!O.value;return(0,C.jsxs)("div",{className:`${K.container} ${s??""}`,children:[(0,C.jsx)("div",{className:`${K.checkmark} ${v?K.checkmarkVisible:""}`,children:(0,C.jsxs)("svg",{width:"72",height:"72",viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Success",children:[(0,C.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"#34C759"}),(0,C.jsx)("path",{d:"M7 12.5l3.5 3.5L17 9",stroke:"#000",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:K.checkmarkPath})]})}),(0,C.jsx)(re,{...V}),(0,C.jsxs)("div",{className:K.inputWrapper,onClick:z,children:[(0,C.jsxs)("div",{className:K.editorArea,children:[(0,C.jsxs)("div",{className:K.sizerContent,"aria-hidden":"true",children:[B&&G?(0,C.jsxs)("span",{className:K.placeholderText,children:[G," "]}):(0,C.jsxs)("span",{className:K.sizerText,children:[w.map((R,N)=>(0,C.jsx)("span",{children:R.value},`${N}-${R.type}`)),w.length===0&&"\xA0"]})," ",(0,C.jsx)(Me,{pills:p,activePillIndex:0,onSelectPill:_})]}),(0,C.jsx)("textarea",{ref:y,className:K.textarea,rows:1,onChange:L,...F})]}),(0,C.jsx)("button",{type:"button",className:K.submitButton,disabled:!q,onClick:R=>{R.stopPropagation(),M()},"aria-label":"Submit",children:(0,C.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,C.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
264
264
  //# sourceMappingURL=index.js.map