@inploi/plugin-chatbot 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-9944cf27.cjs");require("@inploi/sdk");const it=({condition:e,context:r,submissions:n,ifBlock:s})=>{const[a,...o]=e.compareKey.split(".");if(!a)return!1;const i=Ft({context:r,key:a,path:o,submissions:n});if(!i)return!1;switch(i.type){case"address":{const u=t.get(i.value,o.join("."));switch(e.compare){case"equals":return u===e.compareValue;case"contains":return u?u.includes(e.compareValue):!1;case"notEquals":return u!==e.compareValue;case"notContains":return u?!u.includes(e.compareValue):!0}break}case"integration":{if(typeof i.value!="object"||Array.isArray(i.value))return!1;const u=t.get(i.value,o.join(".")),d={...s,data:{...s.data,compareKey:"_temp"}};switch(typeof u){case"boolean":return ye(d,{submissions:{_temp:{value:u,type:"boolean"}},context:r});case"string":return ye(d,{submissions:{_temp:{value:u,type:"string"}},context:r});case"number":return ye(d,{submissions:{_temp:{value:u,type:"number"}},context:r});case"object":return Array.isArray(u)&&u.every(t.isString)?ye(d,{submissions:{_temp:{value:u,type:"enum"}},context:r}):!1}break}case"boolean":{const u=e.compareValue==="true";switch(e.compare){case"equals":return i.value===u;case"notEquals":return i.value!==u}break}case"phone":case"string":{const u=i.type==="phone"?Fe(i.value):i.value;switch(e.compare){case"equals":return u===e.compareValue;case"contains":return u?u.includes(e.compareValue):!1;case"notEquals":return u!==e.compareValue;case"notContains":return u?!u.includes(e.compareValue):!0}break}case"number":{try{const u=Number(e.compareValue);switch(e.compare){case"equals":return i.value===u;case"notEquals":return i.value!==u;case"greaterThan":return i.value>u;case"greaterThanOrEqualTo":return i.value>=u;case"lessThan":return i.value<u;case"lessThanOrEqualTo":return i.value<=u}}catch{return console.error(`Failed to parse number in if-block ${s.id}`,i.value),!1}break}case"enum":switch(e.compare){case"equals":return i.value.length===1&&i.value[0]===e.compareValue;case"notEquals":return i.value.length===1&&i.value[0]!==e.compareValue;case"contains":return i.value.includes(e.compareValue);case"notContains":return!i.value.includes(e.compareValue)}break}},ye=(e,{context:r,submissions:n})=>{const s="combinator"in e.data?e.data.conditions:[e.data];if(("combinator"in e.data?e.data.combinator:"and")==="or"){for(const o of s)if(it({condition:o,context:r,submissions:n,ifBlock:e}))return!0;return!1}else{for(const o of s)if(!it({condition:o,context:r,submissions:n,ifBlock:e}))return!1;return!0}},Qt=/{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g,Z=(e,{context:r,submissions:n})=>e.replace(Qt,(s,a,o="")=>{const[i,...u]=a.trim().split("."),d=Ft({key:i,path:u,submissions:n,context:r});if(!d)return o;switch(d.type){case"boolean":return d.value===!0?"true":"false";case"file":return d.value.map(h=>`${h.name} (${t.kbToReadableSize(h.sizeKb)})`).join(", ");case"enum":return d.value.join(", ");case"address":return Object.values(d.value).filter(h=>h&&h.trim().length>0).join(", ");case"number":case"string":return d.value?d.value.toString():o;case"phone":return Fe(d.value);case"integration":{if(typeof d.value!="object"||Array.isArray(d.value))break;const h=t.get(d.value,u.join("."));switch(typeof h){case"boolean":return h===!0?"true":"false";case"string":return h;case"number":return h.toString();case"object":if(Array.isArray(h)&&h.every(t.isString))return h.join(", ")}break}}return o}),Vt=({node:e,nodes:r,stopWhen:n})=>{if((n==null?void 0:n(e))===!0)return e;const s=e.nextId?r.find(a=>a.id===e.nextId):void 0;if(s)return Vt({node:s,nodes:r,stopWhen:n})},er=({childNode:e,nodes:r})=>{const s=r.filter(a=>a.type==="if-block").find(a=>{if(!a.branchId)return!1;const o=r.find(u=>u.id===a.branchId);if(!o)return!1;const i=Vt({node:o,nodes:r,stopWhen:u=>u.id===e.id});return!(!i||i.id!==e.id)});if(s!=null&&s.nextId)return r.find(a=>a.id===s.nextId)},tr=({flow:e,analytics:r,logger:n,context:s,apiClient:a,getSubmissions:o,chatService:i,onFlowEnd:u,onInterpret:d,t:h})=>{let x=new AbortController;const v={...r.service,log:k=>r.service.log({...k,customProperties:{...k.customProperties,...r.customProperties}})},p=async(k,y)=>{const A=o();d==null||d(k,y);try{await rr({flow:e,analytics:v,logger:n,apiClient:a,context:s,node:k,submissions:A,t:h,chat:{sendMessage:async S=>i.send({groupId:k.id,message:S,signal:x.signal}),userInput:async S=>i.input({input:S,signal:x.signal}),addToSubmissions:i.addToSubmissions},next:S=>{const E=S?e.nodes.find(g=>g.id===S):er({childNode:k,nodes:e.nodes});return E?p(E,k):u==null?void 0:u(k)},end:()=>u==null?void 0:u(k)})}catch(S){if(S instanceof t.AbortedError)return;throw S}};return{interpret:async k=>{const y=e.nodes.find(A=>A.id===k)??t.getHeadOrThrow(e.nodes);return p(y)},undo:k=>{let y=1;const A=e.nodes.find(E=>E.id===k[k.length-1]);for(let E=k.length-2;E>0;E--){const g=k[E],F=e.nodes.find(O=>O.id===g);if(!F||(y++,F.type.startsWith("question-")))break}x.abort(),x=new AbortController;const S=e.nodes.find(E=>E.id===k[k.length-y]);return t.invariant(S,"Undo failed: new start node not found"),p(S,A),{removed:y}},abort:()=>{x.abort()}}},Fe=e=>`+${e.countryCode} ${e.phoneNumber}`;async function rr(e){const r=e.node;switch(r.type){case"text":return cr({...e,node:r});case"image":return dr({...e,node:r});case"question-text":return fr({...e,node:r});case"question-enum":return mr({...e,node:r});case"question-number":return hr({...e,node:r});case"question-phone":return pr({...e,node:r});case"question-boolean":return gr({...e,node:r});case"question-file":return yr({...e,node:r});case"question-address":return br({...e,node:r});case"end-flow":return vr({...e,node:r});case"if-block":return ur({...e,node:r});case"jump":return ar({...e,node:r});case"link":return lr({...e,node:r});case"integration-application-submit":return ir({...e,node:r});case"add-submission":return or({...e,node:r});case"integration-workflow-get":throw Error("Workflow should be unreachable");case"identify":return sr({...e,node:r});case"feedback":return nr({...e,node:r});default:throw new Error(`Unknown node: ${JSON.stringify(r)}`)}}const me=(e,r)=>{var s;const n=(s=e[r])==null?void 0:s.value;if(typeof n!="string"&&typeof n!="number")throw new Error(`Submission at “${r}” is not a string or number`);return n};async function nr({next:e,node:r}){e(r.nextId)}async function sr({next:e,node:r,analytics:n,submissions:s,logger:a}){if(!s)return e(r.nextId);try{n.log({event:"IDENTIFY",properties:{identifier:me(s,r.data.key).toString(),first_name:r.data.firstName?me(s,r.data.firstName).toString():void 0,last_name:r.data.lastName?me(s,r.data.lastName).toString():void 0,email:r.data.email?me(s,r.data.email).toString():void 0,phone_number:r.data.phoneNumber?me(s,r.data.phoneNumber).toString():void 0,custom_traits:r.data.customTraits?Object.fromEntries(r.data.customTraits.map(({key:o,value:i})=>{var u;return[o,(u=s[i])==null?void 0:u.value]})):void 0}})}catch(o){a.error(o)}finally{e(r.nextId)}}async function ar({next:e,node:r}){e(r.data.targetId)}async function or({next:e,node:r,logger:n,submissions:s,context:a}){if(!s){n.error("Submissions not found");return}s[r.data.key]={type:"string",value:Z(r.data.value,{submissions:s,context:a})},e(r.nextId)}async function ir({chat:e,next:r,node:n,logger:s,apiClient:a,submissions:o,analytics:i,flow:u,t:d}){const h=async x=>{x!==!0&&await e.userInput({type:"submit",key:void 0,config:{label:n.data.submitLabel}}),await e.sendMessage({type:"loading"});const{anonymous_id:v,session_id:p}=i.getSessionInfo(),k=await a.fetch("/flow/submit",{method:"POST",body:JSON.stringify({log_submit:!1,integration_id:n.data.integrationId,anonymous_id:v,session_id:p,job:u.job,submissions:t.getFlowSubmissionsPayload(o||{})})}).catch(y=>y);n.data.key&&e.addToSubmissions(n.data.key,{type:"integration",value:k}),t.N(k).with({integration_response:t._.select(t._.union({service:t._.optional(t._.string),status:t._.number,data:t._.any},{service:t._.optional(t._.string),status:t._.number,error:{message:t._.string,data:t._.any}}))},y=>{i.log({event:"FLOW_SUBMIT",properties:{flow_id:u.id,flow_version:u.version,flow_session_id:u.data.flowSessionId,flow_build:u.build,service:y.service??"INVALID_SERVICE",response:{status:y.status,payload:"data"in y?y.data:y.error.data??null},job:u.job}})}).otherwise(()=>{}),await t.N(k).with({integration_response:{data:t._.select("redirect",{redirect_url:t._.string,message:t._.optional(t._.union(t._.string,t._.nullish)),button_text:t._.optional(t._.union(t._.string,t._.nullish))})}},async y=>{await e.sendMessage({type:"text",author:"bot",text:y.redirect.message??d("submission_redirect_message")});try{const A=new URL(y.redirect.redirect_url);v&&!A.searchParams.has("anonymous_id")&&A.searchParams.set("anonymous_id",v),await e.sendMessage({type:"link",href:A.toString(),text:y.redirect.button_text??d("complete_submission"),onClick:()=>{if(!p){s.error("session_id not set, cannot log FLOW_REDIRECT event");return}i.log({event:"FLOW_REDIRECT",properties:{flow_build:u.build,flow_id:u.id,flow_session_id:p,flow_version:u.version,href:A.toString(),job:u.job}})}})}catch(A){s.error(`Invalid redirect URL: ${y.redirect.redirect_url}`,A),e.sendMessage({type:"system",variant:"error",text:d("redirect_url_error")})}r(n.nextId)}).with({success:!0},async()=>{n.data.skipConfirmation!==!0&&await e.sendMessage({type:"system",variant:"success",text:d("submission_completed")}),r(n.nextId)}).with({integration_response:{error:t._.select("error",{message:t._.string})}},async y=>{s.error(y.error),await e.sendMessage({type:"system",variant:"error",text:y.error.message||d("submission_failed")}),await h(!1)}).otherwise(async y=>{s.error(y),await e.sendMessage({type:"system",variant:"error",text:d("submission_failed")}),await h(!1)})};await h(n.data.skipConfirmation)}async function lr({chat:e,next:r,node:n,submissions:s,context:a}){await e.sendMessage({type:"link",href:Z(n.data.href,{submissions:s,context:a}),text:Z(n.data.cta,{submissions:s,context:a})}),r(n.nextId)}async function ur({submissions:e,next:r,node:n,context:s}){r(ye(n,{submissions:e,context:s})?n.branchId:n.nextId)}async function cr({chat:e,next:r,node:n,submissions:s,context:a}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.text,{submissions:s,context:a})}),r(n.nextId)}async function dr({chat:e,next:r,node:n}){await e.sendMessage({author:"bot",type:"image",url:n.data.url,height:n.data.height,width:n.data.width}),r(n.nextId)}async function fr({chat:e,next:r,node:n,submissions:s,context:a,t:o}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.question,{submissions:s,context:a})});const i=n.data.format==="phone"?await e.userInput({key:n.data.key,type:"phone",config:{optional:n.data.optional,placeholder:n.data.placeholder,minChars:n.data.minChars,submissionFormat:"text",defaultValue:{}}}):await e.userInput({key:n.data.key,type:"text",config:{optional:n.data.optional,placeholder:n.data.placeholder,format:n.data.format,maxChars:n.data.maxChars,minChars:n.data.minChars}});i===null?await e.sendMessage({type:"system",variant:"info",text:o("skipped")}):await e.sendMessage({author:"user",type:"text",text:i.type==="phone"?Fe(i.value):i.value}),r(n.nextId)}async function hr({chat:e,next:r,node:n,submissions:s,context:a,t:o}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.question,{submissions:s,context:a})});const i=await e.userInput({key:n.data.key,type:"number",config:{max:n.data.max,min:n.data.min,optional:n.data.optional,placeholder:n.data.placeholder,decimalCases:n.data.decimalCases}});i===null?await e.sendMessage({type:"system",variant:"info",text:o("skipped")}):await e.sendMessage({author:"user",type:"text",text:i.value.toString()}),r(n.nextId)}async function pr({chat:e,next:r,node:n,submissions:s,context:a}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.question,{submissions:s,context:a})});const o=await e.userInput({key:n.data.key,type:"phone",config:{minChars:n.data.minChars,defaultValue:{countryCode:n.data.defaultCountryCode},placeholder:n.data.placeholder,submissionFormat:"phone",optional:n.data.optional}});o===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:o.type==="phone"?Fe(o.value):o.value}),r(n.nextId)}async function mr({chat:e,next:r,node:n,submissions:s,context:a,t:o}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.question,{submissions:s,context:a})});const i=await e.userInput({key:n.data.key,type:"multiple-choice",config:n.data});i.value.length===0?await e.sendMessage({type:"system",variant:"info",text:o("skipped")}):await e.sendMessage({author:"user",type:"text",text:n.data.options.filter(u=>i.value.includes(u.value)).map(u=>u.label).join(", ")}),r(n.nextId)}async function gr({chat:e,next:r,node:n,submissions:s,context:a,t:o}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.question,{submissions:s,context:a})});const i=await e.userInput({key:n.data.key,type:"boolean",config:{optional:n.data.optional,labels:{true:n.data.trueLabel,false:n.data.falseLabel}}});i===null?await e.sendMessage({type:"system",variant:"info",text:o("skipped")}):await e.sendMessage({author:"user",type:"text",text:i.value===!0?n.data.trueLabel:n.data.falseLabel}),r(n.nextId)}async function br({chat:e,next:r,node:n,t:s}){await e.sendMessage({author:"bot",type:"text",text:n.data.question});const a=await e.userInput({type:"address",key:n.data.key,config:{optional:n.data.optional,keys:n.data.keys,placeholder:n.data.placeholder}});if(a===null)await e.sendMessage({type:"system",variant:"info",text:s("skipped")});else{const o=Object.values(a.value).filter(i=>i&&i.trim().length>0).join(", ");await e.sendMessage({author:"user",type:"text",text:o})}return r(n.nextId)}async function yr({node:e,chat:r,next:n,submissions:s,context:a,t:o}){await r.sendMessage({author:"bot",type:"text",text:Z(e.data.question,{submissions:s,context:a})});const i=await r.userInput({key:e.data.key,type:"file",config:{optional:e.data.optional,extensions:e.data.extensions,fileSizeLimitKib:e.data.maxSizeKb??10*1024,allowMultiple:e.data.multiple===!0}});if(i===null)await r.sendMessage({type:"system",variant:"info",text:o("skipped")});else for(const u of i.value)await r.sendMessage({author:"user",type:"file",fileName:u.name,fileSizeKb:u.sizeKb});n(e.nextId)}async function vr({chat:e,end:r,node:n}){await e.sendMessage({type:"system",variant:"info",text:n.data.systemMessage}),r()}const Ft=({key:e,path:r,submissions:n,context:s})=>{if(e==="$context"){if(!r)return;const a=t.get(s,r.join("."));switch(typeof a){case"string":return{type:"string",value:a};case"number":return{type:"number",value:a};case"boolean":return{type:"boolean",value:a};default:console.warn(`Unexpected type for $context.${r.join(".")}`,a);return}}return n==null?void 0:n[e]};function qe(e,r,n){var s,a,o,i,u;r==null&&(r=100);function d(){var x=Date.now()-i;x<r&&x>=0?s=setTimeout(d,r-x):(s=null,n||(u=e.apply(o,a),o=a=null))}var h=function(){o=this,a=arguments,i=Date.now();var x=n&&!s;return s||(s=setTimeout(d,r)),x&&(u=e.apply(o,a),o=a=null),u};return h.clear=function(){s&&(clearTimeout(s),s=null)},h.flush=function(){s&&(u=e.apply(o,a),o=a=null,clearTimeout(s),s=null)},h}qe.debounce=qe;var xr=qe;const lt=t.getDefaultExportFromCjs(xr);function wr(e){let{debounce:r,scroll:n,polyfill:s,offsetSize:a}=e===void 0?{debounce:0,scroll:!1,offsetSize:!1}:e;const o=s||(typeof window>"u"?class{}:window.ResizeObserver);if(!o)throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");const[i,u]=t.h({left:0,top:0,width:0,height:0,bottom:0,right:0,x:0,y:0}),d=t._$1({element:null,scrollContainers:null,resizeObserver:null,lastBounds:i}),h=r?typeof r=="number"?r:r.scroll:null,x=r?typeof r=="number"?r:r.resize:null,v=t._$1(!1);t.p(()=>(v.current=!0,()=>void(v.current=!1)));const[p,k,y]=t.F(()=>{const g=()=>{if(!d.current.element)return;const{left:F,top:O,width:L,height:se,bottom:te,right:he,x:U,y:X}=d.current.element.getBoundingClientRect(),j={left:F,top:O,width:L,height:se,bottom:te,right:he,x:U,y:X};d.current.element instanceof HTMLElement&&a&&(j.height=d.current.element.offsetHeight,j.width=d.current.element.offsetWidth),Object.freeze(j),v.current&&!Cr(d.current.lastBounds,j)&&u(d.current.lastBounds=j)};return[g,x?lt(g,x):g,h?lt(g,h):g]},[u,a,h,x]);function A(){d.current.scrollContainers&&(d.current.scrollContainers.forEach(g=>g.removeEventListener("scroll",y,!0)),d.current.scrollContainers=null),d.current.resizeObserver&&(d.current.resizeObserver.disconnect(),d.current.resizeObserver=null)}function S(){d.current.element&&(d.current.resizeObserver=new o(y),d.current.resizeObserver.observe(d.current.element),n&&d.current.scrollContainers&&d.current.scrollContainers.forEach(g=>g.addEventListener("scroll",y,{capture:!0,passive:!0})))}const E=g=>{!g||g===d.current.element||(A(),d.current.element=g,d.current.scrollContainers=It(g),S())};return kr(y,!!n),_r(k),t.p(()=>{A(),S()},[n,y,k]),t.p(()=>A,[]),[E,i,p]}function _r(e){t.p(()=>{const r=e;return window.addEventListener("resize",r),()=>void window.removeEventListener("resize",r)},[e])}function kr(e,r){t.p(()=>{if(r){const n=e;return window.addEventListener("scroll",n,{capture:!0,passive:!0}),()=>void window.removeEventListener("scroll",n,!0)}},[e,r])}function It(e){const r=[];if(!e||e===document.body)return r;const{overflow:n,overflowX:s,overflowY:a}=window.getComputedStyle(e);return[n,s,a].some(o=>o==="auto"||o==="scroll")&&r.push(e),[...r,...It(e.parentElement)]}const Sr=["x","y","top","bottom","left","right","width","height"],Cr=(e,r)=>Sr.every(n=>e[n]===r[n]),ie=({class:e,...r})=>{const{t:n}=t.useTranslation();return t.o("button",{class:t.clsx("bg-accent-9 active:bg-accent-10 pointer-coarse:touch-hitbox fr flex-shrink-0 rounded-full p-2 text-white transition-all disabled:cursor-not-allowed disabled:opacity-50",e),type:"submit",...r,children:t.o("svg",{class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"2",children:[t.o("title",{children:n("send")}),t.o("path",{d:"M3.5 7.5L8 3L12.5 7.5"}),t.o("path",{d:"M8 4V13"})]})})},Er=25,Ue=t.a({instant:()=>{},smooth:()=>{}}),$={onSubmitSuccessFn$:t.a(()=>{}),isBotTyping$:t.a(!1),scrollToEnd:{instant:()=>Ue.value.instant(),smooth:()=>Ue.value.smooth()}},Ar=()=>{const e=t._$1(null);t.y(()=>{Ue.value={instant:()=>{var n;return(n=e.current)==null?void 0:n.scrollTo({top:e.current.scrollHeight,behavior:"instant"})},smooth:()=>{e.current&&e.current.scrollHeight-e.current.scrollTop<=e.current.clientHeight*2&&e.current.scrollTo({top:e.current.scrollHeight,behavior:"smooth"})}}},[e]);const r=t.F(()=>({addToSubmissions:(s,a)=>t.store.setSubmission(s,a),send:async({message:s,signal:a,groupId:o})=>{if(await t.N(s).with({author:"bot",type:"text"},async i=>{if(a!=null&&a.aborted)throw new t.AbortedError;$.isBotTyping$.value=!0;const u=Math.min(Math.max(20,i.text.length),100)*Er;await new Promise(d=>setTimeout(d,u,{signal:a})),$.isBotTyping$.value=!1}).otherwise(async()=>{}),a!=null&&a.aborted)throw new t.AbortedError;t.store.addMessage(s,o)},input:({input:s,signal:a})=>{if(a!=null&&a.aborted)throw new t.AbortedError;return t.store.setInput(s),new Promise(o=>{const i=u=>{if(a!=null&&a.aborted)throw new t.AbortedError;t.store.setInput(void 0),s.key&&t.store.setSubmission(s.key,u),o(u)};$.onSubmitSuccessFn$.value=i})}}),[]);return{chatRef:e,chatService:r}},fe=({error:e})=>!e||!e.message?null:t.o("div",{role:"alert",class:"text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full px-2 py-2",children:[t.o("svg",{class:"text-error-9 h-4 w-4",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.o("circle",{cx:"8",cy:"8",r:"6.3",stroke:"currentColor","stroke-width":"1.4"}),t.o("rect",{x:"7",y:"4",width:"2",height:"5",fill:"currentColor"}),t.o("rect",{x:"7",y:"10",width:"2",height:"2",fill:"currentColor"})]}),t.o("p",{class:"truncate pr-1 text-sm",children:e.message})]}),le=({class:e,...r})=>{const{t:n}=t.useTranslation();return t.o("button",{type:"button",class:t.clsx("fr text-neutral-9 flex flex-shrink-0 items-center justify-center gap-1 rounded-full py-[6px] pl-2 pr-3 text-sm underline-offset-2 transition-all",e),...r,children:[t.o("svg",{"aria-hidden":!0,class:"block",width:"16",height:"16",viewBox:"0 0 16 16",fill:"transparent",stroke:"currentColor","stroke-linecap":"round","stroke-width":"1.5",children:[t.o("title",{children:n("skip")}),t.o("path",{d:"M3.25 11.25A5 5 0 0 1 12 7"}),t.o("path",{d:"M13.25 4.5V8.25H9.5"})]}),n("skip")]})},Ke={Afghanistan:"93",Albania:"355",Algeria:"213","American Samoa":"1 684",Andorra:"376",Angola:"244",Anguilla:"1 264",Antarctica:"672","Antigua and Barbuda":"1 268",Argentina:"54",Armenia:"374",Aruba:"297",Australia:"61",Austria:"43",Azerbaijan:"994",Bahrain:"973",Bangladesh:"880",Barbados:"1 246",Belarus:"375",Belgium:"32",Belize:"501",Benin:"229",Bermuda:"1 441",Bhutan:"975",Bolivia:"591","Bosnia and Herzegovina":"387",Botswana:"267","Bouvet Island":"47",Brazil:"55","British Indian Ocean Territory":"246","British Virgin Islands":"1 284",Brunei:"673",Bulgaria:"359","Burkina Faso":"226",Burundi:"257","Cabo Verde":"238",Cambodia:"855",Cameroon:"237",Canada:"1","Caribbean Netherlands":"599","Cayman Islands":"1 345","Central African Republic":"236",Chad:"235",Chile:"56",China:"86","Christmas Island":"61","Cocos (Keeling) Islands":"61",Colombia:"57",Comoros:"269","Cook Islands":"682","Costa Rica":"506",Croatia:"385",Cuba:"53",Curaçao:"599",Cyprus:"357",Czechia:"420","Côte d'Ivoire":"225","Democratic Republic of the Congo":"243",Denmark:"45",Djibouti:"253","Dominican Republic":"1 809",Ecuador:"593",Egypt:"20","El Salvador":"503","Equatorial Guinea":"240",Eritrea:"291",Estonia:"372",Eswatini:"268",Ethiopia:"251","Falkland Islands (Islas Malvinas)":"500","Faroe Islands":"298",Fiji:"679",Finland:"358",France:"33","French Guiana":"594","French Polynesia":"689","French Southern and Antarctic Lands":"262",Gabon:"241",Georgia:"995",Germany:"49",Ghana:"233",Gibraltar:"350",Greece:"30",Greenland:"299",Grenada:"1 473",Guadeloupe:"590",Guam:"1 671",Guatemala:"502",Guernsey:"44",Guinea:"224","Guinea-Bissau":"245",Guyana:"592",Haiti:"509",Honduras:"504","Hong Kong":"852",Hungary:"36",Iceland:"354",India:"91",Indonesia:"62",Iran:"98",Iraq:"964",Ireland:"353","Isle of Man":"44",Israel:"972",Italy:"39",Jamaica:"1 876",Japan:"81",Jersey:"44",Jordan:"962",Kazakhstan:"7",Kenya:"254",Kiribati:"686",Kosovo:"383",Kuwait:"965",Kyrgyzstan:"996",Laos:"856",Latvia:"371",Lebanon:"961",Lesotho:"266",Liberia:"231",Libya:"218",Liechtenstein:"423",Lithuania:"370",Luxembourg:"352",Macao:"853",Madagascar:"261",Malawi:"265",Malaysia:"60",Maldives:"960",Mali:"223",Malta:"356","Marshall Islands":"692",Martinique:"596",Mauritania:"222",Mauritius:"230",Mayotte:"262",Mexico:"52",Micronesia:"691",Moldova:"373",Monaco:"377",Mongolia:"976",Montenegro:"382",Montserrat:"1 664",Morocco:"212",Mozambique:"258","Myanmar (Burma)":"95",Namibia:"264",Nauru:"674",Nepal:"977",Netherlands:"31","New Caledonia":"687","New Zealand":"64",Nicaragua:"505",Niger:"227",Nigeria:"234",Niue:"683","Norfolk Island":"672","North Korea":"850","North Macedonia":"389","Northern Mariana Islands":"1 670",Norway:"47",Oman:"968",Pakistan:"92",Palau:"680",Palestine:"970",Panama:"507","Papua New Guinea":"675",Paraguay:"595",Peru:"51",Philippines:"63","Pitcairn Islands":"64",Poland:"48",Portugal:"351","Puerto Rico":"1 787",Qatar:"974",Romania:"40",Russia:"7",Rwanda:"250",Réunion:"262","Saint Barthélemy":"590","Saint Helena, Ascension and Tristan da Cunha":"290","Saint Kitts and Nevis":"1 869","Saint Lucia":"1 758","Saint Martin":"590","Saint Pierre and Miquelon":"508","Saint Vincent and the Grenadines":"1 784",Samoa:"685","San Marino":"378","Saudi Arabia":"966",Senegal:"221",Serbia:"381",Seychelles:"248","Sierra Leone":"232",Singapore:"65","Sint Maarten":"1 721",Slovakia:"421",Slovenia:"386","Solomon Islands":"677",Somalia:"252","South Africa":"27","South Georgia and the South Sandwich Islands":"500","South Korea":"82","South Sudan":"211",Spain:"34","Sri Lanka":"94",Sudan:"249",Suriname:"597","Svalbard and Jan Mayen":"47",Sweden:"46",Switzerland:"41",Syria:"963","São Tomé and Príncipe":"239",Taiwan:"886",Tajikistan:"992",Tanzania:"255",Thailand:"66","The Bahamas":"1 242","The Gambia":"220","Timor-Leste":"670",Togo:"228",Tokelau:"690",Tonga:"676","Trinidad and Tobago":"1 868",Tunisia:"216",Turkmenistan:"993","Turks and Caicos Islands":"1 649",Tuvalu:"688",Türkiye:"90","U.S. Virgin Islands":"1 340",Uganda:"256",Ukraine:"380","United Arab Emirates":"971","United Kingdom":"44","United States":"1","United States Minor Outlying Islands":"1",Uruguay:"598",Uzbekistan:"998",Vanuatu:"678","Vatican City":"379",Venezuela:"58",Vietnam:"84","Wallis and Futuna":"681","Western Sahara":"212",Yemen:"967",Zambia:"260",Zimbabwe:"263","Åland Islands":"358"},ve=t.cva("outline-divider ease-expo-out placeholder:text-neutral-10 text-neutral-12 focus-visible:outline-accent-7 caret-accent-9 bg-lowest py-1 text-base outline outline-2 transition-all",{variants:{optional:{true:"pr-16 pl-3",false:"pl-3 pr-3"}},defaultVariants:{optional:!1}}),Tr="https://api.mapbox.com/search/searchbox/v1/suggest",Vr="ZzRDWFU0dTZ3SF9aWk9RNGl6QzZaWS5RZmlFak13a0hPbGxXZXlNSGN5RUhObUJ6TXpSV08yUW5OdE5tSTZJU1lpd2lJb1JYYXRObmJ2Tm5iaGhHZWx4V1lpb2pJMUp5ZS5rcA==",Fr=e=>atob(e).split("").reverse().join(""),Y=t.object({name:t.string()}),Ir=t.object({suggestions:t.array(t.object({full_address:t.optional(t.string()),place_formatted:t.optional(t.string()),name:t.optional(t.string()),mapbox_id:t.string(),context:t.partial(t.object({address:Y,street:Y,neighborhood:Y,locality:Y,district:Y,place:Y,region:Y,postcode:Y,country:Y}))}))}),Mr=({logger:e,t:r})=>t.F(()=>{var s;const n=(s=t.store.current$.peek().flow)==null?void 0:s.data.flowSessionId;return n?{enabled:!0,getPredictions:async a=>{const o=new URL(Tr);o.searchParams.set("q",a),o.searchParams.set("session_token",n),o.searchParams.set("access_token",Fr(Vr));const i=await fetch(o);if(!i.ok)return e.error("Failed to get address details",i),{ok:!1,error:r("address_error")};const u=t.safeParse(Ir,await i.json());if(u.success===!1)return e.error("Failed to parse address details",u.issues),{ok:!1,error:r("address_error")};const{suggestions:d}=u.output;return{ok:!0,data:d.map(h=>{var x,v,p,k,y,A,S,E,g;return{label:h.full_address??h.place_formatted??h.name??h.mapbox_id,id:h.mapbox_id,address:{line1:((x=h.context.address)==null?void 0:x.name)??((v=h.context.street)==null?void 0:v.name),line2:void 0,line3:((p=h.context.neighborhood)==null?void 0:p.name)??((k=h.context.locality)==null?void 0:k.name),city:((y=h.context.place)==null?void 0:y.name)??((A=h.context.district)==null?void 0:A.name),state:(S=h.context.region)==null?void 0:S.name,postcode:(E=h.context.postcode)==null?void 0:E.name,country:(g=h.context.country)==null?void 0:g.name}}})}}}:{enabled:!1}},[e,r]),ut=e=>{const{t:r}=t.useTranslation();return t.o("button",{type:"button",class:"text-neutral-10 hover:bg-neutral-4 hover:text-neutral-12 hover:border-neutral-5 flex items-center gap-1 rounded-[18px] border border-solid border-transparent px-3 py-1 pl-1.5 text-sm transition-colors",...e,children:[t.o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",stroke:"currentColor","stroke-width":"1.5",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.o("path",{d:"M10 3L5 8L10 13"})}),t.o("span",{children:r("back")})]})},Lr=({input:e,onSubmitSuccess:r,logger:n})=>{const{t:s}=t.useTranslation(),[a,o]=t.h(),[i,u]=t.h([]),{enabled:d,getPredictions:h}=Mr({logger:n,t:s}),[x,v]=t.h(d?"query":"manual"),[p,k]=t.h(""),[y,A]=t.h(),S=E=>{t.invariant(d,"Query state should not be enabled"),E=E.trim(),E!==(p==null?void 0:p.trim())&&(k(E),E===""&&u([]),A(void 0),h(E).then(g=>{if(g.ok===!1){u([]),A(g.error);return}u(g.data)}))};switch(x){case"query":return t.invariant(d,"Query state should not be enabled"),t.o(Nr,{input:e,onSkip:()=>r(null),onAddressSelect:E=>{if(E===""){o(void 0),v("manual");return}const g=i.find(F=>F.id===E);g&&(o(g.address),v("details"))},onAddressSearch:E=>{S(E)},suggestions:i,query:p,error:y});case"details":return t.invariant(a!==void 0),t.o(dt,{input:e,logger:n,onSubmitSuccess:r,addressFields:a,actions:t.o(ut,{onClick:()=>{v("query")}})});case"manual":return t.o(dt,{logger:n,input:e,onSubmitSuccess:r,addressFields:{},actions:d?t.o(ut,{onClick:()=>{v("query")}}):void 0})}},Nr=({input:e,onSkip:r,suggestions:n,onAddressSelect:s,query:a,onAddressSearch:o,error:i})=>{const{t:u}=t.useTranslation(),d=t._$1(null);return t.y(()=>{d.current&&(d.current.focus(),d.current.select())},[]),t.o(t.k,{children:[t.o("form",{noValidate:!0,onSubmit:h=>{h.preventDefault();const v=new FormData(h.currentTarget).get("address");typeof v=="string"&&o(v)},class:"flex gap-1 p-2.5",children:[t.o("div",{class:"group relative flex-1",children:[t.o("input",{ref:d,name:"address",id:"chat-address",autocomplete:"address-line1 country-name postal-code",autoFocus:!0,placeholder:e.config.placeholder||u("address_search"),defaultValue:a,class:ve({optional:!!e.config.optional,className:"w-full rounded-full"})}),t.o("button",{type:"submit",class:"touch-hitbox text-neutral-12 hover:bg-neutral-3 fr absolute bottom-0 right-0 top-0 flex cursor-pointer items-center gap-1 rounded-full px-3 transition-all",children:t.o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.o("g",{id:"inploi",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round",strokeWidth:"1.5",children:[t.o("circle",{cx:"7",cy:"7",r:"4"}),t.o("path",{d:"M10 10L13 13"})]}),t.o("span",{class:"sr-only",children:u("search")})]})})]}),e.config.optional&&t.o(le,{class:"",onClick:r})]}),i?t.o(fe,{error:{message:i}}):null,t.o("ul",{children:[n.map(h=>t.o("li",{children:t.o("button",{class:"text-neutral-11 fr hover:bg-neutral-3 focus-visible:bg-neutral-3 hover:text-neutral-12 border-b-neutral-3 flex w-full items-center border border-b border-solid border-transparent px-4 py-3 text-sm transition-colors duration-100",onClick:()=>{s(h.id)},children:[t.o("span",{class:"flex-grow",children:h.label}),t.o("svg",{class:"flex-none",width:"16",height:"16",viewBox:"0 0 16 16",stroke:"currentColor","stroke-width":"1.5",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.o("path",{d:"M6 3L11 8L6 13"})})]})},h.id)),t.o("li",{children:t.o("button",{class:"text-neutral-11 fr hover:bg-neutral-3 focus-visible:bg-neutral-3 hover:text-neutral-12 border-b-neutral-3 flex w-full items-center border border-b border-solid border-transparent px-4 py-3 text-sm transition-colors duration-100",onClick:()=>{s("")},children:t.o("span",{class:"flex-grow",children:u("address_manual")})})},"")]})]})},ct=["line1","line2","line3","city","state","postcode","country"],dt=({addressFields:e,onSubmitSuccess:r,actions:n,input:s})=>{const a=t._$1(null);t.y(()=>{if(a.current){const u=a.current.querySelector("input");u&&(u.focus(),u.select())}},[]);const o=Object.keys(Ke),{t:i}=t.useTranslation();return t.o("form",{class:"bg-neutral-1/90 flex flex-col justify-end gap-2 p-2",onSubmit:u=>{const d=new FormData(u.currentTarget),h=Object.fromEntries(d.entries());r({type:"address",value:h})},children:[t.o("div",{class:"bg-neutral-3 border-neutral-5 grid items-center gap-1.5 rounded-2xl border pb-2 pl-4 pr-3 pt-3 [grid-template-columns:min-content_1fr]",ref:a,children:ct.map((u,d)=>{const h=`isdk_${u}`,x=s.config.keys[u];return x?t.o(t.k,{children:[t.o("label",{for:h,class:"text-neutral-9 [&:has(+*>input:focus)]:text-neutral-11 w-24 pb-2 text-xs uppercase leading-3 tracking-widest transition-colors",children:i(u)}),t.o("div",{class:"flex flex-col items-stretch gap-1.5",children:[u==="country"?t.o("div",{class:"relative",children:[t.o("select",{class:"text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus:bg-neutral-5 w-full flex-1 appearance-none rounded-lg border-solid bg-transparent bg-none px-3 py-1.5 text-base transition-colors focus:outline-none",name:x,id:h,defaultValue:e[u],required:!0,children:[e.country&&!o.includes(e.country)?t.o("option",{value:e[u],children:e[u]}):t.o("option",{value:"",children:i("select_country")}),o.map(v=>t.o("option",{value:v,children:v},v))]}),t.o("svg",{class:"text-neutral-12 absolute bottom-2.5 right-2 flex items-center justify-center",width:"16",height:"16",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.o("path",{d:"M4 6.5L8 10.5L12 6.5"})})]}):t.o("input",{autoFocus:d===0?!0:void 0,class:"text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus:bg-neutral-5 flex-1 rounded-lg border-solid bg-transparent px-3 py-1.5 text-base transition-colors autofill:shadow-[inset_0_0_0_1000px_hsl(210_16.7%_97.6%)] focus:outline-none",name:x,id:h,defaultValue:e[u],required:!0}),d===ct.length-1?t.o("hr",{class:"m-0 w-full border-b border-b-transparent"}):t.o("hr",{class:"border-b-neutral-5 m-0 w-full border-b border-solid"})]})]}):null})}),t.o("div",{class:"flex w-full flex-1 ",children:[t.o("div",{class:"flex-grow",children:n}),t.o(ie,{class:"flex items-center justify-center"})]})]})},Ge=()=>{const e=t._$1(null);return t.p(()=>{var r;(r=e.current)==null||r.focus()},[]),e},Mt=["true","false"],Rr=t.picklist(Mt),Dr="answer",Lt="flex items-center gap-2 p-2.5",Nt=t.k$1(({label:e,...r},n)=>t.o("button",{class:"bg-lowest ease-expo-out ring-divider text-neutral-12 active:ring-accent-7 active:bg-accent-2 active:text-accent-11 fr block w-full overflow-hidden rounded-2xl px-2.5 py-2.5 ring-2 transition-all selection:bg-transparent",...r,ref:n,children:t.o("p",{class:"truncate text-center text-base",children:e})})),Or=({input:e,onSubmitSuccess:r})=>{const n=Ge();return t.o("form",{noValidate:!0,class:"",onSubmit:s=>{s.preventDefault();const a=t.getFormSubmitter(s).value,o=t.parse(Rr,a);r({type:"boolean",value:o==="true"})},children:[t.o("ul",{class:Lt,children:Mt.map((s,a)=>t.o("li",{class:"flex-1",children:t.o(Nt,{ref:a===0?n:null,type:"submit",name:Dr,value:s,label:e.config.labels[s]},s)}))}),e.config.optional&&t.o("div",{class:"px-2 pb-2",children:t.o(le,{class:"w-full",type:"button",onClick:()=>r(null)})})]})},Br=e=>new Promise((r,n)=>{const s=new FileReader;s.readAsDataURL(e),s.onload=()=>s.result?r(s.result.toString()):n("No result from reader"),s.onerror=n}),Pr=e=>e.reduce((r,n)=>r+n.sizeKb,0),$r=t.isSubmissionOfType("file"),ft=3,jr=({file:e,class:r,...n})=>{const s=e.name.split(".").pop(),a=e.name.replace(new RegExp(`.${s}$`),"");return t.o("div",{class:t.clsx("bg-accent-1 outline-accent-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline",r),...n,children:[t.o("p",{"aria-label":"File name",class:"text-accent-12 flex flex-grow overflow-hidden",children:[t.o("span",{class:"block truncate",children:a}),t.o("span",{children:[".",s]})]}),t.o("p",{"aria-label":"File size",class:"text-accent-11",children:t.kbToReadableSize(e.sizeKb)})]})},ht=({class:e,...r})=>t.o("li",{class:t.clsx("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1",e),...r}),Rt=e=>{const r=e.split(".").pop();if(!r)throw new Error("No file extension found");return r?"."+r:""},zr=({allowedExtensions:e,files:r})=>{const n=e.map(s=>s.toLowerCase());return r.every(s=>n.includes(Rt(s.name).toLowerCase()))},qr=(e,r)=>{const n=Rt(e);return`${e.replace(new RegExp(`${n}$`),"").slice(0,r)}${n}`},Ur=({input:e,onSubmitSuccess:r})=>{var v;const n=(v=t.store.current$.value.flow)==null?void 0:v.data.submissions[e.key],[s,a]=t.h($r(n)?n.value:[]),[o,i]=t.h(),u=s.length-ft,d=Pr(s),h=Ge(),{t:x}=t.useTranslation();return t.o("form",{class:"flex flex-col gap-1 p-2.5",onSubmit:p=>(p.preventDefault(),i(void 0),s.length===0?i({type:"required",message:x("validation_file")}):e.config.extensions.length>0&&!zr({allowedExtensions:e.config.extensions,files:s})?i({type:"validate",message:`${x("validation_file_ext",{ext:e.config.extensions.join(", ")})}`}):e.config.fileSizeLimitKib&&d>e.config.fileSizeLimitKib?i({type:"max",message:`File size exceeds limit of ${t.kbToReadableSize(e.config.fileSizeLimitKib)}`}):e.config.allowMultiple===!1&&s.length>1?i({type:"invalid",message:x("validation_file_max",{count:1})}):r({type:"file",value:s})),children:[t.o("div",{class:"flex items-center gap-2",children:[t.o("label",{ref:h,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:[s.length>0?t.o(t.k,{children:[t.o("ul",{class:"flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",children:[s.slice(0,ft).map(p=>{const k=p.name.split(".").pop(),y=p.name.replace(new RegExp(`.${k}$`),"");return t.o(ht,{class:"flex overflow-hidden",children:[t.o("span",{class:"block truncate",children:y}),t.o("span",{children:[".",k]})]})}),u>0?t.o(ht,{children:["+",u," file",u!==1?"s":""]}):null]}),t.o("p",{class:"text-neutral-11 text-xs",children:[t.kbToReadableSize(d)," ",s.length>1?"total":""]})]}):t.o("div",{class:"flex flex-col justify-center gap-4 pb-6 pt-5",children:[t.o("header",{class:"flex flex-col items-center gap-0",children:[t.o("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:t.o("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"})}),t.o("p",{class:"text-neutral-12 tracking-[-0.01em]",children:x("upload_file",{count:e.config.allowMultiple?2:1})}),e.config.fileSizeLimitKib?t.o("p",{class:"text-neutral-10 text-xs",children:["(",x("file_max_size",{size:t.kbToReadableSize(e.config.fileSizeLimitKib)}),")"]}):null]}),t.o("aside",{class:"flex flex-col items-center gap-2",children:[t.o("p",{id:"accepted-filetypes",class:"sr-only",children:x("file_extensions")}),t.o("ul",{"aria-describedby":"accepted-filetypes",class:"flex flex-wrap justify-center gap-2",children:e.config.extensions.map(p=>t.o("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:p.replace(".","")}))})]})]}),t.o("input",{id:"dropzone-file",onInput:async p=>{t.invariant(p.target instanceof HTMLInputElement);const k=p.target.files?Array.from(p.target.files):[],y=await Promise.allSettled(k.map(async S=>{const E=await Br(S);return{name:qr(S.name,42),data:E,sizeKb:S.size/1e3}}));if(y.some(({status:S})=>S==="rejected"))return i({type:"invalid",message:"Invalid file"});const A=y.map(S=>S.status==="fulfilled"?S.value:null).filter(Boolean);a(A)},multiple:e.config.allowMultiple,type:"file",class:"sr-only"})]}),t.o("div",{class:"flex h-full flex-col items-center gap-2",children:[t.o(ie,{disabled:s.length===0}),e.config.optional&&t.o(le,{onClick:()=>r(null)})]})]}),t.o(fe,{error:o})]})};var xe=e=>e.type==="checkbox",de=e=>e instanceof Date,z=e=>e==null;const Dt=e=>typeof e=="object";var B=e=>!z(e)&&!Array.isArray(e)&&Dt(e)&&!de(e),Kr=e=>B(e)&&e.target?xe(e.target)?e.target.checked:e.target.value:e,Gr=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Hr=(e,r)=>e.has(Gr(r)),Wr=e=>{const r=e.constructor&&e.constructor.prototype;return B(r)&&r.hasOwnProperty("isPrototypeOf")},He=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ee(e){let r;const n=Array.isArray(e);if(e instanceof Date)r=new Date(e);else if(e instanceof Set)r=new Set(e);else if(!(He&&(e instanceof Blob||e instanceof FileList))&&(n||B(e)))if(r=n?[]:{},!n&&!Wr(e))r=e;else for(const s in e)e.hasOwnProperty(s)&&(r[s]=ee(e[s]));else return e;return r}var we=e=>Array.isArray(e)?e.filter(Boolean):[],R=e=>e===void 0,w=(e,r,n)=>{if(!r||!B(e))return n;const s=we(r.split(/[,[\].]+?/)).reduce((a,o)=>z(a)?a:a[o],e);return R(s)||s===e?R(e[r])?n:e[r]:s},re=e=>typeof e=="boolean";const pt={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},H={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Q={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};t.Cn.createContext(null);var Jr=(e,r,n,s=!0)=>{const a={defaultValues:r._defaultValues};for(const o in e)Object.defineProperty(a,o,{get:()=>{const i=o;return r._proxyFormState[i]!==H.all&&(r._proxyFormState[i]=!s||H.all),n&&(n[i]=!0),e[i]}});return a},G=e=>B(e)&&!Object.keys(e).length,Zr=(e,r,n,s)=>{n(e);const{name:a,...o}=e;return G(o)||Object.keys(o).length>=Object.keys(r).length||Object.keys(o).find(i=>r[i]===(!s||H.all))},Be=e=>Array.isArray(e)?e:[e];function Xr(e){const r=t.Cn.useRef(e);r.current=e,t.Cn.useEffect(()=>{const n=!e.disabled&&r.current.subject&&r.current.subject.subscribe({next:r.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}var J=e=>typeof e=="string",Yr=(e,r,n,s,a)=>J(e)?(s&&r.watch.add(e),w(n,e,a)):Array.isArray(e)?e.map(o=>(s&&r.watch.add(o),w(n,o))):(s&&(r.watchAll=!0),n),We=e=>/^\w*$/.test(e),Ot=e=>we(e.replace(/["|']|\]/g,"").split(/\.|\[/));function I(e,r,n){let s=-1;const a=We(r)?[r]:Ot(r),o=a.length,i=o-1;for(;++s<o;){const u=a[s];let d=n;if(s!==i){const h=e[u];d=B(h)||Array.isArray(h)?h:isNaN(+a[s+1])?{}:[]}e[u]=d,e=e[u]}return e}var Bt=(e,r,n,s,a)=>r?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[s]:a||!0}}:{},mt=e=>({isOnSubmit:!e||e===H.onSubmit,isOnBlur:e===H.onBlur,isOnChange:e===H.onChange,isOnAll:e===H.all,isOnTouch:e===H.onTouched}),gt=(e,r,n)=>!n&&(r.watchAll||r.watch.has(e)||[...r.watch].some(s=>e.startsWith(s)&&/^\.\w+/.test(e.slice(s.length))));const Se=(e,r,n,s)=>{for(const a of n||Object.keys(e)){const o=w(e,a);if(o){const{_f:i,...u}=o;if(i){if(i.refs&&i.refs[0]&&r(i.refs[0],a)&&!s)break;if(i.ref&&r(i.ref,i.name)&&!s)break}else B(u)&&Se(u,r)}}};var Qr=(e,r,n)=>{const s=we(w(e,n));return I(s,"root",r[n]),I(e,n,s),e},Je=e=>e.type==="file",ne=e=>typeof e=="function",Ee=e=>{if(!He)return!1;const r=e?e.ownerDocument:0;return e instanceof(r&&r.defaultView?r.defaultView.HTMLElement:HTMLElement)},Ce=e=>J(e),Ze=e=>e.type==="radio",Ae=e=>e instanceof RegExp;const bt={value:!1,isValid:!1},yt={value:!0,isValid:!0};var Pt=e=>{if(Array.isArray(e)){if(e.length>1){const r=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:r,isValid:!!r.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!R(e[0].attributes.value)?R(e[0].value)||e[0].value===""?yt:{value:e[0].value,isValid:!0}:yt:bt}return bt};const vt={isValid:!1,value:null};var $t=e=>Array.isArray(e)?e.reduce((r,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:r,vt):vt;function xt(e,r,n="validate"){if(Ce(e)||Array.isArray(e)&&e.every(Ce)||re(e)&&!e)return{type:n,message:Ce(e)?e:"",ref:r}}var ce=e=>B(e)&&!Ae(e)?e:{value:e,message:""},wt=async(e,r,n,s,a)=>{const{ref:o,refs:i,required:u,maxLength:d,minLength:h,min:x,max:v,pattern:p,validate:k,name:y,valueAsNumber:A,mount:S,disabled:E}=e._f,g=w(r,y);if(!S||E)return{};const F=i?i[0]:o,O=V=>{s&&F.reportValidity&&(F.setCustomValidity(re(V)?"":V||""),F.reportValidity())},L={},se=Ze(o),te=xe(o),he=se||te,U=(A||Je(o))&&R(o.value)&&R(g)||Ee(o)&&o.value===""||g===""||Array.isArray(g)&&!g.length,X=Bt.bind(null,y,n,L),j=(V,T,N,q=Q.maxLength,K=Q.minLength)=>{const W=V?T:N;L[y]={type:V?q:K,message:W,ref:o,...X(V?q:K,W)}};if(a?!Array.isArray(g)||!g.length:u&&(!he&&(U||z(g))||re(g)&&!g||te&&!Pt(i).isValid||se&&!$t(i).isValid)){const{value:V,message:T}=Ce(u)?{value:!!u,message:u}:ce(u);if(V&&(L[y]={type:Q.required,message:T,ref:F,...X(Q.required,T)},!n))return O(T),L}if(!U&&(!z(x)||!z(v))){let V,T;const N=ce(v),q=ce(x);if(!z(g)&&!isNaN(g)){const K=o.valueAsNumber||g&&+g;z(N.value)||(V=K>N.value),z(q.value)||(T=K<q.value)}else{const K=o.valueAsDate||new Date(g),W=_e=>new Date(new Date().toDateString()+" "+_e),ae=o.type=="time",pe=o.type=="week";J(N.value)&&g&&(V=ae?W(g)>W(N.value):pe?g>N.value:K>new Date(N.value)),J(q.value)&&g&&(T=ae?W(g)<W(q.value):pe?g<q.value:K<new Date(q.value))}if((V||T)&&(j(!!V,N.message,q.message,Q.max,Q.min),!n))return O(L[y].message),L}if((d||h)&&!U&&(J(g)||a&&Array.isArray(g))){const V=ce(d),T=ce(h),N=!z(V.value)&&g.length>+V.value,q=!z(T.value)&&g.length<+T.value;if((N||q)&&(j(N,V.message,T.message),!n))return O(L[y].message),L}if(p&&!U&&J(g)){const{value:V,message:T}=ce(p);if(Ae(V)&&!g.match(V)&&(L[y]={type:Q.pattern,message:T,ref:o,...X(Q.pattern,T)},!n))return O(T),L}if(k){if(ne(k)){const V=await k(g,r),T=xt(V,F);if(T&&(L[y]={...T,...X(Q.validate,T.message)},!n))return O(T.message),L}else if(B(k)){let V={};for(const T in k){if(!G(V)&&!n)break;const N=xt(await k[T](g,r),F,T);N&&(V={...N,...X(T,N.message)},O(N.message),n&&(L[y]=V))}if(!G(V)&&(L[y]={ref:F,...V},!n))return L}}return O(!0),L};function en(e,r){const n=r.slice(0,-1).length;let s=0;for(;s<n;)e=R(e)?s++:e[r[s++]];return e}function tn(e){for(const r in e)if(e.hasOwnProperty(r)&&!R(e[r]))return!1;return!0}function P(e,r){const n=Array.isArray(r)?r:We(r)?[r]:Ot(r),s=n.length===1?e:en(e,n),a=n.length-1,o=n[a];return s&&delete s[o],a!==0&&(B(s)&&G(s)||Array.isArray(s)&&tn(s))&&P(e,n.slice(0,-1)),e}function Pe(){let e=[];return{get observers(){return e},next:a=>{for(const o of e)o.next&&o.next(a)},subscribe:a=>(e.push(a),{unsubscribe:()=>{e=e.filter(o=>o!==a)}}),unsubscribe:()=>{e=[]}}}var Te=e=>z(e)||!Dt(e);function oe(e,r){if(Te(e)||Te(r))return e===r;if(de(e)&&de(r))return e.getTime()===r.getTime();const n=Object.keys(e),s=Object.keys(r);if(n.length!==s.length)return!1;for(const a of n){const o=e[a];if(!s.includes(a))return!1;if(a!=="ref"){const i=r[a];if(de(o)&&de(i)||B(o)&&B(i)||Array.isArray(o)&&Array.isArray(i)?!oe(o,i):o!==i)return!1}}return!0}var jt=e=>e.type==="select-multiple",rn=e=>Ze(e)||xe(e),$e=e=>Ee(e)&&e.isConnected,zt=e=>{for(const r in e)if(ne(e[r]))return!0;return!1};function Ve(e,r={}){const n=Array.isArray(e);if(B(e)||n)for(const s in e)Array.isArray(e[s])||B(e[s])&&!zt(e[s])?(r[s]=Array.isArray(e[s])?[]:{},Ve(e[s],r[s])):z(e[s])||(r[s]=!0);return r}function qt(e,r,n){const s=Array.isArray(e);if(B(e)||s)for(const a in e)Array.isArray(e[a])||B(e[a])&&!zt(e[a])?R(r)||Te(n[a])?n[a]=Array.isArray(e[a])?Ve(e[a],[]):{...Ve(e[a])}:qt(e[a],z(r)?{}:r[a],n[a]):n[a]=!oe(e[a],r[a]);return n}var je=(e,r)=>qt(e,r,Ve(r)),Ut=(e,{valueAsNumber:r,valueAsDate:n,setValueAs:s})=>R(e)?e:r?e===""?NaN:e&&+e:n&&J(e)?new Date(e):s?s(e):e;function ze(e){const r=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):r.disabled))return Je(r)?r.files:Ze(r)?$t(e.refs).value:jt(r)?[...r.selectedOptions].map(({value:n})=>n):xe(r)?Pt(e.refs).value:Ut(R(r.value)?e.ref.value:r.value,e)}var nn=(e,r,n,s)=>{const a={};for(const o of e){const i=w(r,o);i&&I(a,o,i._f)}return{criteriaMode:n,names:[...e],fields:a,shouldUseNativeValidation:s}},ge=e=>R(e)?e:Ae(e)?e.source:B(e)?Ae(e.value)?e.value.source:e.value:e,sn=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function _t(e,r,n){const s=w(e,n);if(s||We(n))return{error:s,name:n};const a=n.split(".");for(;a.length;){const o=a.join("."),i=w(r,o),u=w(e,o);if(i&&!Array.isArray(i)&&n!==o)return{name:n};if(u&&u.type)return{name:o,error:u};a.pop()}return{name:n}}var an=(e,r,n,s,a)=>a.isOnAll?!1:!n&&a.isOnTouch?!(r||e):(n?s.isOnBlur:a.isOnBlur)?!e:(n?s.isOnChange:a.isOnChange)?e:!0,on=(e,r)=>!we(w(e,r)).length&&P(e,r);const ln={mode:H.onSubmit,reValidateMode:H.onChange,shouldFocusError:!0};function un(e={},r){let n={...ln,...e},s={submitCount:0,isDirty:!1,isLoading:ne(n.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},a={},o=B(n.defaultValues)||B(n.values)?ee(n.defaultValues||n.values)||{}:{},i=n.shouldUnregister?{}:ee(o),u={action:!1,mount:!1,watch:!1},d={mount:new Set,unMount:new Set,array:new Set,watch:new Set},h,x=0;const v={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},p={values:Pe(),array:Pe(),state:Pe()},k=e.resetOptions&&e.resetOptions.keepDirtyValues,y=mt(n.mode),A=mt(n.reValidateMode),S=n.criteriaMode===H.all,E=l=>c=>{clearTimeout(x),x=setTimeout(l,c)},g=async l=>{if(v.isValid||l){const c=n.resolver?G((await U()).errors):await j(a,!0);c!==s.isValid&&p.state.next({isValid:c})}},F=l=>v.isValidating&&p.state.next({isValidating:l}),O=(l,c=[],f,_,b=!0,m=!0)=>{if(_&&f){if(u.action=!0,m&&Array.isArray(w(a,l))){const C=f(w(a,l),_.argA,_.argB);b&&I(a,l,C)}if(m&&Array.isArray(w(s.errors,l))){const C=f(w(s.errors,l),_.argA,_.argB);b&&I(s.errors,l,C),on(s.errors,l)}if(v.touchedFields&&m&&Array.isArray(w(s.touchedFields,l))){const C=f(w(s.touchedFields,l),_.argA,_.argB);b&&I(s.touchedFields,l,C)}v.dirtyFields&&(s.dirtyFields=je(o,i)),p.state.next({name:l,isDirty:T(l,c),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else I(i,l,c)},L=(l,c)=>{I(s.errors,l,c),p.state.next({errors:s.errors})},se=(l,c,f,_)=>{const b=w(a,l);if(b){const m=w(i,l,R(f)?w(o,l):f);R(m)||_&&_.defaultChecked||c?I(i,l,c?m:ze(b._f)):K(l,m),u.mount&&g()}},te=(l,c,f,_,b)=>{let m=!1,C=!1;const M={name:l};if(!f||_){v.isDirty&&(C=s.isDirty,s.isDirty=M.isDirty=T(),m=C!==M.isDirty);const D=oe(w(o,l),c);C=w(s.dirtyFields,l),D?P(s.dirtyFields,l):I(s.dirtyFields,l,!0),M.dirtyFields=s.dirtyFields,m=m||v.dirtyFields&&C!==!D}if(f){const D=w(s.touchedFields,l);D||(I(s.touchedFields,l,f),M.touchedFields=s.touchedFields,m=m||v.touchedFields&&D!==f)}return m&&b&&p.state.next(M),m?M:{}},he=(l,c,f,_)=>{const b=w(s.errors,l),m=v.isValid&&re(c)&&s.isValid!==c;if(e.delayError&&f?(h=E(()=>L(l,f)),h(e.delayError)):(clearTimeout(x),h=null,f?I(s.errors,l,f):P(s.errors,l)),(f?!oe(b,f):b)||!G(_)||m){const C={..._,...m&&re(c)?{isValid:c}:{},errors:s.errors,name:l};s={...s,...C},p.state.next(C)}F(!1)},U=async l=>n.resolver(i,n.context,nn(l||d.mount,a,n.criteriaMode,n.shouldUseNativeValidation)),X=async l=>{const{errors:c}=await U(l);if(l)for(const f of l){const _=w(c,f);_?I(s.errors,f,_):P(s.errors,f)}else s.errors=c;return c},j=async(l,c,f={valid:!0})=>{for(const _ in l){const b=l[_];if(b){const{_f:m,...C}=b;if(m){const M=d.array.has(m.name),D=await wt(b,i,S,n.shouldUseNativeValidation&&!c,M);if(D[m.name]&&(f.valid=!1,c))break;!c&&(w(D,m.name)?M?Qr(s.errors,D,m.name):I(s.errors,m.name,D[m.name]):P(s.errors,m.name))}C&&await j(C,c,f)}}return f.valid},V=()=>{for(const l of d.unMount){const c=w(a,l);c&&(c._f.refs?c._f.refs.every(f=>!$e(f)):!$e(c._f.ref))&&Ne(l)}d.unMount=new Set},T=(l,c)=>(l&&c&&I(i,l,c),!oe(Xe(),o)),N=(l,c,f)=>Yr(l,d,{...u.mount?i:R(c)?o:J(l)?{[l]:c}:c},f,c),q=l=>we(w(u.mount?i:o,l,e.shouldUnregister?w(o,l,[]):[])),K=(l,c,f={})=>{const _=w(a,l);let b=c;if(_){const m=_._f;m&&(!m.disabled&&I(i,l,Ut(c,m)),b=Ee(m.ref)&&z(c)?"":c,jt(m.ref)?[...m.ref.options].forEach(C=>C.selected=b.includes(C.value)):m.refs?xe(m.ref)?m.refs.length>1?m.refs.forEach(C=>(!C.defaultChecked||!C.disabled)&&(C.checked=Array.isArray(b)?!!b.find(M=>M===C.value):b===C.value)):m.refs[0]&&(m.refs[0].checked=!!b):m.refs.forEach(C=>C.checked=C.value===b):Je(m.ref)?m.ref.value="":(m.ref.value=b,m.ref.type||p.values.next({name:l,values:{...i}})))}(f.shouldDirty||f.shouldTouch)&&te(l,b,f.shouldTouch,f.shouldDirty,!0),f.shouldValidate&&Le(l)},W=(l,c,f)=>{for(const _ in c){const b=c[_],m=`${l}.${_}`,C=w(a,m);(d.array.has(l)||!Te(b)||C&&!C._f)&&!de(b)?W(m,b,f):K(m,b,f)}},ae=(l,c,f={})=>{const _=w(a,l),b=d.array.has(l),m=ee(c);I(i,l,m),b?(p.array.next({name:l,values:{...i}}),(v.isDirty||v.dirtyFields)&&f.shouldDirty&&p.state.next({name:l,dirtyFields:je(o,i),isDirty:T(l,m)})):_&&!_._f&&!z(m)?W(l,m,f):K(l,m,f),gt(l,d)&&p.state.next({...s}),p.values.next({name:l,values:{...i}}),!u.mount&&r()},pe=async l=>{const c=l.target;let f=c.name,_=!0;const b=w(a,f),m=()=>c.type?ze(b._f):Kr(l),C=M=>{_=Number.isNaN(M)||M===w(i,f,M)};if(b){let M,D;const ke=m(),ue=l.type===pt.BLUR||l.type===pt.FOCUS_OUT,Zt=!sn(b._f)&&!n.resolver&&!w(s.errors,f)&&!b._f.deps||an(ue,w(s.touchedFields,f),s.isSubmitted,A,y),De=gt(f,d,ue);I(i,f,ke),ue?(b._f.onBlur&&b._f.onBlur(l),h&&h(0)):b._f.onChange&&b._f.onChange(l);const Oe=te(f,ke,ue,!1),Xt=!G(Oe)||De;if(!ue&&p.values.next({name:f,type:l.type,values:{...i}}),Zt)return v.isValid&&g(),Xt&&p.state.next({name:f,...De?{}:Oe});if(!ue&&De&&p.state.next({...s}),F(!0),n.resolver){const{errors:at}=await U([f]);if(C(ke),_){const Yt=_t(s.errors,a,f),ot=_t(at,a,Yt.name||f);M=ot.error,f=ot.name,D=G(at)}}else M=(await wt(b,i,S,n.shouldUseNativeValidation))[f],C(ke),_&&(M?D=!1:v.isValid&&(D=await j(a,!0)));_&&(b._f.deps&&Le(b._f.deps),he(f,D,M,Oe))}},_e=(l,c)=>{if(w(s.errors,c)&&l.focus)return l.focus(),1},Le=async(l,c={})=>{let f,_;const b=Be(l);if(F(!0),n.resolver){const m=await X(R(l)?l:b);f=G(m),_=l?!b.some(C=>w(m,C)):f}else l?(_=(await Promise.all(b.map(async m=>{const C=w(a,m);return await j(C&&C._f?{[m]:C}:C)}))).every(Boolean),!(!_&&!s.isValid)&&g()):_=f=await j(a);return p.state.next({...!J(l)||v.isValid&&f!==s.isValid?{}:{name:l},...n.resolver||!l?{isValid:f}:{},errors:s.errors,isValidating:!1}),c.shouldFocus&&!_&&Se(a,_e,l?b:d.mount),_},Xe=l=>{const c={...o,...u.mount?i:{}};return R(l)?c:J(l)?w(c,l):l.map(f=>w(c,f))},Ye=(l,c)=>({invalid:!!w((c||s).errors,l),isDirty:!!w((c||s).dirtyFields,l),isTouched:!!w((c||s).touchedFields,l),error:w((c||s).errors,l)}),Gt=l=>{l&&Be(l).forEach(c=>P(s.errors,c)),p.state.next({errors:l?s.errors:{}})},Qe=(l,c,f)=>{const _=(w(a,l,{_f:{}})._f||{}).ref;I(s.errors,l,{...c,ref:_}),p.state.next({name:l,errors:s.errors,isValid:!1}),f&&f.shouldFocus&&_&&_.focus&&_.focus()},Ht=(l,c)=>ne(l)?p.values.subscribe({next:f=>l(N(void 0,c),f)}):N(l,c,!0),Ne=(l,c={})=>{for(const f of l?Be(l):d.mount)d.mount.delete(f),d.array.delete(f),c.keepValue||(P(a,f),P(i,f)),!c.keepError&&P(s.errors,f),!c.keepDirty&&P(s.dirtyFields,f),!c.keepTouched&&P(s.touchedFields,f),!n.shouldUnregister&&!c.keepDefaultValue&&P(o,f);p.values.next({values:{...i}}),p.state.next({...s,...c.keepDirty?{isDirty:T()}:{}}),!c.keepIsValid&&g()},et=({disabled:l,name:c,field:f,fields:_,value:b})=>{if(re(l)){const m=l?void 0:R(b)?ze(f?f._f:w(_,c)._f):b;I(i,c,m),te(c,m,!1,!1,!0)}},Re=(l,c={})=>{let f=w(a,l);const _=re(c.disabled);return I(a,l,{...f||{},_f:{...f&&f._f?f._f:{ref:{name:l}},name:l,mount:!0,...c}}),d.mount.add(l),f?et({field:f,disabled:c.disabled,name:l}):se(l,!0,c.value),{..._?{disabled:c.disabled}:{},...n.progressive?{required:!!c.required,min:ge(c.min),max:ge(c.max),minLength:ge(c.minLength),maxLength:ge(c.maxLength),pattern:ge(c.pattern)}:{},name:l,onChange:pe,onBlur:pe,ref:b=>{if(b){Re(l,c),f=w(a,l);const m=R(b.value)&&b.querySelectorAll&&b.querySelectorAll("input,select,textarea")[0]||b,C=rn(m),M=f._f.refs||[];if(C?M.find(D=>D===m):m===f._f.ref)return;I(a,l,{_f:{...f._f,...C?{refs:[...M.filter($e),m,...Array.isArray(w(o,l))?[{}]:[]],ref:{type:m.type,name:l}}:{ref:m}}}),se(l,!1,void 0,m)}else f=w(a,l,{}),f._f&&(f._f.mount=!1),(n.shouldUnregister||c.shouldUnregister)&&!(Hr(d.array,l)&&u.action)&&d.unMount.add(l)}}},tt=()=>n.shouldFocusError&&Se(a,_e,d.mount),Wt=l=>{re(l)&&(p.state.next({disabled:l}),Se(a,c=>{c.disabled=l},0,!1))},rt=(l,c)=>async f=>{f&&(f.preventDefault&&f.preventDefault(),f.persist&&f.persist());let _=ee(i);if(p.state.next({isSubmitting:!0}),n.resolver){const{errors:b,values:m}=await U();s.errors=b,_=m}else await j(a);P(s.errors,"root"),G(s.errors)?(p.state.next({errors:{}}),await l(_,f)):(c&&await c({...s.errors},f),tt(),setTimeout(tt)),p.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:G(s.errors),submitCount:s.submitCount+1,errors:s.errors})},Jt=(l,c={})=>{w(a,l)&&(R(c.defaultValue)?ae(l,w(o,l)):(ae(l,c.defaultValue),I(o,l,c.defaultValue)),c.keepTouched||P(s.touchedFields,l),c.keepDirty||(P(s.dirtyFields,l),s.isDirty=c.defaultValue?T(l,w(o,l)):T()),c.keepError||(P(s.errors,l),v.isValid&&g()),p.state.next({...s}))},nt=(l,c={})=>{const f=l?ee(l):o,_=ee(f),b=l&&!G(l)?_:o;if(c.keepDefaultValues||(o=f),!c.keepValues){if(c.keepDirtyValues||k)for(const m of d.mount)w(s.dirtyFields,m)?I(b,m,w(i,m)):ae(m,w(b,m));else{if(He&&R(l))for(const m of d.mount){const C=w(a,m);if(C&&C._f){const M=Array.isArray(C._f.refs)?C._f.refs[0]:C._f.ref;if(Ee(M)){const D=M.closest("form");if(D){D.reset();break}}}}a={}}i=e.shouldUnregister?c.keepDefaultValues?ee(o):{}:ee(b),p.array.next({values:{...b}}),p.values.next({values:{...b}})}d={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!u.mount&&r(),u.mount=!v.isValid||!!c.keepIsValid,u.watch=!!e.shouldUnregister,p.state.next({submitCount:c.keepSubmitCount?s.submitCount:0,isDirty:c.keepDirty?s.isDirty:!!(c.keepDefaultValues&&!oe(l,o)),isSubmitted:c.keepIsSubmitted?s.isSubmitted:!1,dirtyFields:c.keepDirtyValues?s.dirtyFields:c.keepDefaultValues&&l?je(o,l):{},touchedFields:c.keepTouched?s.touchedFields:{},errors:c.keepErrors?s.errors:{},isSubmitSuccessful:c.keepIsSubmitSuccessful?s.isSubmitSuccessful:!1,isSubmitting:!1})},st=(l,c)=>nt(ne(l)?l(i):l,c);return{control:{register:Re,unregister:Ne,getFieldState:Ye,handleSubmit:rt,setError:Qe,_executeSchema:U,_getWatch:N,_getDirty:T,_updateValid:g,_removeUnmounted:V,_updateFieldArray:O,_updateDisabledField:et,_getFieldArray:q,_reset:nt,_resetDefaultValues:()=>ne(n.defaultValues)&&n.defaultValues().then(l=>{st(l,n.resetOptions),p.state.next({isLoading:!1})}),_updateFormState:l=>{s={...s,...l}},_disableForm:Wt,_subjects:p,_proxyFormState:v,get _fields(){return a},get _formValues(){return i},get _state(){return u},set _state(l){u=l},get _defaultValues(){return o},get _names(){return d},set _names(l){d=l},get _formState(){return s},set _formState(l){s=l},get _options(){return n},set _options(l){n={...n,...l}}},trigger:Le,register:Re,handleSubmit:rt,watch:Ht,setValue:ae,getValues:Xe,reset:st,resetField:Jt,clearErrors:Gt,unregister:Ne,setError:Qe,setFocus:(l,c={})=>{const f=w(a,l),_=f&&f._f;if(_){const b=_.refs?_.refs[0]:_.ref;b.focus&&(b.focus(),c.shouldSelect&&b.select())}},getFieldState:Ye}}function Ie(e={}){const r=t.Cn.useRef(),n=t.Cn.useRef(),[s,a]=t.Cn.useState({isDirty:!1,isValidating:!1,isLoading:ne(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:ne(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...un(e,()=>a(i=>({...i}))),formState:s});const o=r.current.control;return o._options=e,Xr({subject:o._subjects.state,next:i=>{Zr(i,o._proxyFormState,o._updateFormState,!0)&&a({...o._formState})}}),t.Cn.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),t.Cn.useEffect(()=>{if(o._proxyFormState.isDirty){const i=o._getDirty();i!==s.isDirty&&o._subjects.state.next({isDirty:i})}},[o,s.isDirty]),t.Cn.useEffect(()=>{e.values&&!oe(e.values,n.current)?(o._reset(e.values,o._options.resetOptions),n.current=e.values):o._resetDefaultValues()},[e.values,o]),t.Cn.useEffect(()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),r.current.formState=Jr(s,o),r.current}var kt=function(e,r,n){if(e&&"reportValidity"in e){var s=w(n,r);e.setCustomValidity(s&&s.message||""),e.reportValidity()}},cn=function(e,r){var n=function(a){var o=r.fields[a];o&&o.ref&&"reportValidity"in o.ref?kt(o.ref,a,e):o.refs&&o.refs.forEach(function(i){return kt(i,a,e)})};for(var s in r.fields)n(s)},dn=function(e,r){r.shouldUseNativeValidation&&cn(e,r);var n={};for(var s in e){var a=w(r.fields,s),o=Object.assign(e[s]||{},{ref:a&&a.ref});if(hn(r.names||Object.keys(e),s)){var i=Object.assign({},fn(w(n,s)));I(i,"root",o),I(n,s,i)}else I(n,s,o)}return n},fn=function(e){return Array.isArray(e)?e.filter(Boolean):[]},hn=function(e,r){return e.some(function(n){return n.startsWith(r+".")})},pn=function(e,r){for(var n={};e.issues.length;){var s=e.issues[0];if(s.path){var a=s.path.map(function(u){return u.key}).join(".");if(n[a]||(n[a]={message:s.message,type:s.validation}),r){var o=n[a].types,i=o&&o[s.validation];n[a]=Bt(a,r,n,s.validation,i?[].concat(i,s.message):s.message)}e.issues.shift()}}return n},Me=function(e,r,n){return n===void 0&&(n={}),function(s,a,o){try{return Promise.resolve(function(i,u){try{var d=function(){function h(v){return{values:n.raw?s:v,errors:{}}}var x=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},r);return n.mode==="sync"?h(t.parse(e,s,x)):Promise.resolve(t.parseAsync(e,s,x)).then(h)}()}catch(h){return u(h)}return d&&d.then?d.then(void 0,u):d}(0,function(i){if(i instanceof t.ValiError)return{values:{},errors:dn(pn(i,!o.shouldUseNativeValidation&&o.criteriaMode==="all"),o)};throw i}))}catch(i){return Promise.reject(i)}}};const St=27,Ct=12,Et=10,mn=t.isSubmissionOfType("enum"),gn=(e,r)=>{const n={min:e.minSelected??0,max:e.maxSelected??e.options.length};return Me(t.object({checked:t.transform(t.record(t.boolean()),s=>Object.entries(s).filter(([a,o])=>o).map(([a,o])=>a),[t.maxLength(n.max,r("validation_multiple_choice_max",{count:n.max})),t.minLength(n.min,r("validation_multiple_choice_min",{count:n.min}))])}))},bn=t.k$1(({option:e,...r},n)=>t.o(t.k,{children:[t.o("input",{class:"peer sr-only h-full",type:"checkbox",...r,ref:n}),t.o("label",{class:"bg-lowest hover:bg-neutral-2 active:outline-neutral-8 ease-expo-out outline-divider text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 peer-focus-visible:ring-accent-9 peer-focus-visible:ring-offset-accent-7 block cursor-pointer select-none rounded-2xl px-3 py-1.5 outline outline-1 ring-0 ring-transparent transition-all selection:bg-transparent peer-focus-visible:ring-4",htmlFor:r.id,children:e.label})]})),At=t.cva("gutter-stable flex w-full flex-1 flex-wrap gap-3 overflow-y-auto rounded-xl p-2.5 pr-4",{variants:{variant:{singleOption:"justify-center",booleanLike:Lt}}}),yn=({input:e,onSubmitSuccess:r})=>{var x,v;const n=e.key?(x=t.store.current$.value.flow)==null?void 0:x.data.submissions[e.key]:void 0,s=(e.config.minSelected===1||e.config.minSelected===void 0)&&e.config.maxSelected===1,a=s&&e.config.options.length===2,{t:o}=t.useTranslation(),{register:i,handleSubmit:u,formState:{errors:d}}=Ie({defaultValues:{checked:s?{}:mn(n)?Object.fromEntries(n.value.map(p=>[p,!0])):{}},resolver:gn(e.config,o)}),h=Ge();return a?t.o("ul",{style:{maxHeight:6.5*St+5*Ct+2*Et},class:At({variant:"booleanLike"}),children:e.config.options.map((p,k)=>t.o("li",{class:"flex-1",children:t.o(Nt,{type:"submit",ref:y=>{y&&k===0&&(h.current=y)},label:p.label,value:"true",onClick:()=>r({type:"enum",value:[p.value]})})},p.value))}):t.o("form",{noValidate:!0,onSubmit:p=>u(k=>{const y=k.checked;r({type:"enum",value:y})})(p),children:[t.o("div",{class:"flex items-center gap-1",children:[t.o("ul",{style:{maxHeight:6.5*St+5*Ct+2*Et},class:At({variant:e.config.options.length===1?"singleOption":void 0}),children:e.config.options.map((p,k)=>{const y=`checked.${p.value}`,{ref:A,...S}=i(y);return t.o("li",{class:"relative",children:t.o(bn,{option:p,autoFocus:k===0,ref:E=>{E&&k===0&&(h.current=E),A(E)},id:y,...S,onClick:s?()=>r({type:"enum",value:[p.value]}):void 0})},p.value)})}),t.o("div",{class:"flex flex-col items-center gap-2 pr-2.5 pt-2.5",children:[s?null:t.o(ie,{}),e.config.minSelected===0&&t.o(le,{type:"button",onClick:()=>r({type:"enum",value:[]})})]})]}),t.o("div",{class:"px-1",children:t.o(fe,{error:(v=d.checked)==null?void 0:v.root})})]})},vn=t.isSubmissionOfType("number"),xn=(e,r)=>{const n=e.min??Number.MIN_SAFE_INTEGER,s=e.max??Number.MAX_SAFE_INTEGER,a=e.decimalCases??0;return Me(t.object({number:t.number(r("validation_number"),[t.minValue(n,r("validation_number_min",{min:n})),t.maxValue(s,r("validation_number_max",{max:s})),t.custom(o=>o===Number(o.toFixed(a)),r("validation_number_decimal_cases",{count:a}))])}))},wn=({input:e,onSubmitSuccess:r})=>{var v;const n=e.config.defaultValue,s=e.key?(v=t.store.current$.value.flow)==null?void 0:v.data.submissions[e.key]:void 0,{t:a}=t.useTranslation(),{register:o,handleSubmit:i,formState:{errors:u}}=Ie({defaultValues:{number:n?Number(n):vn(s)?s.value:void 0},resolver:xn(e.config,a)}),{ref:d,...h}=o("number",{required:!e.config.optional,valueAsNumber:!0}),x=t._$1();return t.y(()=>{x.current&&(x.current.focus(),x.current.select())},[]),t.o("form",{class:"flex flex-col gap-1 p-2.5",onSubmit:i(p=>{p.number!==void 0&&r({type:"number",value:p.number})}),children:[t.o("div",{class:"flex items-center gap-2",children:[t.o("div",{class:"relative min-w-0 flex-grow",children:[t.o("input",{...h,id:"chat-input",autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:p=>{p&&(x.current=p),d(p)},type:"text",min:e.config.min,max:e.config.max,class:ve({optional:e.config.optional,className:"[type=number:-webkit-inner-spin-button] w-full rounded-full [-webkit-outer-spin-button:none]"}),placeholder:e.config.placeholder}),e.config.optional&&t.o(le,{class:"absolute right-0 top-0",onClick:()=>r(null)})]}),t.o(ie,{})]}),t.o(fe,{error:u.number})]})},_n=e=>{if(e==="")return{countryCode:"",phoneNumber:""};const r=Object.entries(Ke).find(a=>e.startsWith(a[1])),n=r?r[1]:"",s=e.replace(n,"");return/^\d+$/.test(s)?{countryCode:n,phoneNumber:s}:{countryCode:"",phoneNumber:""}},kn="44",Sn=/^[0-9 ]+$/,Cn=t.isSubmissionOfType("string"),En=t.isSubmissionOfType("phone"),An=e=>{const r=t.string(e("validation_country_code"),[t.regex(Sn,e("validation_country_code"))]),n=t.transform(t.string(e("validation_phone"),[t.minLength(1,e("validation_phone"))]),s=>s.replace(/[^0-9]/g,""),[]);return Me(t.object({countryCode:r,phoneNumber:n}))},Tn=({input:e,onSubmitSuccess:r})=>{var A;const n=e.key?(A=t.store.current$.value.flow)==null?void 0:A.data.submissions[e.key]:void 0,{t:s}=t.useTranslation(),[a,o]=t.h(),i=Cn(n)?_n(n.value):En(n)?n.value:void 0,{register:u,handleSubmit:d,formState:{errors:h},watch:x}=Ie({defaultValues:{countryCode:(i==null?void 0:i.countryCode)??e.config.defaultValue.countryCode??kn,phoneNumber:(i==null?void 0:i.phoneNumber)??e.config.defaultValue.phoneNumber??""},resolver:An(s)}),{ref:v,...p}=u("phoneNumber",{required:!e.config.optional}),k=t._$1(),y=x("countryCode");return t.y(()=>{k.current&&(k.current.focus(),k.current.select())},[]),t.o("form",{noValidate:!0,class:"flex flex-col gap-1 p-2.5",onSubmit:d(S=>{const E=S.phoneNumber.replace(/[^0-9]/g,""),g=S.countryCode.replace(/[^0-9]/g,"");o(void 0);const F=e.config.minChars??7;if(E.length+g.length<F)return o(s("validation_phone_min_chars",{count:F}));e.config.submissionFormat==="phone"?r({type:"phone",value:{countryCode:g,phoneNumber:E}}):r({type:"string",value:y+S.phoneNumber})}),children:[t.o("div",{class:"flex items-center gap-2",children:[t.o("div",{class:"relative flex min-w-0 flex-1 flex-grow gap-2",children:[t.o("label",{class:"text-neutral-12 bg-lowest hover:bg-neutral-5 placeholder:text-neutral-8 focus-visible:outline-accent-7 focus-within:bg-neutral-5 focus-within:outline-accent-7 outline-divider relative flex h-full cursor-pointer appearance-none items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-l-full border-solid px-3 py-1.5 text-center text-base outline outline-2 transition-all focus-within:outline-none",htmlFor:`isdk_phone_${e.key}`,children:[t.o("span",{children:["+",y]}),t.o("select",{...u("countryCode",{}),id:`isdk_phone_${e.key}`,class:"absolute inset-0 opacity-0",children:Object.entries(Ke).map(([S,E])=>t.o("option",{value:E,children:[S," (+",E,")"]},S))})]}),t.o("input",{...p,id:"chat-input",type:"tel",inputMode:"tel",autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:S=>{S&&(k.current=S),v(S)},class:ve({optional:e.config.optional,className:"min-w-0 flex-1 rounded-r-full"}),placeholder:e.config.placeholder}),e.config.optional&&t.o(le,{class:"absolute bottom-0 right-0 top-0",onClick:()=>r(null)})]}),t.o(ie,{})]}),t.o(fe,{error:h.countryCode||h.phoneNumber||{message:a}})]})},Vn=({input:e,onSubmitSuccess:r})=>t.o("div",{class:"flex flex-col items-center py-3",children:t.o("button",{class:"bg-accent-9 hover:bg-accent-10 active:bg-submit-bg-active hover:border-accent-10 active:border-submit-bg-active border-accent-9 ring-accent-6 focus-visible:outline-accent-8 ring-offset-neutral-1 flex cursor-pointer rounded-full border border-solid px-5 py-3 pr-4 text-white outline-none ring-1 ring-offset-[1.5px] transition-all duration-300 focus-visible:outline-2 active:ring-2 active:ring-offset-2",name:e.key,onClick:()=>{r(null)},children:t.o("span",{class:"flex items-center gap-1.5",children:[t.o("span",{class:"inline-flex items-center text-sm font-medium",children:e.config.label||"Submit"}),t.o("svg",{stroke:"currentColor","stroke-width":"1.5",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.o("path",{d:"M4 8L8 4L12 8"}),t.o("path",{d:"M8 4V13"})]})]})})}),Fn={email:{type:"email",inputMode:"email",formNoValidate:!0},text:{type:"text",inputMode:"text"},url:{type:"url",inputMode:"url",formNoValidate:!0}},In=t.isSubmissionOfType("string"),Mn=(e,r)=>{const n={maxLength:r("validation_max_chars",{count:e.maxChars??999}),minLength:r("validation_min_chars",{count:e.minChars??1})};return Me(t.object({text:{email:t.string(r("validation_email"),[t.email(r("validation_email")),t.minLength(e.minChars??1,n.minLength),t.maxLength(e.maxChars??1/0,n.maxLength)]),text:t.string([t.minLength(e.minChars??1,n.minLength),t.maxLength(e.maxChars??1/0,n.maxLength)]),url:t.string([t.url(r("validation_url")),t.minLength(e.minChars??1,n.minLength),t.maxLength(e.maxChars??1/0,n.maxLength)])}[e.format]}))},Ln=({input:e,onSubmitSuccess:r})=>{var v;const{t:n}=t.useTranslation(),s=e.key?(v=t.store.current$.value.flow)==null?void 0:v.data.submissions[e.key]:void 0,a=e.config.defaultValue,{register:o,handleSubmit:i,formState:{errors:u}}=Ie({defaultValues:{text:a||(In(s)?s.value:"")},resolver:Mn(e.config,n)}),{ref:d,...h}=o("text",{required:!e.config.optional}),x=t._$1();return t.y(()=>{x.current&&(x.current.focus(),x.current.select())},[]),t.o("form",{noValidate:!0,class:"flex flex-col gap-1 p-2.5",onSubmit:i(p=>{r({type:"string",value:p.text})}),children:[t.o("div",{class:"flex items-center gap-2",children:[t.o("div",{class:"relative min-w-0 flex-1",children:[t.o("input",{id:"chat-input",...h,...Fn[e.config.format],autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:p=>{p&&(x.current=p),d(p)},placeholder:e.config.placeholder,class:ve({optional:!!e.config.optional,className:"w-full rounded-full"})}),e.config.optional&&t.o(le,{class:"absolute right-0 top-0",onClick:()=>r(null)})]}),t.o(ie,{})]}),t.o(fe,{error:u.text})]})},Nn={text:Ln,phone:Tn,"multiple-choice":yn,boolean:Or,file:Ur,submit:Vn,address:Lr,number:wn},Rn=({logger:e})=>{var o;const r=(o=t.store.current$.value.flow)==null?void 0:o.data.currentInput,[n,s]=wr(),a=t._$1(null);return t.store.inputHeight$.value=s.height,t.p(()=>{const i=a.current;if(i)return i.addEventListener("transitionstart",$.scrollToEnd.smooth),i.addEventListener("transitioncancel",$.scrollToEnd.smooth),i.addEventListener("transitionend",$.scrollToEnd.smooth),()=>{i.removeEventListener("transitionstart",$.scrollToEnd.smooth),i.removeEventListener("transitioncancel",$.scrollToEnd.smooth),i.removeEventListener("transitionend",$.scrollToEnd.smooth)}},[]),t.o("div",{ref:a,class:"ease-expo-out absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-xl transition-all duration-700 will-change-[height]",style:{height:s.height},children:t.o("div",{ref:n,class:"border-divider flex flex-col justify-end border-t",children:r?(()=>{const i=Nn[r.type];return t.o(i,{logger:e,onSubmitSuccess:$.onSubmitSuccessFn$.value,input:r})})():t.o("div",{class:"flex items-center gap-2 p-2.5",children:[t.o("input",{"aria-hidden":"true",id:"chat-input",class:ve({optional:!1,className:"flex-grow rounded-full"}),disabled:!0}),t.o(ie,{disabled:!0,"aria-hidden":"true",tabIndex:-1})]})})})};var Dn=function(e){return e instanceof RegExp},On=function(r){var n=/[\\^$.*+?()[\]{}|]/g,s=RegExp(n.source);return r&&s.test(r)?r.replace(n,"\\$&"):r},Kt=function(e){return typeof e=="string"},Bn=function(e){var r=[];return e.forEach(function(n){Array.isArray(n)?r=r.concat(n):r.push(n)}),r};function Pn(e,r,n){var s=0,a=0;if(e==="")return e;if(!e||!Kt(e))throw new TypeError("First argument to react-string-replace#replaceString must be a string");var o=r;Dn(o)||(o=new RegExp("("+On(o)+")","gi"));for(var i=e.split(o),u=1,d=i.length;u<d;u+=2){if(i[u]===void 0||i[u-1]===void 0){console.warn("reactStringReplace: Encountered undefined value during string replacement. Your RegExp may not be working the way you expect.");continue}a=i[u].length,s+=i[u-1].length,i[u]=n(i[u],u,s),s+=a}return i}var $n=function(r,n,s){return Array.isArray(r)||(r=[r]),Bn(r.map(function(a){return Kt(a)?Pn(a,n,s):a}))};const be=t.getDefaultExportFromCjs($n),jn=/(\[[^\]]+\]\([^)]+\))/g,zn=/\[([^\]]+)\]\(([^)]+)\)/,qn=/(https?:\/\/[^\s]+)/g,Un=/_(.*?)_/g,Kn=/\*\*(.*?)\*\*/g,Gn=/\\n|\n/g,Tt="text-accent-10 hover:text-accent-11 no-underline underline-offset-2 hover:underline",Hn=e=>{const r=be(e,jn,(i,u)=>{const[,d,h]=i.match(zn)??[];return h?t.o("a",{class:Tt,href:h,children:d??h},h+u):t.o("span",{children:"INVALID LINK"})}),n=be(r,qn,(i,u)=>t.o("a",{class:Tt,href:i,children:i},i+u)),s=be(n,Un,(i,u)=>t.o("em",{children:i},i+u)),a=be(s,Kn,(i,u)=>t.o("strong",{children:i},i+u));return be(a,Gn,(i,u)=>t.o("br",{},`br-${u}`))},Wn=t.cva("select-text max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink min-w-[2rem] py-2 px-3 rounded-[18px] min-h-[36px] break-words relative",{variants:{side:{left:"bg-bubble-weak-bg text-neutral-12 shadow-surface-sm outline outline-1 outline-bubble-weak rounded-bl-md",right:"ml-auto bg-accent-9 text-white rounded-br-md shadow-surface-sm shadow-bubble-strong-shadow"},animate:{true:"animate-bubble-in",false:""}},defaultVariants:{side:"left"}}),Jn=({children:e,className:r,animate:n,side:s,...a})=>t.o("p",{style:{transformOrigin:s==="left"?"0% 50%":"100% 50%"},class:Wn({className:r,side:s,animate:n}),...a,children:e}),Zn=({message:e})=>t.o("div",{class:"bg-accent-3 flex w-full items-center justify-center overflow-hidden rounded-xl px-2 py-2",children:t.o("a",{onClick:e.onClick,class:"bg-lowest shadow-surface-sm ring-accent-6 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 text-wrap-balance flex items-center gap-1.5 rounded-full py-2 pl-4 pr-2.5 text-center no-underline ring-1 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2",target:"_blank",href:e.href,children:[e.text,t.o("svg",{class:"flex-none",width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.o("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"})})]})}),Xn=({className:e,...r})=>(t.p(()=>{$.scrollToEnd.smooth()}),t.o("div",{"aria-hidden":!0,children:$.isBotTyping$.value===!0?t.o("div",{"aria-label":"Typing…",class:t.clsx("flex gap-1 p-4",e),...r,children:Array.from({length:3},(n,s)=>t.o("div",{class:"bg-accent-9 h-1.5 w-1.5 animate-bounce rounded-full",style:{animationDelay:`${-s*200}ms`}}))}):void 0})),Yn={bot:"left",user:"right"},Qn=t.cva("w-full select-none py-2 text-wrap-balance text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_var(--i-color-n-1)]",{variants:{variant:{info:"text-neutral-8",warning:"text-[#FFC107]",error:"text-error-9",success:"text-[#4CAF50]"}}}),es=({lastSentMessageFooter:e})=>{var n;const r=((n=t.store.current$.value.flow)==null?void 0:n.data.messages)??[];return t.p(()=>{$.scrollToEnd.smooth()},[r.length]),t.o("ol",{"aria-label":"Chat messages",class:"mt-auto flex flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",children:[r.map((s,a)=>t.o(t.k,{children:t.o("li",{class:"flex",children:t.N(s).with({type:"system"},o=>t.o("p",{class:Qn({variant:o.variant}),children:o.text})).with({type:"text",author:t._.union("bot","user")},o=>{const i=o.author==="user"&&!r.slice(a+1).some(h=>h.type==="text"&&h.author==="user"),u=a===r.length-1,d=o.author==="bot"?Hn(o.text):o.text;return t.o(Jn,{animate:u,side:Yn[o.author],children:[d,i?e:null]},a)}).with({type:"link"},o=>t.o(Zn,{message:o})).with({type:"image"},o=>t.o("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=>t.o(jr,{class:o.author==="bot"?void 0:"ml-auto",file:{name:o.fileName,sizeKb:o.fileSizeKb}})).with({type:"loading"},o=>{const i=r[r.length-1];return!(o===i)||$.isBotTyping$.value?null:t.o("div",{class:"flex flex-grow flex-col items-center justify-center",children:t.o(t.LoadingIndicator,{class:"text-neutral-6 h-8 w-8"})})}).exhaustive()})},a)),t.o(Xn,{},"typing")]})},ts=({logger:e,apiClient:r,analytics:n})=>{const{flow:s}=t.store.current$.value;t.invariant(s,"Flow is required to exist to show chatbot body");const a=t.store.viewState$.value,{chatRef:o,chatService:i}=Ar(),{t:u}=t.useTranslation(),[d,h]=t.h();return t.y(()=>{a==="maximised"&&$.scrollToEnd.instant()},[a]),t.y(()=>{var S,E;const{state:x,flow:v}=t.store.current$.peek();if(x!=="loaded")throw new Error(u("invalid_state"));let p=v.data.nodeHistory.at(-1);if($.scrollToEnd.instant(),t.store.setInput(void 0),v.data.isFinished)return;p===void 0?(p=t.getHeadOrThrow(s.nodes).id,t.store.setCurrentNodeId(p),n.log({event:"FLOW_START",properties:{flow_id:s.id,flow_version:s.version,flow_session_id:v.data.flowSessionId,flow_build:s.build,job:s.job},customProperties:(S=s.analytics)==null?void 0:S.customProperties})):t.store.removeMessagesSentByNodeIds([p]);const{interpret:k,abort:y,undo:A}=tr({context:s.context,analytics:{service:n,customProperties:(E=s.analytics)==null?void 0:E.customProperties},apiClient:r,logger:e,flow:s,chatService:i,t:u,getSubmissions:()=>{var g;return(g=t.store.current$.peek().flow)==null?void 0:g.data.submissions},onInterpret:(g,F)=>{var L;const O=t.store.current$.peek().flow;t.invariant(O),F&&(O.data.sequence=O.data.sequence+1,n.log({event:"FLOW_NODE",properties:{flow_id:s.id,flow_version:s.version,from_node_id:F.id,flow_build:s.build,to_node_id:g.id,sequence:O.data.sequence,flow_session_id:O.data.flowSessionId,job:s.job},customProperties:(L=s.analytics)==null?void 0:L.customProperties})),t.store.setCurrentNodeId(g.id)},onFlowEnd:async()=>{var F;t.store.markAsFinished();const g=t.store.current$.peek().flow;t.invariant(g),n.log({event:"FLOW_END",properties:{flow_id:s.id,flow_version:s.version,flow_session_id:g.data.flowSessionId,flow_build:s.build,job:s.job},customProperties:(F=s.analytics)==null?void 0:F.customProperties})}});return h(()=>A),k(p),y},[n,r,i,e,s,u]),t.o(t.k,{children:[t.o("div",{ref:o,className:"hide-scrollbars relative flex w-full max-w-full flex-grow flex-col overflow-y-scroll",style:{WebkitOverflowScrolling:"touch",paddingBottom:t.store.inputHeight$.value},children:t.o(es,{lastSentMessageFooter:s.data.isFinished||!d?null:t.o(ns,{undoFn:d})})}),t.o(Rn,{logger:e})]})},rs=e=>"key"in e.data&&e.data.key?[e.data.key]:"keys"in e.data?Object.values(e.data.keys).filter(r=>typeof r=="string"):[],ns=({undoFn:e})=>{const{t:r}=t.useTranslation();return t.o("div",{class:"absolute bottom-0 right-0 flex w-full translate-y-full justify-end",children:t.o("button",{class:"fr touch-hitbox text-neutral-9 hover:text-neutral-12 rounded-full p-1 text-right text-xs transition-all",onClick:async()=>{const{flow:n}=t.store.current$.peek();t.invariant(n);const{removed:s}=e(n.data.nodeHistory),a=n.data.nodeHistory.splice(-s);a.length!==0&&(t.store.removeMessagesSentByNodeIds(a),t.store.setInput(void 0),a.pop(),a.map(o=>n.nodes.find(i=>i.id===o)).filter(Boolean).flatMap(rs).forEach(o=>delete n.data.submissions[o]),t.store.current$.value={...t.store.current$.value})},children:r("undo")})})};exports.ChatbotBody=ts;