@inploi/plugin-chatbot 4.0.3 → 4.1.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.
- package/cdn/index.js +3 -3
- package/dist/chatbot-body-7fa34af3.cjs +1 -0
- package/dist/{chatbot-body-4157a64b.js → chatbot-body-8b3ebdca.js} +947 -945
- package/dist/chatbot.api.d.ts +0 -11
- package/dist/chatbot.utils.d.ts +0 -1
- package/dist/components/chat-input/chat-input.phone-number.d.ts +0 -1
- package/dist/i18n.d.ts +54 -0
- package/dist/{index-432cb092.js → index-cdef556d.js} +11 -2
- package/dist/index-d8af0361.cjs +5 -0
- package/dist/plugin-chatbot.cjs +1 -1
- package/dist/plugin-chatbot.js +1 -1
- package/package.json +10 -11
- package/dist/chatbot-body-faf3f35a.cjs +0 -1
- package/dist/index-fc252b7c.cjs +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inploi/plugin-chatbot",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/plugin-chatbot.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,22 +15,20 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"lodash": "^4.17.21",
|
|
20
|
-
"react-use-measure": "^2.1.1",
|
|
21
|
-
"@inploi/i18n": "0.1.2"
|
|
22
|
-
},
|
|
18
|
+
"dependencies": {},
|
|
23
19
|
"peerDependencies": {
|
|
24
20
|
"@inploi/sdk": "*",
|
|
25
21
|
"@inploi/plugin-feedback": "*"
|
|
26
22
|
},
|
|
27
23
|
"devDependencies": {
|
|
24
|
+
"react-use-measure": "^2.1.1",
|
|
25
|
+
"lodash": "^4.17.21",
|
|
28
26
|
"@happy-dom/global-registrator": "14.3.6",
|
|
29
27
|
"@hookform/resolvers": "^3.3.2",
|
|
30
28
|
"@preact/preset-vite": "2.5.0",
|
|
31
29
|
"@preact/signals": "1.2.2",
|
|
32
30
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
33
|
-
"@types/bun": "^1.
|
|
31
|
+
"@types/bun": "^1.2.5",
|
|
34
32
|
"@types/culori": "^2.0.4",
|
|
35
33
|
"@types/lodash": "^4.17.7",
|
|
36
34
|
"@types/node": "^20.10.0",
|
|
@@ -38,7 +36,7 @@
|
|
|
38
36
|
"autoprefixer": "^10.4.16",
|
|
39
37
|
"class-variance-authority": "^0.7.0",
|
|
40
38
|
"clsx": "^2.0.0",
|
|
41
|
-
"concurrently": "
|
|
39
|
+
"concurrently": "9.1.2",
|
|
42
40
|
"culori": "^3.3.0",
|
|
43
41
|
"dotenv": "^16.3.1",
|
|
44
42
|
"eslint": "^7.32.0",
|
|
@@ -48,7 +46,7 @@
|
|
|
48
46
|
"idb": "^8.0.0",
|
|
49
47
|
"msw": "^2.0.10",
|
|
50
48
|
"playwright-msw": "^3.0.0",
|
|
51
|
-
"postcss": "
|
|
49
|
+
"postcss": "8.4.33",
|
|
52
50
|
"postcss-nesting": "^12.0.1",
|
|
53
51
|
"preact": "10.16.0",
|
|
54
52
|
"react": "npm:@preact/compat@17.1.2",
|
|
@@ -64,9 +62,10 @@
|
|
|
64
62
|
"vite": "^4.4.5",
|
|
65
63
|
"vite-plugin-dts": "^3.7.0",
|
|
66
64
|
"vite-tsconfig-paths": "^4.2.1",
|
|
67
|
-
"@inploi/
|
|
65
|
+
"@inploi/i18n": "0.1.2",
|
|
66
|
+
"@inploi/core": "1.16.0",
|
|
68
67
|
"@inploi/design-tokens": "0.2.1",
|
|
69
|
-
"@inploi/plugin-feedback": "0.4.
|
|
68
|
+
"@inploi/plugin-feedback": "0.4.3",
|
|
70
69
|
"@inploi/sdk": "1.14.11",
|
|
71
70
|
"eslint-config-custom": "0.1.0",
|
|
72
71
|
"tsconfig": "0.1.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-fc252b7c.cjs");require("@inploi/sdk");const ot=({condition:e,context:r,submissions:n,ifBlock:s})=>{const[a,...i]=e.compareKey.split(".");if(!a)return!1;const o=Vt({context:r,key:a,path:i,submissions:n});if(!o)return!1;switch(o.type){case"address":{const u=t.get(o.value,i.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 o.value!="object"||Array.isArray(o.value))return!1;const u=t.get(o.value,i.join(".")),d={...s,data:{...s.data,compareKey:"_temp"}};switch(typeof u){case"boolean":return be(d,{submissions:{_temp:{value:u,type:"boolean"}},context:r});case"string":return be(d,{submissions:{_temp:{value:u,type:"string"}},context:r});case"number":return be(d,{submissions:{_temp:{value:u,type:"number"}},context:r});case"object":return Array.isArray(u)&&u.every(t.isString)?be(d,{submissions:{_temp:{value:u,type:"enum"}},context:r}):!1}break}case"boolean":{const u=e.compareValue==="true";switch(e.compare){case"equals":return o.value===u;case"notEquals":return o.value!==u}break}case"phone":case"string":{const u=o.type==="phone"?Ve(o.value):o.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 o.value===u;case"notEquals":return o.value!==u;case"greaterThan":return o.value>u;case"greaterThanOrEqualTo":return o.value>=u;case"lessThan":return o.value<u;case"lessThanOrEqualTo":return o.value<=u}}catch{return console.error(`Failed to parse number in if-block ${s.id}`,o.value),!1}break}case"enum":switch(e.compare){case"equals":return o.value.length===1&&o.value[0]===e.compareValue;case"notEquals":return o.value.length===1&&o.value[0]!==e.compareValue;case"contains":return o.value.includes(e.compareValue);case"notContains":return!o.value.includes(e.compareValue)}break}},be=(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 i of s)if(ot({condition:i,context:r,submissions:n,ifBlock:e}))return!0;return!1}else{for(const i of s)if(!ot({condition:i,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,i="")=>{const[o,...u]=a.trim().split("."),d=Vt({key:o,path:u,submissions:n,context:r});if(!d)return i;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():i;case"phone":return Ve(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 i}),It=({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 It({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 i=r.find(u=>u.id===a.branchId);if(!i)return!1;const o=It({node:i,nodes:r,stopWhen:u=>u.id===e.id});return!(!o||o.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:i,chatService:o,onFlowEnd:u,onInterpret:d,t:h})=>{let x=new AbortController;const b={...r.service,log:_=>r.service.log({..._,customProperties:{..._.customProperties,...r.customProperties}})},p=async(_,v)=>{const A=i();d==null||d(_,v);try{await rr({flow:e,analytics:b,logger:n,apiClient:a,context:s,node:_,submissions:A,t:h,chat:{sendMessage:async S=>o.send({groupId:_.id,message:S,signal:x.signal}),userInput:async S=>o.input({input:S,signal:x.signal}),addToSubmissions:o.addToSubmissions},next:S=>{const E=S?e.nodes.find(g=>g.id===S):er({childNode:_,nodes:e.nodes});return E?p(E,_):u==null?void 0:u(_)},end:()=>u==null?void 0:u(_)})}catch(S){if(S instanceof t.AbortedError)return;throw S}};return{interpret:async _=>{const v=e.nodes.find(A=>A.id===_)??t.getHeadOrThrow(e.nodes);return p(v)},undo:_=>{let v=1;const A=e.nodes.find(E=>E.id===_[_.length-1]);for(let E=_.length-2;E>0;E--){const g=_[E],M=e.nodes.find(O=>O.id===g);if(!M||(v++,M.type.startsWith("question-")))break}x.abort(),x=new AbortController;const S=e.nodes.find(E=>E.id===_[_.length-v]);return t.invariant(S,"Undo failed: new start node not found"),p(S,A),{removed:v}},abort:()=>{x.abort()}}},Ve=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 or({...e,node:r});case"add-submission":return ir({...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:i,value:o})=>{var u;return[i,(u=s[o])==null?void 0:u.value]})):void 0}})}catch(i){a.error(i)}finally{e(r.nextId)}}async function ar({next:e,node:r}){e(r.data.targetId)}async function ir({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 or({chat:e,next:r,node:n,logger:s,apiClient:a,submissions:i,analytics:o,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:b,session_id:p}=o.getSessionInfo(),_=await a.fetch("/flow/submit",{method:"POST",body:JSON.stringify({log_submit:!1,integration_id:n.data.integrationId,anonymous_id:b,session_id:p,job:u.job,submissions:t.getFlowSubmissionsPayload(i||{})})}).catch(v=>v);n.data.key&&e.addToSubmissions(n.data.key,{type:"integration",value:_}),t.N(_).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}}))},v=>{o.log({event:"FLOW_SUBMIT",properties:{flow_id:u.id,flow_version:u.version,flow_session_id:u.data.flowSessionId,flow_build:u.build,service:v.service??"INVALID_SERVICE",response:{status:v.status,payload:"data"in v?v.data:v.error.data??null},job:u.job}})}).otherwise(()=>{}),await t.N(_).with(t._.union({ats_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))})},{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 v=>{if(v.redirect!==void 0){await e.sendMessage({type:"text",author:"bot",text:v.redirect.message??d("submission_redirect_message")});try{const A=new URL(v.redirect.redirect_url);b&&!A.searchParams.has("anonymous_id")&&A.searchParams.set("anonymous_id",b),await e.sendMessage({type:"link",href:A.toString(),text:v.redirect.button_text??d("complete_submission"),onClick:()=>{if(!p){s.error("session_id not set, cannot log FLOW_REDIRECT event");return}o.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: ${v.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(t._.union({success:!1,ats_data:t._.select("error",{message:t._.string})},{integration_response:{error:t._.select("error",{message:t._.string})}}),async v=>{var A;s.error(v.error),await e.sendMessage({type:"system",variant:"error",text:((A=v.error)==null?void 0:A.message)||d("submission_failed")}),await h(!1)}).otherwise(async v=>{s.error(v),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(be(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:i}){await e.sendMessage({author:"bot",type:"text",text:Z(n.data.question,{submissions:s,context:a})});const o=n.data.format==="phone"?await e.userInput({key:n.data.key,type:"phone",config:{optional:n.data.optional,placeholder:n.data.placeholder,maxChars:n.data.maxChars,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}});o===null?await e.sendMessage({type:"system",variant:"info",text:i("skipped")}):await e.sendMessage({author:"user",type:"text",text:o.type==="phone"?Ve(o.value):o.value}),r(n.nextId)}async function hr({chat:e,next:r,node:n,submissions:s,context:a,t:i}){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:"number",config:{max:n.data.max,min:n.data.min,optional:n.data.optional,placeholder:n.data.placeholder,decimalCases:n.data.decimalCases}});o===null?await e.sendMessage({type:"system",variant:"info",text:i("skipped")}):await e.sendMessage({author:"user",type:"text",text:o.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 i=await e.userInput({key:n.data.key,type:"phone",config:{minChars:n.data.minChars,maxChars:n.data.maxChars,defaultValue:{countryCode:n.data.defaultCountryCode},placeholder:n.data.placeholder,submissionFormat:"phone",optional:n.data.optional}});i===null?await e.sendMessage({type:"system",variant:"info",text:"Skipped"}):await e.sendMessage({author:"user",type:"text",text:i.type==="phone"?Ve(i.value):i.value}),r(n.nextId)}async function mr({chat:e,next:r,node:n,submissions:s,context:a,t:i}){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:"multiple-choice",config:n.data});o.value.length===0?await e.sendMessage({type:"system",variant:"info",text:i("skipped")}):await e.sendMessage({author:"user",type:"text",text:n.data.options.filter(u=>o.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:i}){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:"boolean",config:{optional:n.data.optional,labels:{true:n.data.trueLabel,false:n.data.falseLabel}}});o===null?await e.sendMessage({type:"system",variant:"info",text:i("skipped")}):await e.sendMessage({author:"user",type:"text",text:o.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 i=Object.values(a.value).filter(o=>o&&o.trim().length>0).join(", ");await e.sendMessage({author:"user",type:"text",text:i})}return r(n.nextId)}async function yr({node:e,chat:r,next:n,submissions:s,context:a,t:i}){await r.sendMessage({author:"bot",type:"text",text:Z(e.data.question,{submissions:s,context:a})});const o=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(o===null)await r.sendMessage({type:"system",variant:"info",text:i("skipped")});else for(const u of o.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 Vt=({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,i,o,u;r==null&&(r=100);function d(){var x=Date.now()-o;x<r&&x>=0?s=setTimeout(d,r-x):(s=null,n||(u=e.apply(i,a),i=a=null))}var h=function(){i=this,a=arguments,o=Date.now();var x=n&&!s;return s||(s=setTimeout(d,r)),x&&(u=e.apply(i,a),i=a=null),u};return h.clear=function(){s&&(clearTimeout(s),s=null)},h.flush=function(){s&&(u=e.apply(i,a),i=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 i=s||(typeof window>"u"?class{}:window.ResizeObserver);if(!i)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[o,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:o}),h=r?typeof r=="number"?r:r.scroll:null,x=r?typeof r=="number"?r:r.resize:null,b=t._$1(!1);t.p(()=>(b.current=!0,()=>void(b.current=!1)));const[p,_,v]=t.F(()=>{const g=()=>{if(!d.current.element)return;const{left:M,top:O,width:L,height:se,bottom:te,right:he,x:U,y:X}=d.current.element.getBoundingClientRect(),j={left:M,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),b.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",v,!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 i(v),d.current.resizeObserver.observe(d.current.element),n&&d.current.scrollContainers&&d.current.scrollContainers.forEach(g=>g.addEventListener("scroll",v,{capture:!0,passive:!0})))}const E=g=>{!g||g===d.current.element||(A(),d.current.element=g,d.current.scrollContainers=Ft(g),S())};return kr(v,!!n),_r(_),t.p(()=>{A(),S()},[n,v,_]),t.p(()=>A,[]),[E,o,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 Ft(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(i=>i==="auto"||i==="scroll")&&r.push(e),[...r,...Ft(e.parentElement)]}const Sr=["x","y","top","bottom","left","right","width","height"],Cr=(e,r)=>Sr.every(n=>e[n]===r[n]),oe=({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:()=>{}}),P={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:i})=>{if(await t.N(s).with({author:"bot",type:"text"},async o=>{if(a!=null&&a.aborted)throw new t.AbortedError;P.isBotTyping$.value=!0;const u=Math.min(Math.max(20,o.text.length),100)*Er;await new Promise(d=>setTimeout(d,u,{signal:a})),P.isBotTyping$.value=!1}).otherwise(async()=>{}),a!=null&&a.aborted)throw new t.AbortedError;t.store.addMessage(s,i)},input:({input:s,signal:a})=>{if(a!=null&&a.aborted)throw new t.AbortedError;return t.store.setInput(s),new Promise(i=>{const o=u=>{if(a!=null&&a.aborted)throw new t.AbortedError;t.store.setInput(void 0),s.key&&t.store.setSubmission(s.key,u),i(u)};P.onSubmitSuccessFn$.value=o})}}),[]);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"},ye=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",Ir="ZzRDWFU0dTZ3SF9aWk9RNGl6QzZaWS5RZmlFak13a0hPbGxXZXlNSGN5RUhObUJ6TXpSV08yUW5OdE5tSTZJU1lpd2lJb1JYYXRObmJ2Tm5iaGhHZWx4V1lpb2pJMUp5ZS5rcA==",Vr=e=>atob(e).split("").reverse().join(""),Y=t.object({name:t.string()}),Fr=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 i=new URL(Tr);i.searchParams.set("q",a),i.searchParams.set("session_token",n),i.searchParams.set("access_token",Vr(Ir));const o=await fetch(i);if(!o.ok)return e.error("Failed to get address details",o),{ok:!1,error:r("address_error")};const u=t.safeParse(Fr,await o.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,b,p,_,v,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)??((b=h.context.street)==null?void 0:b.name),line2:void 0,line3:((p=h.context.neighborhood)==null?void 0:p.name)??((_=h.context.locality)==null?void 0:_.name),city:((v=h.context.place)==null?void 0:v.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,i]=t.h(),[o,u]=t.h([]),{enabled:d,getPredictions:h}=Mr({logger:n,t:s}),[x,b]=t.h(d?"query":"manual"),[p,_]=t.h(""),[v,A]=t.h(),S=E=>{t.invariant(d,"Query state should not be enabled"),E=E.trim(),E!==(p==null?void 0:p.trim())&&(_(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===""){i(void 0),b("manual");return}const g=o.find(M=>M.id===E);g&&(i(g.address),b("details"))},onAddressSearch:E=>{S(E)},suggestions:o,query:p,error:v});case"details":return t.invariant(a!==void 0),t.o(dt,{input:e,logger:n,onSubmitSuccess:r,addressFields:a,actions:t.o(ut,{onClick:()=>{b("query")}})});case"manual":return t.o(dt,{logger:n,input:e,onSubmitSuccess:r,addressFields:{},actions:d?t.o(ut,{onClick:()=>{b("query")}}):void 0})}},Nr=({input:e,onSkip:r,suggestions:n,onAddressSelect:s,query:a,onAddressSearch:i,error:o})=>{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 b=new FormData(h.currentTarget).get("address");typeof b=="string"&&i(b)},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:ye({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})]}),o?t.o(fe,{error:{message:o}}):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 i=Object.keys(Ke),{t:o}=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:o(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&&!i.includes(e.country)?t.o("option",{value:e[u],children:e[u]}):t.o("option",{value:"",children:o("select_country")}),i.map(b=>t.o("option",{value:b,children:b},b))]}),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(oe,{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"],Dr=t.picklist(Mt),Rr="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,i=t.parse(Dr,a);r({type:"boolean",value:i==="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:Rr,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}),$r=e=>e.reduce((r,n)=>r+n.sizeKb,0),Pr=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}),Dt=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(Dt(s.name).toLowerCase()))},qr=(e,r)=>{const n=Dt(e);return`${e.replace(new RegExp(`${n}$`),"").slice(0,r)}${n}`},Ur=({input:e,onSubmitSuccess:r})=>{var b;const n=(b=t.store.current$.value.flow)==null?void 0:b.data.submissions[e.key],[s,a]=t.h(Pr(n)?n.value:[]),[i,o]=t.h(),u=s.length-ft,d=$r(s),h=Ge(),{t:x}=t.useTranslation();return t.o("form",{class:"flex flex-col gap-1 p-2.5",onSubmit:p=>(p.preventDefault(),o(void 0),s.length===0?o({type:"required",message:x("validation_file")}):e.config.extensions.length>0&&!zr({allowedExtensions:e.config.extensions,files:s})?o({type:"validate",message:`${x("validation_file_ext",{ext:e.config.extensions.join(", ")})}`}):e.config.fileSizeLimitKib&&d>e.config.fileSizeLimitKib?o({type:"max",message:`File size exceeds limit of ${t.kbToReadableSize(e.config.fileSizeLimitKib)}`}):e.config.allowMultiple===!1&&s.length>1?o({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 _=p.name.split(".").pop(),v=p.name.replace(new RegExp(`.${_}$`),"");return t.o(ht,{class:"flex overflow-hidden",children:[t.o("span",{class:"block truncate",children:v}),t.o("span",{children:[".",_]})]})}),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 _=p.target.files?Array.from(p.target.files):[],v=await Promise.allSettled(_.map(async S=>{const E=await Br(S);return{name:qr(S.name,42),data:E,sizeKb:S.size/1e3}}));if(v.some(({status:S})=>S==="rejected"))return o({type:"invalid",message:"Invalid file"});const A=v.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(oe,{disabled:s.length===0}),e.config.optional&&t.o(le,{onClick:()=>r(null)})]})]}),t.o(fe,{error:i})]})};var ve=e=>e.type==="checkbox",de=e=>e instanceof Date,z=e=>e==null;const Rt=e=>typeof e=="object";var B=e=>!z(e)&&!Array.isArray(e)&&Rt(e)&&!de(e),Kr=e=>B(e)&&e.target?ve(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 xe=e=>Array.isArray(e)?e.filter(Boolean):[],D=e=>e===void 0,w=(e,r,n)=>{if(!r||!B(e))return n;const s=xe(r.split(/[,[\].]+?/)).reduce((a,i)=>z(a)?a:a[i],e);return D(s)||s===e?D(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 i in e)Object.defineProperty(a,i,{get:()=>{const o=i;return r._proxyFormState[o]!==H.all&&(r._proxyFormState[o]=!s||H.all),n&&(n[o]=!0),e[o]}});return a},G=e=>B(e)&&!Object.keys(e).length,Zr=(e,r,n,s)=>{n(e);const{name:a,...i}=e;return G(i)||Object.keys(i).length>=Object.keys(r).length||Object.keys(i).find(o=>r[o]===(!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(i=>(s&&r.watch.add(i),w(n,i))):(s&&(r.watchAll=!0),n),We=e=>/^\w*$/.test(e),Ot=e=>xe(e.replace(/["|']|\]/g,"").split(/\.|\[/));function V(e,r,n){let s=-1;const a=We(r)?[r]:Ot(r),i=a.length,o=i-1;for(;++s<i;){const u=a[s];let d=n;if(s!==o){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 i=w(e,a);if(i){const{_f:o,...u}=i;if(o){if(o.refs&&o.refs[0]&&r(o.refs[0],a)&&!s)break;if(o.ref&&r(o.ref,o.name)&&!s)break}else B(u)&&Se(u,r)}}};var Qr=(e,r,n)=>{const s=xe(w(e,n));return V(s,"root",r[n]),V(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 $t=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&&!D(e[0].attributes.value)?D(e[0].value)||e[0].value===""?yt:{value:e[0].value,isValid:!0}:yt:bt}return bt};const vt={isValid:!1,value:null};var Pt=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:i,refs:o,required:u,maxLength:d,minLength:h,min:x,max:b,pattern:p,validate:_,name:v,valueAsNumber:A,mount:S,disabled:E}=e._f,g=w(r,v);if(!S||E)return{};const M=o?o[0]:i,O=I=>{s&&M.reportValidity&&(M.setCustomValidity(re(I)?"":I||""),M.reportValidity())},L={},se=Ze(i),te=ve(i),he=se||te,U=(A||Je(i))&&D(i.value)&&D(g)||Ee(i)&&i.value===""||g===""||Array.isArray(g)&&!g.length,X=Bt.bind(null,v,n,L),j=(I,T,N,q=Q.maxLength,K=Q.minLength)=>{const W=I?T:N;L[v]={type:I?q:K,message:W,ref:i,...X(I?q:K,W)}};if(a?!Array.isArray(g)||!g.length:u&&(!he&&(U||z(g))||re(g)&&!g||te&&!$t(o).isValid||se&&!Pt(o).isValid)){const{value:I,message:T}=Ce(u)?{value:!!u,message:u}:ce(u);if(I&&(L[v]={type:Q.required,message:T,ref:M,...X(Q.required,T)},!n))return O(T),L}if(!U&&(!z(x)||!z(b))){let I,T;const N=ce(b),q=ce(x);if(!z(g)&&!isNaN(g)){const K=i.valueAsNumber||g&&+g;z(N.value)||(I=K>N.value),z(q.value)||(T=K<q.value)}else{const K=i.valueAsDate||new Date(g),W=we=>new Date(new Date().toDateString()+" "+we),ae=i.type=="time",pe=i.type=="week";J(N.value)&&g&&(I=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((I||T)&&(j(!!I,N.message,q.message,Q.max,Q.min),!n))return O(L[v].message),L}if((d||h)&&!U&&(J(g)||a&&Array.isArray(g))){const I=ce(d),T=ce(h),N=!z(I.value)&&g.length>+I.value,q=!z(T.value)&&g.length<+T.value;if((N||q)&&(j(N,I.message,T.message),!n))return O(L[v].message),L}if(p&&!U&&J(g)){const{value:I,message:T}=ce(p);if(Ae(I)&&!g.match(I)&&(L[v]={type:Q.pattern,message:T,ref:i,...X(Q.pattern,T)},!n))return O(T),L}if(_){if(ne(_)){const I=await _(g,r),T=xt(I,M);if(T&&(L[v]={...T,...X(Q.validate,T.message)},!n))return O(T.message),L}else if(B(_)){let I={};for(const T in _){if(!G(I)&&!n)break;const N=xt(await _[T](g,r),M,T);N&&(I={...N,...X(T,N.message)},O(N.message),n&&(L[v]=I))}if(!G(I)&&(L[v]={ref:M,...I},!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=D(e)?s++:e[r[s++]];return e}function tn(e){for(const r in e)if(e.hasOwnProperty(r)&&!D(e[r]))return!1;return!0}function $(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,i=n[a];return s&&delete s[i],a!==0&&(B(s)&&G(s)||Array.isArray(s)&&tn(s))&&$(e,n.slice(0,-1)),e}function $e(){let e=[];return{get observers(){return e},next:a=>{for(const i of e)i.next&&i.next(a)},subscribe:a=>(e.push(a),{unsubscribe:()=>{e=e.filter(i=>i!==a)}}),unsubscribe:()=>{e=[]}}}var Te=e=>z(e)||!Rt(e);function ie(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 i=e[a];if(!s.includes(a))return!1;if(a!=="ref"){const o=r[a];if(de(i)&&de(o)||B(i)&&B(o)||Array.isArray(i)&&Array.isArray(o)?!ie(i,o):i!==o)return!1}}return!0}var jt=e=>e.type==="select-multiple",rn=e=>Ze(e)||ve(e),Pe=e=>Ee(e)&&e.isConnected,zt=e=>{for(const r in e)if(ne(e[r]))return!0;return!1};function Ie(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])?[]:{},Ie(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])?D(r)||Te(n[a])?n[a]=Array.isArray(e[a])?Ie(e[a],[]):{...Ie(e[a])}:qt(e[a],z(r)?{}:r[a],n[a]):n[a]=!ie(e[a],r[a]);return n}var je=(e,r)=>qt(e,r,Ie(r)),Ut=(e,{valueAsNumber:r,valueAsDate:n,setValueAs:s})=>D(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)?Pt(e.refs).value:jt(r)?[...r.selectedOptions].map(({value:n})=>n):ve(r)?$t(e.refs).value:Ut(D(r.value)?e.ref.value:r.value,e)}var nn=(e,r,n,s)=>{const a={};for(const i of e){const o=w(r,i);o&&V(a,i,o._f)}return{criteriaMode:n,names:[...e],fields:a,shouldUseNativeValidation:s}},ge=e=>D(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 i=a.join("."),o=w(r,i),u=w(e,i);if(o&&!Array.isArray(o)&&n!==i)return{name:n};if(u&&u.type)return{name:i,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)=>!xe(w(e,r)).length&&$(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={},i=B(n.defaultValues)||B(n.values)?ee(n.defaultValues||n.values)||{}:{},o=n.shouldUnregister?{}:ee(i),u={action:!1,mount:!1,watch:!1},d={mount:new Set,unMount:new Set,array:new Set,watch:new Set},h,x=0;const b={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},p={values:$e(),array:$e(),state:$e()},_=e.resetOptions&&e.resetOptions.keepDirtyValues,v=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(b.isValid||l){const c=n.resolver?G((await U()).errors):await j(a,!0);c!==s.isValid&&p.state.next({isValid:c})}},M=l=>b.isValidating&&p.state.next({isValidating:l}),O=(l,c=[],f,k,y=!0,m=!0)=>{if(k&&f){if(u.action=!0,m&&Array.isArray(w(a,l))){const C=f(w(a,l),k.argA,k.argB);y&&V(a,l,C)}if(m&&Array.isArray(w(s.errors,l))){const C=f(w(s.errors,l),k.argA,k.argB);y&&V(s.errors,l,C),on(s.errors,l)}if(b.touchedFields&&m&&Array.isArray(w(s.touchedFields,l))){const C=f(w(s.touchedFields,l),k.argA,k.argB);y&&V(s.touchedFields,l,C)}b.dirtyFields&&(s.dirtyFields=je(i,o)),p.state.next({name:l,isDirty:T(l,c),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else V(o,l,c)},L=(l,c)=>{V(s.errors,l,c),p.state.next({errors:s.errors})},se=(l,c,f,k)=>{const y=w(a,l);if(y){const m=w(o,l,D(f)?w(i,l):f);D(m)||k&&k.defaultChecked||c?V(o,l,c?m:ze(y._f)):K(l,m),u.mount&&g()}},te=(l,c,f,k,y)=>{let m=!1,C=!1;const F={name:l};if(!f||k){b.isDirty&&(C=s.isDirty,s.isDirty=F.isDirty=T(),m=C!==F.isDirty);const R=ie(w(i,l),c);C=w(s.dirtyFields,l),R?$(s.dirtyFields,l):V(s.dirtyFields,l,!0),F.dirtyFields=s.dirtyFields,m=m||b.dirtyFields&&C!==!R}if(f){const R=w(s.touchedFields,l);R||(V(s.touchedFields,l,f),F.touchedFields=s.touchedFields,m=m||b.touchedFields&&R!==f)}return m&&y&&p.state.next(F),m?F:{}},he=(l,c,f,k)=>{const y=w(s.errors,l),m=b.isValid&&re(c)&&s.isValid!==c;if(e.delayError&&f?(h=E(()=>L(l,f)),h(e.delayError)):(clearTimeout(x),h=null,f?V(s.errors,l,f):$(s.errors,l)),(f?!ie(y,f):y)||!G(k)||m){const C={...k,...m&&re(c)?{isValid:c}:{},errors:s.errors,name:l};s={...s,...C},p.state.next(C)}M(!1)},U=async l=>n.resolver(o,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 k=w(c,f);k?V(s.errors,f,k):$(s.errors,f)}else s.errors=c;return c},j=async(l,c,f={valid:!0})=>{for(const k in l){const y=l[k];if(y){const{_f:m,...C}=y;if(m){const F=d.array.has(m.name),R=await wt(y,o,S,n.shouldUseNativeValidation&&!c,F);if(R[m.name]&&(f.valid=!1,c))break;!c&&(w(R,m.name)?F?Qr(s.errors,R,m.name):V(s.errors,m.name,R[m.name]):$(s.errors,m.name))}C&&await j(C,c,f)}}return f.valid},I=()=>{for(const l of d.unMount){const c=w(a,l);c&&(c._f.refs?c._f.refs.every(f=>!Pe(f)):!Pe(c._f.ref))&&Ne(l)}d.unMount=new Set},T=(l,c)=>(l&&c&&V(o,l,c),!ie(Xe(),i)),N=(l,c,f)=>Yr(l,d,{...u.mount?o:D(c)?i:J(l)?{[l]:c}:c},f,c),q=l=>xe(w(u.mount?o:i,l,e.shouldUnregister?w(i,l,[]):[])),K=(l,c,f={})=>{const k=w(a,l);let y=c;if(k){const m=k._f;m&&(!m.disabled&&V(o,l,Ut(c,m)),y=Ee(m.ref)&&z(c)?"":c,jt(m.ref)?[...m.ref.options].forEach(C=>C.selected=y.includes(C.value)):m.refs?ve(m.ref)?m.refs.length>1?m.refs.forEach(C=>(!C.defaultChecked||!C.disabled)&&(C.checked=Array.isArray(y)?!!y.find(F=>F===C.value):y===C.value)):m.refs[0]&&(m.refs[0].checked=!!y):m.refs.forEach(C=>C.checked=C.value===y):Je(m.ref)?m.ref.value="":(m.ref.value=y,m.ref.type||p.values.next({name:l,values:{...o}})))}(f.shouldDirty||f.shouldTouch)&&te(l,y,f.shouldTouch,f.shouldDirty,!0),f.shouldValidate&&Le(l)},W=(l,c,f)=>{for(const k in c){const y=c[k],m=`${l}.${k}`,C=w(a,m);(d.array.has(l)||!Te(y)||C&&!C._f)&&!de(y)?W(m,y,f):K(m,y,f)}},ae=(l,c,f={})=>{const k=w(a,l),y=d.array.has(l),m=ee(c);V(o,l,m),y?(p.array.next({name:l,values:{...o}}),(b.isDirty||b.dirtyFields)&&f.shouldDirty&&p.state.next({name:l,dirtyFields:je(i,o),isDirty:T(l,m)})):k&&!k._f&&!z(m)?W(l,m,f):K(l,m,f),gt(l,d)&&p.state.next({...s}),p.values.next({name:l,values:{...o}}),!u.mount&&r()},pe=async l=>{const c=l.target;let f=c.name,k=!0;const y=w(a,f),m=()=>c.type?ze(y._f):Kr(l),C=F=>{k=Number.isNaN(F)||F===w(o,f,F)};if(y){let F,R;const _e=m(),ue=l.type===pt.BLUR||l.type===pt.FOCUS_OUT,Zt=!sn(y._f)&&!n.resolver&&!w(s.errors,f)&&!y._f.deps||an(ue,w(s.touchedFields,f),s.isSubmitted,A,v),Re=gt(f,d,ue);V(o,f,_e),ue?(y._f.onBlur&&y._f.onBlur(l),h&&h(0)):y._f.onChange&&y._f.onChange(l);const Oe=te(f,_e,ue,!1),Xt=!G(Oe)||Re;if(!ue&&p.values.next({name:f,type:l.type,values:{...o}}),Zt)return b.isValid&&g(),Xt&&p.state.next({name:f,...Re?{}:Oe});if(!ue&&Re&&p.state.next({...s}),M(!0),n.resolver){const{errors:at}=await U([f]);if(C(_e),k){const Yt=_t(s.errors,a,f),it=_t(at,a,Yt.name||f);F=it.error,f=it.name,R=G(at)}}else F=(await wt(y,o,S,n.shouldUseNativeValidation))[f],C(_e),k&&(F?R=!1:b.isValid&&(R=await j(a,!0)));k&&(y._f.deps&&Le(y._f.deps),he(f,R,F,Oe))}},we=(l,c)=>{if(w(s.errors,c)&&l.focus)return l.focus(),1},Le=async(l,c={})=>{let f,k;const y=Be(l);if(M(!0),n.resolver){const m=await X(D(l)?l:y);f=G(m),k=l?!y.some(C=>w(m,C)):f}else l?(k=(await Promise.all(y.map(async m=>{const C=w(a,m);return await j(C&&C._f?{[m]:C}:C)}))).every(Boolean),!(!k&&!s.isValid)&&g()):k=f=await j(a);return p.state.next({...!J(l)||b.isValid&&f!==s.isValid?{}:{name:l},...n.resolver||!l?{isValid:f}:{},errors:s.errors,isValidating:!1}),c.shouldFocus&&!k&&Se(a,we,l?y:d.mount),k},Xe=l=>{const c={...i,...u.mount?o:{}};return D(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=>$(s.errors,c)),p.state.next({errors:l?s.errors:{}})},Qe=(l,c,f)=>{const k=(w(a,l,{_f:{}})._f||{}).ref;V(s.errors,l,{...c,ref:k}),p.state.next({name:l,errors:s.errors,isValid:!1}),f&&f.shouldFocus&&k&&k.focus&&k.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||($(a,f),$(o,f)),!c.keepError&&$(s.errors,f),!c.keepDirty&&$(s.dirtyFields,f),!c.keepTouched&&$(s.touchedFields,f),!n.shouldUnregister&&!c.keepDefaultValue&&$(i,f);p.values.next({values:{...o}}),p.state.next({...s,...c.keepDirty?{isDirty:T()}:{}}),!c.keepIsValid&&g()},et=({disabled:l,name:c,field:f,fields:k,value:y})=>{if(re(l)){const m=l?void 0:D(y)?ze(f?f._f:w(k,c)._f):y;V(o,c,m),te(c,m,!1,!1,!0)}},De=(l,c={})=>{let f=w(a,l);const k=re(c.disabled);return V(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),{...k?{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:y=>{if(y){De(l,c),f=w(a,l);const m=D(y.value)&&y.querySelectorAll&&y.querySelectorAll("input,select,textarea")[0]||y,C=rn(m),F=f._f.refs||[];if(C?F.find(R=>R===m):m===f._f.ref)return;V(a,l,{_f:{...f._f,...C?{refs:[...F.filter(Pe),m,...Array.isArray(w(i,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,we,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 k=ee(o);if(p.state.next({isSubmitting:!0}),n.resolver){const{errors:y,values:m}=await U();s.errors=y,k=m}else await j(a);$(s.errors,"root"),G(s.errors)?(p.state.next({errors:{}}),await l(k,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)&&(D(c.defaultValue)?ae(l,w(i,l)):(ae(l,c.defaultValue),V(i,l,c.defaultValue)),c.keepTouched||$(s.touchedFields,l),c.keepDirty||($(s.dirtyFields,l),s.isDirty=c.defaultValue?T(l,w(i,l)):T()),c.keepError||($(s.errors,l),b.isValid&&g()),p.state.next({...s}))},nt=(l,c={})=>{const f=l?ee(l):i,k=ee(f),y=l&&!G(l)?k:i;if(c.keepDefaultValues||(i=f),!c.keepValues){if(c.keepDirtyValues||_)for(const m of d.mount)w(s.dirtyFields,m)?V(y,m,w(o,m)):ae(m,w(y,m));else{if(He&&D(l))for(const m of d.mount){const C=w(a,m);if(C&&C._f){const F=Array.isArray(C._f.refs)?C._f.refs[0]:C._f.ref;if(Ee(F)){const R=F.closest("form");if(R){R.reset();break}}}}a={}}o=e.shouldUnregister?c.keepDefaultValues?ee(i):{}:ee(y),p.array.next({values:{...y}}),p.values.next({values:{...y}})}d={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!u.mount&&r(),u.mount=!b.isValid||!!c.keepIsValid,u.watch=!!e.shouldUnregister,p.state.next({submitCount:c.keepSubmitCount?s.submitCount:0,isDirty:c.keepDirty?s.isDirty:!!(c.keepDefaultValues&&!ie(l,i)),isSubmitted:c.keepIsSubmitted?s.isSubmitted:!1,dirtyFields:c.keepDirtyValues?s.dirtyFields:c.keepDefaultValues&&l?je(i,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(o):l,c);return{control:{register:De,unregister:Ne,getFieldState:Ye,handleSubmit:rt,setError:Qe,_executeSchema:U,_getWatch:N,_getDirty:T,_updateValid:g,_removeUnmounted:I,_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:b,get _fields(){return a},get _formValues(){return o},get _state(){return u},set _state(l){u=l},get _defaultValues(){return i},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:De,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),k=f&&f._f;if(k){const y=k.refs?k.refs[0]:k.ref;y.focus&&(y.focus(),c.shouldSelect&&y.select())}},getFieldState:Ye}}function Fe(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(o=>({...o}))),formState:s});const i=r.current.control;return i._options=e,Xr({subject:i._subjects.state,next:o=>{Zr(o,i._proxyFormState,i._updateFormState,!0)&&a({...i._formState})}}),t.Cn.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),t.Cn.useEffect(()=>{if(i._proxyFormState.isDirty){const o=i._getDirty();o!==s.isDirty&&i._subjects.state.next({isDirty:o})}},[i,s.isDirty]),t.Cn.useEffect(()=>{e.values&&!ie(e.values,n.current)?(i._reset(e.values,i._options.resetOptions),n.current=e.values):i._resetDefaultValues()},[e.values,i]),t.Cn.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()}),r.current.formState=Jr(s,i),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 i=r.fields[a];i&&i.ref&&"reportValidity"in i.ref?kt(i.ref,a,e):i.refs&&i.refs.forEach(function(o){return kt(o,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),i=Object.assign(e[s]||{},{ref:a&&a.ref});if(hn(r.names||Object.keys(e),s)){var o=Object.assign({},fn(w(n,s)));V(o,"root",i),V(n,s,o)}else V(n,s,i)}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 i=n[a].types,o=i&&i[s.validation];n[a]=Bt(a,r,n,s.validation,o?[].concat(o,s.message):s.message)}e.issues.shift()}}return n},Me=function(e,r,n){return n===void 0&&(n={}),function(s,a,i){try{return Promise.resolve(function(o,u){try{var d=function(){function h(b){return{values:n.raw?s:b,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(o){if(o instanceof t.ValiError)return{values:{},errors:dn(pn(o,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw o}))}catch(o){return Promise.reject(o)}}};const St=27,Ct=12,Et=10,mn=t.isSubmissionOfType("enum"),gn=e=>{const r={min:e.minSelected??0,max:e.maxSelected??e.options.length};return Me(t.object({checked:t.transform(t.record(t.boolean()),n=>Object.entries(n).filter(([s,a])=>a).map(([s,a])=>s),[t.maxLength(r.max,`Please select at most ${r.max} option${r.max!==1?"s":""}`),t.minLength(r.min,`Please select at least ${r.min} option${r.min!==1?"s":""}`)])}))},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 h,x;const n=e.key?(h=t.store.current$.value.flow)==null?void 0:h.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,{register:i,handleSubmit:o,formState:{errors:u}}=Fe({defaultValues:{checked:s?{}:mn(n)?Object.fromEntries(n.value.map(b=>[b,!0])):{}},resolver:gn(e.config)}),d=Ge();return a?t.o("ul",{style:{maxHeight:6.5*St+5*Ct+2*Et},class:At({variant:"booleanLike"}),children:e.config.options.map((b,p)=>t.o("li",{class:"flex-1",children:t.o(Nt,{type:"submit",ref:_=>{_&&p===0&&(d.current=_)},label:b.label,value:"true",onClick:()=>r({type:"enum",value:[b.value]})})},b.value))}):t.o("form",{noValidate:!0,onSubmit:b=>o(p=>{const _=p.checked;r({type:"enum",value:_})})(b),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((b,p)=>{const _=`checked.${b.value}`,{ref:v,...A}=i(_);return t.o("li",{class:"relative",children:t.o(bn,{option:b,autoFocus:p===0,ref:S=>{S&&p===0&&(d.current=S),v(S)},id:_,...A,onClick:s?()=>r({type:"enum",value:[b.value]}):void 0})},b.value)})}),t.o("div",{class:"flex flex-col items-center gap-2 pr-2.5 pt-2.5",children:[s?null:t.o(oe,{}),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:(x=u.checked)==null?void 0:x.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(i=>i===Number(i.toFixed(a)),r("validation_number_decimal_cases",{count:a}))])}))},wn=({input:e,onSubmitSuccess:r})=>{var b;const n=e.config.defaultValue,s=e.key?(b=t.store.current$.value.flow)==null?void 0:b.data.submissions[e.key]:void 0,{t:a}=t.useTranslation(),{register:i,handleSubmit:o,formState:{errors:u}}=Fe({defaultValues:{number:n?Number(n):vn(s)?s.value:void 0},resolver:xn(e.config,a)}),{ref:d,...h}=i("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:o(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:ye({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(oe,{})]}),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=t.isSubmissionOfType("string"),Cn=t.isSubmissionOfType("phone"),En=e=>{const r=t.string(e("validation_country_code"),[t.regex(/^\+?[0-9 -]+$/,e("validation_country_code"))]);return Me(t.object({countryCode:r,phoneNumber:t.transform(t.string(e("validation_phone"),[t.regex(/^\+?[0-9 -]+$/,e("validation_phone"))]),n=>n.replace(/[^0-9]/g,""),[])}))},An=({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,i]=t.h(),o=Sn(n)?_n(n.value):Cn(n)?n.value:void 0,{register:u,handleSubmit:d,formState:{errors:h},watch:x}=Fe({defaultValues:{countryCode:(o==null?void 0:o.countryCode)??e.config.defaultValue.countryCode??kn,phoneNumber:(o==null?void 0:o.phoneNumber)??e.config.defaultValue.phoneNumber??""},resolver:En(s)}),{ref:b,...p}=u("phoneNumber",{required:!e.config.optional}),_=t._$1(),v=x("countryCode");return t.y(()=>{_.current&&(_.current.focus(),_.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,"");if(i(void 0),E.length+g.length>(e.config.maxChars||Number.POSITIVE_INFINITY))return i(s("validation_max_chars",{count:e.config.maxChars??999}));if(E.length+g.length<(e.config.minChars||0))return i(s("validation_min_chars",{count:e.config.minChars??1}));e.config.submissionFormat==="phone"?r({type:"phone",value:{countryCode:g,phoneNumber:E}}):r({type:"string",value:v+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:["+",v]}),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&&(_.current=S),b(S)},class:ye({optional:e.config.optional,className:"flex-1 rounded-r-full"}),placeholder:e.config.placeholder}),e.config.optional&&t.o(le,{class:"absolute right-0 top-0",onClick:()=>r(null)})]}),t.o(oe,{})]}),t.o(fe,{error:h.countryCode||h.phoneNumber||{message:a}})]})},Tn=({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"})]})]})})}),In={email:{type:"email",inputMode:"email",formNoValidate:!0},text:{type:"text",inputMode:"text"},url:{type:"url",inputMode:"url",formNoValidate:!0}},Vn=t.isSubmissionOfType("string"),Fn=(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]}))},Mn=({input:e,onSubmitSuccess:r})=>{var b;const{t:n}=t.useTranslation(),s=e.key?(b=t.store.current$.value.flow)==null?void 0:b.data.submissions[e.key]:void 0,a=e.config.defaultValue,{register:i,handleSubmit:o,formState:{errors:u}}=Fe({defaultValues:{text:a||(Vn(s)?s.value:"")},resolver:Fn(e.config,n)}),{ref:d,...h}=i("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:o(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,...In[e.config.format],autocomplete:"off",autoCapitalize:"off",autoCorrect:"off",autoFocus:!0,ref:p=>{p&&(x.current=p),d(p)},placeholder:e.config.placeholder,class:ye({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(oe,{})]}),t.o(fe,{error:u.text})]})},Ln={text:Mn,phone:An,"multiple-choice":yn,boolean:Or,file:Ur,submit:Tn,address:Lr,number:wn},Nn=({logger:e})=>{var i;const r=(i=t.store.current$.value.flow)==null?void 0:i.data.currentInput,[n,s]=wr(),a=t._$1(null);return t.store.inputHeight$.value=s.height,t.p(()=>{const o=a.current;if(o)return o.addEventListener("transitionstart",P.scrollToEnd.smooth),o.addEventListener("transitioncancel",P.scrollToEnd.smooth),o.addEventListener("transitionend",P.scrollToEnd.smooth),()=>{o.removeEventListener("transitionstart",P.scrollToEnd.smooth),o.removeEventListener("transitioncancel",P.scrollToEnd.smooth),o.removeEventListener("transitionend",P.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 o=Ln[r.type];return t.o(o,{logger:e,onSubmitSuccess:P.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:ye({optional:!1,className:"flex-grow rounded-full"}),disabled:!0}),t.o(oe,{disabled:!0,"aria-hidden":"true",tabIndex:-1})]})})})};var Dn=function(e){return e instanceof RegExp},Rn=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"},On=function(e){var r=[];return e.forEach(function(n){Array.isArray(n)?r=r.concat(n):r.push(n)}),r};function Bn(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 i=r;Dn(i)||(i=new RegExp("("+Rn(i)+")","gi"));for(var o=e.split(i),u=1,d=o.length;u<d;u+=2){if(o[u]===void 0||o[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=o[u].length,s+=o[u-1].length,o[u]=n(o[u],u,s),s+=a}return o}var $n=function(r,n,s){return Array.isArray(r)||(r=[r]),On(r.map(function(a){return Kt(a)?Bn(a,n,s):a}))};const ke=t.getDefaultExportFromCjs($n),Pn=/(\[[^\]]+\]\([^)]+\))/g,jn=/\[([^\]]+)\]\(([^)]+)\)/,zn=/(https?:\/\/[^\s]+)/g,qn=/_(.*?)_/g,Un=/\*\*(.*?)\*\*/g,Tt="text-accent-10 hover:text-accent-11 no-underline underline-offset-2 hover:underline",Kn=e=>{const r=ke(e,Pn,(i,o)=>{const[,u,d]=i.match(jn)??[];return d?t.o("a",{class:Tt,href:d,children:u??d},d+o):t.o("span",{children:"INVALID LINK"})}),n=ke(r,zn,(i,o)=>t.o("a",{class:Tt,href:i,children:i},i+o)),s=ke(n,qn,(i,o)=>t.o("em",{children:i},i+o));return ke(s,Un,(i,o)=>t.o("strong",{children:i},i+o))},Gn=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"}}),Hn=({children:e,className:r,animate:n,side:s,...a})=>t.o("p",{style:{transformOrigin:s==="left"?"0% 50%":"100% 50%"},class:Gn({className:r,side:s,animate:n}),...a,children:e}),Wn=({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"})})]})}),Jn=({className:e,...r})=>(t.p(()=>{P.scrollToEnd.smooth()}),t.o("div",{"aria-hidden":!0,children:P.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})),Zn={bot:"left",user:"right"},Xn=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]"}}}),Yn=({lastSentMessageFooter:e})=>{var n;const r=((n=t.store.current$.value.flow)==null?void 0:n.data.messages)??[];return t.p(()=>{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"},i=>t.o("p",{class:Xn({variant:i.variant}),children:i.text})).with({type:"text",author:t._.union("bot","user")},i=>{const o=i.author==="user"&&!r.slice(a+1).some(h=>h.type==="text"&&h.author==="user"),u=a===r.length-1,d=i.author==="bot"?Kn(i.text):i.text;return t.o(Hn,{animate:u,side:Zn[i.author],children:[d,o?e:null]},a)}).with({type:"link"},i=>t.o(Wn,{message:i})).with({type:"image"},i=>t.o("img",{class:"shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",src:i.url,style:{aspectRatio:i.width/i.height}})).with({type:"file"},i=>t.o(jr,{class:i.author==="bot"?void 0:"ml-auto",file:{name:i.fileName,sizeKb:i.fileSizeKb}})).with({type:"loading"},i=>{const o=r[r.length-1];return!(i===o)||P.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(Jn,{},"typing")]})},Qn=({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:i,chatService:o}=Ar(),{t:u}=t.useTranslation(),[d,h]=t.h();return t.y(()=>{a==="maximised"&&P.scrollToEnd.instant()},[a]),t.y(()=>{var S,E;const{state:x,flow:b}=t.store.current$.peek();if(x!=="loaded")throw new Error(u("invalid_state"));let p=b.data.nodeHistory.at(-1);if(P.scrollToEnd.instant(),t.store.setInput(void 0),b.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:b.data.flowSessionId,flow_build:s.build,job:s.job},customProperties:(S=s.analytics)==null?void 0:S.customProperties})):t.store.removeMessagesSentByNodeIds([p]);const{interpret:_,abort:v,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:o,t:u,getSubmissions:()=>{var g;return(g=t.store.current$.peek().flow)==null?void 0:g.data.submissions},onInterpret:(g,M)=>{var L;const O=t.store.current$.peek().flow;t.invariant(O),M&&(O.data.sequence=O.data.sequence+1,n.log({event:"FLOW_NODE",properties:{flow_id:s.id,flow_version:s.version,from_node_id:M.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 M;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:(M=s.analytics)==null?void 0:M.customProperties})}});return h(()=>A),_(p),v},[n,r,o,e,s,u]),t.o(t.k,{children:[t.o("div",{ref:i,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(Yn,{lastSentMessageFooter:s.data.isFinished||!d?null:t.o(ts,{undoFn:d})})}),t.o(Nn,{logger:e})]})},es=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"):[],ts=({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(i=>n.nodes.find(o=>o.id===i)).filter(Boolean).flatMap(es).forEach(i=>delete n.data.submissions[i]),t.store.current$.value={...t.store.current$.value})},children:r("undo")})})};exports.ChatbotBody=Qn;
|