@inploi/plugin-chatbot 3.12.0 → 3.12.1

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/cdn/index.js CHANGED
@@ -50,4 +50,4 @@ var uy=Object.defineProperty;var dy=(ft,xe,E)=>xe in ft?uy(ft,xe,{enumerable:!0,
50
50
  `,Am=()=>({getOrCreateChatbotElement:()=>{const e=document.getElementById(sl);if(e)return e;const t=document.createElement("div");return document.body.appendChild(t),t.id=sl,t}});var Pm=["1","2","3","4","5","6","7","8","9","10","11","12"],Em={light:{1:[98.8,.015],2:[97.8,.018],3:[95.8,.025],4:[92,.04],5:[89,.05],6:[85,.07],7:[80.5,.08],8:[74,.11],9:[60,.22],10:[56,.23],11:[50,.19],12:[25,.18]},dark:{1:[19,.015],2:[21,.018],3:[25.5,.055],4:[29.3,.084],5:[33.5,.098],6:[39.05,.107],7:[45,.11],8:[55,.13],9:[60,.22],10:[67,.18],11:[79.3,.12],12:[95,.04]}},Tm=(e,t=1,n)=>r=>{const[i,o]=Em[n][r];return"oklch("+i+"% "+o*t+" "+e+")"},xo=e=>{const t=Tm(e.hue,e.chroma,e.mode);return Object.fromEntries(Pm.map(n=>[e.prefix+n,e.transform(t(n))]))},ko=e=>e,Vm=e=>{const t=Object.keys(e).flatMap(n=>{const r=e[n];return typeof r=="object"&&r!==null?Object.keys(r).map(i=>{const o=r[i];return[`${String(n)}.${i}`,o]}):[[n,r]]});return Object.fromEntries(t)},Mr=e=>!!e&&typeof e=="object"&&!Array.isArray(e),So=(e,...t)=>{if(!t.length)return e;const n=t.shift();if(Mr(e)&&Mr(n))for(const r in n){const i=n[r];if(Mr(i)){e[r]||Object.assign(e,{[r]:{}});const o=e[r];Mr(o)&&So(o,i)}else Object.assign(e,{[r]:n[r]})}return So(e,...t)},Mm=e=>{function t(n,r){const i=[e.prefix,r.toString().replace(/\./g,"-")].join("");return n==="declaration"?`--${i}`:`var(--${i})`}return t},Om=()=>({core:e=>({semantic:t=>({component:n=>({from:r=>{const{theme:i,getToken:o}=r,s=f=>o("reference",f.toString()),a=e({theme:i}),c=t({theme:i,core:s,raw:{core:a}}),u=n({theme:i,core:s,semantic:s,raw:{core:a,semantic:c}}),d=Vm(So(a,c,u)),l=([f,p],h)=>{const v=[h,f].filter(Boolean).join(".");return typeof p=="object"?Object.entries(p).flatMap(b=>l(b,v)):[[r.getToken("declaration",v),p]]};return{values:d,declarations:Object.fromEntries(Object.entries(d).flatMap(f=>l(f))),ref:f=>o("reference",f.toString())}}})})})});const[Co,$o,$l]=["oklch(0% 0 0)","oklch(100% 0 0)","transparent"],Fm=Om().core(({theme:e})=>({color:{black:Co,white:$o,lowest:e.mode==="light"?$o:Co,highest:e.mode==="light"?Co:$o,...xo({prefix:"a-",hue:e.hue,chroma:e.chroma,mode:e.mode,transform:ko}),...xo({prefix:"n-",hue:e.hue,chroma:.05,mode:e.mode,transform:ko}),...xo({prefix:"e-",hue:20,chroma:e.chroma,mode:e.mode,transform:ko})},typography:{}})).semantic(({core:e,raw:t,theme:n})=>{const r=(i,o)=>t.core.color[i].replace(")",` / ${o})`);return{"font-family":{body:"inherit",headings:"inherit"},"font-style":{body:"normal",headings:"normal"},"font-weight-body":"normal","font-weight-headings":"normal","radius-app":"1.5rem","radius-interactive":"1.5rem",color:{divider:r("n-8",n.mode==="dark"?.4:.2)},"copy-body":e("color.n-12"),"copy-headings":e("color.n-12"),interactive:{copy:e("color.n-11"),"copy-hover":e("color.n-12"),"copy-active":e("color.n-12"),bg:$l,"bg-hover":r("n-10",.4),"bg-active":r("n-10",.5)}}}).component(({raw:e,theme:t,semantic:n,core:r})=>{const i=(o,s)=>e.core.color[o].replace(")",` / ${s})`);return{app:{bg:r(t.mode==="dark"?"color.n-1":"color.n-2")},overlay:{bg:i("black",.4)},bubble:{"weak-bg":r(t.mode==="dark"?"color.n-3":"color.lowest"),"weak-outline":n("color.divider"),"strong-shadow":i("a-9",.05)},"status-bar":{bg:i("n-2",.8),"bg-button":$l,"bg-button-hover":i("n-10",.4),"bg-button-active":i("n-10",.5)},"submit-button":{"bg-active":r(t.mode==="dark"?"color.a-9":"color.a-10")}}}),Im=Mm({prefix:"i-"}),Dm=e=>{const t=Fm.from({theme:e,getToken:Im}),n=Object.entries(t.declarations).map(([r,i])=>`${r}: ${i};`);return`#isdk {
51
51
  ${n.concat(n).join(`
52
52
  `)}
53
- }`},Nm=({_internal_domManager:e=Am(),theme:t})=>ft(({apiClient:n,logger:r,analytics:i})=>{let o=!1;const s=()=>{if(typeof window>"u")return;const a=[O("style",{id:"inploi-chatbot-styles"},$m),O("style",{id:"inploi-chatbot-theme"},Dm(t))],c=e.getOrCreateChatbotElement();Dt(O(Q,{},[a,O(xm,{apiClient:n,logger:r,analytics:i})]),c),o=!0};return{prepare:async()=>{if(!(typeof window>"u"))try{if(o)return;s(),r.info("Chatbot plugin prepared")}catch(a){r.error("Error preparing chatbot plugin",a)}},fetchFlowByJobId:async a=>n.fetch(`/flow/job/${a}`).then(c=>{const u=cn(Sm,c);return{context:{job_id:u.job.id,flow_id:u.flow.id},flow:u.flow,title:`Applying for “${u.job.title}”`,flowKeys:[u.job.id]}}),fetchFlowById:async a=>n.fetch(`/flow/${a}`).then(c=>{const u=cn(km,c);return{flow:u.flow,context:{flow_id:u.flow.id},title:"Chatbot",flowKeys:[]}}),open:async a=>{if(!(typeof window>"u"))try{L.cancelCurrentFlow(),L.viewState$.value="maximised",a instanceof Promise?(L.current$.value={state:"loading"},a.then(async c=>{const u=cn(Cm,c);L.startFlow(u)}).catch(c=>{const u=c instanceof Error?c.message:"An error occurred";L.current$.value={state:"error",error:u}})):L.startFlow(a)}catch(c){r.error("Error starting flow",c)}},startApplication:void 0,closeApplication:void 0,close:async()=>{typeof window>"u"||(L.cancelCurrentFlow(),r.info("Closed flow from an external source"))}}});if(!window.inploi)throw new Error("Please insert the SDK script tag above the plugins.");window.inploi.chatbotPlugin=Nm;const Al=({node:e,nodes:t,stopWhen:n})=>{if((n==null?void 0:n(e))===!0)return e;const r=e.nextId?t.find(i=>i.id===e.nextId):void 0;if(r)return Al({node:r,nodes:t,stopWhen:n})},Lm=({childNode:e,nodes:t})=>{const r=t.filter(i=>i.type==="if-block").find(i=>{if(!i.branchId)return!1;const o=t.find(a=>a.id===i.branchId);if(!o)return!1;const s=Al({node:o,nodes:t,stopWhen:a=>a.id===e.id});return!(!s||s.id!==e.id)});if(r!=null&&r.nextId)return t.find(i=>i.id===r.nextId)},Rm=({flow:e,analytics:t,logger:n,context:r,apiClient:i,getSubmissions:o,chatService:s,onFlowEnd:a,onInterpret:c})=>{let u=new AbortController;const d=async(l,f)=>{const p=o();c==null||c(l,f);try{await Bm({analytics:t,logger:n,apiClient:i,context:r,node:l,submissions:p,chat:{sendMessage:async h=>s.send({groupId:l.id,message:h,signal:u.signal}),userInput:async h=>s.input({input:h,signal:u.signal})},next:h=>{const v=h?e.find(b=>b.id===h):Lm({childNode:l,nodes:e});return v?d(v,l):a==null?void 0:a(l)},end:()=>a==null?void 0:a(l)})}catch(h){if(h instanceof En)return;throw h}};return{interpret:async l=>{const f=e.find(p=>p.id===l)??wl(e);return d(f)},undo:l=>{let f=1;const p=e.find(v=>v.id===l[l.length-1]);for(let v=l.length-2;v>0;v--){const b=l[v],x=e.find(y=>y.id===b);if(!x||(f++,x.type.startsWith("question-")))break}u.abort(),u=new AbortController;const h=e.find(v=>v.id===l[l.length-f]);return vt(h,"Undo failed: new start node not found"),d(h,p),{removed:f}},abort:()=>{u.abort()}}};async function Bm(e){return await Ue(e).with({node:{type:"text"}},Hm).with({node:{type:"image"}},Wm).with({node:{type:"question-text"}},Km).with({node:{type:"question-enum"}},Gm).with({node:{type:"question-number"}},qm).with({node:{type:"question-boolean"}},Ym).with({node:{type:"question-file"}},Qm).with({node:{type:"question-address"}},Xm).with({node:{type:"end-flow"}},Jm).with({node:{type:"if-block"}},zm).with({node:{type:"jump"}},({node:t,next:n})=>n(t.data.targetId)).with({node:{type:"link"}},Um).with({node:{type:"integration-application-submit"}},jm).with({node:{type:"integration-workflow-get"}},()=>Error("Unreachable")).exhaustive()}async function jm({chat:e,next:t,node:n,logger:r,apiClient:i,submissions:o,context:s,analytics:a}){await e.userInput({type:"submit",key:void 0,config:{label:"Submit my application"}});const c=()=>{const f=typeof s.job_id=="string"?s.job_id:void 0,p=typeof s.flow_id=="string"?s.flow_id:void 0;!f||!p||f&&a.log({event:"APPLY_COMPLETE",attributionKey:`job_${f}`,properties:{job_id:f,flow_id:p}})};await e.sendMessage({type:"system",variant:"info",text:"Submitting your application…"});const{anonymous_id:u,session_id:d}=a.getSessionInfo(),l=await i.fetch("/flow/apply",{method:"POST",body:JSON.stringify({...s,integration_id:n.data.integrationId,anonymous_id:u,session_id:d,submissions:lm(o||{})})}).catch(f=>f);await Ue(l).with({ats_data:{redirect_url:_e.string}},async f=>{await e.sendMessage({type:"text",author:"bot",text:"Almost there! Please finalise your application on our partner’s website."});const p=new URL(f.ats_data.redirect_url);u&&!p.searchParams.has("anonymous_id")&&p.searchParams.set("anonymous_id",u),c(),await e.sendMessage({type:"link",href:p.toString(),text:"Finalise application on partner"}),t(n.nextId)}).with({success:!0},async()=>{c(),await e.sendMessage({type:"system",variant:"success",text:"Application submitted"}),t(n.nextId)}).otherwise(async f=>{r.error(f),await e.sendMessage({type:"system",variant:"error",text:"Failed to submit application"}),t(n.id)})}async function Um({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({type:"link",href:n.data.href,text:Et(n.data.cta,r)}),t(n.nextId)}async function zm({submissions:e,next:t,node:n}){const r=eg(n,e)?n.branchId:n.nextId;t(r)}async function Hm({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.text,r)}),t(n.nextId)}async function Wm({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"image",url:n.data.url,height:n.data.height,width:n.data.width}),t(n.nextId)}async function Km({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const i=await e.userInput({key:n.data.key,type:"text",config:{optional:n.data.optional,placeholder:n.data.placeholder,format:n.data.format}});i.value===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:i.value}),t(n.nextId)}async function qm({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const i=await e.userInput({key:n.data.key,type:"text",config:{optional:n.data.optional,placeholder:n.data.placeholder,format:"text"}});i.value===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:i.value}),t(n.nextId)}async function Gm({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const i=await e.userInput({key:n.data.key,type:"multiple-choice",config:n.data});i.value.length===0?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:n.data.options.filter(o=>i.value.includes(o.value)).map(o=>o.label).join(", ")}),t(n.nextId)}async function Ym({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const o=(await e.userInput({key:n.data.key,type:"boolean",config:{optional:n.data.optional,labels:{true:n.data.trueLabel,false:n.data.falseLabel}}})).value;o===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:{true:n.data.trueLabel,false:n.data.falseLabel}[o]}),t(n.nextId)}const Zm=document.createElement("div"),Pl={line1:["street_number","floor","room","premise"],line2:["subpremise","street_address","route"],line3:["sublocality","neighborhood"],city:["locality","postal_town"],state:["administrative_area_level_1"],postcode:["postal_code"],country:["country"]},El=Object.keys(Pl);async function Xm({chat:e,next:t,node:n,logger:r}){if(El.every(h=>n.data.keys[h]===null))return t(n.nextId);const{google:i}=window;await e.sendMessage({author:"bot",type:"text",text:n.data.question});const o=async h=>{const v=[{label:"Postcode",key:n.data.keys.postcode,optional:!1,defaultValue:h.postcode},{label:"Line 1",key:n.data.keys.line1,optional:!1,defaultValue:h.line1},{label:"Line 2",key:n.data.keys.line2,optional:!0,defaultValue:h.line2},{label:"Line 3",key:n.data.keys.line3,optional:!0,defaultValue:h.line3},{label:"City",key:n.data.keys.city,optional:!1,defaultValue:h.city},{label:"State/County/Province",key:n.data.keys.state,optional:!0,defaultValue:h.state},{label:"Country",key:n.data.keys.country,optional:!1,defaultValue:h.country}];for(const b of v){if(b.key===null)continue;await e.sendMessage({author:"bot",type:"text",text:b.label});const{value:x}=await e.userInput({type:"text",key:b.key,config:{format:"text",optional:b.optional,defaultValue:b.defaultValue}});x===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:x})}};if(!Zr(window,"google")||!Zr(window.google,"maps")||!Zr(window.google.maps,"places"))return r.warn("Google maps not available, falling back to manual input."),r.info("If you’d like to use the address autocomplete, please insert the google maps API snippet in your website and make sure it has access to the *places* library."),await o({}),t(n.nextId);const s=new i.maps.places.AutocompleteService,a=new i.maps.places.PlacesService(Zm),{value:c}=await e.userInput({type:"text",key:"_internal-address-search",config:{format:"text",optional:!1,placeholder:"Search for your address"}});if(c===null)return t(n.id);await e.sendMessage({author:"user",type:"text",text:`Search for “${c}”`});const{predictions:u}=await s.getPlacePredictions({input:c}),{value:[d]}=await e.userInput({type:"multiple-choice",key:void 0,config:{options:u.slice(0,4).map(h=>({label:h.description,value:h.place_id})).concat({label:"None of these",value:"none"}),maxSelected:1,minSelected:1}});if(!d||d==="none")return t(n.id);const l=await new Promise((h,v)=>a.getDetails({placeId:d,fields:["address_components"]},(b,x)=>x!==i.maps.places.PlacesServiceStatus.OK?v(x):b===null?v("ZERO_RESULTS"):h({ok:!0,place:b}))).catch(async h=>(r.error("Failed to get address details",h),{ok:!1}));if(l.ok===!1)return await e.sendMessage({type:"system",variant:"error",text:"Failed to get address details"}),await o({}),t(n.id);const f=l.place.address_components,p=f?El.reduce((h,v)=>{const b=Pl[v],x=f.filter(y=>y.types.some(_=>b.includes(_))).map(y=>y.long_name).join(", ");return x&&(h[v]=x),h},{}):{};return await e.sendMessage({author:"bot",type:"text",text:"Please confirm or adjust your address:"}),await o(p),t(n.nextId)}async function Qm({node:e,chat:t,next:n,submissions:r}){await t.sendMessage({author:"bot",type:"text",text:Et(e.data.question,r)});const i=await t.userInput({key:e.data.key,type:"file",config:{optional:e.data.optional,extensions:e.data.extensions,fileSizeLimitKib:e.data.maxSizeKb??10*1024,allowMultiple:e.data.multiple===!0}});if(i.value===null)await t.sendMessage({type:"system",variant:"info",text:"Skipped"});else for(const o of i.value)await t.sendMessage({author:"user",type:"file",fileName:o.name,fileSizeKb:o.sizeKb});n(e.nextId)}async function Jm({chat:e,end:t,node:n}){await e.sendMessage({type:"system",variant:"info",text:n.data.systemMessage}),t()}const Tl=_e.union(_e.string,_e.array(_e.string),null),eg=(e,t)=>{const n=t==null?void 0:t[e.data.compareKey];return n?Ue({...e.data,answer:n}).with({compare:"equals"},({compareValue:r})=>typeof n.value=="string"||typeof n.value=="boolean"?r===n.value.toString():!1).with({compare:"notEquals"},({compareValue:r})=>typeof n.value=="string"||typeof n.value=="boolean"?r!==n.value.toString():!1).with({compare:"contains",answer:{value:Tl}},({compareValue:r,answer:i})=>i.value!==null&&i.value.includes(r)).with({compare:"notContains",answer:{value:Tl}},({compareValue:r,answer:i})=>i.value===null||!i.value.includes(r)).with({answer:{type:"file"}},()=>!1).exhaustive():!1},Et=(e,t)=>{const n=/{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g;return e.replace(n,(r,i,o="")=>{i=i.trim();const s=t==null?void 0:t[i];if(!s)return o;switch(s.type){case"boolean":return s.value==="true"?"true":"false";case"file":return s.value?s.value.map(a=>`${a.name} (${Pn(a.sizeKb)})`).join(", "):"no files";case"multiple-choice":return s.value.join(", ");default:return s.value||o}})},Or=({class:e,...t})=>g("button",{class:at("bg-accent-9 active:bg-accent-10 pointer-coarse:touch-hitbox fr flex-shrink-0 rounded-full p-2 text-white transition-all disabled:cursor-not-allowed disabled:opacity-50",e),type:"submit",...t,children:g("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"2",children:[g("title",{children:"Send"}),g("path",{d:"M3.5 7.5L8 3L12.5 7.5"}),g("path",{d:"M8 4V13"})]})}),tg=25,Ao=it({instant:()=>{},smooth:()=>{}}),Ve={onSubmitSuccessFn$:it(()=>{}),isBotTyping$:it(!1),scrollToEnd:{instant:()=>Ao.value.instant(),smooth:()=>Ao.value.smooth()}},ng=()=>{const e=j(null);Ae(()=>{Ao.value={instant:()=>{var n;return(n=e.current)==null?void 0:n.scrollTo({top:e.current.scrollHeight,behavior:"instant"})},smooth:()=>{e.current&&e.current.scrollHeight-e.current.scrollTop<=e.current.clientHeight*1.5&&e.current.scrollTo({top:e.current.scrollHeight,behavior:"smooth"})}}},[e]);const t=se(()=>({send:async({message:n,signal:r,groupId:i})=>{if(await Ue(n).with({author:"bot",type:"text"},async o=>{if(r!=null&&r.aborted)throw new En;Ve.isBotTyping$.value=!0;const s=Math.min(Math.max(20,o.text.length),100)*tg;await new Promise(a=>setTimeout(a,s,{signal:r})),Ve.isBotTyping$.value=!1}).otherwise(async()=>{}),r!=null&&r.aborted)throw new En;L.addMessage(n,i)},input:async({input:n,signal:r})=>{if(r!=null&&r.aborted)throw new En;return L.setInput(n),await new Promise(i=>{const o=s=>{if(r!=null&&r.aborted)throw new En;L.setInput(void 0),n.key&&L.setSubmission(n.key,s),i(s)};Ve.onSubmitSuccessFn$.value=o})}}),[]);return{chatRef:e,chatService:t}},Fr=({class:e,...t})=>g("button",{type:"button",class:at("fr text-neutral-9 flex flex-shrink-0 items-center justify-center gap-1 rounded-full py-[6px] pl-2 pr-3 text-sm underline-offset-2 transition-all",e),...t,children:[g("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"1.5",children:[g("title",{children:"Skip"}),g("path",{d:"M3.25 11.25A5 5 0 0 1 12 7"}),g("path",{d:"M13.25 4.5V8.25H9.5"})]}),"Skip"]}),Po=()=>{const e=j(null);return W(()=>{var t;(t=e.current)==null||t.focus()},[]),e},Vl=["true","false"],rg=wu(Vl),ig="answer",og=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{const r=Po();return n(),g("form",{noValidate:!0,class:"",onSubmit:i=>{i.preventDefault();const o=Ue(i).with({nativeEvent:{submitter:_e.select(_e.union(_e.instanceOf(HTMLButtonElement),_e.instanceOf(HTMLInputElement)))}},a=>a.value).otherwise(()=>{throw new Error("invalid form")}),s=cn(rg,o);t(s)},children:[g("div",{class:"flex items-center gap-2 p-2.5",children:Vl.map((i,o)=>g("button",{ref:o===0?r:null,type:"submit",name:ig,value:i,class:"bg-lowest ease-expo-out ring-divider text-neutral-12 active:ring-accent-7 active:bg-accent-2 active:text-accent-11 fr block flex-1 overflow-hidden rounded-2xl px-2.5 py-2.5 ring-2 transition-all selection:bg-transparent",children:g("p",{class:"truncate text-center text-base",children:e.config.labels[i]})}))}),e.config.optional&&g("div",{class:"px-2 pb-2",children:g(Fr,{class:"w-full",type:"button",onClick:()=>t(null)})})]})},Eo=({error:e,onAnimationComplete:t})=>(Ae(()=>{e&&t()},[e,t]),e?g("div",{role:"alert",class:"text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full px-2 py-2",children:[g("svg",{class:"text-error-9 h-4 w-4",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"8",cy:"8",r:"6.3",stroke:"currentColor","stroke-width":"1.4"}),g("rect",{x:"7",y:"4",width:"2",height:"5",fill:"currentColor"}),g("rect",{x:"7",y:"10",width:"2",height:"2",fill:"currentColor"})]}),g("p",{class:"truncate pr-1 text-sm",children:e.message})]}):null),sg=e=>new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>r.result?t(r.result.toString()):n("No result from reader"),r.onerror=n}),ag=e=>e.reduce((t,n)=>t+n.sizeKb,0),cg=wo("file"),Ml=3,lg=({file:e,class:t,...n})=>{const r=e.name.split(".").pop(),i=e.name.replace(new RegExp(`.${r}$`),"");return g("div",{class:at("bg-accent-1 outline-accent-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline",t),...n,children:[g("p",{"aria-label":"File name",class:"text-accent-12 flex flex-grow overflow-hidden",children:[g("span",{class:"block truncate",children:i}),g("span",{children:[".",r]})]}),g("p",{"aria-label":"File size",class:"text-accent-11",children:Pn(e.sizeKb)})]})},Ol=({class:e,...t})=>g("li",{class:at("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1",e),...t}),ug=e=>{const t=e.split(".").pop();if(!t)throw new Error("No file extension found");return t?"."+t:""},dg=({allowedExtensions:e,files:t})=>{const n=e.map(r=>r.toLowerCase());return t.every(r=>n.includes(ug(r.name).toLowerCase()))},fg=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var l;const r=(l=L.current$.value.flow)==null?void 0:l.data.submissions[e.key],[i,o]=ie(cg(r)&&r.value!==null?r.value:[]),[s,a]=ie(),c=i.length-Ml,u=ag(i),d=Po();return g("form",{class:"flex flex-col gap-1 p-2.5",onSubmit:f=>(f.preventDefault(),a(void 0),i.length===0?a({type:"required",message:"Please select a file"}):e.config.extensions.length>0&&!dg({allowedExtensions:e.config.extensions,files:i})?a({type:"validate",message:`Please upload ${e.config.extensions.join(", ")} files only`}):e.config.fileSizeLimitKib&&u>e.config.fileSizeLimitKib?a({type:"max",message:`File size exceeds limit of ${Pn(e.config.fileSizeLimitKib)}`}):e.config.allowMultiple===!1&&i.length>1?a({type:"invalid",message:"Only one file is allowed"}):t(i)),children:[g("div",{class:"flex items-center gap-2",children:[g("label",{ref:d,for:"dropzone-file",class:"border-neutral-8 bg-neutral-2 flex h-48 w-full cursor-pointer flex-col items-center justify-center overflow-hidden rounded-2xl border border-dashed p-4",children:[i.length>0?g(Q,{children:[g("ul",{class:"flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",children:[i.slice(0,Ml).map(f=>{const p=f.name.split(".").pop(),h=f.name.replace(new RegExp(`.${p}$`),"");return g(Ol,{class:"flex overflow-hidden",children:[g("span",{class:"block truncate",children:h}),g("span",{children:[".",p]})]})}),c>0?g(Ol,{children:["+",c," file",c!==1?"s":""]}):null]}),g("p",{class:"text-neutral-11 text-xs",children:[Pn(u)," ",i.length>1?"total":""]})]}):g("div",{class:"flex flex-col justify-center gap-4 pb-6 pt-5",children:[g("header",{class:"flex flex-col items-center gap-0",children:[g("svg",{class:"text-neutral-11 mb-1 h-8 w-8","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 16",children:g("path",{stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"})}),g("p",{class:"text-neutral-12 tracking-[-0.01em]",children:[e.config.allowMultiple?"Select files":"Select a file"," to upload"]}),e.config.fileSizeLimitKib?g("p",{class:"text-neutral-10 text-xs",children:["(max ",Pn(e.config.fileSizeLimitKib),")"]}):null]}),g("aside",{class:"flex flex-col items-center gap-2",children:[g("p",{id:"accepted-filetypes",class:"sr-only",children:"Accepted file extensions"}),g("ul",{"aria-describedby":"accepted-filetypes",class:"flex flex-wrap justify-center gap-2",children:e.config.extensions.map(f=>g("li",{class:"ring-lowest outline-neutral-6 text-neutral-9 bg-neutral-1 rounded-md px-1 py-0.5 text-[11px] uppercase tracking-wide outline outline-1 ring-2",children:f.replace(".","")}))})]})]}),g("input",{id:"dropzone-file",onInput:async f=>{vt(f.target instanceof HTMLInputElement);const p=f.target.files?Array.from(f.target.files):[],h=await Promise.allSettled(p.map(async b=>{const x=await sg(b);return{name:b.name,data:x,sizeKb:b.size/1e3}}));if(h.some(({status:b})=>b==="rejected"))return a({type:"invalid",message:"Invalid file"});const v=h.map(b=>b.status==="fulfilled"?b.value:null).filter(Boolean);o(v)},multiple:e.config.allowMultiple,type:"file",class:"sr-only"})]}),g("div",{class:"flex h-full flex-col items-center gap-2",children:[g(Or,{disabled:i.length===0}),e.config.optional&&g(Fr,{onClick:()=>t(null)})]})]}),s&&g(Eo,{onAnimationComplete:n,error:s})]})};var Mn=e=>e.type==="checkbox",Jt=e=>e instanceof Date,ye=e=>e==null;const Fl=e=>typeof e=="object";var oe=e=>!ye(e)&&!Array.isArray(e)&&Fl(e)&&!Jt(e),pg=e=>oe(e)&&e.target?Mn(e.target)?e.target.checked:e.target.value:e,hg=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,vg=(e,t)=>e.has(hg(t)),mg=e=>{const t=e.constructor&&e.constructor.prototype;return oe(t)&&t.hasOwnProperty("isPrototypeOf")},To=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ze(e){let t;const n=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(To&&(e instanceof Blob||e instanceof FileList))&&(n||oe(e)))if(t=n?[]:{},!n&&!mg(e))t=e;else for(const r in e)e.hasOwnProperty(r)&&(t[r]=ze(e[r]));else return e;return t}var On=e=>Array.isArray(e)?e.filter(Boolean):[],te=e=>e===void 0,V=(e,t,n)=>{if(!t||!oe(e))return n;const r=On(t.split(/[,[\].]+?/)).reduce((i,o)=>ye(i)?i:i[o],e);return te(r)||r===e?te(e[t])?n:e[t]:r},ct=e=>typeof e=="boolean";const Il={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Me={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},He={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};Te.createContext(null);var gg=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const o in e)Object.defineProperty(i,o,{get:()=>{const s=o;return t._proxyFormState[s]!==Me.all&&(t._proxyFormState[s]=!r||Me.all),n&&(n[s]=!0),e[s]}});return i},Pe=e=>oe(e)&&!Object.keys(e).length,yg=(e,t,n,r)=>{n(e);const{name:i,...o}=e;return Pe(o)||Object.keys(o).length>=Object.keys(t).length||Object.keys(o).find(s=>t[s]===(!r||Me.all))},Vo=e=>Array.isArray(e)?e:[e];function bg(e){const t=Te.useRef(e);t.current=e,Te.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var Le=e=>typeof e=="string",wg=(e,t,n,r,i)=>Le(e)?(r&&t.watch.add(e),V(n,e,i)):Array.isArray(e)?e.map(o=>(r&&t.watch.add(o),V(n,o))):(r&&(t.watchAll=!0),n),Mo=e=>/^\w*$/.test(e),Dl=e=>On(e.replace(/["|']|\]/g,"").split(/\.|\[/));function G(e,t,n){let r=-1;const i=Mo(t)?[t]:Dl(t),o=i.length,s=o-1;for(;++r<o;){const a=i[r];let c=n;if(r!==s){const u=e[a];c=oe(u)||Array.isArray(u)?u:isNaN(+i[r+1])?{}:[]}e[a]=c,e=e[a]}return e}var Nl=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},Ll=e=>({isOnSubmit:!e||e===Me.onSubmit,isOnBlur:e===Me.onBlur,isOnChange:e===Me.onChange,isOnAll:e===Me.all,isOnTouch:e===Me.onTouched}),Rl=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Ir=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const o=V(e,i);if(o){const{_f:s,...a}=o;if(s){if(s.refs&&s.refs[0]&&t(s.refs[0],i)&&!r)break;if(s.ref&&t(s.ref,s.name)&&!r)break}else oe(a)&&Ir(a,t)}}};var _g=(e,t,n)=>{const r=On(V(e,n));return G(r,"root",t[n]),G(e,n,r),e},Oo=e=>e.type==="file",lt=e=>typeof e=="function",Dr=e=>{if(!To)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Nr=e=>Le(e),Fo=e=>e.type==="radio",Lr=e=>e instanceof RegExp;const Bl={value:!1,isValid:!1},jl={value:!0,isValid:!0};var Ul=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!te(e[0].attributes.value)?te(e[0].value)||e[0].value===""?jl:{value:e[0].value,isValid:!0}:jl:Bl}return Bl};const zl={isValid:!1,value:null};var Hl=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,zl):zl;function Wl(e,t,n="validate"){if(Nr(e)||Array.isArray(e)&&e.every(Nr)||ct(e)&&!e)return{type:n,message:Nr(e)?e:"",ref:t}}var en=e=>oe(e)&&!Lr(e)?e:{value:e,message:""},Kl=async(e,t,n,r,i)=>{const{ref:o,refs:s,required:a,maxLength:c,minLength:u,min:d,max:l,pattern:f,validate:p,name:h,valueAsNumber:v,mount:b,disabled:x}=e._f,y=V(t,h);if(!b||x)return{};const _=s?s[0]:o,C=U=>{r&&_.reportValidity&&(_.setCustomValidity(ct(U)?"":U||""),_.reportValidity())},S={},N=Fo(o),I=Mn(o),A=N||I,T=(v||Oo(o))&&te(o.value)&&te(y)||Dr(o)&&o.value===""||y===""||Array.isArray(y)&&!y.length,K=Nl.bind(null,h,n,S),J=(U,R,B,z=He.maxLength,ne=He.minLength)=>{const de=U?R:B;S[h]={type:U?z:ne,message:de,ref:o,...K(U?z:ne,de)}};if(i?!Array.isArray(y)||!y.length:a&&(!A&&(T||ye(y))||ct(y)&&!y||I&&!Ul(s).isValid||N&&!Hl(s).isValid)){const{value:U,message:R}=Nr(a)?{value:!!a,message:a}:en(a);if(U&&(S[h]={type:He.required,message:R,ref:_,...K(He.required,R)},!n))return C(R),S}if(!T&&(!ye(d)||!ye(l))){let U,R;const B=en(l),z=en(d);if(!ye(y)&&!isNaN(y)){const ne=o.valueAsNumber||y&&+y;ye(B.value)||(U=ne>B.value),ye(z.value)||(R=ne<z.value)}else{const ne=o.valueAsDate||new Date(y),de=Vt=>new Date(new Date().toDateString()+" "+Vt),We=o.type=="time",ut=o.type=="week";Le(B.value)&&y&&(U=We?de(y)>de(B.value):ut?y>B.value:ne>new Date(B.value)),Le(z.value)&&y&&(R=We?de(y)<de(z.value):ut?y<z.value:ne<new Date(z.value))}if((U||R)&&(J(!!U,B.message,z.message,He.max,He.min),!n))return C(S[h].message),S}if((c||u)&&!T&&(Le(y)||i&&Array.isArray(y))){const U=en(c),R=en(u),B=!ye(U.value)&&y.length>+U.value,z=!ye(R.value)&&y.length<+R.value;if((B||z)&&(J(B,U.message,R.message),!n))return C(S[h].message),S}if(f&&!T&&Le(y)){const{value:U,message:R}=en(f);if(Lr(U)&&!y.match(U)&&(S[h]={type:He.pattern,message:R,ref:o,...K(He.pattern,R)},!n))return C(R),S}if(p){if(lt(p)){const U=await p(y,t),R=Wl(U,_);if(R&&(S[h]={...R,...K(He.validate,R.message)},!n))return C(R.message),S}else if(oe(p)){let U={};for(const R in p){if(!Pe(U)&&!n)break;const B=Wl(await p[R](y,t),_,R);B&&(U={...B,...K(R,B.message)},C(B.message),n&&(S[h]=U))}if(!Pe(U)&&(S[h]={ref:_,...U},!n))return S}}return C(!0),S};function xg(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=te(e)?r++:e[t[r++]];return e}function kg(e){for(const t in e)if(e.hasOwnProperty(t)&&!te(e[t]))return!1;return!0}function ue(e,t){const n=Array.isArray(t)?t:Mo(t)?[t]:Dl(t),r=n.length===1?e:xg(e,n),i=n.length-1,o=n[i];return r&&delete r[o],i!==0&&(oe(r)&&Pe(r)||Array.isArray(r)&&kg(r))&&ue(e,n.slice(0,-1)),e}function Io(){let e=[];return{get observers(){return e},next:i=>{for(const o of e)o.next&&o.next(i)},subscribe:i=>(e.push(i),{unsubscribe:()=>{e=e.filter(o=>o!==i)}}),unsubscribe:()=>{e=[]}}}var Rr=e=>ye(e)||!Fl(e);function Tt(e,t){if(Rr(e)||Rr(t))return e===t;if(Jt(e)&&Jt(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const o=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const s=t[i];if(Jt(o)&&Jt(s)||oe(o)&&oe(s)||Array.isArray(o)&&Array.isArray(s)?!Tt(o,s):o!==s)return!1}}return!0}var ql=e=>e.type==="select-multiple",Sg=e=>Fo(e)||Mn(e),Do=e=>Dr(e)&&e.isConnected,Gl=e=>{for(const t in e)if(lt(e[t]))return!0;return!1};function Br(e,t={}){const n=Array.isArray(e);if(oe(e)||n)for(const r in e)Array.isArray(e[r])||oe(e[r])&&!Gl(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Br(e[r],t[r])):ye(e[r])||(t[r]=!0);return t}function Yl(e,t,n){const r=Array.isArray(e);if(oe(e)||r)for(const i in e)Array.isArray(e[i])||oe(e[i])&&!Gl(e[i])?te(t)||Rr(n[i])?n[i]=Array.isArray(e[i])?Br(e[i],[]):{...Br(e[i])}:Yl(e[i],ye(t)?{}:t[i],n[i]):n[i]=!Tt(e[i],t[i]);return n}var No=(e,t)=>Yl(e,t,Br(t)),Zl=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>te(e)?e:t?e===""?NaN:e&&+e:n&&Le(e)?new Date(e):r?r(e):e;function Lo(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return Oo(t)?t.files:Fo(t)?Hl(e.refs).value:ql(t)?[...t.selectedOptions].map(({value:n})=>n):Mn(t)?Ul(e.refs).value:Zl(te(t.value)?e.ref.value:t.value,e)}var Cg=(e,t,n,r)=>{const i={};for(const o of e){const s=V(t,o);s&&G(i,o,s._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Fn=e=>te(e)?e:Lr(e)?e.source:oe(e)?Lr(e.value)?e.value.source:e.value:e,$g=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Xl(e,t,n){const r=V(e,n);if(r||Mo(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const o=i.join("."),s=V(t,o),a=V(e,o);if(s&&!Array.isArray(s)&&n!==o)return{name:n};if(a&&a.type)return{name:o,error:a};i.pop()}return{name:n}}var Ag=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,Pg=(e,t)=>!On(V(e,t)).length&&ue(e,t);const Eg={mode:Me.onSubmit,reValidateMode:Me.onChange,shouldFocusError:!0};function Tg(e={},t){let n={...Eg,...e},r={submitCount:0,isDirty:!1,isLoading:lt(n.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},i={},o=oe(n.defaultValues)||oe(n.values)?ze(n.defaultValues||n.values)||{}:{},s=n.shouldUnregister?{}:ze(o),a={action:!1,mount:!1,watch:!1},c={mount:new Set,unMount:new Set,array:new Set,watch:new Set},u,d=0;const l={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Io(),array:Io(),state:Io()},p=e.resetOptions&&e.resetOptions.keepDirtyValues,h=Ll(n.mode),v=Ll(n.reValidateMode),b=n.criteriaMode===Me.all,x=m=>w=>{clearTimeout(d),d=setTimeout(m,w)},y=async m=>{if(l.isValid||m){const w=n.resolver?Pe((await T()).errors):await J(i,!0);w!==r.isValid&&f.state.next({isValid:w})}},_=m=>l.isValidating&&f.state.next({isValidating:m}),C=(m,w=[],k,M,P=!0,$=!0)=>{if(M&&k){if(a.action=!0,$&&Array.isArray(V(i,m))){const F=k(V(i,m),M.argA,M.argB);P&&G(i,m,F)}if($&&Array.isArray(V(r.errors,m))){const F=k(V(r.errors,m),M.argA,M.argB);P&&G(r.errors,m,F),Pg(r.errors,m)}if(l.touchedFields&&$&&Array.isArray(V(r.touchedFields,m))){const F=k(V(r.touchedFields,m),M.argA,M.argB);P&&G(r.touchedFields,m,F)}l.dirtyFields&&(r.dirtyFields=No(o,s)),f.state.next({name:m,isDirty:R(m,w),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else G(s,m,w)},S=(m,w)=>{G(r.errors,m,w),f.state.next({errors:r.errors})},N=(m,w,k,M)=>{const P=V(i,m);if(P){const $=V(s,m,te(k)?V(o,m):k);te($)||M&&M.defaultChecked||w?G(s,m,w?$:Lo(P._f)):ne(m,$),a.mount&&y()}},I=(m,w,k,M,P)=>{let $=!1,F=!1;const Z={name:m};if(!k||M){l.isDirty&&(F=r.isDirty,r.isDirty=Z.isDirty=R(),$=F!==Z.isDirty);const re=Tt(V(o,m),w);F=V(r.dirtyFields,m),re?ue(r.dirtyFields,m):G(r.dirtyFields,m,!0),Z.dirtyFields=r.dirtyFields,$=$||l.dirtyFields&&F!==!re}if(k){const re=V(r.touchedFields,m);re||(G(r.touchedFields,m,k),Z.touchedFields=r.touchedFields,$=$||l.touchedFields&&re!==k)}return $&&P&&f.state.next(Z),$?Z:{}},A=(m,w,k,M)=>{const P=V(r.errors,m),$=l.isValid&&ct(w)&&r.isValid!==w;if(e.delayError&&k?(u=x(()=>S(m,k)),u(e.delayError)):(clearTimeout(d),u=null,k?G(r.errors,m,k):ue(r.errors,m)),(k?!Tt(P,k):P)||!Pe(M)||$){const F={...M,...$&&ct(w)?{isValid:w}:{},errors:r.errors,name:m};r={...r,...F},f.state.next(F)}_(!1)},T=async m=>n.resolver(s,n.context,Cg(m||c.mount,i,n.criteriaMode,n.shouldUseNativeValidation)),K=async m=>{const{errors:w}=await T(m);if(m)for(const k of m){const M=V(w,k);M?G(r.errors,k,M):ue(r.errors,k)}else r.errors=w;return w},J=async(m,w,k={valid:!0})=>{for(const M in m){const P=m[M];if(P){const{_f:$,...F}=P;if($){const Z=c.array.has($.name),re=await Kl(P,s,b,n.shouldUseNativeValidation&&!w,Z);if(re[$.name]&&(k.valid=!1,w))break;!w&&(V(re,$.name)?Z?_g(r.errors,re,$.name):G(r.errors,$.name,re[$.name]):ue(r.errors,$.name))}F&&await J(F,w,k)}}return k.valid},U=()=>{for(const m of c.unMount){const w=V(i,m);w&&(w._f.refs?w._f.refs.every(k=>!Do(k)):!Do(w._f.ref))&&nn(m)}c.unMount=new Set},R=(m,w)=>(m&&w&&G(s,m,w),!Tt(dt(),o)),B=(m,w,k)=>wg(m,c,{...a.mount?s:te(w)?o:Le(m)?{[m]:w}:w},k,w),z=m=>On(V(a.mount?s:o,m,e.shouldUnregister?V(o,m,[]):[])),ne=(m,w,k={})=>{const M=V(i,m);let P=w;if(M){const $=M._f;$&&(!$.disabled&&G(s,m,Zl(w,$)),P=Dr($.ref)&&ye(w)?"":w,ql($.ref)?[...$.ref.options].forEach(F=>F.selected=P.includes(F.value)):$.refs?Mn($.ref)?$.refs.length>1?$.refs.forEach(F=>(!F.defaultChecked||!F.disabled)&&(F.checked=Array.isArray(P)?!!P.find(Z=>Z===F.value):P===F.value)):$.refs[0]&&($.refs[0].checked=!!P):$.refs.forEach(F=>F.checked=F.value===P):Oo($.ref)?$.ref.value="":($.ref.value=P,$.ref.type||f.values.next({name:m,values:{...s}})))}(k.shouldDirty||k.shouldTouch)&&I(m,P,k.shouldTouch,k.shouldDirty,!0),k.shouldValidate&&Y(m)},de=(m,w,k)=>{for(const M in w){const P=w[M],$=`${m}.${M}`,F=V(i,$);(c.array.has(m)||!Rr(P)||F&&!F._f)&&!Jt(P)?de($,P,k):ne($,P,k)}},We=(m,w,k={})=>{const M=V(i,m),P=c.array.has(m),$=ze(w);G(s,m,$),P?(f.array.next({name:m,values:{...s}}),(l.isDirty||l.dirtyFields)&&k.shouldDirty&&f.state.next({name:m,dirtyFields:No(o,s),isDirty:R(m,$)})):M&&!M._f&&!ye($)?de(m,$,k):ne(m,$,k),Rl(m,c)&&f.state.next({...r}),f.values.next({name:m,values:{...s}}),!a.mount&&t()},ut=async m=>{const w=m.target;let k=w.name,M=!0;const P=V(i,k),$=()=>w.type?Lo(P._f):pg(m),F=Z=>{M=Number.isNaN(Z)||Z===V(s,k,Z)};if(P){let Z,re;const Hr=$(),rn=m.type===Il.BLUR||m.type===Il.FOCUS_OUT,ay=!$g(P._f)&&!n.resolver&&!V(r.errors,k)&&!P._f.deps||Ag(rn,V(r.touchedFields,k),r.isSubmitted,v,h),Ro=Rl(k,c,rn);G(s,k,Hr),rn?(P._f.onBlur&&P._f.onBlur(m),u&&u(0)):P._f.onChange&&P._f.onChange(m);const Bo=I(k,Hr,rn,!1),cy=!Pe(Bo)||Ro;if(!rn&&f.values.next({name:k,type:m.type,values:{...s}}),ay)return l.isValid&&y(),cy&&f.state.next({name:k,...Ro?{}:Bo});if(!rn&&Ro&&f.state.next({...r}),_(!0),n.resolver){const{errors:su}=await T([k]);if(F(Hr),M){const ly=Xl(r.errors,i,k),au=Xl(su,i,ly.name||k);Z=au.error,k=au.name,re=Pe(su)}}else Z=(await Kl(P,s,b,n.shouldUseNativeValidation))[k],F(Hr),M&&(Z?re=!1:l.isValid&&(re=await J(i,!0)));M&&(P._f.deps&&Y(P._f.deps),A(k,re,Z,Bo))}},Vt=(m,w)=>{if(V(r.errors,w)&&m.focus)return m.focus(),1},Y=async(m,w={})=>{let k,M;const P=Vo(m);if(_(!0),n.resolver){const $=await K(te(m)?m:P);k=Pe($),M=m?!P.some(F=>V($,F)):k}else m?(M=(await Promise.all(P.map(async $=>{const F=V(i,$);return await J(F&&F._f?{[$]:F}:F)}))).every(Boolean),!(!M&&!r.isValid)&&y()):M=k=await J(i);return f.state.next({...!Le(m)||l.isValid&&k!==r.isValid?{}:{name:m},...n.resolver||!m?{isValid:k}:{},errors:r.errors,isValidating:!1}),w.shouldFocus&&!M&&Ir(i,Vt,m?P:c.mount),M},dt=m=>{const w={...o,...a.mount?s:{}};return te(m)?w:Le(m)?V(w,m):m.map(k=>V(w,k))},In=(m,w)=>({invalid:!!V((w||r).errors,m),isDirty:!!V((w||r).dirtyFields,m),isTouched:!!V((w||r).touchedFields,m),error:V((w||r).errors,m)}),jr=m=>{m&&Vo(m).forEach(w=>ue(r.errors,w)),f.state.next({errors:m?r.errors:{}})},Dn=(m,w,k)=>{const M=(V(i,m,{_f:{}})._f||{}).ref;G(r.errors,m,{...w,ref:M}),f.state.next({name:m,errors:r.errors,isValid:!1}),k&&k.shouldFocus&&M&&M.focus&&M.focus()},Mt=(m,w)=>lt(m)?f.values.subscribe({next:k=>m(B(void 0,w),k)}):B(m,w,!0),nn=(m,w={})=>{for(const k of m?Vo(m):c.mount)c.mount.delete(k),c.array.delete(k),w.keepValue||(ue(i,k),ue(s,k)),!w.keepError&&ue(r.errors,k),!w.keepDirty&&ue(r.dirtyFields,k),!w.keepTouched&&ue(r.touchedFields,k),!n.shouldUnregister&&!w.keepDefaultValue&&ue(o,k);f.values.next({values:{...s}}),f.state.next({...r,...w.keepDirty?{isDirty:R()}:{}}),!w.keepIsValid&&y()},Ur=({disabled:m,name:w,field:k,fields:M,value:P})=>{if(ct(m)){const $=m?void 0:te(P)?Lo(k?k._f:V(M,w)._f):P;G(s,w,$),I(w,$,!1,!1,!0)}},Ot=(m,w={})=>{let k=V(i,m);const M=ct(w.disabled);return G(i,m,{...k||{},_f:{...k&&k._f?k._f:{ref:{name:m}},name:m,mount:!0,...w}}),c.mount.add(m),k?Ur({field:k,disabled:w.disabled,name:m}):N(m,!0,w.value),{...M?{disabled:w.disabled}:{},...n.progressive?{required:!!w.required,min:Fn(w.min),max:Fn(w.max),minLength:Fn(w.minLength),maxLength:Fn(w.maxLength),pattern:Fn(w.pattern)}:{},name:m,onChange:ut,onBlur:ut,ref:P=>{if(P){Ot(m,w),k=V(i,m);const $=te(P.value)&&P.querySelectorAll&&P.querySelectorAll("input,select,textarea")[0]||P,F=Sg($),Z=k._f.refs||[];if(F?Z.find(re=>re===$):$===k._f.ref)return;G(i,m,{_f:{...k._f,...F?{refs:[...Z.filter(Do),$,...Array.isArray(V(o,m))?[{}]:[]],ref:{type:$.type,name:m}}:{ref:$}}}),N(m,!1,void 0,$)}else k=V(i,m,{}),k._f&&(k._f.mount=!1),(n.shouldUnregister||w.shouldUnregister)&&!(vg(c.array,m)&&a.action)&&c.unMount.add(m)}}},Ft=()=>n.shouldFocusError&&Ir(i,Vt,c.mount),Ke=m=>{ct(m)&&(f.state.next({disabled:m}),Ir(i,w=>{w.disabled=m},0,!1))},Nn=(m,w)=>async k=>{k&&(k.preventDefault&&k.preventDefault(),k.persist&&k.persist());let M=ze(s);if(f.state.next({isSubmitting:!0}),n.resolver){const{errors:P,values:$}=await T();r.errors=P,M=$}else await J(i);ue(r.errors,"root"),Pe(r.errors)?(f.state.next({errors:{}}),await m(M,k)):(w&&await w({...r.errors},k),Ft(),setTimeout(Ft)),f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Pe(r.errors),submitCount:r.submitCount+1,errors:r.errors})},zr=(m,w={})=>{V(i,m)&&(te(w.defaultValue)?We(m,V(o,m)):(We(m,w.defaultValue),G(o,m,w.defaultValue)),w.keepTouched||ue(r.touchedFields,m),w.keepDirty||(ue(r.dirtyFields,m),r.isDirty=w.defaultValue?R(m,V(o,m)):R()),w.keepError||(ue(r.errors,m),l.isValid&&y()),f.state.next({...r}))},iu=(m,w={})=>{const k=m?ze(m):o,M=ze(k),P=m&&!Pe(m)?M:o;if(w.keepDefaultValues||(o=k),!w.keepValues){if(w.keepDirtyValues||p)for(const $ of c.mount)V(r.dirtyFields,$)?G(P,$,V(s,$)):We($,V(P,$));else{if(To&&te(m))for(const $ of c.mount){const F=V(i,$);if(F&&F._f){const Z=Array.isArray(F._f.refs)?F._f.refs[0]:F._f.ref;if(Dr(Z)){const re=Z.closest("form");if(re){re.reset();break}}}}i={}}s=e.shouldUnregister?w.keepDefaultValues?ze(o):{}:ze(P),f.array.next({values:{...P}}),f.values.next({values:{...P}})}c={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!a.mount&&t(),a.mount=!l.isValid||!!w.keepIsValid,a.watch=!!e.shouldUnregister,f.state.next({submitCount:w.keepSubmitCount?r.submitCount:0,isDirty:w.keepDirty?r.isDirty:!!(w.keepDefaultValues&&!Tt(m,o)),isSubmitted:w.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:w.keepDirtyValues?r.dirtyFields:w.keepDefaultValues&&m?No(o,m):{},touchedFields:w.keepTouched?r.touchedFields:{},errors:w.keepErrors?r.errors:{},isSubmitSuccessful:w.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1})},ou=(m,w)=>iu(lt(m)?m(s):m,w);return{control:{register:Ot,unregister:nn,getFieldState:In,handleSubmit:Nn,setError:Dn,_executeSchema:T,_getWatch:B,_getDirty:R,_updateValid:y,_removeUnmounted:U,_updateFieldArray:C,_updateDisabledField:Ur,_getFieldArray:z,_reset:iu,_resetDefaultValues:()=>lt(n.defaultValues)&&n.defaultValues().then(m=>{ou(m,n.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:m=>{r={...r,...m}},_disableForm:Ke,_subjects:f,_proxyFormState:l,get _fields(){return i},get _formValues(){return s},get _state(){return a},set _state(m){a=m},get _defaultValues(){return o},get _names(){return c},set _names(m){c=m},get _formState(){return r},set _formState(m){r=m},get _options(){return n},set _options(m){n={...n,...m}}},trigger:Y,register:Ot,handleSubmit:Nn,watch:Mt,setValue:We,getValues:dt,reset:ou,resetField:zr,clearErrors:jr,unregister:nn,setError:Dn,setFocus:(m,w={})=>{const k=V(i,m),M=k&&k._f;if(M){const P=M.refs?M.refs[0]:M.ref;P.focus&&(P.focus(),w.shouldSelect&&P.select())}},getFieldState:In}}function Ql(e={}){const t=Te.useRef(),n=Te.useRef(),[r,i]=Te.useState({isDirty:!1,isValidating:!1,isLoading:lt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:lt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Tg(e,()=>i(s=>({...s}))),formState:r});const o=t.current.control;return o._options=e,bg({subject:o._subjects.state,next:s=>{yg(s,o._proxyFormState,o._updateFormState,!0)&&i({...o._formState})}}),Te.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),Te.useEffect(()=>{if(o._proxyFormState.isDirty){const s=o._getDirty();s!==r.isDirty&&o._subjects.state.next({isDirty:s})}},[o,r.isDirty]),Te.useEffect(()=>{e.values&&!Tt(e.values,n.current)?(o._reset(e.values,o._options.resetOptions),n.current=e.values):o._resetDefaultValues()},[e.values,o]),Te.useEffect(()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),t.current.formState=gg(r,o),t.current}var Jl=function(e,t,n){if(e&&"reportValidity"in e){var r=V(n,t);e.setCustomValidity(r&&r.message||""),e.reportValidity()}},Vg=function(e,t){var n=function(i){var o=t.fields[i];o&&o.ref&&"reportValidity"in o.ref?Jl(o.ref,i,e):o.refs&&o.refs.forEach(function(s){return Jl(s,i,e)})};for(var r in t.fields)n(r)},Mg=function(e,t){t.shouldUseNativeValidation&&Vg(e,t);var n={};for(var r in e){var i=V(t.fields,r),o=Object.assign(e[r]||{},{ref:i&&i.ref});if(Fg(t.names||Object.keys(e),r)){var s=Object.assign({},Og(V(n,r)));G(s,"root",o),G(n,r,s)}else G(n,r,o)}return n},Og=function(e){return Array.isArray(e)?e.filter(Boolean):[]},Fg=function(e,t){return e.some(function(n){return n.startsWith(t+".")})},Ig=function(e,t){for(var n={};e.issues.length;){var r=e.issues[0];if(r.path){var i=r.path.map(function(a){return a.key}).join(".");if(n[i]||(n[i]={message:r.message,type:r.validation}),t){var o=n[i].types,s=o&&o[r.validation];n[i]=Nl(i,t,n,r.validation,s?[].concat(s,r.message):r.message)}e.issues.shift()}}return n},eu=function(e,t,n){return n===void 0&&(n={}),function(r,i,o){try{return Promise.resolve(function(s,a){try{var c=function(){function u(l){return{values:n.raw?r:l,errors:{}}}var d=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},t);return n.mode==="sync"?u(cn(e,r,d)):Promise.resolve(ku(e,r,d)).then(u)}()}catch(u){return a(u)}return c&&c.then?c.then(void 0,a):c}(0,function(s){if(s instanceof Yr)return{values:{},errors:Mg(Ig(s,!o.shouldUseNativeValidation&&o.criteriaMode==="all"),o)};throw s}))}catch(s){return Promise.reject(s)}}};const Dg=27,Ng=12,Lg=10,Rg=e=>{const t=Object.fromEntries(new FormData(e).entries());Object.keys(t).length&&e.dispatchEvent(new Event("submit",{bubbles:!0}))},Bg=wo("multiple-choice"),jg=e=>{const t={min:e.minSelected??0,max:e.maxSelected??e.options.length};return eu(Ze({checked:us(ls(yu()),n=>Object.entries(n).filter(([r,i])=>i).map(([r,i])=>r),[$u(t.max,`Please select at most ${t.max} option${t.max!==1?"s":""}`),ds(t.min,`Please select at least ${t.min} option${t.min!==1?"s":""}`)])}))},Ug=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var u,d;const r=e.key?(u=L.current$.value.flow)==null?void 0:u.data.submissions[e.key]:void 0,i=(e.config.minSelected===1||e.config.minSelected===void 0)&&e.config.maxSelected===1,{register:o,handleSubmit:s,formState:{errors:a}}=Ql({defaultValues:{checked:i?{}:Bg(r)?Object.fromEntries(r.value.map(l=>[l,!0])):{}},resolver:jg(e.config)}),c=Po();return g("form",{noValidate:!0,class:"flex flex-col gap-1 pr-2.5",onChange:l=>{i&&Rg(l.currentTarget)},onSubmit:s(l=>{const f=l.checked;t(f)}),children:[g("div",{class:"flex items-center gap-1",children:[g("ul",{style:{maxHeight:6.5*Dg+5*Ng+2*Lg},class:at("gutter-stable flex w-full flex-1 flex-wrap gap-3 overflow-y-auto rounded-xl p-2.5 pr-4",{"justify-center":e.config.options.length===1}),children:e.config.options.map((l,f)=>{const p=`checked.${l.value}`,{ref:h,...v}=o(p);return g("li",{class:"relative",children:[g("input",{autoFocus:f===0,ref:b=>{b&&f===0&&(c.current=b),h(b)},id:p,...v,class:"peer sr-only h-full",type:"checkbox"}),g("label",{class:"bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-divider text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 block rounded-2xl px-2.5 py-1 outline outline-2 ring-0 ring-transparent transition-all selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",htmlFor:p,children:l.label})]},l.value)})}),g("div",{class:"flex flex-col items-center gap-2",children:[!i&&g(Or,{}),e.config.minSelected===0&&g(Fr,{type:"button",onClick:()=>t([])})]})]}),g("div",{class:"px-1",children:g(Eo,{onAnimationComplete:n,error:(d=a.checked)==null?void 0:d.root})})]})},zg=({input:e,onSubmitSuccess:t})=>g("div",{class:"flex flex-col items-center py-3",children:g("button",{class:"bg-accent-9 hover:bg-accent-10 active:bg-submit-bg-active hover:border-accent-10 active:border-submit-bg-active border-accent-9 ring-accent-6 focus-visible:outline-accent-8 ring-offset-neutral-1 group flex cursor-pointer rounded-full border border-solid px-5 py-3 pr-4 text-white shadow-[inset_0px_-6px_2px_-1px_oklch(100_0_0/.45),inset_0px_1px_1px_oklch(100_0_0/.3)] outline-none ring-1 ring-offset-[1.5px] transition-all duration-300 focus-visible:outline-2 active:shadow-[inset_0px_0px_2px_-1px_oklch(100_0_0/.45),inset_0px_3px_1px_.5px_oklch(0_0_0/.08)] active:ring-2 active:ring-offset-2",name:e.key,onClick:()=>{t(null)},children:g("span",{class:"relative bottom-[2px] top-[-2px] flex items-center gap-1.5 transition-all duration-300 group-active:bottom-0 group-active:top-0",children:[g("span",{class:"inline-flex items-center text-sm font-medium",children:e.config.label}),g("svg",{stroke:"currentColor","stroke-width":"1.5",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("path",{d:"M4 8L8 4L12 8"}),g("path",{d:"M8 4V13"})]})]})})}),tn={empty:"Please enter some text",email:"That doesn’t look like a valid email address",phone:"That doesn’t look like a valid phone number",url:"That doesn’t look like a valid URL"},Hg=$e(tn.phone,[Au(/^\+?[0-9 -]+$/,tn.phone)]),Wg={email:{type:"email",inputMode:"email",formNoValidate:!0},phone:{type:"tel",inputMode:"tel"},text:{type:"text",inputMode:"text"},url:{type:"url",inputMode:"url",formNoValidate:!0}},Kg=wo("text"),qg=e=>eu(Ze({text:{email:$e(tn.email,[Cu(tn.email)]),phone:us(Hg,t=>t.replace(/[^0-9]/g,"")),text:$e([ds(1,tn.empty)]),url:$e([Pu(tn.url)])}[e.format]})),Gg=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var l;const r=e.key?(l=L.current$.value.flow)==null?void 0:l.data.submissions[e.key]:void 0,i=e.config.defaultValue,{register:o,handleSubmit:s,formState:{errors:a}}=Ql({defaultValues:{text:i||(Kg(r)?r.value:"")},resolver:qg(e.config)}),{ref:c,...u}=o("text",{required:!e.config.optional}),d=j();return Ae(()=>{d.current&&(d.current.focus(),d.current.select())},[]),g(Q,{children:g("form",{noValidate:!0,class:"flex flex-col gap-1 p-2.5",onSubmit:s(f=>{t(f.text)}),children:[g("div",{class:"flex items-center gap-2",children:[g("div",{class:"relative min-w-0 flex-grow",children:[g("input",{id:"chat-input",...u,...Wg[e.config.format],autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:f=>{f&&(d.current=f),c(f)},class:"outline-divider ease-expo-out placeholder:text-neutral-10 text-neutral-12 focus-visible:outline-accent-7 caret-accent-9 bg-lowest w-full rounded-full px-3 py-1 text-base outline outline-2 transition-all",placeholder:e.config.placeholder}),e.config.optional&&g(Fr,{class:"absolute right-0 top-0",onClick:()=>t(null)})]}),g(Or,{})]}),g(Eo,{onAnimationComplete:n,error:a.text})]})})},Yg=()=>{var i;const e=(i=L.current$.value.flow)==null?void 0:i.data.currentInput,t=j(null),n=ae(()=>{t.current&&(L.inputHeight$.value=t.current.getBoundingClientRect().height)},[]);W(()=>{n()},[e==null?void 0:e.type,n]);const r=o=>s=>Ve.onSubmitSuccessFn$.value({type:o,value:s});return g(xr.div,{initial:{height:0},animate:{height:L.inputHeight$.value},exit:{height:0,opacity:0},onAnimationStart:Ve.scrollToEnd.smooth,onAnimationComplete:Ve.scrollToEnd.smooth,class:"bg-statusbar absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",children:g("div",{ref:t,class:"border-divider border-t",children:Ue({input:e,onHeightChange:n}).with({input:_e.nullish},()=>g("div",{class:"flex items-center gap-2 p-2.5",children:[g("input",{"aria-hidden":"true",id:"chat-input",class:"outline-divider flex-grow rounded-full bg-transparent px-3 py-1 text-base outline outline-2",disabled:!0}),g(Or,{disabled:!0,"aria-hidden":"true",tabIndex:-1})]})).with({input:{type:"text"}},o=>g(Gg,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"multiple-choice"}},o=>g(Ug,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"boolean"}},o=>g(og,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"file"}},o=>g(fg,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"submit"}},o=>g(zg,{onSubmitSuccess:r(o.input.type),...o})).exhaustive()})})},tu=e=>typeof e=="boolean"?"".concat(e):e===0?"0":e,nu=at,ru=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return nu(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:o}=t,s=Object.keys(i).map(u=>{const d=n==null?void 0:n[u],l=o==null?void 0:o[u];if(d===null)return null;const f=tu(d)||tu(l);return i[u][f]}),a=n&&Object.entries(n).reduce((u,d)=>{let[l,f]=d;return f===void 0||(u[l]=f),u},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,d)=>{let{class:l,className:f,...p}=d;return Object.entries(p).every(h=>{let[v,b]=h;return Array.isArray(b)?b.includes({...o,...a}[v]):{...o,...a}[v]===b})?[...u,l,f]:u},[]);return nu(e,s,c,n==null?void 0:n.class,n==null?void 0:n.className)},Zg=ru("max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink min-w-[2rem] py-2 px-3 rounded-[18px] min-h-[36px] break-words relative",{variants:{side:{left:"bg-bubble-weak-bg text-neutral-12 shadow-surface-sm outline outline-1 outline-bubble-weak rounded-bl-md",right:"ml-auto bg-accent-9 text-white rounded-br-md shadow-surface-sm shadow-bubble-strong-shadow"},transitionState:{entering:"opacity-0 translate-y-8",entered:"opacity-100 translate-y-0",exiting:"opacity-0 scale-0",exited:""}},defaultVariants:{side:"left"}}),Xg={hidden:{y:"100%",scale:.75},shown:{y:0,scale:1}},Qg=({children:e,className:t,transitionState:n,side:r,...i})=>g(xr.p,{variants:Xg,initial:"hidden",animate:"shown",transition:{type:"spring",damping:25,stiffness:500},"data-transition":n,style:{transformOrigin:r==="left"?"0% 50%":"100% 50%"},class:Zg({className:t,side:r,transitionState:n}),...i,children:e}),Jg=({className:e,...t})=>(W(()=>{Ve.scrollToEnd.smooth()}),g("div",{"aria-hidden":!0,children:Ve.isBotTyping$.value===!0?g("div",{"aria-label":"Typing…",class:at("flex gap-1 p-4",e),...t,children:Array.from({length:3},(n,r)=>g("div",{class:"bg-accent-9 h-1.5 w-1.5 animate-bounce rounded-full",style:{animationDelay:`${-r*200}ms`}}))}):void 0})),ey={bot:"left",user:"right"},ty=ru("w-full select-none py-2 text-wrap-balance text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_var(--i-color-n-1)]",{variants:{variant:{info:"text-neutral-8",warning:"text-[#FFC107]",error:"text-error-9",success:"text-[#4CAF50]"}}}),ny=({lastSentMessageFooter:e})=>{var n;const t=((n=L.current$.value.flow)==null?void 0:n.data.messages)??[];return W(()=>{Ve.scrollToEnd.smooth()},[t.length]),g("ol",{"aria-label":"Chat messages",class:"flex flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",children:[g(nl,{initial:!1,children:t.map((r,i)=>g(Q,{children:g("li",{class:"flex",children:Ue(r).with({type:"system"},o=>g("p",{class:ty({variant:o.variant}),children:o.text})).with({type:"text",author:_e.union("bot","user")},o=>{const s=o.author==="user"&&!t.slice(i+1).some(a=>a.type==="text"&&a.author==="user");return g(Qg,{side:ey[o.author],children:[o.text,s?e:null]},i)}).with({type:"link"},o=>g("div",{class:"bg-accent-3 flex w-full items-center justify-center overflow-hidden rounded-xl px-2 py-2",children:g("a",{class:"bg-lowest shadow-surface-sm ring-accent-6 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 text-wrap-balance flex items-center gap-1.5 rounded-full py-2 pl-4 pr-2.5 text-center no-underline ring-1 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2",target:"_blank",href:o.href,children:[o.text,g("svg",{class:"flex-none",width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:g("path",{d:"M3.64645 11.3536C3.45118 11.1583 3.45118 10.8417 3.64645 10.6465L10.2929 4L6 4C5.72386 4 5.5 3.77614 5.5 3.5C5.5 3.22386 5.72386 3 6 3L11.5 3C11.6326 3 11.7598 3.05268 11.8536 3.14645C11.9473 3.24022 12 3.36739 12 3.5L12 9.00001C12 9.27615 11.7761 9.50001 11.5 9.50001C11.2239 9.50001 11 9.27615 11 9.00001V4.70711L4.35355 11.3536C4.15829 11.5488 3.84171 11.5488 3.64645 11.3536Z",fill:"currentColor","fill-rule":"evenodd","clip-rule":"evenodd"})})]})})).with({type:"image"},o=>g("img",{class:"shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",src:o.url,style:{aspectRatio:o.width/o.height}})).with({type:"file"},o=>g(lg,{class:o.author==="bot"?"":"ml-auto",file:{name:o.fileName,sizeKb:o.fileSizeKb}})).exhaustive()})},i))}),g(Jg,{},"typing")]})},ry=({logger:e,apiClient:t,analytics:n})=>{const{flow:r}=L.current$.value;vt(r,"Flow is required to exist to show chatbot body");const i=L.viewState$.value,{chatRef:o,chatService:s}=ng(),[a,c]=ie();return Ae(()=>{i==="maximised"&&Ve.scrollToEnd.instant()},[i]),Ae(()=>{const{state:u,flow:d}=L.current$.peek();if(u!=="loaded")throw new Error(Wv.invalid_state);let l=d.data.nodeHistory.at(-1);if(Ve.scrollToEnd.instant(),L.setInput(void 0),d.data.isFinished)return;l===void 0?(l=wl(r.nodes).id,L.setCurrentNodeId(l)):L.removeMessagesSentByNodeIds([l]);const{interpret:f,abort:p,undo:h}=Rm({context:r.context,analytics:n,apiClient:t,logger:e,flow:r.nodes,chatService:s,getSubmissions:()=>{var v;return(v=L.current$.peek().flow)==null?void 0:v.data.submissions},onInterpret:(v,b)=>{const x=L.current$.peek().flow;vt(x),b&&(x.data.sequence=x.data.sequence+1,n.log({event:"FLOW_NODE",properties:{flow_id:r.id,flow_version:r.version,from_node_id:b.id,to_node_id:v.id,sequence:x.data.sequence,flow_session_id:x.data.flowSessionId},customProperties:r.context})),L.setCurrentNodeId(v.id)},onFlowEnd:async()=>{L.markAsFinished()}});return c(()=>h),f(l),p},[n,t,s,e,r]),g(Q,{children:[g("div",{ref:o,className:"hide-scrollbars relative flex w-full max-w-full flex-grow flex-col overflow-y-scroll",style:{WebkitOverflowScrolling:"touch",paddingBottom:L.inputHeight$.value},children:g(ny,{lastSentMessageFooter:r.data.isFinished||!a?null:g(oy,{undoFn:a})})}),g(Yg,{})]})},iy=e=>"key"in e.data&&e.data.key?[e.data.key]:"keys"in e.data?Object.values(e.data.keys).filter(t=>typeof t=="string"):[],oy=({undoFn:e})=>g("div",{class:"absolute bottom-0 right-0 flex w-full translate-y-full justify-end",children:g("button",{class:"fr touch-hitbox text-neutral-9 hover:text-neutral-12 rounded-full p-1 text-right text-xs transition-all",onClick:async()=>{const{flow:t}=L.current$.peek();vt(t);const{removed:n}=e(t.data.nodeHistory),r=t.data.nodeHistory.splice(-n);r.length!==0&&(L.removeMessagesSentByNodeIds(r),L.setInput(void 0),r.pop(),r.map(i=>t.nodes.find(o=>o.id===i)).filter(Boolean).flatMap(iy).forEach(i=>delete t.data.submissions[i]),L.current$.value={...L.current$.value})},children:"Undo"})}),sy=Object.freeze(Object.defineProperty({__proto__:null,ChatbotBody:ry},Symbol.toStringTag,{value:"Module"}))})();
53
+ }`},Nm=({_internal_domManager:e=Am(),theme:t})=>ft(({apiClient:n,logger:r,analytics:i})=>{let o=!1;const s=()=>{if(typeof window>"u")return;const a=[O("style",{id:"inploi-chatbot-styles"},$m),O("style",{id:"inploi-chatbot-theme"},Dm(t))],c=e.getOrCreateChatbotElement();Dt(O(Q,{},[a,O(xm,{apiClient:n,logger:r,analytics:i})]),c),o=!0};return{prepare:async()=>{if(!(typeof window>"u"))try{if(o)return;s(),r.info("Chatbot plugin prepared")}catch(a){r.error("Error preparing chatbot plugin",a)}},fetchFlowByJobId:async a=>n.fetch(`/flow/job/${a}`).then(c=>{const u=cn(Sm,c);return{context:{job_id:u.job.id,flow_id:u.flow.id},flow:u.flow,title:`Applying for “${u.job.title}”`,flowKeys:[u.job.id]}}),fetchFlowById:async a=>n.fetch(`/flow/id/${a}`).then(c=>{const u=cn(km,c);return{flow:u.flow,context:{flow_id:u.flow.id},title:"Chatbot",flowKeys:[]}}),open:async a=>{if(!(typeof window>"u"))try{L.cancelCurrentFlow(),L.viewState$.value="maximised",o||s(),a instanceof Promise?(L.current$.value={state:"loading"},a.then(async c=>{const u=cn(Cm,c);L.startFlow(u)}).catch(c=>{const u=c instanceof Error?c.message:"An error occurred";L.current$.value={state:"error",error:u}})):L.startFlow(a)}catch(c){r.error("Error starting flow",c)}},startApplication:void 0,closeApplication:void 0,close:async()=>{typeof window>"u"||(L.cancelCurrentFlow(),r.info("Closed flow from an external source"))}}});if(!window.inploi)throw new Error("Please insert the SDK script tag above the plugins.");window.inploi.chatbotPlugin=Nm;const Al=({node:e,nodes:t,stopWhen:n})=>{if((n==null?void 0:n(e))===!0)return e;const r=e.nextId?t.find(i=>i.id===e.nextId):void 0;if(r)return Al({node:r,nodes:t,stopWhen:n})},Lm=({childNode:e,nodes:t})=>{const r=t.filter(i=>i.type==="if-block").find(i=>{if(!i.branchId)return!1;const o=t.find(a=>a.id===i.branchId);if(!o)return!1;const s=Al({node:o,nodes:t,stopWhen:a=>a.id===e.id});return!(!s||s.id!==e.id)});if(r!=null&&r.nextId)return t.find(i=>i.id===r.nextId)},Rm=({flow:e,analytics:t,logger:n,context:r,apiClient:i,getSubmissions:o,chatService:s,onFlowEnd:a,onInterpret:c})=>{let u=new AbortController;const d=async(l,f)=>{const p=o();c==null||c(l,f);try{await Bm({analytics:t,logger:n,apiClient:i,context:r,node:l,submissions:p,chat:{sendMessage:async h=>s.send({groupId:l.id,message:h,signal:u.signal}),userInput:async h=>s.input({input:h,signal:u.signal})},next:h=>{const v=h?e.find(b=>b.id===h):Lm({childNode:l,nodes:e});return v?d(v,l):a==null?void 0:a(l)},end:()=>a==null?void 0:a(l)})}catch(h){if(h instanceof En)return;throw h}};return{interpret:async l=>{const f=e.find(p=>p.id===l)??wl(e);return d(f)},undo:l=>{let f=1;const p=e.find(v=>v.id===l[l.length-1]);for(let v=l.length-2;v>0;v--){const b=l[v],x=e.find(y=>y.id===b);if(!x||(f++,x.type.startsWith("question-")))break}u.abort(),u=new AbortController;const h=e.find(v=>v.id===l[l.length-f]);return vt(h,"Undo failed: new start node not found"),d(h,p),{removed:f}},abort:()=>{u.abort()}}};async function Bm(e){return await Ue(e).with({node:{type:"text"}},Hm).with({node:{type:"image"}},Wm).with({node:{type:"question-text"}},Km).with({node:{type:"question-enum"}},Gm).with({node:{type:"question-number"}},qm).with({node:{type:"question-boolean"}},Ym).with({node:{type:"question-file"}},Qm).with({node:{type:"question-address"}},Xm).with({node:{type:"end-flow"}},Jm).with({node:{type:"if-block"}},zm).with({node:{type:"jump"}},({node:t,next:n})=>n(t.data.targetId)).with({node:{type:"link"}},Um).with({node:{type:"integration-application-submit"}},jm).with({node:{type:"integration-workflow-get"}},()=>Error("Unreachable")).exhaustive()}async function jm({chat:e,next:t,node:n,logger:r,apiClient:i,submissions:o,context:s,analytics:a}){await e.userInput({type:"submit",key:void 0,config:{label:"Submit my application"}});const c=()=>{const f=typeof s.job_id=="string"?s.job_id:void 0,p=typeof s.flow_id=="string"?s.flow_id:void 0;!f||!p||f&&a.log({event:"APPLY_COMPLETE",attributionKey:`job_${f}`,properties:{job_id:f,flow_id:p}})};await e.sendMessage({type:"system",variant:"info",text:"Submitting your application…"});const{anonymous_id:u,session_id:d}=a.getSessionInfo(),l=await i.fetch("/flow/apply",{method:"POST",body:JSON.stringify({...s,integration_id:n.data.integrationId,anonymous_id:u,session_id:d,submissions:lm(o||{})})}).catch(f=>f);await Ue(l).with({ats_data:{redirect_url:_e.string}},async f=>{await e.sendMessage({type:"text",author:"bot",text:"Almost there! Please finalise your application on our partner’s website."});const p=new URL(f.ats_data.redirect_url);u&&!p.searchParams.has("anonymous_id")&&p.searchParams.set("anonymous_id",u),c(),await e.sendMessage({type:"link",href:p.toString(),text:"Finalise application on partner"}),t(n.nextId)}).with({success:!0},async()=>{c(),await e.sendMessage({type:"system",variant:"success",text:"Application submitted"}),t(n.nextId)}).otherwise(async f=>{r.error(f),await e.sendMessage({type:"system",variant:"error",text:"Failed to submit application"}),t(n.id)})}async function Um({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({type:"link",href:n.data.href,text:Et(n.data.cta,r)}),t(n.nextId)}async function zm({submissions:e,next:t,node:n}){const r=eg(n,e)?n.branchId:n.nextId;t(r)}async function Hm({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.text,r)}),t(n.nextId)}async function Wm({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"image",url:n.data.url,height:n.data.height,width:n.data.width}),t(n.nextId)}async function Km({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const i=await e.userInput({key:n.data.key,type:"text",config:{optional:n.data.optional,placeholder:n.data.placeholder,format:n.data.format}});i.value===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:i.value}),t(n.nextId)}async function qm({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const i=await e.userInput({key:n.data.key,type:"text",config:{optional:n.data.optional,placeholder:n.data.placeholder,format:"text"}});i.value===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:i.value}),t(n.nextId)}async function Gm({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const i=await e.userInput({key:n.data.key,type:"multiple-choice",config:n.data});i.value.length===0?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:n.data.options.filter(o=>i.value.includes(o.value)).map(o=>o.label).join(", ")}),t(n.nextId)}async function Ym({chat:e,next:t,node:n,submissions:r}){await e.sendMessage({author:"bot",type:"text",text:Et(n.data.question,r)});const o=(await e.userInput({key:n.data.key,type:"boolean",config:{optional:n.data.optional,labels:{true:n.data.trueLabel,false:n.data.falseLabel}}})).value;o===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:{true:n.data.trueLabel,false:n.data.falseLabel}[o]}),t(n.nextId)}const Zm=document.createElement("div"),Pl={line1:["street_number","floor","room","premise"],line2:["subpremise","street_address","route"],line3:["sublocality","neighborhood"],city:["locality","postal_town"],state:["administrative_area_level_1"],postcode:["postal_code"],country:["country"]},El=Object.keys(Pl);async function Xm({chat:e,next:t,node:n,logger:r}){if(El.every(h=>n.data.keys[h]===null))return t(n.nextId);const{google:i}=window;await e.sendMessage({author:"bot",type:"text",text:n.data.question});const o=async h=>{const v=[{label:"Postcode",key:n.data.keys.postcode,optional:!1,defaultValue:h.postcode},{label:"Line 1",key:n.data.keys.line1,optional:!1,defaultValue:h.line1},{label:"Line 2",key:n.data.keys.line2,optional:!0,defaultValue:h.line2},{label:"Line 3",key:n.data.keys.line3,optional:!0,defaultValue:h.line3},{label:"City",key:n.data.keys.city,optional:!1,defaultValue:h.city},{label:"State/County/Province",key:n.data.keys.state,optional:!0,defaultValue:h.state},{label:"Country",key:n.data.keys.country,optional:!1,defaultValue:h.country}];for(const b of v){if(b.key===null)continue;await e.sendMessage({author:"bot",type:"text",text:b.label});const{value:x}=await e.userInput({type:"text",key:b.key,config:{format:"text",optional:b.optional,defaultValue:b.defaultValue}});x===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:x})}};if(!Zr(window,"google")||!Zr(window.google,"maps")||!Zr(window.google.maps,"places"))return r.warn("Google maps not available, falling back to manual input."),r.info("If you’d like to use the address autocomplete, please insert the google maps API snippet in your website and make sure it has access to the *places* library."),await o({}),t(n.nextId);const s=new i.maps.places.AutocompleteService,a=new i.maps.places.PlacesService(Zm),{value:c}=await e.userInput({type:"text",key:"_internal-address-search",config:{format:"text",optional:!1,placeholder:"Search for your address"}});if(c===null)return t(n.id);await e.sendMessage({author:"user",type:"text",text:`Search for “${c}”`});const{predictions:u}=await s.getPlacePredictions({input:c}),{value:[d]}=await e.userInput({type:"multiple-choice",key:void 0,config:{options:u.slice(0,4).map(h=>({label:h.description,value:h.place_id})).concat({label:"None of these",value:"none"}),maxSelected:1,minSelected:1}});if(!d||d==="none")return t(n.id);const l=await new Promise((h,v)=>a.getDetails({placeId:d,fields:["address_components"]},(b,x)=>x!==i.maps.places.PlacesServiceStatus.OK?v(x):b===null?v("ZERO_RESULTS"):h({ok:!0,place:b}))).catch(async h=>(r.error("Failed to get address details",h),{ok:!1}));if(l.ok===!1)return await e.sendMessage({type:"system",variant:"error",text:"Failed to get address details"}),await o({}),t(n.id);const f=l.place.address_components,p=f?El.reduce((h,v)=>{const b=Pl[v],x=f.filter(y=>y.types.some(_=>b.includes(_))).map(y=>y.long_name).join(", ");return x&&(h[v]=x),h},{}):{};return await e.sendMessage({author:"bot",type:"text",text:"Please confirm or adjust your address:"}),await o(p),t(n.nextId)}async function Qm({node:e,chat:t,next:n,submissions:r}){await t.sendMessage({author:"bot",type:"text",text:Et(e.data.question,r)});const i=await t.userInput({key:e.data.key,type:"file",config:{optional:e.data.optional,extensions:e.data.extensions,fileSizeLimitKib:e.data.maxSizeKb??10*1024,allowMultiple:e.data.multiple===!0}});if(i.value===null)await t.sendMessage({type:"system",variant:"info",text:"Skipped"});else for(const o of i.value)await t.sendMessage({author:"user",type:"file",fileName:o.name,fileSizeKb:o.sizeKb});n(e.nextId)}async function Jm({chat:e,end:t,node:n}){await e.sendMessage({type:"system",variant:"info",text:n.data.systemMessage}),t()}const Tl=_e.union(_e.string,_e.array(_e.string),null),eg=(e,t)=>{const n=t==null?void 0:t[e.data.compareKey];return n?Ue({...e.data,answer:n}).with({compare:"equals"},({compareValue:r})=>typeof n.value=="string"||typeof n.value=="boolean"?r===n.value.toString():!1).with({compare:"notEquals"},({compareValue:r})=>typeof n.value=="string"||typeof n.value=="boolean"?r!==n.value.toString():!1).with({compare:"contains",answer:{value:Tl}},({compareValue:r,answer:i})=>i.value!==null&&i.value.includes(r)).with({compare:"notContains",answer:{value:Tl}},({compareValue:r,answer:i})=>i.value===null||!i.value.includes(r)).with({answer:{type:"file"}},()=>!1).exhaustive():!1},Et=(e,t)=>{const n=/{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g;return e.replace(n,(r,i,o="")=>{i=i.trim();const s=t==null?void 0:t[i];if(!s)return o;switch(s.type){case"boolean":return s.value==="true"?"true":"false";case"file":return s.value?s.value.map(a=>`${a.name} (${Pn(a.sizeKb)})`).join(", "):"no files";case"multiple-choice":return s.value.join(", ");default:return s.value||o}})},Or=({class:e,...t})=>g("button",{class:at("bg-accent-9 active:bg-accent-10 pointer-coarse:touch-hitbox fr flex-shrink-0 rounded-full p-2 text-white transition-all disabled:cursor-not-allowed disabled:opacity-50",e),type:"submit",...t,children:g("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"2",children:[g("title",{children:"Send"}),g("path",{d:"M3.5 7.5L8 3L12.5 7.5"}),g("path",{d:"M8 4V13"})]})}),tg=25,Ao=it({instant:()=>{},smooth:()=>{}}),Ve={onSubmitSuccessFn$:it(()=>{}),isBotTyping$:it(!1),scrollToEnd:{instant:()=>Ao.value.instant(),smooth:()=>Ao.value.smooth()}},ng=()=>{const e=j(null);Ae(()=>{Ao.value={instant:()=>{var n;return(n=e.current)==null?void 0:n.scrollTo({top:e.current.scrollHeight,behavior:"instant"})},smooth:()=>{e.current&&e.current.scrollHeight-e.current.scrollTop<=e.current.clientHeight*1.5&&e.current.scrollTo({top:e.current.scrollHeight,behavior:"smooth"})}}},[e]);const t=se(()=>({send:async({message:n,signal:r,groupId:i})=>{if(await Ue(n).with({author:"bot",type:"text"},async o=>{if(r!=null&&r.aborted)throw new En;Ve.isBotTyping$.value=!0;const s=Math.min(Math.max(20,o.text.length),100)*tg;await new Promise(a=>setTimeout(a,s,{signal:r})),Ve.isBotTyping$.value=!1}).otherwise(async()=>{}),r!=null&&r.aborted)throw new En;L.addMessage(n,i)},input:async({input:n,signal:r})=>{if(r!=null&&r.aborted)throw new En;return L.setInput(n),await new Promise(i=>{const o=s=>{if(r!=null&&r.aborted)throw new En;L.setInput(void 0),n.key&&L.setSubmission(n.key,s),i(s)};Ve.onSubmitSuccessFn$.value=o})}}),[]);return{chatRef:e,chatService:t}},Fr=({class:e,...t})=>g("button",{type:"button",class:at("fr text-neutral-9 flex flex-shrink-0 items-center justify-center gap-1 rounded-full py-[6px] pl-2 pr-3 text-sm underline-offset-2 transition-all",e),...t,children:[g("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"1.5",children:[g("title",{children:"Skip"}),g("path",{d:"M3.25 11.25A5 5 0 0 1 12 7"}),g("path",{d:"M13.25 4.5V8.25H9.5"})]}),"Skip"]}),Po=()=>{const e=j(null);return W(()=>{var t;(t=e.current)==null||t.focus()},[]),e},Vl=["true","false"],rg=wu(Vl),ig="answer",og=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{const r=Po();return n(),g("form",{noValidate:!0,class:"",onSubmit:i=>{i.preventDefault();const o=Ue(i).with({nativeEvent:{submitter:_e.select(_e.union(_e.instanceOf(HTMLButtonElement),_e.instanceOf(HTMLInputElement)))}},a=>a.value).otherwise(()=>{throw new Error("invalid form")}),s=cn(rg,o);t(s)},children:[g("div",{class:"flex items-center gap-2 p-2.5",children:Vl.map((i,o)=>g("button",{ref:o===0?r:null,type:"submit",name:ig,value:i,class:"bg-lowest ease-expo-out ring-divider text-neutral-12 active:ring-accent-7 active:bg-accent-2 active:text-accent-11 fr block flex-1 overflow-hidden rounded-2xl px-2.5 py-2.5 ring-2 transition-all selection:bg-transparent",children:g("p",{class:"truncate text-center text-base",children:e.config.labels[i]})}))}),e.config.optional&&g("div",{class:"px-2 pb-2",children:g(Fr,{class:"w-full",type:"button",onClick:()=>t(null)})})]})},Eo=({error:e,onAnimationComplete:t})=>(Ae(()=>{e&&t()},[e,t]),e?g("div",{role:"alert",class:"text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full px-2 py-2",children:[g("svg",{class:"text-error-9 h-4 w-4",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"8",cy:"8",r:"6.3",stroke:"currentColor","stroke-width":"1.4"}),g("rect",{x:"7",y:"4",width:"2",height:"5",fill:"currentColor"}),g("rect",{x:"7",y:"10",width:"2",height:"2",fill:"currentColor"})]}),g("p",{class:"truncate pr-1 text-sm",children:e.message})]}):null),sg=e=>new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>r.result?t(r.result.toString()):n("No result from reader"),r.onerror=n}),ag=e=>e.reduce((t,n)=>t+n.sizeKb,0),cg=wo("file"),Ml=3,lg=({file:e,class:t,...n})=>{const r=e.name.split(".").pop(),i=e.name.replace(new RegExp(`.${r}$`),"");return g("div",{class:at("bg-accent-1 outline-accent-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline",t),...n,children:[g("p",{"aria-label":"File name",class:"text-accent-12 flex flex-grow overflow-hidden",children:[g("span",{class:"block truncate",children:i}),g("span",{children:[".",r]})]}),g("p",{"aria-label":"File size",class:"text-accent-11",children:Pn(e.sizeKb)})]})},Ol=({class:e,...t})=>g("li",{class:at("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1",e),...t}),ug=e=>{const t=e.split(".").pop();if(!t)throw new Error("No file extension found");return t?"."+t:""},dg=({allowedExtensions:e,files:t})=>{const n=e.map(r=>r.toLowerCase());return t.every(r=>n.includes(ug(r.name).toLowerCase()))},fg=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var l;const r=(l=L.current$.value.flow)==null?void 0:l.data.submissions[e.key],[i,o]=ie(cg(r)&&r.value!==null?r.value:[]),[s,a]=ie(),c=i.length-Ml,u=ag(i),d=Po();return g("form",{class:"flex flex-col gap-1 p-2.5",onSubmit:f=>(f.preventDefault(),a(void 0),i.length===0?a({type:"required",message:"Please select a file"}):e.config.extensions.length>0&&!dg({allowedExtensions:e.config.extensions,files:i})?a({type:"validate",message:`Please upload ${e.config.extensions.join(", ")} files only`}):e.config.fileSizeLimitKib&&u>e.config.fileSizeLimitKib?a({type:"max",message:`File size exceeds limit of ${Pn(e.config.fileSizeLimitKib)}`}):e.config.allowMultiple===!1&&i.length>1?a({type:"invalid",message:"Only one file is allowed"}):t(i)),children:[g("div",{class:"flex items-center gap-2",children:[g("label",{ref:d,for:"dropzone-file",class:"border-neutral-8 bg-neutral-2 flex h-48 w-full cursor-pointer flex-col items-center justify-center overflow-hidden rounded-2xl border border-dashed p-4",children:[i.length>0?g(Q,{children:[g("ul",{class:"flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",children:[i.slice(0,Ml).map(f=>{const p=f.name.split(".").pop(),h=f.name.replace(new RegExp(`.${p}$`),"");return g(Ol,{class:"flex overflow-hidden",children:[g("span",{class:"block truncate",children:h}),g("span",{children:[".",p]})]})}),c>0?g(Ol,{children:["+",c," file",c!==1?"s":""]}):null]}),g("p",{class:"text-neutral-11 text-xs",children:[Pn(u)," ",i.length>1?"total":""]})]}):g("div",{class:"flex flex-col justify-center gap-4 pb-6 pt-5",children:[g("header",{class:"flex flex-col items-center gap-0",children:[g("svg",{class:"text-neutral-11 mb-1 h-8 w-8","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 16",children:g("path",{stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"})}),g("p",{class:"text-neutral-12 tracking-[-0.01em]",children:[e.config.allowMultiple?"Select files":"Select a file"," to upload"]}),e.config.fileSizeLimitKib?g("p",{class:"text-neutral-10 text-xs",children:["(max ",Pn(e.config.fileSizeLimitKib),")"]}):null]}),g("aside",{class:"flex flex-col items-center gap-2",children:[g("p",{id:"accepted-filetypes",class:"sr-only",children:"Accepted file extensions"}),g("ul",{"aria-describedby":"accepted-filetypes",class:"flex flex-wrap justify-center gap-2",children:e.config.extensions.map(f=>g("li",{class:"ring-lowest outline-neutral-6 text-neutral-9 bg-neutral-1 rounded-md px-1 py-0.5 text-[11px] uppercase tracking-wide outline outline-1 ring-2",children:f.replace(".","")}))})]})]}),g("input",{id:"dropzone-file",onInput:async f=>{vt(f.target instanceof HTMLInputElement);const p=f.target.files?Array.from(f.target.files):[],h=await Promise.allSettled(p.map(async b=>{const x=await sg(b);return{name:b.name,data:x,sizeKb:b.size/1e3}}));if(h.some(({status:b})=>b==="rejected"))return a({type:"invalid",message:"Invalid file"});const v=h.map(b=>b.status==="fulfilled"?b.value:null).filter(Boolean);o(v)},multiple:e.config.allowMultiple,type:"file",class:"sr-only"})]}),g("div",{class:"flex h-full flex-col items-center gap-2",children:[g(Or,{disabled:i.length===0}),e.config.optional&&g(Fr,{onClick:()=>t(null)})]})]}),s&&g(Eo,{onAnimationComplete:n,error:s})]})};var Mn=e=>e.type==="checkbox",Jt=e=>e instanceof Date,ye=e=>e==null;const Fl=e=>typeof e=="object";var oe=e=>!ye(e)&&!Array.isArray(e)&&Fl(e)&&!Jt(e),pg=e=>oe(e)&&e.target?Mn(e.target)?e.target.checked:e.target.value:e,hg=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,vg=(e,t)=>e.has(hg(t)),mg=e=>{const t=e.constructor&&e.constructor.prototype;return oe(t)&&t.hasOwnProperty("isPrototypeOf")},To=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ze(e){let t;const n=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(To&&(e instanceof Blob||e instanceof FileList))&&(n||oe(e)))if(t=n?[]:{},!n&&!mg(e))t=e;else for(const r in e)e.hasOwnProperty(r)&&(t[r]=ze(e[r]));else return e;return t}var On=e=>Array.isArray(e)?e.filter(Boolean):[],te=e=>e===void 0,V=(e,t,n)=>{if(!t||!oe(e))return n;const r=On(t.split(/[,[\].]+?/)).reduce((i,o)=>ye(i)?i:i[o],e);return te(r)||r===e?te(e[t])?n:e[t]:r},ct=e=>typeof e=="boolean";const Il={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Me={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},He={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};Te.createContext(null);var gg=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const o in e)Object.defineProperty(i,o,{get:()=>{const s=o;return t._proxyFormState[s]!==Me.all&&(t._proxyFormState[s]=!r||Me.all),n&&(n[s]=!0),e[s]}});return i},Pe=e=>oe(e)&&!Object.keys(e).length,yg=(e,t,n,r)=>{n(e);const{name:i,...o}=e;return Pe(o)||Object.keys(o).length>=Object.keys(t).length||Object.keys(o).find(s=>t[s]===(!r||Me.all))},Vo=e=>Array.isArray(e)?e:[e];function bg(e){const t=Te.useRef(e);t.current=e,Te.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var Le=e=>typeof e=="string",wg=(e,t,n,r,i)=>Le(e)?(r&&t.watch.add(e),V(n,e,i)):Array.isArray(e)?e.map(o=>(r&&t.watch.add(o),V(n,o))):(r&&(t.watchAll=!0),n),Mo=e=>/^\w*$/.test(e),Dl=e=>On(e.replace(/["|']|\]/g,"").split(/\.|\[/));function G(e,t,n){let r=-1;const i=Mo(t)?[t]:Dl(t),o=i.length,s=o-1;for(;++r<o;){const a=i[r];let c=n;if(r!==s){const u=e[a];c=oe(u)||Array.isArray(u)?u:isNaN(+i[r+1])?{}:[]}e[a]=c,e=e[a]}return e}var Nl=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},Ll=e=>({isOnSubmit:!e||e===Me.onSubmit,isOnBlur:e===Me.onBlur,isOnChange:e===Me.onChange,isOnAll:e===Me.all,isOnTouch:e===Me.onTouched}),Rl=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Ir=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const o=V(e,i);if(o){const{_f:s,...a}=o;if(s){if(s.refs&&s.refs[0]&&t(s.refs[0],i)&&!r)break;if(s.ref&&t(s.ref,s.name)&&!r)break}else oe(a)&&Ir(a,t)}}};var _g=(e,t,n)=>{const r=On(V(e,n));return G(r,"root",t[n]),G(e,n,r),e},Oo=e=>e.type==="file",lt=e=>typeof e=="function",Dr=e=>{if(!To)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Nr=e=>Le(e),Fo=e=>e.type==="radio",Lr=e=>e instanceof RegExp;const Bl={value:!1,isValid:!1},jl={value:!0,isValid:!0};var Ul=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!te(e[0].attributes.value)?te(e[0].value)||e[0].value===""?jl:{value:e[0].value,isValid:!0}:jl:Bl}return Bl};const zl={isValid:!1,value:null};var Hl=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,zl):zl;function Wl(e,t,n="validate"){if(Nr(e)||Array.isArray(e)&&e.every(Nr)||ct(e)&&!e)return{type:n,message:Nr(e)?e:"",ref:t}}var en=e=>oe(e)&&!Lr(e)?e:{value:e,message:""},Kl=async(e,t,n,r,i)=>{const{ref:o,refs:s,required:a,maxLength:c,minLength:u,min:d,max:l,pattern:f,validate:p,name:h,valueAsNumber:v,mount:b,disabled:x}=e._f,y=V(t,h);if(!b||x)return{};const _=s?s[0]:o,C=U=>{r&&_.reportValidity&&(_.setCustomValidity(ct(U)?"":U||""),_.reportValidity())},S={},N=Fo(o),I=Mn(o),A=N||I,T=(v||Oo(o))&&te(o.value)&&te(y)||Dr(o)&&o.value===""||y===""||Array.isArray(y)&&!y.length,K=Nl.bind(null,h,n,S),J=(U,R,B,z=He.maxLength,ne=He.minLength)=>{const de=U?R:B;S[h]={type:U?z:ne,message:de,ref:o,...K(U?z:ne,de)}};if(i?!Array.isArray(y)||!y.length:a&&(!A&&(T||ye(y))||ct(y)&&!y||I&&!Ul(s).isValid||N&&!Hl(s).isValid)){const{value:U,message:R}=Nr(a)?{value:!!a,message:a}:en(a);if(U&&(S[h]={type:He.required,message:R,ref:_,...K(He.required,R)},!n))return C(R),S}if(!T&&(!ye(d)||!ye(l))){let U,R;const B=en(l),z=en(d);if(!ye(y)&&!isNaN(y)){const ne=o.valueAsNumber||y&&+y;ye(B.value)||(U=ne>B.value),ye(z.value)||(R=ne<z.value)}else{const ne=o.valueAsDate||new Date(y),de=Vt=>new Date(new Date().toDateString()+" "+Vt),We=o.type=="time",ut=o.type=="week";Le(B.value)&&y&&(U=We?de(y)>de(B.value):ut?y>B.value:ne>new Date(B.value)),Le(z.value)&&y&&(R=We?de(y)<de(z.value):ut?y<z.value:ne<new Date(z.value))}if((U||R)&&(J(!!U,B.message,z.message,He.max,He.min),!n))return C(S[h].message),S}if((c||u)&&!T&&(Le(y)||i&&Array.isArray(y))){const U=en(c),R=en(u),B=!ye(U.value)&&y.length>+U.value,z=!ye(R.value)&&y.length<+R.value;if((B||z)&&(J(B,U.message,R.message),!n))return C(S[h].message),S}if(f&&!T&&Le(y)){const{value:U,message:R}=en(f);if(Lr(U)&&!y.match(U)&&(S[h]={type:He.pattern,message:R,ref:o,...K(He.pattern,R)},!n))return C(R),S}if(p){if(lt(p)){const U=await p(y,t),R=Wl(U,_);if(R&&(S[h]={...R,...K(He.validate,R.message)},!n))return C(R.message),S}else if(oe(p)){let U={};for(const R in p){if(!Pe(U)&&!n)break;const B=Wl(await p[R](y,t),_,R);B&&(U={...B,...K(R,B.message)},C(B.message),n&&(S[h]=U))}if(!Pe(U)&&(S[h]={ref:_,...U},!n))return S}}return C(!0),S};function xg(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=te(e)?r++:e[t[r++]];return e}function kg(e){for(const t in e)if(e.hasOwnProperty(t)&&!te(e[t]))return!1;return!0}function ue(e,t){const n=Array.isArray(t)?t:Mo(t)?[t]:Dl(t),r=n.length===1?e:xg(e,n),i=n.length-1,o=n[i];return r&&delete r[o],i!==0&&(oe(r)&&Pe(r)||Array.isArray(r)&&kg(r))&&ue(e,n.slice(0,-1)),e}function Io(){let e=[];return{get observers(){return e},next:i=>{for(const o of e)o.next&&o.next(i)},subscribe:i=>(e.push(i),{unsubscribe:()=>{e=e.filter(o=>o!==i)}}),unsubscribe:()=>{e=[]}}}var Rr=e=>ye(e)||!Fl(e);function Tt(e,t){if(Rr(e)||Rr(t))return e===t;if(Jt(e)&&Jt(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const o=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const s=t[i];if(Jt(o)&&Jt(s)||oe(o)&&oe(s)||Array.isArray(o)&&Array.isArray(s)?!Tt(o,s):o!==s)return!1}}return!0}var ql=e=>e.type==="select-multiple",Sg=e=>Fo(e)||Mn(e),Do=e=>Dr(e)&&e.isConnected,Gl=e=>{for(const t in e)if(lt(e[t]))return!0;return!1};function Br(e,t={}){const n=Array.isArray(e);if(oe(e)||n)for(const r in e)Array.isArray(e[r])||oe(e[r])&&!Gl(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Br(e[r],t[r])):ye(e[r])||(t[r]=!0);return t}function Yl(e,t,n){const r=Array.isArray(e);if(oe(e)||r)for(const i in e)Array.isArray(e[i])||oe(e[i])&&!Gl(e[i])?te(t)||Rr(n[i])?n[i]=Array.isArray(e[i])?Br(e[i],[]):{...Br(e[i])}:Yl(e[i],ye(t)?{}:t[i],n[i]):n[i]=!Tt(e[i],t[i]);return n}var No=(e,t)=>Yl(e,t,Br(t)),Zl=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>te(e)?e:t?e===""?NaN:e&&+e:n&&Le(e)?new Date(e):r?r(e):e;function Lo(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return Oo(t)?t.files:Fo(t)?Hl(e.refs).value:ql(t)?[...t.selectedOptions].map(({value:n})=>n):Mn(t)?Ul(e.refs).value:Zl(te(t.value)?e.ref.value:t.value,e)}var Cg=(e,t,n,r)=>{const i={};for(const o of e){const s=V(t,o);s&&G(i,o,s._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Fn=e=>te(e)?e:Lr(e)?e.source:oe(e)?Lr(e.value)?e.value.source:e.value:e,$g=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Xl(e,t,n){const r=V(e,n);if(r||Mo(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const o=i.join("."),s=V(t,o),a=V(e,o);if(s&&!Array.isArray(s)&&n!==o)return{name:n};if(a&&a.type)return{name:o,error:a};i.pop()}return{name:n}}var Ag=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,Pg=(e,t)=>!On(V(e,t)).length&&ue(e,t);const Eg={mode:Me.onSubmit,reValidateMode:Me.onChange,shouldFocusError:!0};function Tg(e={},t){let n={...Eg,...e},r={submitCount:0,isDirty:!1,isLoading:lt(n.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},i={},o=oe(n.defaultValues)||oe(n.values)?ze(n.defaultValues||n.values)||{}:{},s=n.shouldUnregister?{}:ze(o),a={action:!1,mount:!1,watch:!1},c={mount:new Set,unMount:new Set,array:new Set,watch:new Set},u,d=0;const l={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Io(),array:Io(),state:Io()},p=e.resetOptions&&e.resetOptions.keepDirtyValues,h=Ll(n.mode),v=Ll(n.reValidateMode),b=n.criteriaMode===Me.all,x=m=>w=>{clearTimeout(d),d=setTimeout(m,w)},y=async m=>{if(l.isValid||m){const w=n.resolver?Pe((await T()).errors):await J(i,!0);w!==r.isValid&&f.state.next({isValid:w})}},_=m=>l.isValidating&&f.state.next({isValidating:m}),C=(m,w=[],k,M,P=!0,$=!0)=>{if(M&&k){if(a.action=!0,$&&Array.isArray(V(i,m))){const F=k(V(i,m),M.argA,M.argB);P&&G(i,m,F)}if($&&Array.isArray(V(r.errors,m))){const F=k(V(r.errors,m),M.argA,M.argB);P&&G(r.errors,m,F),Pg(r.errors,m)}if(l.touchedFields&&$&&Array.isArray(V(r.touchedFields,m))){const F=k(V(r.touchedFields,m),M.argA,M.argB);P&&G(r.touchedFields,m,F)}l.dirtyFields&&(r.dirtyFields=No(o,s)),f.state.next({name:m,isDirty:R(m,w),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else G(s,m,w)},S=(m,w)=>{G(r.errors,m,w),f.state.next({errors:r.errors})},N=(m,w,k,M)=>{const P=V(i,m);if(P){const $=V(s,m,te(k)?V(o,m):k);te($)||M&&M.defaultChecked||w?G(s,m,w?$:Lo(P._f)):ne(m,$),a.mount&&y()}},I=(m,w,k,M,P)=>{let $=!1,F=!1;const Z={name:m};if(!k||M){l.isDirty&&(F=r.isDirty,r.isDirty=Z.isDirty=R(),$=F!==Z.isDirty);const re=Tt(V(o,m),w);F=V(r.dirtyFields,m),re?ue(r.dirtyFields,m):G(r.dirtyFields,m,!0),Z.dirtyFields=r.dirtyFields,$=$||l.dirtyFields&&F!==!re}if(k){const re=V(r.touchedFields,m);re||(G(r.touchedFields,m,k),Z.touchedFields=r.touchedFields,$=$||l.touchedFields&&re!==k)}return $&&P&&f.state.next(Z),$?Z:{}},A=(m,w,k,M)=>{const P=V(r.errors,m),$=l.isValid&&ct(w)&&r.isValid!==w;if(e.delayError&&k?(u=x(()=>S(m,k)),u(e.delayError)):(clearTimeout(d),u=null,k?G(r.errors,m,k):ue(r.errors,m)),(k?!Tt(P,k):P)||!Pe(M)||$){const F={...M,...$&&ct(w)?{isValid:w}:{},errors:r.errors,name:m};r={...r,...F},f.state.next(F)}_(!1)},T=async m=>n.resolver(s,n.context,Cg(m||c.mount,i,n.criteriaMode,n.shouldUseNativeValidation)),K=async m=>{const{errors:w}=await T(m);if(m)for(const k of m){const M=V(w,k);M?G(r.errors,k,M):ue(r.errors,k)}else r.errors=w;return w},J=async(m,w,k={valid:!0})=>{for(const M in m){const P=m[M];if(P){const{_f:$,...F}=P;if($){const Z=c.array.has($.name),re=await Kl(P,s,b,n.shouldUseNativeValidation&&!w,Z);if(re[$.name]&&(k.valid=!1,w))break;!w&&(V(re,$.name)?Z?_g(r.errors,re,$.name):G(r.errors,$.name,re[$.name]):ue(r.errors,$.name))}F&&await J(F,w,k)}}return k.valid},U=()=>{for(const m of c.unMount){const w=V(i,m);w&&(w._f.refs?w._f.refs.every(k=>!Do(k)):!Do(w._f.ref))&&nn(m)}c.unMount=new Set},R=(m,w)=>(m&&w&&G(s,m,w),!Tt(dt(),o)),B=(m,w,k)=>wg(m,c,{...a.mount?s:te(w)?o:Le(m)?{[m]:w}:w},k,w),z=m=>On(V(a.mount?s:o,m,e.shouldUnregister?V(o,m,[]):[])),ne=(m,w,k={})=>{const M=V(i,m);let P=w;if(M){const $=M._f;$&&(!$.disabled&&G(s,m,Zl(w,$)),P=Dr($.ref)&&ye(w)?"":w,ql($.ref)?[...$.ref.options].forEach(F=>F.selected=P.includes(F.value)):$.refs?Mn($.ref)?$.refs.length>1?$.refs.forEach(F=>(!F.defaultChecked||!F.disabled)&&(F.checked=Array.isArray(P)?!!P.find(Z=>Z===F.value):P===F.value)):$.refs[0]&&($.refs[0].checked=!!P):$.refs.forEach(F=>F.checked=F.value===P):Oo($.ref)?$.ref.value="":($.ref.value=P,$.ref.type||f.values.next({name:m,values:{...s}})))}(k.shouldDirty||k.shouldTouch)&&I(m,P,k.shouldTouch,k.shouldDirty,!0),k.shouldValidate&&Y(m)},de=(m,w,k)=>{for(const M in w){const P=w[M],$=`${m}.${M}`,F=V(i,$);(c.array.has(m)||!Rr(P)||F&&!F._f)&&!Jt(P)?de($,P,k):ne($,P,k)}},We=(m,w,k={})=>{const M=V(i,m),P=c.array.has(m),$=ze(w);G(s,m,$),P?(f.array.next({name:m,values:{...s}}),(l.isDirty||l.dirtyFields)&&k.shouldDirty&&f.state.next({name:m,dirtyFields:No(o,s),isDirty:R(m,$)})):M&&!M._f&&!ye($)?de(m,$,k):ne(m,$,k),Rl(m,c)&&f.state.next({...r}),f.values.next({name:m,values:{...s}}),!a.mount&&t()},ut=async m=>{const w=m.target;let k=w.name,M=!0;const P=V(i,k),$=()=>w.type?Lo(P._f):pg(m),F=Z=>{M=Number.isNaN(Z)||Z===V(s,k,Z)};if(P){let Z,re;const Hr=$(),rn=m.type===Il.BLUR||m.type===Il.FOCUS_OUT,ay=!$g(P._f)&&!n.resolver&&!V(r.errors,k)&&!P._f.deps||Ag(rn,V(r.touchedFields,k),r.isSubmitted,v,h),Ro=Rl(k,c,rn);G(s,k,Hr),rn?(P._f.onBlur&&P._f.onBlur(m),u&&u(0)):P._f.onChange&&P._f.onChange(m);const Bo=I(k,Hr,rn,!1),cy=!Pe(Bo)||Ro;if(!rn&&f.values.next({name:k,type:m.type,values:{...s}}),ay)return l.isValid&&y(),cy&&f.state.next({name:k,...Ro?{}:Bo});if(!rn&&Ro&&f.state.next({...r}),_(!0),n.resolver){const{errors:su}=await T([k]);if(F(Hr),M){const ly=Xl(r.errors,i,k),au=Xl(su,i,ly.name||k);Z=au.error,k=au.name,re=Pe(su)}}else Z=(await Kl(P,s,b,n.shouldUseNativeValidation))[k],F(Hr),M&&(Z?re=!1:l.isValid&&(re=await J(i,!0)));M&&(P._f.deps&&Y(P._f.deps),A(k,re,Z,Bo))}},Vt=(m,w)=>{if(V(r.errors,w)&&m.focus)return m.focus(),1},Y=async(m,w={})=>{let k,M;const P=Vo(m);if(_(!0),n.resolver){const $=await K(te(m)?m:P);k=Pe($),M=m?!P.some(F=>V($,F)):k}else m?(M=(await Promise.all(P.map(async $=>{const F=V(i,$);return await J(F&&F._f?{[$]:F}:F)}))).every(Boolean),!(!M&&!r.isValid)&&y()):M=k=await J(i);return f.state.next({...!Le(m)||l.isValid&&k!==r.isValid?{}:{name:m},...n.resolver||!m?{isValid:k}:{},errors:r.errors,isValidating:!1}),w.shouldFocus&&!M&&Ir(i,Vt,m?P:c.mount),M},dt=m=>{const w={...o,...a.mount?s:{}};return te(m)?w:Le(m)?V(w,m):m.map(k=>V(w,k))},In=(m,w)=>({invalid:!!V((w||r).errors,m),isDirty:!!V((w||r).dirtyFields,m),isTouched:!!V((w||r).touchedFields,m),error:V((w||r).errors,m)}),jr=m=>{m&&Vo(m).forEach(w=>ue(r.errors,w)),f.state.next({errors:m?r.errors:{}})},Dn=(m,w,k)=>{const M=(V(i,m,{_f:{}})._f||{}).ref;G(r.errors,m,{...w,ref:M}),f.state.next({name:m,errors:r.errors,isValid:!1}),k&&k.shouldFocus&&M&&M.focus&&M.focus()},Mt=(m,w)=>lt(m)?f.values.subscribe({next:k=>m(B(void 0,w),k)}):B(m,w,!0),nn=(m,w={})=>{for(const k of m?Vo(m):c.mount)c.mount.delete(k),c.array.delete(k),w.keepValue||(ue(i,k),ue(s,k)),!w.keepError&&ue(r.errors,k),!w.keepDirty&&ue(r.dirtyFields,k),!w.keepTouched&&ue(r.touchedFields,k),!n.shouldUnregister&&!w.keepDefaultValue&&ue(o,k);f.values.next({values:{...s}}),f.state.next({...r,...w.keepDirty?{isDirty:R()}:{}}),!w.keepIsValid&&y()},Ur=({disabled:m,name:w,field:k,fields:M,value:P})=>{if(ct(m)){const $=m?void 0:te(P)?Lo(k?k._f:V(M,w)._f):P;G(s,w,$),I(w,$,!1,!1,!0)}},Ot=(m,w={})=>{let k=V(i,m);const M=ct(w.disabled);return G(i,m,{...k||{},_f:{...k&&k._f?k._f:{ref:{name:m}},name:m,mount:!0,...w}}),c.mount.add(m),k?Ur({field:k,disabled:w.disabled,name:m}):N(m,!0,w.value),{...M?{disabled:w.disabled}:{},...n.progressive?{required:!!w.required,min:Fn(w.min),max:Fn(w.max),minLength:Fn(w.minLength),maxLength:Fn(w.maxLength),pattern:Fn(w.pattern)}:{},name:m,onChange:ut,onBlur:ut,ref:P=>{if(P){Ot(m,w),k=V(i,m);const $=te(P.value)&&P.querySelectorAll&&P.querySelectorAll("input,select,textarea")[0]||P,F=Sg($),Z=k._f.refs||[];if(F?Z.find(re=>re===$):$===k._f.ref)return;G(i,m,{_f:{...k._f,...F?{refs:[...Z.filter(Do),$,...Array.isArray(V(o,m))?[{}]:[]],ref:{type:$.type,name:m}}:{ref:$}}}),N(m,!1,void 0,$)}else k=V(i,m,{}),k._f&&(k._f.mount=!1),(n.shouldUnregister||w.shouldUnregister)&&!(vg(c.array,m)&&a.action)&&c.unMount.add(m)}}},Ft=()=>n.shouldFocusError&&Ir(i,Vt,c.mount),Ke=m=>{ct(m)&&(f.state.next({disabled:m}),Ir(i,w=>{w.disabled=m},0,!1))},Nn=(m,w)=>async k=>{k&&(k.preventDefault&&k.preventDefault(),k.persist&&k.persist());let M=ze(s);if(f.state.next({isSubmitting:!0}),n.resolver){const{errors:P,values:$}=await T();r.errors=P,M=$}else await J(i);ue(r.errors,"root"),Pe(r.errors)?(f.state.next({errors:{}}),await m(M,k)):(w&&await w({...r.errors},k),Ft(),setTimeout(Ft)),f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Pe(r.errors),submitCount:r.submitCount+1,errors:r.errors})},zr=(m,w={})=>{V(i,m)&&(te(w.defaultValue)?We(m,V(o,m)):(We(m,w.defaultValue),G(o,m,w.defaultValue)),w.keepTouched||ue(r.touchedFields,m),w.keepDirty||(ue(r.dirtyFields,m),r.isDirty=w.defaultValue?R(m,V(o,m)):R()),w.keepError||(ue(r.errors,m),l.isValid&&y()),f.state.next({...r}))},iu=(m,w={})=>{const k=m?ze(m):o,M=ze(k),P=m&&!Pe(m)?M:o;if(w.keepDefaultValues||(o=k),!w.keepValues){if(w.keepDirtyValues||p)for(const $ of c.mount)V(r.dirtyFields,$)?G(P,$,V(s,$)):We($,V(P,$));else{if(To&&te(m))for(const $ of c.mount){const F=V(i,$);if(F&&F._f){const Z=Array.isArray(F._f.refs)?F._f.refs[0]:F._f.ref;if(Dr(Z)){const re=Z.closest("form");if(re){re.reset();break}}}}i={}}s=e.shouldUnregister?w.keepDefaultValues?ze(o):{}:ze(P),f.array.next({values:{...P}}),f.values.next({values:{...P}})}c={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!a.mount&&t(),a.mount=!l.isValid||!!w.keepIsValid,a.watch=!!e.shouldUnregister,f.state.next({submitCount:w.keepSubmitCount?r.submitCount:0,isDirty:w.keepDirty?r.isDirty:!!(w.keepDefaultValues&&!Tt(m,o)),isSubmitted:w.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:w.keepDirtyValues?r.dirtyFields:w.keepDefaultValues&&m?No(o,m):{},touchedFields:w.keepTouched?r.touchedFields:{},errors:w.keepErrors?r.errors:{},isSubmitSuccessful:w.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1})},ou=(m,w)=>iu(lt(m)?m(s):m,w);return{control:{register:Ot,unregister:nn,getFieldState:In,handleSubmit:Nn,setError:Dn,_executeSchema:T,_getWatch:B,_getDirty:R,_updateValid:y,_removeUnmounted:U,_updateFieldArray:C,_updateDisabledField:Ur,_getFieldArray:z,_reset:iu,_resetDefaultValues:()=>lt(n.defaultValues)&&n.defaultValues().then(m=>{ou(m,n.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:m=>{r={...r,...m}},_disableForm:Ke,_subjects:f,_proxyFormState:l,get _fields(){return i},get _formValues(){return s},get _state(){return a},set _state(m){a=m},get _defaultValues(){return o},get _names(){return c},set _names(m){c=m},get _formState(){return r},set _formState(m){r=m},get _options(){return n},set _options(m){n={...n,...m}}},trigger:Y,register:Ot,handleSubmit:Nn,watch:Mt,setValue:We,getValues:dt,reset:ou,resetField:zr,clearErrors:jr,unregister:nn,setError:Dn,setFocus:(m,w={})=>{const k=V(i,m),M=k&&k._f;if(M){const P=M.refs?M.refs[0]:M.ref;P.focus&&(P.focus(),w.shouldSelect&&P.select())}},getFieldState:In}}function Ql(e={}){const t=Te.useRef(),n=Te.useRef(),[r,i]=Te.useState({isDirty:!1,isValidating:!1,isLoading:lt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:lt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Tg(e,()=>i(s=>({...s}))),formState:r});const o=t.current.control;return o._options=e,bg({subject:o._subjects.state,next:s=>{yg(s,o._proxyFormState,o._updateFormState,!0)&&i({...o._formState})}}),Te.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),Te.useEffect(()=>{if(o._proxyFormState.isDirty){const s=o._getDirty();s!==r.isDirty&&o._subjects.state.next({isDirty:s})}},[o,r.isDirty]),Te.useEffect(()=>{e.values&&!Tt(e.values,n.current)?(o._reset(e.values,o._options.resetOptions),n.current=e.values):o._resetDefaultValues()},[e.values,o]),Te.useEffect(()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),t.current.formState=gg(r,o),t.current}var Jl=function(e,t,n){if(e&&"reportValidity"in e){var r=V(n,t);e.setCustomValidity(r&&r.message||""),e.reportValidity()}},Vg=function(e,t){var n=function(i){var o=t.fields[i];o&&o.ref&&"reportValidity"in o.ref?Jl(o.ref,i,e):o.refs&&o.refs.forEach(function(s){return Jl(s,i,e)})};for(var r in t.fields)n(r)},Mg=function(e,t){t.shouldUseNativeValidation&&Vg(e,t);var n={};for(var r in e){var i=V(t.fields,r),o=Object.assign(e[r]||{},{ref:i&&i.ref});if(Fg(t.names||Object.keys(e),r)){var s=Object.assign({},Og(V(n,r)));G(s,"root",o),G(n,r,s)}else G(n,r,o)}return n},Og=function(e){return Array.isArray(e)?e.filter(Boolean):[]},Fg=function(e,t){return e.some(function(n){return n.startsWith(t+".")})},Ig=function(e,t){for(var n={};e.issues.length;){var r=e.issues[0];if(r.path){var i=r.path.map(function(a){return a.key}).join(".");if(n[i]||(n[i]={message:r.message,type:r.validation}),t){var o=n[i].types,s=o&&o[r.validation];n[i]=Nl(i,t,n,r.validation,s?[].concat(s,r.message):r.message)}e.issues.shift()}}return n},eu=function(e,t,n){return n===void 0&&(n={}),function(r,i,o){try{return Promise.resolve(function(s,a){try{var c=function(){function u(l){return{values:n.raw?r:l,errors:{}}}var d=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},t);return n.mode==="sync"?u(cn(e,r,d)):Promise.resolve(ku(e,r,d)).then(u)}()}catch(u){return a(u)}return c&&c.then?c.then(void 0,a):c}(0,function(s){if(s instanceof Yr)return{values:{},errors:Mg(Ig(s,!o.shouldUseNativeValidation&&o.criteriaMode==="all"),o)};throw s}))}catch(s){return Promise.reject(s)}}};const Dg=27,Ng=12,Lg=10,Rg=e=>{const t=Object.fromEntries(new FormData(e).entries());Object.keys(t).length&&e.dispatchEvent(new Event("submit",{bubbles:!0}))},Bg=wo("multiple-choice"),jg=e=>{const t={min:e.minSelected??0,max:e.maxSelected??e.options.length};return eu(Ze({checked:us(ls(yu()),n=>Object.entries(n).filter(([r,i])=>i).map(([r,i])=>r),[$u(t.max,`Please select at most ${t.max} option${t.max!==1?"s":""}`),ds(t.min,`Please select at least ${t.min} option${t.min!==1?"s":""}`)])}))},Ug=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var u,d;const r=e.key?(u=L.current$.value.flow)==null?void 0:u.data.submissions[e.key]:void 0,i=(e.config.minSelected===1||e.config.minSelected===void 0)&&e.config.maxSelected===1,{register:o,handleSubmit:s,formState:{errors:a}}=Ql({defaultValues:{checked:i?{}:Bg(r)?Object.fromEntries(r.value.map(l=>[l,!0])):{}},resolver:jg(e.config)}),c=Po();return g("form",{noValidate:!0,class:"flex flex-col gap-1 pr-2.5",onChange:l=>{i&&Rg(l.currentTarget)},onSubmit:s(l=>{const f=l.checked;t(f)}),children:[g("div",{class:"flex items-center gap-1",children:[g("ul",{style:{maxHeight:6.5*Dg+5*Ng+2*Lg},class:at("gutter-stable flex w-full flex-1 flex-wrap gap-3 overflow-y-auto rounded-xl p-2.5 pr-4",{"justify-center":e.config.options.length===1}),children:e.config.options.map((l,f)=>{const p=`checked.${l.value}`,{ref:h,...v}=o(p);return g("li",{class:"relative",children:[g("input",{autoFocus:f===0,ref:b=>{b&&f===0&&(c.current=b),h(b)},id:p,...v,class:"peer sr-only h-full",type:"checkbox"}),g("label",{class:"bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-divider text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 block rounded-2xl px-2.5 py-1 outline outline-2 ring-0 ring-transparent transition-all selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",htmlFor:p,children:l.label})]},l.value)})}),g("div",{class:"flex flex-col items-center gap-2",children:[!i&&g(Or,{}),e.config.minSelected===0&&g(Fr,{type:"button",onClick:()=>t([])})]})]}),g("div",{class:"px-1",children:g(Eo,{onAnimationComplete:n,error:(d=a.checked)==null?void 0:d.root})})]})},zg=({input:e,onSubmitSuccess:t})=>g("div",{class:"flex flex-col items-center py-3",children:g("button",{class:"bg-accent-9 hover:bg-accent-10 active:bg-submit-bg-active hover:border-accent-10 active:border-submit-bg-active border-accent-9 ring-accent-6 focus-visible:outline-accent-8 ring-offset-neutral-1 group flex cursor-pointer rounded-full border border-solid px-5 py-3 pr-4 text-white shadow-[inset_0px_-6px_2px_-1px_oklch(100_0_0/.45),inset_0px_1px_1px_oklch(100_0_0/.3)] outline-none ring-1 ring-offset-[1.5px] transition-all duration-300 focus-visible:outline-2 active:shadow-[inset_0px_0px_2px_-1px_oklch(100_0_0/.45),inset_0px_3px_1px_.5px_oklch(0_0_0/.08)] active:ring-2 active:ring-offset-2",name:e.key,onClick:()=>{t(null)},children:g("span",{class:"relative bottom-[2px] top-[-2px] flex items-center gap-1.5 transition-all duration-300 group-active:bottom-0 group-active:top-0",children:[g("span",{class:"inline-flex items-center text-sm font-medium",children:e.config.label}),g("svg",{stroke:"currentColor","stroke-width":"1.5",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("path",{d:"M4 8L8 4L12 8"}),g("path",{d:"M8 4V13"})]})]})})}),tn={empty:"Please enter some text",email:"That doesn’t look like a valid email address",phone:"That doesn’t look like a valid phone number",url:"That doesn’t look like a valid URL"},Hg=$e(tn.phone,[Au(/^\+?[0-9 -]+$/,tn.phone)]),Wg={email:{type:"email",inputMode:"email",formNoValidate:!0},phone:{type:"tel",inputMode:"tel"},text:{type:"text",inputMode:"text"},url:{type:"url",inputMode:"url",formNoValidate:!0}},Kg=wo("text"),qg=e=>eu(Ze({text:{email:$e(tn.email,[Cu(tn.email)]),phone:us(Hg,t=>t.replace(/[^0-9]/g,"")),text:$e([ds(1,tn.empty)]),url:$e([Pu(tn.url)])}[e.format]})),Gg=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var l;const r=e.key?(l=L.current$.value.flow)==null?void 0:l.data.submissions[e.key]:void 0,i=e.config.defaultValue,{register:o,handleSubmit:s,formState:{errors:a}}=Ql({defaultValues:{text:i||(Kg(r)?r.value:"")},resolver:qg(e.config)}),{ref:c,...u}=o("text",{required:!e.config.optional}),d=j();return Ae(()=>{d.current&&(d.current.focus(),d.current.select())},[]),g(Q,{children:g("form",{noValidate:!0,class:"flex flex-col gap-1 p-2.5",onSubmit:s(f=>{t(f.text)}),children:[g("div",{class:"flex items-center gap-2",children:[g("div",{class:"relative min-w-0 flex-grow",children:[g("input",{id:"chat-input",...u,...Wg[e.config.format],autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:f=>{f&&(d.current=f),c(f)},class:"outline-divider ease-expo-out placeholder:text-neutral-10 text-neutral-12 focus-visible:outline-accent-7 caret-accent-9 bg-lowest w-full rounded-full px-3 py-1 text-base outline outline-2 transition-all",placeholder:e.config.placeholder}),e.config.optional&&g(Fr,{class:"absolute right-0 top-0",onClick:()=>t(null)})]}),g(Or,{})]}),g(Eo,{onAnimationComplete:n,error:a.text})]})})},Yg=()=>{var i;const e=(i=L.current$.value.flow)==null?void 0:i.data.currentInput,t=j(null),n=ae(()=>{t.current&&(L.inputHeight$.value=t.current.getBoundingClientRect().height)},[]);W(()=>{n()},[e==null?void 0:e.type,n]);const r=o=>s=>Ve.onSubmitSuccessFn$.value({type:o,value:s});return g(xr.div,{initial:{height:0},animate:{height:L.inputHeight$.value},exit:{height:0,opacity:0},onAnimationStart:Ve.scrollToEnd.smooth,onAnimationComplete:Ve.scrollToEnd.smooth,class:"bg-statusbar absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",children:g("div",{ref:t,class:"border-divider border-t",children:Ue({input:e,onHeightChange:n}).with({input:_e.nullish},()=>g("div",{class:"flex items-center gap-2 p-2.5",children:[g("input",{"aria-hidden":"true",id:"chat-input",class:"outline-divider flex-grow rounded-full bg-transparent px-3 py-1 text-base outline outline-2",disabled:!0}),g(Or,{disabled:!0,"aria-hidden":"true",tabIndex:-1})]})).with({input:{type:"text"}},o=>g(Gg,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"multiple-choice"}},o=>g(Ug,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"boolean"}},o=>g(og,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"file"}},o=>g(fg,{onSubmitSuccess:r(o.input.type),...o})).with({input:{type:"submit"}},o=>g(zg,{onSubmitSuccess:r(o.input.type),...o})).exhaustive()})})},tu=e=>typeof e=="boolean"?"".concat(e):e===0?"0":e,nu=at,ru=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return nu(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:o}=t,s=Object.keys(i).map(u=>{const d=n==null?void 0:n[u],l=o==null?void 0:o[u];if(d===null)return null;const f=tu(d)||tu(l);return i[u][f]}),a=n&&Object.entries(n).reduce((u,d)=>{let[l,f]=d;return f===void 0||(u[l]=f),u},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,d)=>{let{class:l,className:f,...p}=d;return Object.entries(p).every(h=>{let[v,b]=h;return Array.isArray(b)?b.includes({...o,...a}[v]):{...o,...a}[v]===b})?[...u,l,f]:u},[]);return nu(e,s,c,n==null?void 0:n.class,n==null?void 0:n.className)},Zg=ru("max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink min-w-[2rem] py-2 px-3 rounded-[18px] min-h-[36px] break-words relative",{variants:{side:{left:"bg-bubble-weak-bg text-neutral-12 shadow-surface-sm outline outline-1 outline-bubble-weak rounded-bl-md",right:"ml-auto bg-accent-9 text-white rounded-br-md shadow-surface-sm shadow-bubble-strong-shadow"},transitionState:{entering:"opacity-0 translate-y-8",entered:"opacity-100 translate-y-0",exiting:"opacity-0 scale-0",exited:""}},defaultVariants:{side:"left"}}),Xg={hidden:{y:"100%",scale:.75},shown:{y:0,scale:1}},Qg=({children:e,className:t,transitionState:n,side:r,...i})=>g(xr.p,{variants:Xg,initial:"hidden",animate:"shown",transition:{type:"spring",damping:25,stiffness:500},"data-transition":n,style:{transformOrigin:r==="left"?"0% 50%":"100% 50%"},class:Zg({className:t,side:r,transitionState:n}),...i,children:e}),Jg=({className:e,...t})=>(W(()=>{Ve.scrollToEnd.smooth()}),g("div",{"aria-hidden":!0,children:Ve.isBotTyping$.value===!0?g("div",{"aria-label":"Typing…",class:at("flex gap-1 p-4",e),...t,children:Array.from({length:3},(n,r)=>g("div",{class:"bg-accent-9 h-1.5 w-1.5 animate-bounce rounded-full",style:{animationDelay:`${-r*200}ms`}}))}):void 0})),ey={bot:"left",user:"right"},ty=ru("w-full select-none py-2 text-wrap-balance text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_var(--i-color-n-1)]",{variants:{variant:{info:"text-neutral-8",warning:"text-[#FFC107]",error:"text-error-9",success:"text-[#4CAF50]"}}}),ny=({lastSentMessageFooter:e})=>{var n;const t=((n=L.current$.value.flow)==null?void 0:n.data.messages)??[];return W(()=>{Ve.scrollToEnd.smooth()},[t.length]),g("ol",{"aria-label":"Chat messages",class:"flex flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",children:[g(nl,{initial:!1,children:t.map((r,i)=>g(Q,{children:g("li",{class:"flex",children:Ue(r).with({type:"system"},o=>g("p",{class:ty({variant:o.variant}),children:o.text})).with({type:"text",author:_e.union("bot","user")},o=>{const s=o.author==="user"&&!t.slice(i+1).some(a=>a.type==="text"&&a.author==="user");return g(Qg,{side:ey[o.author],children:[o.text,s?e:null]},i)}).with({type:"link"},o=>g("div",{class:"bg-accent-3 flex w-full items-center justify-center overflow-hidden rounded-xl px-2 py-2",children:g("a",{class:"bg-lowest shadow-surface-sm ring-accent-6 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 text-wrap-balance flex items-center gap-1.5 rounded-full py-2 pl-4 pr-2.5 text-center no-underline ring-1 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2",target:"_blank",href:o.href,children:[o.text,g("svg",{class:"flex-none",width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:g("path",{d:"M3.64645 11.3536C3.45118 11.1583 3.45118 10.8417 3.64645 10.6465L10.2929 4L6 4C5.72386 4 5.5 3.77614 5.5 3.5C5.5 3.22386 5.72386 3 6 3L11.5 3C11.6326 3 11.7598 3.05268 11.8536 3.14645C11.9473 3.24022 12 3.36739 12 3.5L12 9.00001C12 9.27615 11.7761 9.50001 11.5 9.50001C11.2239 9.50001 11 9.27615 11 9.00001V4.70711L4.35355 11.3536C4.15829 11.5488 3.84171 11.5488 3.64645 11.3536Z",fill:"currentColor","fill-rule":"evenodd","clip-rule":"evenodd"})})]})})).with({type:"image"},o=>g("img",{class:"shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",src:o.url,style:{aspectRatio:o.width/o.height}})).with({type:"file"},o=>g(lg,{class:o.author==="bot"?"":"ml-auto",file:{name:o.fileName,sizeKb:o.fileSizeKb}})).exhaustive()})},i))}),g(Jg,{},"typing")]})},ry=({logger:e,apiClient:t,analytics:n})=>{const{flow:r}=L.current$.value;vt(r,"Flow is required to exist to show chatbot body");const i=L.viewState$.value,{chatRef:o,chatService:s}=ng(),[a,c]=ie();return Ae(()=>{i==="maximised"&&Ve.scrollToEnd.instant()},[i]),Ae(()=>{const{state:u,flow:d}=L.current$.peek();if(u!=="loaded")throw new Error(Wv.invalid_state);let l=d.data.nodeHistory.at(-1);if(Ve.scrollToEnd.instant(),L.setInput(void 0),d.data.isFinished)return;l===void 0?(l=wl(r.nodes).id,L.setCurrentNodeId(l)):L.removeMessagesSentByNodeIds([l]);const{interpret:f,abort:p,undo:h}=Rm({context:r.context,analytics:n,apiClient:t,logger:e,flow:r.nodes,chatService:s,getSubmissions:()=>{var v;return(v=L.current$.peek().flow)==null?void 0:v.data.submissions},onInterpret:(v,b)=>{const x=L.current$.peek().flow;vt(x),b&&(x.data.sequence=x.data.sequence+1,n.log({event:"FLOW_NODE",properties:{flow_id:r.id,flow_version:r.version,from_node_id:b.id,to_node_id:v.id,sequence:x.data.sequence,flow_session_id:x.data.flowSessionId},customProperties:r.context})),L.setCurrentNodeId(v.id)},onFlowEnd:async()=>{L.markAsFinished()}});return c(()=>h),f(l),p},[n,t,s,e,r]),g(Q,{children:[g("div",{ref:o,className:"hide-scrollbars relative flex w-full max-w-full flex-grow flex-col overflow-y-scroll",style:{WebkitOverflowScrolling:"touch",paddingBottom:L.inputHeight$.value},children:g(ny,{lastSentMessageFooter:r.data.isFinished||!a?null:g(oy,{undoFn:a})})}),g(Yg,{})]})},iy=e=>"key"in e.data&&e.data.key?[e.data.key]:"keys"in e.data?Object.values(e.data.keys).filter(t=>typeof t=="string"):[],oy=({undoFn:e})=>g("div",{class:"absolute bottom-0 right-0 flex w-full translate-y-full justify-end",children:g("button",{class:"fr touch-hitbox text-neutral-9 hover:text-neutral-12 rounded-full p-1 text-right text-xs transition-all",onClick:async()=>{const{flow:t}=L.current$.peek();vt(t);const{removed:n}=e(t.data.nodeHistory),r=t.data.nodeHistory.splice(-n);r.length!==0&&(L.removeMessagesSentByNodeIds(r),L.setInput(void 0),r.pop(),r.map(i=>t.nodes.find(o=>o.id===i)).filter(Boolean).flatMap(iy).forEach(i=>delete t.data.submissions[i]),L.current$.value={...L.current$.value})},children:"Undo"})}),sy=Object.freeze(Object.defineProperty({__proto__:null,ChatbotBody:ry},Symbol.toStringTag,{value:"Module"}))})();
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-413f4efe.cjs");
3
+ const index = require("./index-9f0cf58e.cjs");
4
4
  require("@inploi/sdk");
5
5
  const followNodes = ({
6
6
  node,
@@ -1,4 +1,4 @@
1
- import { _, g as getHeadOrThrow, i as invariant, A as AbortedError, N, a as getFlowSubmissionsPayload, h as hasProp, k as kbToReadableSize, o as o$1, c as clsx, b as a$2, d as _$1, y, F, s as store, p, e as parse, f as picklist, j as h, l as k, m as isSubmissionOfType, C as Cn, n as parseAsync, V as ValiError, q as object, t as transform, r as maxLength, u as minLength, v as record, w as boolean, x as string, z as email, B as url, D as regex, T, E as m, G as AnimatePresence, H as ERROR_MESSAGES } from "./index-ec980c39.js";
1
+ import { _, g as getHeadOrThrow, i as invariant, A as AbortedError, N, a as getFlowSubmissionsPayload, h as hasProp, k as kbToReadableSize, o as o$1, c as clsx, b as a$2, d as _$1, y, F, s as store, p, e as parse, f as picklist, j as h, l as k, m as isSubmissionOfType, C as Cn, n as parseAsync, V as ValiError, q as object, t as transform, r as maxLength, u as minLength, v as record, w as boolean, x as string, z as email, B as url, D as regex, T, E as m, G as AnimatePresence, H as ERROR_MESSAGES } from "./index-fc00a362.js";
2
2
  import "@inploi/sdk";
3
3
  const followNodes = ({
4
4
  node,
@@ -9100,7 +9100,7 @@ const StatusBar = ({
9100
9100
  })
9101
9101
  });
9102
9102
  };
9103
- const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-a6d50df4.cjs")).then((module2) => module2.ChatbotBody));
9103
+ const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-5ed580ca.cjs")).then((module2) => module2.ChatbotBody));
9104
9104
  const MotionProvider = ({
9105
9105
  children
9106
9106
  }) => {
@@ -9538,7 +9538,7 @@ const chatbotPlugin = ({
9538
9538
  flowKeys: [data.job.id]
9539
9539
  };
9540
9540
  }),
9541
- fetchFlowById: async (flowId) => apiClient.fetch(`/flow/${flowId}`).then((res) => {
9541
+ fetchFlowById: async (flowId) => apiClient.fetch(`/flow/id/${flowId}`).then((res) => {
9542
9542
  const data = parse$1(FlowByIdPayloadSchema, res);
9543
9543
  return {
9544
9544
  flow: data.flow,
@@ -9555,6 +9555,8 @@ const chatbotPlugin = ({
9555
9555
  try {
9556
9556
  store.cancelCurrentFlow();
9557
9557
  store.viewState$.value = "maximised";
9558
+ if (!prepared)
9559
+ renderAndPrepare();
9558
9560
  if (params instanceof Promise) {
9559
9561
  store.current$.value = {
9560
9562
  state: "loading"
@@ -9099,7 +9099,7 @@ const StatusBar = ({
9099
9099
  })
9100
9100
  });
9101
9101
  };
9102
- const ChatbotBody = M(() => import("./chatbot-body-04c70e40.js").then((module) => module.ChatbotBody));
9102
+ const ChatbotBody = M(() => import("./chatbot-body-ed7bd24c.js").then((module) => module.ChatbotBody));
9103
9103
  const MotionProvider = ({
9104
9104
  children
9105
9105
  }) => {
@@ -9537,7 +9537,7 @@ const chatbotPlugin = ({
9537
9537
  flowKeys: [data.job.id]
9538
9538
  };
9539
9539
  }),
9540
- fetchFlowById: async (flowId) => apiClient.fetch(`/flow/${flowId}`).then((res) => {
9540
+ fetchFlowById: async (flowId) => apiClient.fetch(`/flow/id/${flowId}`).then((res) => {
9541
9541
  const data = parse$1(FlowByIdPayloadSchema, res);
9542
9542
  return {
9543
9543
  flow: data.flow,
@@ -9554,6 +9554,8 @@ const chatbotPlugin = ({
9554
9554
  try {
9555
9555
  store.cancelCurrentFlow();
9556
9556
  store.viewState$.value = "maximised";
9557
+ if (!prepared)
9558
+ renderAndPrepare();
9557
9559
  if (params instanceof Promise) {
9558
9560
  store.current$.value = {
9559
9561
  state: "loading"
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-413f4efe.cjs");
3
+ const index = require("./index-9f0cf58e.cjs");
4
4
  require("@inploi/sdk");
5
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,4 +1,4 @@
1
- import { I } from "./index-ec980c39.js";
1
+ import { I } from "./index-fc00a362.js";
2
2
  import "@inploi/sdk";
3
3
  export {
4
4
  I as chatbotPlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inploi/plugin-chatbot",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "type": "module",
5
5
  "main": "dist/plugin-chatbot.js",
6
6
  "types": "dist/index.d.ts",