@inploi/plugin-chatbot 3.2.4 → 3.2.6

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
@@ -54,4 +54,4 @@ var $y=Object.defineProperty;var Sy=(Pt,Fe,Et)=>Fe in Pt?$y(Pt,Fe,{enumerable:!0
54
54
  ${e.flatMap(n=>Object.entries(n.colors).map(([r,o])=>`--i-${n.name}-${r}: ${ob(o)};`).join(`
55
55
  `)).join(`
56
56
  `)}
57
- }`,sb=({_internal_domManager:e=fg(),theme:t})=>Et(({apiClient:n,logger:r,analytics:o})=>{let i=!1;const s=()=>{const a=e.getOrCreateChatbotElement();e.addStyle(dg,"inploi-chatbot-style");const c=ib([{name:"a",colors:xd(t)},{name:"n",colors:xd({hue:t.hue,chroma:.1})}]);e.addStyle(c,"inploi-chatbot-theme"),en(N(jv,{apiClient:n,logger:r,analytics:o}),a),i=!0};return{prepare:async()=>{try{if(i)return;s(),r.info("Chatbot plugin prepared")}catch(a){console.error(a),r.error("Error preparing chatbot plugin",a)}},startApplication:async({jobId:a})=>{try{re.cancel(),pf(()=>{nt.value="maximised",re.current$.value={state:"loading"}}),ug({jobId:a,apiClient:n,logger:r}).then(c=>{c.ok?re.start(c.value):re.current$.value={state:"error",error:c.error}}),i||s()}catch(c){console.error(c),r.error("Error starting application",c)}},closeApplication:async()=>{r.info("Closing application from an external source"),re.cancel()}}});if(!window.inploi)throw new Error("Please insert the SDK script tag above the plugins.");window.inploi.chatbotPlugin=sb;const kd=({node:e,nodes:t,stopWhen:n})=>{if((n==null?void 0:n(e))===!0)return e;const r=e.nextId?t.find(o=>o.id===e.nextId):void 0;if(r)return kd({node:r,nodes:t,stopWhen:n})},ab=({childNode:e,nodes:t})=>{const r=t.filter(o=>o.type==="if-block").find(o=>{if(!o.branchId)return!1;const i=t.find(a=>a.id===o.branchId);if(!i)return!1;const s=kd({node:i,nodes:t,stopWhen:a=>a.id===e.id});return!(!s||s.id!==e.id)});if(r!=null&&r.nextId)return t.find(o=>o.id===r.nextId)},cb=({flow:e,analytics:t,logger:n,context:r,apiClient:o,getSubmissions:i,chatService:s,onFlowEnd:a,onInterpret:c})=>{const u=new AbortController,d=async(l,f)=>{const h=i();c==null||c(l,f);try{await lb({analytics:t,logger:n,apiClient:o,context:r,node:l,submissions:h,chat:{sendMessage:async p=>s.send({groupId:l.id,message:p,signal:u.signal}),userInput:async p=>s.input({input:p,signal:u.signal})},next:p=>{const m=p?e.find(y=>y.id===p):ab({childNode:l,nodes:e});return m?d(m,l):a==null?void 0:a(l)}})}catch(p){if(p instanceof Jn)return;throw p}};return{interpret:async l=>{const f=e.find(h=>h.id===l)??vu(e);return d(f)},abort:()=>{u.abort()}}};async function lb(e){return await tt(e).with({node:{type:"text"}},hb).with({node:{type:"image"}},pb).with({node:{type:"question-text"}},mb).with({node:{type:"question-enum"}},gb).with({node:{type:"question-number"}},vb).with({node:{type:"question-boolean"}},bb).with({node:{type:"question-file"}},wb).with({node:{type:"question-address"}},yb).with({node:{type:"end-flow"}},_b).with({node:{type:"if-block"}},fb).with({node:{type:"jump"}},({node:t,next:n})=>n(t.data.targetId)).with({node:{type:"link"}},db).with({node:{type:"submit"}},ub).exhaustive()}async function ub({chat:e,next:t,node:n,logger:r,apiClient:o,submissions:i,context:s}){await e.userInput({type:"multiple-choice",key:void 0,config:{options:[{label:"Submit my application",value:"submit"}],maxSelected:1,minSelected:1}}),await e.sendMessage({type:"system",variant:"info",text:"Submitting your application…"});const a=await o.fetch("/flow/apply",{method:"POST",body:JSON.stringify({...s,submissions:Lv(i||{})})}).catch(c=>c);await tt(a).with({redirect_url:Ae.string},async c=>{await e.sendMessage({type:"text",author:"bot",text:"Almost there! Please finalise your application on our partner’s website."}),await e.sendMessage({type:"link",href:c.redirect_url,text:"Finalise application on partner"})}).with({message:"Success"},async()=>{await e.sendMessage({type:"system",variant:"success",text:"Application submitted"}),t(n.nextId)}).otherwise(async c=>{r.error(c),await e.sendMessage({type:"system",variant:"error",text:"Failed to submit application"}),t(n.id)})}async function db({chat:e,next:t,node:n}){await e.sendMessage({type:"link",href:n.data.href,text:n.data.cta}),t(n.nextId)}async function fb({submissions:e,next:t,node:n}){const r=xb(n,e)?n.branchId:n.nextId;t(r)}async function hb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.text}),t(n.nextId)}async function pb({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 mb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const r=await e.userInput({key:n.data.key,type:"text",config:{placeholder:n.data.placeholder,format:n.data.format}});await e.sendMessage({author:"user",type:"text",text:r.value}),t(n.nextId)}async function vb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const r=await e.userInput({key:n.data.key,type:"text",config:{placeholder:n.data.placeholder,format:"text"}});await e.sendMessage({author:"user",type:"text",text:r.value}),t(n.nextId)}async function gb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const r=await e.userInput({key:n.data.key,type:"multiple-choice",config:n.data});await e.sendMessage({author:"user",type:"text",text:r.value.join(", ")}),t(n.nextId)}async function bb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const o=(await e.userInput({key:n.data.key,type:"boolean",config:{labels:{true:n.data.trueLabel,false:n.data.falseLabel}}})).value,i={true:n.data.trueLabel,false:n.data.falseLabel};await e.sendMessage({author:"user",type:"text",text:i[o]}),t(n.nextId)}async function yb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:"Address questions are not implemented yet"}),t(n.nextId)}async function wb({node:e,chat:t,next:n}){await t.sendMessage({author:"bot",type:"text",text:e.data.question});const r=await t.userInput({key:e.data.key,type:"file",config:{extensions:e.data.extensions,fileSizeLimitKib:e.data.maxSizeKb,allowMultiple:e.data.multiple===!0}});for await(const o of r.value)await t.sendMessage({author:"user",type:"file",fileName:o.name,fileSizeKb:o.sizeKb});n(e.nextId)}async function _b({chat:e,next:t,node:n}){await e.sendMessage({type:"system",variant:"info",text:n.data.systemMessage||"Conversation finished"}),t(void 0)}const $d=Ae.union(Ae.string,Ae.array(Ae.string)),xb=(e,t)=>{const n=t==null?void 0:t[e.data.compareKey];return n?tt({...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:$d}},({compareValue:r,answer:o})=>o.value.includes(r)).with({compare:"notContains",answer:{value:$d}},({compareValue:r,answer:o})=>!o.value.includes(r)).with({answer:{type:"file"}},()=>!1).exhaustive():!1},ko=({class:e,...t})=>b("button",{class:Xt("bg-accent-7 active:bg-accent-10 active:text-accent-2 text-lowest pointer-coarse:touch-hitbox focus-visible:ring-accent-7/50 flex-shrink-0 rounded-full p-2 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:b("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"2",children:[b("title",{children:"Send"}),b("path",{d:"M3.5 7.5L8 3L12.5 7.5"}),b("path",{d:"M8 4V13"})]})}),Fs=()=>{const e=U(null);return G(()=>{var t;(t=e.current)==null||t.focus()},[]),e},Sd=["true","false"],kb=Qv(Sd),$b="answer",Sb=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{const r=Fs();return n(),b("form",{noValidate:!0,class:"flex items-center gap-2",onSubmit:o=>{o.preventDefault();const i=tt(o).with({nativeEvent:{submitter:Ae.select(Ae.union(Ae.instanceOf(HTMLButtonElement),Ae.instanceOf(HTMLInputElement)))}},a=>a.value).otherwise(()=>{throw new Error("invalid form")}),s=rs(kb,i);t(s)},children:Sd.map((o,i)=>b("button",{ref:i===0?r:null,type:"submit",name:$b,value:o,class:"bg-lowest ease-expo-out ring-neutral-12/5 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 duration-300 selection:bg-transparent",children:b("p",{class:"truncate text-center text-base",children:e.config.labels[o]})}))})},Ds=({error:e,onAnimationComplete:t})=>b(to,{children:e&&b(Kn.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},onAnimationComplete:t,role:"alert",class:"text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full p-0.5 px-1 opacity-0",children:[b("svg",{class:"text-error-10",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b("circle",{cx:"8",cy:"8",r:"6.3",stroke:"currentColor","stroke-width":"1.4"}),b("rect",{x:"7",y:"4",width:"2",height:"5",fill:"currentColor"}),b("rect",{x:"7",y:"10",width:"2",height:"2",fill:"currentColor"})]}),b("p",{class:"truncate pr-1 text-sm",children:e.message})]})}),Mb=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}),$o=e=>tt(e).with(Ae.number.lte(1e3),()=>`${Math.round(e)}KB`).with(Ae.number.lt(1e3*10),()=>`${(e/1e3).toFixed(1)}MB`).otherwise(()=>`${Math.round(e/1e3)}MB`),Tb=e=>e.reduce((t,n)=>t+n.sizeKb,0),Cb=ts("file"),Md=3,Ab=({file:e,class:t,...n})=>{const r=e.name.split(".").pop(),o=e.name.replace(new RegExp(`.${r}$`),"");return b("div",{class:Xt("bg-accent-1 outline-neutral-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline",t),...n,children:[b("p",{"aria-label":"File name",class:"text-accent-12 flex flex-grow overflow-hidden",children:[b("span",{class:"block truncate",children:o}),b("span",{children:[".",r]})]}),b("p",{"aria-label":"File size",class:"text-neutral-10",children:$o(e.sizeKb)})]})},Td=({class:e,...t})=>b("li",{class:Xt("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1",e),...t}),Pb=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var l;const r=(l=re.current$.value.application)==null?void 0:l.data.submissions[e.key],[o,i]=ae(Cb(r)?r.value:[]),[s,a]=ae(),c=o.length-Md,u=Tb(o),d=Fs();return b("form",{class:"flex flex-col gap-1",onSubmit:f=>(f.preventDefault(),a(void 0),o.length===0&&a({type:"required",message:"Please select a file"}),e.config.fileSizeLimitKib&&u>e.config.fileSizeLimitKib&&a({type:"max",message:`File size exceeds limit of ${$o(e.config.fileSizeLimitKib)}`}),t(o)),children:[b("div",{class:"flex items-center gap-2",children:[b("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:[o.length>0?b(ue,{children:[b("ul",{class:"flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",children:[o.slice(0,Md).map(f=>{const h=f.name.split(".").pop(),p=f.name.replace(new RegExp(`.${h}$`),"");return b(Td,{class:"flex overflow-hidden",children:[b("span",{class:"block truncate",children:p}),b("span",{children:[".",h]})]})}),c>0?b(Td,{children:["+",c," file",c!==1?"s":""]}):null]}),b("p",{class:"text-neutral-11 text-xs",children:[$o(u)," ",o.length>1?"total":""]})]}):b("div",{class:"flex flex-col justify-center gap-4 pb-6 pt-5",children:[b("header",{class:"flex flex-col items-center gap-0",children:[b("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:b("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"})}),b("p",{class:"text-neutral-12 tracking-[-0.01em] dark:text-gray-400",children:[e.config.allowMultiple?"Select files":"Select a file"," to upload"]}),e.config.fileSizeLimitKib?b("p",{class:"text-neutral-10 text-xs",children:["(max ",$o(e.config.fileSizeLimitKib),")"]}):null]}),b("aside",{class:"flex flex-col items-center gap-2",children:[b("p",{id:"accepted-filetypes",class:"sr-only",children:"Accepted file extensions"}),b("ul",{"aria-describedby":"accepted-filetypes",class:"flex flex-wrap justify-center gap-2",children:e.config.extensions.map(f=>b("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(".","")}))})]})]}),b("input",{id:"dropzone-file",onInput:async f=>{Fe(f.target instanceof HTMLInputElement);const h=f.target.files?Array.from(f.target.files):[],p=await Promise.allSettled(h.map(async y=>{const x=await Mb(y);return{name:y.name,data:x,sizeKb:y.size/1e3}}));if(p.some(({status:y})=>y==="rejected"))return a({type:"invalid",message:"Invalid file"});const m=p.map(y=>y.status==="fulfilled"?y.value:null).filter(Boolean);i(m)},multiple:e.config.allowMultiple,type:"file",class:"sr-only"})]}),b(ko,{disabled:o.length===0})]}),s&&b(Ds,{onAnimationComplete:n,error:s})]})};var lr=e=>e.type==="checkbox",Sn=e=>e instanceof Date,Me=e=>e==null;const Cd=e=>typeof e=="object";var fe=e=>!Me(e)&&!Array.isArray(e)&&Cd(e)&&!Sn(e),Eb=e=>fe(e)&&e.target?lr(e.target)?e.target.checked:e.target.value:e,Vb=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Ob=(e,t)=>e.has(Vb(t)),Lb=e=>{const t=e.constructor&&e.constructor.prototype;return fe(t)&&t.hasOwnProperty("isPrototypeOf")},Is=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function at(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(!(Is&&(e instanceof Blob||e instanceof FileList))&&(n||fe(e)))if(t=n?[]:{},!n&&!Lb(e))t=e;else for(const r in e)e.hasOwnProperty(r)&&(t[r]=at(e[r]));else return e;return t}var ur=e=>Array.isArray(e)?e.filter(Boolean):[],ie=e=>e===void 0,O=(e,t,n)=>{if(!t||!fe(e))return n;const r=ur(t.split(/[,[\].]+?/)).reduce((o,i)=>Me(o)?o:o[i],e);return ie(r)||r===e?ie(e[t])?n:e[t]:r},Mt=e=>typeof e=="boolean";const Ad={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},ze={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},ct={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};Ie.createContext(null);var Rb=(e,t,n,r=!0)=>{const o={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(o,i,{get:()=>{const s=i;return t._proxyFormState[s]!==ze.all&&(t._proxyFormState[s]=!r||ze.all),n&&(n[s]=!0),e[s]}});return o},Oe=e=>fe(e)&&!Object.keys(e).length,Nb=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return Oe(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(s=>t[s]===(!r||ze.all))},zs=e=>Array.isArray(e)?e:[e];function Fb(e){const t=Ie.useRef(e);t.current=e,Ie.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var Ye=e=>typeof e=="string",Db=(e,t,n,r,o)=>Ye(e)?(r&&t.watch.add(e),O(n,e,o)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),O(n,i))):(r&&(t.watchAll=!0),n),Bs=e=>/^\w*$/.test(e),Pd=e=>ur(e.replace(/["|']|\]/g,"").split(/\.|\[/));function Q(e,t,n){let r=-1;const o=Bs(t)?[t]:Pd(t),i=o.length,s=i-1;for(;++r<i;){const a=o[r];let c=n;if(r!==s){const u=e[a];c=fe(u)||Array.isArray(u)?u:isNaN(+o[r+1])?{}:[]}e[a]=c,e=e[a]}return e}var Ed=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},Vd=e=>({isOnSubmit:!e||e===ze.onSubmit,isOnBlur:e===ze.onBlur,isOnChange:e===ze.onChange,isOnAll:e===ze.all,isOnTouch:e===ze.onTouched}),Od=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const So=(e,t,n,r)=>{for(const o of n||Object.keys(e)){const i=O(e,o);if(i){const{_f:s,...a}=i;if(s){if(s.refs&&s.refs[0]&&t(s.refs[0],o)&&!r)break;if(s.ref&&t(s.ref,s.name)&&!r)break}else fe(a)&&So(a,t)}}};var Ib=(e,t,n)=>{const r=ur(O(e,n));return Q(r,"root",t[n]),Q(e,n,r),e},js=e=>e.type==="file",Tt=e=>typeof e=="function",Mo=e=>{if(!Is)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},To=e=>Ye(e),Hs=e=>e.type==="radio",Co=e=>e instanceof RegExp;const Ld={value:!1,isValid:!1},Rd={value:!0,isValid:!0};var Nd=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&&!ie(e[0].attributes.value)?ie(e[0].value)||e[0].value===""?Rd:{value:e[0].value,isValid:!0}:Rd:Ld}return Ld};const Fd={isValid:!1,value:null};var Dd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Fd):Fd;function Id(e,t,n="validate"){if(To(e)||Array.isArray(e)&&e.every(To)||Mt(e)&&!e)return{type:n,message:To(e)?e:"",ref:t}}var Mn=e=>fe(e)&&!Co(e)?e:{value:e,message:""},zd=async(e,t,n,r,o)=>{const{ref:i,refs:s,required:a,maxLength:c,minLength:u,min:d,max:l,pattern:f,validate:h,name:p,valueAsNumber:m,mount:y,disabled:x}=e._f,g=O(t,p);if(!y||x)return{};const _=s?s[0]:i,M=j=>{r&&_.reportValidity&&(_.setCustomValidity(Mt(j)?"":j||""),_.reportValidity())},S={},F=Hs(i),R=lr(i),C=F||R,E=(m||js(i))&&ie(i.value)&&ie(g)||Mo(i)&&i.value===""||g===""||Array.isArray(g)&&!g.length,q=Ed.bind(null,p,n,S),K=(j,B,H,X=ct.maxLength,ne=ct.minLength)=>{const se=j?B:H;S[p]={type:j?X:ne,message:se,ref:i,...q(j?X:ne,se)}};if(o?!Array.isArray(g)||!g.length:a&&(!C&&(E||Me(g))||Mt(g)&&!g||R&&!Nd(s).isValid||F&&!Dd(s).isValid)){const{value:j,message:B}=To(a)?{value:!!a,message:a}:Mn(a);if(j&&(S[p]={type:ct.required,message:B,ref:_,...q(ct.required,B)},!n))return M(B),S}if(!E&&(!Me(d)||!Me(l))){let j,B;const H=Mn(l),X=Mn(d);if(!Me(g)&&!isNaN(g)){const ne=i.valueAsNumber||g&&+g;Me(H.value)||(j=ne>H.value),Me(X.value)||(B=ne<X.value)}else{const ne=i.valueAsDate||new Date(g),se=lt=>new Date(new Date().toDateString()+" "+lt),Le=i.type=="time",Re=i.type=="week";Ye(H.value)&&g&&(j=Le?se(g)>se(H.value):Re?g>H.value:ne>new Date(H.value)),Ye(X.value)&&g&&(B=Le?se(g)<se(X.value):Re?g<X.value:ne<new Date(X.value))}if((j||B)&&(K(!!j,H.message,X.message,ct.max,ct.min),!n))return M(S[p].message),S}if((c||u)&&!E&&(Ye(g)||o&&Array.isArray(g))){const j=Mn(c),B=Mn(u),H=!Me(j.value)&&g.length>+j.value,X=!Me(B.value)&&g.length<+B.value;if((H||X)&&(K(H,j.message,B.message),!n))return M(S[p].message),S}if(f&&!E&&Ye(g)){const{value:j,message:B}=Mn(f);if(Co(j)&&!g.match(j)&&(S[p]={type:ct.pattern,message:B,ref:i,...q(ct.pattern,B)},!n))return M(B),S}if(h){if(Tt(h)){const j=await h(g,t),B=Id(j,_);if(B&&(S[p]={...B,...q(ct.validate,B.message)},!n))return M(B.message),S}else if(fe(h)){let j={};for(const B in h){if(!Oe(j)&&!n)break;const H=Id(await h[B](g,t),_,B);H&&(j={...H,...q(B,H.message)},M(H.message),n&&(S[p]=j))}if(!Oe(j)&&(S[p]={ref:_,...j},!n))return S}}return M(!0),S};function zb(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=ie(e)?r++:e[t[r++]];return e}function Bb(e){for(const t in e)if(e.hasOwnProperty(t)&&!ie(e[t]))return!1;return!0}function ye(e,t){const n=Array.isArray(t)?t:Bs(t)?[t]:Pd(t),r=n.length===1?e:zb(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(fe(r)&&Oe(r)||Array.isArray(r)&&Bb(r))&&ye(e,n.slice(0,-1)),e}function Us(){let e=[];return{get observers(){return e},next:o=>{for(const i of e)i.next&&i.next(o)},subscribe:o=>(e.push(o),{unsubscribe:()=>{e=e.filter(i=>i!==o)}}),unsubscribe:()=>{e=[]}}}var Ao=e=>Me(e)||!Cd(e);function Yt(e,t){if(Ao(e)||Ao(t))return e===t;if(Sn(e)&&Sn(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n){const i=e[o];if(!r.includes(o))return!1;if(o!=="ref"){const s=t[o];if(Sn(i)&&Sn(s)||fe(i)&&fe(s)||Array.isArray(i)&&Array.isArray(s)?!Yt(i,s):i!==s)return!1}}return!0}var Bd=e=>e.type==="select-multiple",jb=e=>Hs(e)||lr(e),Xs=e=>Mo(e)&&e.isConnected,jd=e=>{for(const t in e)if(Tt(e[t]))return!0;return!1};function Po(e,t={}){const n=Array.isArray(e);if(fe(e)||n)for(const r in e)Array.isArray(e[r])||fe(e[r])&&!jd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Po(e[r],t[r])):Me(e[r])||(t[r]=!0);return t}function Hd(e,t,n){const r=Array.isArray(e);if(fe(e)||r)for(const o in e)Array.isArray(e[o])||fe(e[o])&&!jd(e[o])?ie(t)||Ao(n[o])?n[o]=Array.isArray(e[o])?Po(e[o],[]):{...Po(e[o])}:Hd(e[o],Me(t)?{}:t[o],n[o]):n[o]=!Yt(e[o],t[o]);return n}var qs=(e,t)=>Hd(e,t,Po(t)),Ud=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>ie(e)?e:t?e===""?NaN:e&&+e:n&&Ye(e)?new Date(e):r?r(e):e;function Ws(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return js(t)?t.files:Hs(t)?Dd(e.refs).value:Bd(t)?[...t.selectedOptions].map(({value:n})=>n):lr(t)?Nd(e.refs).value:Ud(ie(t.value)?e.ref.value:t.value,e)}var Hb=(e,t,n,r)=>{const o={};for(const i of e){const s=O(t,i);s&&Q(o,i,s._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},dr=e=>ie(e)?e:Co(e)?e.source:fe(e)?Co(e.value)?e.value.source:e.value:e,Ub=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Xd(e,t,n){const r=O(e,n);if(r||Bs(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),s=O(t,i),a=O(e,i);if(s&&!Array.isArray(s)&&n!==i)return{name:n};if(a&&a.type)return{name:i,error:a};o.pop()}return{name:n}}var Xb=(e,t,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(t||e):(n?r.isOnBlur:o.isOnBlur)?!e:(n?r.isOnChange:o.isOnChange)?e:!0,qb=(e,t)=>!ur(O(e,t)).length&&ye(e,t);const Wb={mode:ze.onSubmit,reValidateMode:ze.onChange,shouldFocusError:!0};function Kb(e={},t){let n={...Wb,...e},r={submitCount:0,isDirty:!1,isLoading:Tt(n.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},o={},i=fe(n.defaultValues)||fe(n.values)?at(n.defaultValues||n.values)||{}:{},s=n.shouldUnregister?{}:at(i),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:Us(),array:Us(),state:Us()},h=e.resetOptions&&e.resetOptions.keepDirtyValues,p=Vd(n.mode),m=Vd(n.reValidateMode),y=n.criteriaMode===ze.all,x=v=>w=>{clearTimeout(d),d=setTimeout(v,w)},g=async v=>{if(l.isValid||v){const w=n.resolver?Oe((await E()).errors):await K(o,!0);w!==r.isValid&&f.state.next({isValid:w})}},_=v=>l.isValidating&&f.state.next({isValidating:v}),M=(v,w=[],k,L,P=!0,T=!0)=>{if(L&&k){if(a.action=!0,T&&Array.isArray(O(o,v))){const D=k(O(o,v),L.argA,L.argB);P&&Q(o,v,D)}if(T&&Array.isArray(O(r.errors,v))){const D=k(O(r.errors,v),L.argA,L.argB);P&&Q(r.errors,v,D),qb(r.errors,v)}if(l.touchedFields&&T&&Array.isArray(O(r.touchedFields,v))){const D=k(O(r.touchedFields,v),L.argA,L.argB);P&&Q(r.touchedFields,v,D)}l.dirtyFields&&(r.dirtyFields=qs(i,s)),f.state.next({name:v,isDirty:B(v,w),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else Q(s,v,w)},S=(v,w)=>{Q(r.errors,v,w),f.state.next({errors:r.errors})},F=(v,w,k,L)=>{const P=O(o,v);if(P){const T=O(s,v,ie(k)?O(i,v):k);ie(T)||L&&L.defaultChecked||w?Q(s,v,w?T:Ws(P._f)):ne(v,T),a.mount&&g()}},R=(v,w,k,L,P)=>{let T=!1,D=!1;const ee={name:v};if(!k||L){l.isDirty&&(D=r.isDirty,r.isDirty=ee.isDirty=B(),T=D!==ee.isDirty);const le=Yt(O(i,v),w);D=O(r.dirtyFields,v),le?ye(r.dirtyFields,v):Q(r.dirtyFields,v,!0),ee.dirtyFields=r.dirtyFields,T=T||l.dirtyFields&&D!==!le}if(k){const le=O(r.touchedFields,v);le||(Q(r.touchedFields,v,k),ee.touchedFields=r.touchedFields,T=T||l.touchedFields&&le!==k)}return T&&P&&f.state.next(ee),T?ee:{}},C=(v,w,k,L)=>{const P=O(r.errors,v),T=l.isValid&&Mt(w)&&r.isValid!==w;if(e.delayError&&k?(u=x(()=>S(v,k)),u(e.delayError)):(clearTimeout(d),u=null,k?Q(r.errors,v,k):ye(r.errors,v)),(k?!Yt(P,k):P)||!Oe(L)||T){const D={...L,...T&&Mt(w)?{isValid:w}:{},errors:r.errors,name:v};r={...r,...D},f.state.next(D)}_(!1)},E=async v=>n.resolver(s,n.context,Hb(v||c.mount,o,n.criteriaMode,n.shouldUseNativeValidation)),q=async v=>{const{errors:w}=await E(v);if(v)for(const k of v){const L=O(w,k);L?Q(r.errors,k,L):ye(r.errors,k)}else r.errors=w;return w},K=async(v,w,k={valid:!0})=>{for(const L in v){const P=v[L];if(P){const{_f:T,...D}=P;if(T){const ee=c.array.has(T.name),le=await zd(P,s,y,n.shouldUseNativeValidation&&!w,ee);if(le[T.name]&&(k.valid=!1,w))break;!w&&(O(le,T.name)?ee?Ib(r.errors,le,T.name):Q(r.errors,T.name,le[T.name]):ye(r.errors,T.name))}D&&await K(D,w,k)}}return k.valid},j=()=>{for(const v of c.unMount){const w=O(o,v);w&&(w._f.refs?w._f.refs.every(k=>!Xs(k)):!Xs(w._f.ref))&&Ze(v)}c.unMount=new Set},B=(v,w)=>(v&&w&&Q(s,v,w),!Yt(Ne(),i)),H=(v,w,k)=>Db(v,c,{...a.mount?s:ie(w)?i:Ye(v)?{[v]:w}:w},k,w),X=v=>ur(O(a.mount?s:i,v,e.shouldUnregister?O(i,v,[]):[])),ne=(v,w,k={})=>{const L=O(o,v);let P=w;if(L){const T=L._f;T&&(!T.disabled&&Q(s,v,Ud(w,T)),P=Mo(T.ref)&&Me(w)?"":w,Bd(T.ref)?[...T.ref.options].forEach(D=>D.selected=P.includes(D.value)):T.refs?lr(T.ref)?T.refs.length>1?T.refs.forEach(D=>(!D.defaultChecked||!D.disabled)&&(D.checked=Array.isArray(P)?!!P.find(ee=>ee===D.value):P===D.value)):T.refs[0]&&(T.refs[0].checked=!!P):T.refs.forEach(D=>D.checked=D.value===P):js(T.ref)?T.ref.value="":(T.ref.value=P,T.ref.type||f.values.next({name:v,values:{...s}})))}(k.shouldDirty||k.shouldTouch)&&R(v,P,k.shouldTouch,k.shouldDirty,!0),k.shouldValidate&&Y(v)},se=(v,w,k)=>{for(const L in w){const P=w[L],T=`${v}.${L}`,D=O(o,T);(c.array.has(v)||!Ao(P)||D&&!D._f)&&!Sn(P)?se(T,P,k):ne(T,P,k)}},Le=(v,w,k={})=>{const L=O(o,v),P=c.array.has(v),T=at(w);Q(s,v,T),P?(f.array.next({name:v,values:{...s}}),(l.isDirty||l.dirtyFields)&&k.shouldDirty&&f.state.next({name:v,dirtyFields:qs(i,s),isDirty:B(v,T)})):L&&!L._f&&!Me(T)?se(v,T,k):ne(v,T,k),Od(v,c)&&f.state.next({...r}),f.values.next({name:v,values:{...s}}),!a.mount&&t()},Re=async v=>{const w=v.target;let k=w.name,L=!0;const P=O(o,k),T=()=>w.type?Ws(P._f):Eb(v),D=ee=>{L=Number.isNaN(ee)||ee===O(s,k,ee)};if(P){let ee,le;const Lo=T(),Tn=v.type===Ad.BLUR||v.type===Ad.FOCUS_OUT,_y=!Ub(P._f)&&!n.resolver&&!O(r.errors,k)&&!P._f.deps||Xb(Tn,O(r.touchedFields,k),r.isSubmitted,m,p),Ks=Od(k,c,Tn);Q(s,k,Lo),Tn?(P._f.onBlur&&P._f.onBlur(v),u&&u(0)):P._f.onChange&&P._f.onChange(v);const Ys=R(k,Lo,Tn,!1),xy=!Oe(Ys)||Ks;if(!Tn&&f.values.next({name:k,type:v.type,values:{...s}}),_y)return l.isValid&&g(),xy&&f.state.next({name:k,...Ks?{}:Ys});if(!Tn&&Ks&&f.state.next({...r}),_(!0),n.resolver){const{errors:ef}=await E([k]);if(D(Lo),L){const ky=Xd(r.errors,o,k),tf=Xd(ef,o,ky.name||k);ee=tf.error,k=tf.name,le=Oe(ef)}}else ee=(await zd(P,s,y,n.shouldUseNativeValidation))[k],D(Lo),L&&(ee?le=!1:l.isValid&&(le=await K(o,!0)));L&&(P._f.deps&&Y(P._f.deps),C(k,le,ee,Ys))}},lt=(v,w)=>{if(O(r.errors,w)&&v.focus)return v.focus(),1},Y=async(v,w={})=>{let k,L;const P=zs(v);if(_(!0),n.resolver){const T=await q(ie(v)?v:P);k=Oe(T),L=v?!P.some(D=>O(T,D)):k}else v?(L=(await Promise.all(P.map(async T=>{const D=O(o,T);return await K(D&&D._f?{[T]:D}:D)}))).every(Boolean),!(!L&&!r.isValid)&&g()):L=k=await K(o);return f.state.next({...!Ye(v)||l.isValid&&k!==r.isValid?{}:{name:v},...n.resolver||!v?{isValid:k}:{},errors:r.errors,isValidating:!1}),w.shouldFocus&&!L&&So(o,lt,v?P:c.mount),L},Ne=v=>{const w={...i,...a.mount?s:{}};return ie(v)?w:Ye(v)?O(w,v):v.map(k=>O(w,k))},Ct=(v,w)=>({invalid:!!O((w||r).errors,v),isDirty:!!O((w||r).dirtyFields,v),isTouched:!!O((w||r).touchedFields,v),error:O((w||r).errors,v)}),At=v=>{v&&zs(v).forEach(w=>ye(r.errors,w)),f.state.next({errors:v?r.errors:{}})},Gt=(v,w,k)=>{const L=(O(o,v,{_f:{}})._f||{}).ref;Q(r.errors,v,{...w,ref:L}),f.state.next({name:v,errors:r.errors,isValid:!1}),k&&k.shouldFocus&&L&&L.focus&&L.focus()},Ge=(v,w)=>Tt(v)?f.values.subscribe({next:k=>v(H(void 0,w),k)}):H(v,w,!0),Ze=(v,w={})=>{for(const k of v?zs(v):c.mount)c.mount.delete(k),c.array.delete(k),w.keepValue||(ye(o,k),ye(s,k)),!w.keepError&&ye(r.errors,k),!w.keepDirty&&ye(r.dirtyFields,k),!w.keepTouched&&ye(r.touchedFields,k),!n.shouldUnregister&&!w.keepDefaultValue&&ye(i,k);f.values.next({values:{...s}}),f.state.next({...r,...w.keepDirty?{isDirty:B()}:{}}),!w.keepIsValid&&g()},Vo=({disabled:v,name:w,field:k,fields:L,value:P})=>{if(Mt(v)){const T=v?void 0:ie(P)?Ws(k?k._f:O(L,w)._f):P;Q(s,w,T),R(w,T,!1,!1,!0)}},Zt=(v,w={})=>{let k=O(o,v);const L=Mt(w.disabled);return Q(o,v,{...k||{},_f:{...k&&k._f?k._f:{ref:{name:v}},name:v,mount:!0,...w}}),c.mount.add(v),k?Vo({field:k,disabled:w.disabled,name:v}):F(v,!0,w.value),{...L?{disabled:w.disabled}:{},...n.progressive?{required:!!w.required,min:dr(w.min),max:dr(w.max),minLength:dr(w.minLength),maxLength:dr(w.maxLength),pattern:dr(w.pattern)}:{},name:v,onChange:Re,onBlur:Re,ref:P=>{if(P){Zt(v,w),k=O(o,v);const T=ie(P.value)&&P.querySelectorAll&&P.querySelectorAll("input,select,textarea")[0]||P,D=jb(T),ee=k._f.refs||[];if(D?ee.find(le=>le===T):T===k._f.ref)return;Q(o,v,{_f:{...k._f,...D?{refs:[...ee.filter(Xs),T,...Array.isArray(O(i,v))?[{}]:[]],ref:{type:T.type,name:v}}:{ref:T}}}),F(v,!1,void 0,T)}else k=O(o,v,{}),k._f&&(k._f.mount=!1),(n.shouldUnregister||w.shouldUnregister)&&!(Ob(c.array,v)&&a.action)&&c.unMount.add(v)}}},Jt=()=>n.shouldFocusError&&So(o,lt,c.mount),ut=v=>{Mt(v)&&(f.state.next({disabled:v}),So(o,w=>{w.disabled=v},0,!1))},fr=(v,w)=>async k=>{k&&(k.preventDefault&&k.preventDefault(),k.persist&&k.persist());let L=at(s);if(f.state.next({isSubmitting:!0}),n.resolver){const{errors:P,values:T}=await E();r.errors=P,L=T}else await K(o);ye(r.errors,"root"),Oe(r.errors)?(f.state.next({errors:{}}),await v(L,k)):(w&&await w({...r.errors},k),Jt(),setTimeout(Jt)),f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Oe(r.errors),submitCount:r.submitCount+1,errors:r.errors})},Oo=(v,w={})=>{O(o,v)&&(ie(w.defaultValue)?Le(v,O(i,v)):(Le(v,w.defaultValue),Q(i,v,w.defaultValue)),w.keepTouched||ye(r.touchedFields,v),w.keepDirty||(ye(r.dirtyFields,v),r.isDirty=w.defaultValue?B(v,O(i,v)):B()),w.keepError||(ye(r.errors,v),l.isValid&&g()),f.state.next({...r}))},Jd=(v,w={})=>{const k=v?at(v):i,L=at(k),P=v&&!Oe(v)?L:i;if(w.keepDefaultValues||(i=k),!w.keepValues){if(w.keepDirtyValues||h)for(const T of c.mount)O(r.dirtyFields,T)?Q(P,T,O(s,T)):Le(T,O(P,T));else{if(Is&&ie(v))for(const T of c.mount){const D=O(o,T);if(D&&D._f){const ee=Array.isArray(D._f.refs)?D._f.refs[0]:D._f.ref;if(Mo(ee)){const le=ee.closest("form");if(le){le.reset();break}}}}o={}}s=e.shouldUnregister?w.keepDefaultValues?at(i):{}:at(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&&!Yt(v,i)),isSubmitted:w.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:w.keepDirtyValues?r.dirtyFields:w.keepDefaultValues&&v?qs(i,v):{},touchedFields:w.keepTouched?r.touchedFields:{},errors:w.keepErrors?r.errors:{},isSubmitSuccessful:w.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1})},Qd=(v,w)=>Jd(Tt(v)?v(s):v,w);return{control:{register:Zt,unregister:Ze,getFieldState:Ct,handleSubmit:fr,setError:Gt,_executeSchema:E,_getWatch:H,_getDirty:B,_updateValid:g,_removeUnmounted:j,_updateFieldArray:M,_updateDisabledField:Vo,_getFieldArray:X,_reset:Jd,_resetDefaultValues:()=>Tt(n.defaultValues)&&n.defaultValues().then(v=>{Qd(v,n.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:v=>{r={...r,...v}},_disableForm:ut,_subjects:f,_proxyFormState:l,get _fields(){return o},get _formValues(){return s},get _state(){return a},set _state(v){a=v},get _defaultValues(){return i},get _names(){return c},set _names(v){c=v},get _formState(){return r},set _formState(v){r=v},get _options(){return n},set _options(v){n={...n,...v}}},trigger:Y,register:Zt,handleSubmit:fr,watch:Ge,setValue:Le,getValues:Ne,reset:Qd,resetField:Oo,clearErrors:At,unregister:Ze,setError:Gt,setFocus:(v,w={})=>{const k=O(o,v),L=k&&k._f;if(L){const P=L.refs?L.refs[0]:L.ref;P.focus&&(P.focus(),w.shouldSelect&&P.select())}},getFieldState:Ct}}function qd(e={}){const t=Ie.useRef(),n=Ie.useRef(),[r,o]=Ie.useState({isDirty:!1,isValidating:!1,isLoading:Tt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:Tt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Kb(e,()=>o(s=>({...s}))),formState:r});const i=t.current.control;return i._options=e,Fb({subject:i._subjects.state,next:s=>{Nb(s,i._proxyFormState,i._updateFormState,!0)&&o({...i._formState})}}),Ie.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),Ie.useEffect(()=>{if(i._proxyFormState.isDirty){const s=i._getDirty();s!==r.isDirty&&i._subjects.state.next({isDirty:s})}},[i,r.isDirty]),Ie.useEffect(()=>{e.values&&!Yt(e.values,n.current)?(i._reset(e.values,i._options.resetOptions),n.current=e.values):i._resetDefaultValues()},[e.values,i]),Ie.useEffect(()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),t.current.formState=Rb(r,i),t.current}var Wd=function(e,t,n){if(e&&"reportValidity"in e){var r=O(n,t);e.setCustomValidity(r&&r.message||""),e.reportValidity()}},Yb=function(e,t){var n=function(o){var i=t.fields[o];i&&i.ref&&"reportValidity"in i.ref?Wd(i.ref,o,e):i.refs&&i.refs.forEach(function(s){return Wd(s,o,e)})};for(var r in t.fields)n(r)},Gb=function(e,t){t.shouldUseNativeValidation&&Yb(e,t);var n={};for(var r in e){var o=O(t.fields,r),i=Object.assign(e[r]||{},{ref:o&&o.ref});if(Jb(t.names||Object.keys(e),r)){var s=Object.assign({},Zb(O(n,r)));Q(s,"root",i),Q(n,r,s)}else Q(n,r,i)}return n},Zb=function(e){return Array.isArray(e)?e.filter(Boolean):[]},Jb=function(e,t){return e.some(function(n){return n.startsWith(t+".")})},Qb=function(e,t){for(var n={};e.issues.length;){var r=e.issues[0];if(r.path){var o=r.path.map(function(a){return a.key}).join(".");if(n[o]||(n[o]={message:r.message,type:r.validation}),t){var i=n[o].types,s=i&&i[r.validation];n[o]=Ed(o,t,n,r.validation,s?[].concat(s,r.message):r.message)}e.issues.shift()}}return n},Kd=function(e,t,n){return n===void 0&&(n={}),function(r,o,i){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(rs(e,r,d)):Promise.resolve(rg(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 so)return{values:{},errors:Gb(Qb(s,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw s}))}catch(s){return Promise.reject(s)}}};const ey=e=>{const t=Object.fromEntries(new FormData(e).entries());Object.keys(t).length&&e.dispatchEvent(new Event("submit",{bubbles:!0}))},ty=ts("multiple-choice"),ny=e=>{const t={min:e.minSelected??0,max:e.maxSelected??e.options.length};return Kd(gn({checked:ku(ng(Gv()),n=>Object.entries(n).filter(([r,o])=>o).map(([r,o])=>r),[sg(t.max,`Please select at most ${t.max} option${t.max!==1?"s":""}`),$u(t.min,`Please select at least ${t.min} option${t.min!==1?"s":""}`)])}))},ry=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var u,d;const r=e.key?(u=re.current$.value.application)==null?void 0:u.data.submissions[e.key]:void 0,{register:o,handleSubmit:i,formState:{errors:s}}=qd({defaultValues:{checked:ty(r)?Object.fromEntries(r.value.map(l=>[l,!0])):{}},resolver:ny(e.config)}),a=Fs(),c=e.config.minSelected===1&&e.config.maxSelected===1;return b("form",{noValidate:!0,class:"flex flex-col gap-1",onChange:l=>{c&&ey(l.currentTarget)},onSubmit:i(l=>{const f=l.checked;t(f)}),children:[b("div",{class:"flex items-center gap-2",children:[b("div",{class:Xt("flex w-full flex-1 flex-wrap gap-3 p-1",{"justify-center":e.config.options.length===1}),children:e.config.options.map((l,f)=>{const h=`checked.${l.value}`,{ref:p,...m}=o(h);return b("div",{children:[b("input",{autoFocus:f===0,ref:y=>{y&&f===0&&(a.current=y),p(y)},id:h,...m,class:"peer sr-only",type:"checkbox"}),b("label",{class:"bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-neutral-12/5 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 duration-300 selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",htmlFor:h,children:l.label})]},l.value)})}),!c&&b(ko,{})]}),b(Ds,{onAnimationComplete:n,error:(d=s.checked)==null?void 0:d.root})]})},Eo={email:"That doesn’t look like a valid email address",phone:"That doesn’t look like a valid phone number"},oy=We(Eo.phone,[ag(/^\+?[0-9 -]+$/,Eo.phone)]),iy={email:We(Eo.email,[ig(Eo.email)]),phone:ku(oy,e=>e.replace(/[^0-9]/g,"")),text:We([$u(1,"Please enter some text")]),url:We([cg("That doesn’t look like a valid URL")])},sy={email:{type:"email",inputMode:"email",formNoValidate:!0},phone:{type:"tel",inputMode:"tel"},text:{type:"text",inputMode:"text"},url:{type:"url",inputMode:"url",formNoValidate:!0}},ay=ts("text"),cy=e=>Kd(gn({text:iy[e.format]})),ly=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var d;const r=e.key?(d=re.current$.value.application)==null?void 0:d.data.submissions[e.key]:void 0,{register:o,handleSubmit:i,formState:{errors:s}}=qd({defaultValues:{text:ay(r)?r.value:""},resolver:cy(e.config)}),{ref:a,...c}=o("text",{required:!0}),u=U();return Be(()=>{u.current&&(u.current.focus(),u.current.select())},[]),b("form",{noValidate:!0,class:"flex flex-col gap-1",onSubmit:i(l=>{t(l.text)}),children:[b("div",{class:"flex items-center gap-2",children:[b("input",{id:"chat-input",...c,...sy[e.config.format],autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:l=>{l&&(u.current=l),a(l)},class:"outline-neutral-12/5 ease-expo-out placeholder:text-neutral-5 focus-visible:outline-accent-7 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2 transition-all duration-300",placeholder:e.config.placeholder}),b(ko,{})]}),b(Ds,{onAnimationComplete:n,error:s.text})]})},uy=({onSubmit:e,onInputChange:t,input:n})=>{const r=U(null),o=me(()=>{r.current&&(ns.value=r.current.getBoundingClientRect().height)},[]);G(()=>{o(),t(n==null?void 0:n.type)},[n==null?void 0:n.type,t,o]);const i=s=>a=>e({type:s,value:a});return b(Kn.div,{initial:{height:0},animate:{height:ns.value},exit:{height:0,opacity:0},class:"bg-neutral-2/80 absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",children:b("div",{ref:r,class:"border-neutral-12/5 border-t p-2.5",children:tt({application:re,input:n,onHeightChange:o}).with({input:Ae.nullish},()=>b("div",{class:"flex items-center gap-2",children:[b("input",{"aria-hidden":"true",id:"chat-input",class:"outline-neutral-12/5 placeholder:text-neutral-4 focus-visible:outline-accent-9 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2",disabled:!0}),b(ko,{disabled:!0,"aria-hidden":"true",tabIndex:-1})]})).with({input:{type:"text"}},s=>b(ly,{onSubmitSuccess:i(s.input.type),...s})).with({input:{type:"multiple-choice"}},s=>b(ry,{onSubmitSuccess:i(s.input.type),...s})).with({input:{type:"boolean"}},s=>b(Sb,{onSubmitSuccess:i(s.input.type),...s})).with({input:{type:"file"}},s=>b(Pb,{onSubmitSuccess:i(s.input.type),...s})).exhaustive()})})},Yd=e=>typeof e=="boolean"?"".concat(e):e===0?"0":e,Gd=Xt,Zd=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return Gd(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:o,defaultVariants:i}=t,s=Object.keys(o).map(u=>{const d=n==null?void 0:n[u],l=i==null?void 0:i[u];if(d===null)return null;const f=Yd(d)||Yd(l);return o[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,...h}=d;return Object.entries(h).every(p=>{let[m,y]=p;return Array.isArray(y)?y.includes({...i,...a}[m]):{...i,...a}[m]===y})?[...u,l,f]:u},[]);return Gd(e,s,c,n==null?void 0:n.class,n==null?void 0:n.className)},dy=Zd("max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink-1 min-w-[2rem] text-md py-2 px-3 rounded-[18px] min-h-[36px] break-words",{variants:{side:{left:"bg-lowest text-neutral-12 shadow-surface-sm outline outline-1 outline-neutral-11/[.08] rounded-bl-md",right:"ml-auto bg-accent-7 text-lowest rounded-br-md bubble-right"},transitionState:{entering:"opacity-0 translate-y-8",entered:"opacity-100 translate-y-0",exiting:"opacity-0 scale-0",exited:""}},defaultVariants:{side:"left"}}),fy={hidden:{y:"100%",scale:.75},shown:{y:0,scale:1}},hy=({children:e,className:t,transitionState:n,side:r,...o})=>b(Kn.p,{variants:fy,initial:"hidden",animate:"shown",transition:{type:"spring",damping:25,stiffness:500},"data-transition":n,style:{transformOrigin:r==="left"?"0% 50%":"100% 50%"},class:dy({className:t,side:r,transitionState:n}),...o,children:e}),py=({className:e,...t})=>b("div",{class:Xt("flex gap-1 p-4",e),...t,children:Array.from({length:3},(n,r)=>b("div",{class:"bg-accent-7 h-1.5 w-1.5 animate-bounce rounded-full",style:{animationDelay:`${-r*200}ms`}}))}),my={bot:"left",user:"right"},vy=Zd("w-full select-none py-2 text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_white]",{variants:{variant:{info:"text-neutral-8",warning:"text-[#FFC107]",error:"text-error-9",success:"text-[#4CAF50]"}}}),gy=({messages:e,isBotTyping:t})=>b("ol",{"aria-label":"Chat messages",class:"flex flex-grow flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",children:[b(to,{initial:!1,children:e.map((n,r)=>b("li",{class:"flex",children:tt(n).with({type:"system"},o=>b("p",{class:vy({variant:o.variant}),children:o.text})).with({type:"text",author:Ae.union("bot","user")},o=>b(hy,{side:my[o.author],children:o.text},r)).with({type:"link"},o=>b("div",{class:"bg-accent-8/5 flex w-full items-center justify-center overflow-hidden rounded-xl py-2",children:b("a",{class:"bg-lowest shadow-surface-sm ring-accent-8/20 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 flex items-center gap-1.5 truncate rounded-full py-2 pl-4 pr-2.5 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,b("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b("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=>b("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=>b(Ab,{class:o.author==="bot"?"":"ml-auto",file:{name:o.fileName,sizeKb:o.fileSizeKb}})).exhaustive()},r))}),b("aside",{"aria-hidden":!0,children:t&&b(py,{})})]}),by=25,yy=()=>{const e=U(null),[t,n]=ae(!1),[r,o]=ae(()=>()=>{}),i=de(()=>a=>{var c;return(c=e.current)==null?void 0:c.scrollTo({top:e.current.scrollHeight,...a})},[e]),s=de(()=>({send:async({message:a,signal:c,groupId:u})=>{if(await tt(a).with({author:"bot",type:"text"},async d=>{if(c!=null&&c.aborted)throw new Jn;n(!0);const l=Math.max(20,d.text.length)*by;await new Promise(f=>setTimeout(f,l,{signal:c})),n(!1)}).otherwise(async()=>{}),c!=null&&c.aborted)throw new Jn;re.addMessage(a,u)},input:async({input:a,signal:c})=>{if(c!=null&&c.aborted)throw new Jn;return re.setInput(a),await new Promise(u=>{const d=l=>{if(c!=null&&c.aborted)throw new Jn;re.setInput(void 0),a.key&&re.setSubmission(a.key,l),u(l)};o(()=>d)})}}),[]);return{chatRef:e,chatService:s,isBotTyping:t,onSubmitSuccessFn:r,scrollToEnd:i}},wy=Object.freeze(Object.defineProperty({__proto__:null,JobApplicationContent:({currentApplication:e,logger:t,apiClient:n,analytics:r})=>{const{chatRef:o,chatService:i,isBotTyping:s,onSubmitSuccessFn:a,scrollToEnd:c}=yy(),u=nt.value,d=e.flow,l=e.job;return Be(()=>{u==="maximised"&&c({behavior:"instant"})},[c,u]),G(()=>{c({behavior:"smooth"})},[e.data.messages,c]),Be(()=>{const{state:f,application:h}=re.current$.peek();if(f!=="loaded")throw new Error(Ev.invalid_state);const p=h.data.currentNodeId;if(c({behavior:"instant"}),re.setInput(void 0),h.data.isFinished)return;h.data.messages.length===0&&r.log({event:"APPLY_START",properties:{job_id:l.id},customProperties:{flow_id:d.id}}),re.removeLastGroupMessagesById(p);const{interpret:y,abort:x}=cb({context:{jobId:l.id,flowId:d.id},analytics:r,apiClient:n,logger:t,flow:d.nodes,chatService:i,getSubmissions:()=>{var g;return(g=re.current$.peek().application)==null?void 0:g.data.submissions},onInterpret:(g,_)=>{r.log({event:"FLOW_NODE",properties:{flow_id:d.id,flow_version:d.version,job_id:l.id,from_node_id:_?_.id:null,to_node_id:g.id,sequence:1}}),re.setCurrentNodeId(g.id)},onFlowEnd:async()=>{re.markAsFinished()}});return y(p),x},[r,n,i,t,c,d,l.id,e.startedAt]),b(ue,{children:[b("div",{ref:o,className:"hide-scrollbars relative flex max-w-full flex-grow flex-col overflow-y-scroll",style:{WebkitOverflowScrolling:"touch",paddingBottom:ns.value},children:b(to,{children:b(gy,{isBotTyping:s,messages:e.data.messages})})}),b(uy,{input:e.data.currentInput,onInputChange:()=>c({behavior:"smooth"}),onSubmit:a})]})}},Symbol.toStringTag,{value:"Module"}))})();
57
+ }`,sb=({_internal_domManager:e=fg(),theme:t})=>Et(({apiClient:n,logger:r,analytics:o})=>{let i=!1;const s=()=>{if(typeof window>"u")return;const a=e.getOrCreateChatbotElement();e.addStyle(dg,"inploi-chatbot-style");const c=ib([{name:"a",colors:xd(t)},{name:"n",colors:xd({hue:t.hue,chroma:.1})}]);e.addStyle(c,"inploi-chatbot-theme"),en(N(jv,{apiClient:n,logger:r,analytics:o}),a),i=!0};return{prepare:async()=>{if(!(typeof window>"u"))try{if(i)return;s(),r.info("Chatbot plugin prepared")}catch(a){console.error(a),r.error("Error preparing chatbot plugin",a)}},startApplication:async({jobId:a})=>{if(!(typeof window>"u"))try{re.cancel(),pf(()=>{nt.value="maximised",re.current$.value={state:"loading"}}),ug({jobId:a,apiClient:n,logger:r}).then(c=>{c.ok?re.start(c.value):re.current$.value={state:"error",error:c.error}}),i||s()}catch(c){console.error(c),r.error("Error starting application",c)}},closeApplication:async()=>{typeof window>"u"||(r.info("Closing application from an external source"),re.cancel())}}});if(!window.inploi)throw new Error("Please insert the SDK script tag above the plugins.");window.inploi.chatbotPlugin=sb;const kd=({node:e,nodes:t,stopWhen:n})=>{if((n==null?void 0:n(e))===!0)return e;const r=e.nextId?t.find(o=>o.id===e.nextId):void 0;if(r)return kd({node:r,nodes:t,stopWhen:n})},ab=({childNode:e,nodes:t})=>{const r=t.filter(o=>o.type==="if-block").find(o=>{if(!o.branchId)return!1;const i=t.find(a=>a.id===o.branchId);if(!i)return!1;const s=kd({node:i,nodes:t,stopWhen:a=>a.id===e.id});return!(!s||s.id!==e.id)});if(r!=null&&r.nextId)return t.find(o=>o.id===r.nextId)},cb=({flow:e,analytics:t,logger:n,context:r,apiClient:o,getSubmissions:i,chatService:s,onFlowEnd:a,onInterpret:c})=>{const u=new AbortController,d=async(l,f)=>{const h=i();c==null||c(l,f);try{await lb({analytics:t,logger:n,apiClient:o,context:r,node:l,submissions:h,chat:{sendMessage:async p=>s.send({groupId:l.id,message:p,signal:u.signal}),userInput:async p=>s.input({input:p,signal:u.signal})},next:p=>{const m=p?e.find(y=>y.id===p):ab({childNode:l,nodes:e});return m?d(m,l):a==null?void 0:a(l)}})}catch(p){if(p instanceof Jn)return;throw p}};return{interpret:async l=>{const f=e.find(h=>h.id===l)??vu(e);return d(f)},abort:()=>{u.abort()}}};async function lb(e){return await tt(e).with({node:{type:"text"}},hb).with({node:{type:"image"}},pb).with({node:{type:"question-text"}},mb).with({node:{type:"question-enum"}},gb).with({node:{type:"question-number"}},vb).with({node:{type:"question-boolean"}},bb).with({node:{type:"question-file"}},wb).with({node:{type:"question-address"}},yb).with({node:{type:"end-flow"}},_b).with({node:{type:"if-block"}},fb).with({node:{type:"jump"}},({node:t,next:n})=>n(t.data.targetId)).with({node:{type:"link"}},db).with({node:{type:"submit"}},ub).exhaustive()}async function ub({chat:e,next:t,node:n,logger:r,apiClient:o,submissions:i,context:s}){await e.userInput({type:"multiple-choice",key:void 0,config:{options:[{label:"Submit my application",value:"submit"}],maxSelected:1,minSelected:1}}),await e.sendMessage({type:"system",variant:"info",text:"Submitting your application…"});const a=await o.fetch("/flow/apply",{method:"POST",body:JSON.stringify({...s,submissions:Lv(i||{})})}).catch(c=>c);await tt(a).with({redirect_url:Ae.string},async c=>{await e.sendMessage({type:"text",author:"bot",text:"Almost there! Please finalise your application on our partner’s website."}),await e.sendMessage({type:"link",href:c.redirect_url,text:"Finalise application on partner"})}).with({message:"Success"},async()=>{await e.sendMessage({type:"system",variant:"success",text:"Application submitted"}),t(n.nextId)}).otherwise(async c=>{r.error(c),await e.sendMessage({type:"system",variant:"error",text:"Failed to submit application"}),t(n.id)})}async function db({chat:e,next:t,node:n}){await e.sendMessage({type:"link",href:n.data.href,text:n.data.cta}),t(n.nextId)}async function fb({submissions:e,next:t,node:n}){const r=xb(n,e)?n.branchId:n.nextId;t(r)}async function hb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.text}),t(n.nextId)}async function pb({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 mb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const r=await e.userInput({key:n.data.key,type:"text",config:{placeholder:n.data.placeholder,format:n.data.format}});await e.sendMessage({author:"user",type:"text",text:r.value}),t(n.nextId)}async function vb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const r=await e.userInput({key:n.data.key,type:"text",config:{placeholder:n.data.placeholder,format:"text"}});await e.sendMessage({author:"user",type:"text",text:r.value}),t(n.nextId)}async function gb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const r=await e.userInput({key:n.data.key,type:"multiple-choice",config:n.data});await e.sendMessage({author:"user",type:"text",text:r.value.join(", ")}),t(n.nextId)}async function bb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const o=(await e.userInput({key:n.data.key,type:"boolean",config:{labels:{true:n.data.trueLabel,false:n.data.falseLabel}}})).value,i={true:n.data.trueLabel,false:n.data.falseLabel};await e.sendMessage({author:"user",type:"text",text:i[o]}),t(n.nextId)}async function yb({chat:e,next:t,node:n}){await e.sendMessage({author:"bot",type:"text",text:"Address questions are not implemented yet"}),t(n.nextId)}async function wb({node:e,chat:t,next:n}){await t.sendMessage({author:"bot",type:"text",text:e.data.question});const r=await t.userInput({key:e.data.key,type:"file",config:{extensions:e.data.extensions,fileSizeLimitKib:e.data.maxSizeKb,allowMultiple:e.data.multiple===!0}});for await(const o of r.value)await t.sendMessage({author:"user",type:"file",fileName:o.name,fileSizeKb:o.sizeKb});n(e.nextId)}async function _b({chat:e,next:t,node:n}){await e.sendMessage({type:"system",variant:"info",text:n.data.systemMessage||"Conversation finished"}),t(void 0)}const $d=Ae.union(Ae.string,Ae.array(Ae.string)),xb=(e,t)=>{const n=t==null?void 0:t[e.data.compareKey];return n?tt({...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:$d}},({compareValue:r,answer:o})=>o.value.includes(r)).with({compare:"notContains",answer:{value:$d}},({compareValue:r,answer:o})=>!o.value.includes(r)).with({answer:{type:"file"}},()=>!1).exhaustive():!1},ko=({class:e,...t})=>b("button",{class:Xt("bg-accent-7 active:bg-accent-10 active:text-accent-2 text-lowest pointer-coarse:touch-hitbox focus-visible:ring-accent-7/50 flex-shrink-0 rounded-full p-2 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:b("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"2",children:[b("title",{children:"Send"}),b("path",{d:"M3.5 7.5L8 3L12.5 7.5"}),b("path",{d:"M8 4V13"})]})}),Fs=()=>{const e=U(null);return G(()=>{var t;(t=e.current)==null||t.focus()},[]),e},Sd=["true","false"],kb=Qv(Sd),$b="answer",Sb=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{const r=Fs();return n(),b("form",{noValidate:!0,class:"flex items-center gap-2",onSubmit:o=>{o.preventDefault();const i=tt(o).with({nativeEvent:{submitter:Ae.select(Ae.union(Ae.instanceOf(HTMLButtonElement),Ae.instanceOf(HTMLInputElement)))}},a=>a.value).otherwise(()=>{throw new Error("invalid form")}),s=rs(kb,i);t(s)},children:Sd.map((o,i)=>b("button",{ref:i===0?r:null,type:"submit",name:$b,value:o,class:"bg-lowest ease-expo-out ring-neutral-12/5 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 duration-300 selection:bg-transparent",children:b("p",{class:"truncate text-center text-base",children:e.config.labels[o]})}))})},Ds=({error:e,onAnimationComplete:t})=>b(to,{children:e&&b(Kn.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},onAnimationComplete:t,role:"alert",class:"text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full p-0.5 px-1 opacity-0",children:[b("svg",{class:"text-error-10",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b("circle",{cx:"8",cy:"8",r:"6.3",stroke:"currentColor","stroke-width":"1.4"}),b("rect",{x:"7",y:"4",width:"2",height:"5",fill:"currentColor"}),b("rect",{x:"7",y:"10",width:"2",height:"2",fill:"currentColor"})]}),b("p",{class:"truncate pr-1 text-sm",children:e.message})]})}),Mb=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}),$o=e=>tt(e).with(Ae.number.lte(1e3),()=>`${Math.round(e)}KB`).with(Ae.number.lt(1e3*10),()=>`${(e/1e3).toFixed(1)}MB`).otherwise(()=>`${Math.round(e/1e3)}MB`),Tb=e=>e.reduce((t,n)=>t+n.sizeKb,0),Cb=ts("file"),Md=3,Ab=({file:e,class:t,...n})=>{const r=e.name.split(".").pop(),o=e.name.replace(new RegExp(`.${r}$`),"");return b("div",{class:Xt("bg-accent-1 outline-neutral-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline",t),...n,children:[b("p",{"aria-label":"File name",class:"text-accent-12 flex flex-grow overflow-hidden",children:[b("span",{class:"block truncate",children:o}),b("span",{children:[".",r]})]}),b("p",{"aria-label":"File size",class:"text-neutral-10",children:$o(e.sizeKb)})]})},Td=({class:e,...t})=>b("li",{class:Xt("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1",e),...t}),Pb=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var l;const r=(l=re.current$.value.application)==null?void 0:l.data.submissions[e.key],[o,i]=ae(Cb(r)?r.value:[]),[s,a]=ae(),c=o.length-Md,u=Tb(o),d=Fs();return b("form",{class:"flex flex-col gap-1",onSubmit:f=>(f.preventDefault(),a(void 0),o.length===0&&a({type:"required",message:"Please select a file"}),e.config.fileSizeLimitKib&&u>e.config.fileSizeLimitKib&&a({type:"max",message:`File size exceeds limit of ${$o(e.config.fileSizeLimitKib)}`}),t(o)),children:[b("div",{class:"flex items-center gap-2",children:[b("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:[o.length>0?b(ue,{children:[b("ul",{class:"flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",children:[o.slice(0,Md).map(f=>{const h=f.name.split(".").pop(),p=f.name.replace(new RegExp(`.${h}$`),"");return b(Td,{class:"flex overflow-hidden",children:[b("span",{class:"block truncate",children:p}),b("span",{children:[".",h]})]})}),c>0?b(Td,{children:["+",c," file",c!==1?"s":""]}):null]}),b("p",{class:"text-neutral-11 text-xs",children:[$o(u)," ",o.length>1?"total":""]})]}):b("div",{class:"flex flex-col justify-center gap-4 pb-6 pt-5",children:[b("header",{class:"flex flex-col items-center gap-0",children:[b("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:b("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"})}),b("p",{class:"text-neutral-12 tracking-[-0.01em] dark:text-gray-400",children:[e.config.allowMultiple?"Select files":"Select a file"," to upload"]}),e.config.fileSizeLimitKib?b("p",{class:"text-neutral-10 text-xs",children:["(max ",$o(e.config.fileSizeLimitKib),")"]}):null]}),b("aside",{class:"flex flex-col items-center gap-2",children:[b("p",{id:"accepted-filetypes",class:"sr-only",children:"Accepted file extensions"}),b("ul",{"aria-describedby":"accepted-filetypes",class:"flex flex-wrap justify-center gap-2",children:e.config.extensions.map(f=>b("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(".","")}))})]})]}),b("input",{id:"dropzone-file",onInput:async f=>{Fe(f.target instanceof HTMLInputElement);const h=f.target.files?Array.from(f.target.files):[],p=await Promise.allSettled(h.map(async y=>{const x=await Mb(y);return{name:y.name,data:x,sizeKb:y.size/1e3}}));if(p.some(({status:y})=>y==="rejected"))return a({type:"invalid",message:"Invalid file"});const m=p.map(y=>y.status==="fulfilled"?y.value:null).filter(Boolean);i(m)},multiple:e.config.allowMultiple,type:"file",class:"sr-only"})]}),b(ko,{disabled:o.length===0})]}),s&&b(Ds,{onAnimationComplete:n,error:s})]})};var lr=e=>e.type==="checkbox",Sn=e=>e instanceof Date,Me=e=>e==null;const Cd=e=>typeof e=="object";var fe=e=>!Me(e)&&!Array.isArray(e)&&Cd(e)&&!Sn(e),Eb=e=>fe(e)&&e.target?lr(e.target)?e.target.checked:e.target.value:e,Vb=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Ob=(e,t)=>e.has(Vb(t)),Lb=e=>{const t=e.constructor&&e.constructor.prototype;return fe(t)&&t.hasOwnProperty("isPrototypeOf")},Is=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function at(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(!(Is&&(e instanceof Blob||e instanceof FileList))&&(n||fe(e)))if(t=n?[]:{},!n&&!Lb(e))t=e;else for(const r in e)e.hasOwnProperty(r)&&(t[r]=at(e[r]));else return e;return t}var ur=e=>Array.isArray(e)?e.filter(Boolean):[],ie=e=>e===void 0,O=(e,t,n)=>{if(!t||!fe(e))return n;const r=ur(t.split(/[,[\].]+?/)).reduce((o,i)=>Me(o)?o:o[i],e);return ie(r)||r===e?ie(e[t])?n:e[t]:r},Mt=e=>typeof e=="boolean";const Ad={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},ze={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},ct={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};Ie.createContext(null);var Rb=(e,t,n,r=!0)=>{const o={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(o,i,{get:()=>{const s=i;return t._proxyFormState[s]!==ze.all&&(t._proxyFormState[s]=!r||ze.all),n&&(n[s]=!0),e[s]}});return o},Oe=e=>fe(e)&&!Object.keys(e).length,Nb=(e,t,n,r)=>{n(e);const{name:o,...i}=e;return Oe(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(s=>t[s]===(!r||ze.all))},zs=e=>Array.isArray(e)?e:[e];function Fb(e){const t=Ie.useRef(e);t.current=e,Ie.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var Ye=e=>typeof e=="string",Db=(e,t,n,r,o)=>Ye(e)?(r&&t.watch.add(e),O(n,e,o)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),O(n,i))):(r&&(t.watchAll=!0),n),Bs=e=>/^\w*$/.test(e),Pd=e=>ur(e.replace(/["|']|\]/g,"").split(/\.|\[/));function Q(e,t,n){let r=-1;const o=Bs(t)?[t]:Pd(t),i=o.length,s=i-1;for(;++r<i;){const a=o[r];let c=n;if(r!==s){const u=e[a];c=fe(u)||Array.isArray(u)?u:isNaN(+o[r+1])?{}:[]}e[a]=c,e=e[a]}return e}var Ed=(e,t,n,r,o)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:o||!0}}:{},Vd=e=>({isOnSubmit:!e||e===ze.onSubmit,isOnBlur:e===ze.onBlur,isOnChange:e===ze.onChange,isOnAll:e===ze.all,isOnTouch:e===ze.onTouched}),Od=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const So=(e,t,n,r)=>{for(const o of n||Object.keys(e)){const i=O(e,o);if(i){const{_f:s,...a}=i;if(s){if(s.refs&&s.refs[0]&&t(s.refs[0],o)&&!r)break;if(s.ref&&t(s.ref,s.name)&&!r)break}else fe(a)&&So(a,t)}}};var Ib=(e,t,n)=>{const r=ur(O(e,n));return Q(r,"root",t[n]),Q(e,n,r),e},js=e=>e.type==="file",Tt=e=>typeof e=="function",Mo=e=>{if(!Is)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},To=e=>Ye(e),Hs=e=>e.type==="radio",Co=e=>e instanceof RegExp;const Ld={value:!1,isValid:!1},Rd={value:!0,isValid:!0};var Nd=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&&!ie(e[0].attributes.value)?ie(e[0].value)||e[0].value===""?Rd:{value:e[0].value,isValid:!0}:Rd:Ld}return Ld};const Fd={isValid:!1,value:null};var Dd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Fd):Fd;function Id(e,t,n="validate"){if(To(e)||Array.isArray(e)&&e.every(To)||Mt(e)&&!e)return{type:n,message:To(e)?e:"",ref:t}}var Mn=e=>fe(e)&&!Co(e)?e:{value:e,message:""},zd=async(e,t,n,r,o)=>{const{ref:i,refs:s,required:a,maxLength:c,minLength:u,min:d,max:l,pattern:f,validate:h,name:p,valueAsNumber:m,mount:y,disabled:x}=e._f,g=O(t,p);if(!y||x)return{};const _=s?s[0]:i,M=j=>{r&&_.reportValidity&&(_.setCustomValidity(Mt(j)?"":j||""),_.reportValidity())},S={},F=Hs(i),R=lr(i),C=F||R,E=(m||js(i))&&ie(i.value)&&ie(g)||Mo(i)&&i.value===""||g===""||Array.isArray(g)&&!g.length,q=Ed.bind(null,p,n,S),K=(j,B,H,X=ct.maxLength,ne=ct.minLength)=>{const se=j?B:H;S[p]={type:j?X:ne,message:se,ref:i,...q(j?X:ne,se)}};if(o?!Array.isArray(g)||!g.length:a&&(!C&&(E||Me(g))||Mt(g)&&!g||R&&!Nd(s).isValid||F&&!Dd(s).isValid)){const{value:j,message:B}=To(a)?{value:!!a,message:a}:Mn(a);if(j&&(S[p]={type:ct.required,message:B,ref:_,...q(ct.required,B)},!n))return M(B),S}if(!E&&(!Me(d)||!Me(l))){let j,B;const H=Mn(l),X=Mn(d);if(!Me(g)&&!isNaN(g)){const ne=i.valueAsNumber||g&&+g;Me(H.value)||(j=ne>H.value),Me(X.value)||(B=ne<X.value)}else{const ne=i.valueAsDate||new Date(g),se=lt=>new Date(new Date().toDateString()+" "+lt),Le=i.type=="time",Re=i.type=="week";Ye(H.value)&&g&&(j=Le?se(g)>se(H.value):Re?g>H.value:ne>new Date(H.value)),Ye(X.value)&&g&&(B=Le?se(g)<se(X.value):Re?g<X.value:ne<new Date(X.value))}if((j||B)&&(K(!!j,H.message,X.message,ct.max,ct.min),!n))return M(S[p].message),S}if((c||u)&&!E&&(Ye(g)||o&&Array.isArray(g))){const j=Mn(c),B=Mn(u),H=!Me(j.value)&&g.length>+j.value,X=!Me(B.value)&&g.length<+B.value;if((H||X)&&(K(H,j.message,B.message),!n))return M(S[p].message),S}if(f&&!E&&Ye(g)){const{value:j,message:B}=Mn(f);if(Co(j)&&!g.match(j)&&(S[p]={type:ct.pattern,message:B,ref:i,...q(ct.pattern,B)},!n))return M(B),S}if(h){if(Tt(h)){const j=await h(g,t),B=Id(j,_);if(B&&(S[p]={...B,...q(ct.validate,B.message)},!n))return M(B.message),S}else if(fe(h)){let j={};for(const B in h){if(!Oe(j)&&!n)break;const H=Id(await h[B](g,t),_,B);H&&(j={...H,...q(B,H.message)},M(H.message),n&&(S[p]=j))}if(!Oe(j)&&(S[p]={ref:_,...j},!n))return S}}return M(!0),S};function zb(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=ie(e)?r++:e[t[r++]];return e}function Bb(e){for(const t in e)if(e.hasOwnProperty(t)&&!ie(e[t]))return!1;return!0}function ye(e,t){const n=Array.isArray(t)?t:Bs(t)?[t]:Pd(t),r=n.length===1?e:zb(e,n),o=n.length-1,i=n[o];return r&&delete r[i],o!==0&&(fe(r)&&Oe(r)||Array.isArray(r)&&Bb(r))&&ye(e,n.slice(0,-1)),e}function Us(){let e=[];return{get observers(){return e},next:o=>{for(const i of e)i.next&&i.next(o)},subscribe:o=>(e.push(o),{unsubscribe:()=>{e=e.filter(i=>i!==o)}}),unsubscribe:()=>{e=[]}}}var Ao=e=>Me(e)||!Cd(e);function Yt(e,t){if(Ao(e)||Ao(t))return e===t;if(Sn(e)&&Sn(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n){const i=e[o];if(!r.includes(o))return!1;if(o!=="ref"){const s=t[o];if(Sn(i)&&Sn(s)||fe(i)&&fe(s)||Array.isArray(i)&&Array.isArray(s)?!Yt(i,s):i!==s)return!1}}return!0}var Bd=e=>e.type==="select-multiple",jb=e=>Hs(e)||lr(e),Xs=e=>Mo(e)&&e.isConnected,jd=e=>{for(const t in e)if(Tt(e[t]))return!0;return!1};function Po(e,t={}){const n=Array.isArray(e);if(fe(e)||n)for(const r in e)Array.isArray(e[r])||fe(e[r])&&!jd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Po(e[r],t[r])):Me(e[r])||(t[r]=!0);return t}function Hd(e,t,n){const r=Array.isArray(e);if(fe(e)||r)for(const o in e)Array.isArray(e[o])||fe(e[o])&&!jd(e[o])?ie(t)||Ao(n[o])?n[o]=Array.isArray(e[o])?Po(e[o],[]):{...Po(e[o])}:Hd(e[o],Me(t)?{}:t[o],n[o]):n[o]=!Yt(e[o],t[o]);return n}var qs=(e,t)=>Hd(e,t,Po(t)),Ud=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>ie(e)?e:t?e===""?NaN:e&&+e:n&&Ye(e)?new Date(e):r?r(e):e;function Ws(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return js(t)?t.files:Hs(t)?Dd(e.refs).value:Bd(t)?[...t.selectedOptions].map(({value:n})=>n):lr(t)?Nd(e.refs).value:Ud(ie(t.value)?e.ref.value:t.value,e)}var Hb=(e,t,n,r)=>{const o={};for(const i of e){const s=O(t,i);s&&Q(o,i,s._f)}return{criteriaMode:n,names:[...e],fields:o,shouldUseNativeValidation:r}},dr=e=>ie(e)?e:Co(e)?e.source:fe(e)?Co(e.value)?e.value.source:e.value:e,Ub=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Xd(e,t,n){const r=O(e,n);if(r||Bs(n))return{error:r,name:n};const o=n.split(".");for(;o.length;){const i=o.join("."),s=O(t,i),a=O(e,i);if(s&&!Array.isArray(s)&&n!==i)return{name:n};if(a&&a.type)return{name:i,error:a};o.pop()}return{name:n}}var Xb=(e,t,n,r,o)=>o.isOnAll?!1:!n&&o.isOnTouch?!(t||e):(n?r.isOnBlur:o.isOnBlur)?!e:(n?r.isOnChange:o.isOnChange)?e:!0,qb=(e,t)=>!ur(O(e,t)).length&&ye(e,t);const Wb={mode:ze.onSubmit,reValidateMode:ze.onChange,shouldFocusError:!0};function Kb(e={},t){let n={...Wb,...e},r={submitCount:0,isDirty:!1,isLoading:Tt(n.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},o={},i=fe(n.defaultValues)||fe(n.values)?at(n.defaultValues||n.values)||{}:{},s=n.shouldUnregister?{}:at(i),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:Us(),array:Us(),state:Us()},h=e.resetOptions&&e.resetOptions.keepDirtyValues,p=Vd(n.mode),m=Vd(n.reValidateMode),y=n.criteriaMode===ze.all,x=v=>w=>{clearTimeout(d),d=setTimeout(v,w)},g=async v=>{if(l.isValid||v){const w=n.resolver?Oe((await E()).errors):await K(o,!0);w!==r.isValid&&f.state.next({isValid:w})}},_=v=>l.isValidating&&f.state.next({isValidating:v}),M=(v,w=[],k,L,P=!0,T=!0)=>{if(L&&k){if(a.action=!0,T&&Array.isArray(O(o,v))){const D=k(O(o,v),L.argA,L.argB);P&&Q(o,v,D)}if(T&&Array.isArray(O(r.errors,v))){const D=k(O(r.errors,v),L.argA,L.argB);P&&Q(r.errors,v,D),qb(r.errors,v)}if(l.touchedFields&&T&&Array.isArray(O(r.touchedFields,v))){const D=k(O(r.touchedFields,v),L.argA,L.argB);P&&Q(r.touchedFields,v,D)}l.dirtyFields&&(r.dirtyFields=qs(i,s)),f.state.next({name:v,isDirty:B(v,w),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else Q(s,v,w)},S=(v,w)=>{Q(r.errors,v,w),f.state.next({errors:r.errors})},F=(v,w,k,L)=>{const P=O(o,v);if(P){const T=O(s,v,ie(k)?O(i,v):k);ie(T)||L&&L.defaultChecked||w?Q(s,v,w?T:Ws(P._f)):ne(v,T),a.mount&&g()}},R=(v,w,k,L,P)=>{let T=!1,D=!1;const ee={name:v};if(!k||L){l.isDirty&&(D=r.isDirty,r.isDirty=ee.isDirty=B(),T=D!==ee.isDirty);const le=Yt(O(i,v),w);D=O(r.dirtyFields,v),le?ye(r.dirtyFields,v):Q(r.dirtyFields,v,!0),ee.dirtyFields=r.dirtyFields,T=T||l.dirtyFields&&D!==!le}if(k){const le=O(r.touchedFields,v);le||(Q(r.touchedFields,v,k),ee.touchedFields=r.touchedFields,T=T||l.touchedFields&&le!==k)}return T&&P&&f.state.next(ee),T?ee:{}},C=(v,w,k,L)=>{const P=O(r.errors,v),T=l.isValid&&Mt(w)&&r.isValid!==w;if(e.delayError&&k?(u=x(()=>S(v,k)),u(e.delayError)):(clearTimeout(d),u=null,k?Q(r.errors,v,k):ye(r.errors,v)),(k?!Yt(P,k):P)||!Oe(L)||T){const D={...L,...T&&Mt(w)?{isValid:w}:{},errors:r.errors,name:v};r={...r,...D},f.state.next(D)}_(!1)},E=async v=>n.resolver(s,n.context,Hb(v||c.mount,o,n.criteriaMode,n.shouldUseNativeValidation)),q=async v=>{const{errors:w}=await E(v);if(v)for(const k of v){const L=O(w,k);L?Q(r.errors,k,L):ye(r.errors,k)}else r.errors=w;return w},K=async(v,w,k={valid:!0})=>{for(const L in v){const P=v[L];if(P){const{_f:T,...D}=P;if(T){const ee=c.array.has(T.name),le=await zd(P,s,y,n.shouldUseNativeValidation&&!w,ee);if(le[T.name]&&(k.valid=!1,w))break;!w&&(O(le,T.name)?ee?Ib(r.errors,le,T.name):Q(r.errors,T.name,le[T.name]):ye(r.errors,T.name))}D&&await K(D,w,k)}}return k.valid},j=()=>{for(const v of c.unMount){const w=O(o,v);w&&(w._f.refs?w._f.refs.every(k=>!Xs(k)):!Xs(w._f.ref))&&Ze(v)}c.unMount=new Set},B=(v,w)=>(v&&w&&Q(s,v,w),!Yt(Ne(),i)),H=(v,w,k)=>Db(v,c,{...a.mount?s:ie(w)?i:Ye(v)?{[v]:w}:w},k,w),X=v=>ur(O(a.mount?s:i,v,e.shouldUnregister?O(i,v,[]):[])),ne=(v,w,k={})=>{const L=O(o,v);let P=w;if(L){const T=L._f;T&&(!T.disabled&&Q(s,v,Ud(w,T)),P=Mo(T.ref)&&Me(w)?"":w,Bd(T.ref)?[...T.ref.options].forEach(D=>D.selected=P.includes(D.value)):T.refs?lr(T.ref)?T.refs.length>1?T.refs.forEach(D=>(!D.defaultChecked||!D.disabled)&&(D.checked=Array.isArray(P)?!!P.find(ee=>ee===D.value):P===D.value)):T.refs[0]&&(T.refs[0].checked=!!P):T.refs.forEach(D=>D.checked=D.value===P):js(T.ref)?T.ref.value="":(T.ref.value=P,T.ref.type||f.values.next({name:v,values:{...s}})))}(k.shouldDirty||k.shouldTouch)&&R(v,P,k.shouldTouch,k.shouldDirty,!0),k.shouldValidate&&Y(v)},se=(v,w,k)=>{for(const L in w){const P=w[L],T=`${v}.${L}`,D=O(o,T);(c.array.has(v)||!Ao(P)||D&&!D._f)&&!Sn(P)?se(T,P,k):ne(T,P,k)}},Le=(v,w,k={})=>{const L=O(o,v),P=c.array.has(v),T=at(w);Q(s,v,T),P?(f.array.next({name:v,values:{...s}}),(l.isDirty||l.dirtyFields)&&k.shouldDirty&&f.state.next({name:v,dirtyFields:qs(i,s),isDirty:B(v,T)})):L&&!L._f&&!Me(T)?se(v,T,k):ne(v,T,k),Od(v,c)&&f.state.next({...r}),f.values.next({name:v,values:{...s}}),!a.mount&&t()},Re=async v=>{const w=v.target;let k=w.name,L=!0;const P=O(o,k),T=()=>w.type?Ws(P._f):Eb(v),D=ee=>{L=Number.isNaN(ee)||ee===O(s,k,ee)};if(P){let ee,le;const Lo=T(),Tn=v.type===Ad.BLUR||v.type===Ad.FOCUS_OUT,_y=!Ub(P._f)&&!n.resolver&&!O(r.errors,k)&&!P._f.deps||Xb(Tn,O(r.touchedFields,k),r.isSubmitted,m,p),Ks=Od(k,c,Tn);Q(s,k,Lo),Tn?(P._f.onBlur&&P._f.onBlur(v),u&&u(0)):P._f.onChange&&P._f.onChange(v);const Ys=R(k,Lo,Tn,!1),xy=!Oe(Ys)||Ks;if(!Tn&&f.values.next({name:k,type:v.type,values:{...s}}),_y)return l.isValid&&g(),xy&&f.state.next({name:k,...Ks?{}:Ys});if(!Tn&&Ks&&f.state.next({...r}),_(!0),n.resolver){const{errors:ef}=await E([k]);if(D(Lo),L){const ky=Xd(r.errors,o,k),tf=Xd(ef,o,ky.name||k);ee=tf.error,k=tf.name,le=Oe(ef)}}else ee=(await zd(P,s,y,n.shouldUseNativeValidation))[k],D(Lo),L&&(ee?le=!1:l.isValid&&(le=await K(o,!0)));L&&(P._f.deps&&Y(P._f.deps),C(k,le,ee,Ys))}},lt=(v,w)=>{if(O(r.errors,w)&&v.focus)return v.focus(),1},Y=async(v,w={})=>{let k,L;const P=zs(v);if(_(!0),n.resolver){const T=await q(ie(v)?v:P);k=Oe(T),L=v?!P.some(D=>O(T,D)):k}else v?(L=(await Promise.all(P.map(async T=>{const D=O(o,T);return await K(D&&D._f?{[T]:D}:D)}))).every(Boolean),!(!L&&!r.isValid)&&g()):L=k=await K(o);return f.state.next({...!Ye(v)||l.isValid&&k!==r.isValid?{}:{name:v},...n.resolver||!v?{isValid:k}:{},errors:r.errors,isValidating:!1}),w.shouldFocus&&!L&&So(o,lt,v?P:c.mount),L},Ne=v=>{const w={...i,...a.mount?s:{}};return ie(v)?w:Ye(v)?O(w,v):v.map(k=>O(w,k))},Ct=(v,w)=>({invalid:!!O((w||r).errors,v),isDirty:!!O((w||r).dirtyFields,v),isTouched:!!O((w||r).touchedFields,v),error:O((w||r).errors,v)}),At=v=>{v&&zs(v).forEach(w=>ye(r.errors,w)),f.state.next({errors:v?r.errors:{}})},Gt=(v,w,k)=>{const L=(O(o,v,{_f:{}})._f||{}).ref;Q(r.errors,v,{...w,ref:L}),f.state.next({name:v,errors:r.errors,isValid:!1}),k&&k.shouldFocus&&L&&L.focus&&L.focus()},Ge=(v,w)=>Tt(v)?f.values.subscribe({next:k=>v(H(void 0,w),k)}):H(v,w,!0),Ze=(v,w={})=>{for(const k of v?zs(v):c.mount)c.mount.delete(k),c.array.delete(k),w.keepValue||(ye(o,k),ye(s,k)),!w.keepError&&ye(r.errors,k),!w.keepDirty&&ye(r.dirtyFields,k),!w.keepTouched&&ye(r.touchedFields,k),!n.shouldUnregister&&!w.keepDefaultValue&&ye(i,k);f.values.next({values:{...s}}),f.state.next({...r,...w.keepDirty?{isDirty:B()}:{}}),!w.keepIsValid&&g()},Vo=({disabled:v,name:w,field:k,fields:L,value:P})=>{if(Mt(v)){const T=v?void 0:ie(P)?Ws(k?k._f:O(L,w)._f):P;Q(s,w,T),R(w,T,!1,!1,!0)}},Zt=(v,w={})=>{let k=O(o,v);const L=Mt(w.disabled);return Q(o,v,{...k||{},_f:{...k&&k._f?k._f:{ref:{name:v}},name:v,mount:!0,...w}}),c.mount.add(v),k?Vo({field:k,disabled:w.disabled,name:v}):F(v,!0,w.value),{...L?{disabled:w.disabled}:{},...n.progressive?{required:!!w.required,min:dr(w.min),max:dr(w.max),minLength:dr(w.minLength),maxLength:dr(w.maxLength),pattern:dr(w.pattern)}:{},name:v,onChange:Re,onBlur:Re,ref:P=>{if(P){Zt(v,w),k=O(o,v);const T=ie(P.value)&&P.querySelectorAll&&P.querySelectorAll("input,select,textarea")[0]||P,D=jb(T),ee=k._f.refs||[];if(D?ee.find(le=>le===T):T===k._f.ref)return;Q(o,v,{_f:{...k._f,...D?{refs:[...ee.filter(Xs),T,...Array.isArray(O(i,v))?[{}]:[]],ref:{type:T.type,name:v}}:{ref:T}}}),F(v,!1,void 0,T)}else k=O(o,v,{}),k._f&&(k._f.mount=!1),(n.shouldUnregister||w.shouldUnregister)&&!(Ob(c.array,v)&&a.action)&&c.unMount.add(v)}}},Jt=()=>n.shouldFocusError&&So(o,lt,c.mount),ut=v=>{Mt(v)&&(f.state.next({disabled:v}),So(o,w=>{w.disabled=v},0,!1))},fr=(v,w)=>async k=>{k&&(k.preventDefault&&k.preventDefault(),k.persist&&k.persist());let L=at(s);if(f.state.next({isSubmitting:!0}),n.resolver){const{errors:P,values:T}=await E();r.errors=P,L=T}else await K(o);ye(r.errors,"root"),Oe(r.errors)?(f.state.next({errors:{}}),await v(L,k)):(w&&await w({...r.errors},k),Jt(),setTimeout(Jt)),f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Oe(r.errors),submitCount:r.submitCount+1,errors:r.errors})},Oo=(v,w={})=>{O(o,v)&&(ie(w.defaultValue)?Le(v,O(i,v)):(Le(v,w.defaultValue),Q(i,v,w.defaultValue)),w.keepTouched||ye(r.touchedFields,v),w.keepDirty||(ye(r.dirtyFields,v),r.isDirty=w.defaultValue?B(v,O(i,v)):B()),w.keepError||(ye(r.errors,v),l.isValid&&g()),f.state.next({...r}))},Jd=(v,w={})=>{const k=v?at(v):i,L=at(k),P=v&&!Oe(v)?L:i;if(w.keepDefaultValues||(i=k),!w.keepValues){if(w.keepDirtyValues||h)for(const T of c.mount)O(r.dirtyFields,T)?Q(P,T,O(s,T)):Le(T,O(P,T));else{if(Is&&ie(v))for(const T of c.mount){const D=O(o,T);if(D&&D._f){const ee=Array.isArray(D._f.refs)?D._f.refs[0]:D._f.ref;if(Mo(ee)){const le=ee.closest("form");if(le){le.reset();break}}}}o={}}s=e.shouldUnregister?w.keepDefaultValues?at(i):{}:at(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&&!Yt(v,i)),isSubmitted:w.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:w.keepDirtyValues?r.dirtyFields:w.keepDefaultValues&&v?qs(i,v):{},touchedFields:w.keepTouched?r.touchedFields:{},errors:w.keepErrors?r.errors:{},isSubmitSuccessful:w.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1})},Qd=(v,w)=>Jd(Tt(v)?v(s):v,w);return{control:{register:Zt,unregister:Ze,getFieldState:Ct,handleSubmit:fr,setError:Gt,_executeSchema:E,_getWatch:H,_getDirty:B,_updateValid:g,_removeUnmounted:j,_updateFieldArray:M,_updateDisabledField:Vo,_getFieldArray:X,_reset:Jd,_resetDefaultValues:()=>Tt(n.defaultValues)&&n.defaultValues().then(v=>{Qd(v,n.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:v=>{r={...r,...v}},_disableForm:ut,_subjects:f,_proxyFormState:l,get _fields(){return o},get _formValues(){return s},get _state(){return a},set _state(v){a=v},get _defaultValues(){return i},get _names(){return c},set _names(v){c=v},get _formState(){return r},set _formState(v){r=v},get _options(){return n},set _options(v){n={...n,...v}}},trigger:Y,register:Zt,handleSubmit:fr,watch:Ge,setValue:Le,getValues:Ne,reset:Qd,resetField:Oo,clearErrors:At,unregister:Ze,setError:Gt,setFocus:(v,w={})=>{const k=O(o,v),L=k&&k._f;if(L){const P=L.refs?L.refs[0]:L.ref;P.focus&&(P.focus(),w.shouldSelect&&P.select())}},getFieldState:Ct}}function qd(e={}){const t=Ie.useRef(),n=Ie.useRef(),[r,o]=Ie.useState({isDirty:!1,isValidating:!1,isLoading:Tt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:Tt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Kb(e,()=>o(s=>({...s}))),formState:r});const i=t.current.control;return i._options=e,Fb({subject:i._subjects.state,next:s=>{Nb(s,i._proxyFormState,i._updateFormState,!0)&&o({...i._formState})}}),Ie.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),Ie.useEffect(()=>{if(i._proxyFormState.isDirty){const s=i._getDirty();s!==r.isDirty&&i._subjects.state.next({isDirty:s})}},[i,r.isDirty]),Ie.useEffect(()=>{e.values&&!Yt(e.values,n.current)?(i._reset(e.values,i._options.resetOptions),n.current=e.values):i._resetDefaultValues()},[e.values,i]),Ie.useEffect(()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),t.current.formState=Rb(r,i),t.current}var Wd=function(e,t,n){if(e&&"reportValidity"in e){var r=O(n,t);e.setCustomValidity(r&&r.message||""),e.reportValidity()}},Yb=function(e,t){var n=function(o){var i=t.fields[o];i&&i.ref&&"reportValidity"in i.ref?Wd(i.ref,o,e):i.refs&&i.refs.forEach(function(s){return Wd(s,o,e)})};for(var r in t.fields)n(r)},Gb=function(e,t){t.shouldUseNativeValidation&&Yb(e,t);var n={};for(var r in e){var o=O(t.fields,r),i=Object.assign(e[r]||{},{ref:o&&o.ref});if(Jb(t.names||Object.keys(e),r)){var s=Object.assign({},Zb(O(n,r)));Q(s,"root",i),Q(n,r,s)}else Q(n,r,i)}return n},Zb=function(e){return Array.isArray(e)?e.filter(Boolean):[]},Jb=function(e,t){return e.some(function(n){return n.startsWith(t+".")})},Qb=function(e,t){for(var n={};e.issues.length;){var r=e.issues[0];if(r.path){var o=r.path.map(function(a){return a.key}).join(".");if(n[o]||(n[o]={message:r.message,type:r.validation}),t){var i=n[o].types,s=i&&i[r.validation];n[o]=Ed(o,t,n,r.validation,s?[].concat(s,r.message):r.message)}e.issues.shift()}}return n},Kd=function(e,t,n){return n===void 0&&(n={}),function(r,o,i){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(rs(e,r,d)):Promise.resolve(rg(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 so)return{values:{},errors:Gb(Qb(s,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw s}))}catch(s){return Promise.reject(s)}}};const ey=e=>{const t=Object.fromEntries(new FormData(e).entries());Object.keys(t).length&&e.dispatchEvent(new Event("submit",{bubbles:!0}))},ty=ts("multiple-choice"),ny=e=>{const t={min:e.minSelected??0,max:e.maxSelected??e.options.length};return Kd(gn({checked:ku(ng(Gv()),n=>Object.entries(n).filter(([r,o])=>o).map(([r,o])=>r),[sg(t.max,`Please select at most ${t.max} option${t.max!==1?"s":""}`),$u(t.min,`Please select at least ${t.min} option${t.min!==1?"s":""}`)])}))},ry=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var u,d;const r=e.key?(u=re.current$.value.application)==null?void 0:u.data.submissions[e.key]:void 0,{register:o,handleSubmit:i,formState:{errors:s}}=qd({defaultValues:{checked:ty(r)?Object.fromEntries(r.value.map(l=>[l,!0])):{}},resolver:ny(e.config)}),a=Fs(),c=e.config.minSelected===1&&e.config.maxSelected===1;return b("form",{noValidate:!0,class:"flex flex-col gap-1",onChange:l=>{c&&ey(l.currentTarget)},onSubmit:i(l=>{const f=l.checked;t(f)}),children:[b("div",{class:"flex items-center gap-2",children:[b("div",{class:Xt("flex w-full flex-1 flex-wrap gap-3 p-1",{"justify-center":e.config.options.length===1}),children:e.config.options.map((l,f)=>{const h=`checked.${l.value}`,{ref:p,...m}=o(h);return b("div",{children:[b("input",{autoFocus:f===0,ref:y=>{y&&f===0&&(a.current=y),p(y)},id:h,...m,class:"peer sr-only",type:"checkbox"}),b("label",{class:"bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-neutral-12/5 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 duration-300 selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",htmlFor:h,children:l.label})]},l.value)})}),!c&&b(ko,{})]}),b(Ds,{onAnimationComplete:n,error:(d=s.checked)==null?void 0:d.root})]})},Eo={email:"That doesn’t look like a valid email address",phone:"That doesn’t look like a valid phone number"},oy=We(Eo.phone,[ag(/^\+?[0-9 -]+$/,Eo.phone)]),iy={email:We(Eo.email,[ig(Eo.email)]),phone:ku(oy,e=>e.replace(/[^0-9]/g,"")),text:We([$u(1,"Please enter some text")]),url:We([cg("That doesn’t look like a valid URL")])},sy={email:{type:"email",inputMode:"email",formNoValidate:!0},phone:{type:"tel",inputMode:"tel"},text:{type:"text",inputMode:"text"},url:{type:"url",inputMode:"url",formNoValidate:!0}},ay=ts("text"),cy=e=>Kd(gn({text:iy[e.format]})),ly=({input:e,onSubmitSuccess:t,onHeightChange:n})=>{var d;const r=e.key?(d=re.current$.value.application)==null?void 0:d.data.submissions[e.key]:void 0,{register:o,handleSubmit:i,formState:{errors:s}}=qd({defaultValues:{text:ay(r)?r.value:""},resolver:cy(e.config)}),{ref:a,...c}=o("text",{required:!0}),u=U();return Be(()=>{u.current&&(u.current.focus(),u.current.select())},[]),b("form",{noValidate:!0,class:"flex flex-col gap-1",onSubmit:i(l=>{t(l.text)}),children:[b("div",{class:"flex items-center gap-2",children:[b("input",{id:"chat-input",...c,...sy[e.config.format],autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:l=>{l&&(u.current=l),a(l)},class:"outline-neutral-12/5 ease-expo-out placeholder:text-neutral-5 focus-visible:outline-accent-7 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2 transition-all duration-300",placeholder:e.config.placeholder}),b(ko,{})]}),b(Ds,{onAnimationComplete:n,error:s.text})]})},uy=({onSubmit:e,onInputChange:t,input:n})=>{const r=U(null),o=me(()=>{r.current&&(ns.value=r.current.getBoundingClientRect().height)},[]);G(()=>{o(),t(n==null?void 0:n.type)},[n==null?void 0:n.type,t,o]);const i=s=>a=>e({type:s,value:a});return b(Kn.div,{initial:{height:0},animate:{height:ns.value},exit:{height:0,opacity:0},class:"bg-neutral-2/80 absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",children:b("div",{ref:r,class:"border-neutral-12/5 border-t p-2.5",children:tt({application:re,input:n,onHeightChange:o}).with({input:Ae.nullish},()=>b("div",{class:"flex items-center gap-2",children:[b("input",{"aria-hidden":"true",id:"chat-input",class:"outline-neutral-12/5 placeholder:text-neutral-4 focus-visible:outline-accent-9 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2",disabled:!0}),b(ko,{disabled:!0,"aria-hidden":"true",tabIndex:-1})]})).with({input:{type:"text"}},s=>b(ly,{onSubmitSuccess:i(s.input.type),...s})).with({input:{type:"multiple-choice"}},s=>b(ry,{onSubmitSuccess:i(s.input.type),...s})).with({input:{type:"boolean"}},s=>b(Sb,{onSubmitSuccess:i(s.input.type),...s})).with({input:{type:"file"}},s=>b(Pb,{onSubmitSuccess:i(s.input.type),...s})).exhaustive()})})},Yd=e=>typeof e=="boolean"?"".concat(e):e===0?"0":e,Gd=Xt,Zd=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return Gd(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:o,defaultVariants:i}=t,s=Object.keys(o).map(u=>{const d=n==null?void 0:n[u],l=i==null?void 0:i[u];if(d===null)return null;const f=Yd(d)||Yd(l);return o[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,...h}=d;return Object.entries(h).every(p=>{let[m,y]=p;return Array.isArray(y)?y.includes({...i,...a}[m]):{...i,...a}[m]===y})?[...u,l,f]:u},[]);return Gd(e,s,c,n==null?void 0:n.class,n==null?void 0:n.className)},dy=Zd("max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink-1 min-w-[2rem] text-md py-2 px-3 rounded-[18px] min-h-[36px] break-words",{variants:{side:{left:"bg-lowest text-neutral-12 shadow-surface-sm outline outline-1 outline-neutral-11/[.08] rounded-bl-md",right:"ml-auto bg-accent-7 text-lowest rounded-br-md bubble-right"},transitionState:{entering:"opacity-0 translate-y-8",entered:"opacity-100 translate-y-0",exiting:"opacity-0 scale-0",exited:""}},defaultVariants:{side:"left"}}),fy={hidden:{y:"100%",scale:.75},shown:{y:0,scale:1}},hy=({children:e,className:t,transitionState:n,side:r,...o})=>b(Kn.p,{variants:fy,initial:"hidden",animate:"shown",transition:{type:"spring",damping:25,stiffness:500},"data-transition":n,style:{transformOrigin:r==="left"?"0% 50%":"100% 50%"},class:dy({className:t,side:r,transitionState:n}),...o,children:e}),py=({className:e,...t})=>b("div",{class:Xt("flex gap-1 p-4",e),...t,children:Array.from({length:3},(n,r)=>b("div",{class:"bg-accent-7 h-1.5 w-1.5 animate-bounce rounded-full",style:{animationDelay:`${-r*200}ms`}}))}),my={bot:"left",user:"right"},vy=Zd("w-full select-none py-2 text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_white]",{variants:{variant:{info:"text-neutral-8",warning:"text-[#FFC107]",error:"text-error-9",success:"text-[#4CAF50]"}}}),gy=({messages:e,isBotTyping:t})=>b("ol",{"aria-label":"Chat messages",class:"flex flex-grow flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",children:[b(to,{initial:!1,children:e.map((n,r)=>b("li",{class:"flex",children:tt(n).with({type:"system"},o=>b("p",{class:vy({variant:o.variant}),children:o.text})).with({type:"text",author:Ae.union("bot","user")},o=>b(hy,{side:my[o.author],children:o.text},r)).with({type:"link"},o=>b("div",{class:"bg-accent-8/5 flex w-full items-center justify-center overflow-hidden rounded-xl py-2",children:b("a",{class:"bg-lowest shadow-surface-sm ring-accent-8/20 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 flex items-center gap-1.5 truncate rounded-full py-2 pl-4 pr-2.5 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,b("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b("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=>b("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=>b(Ab,{class:o.author==="bot"?"":"ml-auto",file:{name:o.fileName,sizeKb:o.fileSizeKb}})).exhaustive()},r))}),b("aside",{"aria-hidden":!0,children:t&&b(py,{})})]}),by=25,yy=()=>{const e=U(null),[t,n]=ae(!1),[r,o]=ae(()=>()=>{}),i=de(()=>a=>{var c;return(c=e.current)==null?void 0:c.scrollTo({top:e.current.scrollHeight,...a})},[e]),s=de(()=>({send:async({message:a,signal:c,groupId:u})=>{if(await tt(a).with({author:"bot",type:"text"},async d=>{if(c!=null&&c.aborted)throw new Jn;n(!0);const l=Math.max(20,d.text.length)*by;await new Promise(f=>setTimeout(f,l,{signal:c})),n(!1)}).otherwise(async()=>{}),c!=null&&c.aborted)throw new Jn;re.addMessage(a,u)},input:async({input:a,signal:c})=>{if(c!=null&&c.aborted)throw new Jn;return re.setInput(a),await new Promise(u=>{const d=l=>{if(c!=null&&c.aborted)throw new Jn;re.setInput(void 0),a.key&&re.setSubmission(a.key,l),u(l)};o(()=>d)})}}),[]);return{chatRef:e,chatService:s,isBotTyping:t,onSubmitSuccessFn:r,scrollToEnd:i}},wy=Object.freeze(Object.defineProperty({__proto__:null,JobApplicationContent:({currentApplication:e,logger:t,apiClient:n,analytics:r})=>{const{chatRef:o,chatService:i,isBotTyping:s,onSubmitSuccessFn:a,scrollToEnd:c}=yy(),u=nt.value,d=e.flow,l=e.job;return Be(()=>{u==="maximised"&&c({behavior:"instant"})},[c,u]),G(()=>{c({behavior:"smooth"})},[e.data.messages,c]),Be(()=>{const{state:f,application:h}=re.current$.peek();if(f!=="loaded")throw new Error(Ev.invalid_state);const p=h.data.currentNodeId;if(c({behavior:"instant"}),re.setInput(void 0),h.data.isFinished)return;h.data.messages.length===0&&r.log({event:"APPLY_START",properties:{job_id:l.id},customProperties:{flow_id:d.id}}),re.removeLastGroupMessagesById(p);const{interpret:y,abort:x}=cb({context:{jobId:l.id,flowId:d.id},analytics:r,apiClient:n,logger:t,flow:d.nodes,chatService:i,getSubmissions:()=>{var g;return(g=re.current$.peek().application)==null?void 0:g.data.submissions},onInterpret:(g,_)=>{r.log({event:"FLOW_NODE",properties:{flow_id:d.id,flow_version:d.version,job_id:l.id,from_node_id:_?_.id:null,to_node_id:g.id,sequence:1}}),re.setCurrentNodeId(g.id)},onFlowEnd:async()=>{re.markAsFinished()}});return y(p),x},[r,n,i,t,c,d,l.id,e.startedAt]),b(ue,{children:[b("div",{ref:o,className:"hide-scrollbars relative flex max-w-full flex-grow flex-col overflow-y-scroll",style:{WebkitOverflowScrolling:"touch",paddingBottom:ns.value},children:b(to,{children:b(gy,{isBotTyping:s,messages:e.data.messages})})}),b(uy,{input:e.data.currentInput,onInputChange:()=>c({behavior:"smooth"}),onSubmit:a})]})}},Symbol.toStringTag,{value:"Module"}))})();
@@ -0,0 +1,30 @@
1
+ import { FlowNode } from '@inploi/core/flows';
2
+ import { ApiClient, Logger } from '@inploi/sdk';
3
+ type Result<T> = {
4
+ ok: true;
5
+ value: T;
6
+ } | {
7
+ ok: false;
8
+ error: string;
9
+ };
10
+ export type JobApplication = {
11
+ job: {
12
+ id: string;
13
+ title: string;
14
+ };
15
+ company: {
16
+ name: string;
17
+ logo?: string;
18
+ };
19
+ flow: {
20
+ id: string;
21
+ version: number;
22
+ nodes: FlowNode[];
23
+ };
24
+ };
25
+ export declare function getApplicationData({ jobId, apiClient, logger, }: {
26
+ jobId: string;
27
+ apiClient: ApiClient;
28
+ logger: Logger;
29
+ }): Promise<Result<JobApplication>>;
30
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const CHATBOT_ELEMENT_ID = "isdk";
2
+ export declare const HEADER_HEIGHT = 44;
3
+ export declare const ERROR_MESSAGES: {
4
+ not_in_local_storage: string;
5
+ invalid_end_node: string;
6
+ no_submissions: string;
7
+ invalid_state: string;
8
+ };
package/dist/chatbot.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare const chatbotPlugin: ({ _internal_domManager: dom, theme, }: {
7
7
  /** Chroma multiplier. Values between 0 and 1.5 work best. */
8
8
  chroma?: number;
9
9
  };
10
+ /** @deprecated For internal usage only */
10
11
  _internal_domManager?: {
11
12
  getOrCreateChatbotElement: () => HTMLDivElement;
12
13
  addStyle: (css: string, id: string) => void;
@@ -0,0 +1,9 @@
1
+ import { JobApplication } from './chatbot.api';
2
+ import { ApplicationData } from './chatbot.state';
3
+ export declare const idb: {
4
+ getApplicationData: (application: JobApplication) => Promise<ApplicationData | undefined>;
5
+ setApplicationData: (params: {
6
+ application: JobApplication;
7
+ data: ApplicationData;
8
+ }) => Promise<void>;
9
+ };
@@ -0,0 +1,90 @@
1
+ import { Signal } from '@preact/signals';
2
+ import { JobApplication } from './chatbot.api';
3
+ import { DistributivePick } from './chatbot.utils';
4
+ import { ChatInput } from './ui/chat-input/chat-input';
5
+ import { ChatbotInput } from './ui/chat-input/chat-input';
6
+ export declare const getCacheKey: (application: JobApplication) => string;
7
+ export type ViewState = 'maximised' | 'minimised';
8
+ export declare const viewState: Signal<ViewState>;
9
+ export declare const inputHeight: Signal<number>;
10
+ export type StartedJobApplication = JobApplication & {
11
+ data: ApplicationData;
12
+ startedAt: Date;
13
+ };
14
+ type CurrentApplication = {
15
+ state: 'idle';
16
+ application?: never;
17
+ error?: never;
18
+ } | {
19
+ state: 'loading';
20
+ application?: never;
21
+ error?: never;
22
+ } | {
23
+ state: 'loaded';
24
+ application: StartedJobApplication;
25
+ error?: never;
26
+ } | {
27
+ state: 'error';
28
+ application?: never;
29
+ error: string;
30
+ };
31
+ export declare const application: {
32
+ current$: Signal<CurrentApplication>;
33
+ start: (application: JobApplication) => Promise<void>;
34
+ cancel: () => void;
35
+ markAsFinished: () => Promise<void>;
36
+ setCurrentNodeId: (currentNodeId: string) => Promise<void>;
37
+ restart: () => void;
38
+ addMessage: (message: ChatMessage, groupId?: string) => Promise<void>;
39
+ /** Removes from the last message backwards, all the messages that have the groupId passed, until it reaches one that doesn't */
40
+ removeLastGroupMessagesById: (groupId: string) => void;
41
+ setSubmission: (fieldKey: string, submission: ApplicationSubmission) => Promise<void>;
42
+ setInput: (input: ChatInput | undefined) => Promise<void>;
43
+ };
44
+ export type MessageAuthor = 'bot' | 'user';
45
+ type SystemMessage = {
46
+ type: 'system';
47
+ text: string;
48
+ variant: 'info' | 'warning' | 'error' | 'success';
49
+ };
50
+ type TextMessage = {
51
+ author: MessageAuthor;
52
+ type: 'text';
53
+ text: string;
54
+ };
55
+ type LinkMessage = {
56
+ type: 'link';
57
+ href: string;
58
+ text: string;
59
+ };
60
+ type ImageMessage = {
61
+ author: MessageAuthor;
62
+ type: 'image';
63
+ url: string;
64
+ width: number;
65
+ height: number;
66
+ };
67
+ type FileMessage = {
68
+ author: MessageAuthor;
69
+ type: 'file';
70
+ fileName: string;
71
+ fileSizeKb: number;
72
+ };
73
+ export type ChatMessage = TextMessage | ImageMessage | SystemMessage | FileMessage | LinkMessage;
74
+ export type ApplicationSubmission = DistributivePick<ChatbotInput, 'type' | 'value'>;
75
+ export type KeyToSubmissionMap = {
76
+ [key: string]: ApplicationSubmission;
77
+ };
78
+ /** Dynamic part of an application */
79
+ export type ApplicationData = {
80
+ /** History of messages left in the chat */
81
+ messages: (ChatMessage & {
82
+ groupId?: string;
83
+ })[];
84
+ submissions: KeyToSubmissionMap;
85
+ currentNodeId: string;
86
+ /** Needs to be separate because a node can have many inputs */
87
+ currentInput?: ChatInput;
88
+ isFinished: boolean;
89
+ };
90
+ export {};
@@ -0,0 +1,160 @@
1
+ import { FlowNode } from '@inploi/core/flows';
2
+ import { ApplicationSubmission, KeyToSubmissionMap } from './chatbot.state';
3
+ export type DistributivePick<T, K extends keyof T> = T extends unknown ? Pick<T, K> : never;
4
+ export declare const getHeadOrThrow: (nodes: FlowNode[]) => {
5
+ id: string;
6
+ data: {
7
+ text: string;
8
+ };
9
+ type: "text";
10
+ isHead?: boolean | undefined;
11
+ nextId?: string | undefined;
12
+ } | {
13
+ id: string;
14
+ data: {
15
+ systemMessage?: string | undefined;
16
+ };
17
+ type: "end-flow";
18
+ isHead?: boolean | undefined;
19
+ nextId?: string | undefined;
20
+ } | {
21
+ id: string;
22
+ data: {
23
+ type: "ats";
24
+ };
25
+ type: "submit";
26
+ isHead?: boolean | undefined;
27
+ nextId?: string | undefined;
28
+ } | {
29
+ id: string;
30
+ data: {
31
+ href: string;
32
+ cta: string;
33
+ };
34
+ type: "link";
35
+ isHead?: boolean | undefined;
36
+ nextId?: string | undefined;
37
+ } | {
38
+ id: string;
39
+ data: {
40
+ url: string;
41
+ width: number;
42
+ height: number;
43
+ };
44
+ type: "image";
45
+ isHead?: boolean | undefined;
46
+ nextId?: string | undefined;
47
+ } | {
48
+ id: string;
49
+ data: {
50
+ key: string;
51
+ question: string;
52
+ trueLabel: string;
53
+ falseLabel: string;
54
+ };
55
+ type: "question-boolean";
56
+ isHead?: boolean | undefined;
57
+ nextId?: string | undefined;
58
+ } | {
59
+ id: string;
60
+ data: {
61
+ key: string;
62
+ question: string;
63
+ format: "text" | "url" | "email" | "phone";
64
+ placeholder?: string | undefined;
65
+ };
66
+ type: "question-text";
67
+ isHead?: boolean | undefined;
68
+ nextId?: string | undefined;
69
+ } | {
70
+ id: string;
71
+ data: {
72
+ key: string;
73
+ question: string;
74
+ placeholder?: string | undefined;
75
+ decimalCases?: number | undefined;
76
+ min?: number | undefined;
77
+ max?: number | undefined;
78
+ };
79
+ type: "question-number";
80
+ isHead?: boolean | undefined;
81
+ nextId?: string | undefined;
82
+ } | {
83
+ id: string;
84
+ data: {
85
+ options: {
86
+ value: string;
87
+ label: string;
88
+ }[];
89
+ key: string;
90
+ question: string;
91
+ maxSelected: number;
92
+ minSelected: number;
93
+ };
94
+ type: "question-enum";
95
+ isHead?: boolean | undefined;
96
+ nextId?: string | undefined;
97
+ } | {
98
+ id: string;
99
+ data: {
100
+ key: string;
101
+ question: string;
102
+ extensions: string[];
103
+ multiple?: boolean | undefined;
104
+ maxSizeKb?: number | undefined;
105
+ };
106
+ type: "question-file";
107
+ isHead?: boolean | undefined;
108
+ nextId?: string | undefined;
109
+ } | {
110
+ id: string;
111
+ data: {
112
+ keys: {
113
+ line1: string;
114
+ line2: string;
115
+ line3: string;
116
+ city: string;
117
+ state: string;
118
+ postcode: string;
119
+ country: string;
120
+ };
121
+ question: string;
122
+ placeholder?: string | undefined;
123
+ };
124
+ type: "question-address";
125
+ isHead?: boolean | undefined;
126
+ nextId?: string | undefined;
127
+ } | {
128
+ id: string;
129
+ data: {
130
+ compareKey: string;
131
+ compareValue: string;
132
+ compare: "equals" | "notEquals" | "contains" | "notContains";
133
+ };
134
+ type: "if-block";
135
+ isHead?: boolean | undefined;
136
+ nextId?: string | undefined;
137
+ branchId?: string | undefined;
138
+ } | {
139
+ id: string;
140
+ data: {
141
+ targetId: string;
142
+ };
143
+ type: "jump";
144
+ isHead?: boolean | undefined;
145
+ nextId?: string | undefined;
146
+ };
147
+ export declare const getApplicationSubmissionsPayload: (submissions: KeyToSubmissionMap) => Record<string, string | string[] | import("./ui/chat-input/chat-input.file").FileToUpload[]>;
148
+ export declare const isSubmissionOfType: <T extends "boolean" | "text" | "multiple-choice" | "file">(type: T) => (submission?: ApplicationSubmission) => submission is Extract<Pick<import("./ui/chat-input/chat-input.text").TextPayload, "value" | "type">, {
149
+ type: T;
150
+ }> | Extract<Pick<import("./ui/chat-input/chat-input.multiple-choice").MultipleChoicePayload, "value" | "type">, {
151
+ type: T;
152
+ }> | Extract<Pick<import("./ui/chat-input/chat-input.boolean").BooleanChoicePayload, "value" | "type">, {
153
+ type: T;
154
+ }> | Extract<Pick<import("./ui/chat-input/chat-input.file").FilePayload, "value" | "type">, {
155
+ type: T;
156
+ }>;
157
+ export declare function gzip(string: string): string | Promise<string>;
158
+ export declare class AbortedError extends Error {
159
+ constructor();
160
+ }