@sonata-innovations/fiber-fbre 2.0.3 → 2.0.5

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),x=require("react"),z=require("zustand"),on=require("@sonata-innovations/fiber-types"),M=require("@sonata-innovations/fiber-shared"),sn=new Map,rn=n=>sn.get(n),cn=new Set(["header","text","divider","callout","table"]),pe=n=>cn.has(n),an=(n,s)=>{var o,t,e,r;if(s.includes(":")){const c=s.split(":"),i=n.components[c[0]];return(e=(t=(o=i==null?void 0:i.addedComponents)==null?void 0:o[parseInt(c[1])])==null?void 0:t[parseInt(c[2])])==null?void 0:e.value}return(r=n.components[s])==null?void 0:r.value},_=(n,s)=>{var t;const o=(t=n.properties)==null?void 0:t.validation;return!o||!o.rules||o.rules.length===0?[]:M.validateValue(n.value,o,s?e=>an(s,e):void 0)},ln=n=>{var o;const s=(o=n.properties)==null?void 0:o.validation;return!s||!s.rules?!1:s.rules.some(t=>t.type==="required")},W=n=>{var o,t;const s={...n};return Array.isArray((o=s.properties)==null?void 0:o.options)&&(s.properties={...s.properties,options:on.normalizeOptions(s.properties.options)}),n.type==="computed"?(s.value=null,s.valid=!0):!pe(n.type)&&n.type!=="group"&&n.type!=="repeater"&&(s.value=null,s.valid=!ln(n)),(n.type==="checkbox"||n.type==="dropDownMulti")&&(s.value=[]),n.type==="radio"&&"options"in n.properties&&n.properties.options.length>0&&(s.value=n.properties.options[0].value),n.type==="toggleSwitch"&&(s.value=!1),n.type==="colorPicker"&&((t=n.properties)!=null&&t.defaultValue)&&(s.value=n.properties.defaultValue),n.type==="slider"&&(s.value="initValue"in n.properties?n.properties.initValue:"min"in n.properties?n.properties.min:0),s},se=(n,s,o)=>{var t;for(const e of o.rules)if(e.type==="matchesField"&&((t=e.params)!=null&&t.field)){const r=e.params.field;n[r]||(n[r]=[]),n[r].push({target:s,config:o})}},Z=(n,s)=>{const o=n.screens[s];return o?!o.components.some(e=>{var i;const r=n.components[e.uuid];if(!r)return!1;if(r.type==="group"||r.type==="repeater")return(i=r.addedComponents)==null?void 0:i.some(l=>l.some(a=>{const u=a.conditions&&"when"in a.conditions?a.conditions:void 0;return u&&M.isHiddenByCondition(u,n.conditionResults[a.uuid])?!1:!a.valid}));const c=r.conditions&&"when"in r.conditions?r.conditions:void 0;return M.isHiddenByCondition(c,n.conditionResults[r.uuid])?!1:r&&"valid"in r&&!r.valid}):!0};function un(n){const s={};for(const o of n){const t=M.extractFormulaReferences(o.formula);for(const e of t)s[e]||(s[e]=[]),s[e].includes(o.uuid)||s[e].push(o.uuid)}return s}function qe(n){const s=new Map(n.map(c=>[c.uuid,c])),o=new Set(n.map(c=>c.uuid)),t=new Set,e=[];function r(c,i){if(t.has(c)||i.has(c))return;i.add(c);const l=s.get(c);if(!l)return;const a=M.extractFormulaReferences(l.formula);for(const u of a)o.has(u)&&r(u,i);i.delete(c),t.add(c),e.push(l)}for(const c of n)r(c.uuid,new Set);return e}function He(n,s){return{resolveValue:o=>{if(o in s)return s[o];const t=K(n,o);if(!t)return null;const e=t.value;if(e==null||e==="")return null;const r=Number(e);return isNaN(r)?null:r},resolveOptionMetadata:(o,t)=>{var u;const e=K(n,o);if(!e)return null;const r=e.value;if(!r)return null;const c=(u=e.properties)==null?void 0:u.options;if(!Array.isArray(c))return null;const i=c.find(d=>d.value===r||d.label===r);if(!(i!=null&&i.metadata))return null;const l=i.metadata[t];if(l==null)return null;const a=Number(l);return isNaN(a)?null:a},resolveRepeaterValues:o=>{for(const t of Object.keys(n.components)){const e=n.components[t];if(e.type!=="repeater"||!e.addedComponents||!e.components)continue;const r=e.components.findIndex(i=>i.uuid===o);if(r===-1)continue;const c=[];for(const i of e.addedComponents){const l=i[r];if(!l)continue;const a=l.value;if(a==null||a==="")continue;const u=Number(a);isNaN(u)||c.push(u)}return c.length>0?c:null}return null}}}function be(n){const s=n.calculations??[];if(s.length===0)return{};const o=qe(s),t={},e=He(n,t);for(const r of o)t[r.uuid]=M.evaluateFormula(r.formula,e);return t}function ye(n,s){const o=n.calculationsByDependency,t=n.calculations??[];if(t.length===0||!o)return null;const e=new Set,r=[s];for(;r.length>0;){const u=r.shift(),d=o[u];if(d)for(const m of d)e.has(m)||(e.add(m),r.push(m))}if(e.size===0)return null;const c=qe(t),i={...n.calculationResults},l=He(n,i);let a=!1;for(const u of c)if(e.has(u.uuid)){const d=M.evaluateFormula(u.formula,l);i[u.uuid]!==d&&(i[u.uuid]=d,a=!0)}return a?i:null}function dn(n){const s={},o=t=>{var r;if(t.type!=="computed"||!((r=t.properties)!=null&&r.formula))return;const e=M.extractFormulaReferences(t.properties.formula);for(const c of e)s[c]||(s[c]=[]),s[c].includes(t.uuid)||s[c].push(t.uuid)};for(const t of Object.values(n))if(o(t),(t.type==="repeater"||t.type==="group")&&t.components)for(const e of t.components)o(e);return s}function Ye(n,s,o,t){var l,a;const e=n.components[o],r=((l=e==null?void 0:e.components)==null?void 0:l.map(u=>u.uuid))??[],c=(a=e==null?void 0:e.addedComponents)==null?void 0:a[t],i=new Map;if(c)for(let u=0;u<c.length;u++){const d=r[u];d&&i.set(d,c[u])}return{resolveValue:u=>{if(u in s)return s[u];const d=i.get(u);if(d){const g=d.value;if(g==null||g==="")return null;const h=Number(g);return isNaN(h)?null:h}const m=K(n,u);if(!m)return null;const f=m.value;if(f==null||f==="")return null;const y=Number(f);return isNaN(y)?null:y},resolveOptionMetadata:(u,d)=>{var b;const f=i.get(u)??K(n,u);if(!f)return null;const y=f.value;if(!y)return null;const g=(b=f.properties)==null?void 0:b.options;if(!Array.isArray(g))return null;const h=g.find(S=>S.value===y||S.label===y);if(!(h!=null&&h.metadata))return null;const v=h.metadata[d];if(v==null)return null;const C=Number(v);return isNaN(C)?null:C},resolveRepeaterValues:u=>{for(const d of Object.keys(n.components)){const m=n.components[d];if(m.type!=="repeater"||!m.addedComponents||!m.components)continue;const f=m.components.findIndex(g=>g.uuid===u);if(f===-1)continue;const y=[];for(const g of m.addedComponents){const h=g[f];if(!h)continue;const v=h.value;if(v==null||v==="")continue;const C=Number(v);isNaN(C)||y.push(C)}return y.length>0?y:null}return null}}}function fe(n,s){return{resolveValue:o=>{if(o in s)return s[o];const t=K(n,o);if(!t)return null;const e=t.value;if(e==null||e==="")return null;const r=Number(e);return isNaN(r)?null:r},resolveOptionMetadata:(o,t)=>{var u;const e=K(n,o);if(!e)return null;const r=e.value;if(!r)return null;const c=(u=e.properties)==null?void 0:u.options;if(!Array.isArray(c))return null;const i=c.find(d=>d.value===r||d.label===r);if(!(i!=null&&i.metadata))return null;const l=i.metadata[t];if(l==null)return null;const a=Number(l);return isNaN(a)?null:a},resolveRepeaterValues:o=>{for(const t of Object.keys(n.components)){const e=n.components[t];if(e.type!=="repeater"||!e.addedComponents||!e.components)continue;const r=e.components.findIndex(i=>i.uuid===o);if(r===-1)continue;const c=[];for(const i of e.addedComponents){const l=i[r];if(!l)continue;const a=l.value;if(a==null||a==="")continue;const u=Number(a);isNaN(u)||c.push(u)}return c.length>0?c:null}return null}}}function xe(n){var o,t;const s=n.calculationResults??{};for(const e of Object.values(n.components))if(e.type==="computed"&&((o=e.properties)!=null&&o.formula)){const r=fe(n,s),c=M.evaluateFormula(e.properties.formula,r);e.value=c}for(const e of Object.values(n.components))if((e.type==="repeater"||e.type==="group")&&e.addedComponents&&e.components)for(let r=0;r<e.addedComponents.length;r++){const c=e.addedComponents[r];for(let i=0;i<c.length;i++){const l=c[i],a=e.components[i];if((a==null?void 0:a.type)==="computed"&&((t=a.properties)!=null&&t.formula)){const u=e.type==="repeater"?Ye(n,s,e.uuid,r):fe(n,s),d=M.evaluateFormula(a.properties.formula,u);l.value=d}}}}function pn(n,s){var c,i;const o=n.computedByDependency;if(!o)return!1;const t=o[s];if(!t||t.length===0)return!1;const e=n.calculationResults??{};let r=!1;for(const l of t){const a=n.components[l];if(a&&a.type==="computed"&&((c=a.properties)!=null&&c.formula)){const u=fe(n,e),d=M.evaluateFormula(a.properties.formula,u);a.value!==d&&(n.components[l]={...a,value:d},r=!0);continue}for(const u of Object.values(n.components))if((u.type==="repeater"||u.type==="group")&&u.components&&u.addedComponents){const d=u.components.findIndex(f=>f.uuid===l);if(d===-1)continue;const m=u.components[d];if((m==null?void 0:m.type)!=="computed"||!((i=m.properties)!=null&&i.formula))continue;for(let f=0;f<u.addedComponents.length;f++){const y=u.addedComponents[f][d];if(!y)continue;const g=u.type==="repeater"?Ye(n,e,u.uuid,f):fe(n,e),h=M.evaluateFormula(m.properties.formula,g);y.value!==h&&(u.addedComponents[f][d]={...y,value:h},r=!0)}}}return r}const Ge=(n,s)=>{var o,t;if(s.includes(":")){const e=s.split(":"),r=n[e[0]];return(t=(o=r==null?void 0:r.addedComponents)==null?void 0:o[parseInt(e[1])])==null?void 0:t[parseInt(e[2])]}return n[s]},ue=(n,s)=>{for(const o of n.screenOrder)if(n.screens[o].components.some(e=>e.uuid===s))return o;return null},fn=(n,s)=>{if(!s.includes(":"))return null;const o=s.split(":");if(o.length!==3)return null;const t=o[0],e=parseInt(o[2]),r=n.components[t];if(!r||r.type!=="repeater"||!r.components)return null;const c=r.components[e];return(c==null?void 0:c.uuid)??null},_e=(n,s,o,t,e)=>{const r=s(),c=r.groupComponentMap[o]??o,i=hn(n,s,c),l={components:r.components,groupComponentMap:r.groupComponentMap},a=_(t,l);t.valid=a.length===0;const u={...r.validationErrors,[o]:a},d=r.validationsByDependency[o];if(d)for(const b of d){const S=K(r,b.target);if(S){const w=_(S,l);S.valid=w.length===0,u[b.target]=w}}const m=ue(r,e),f={components:{...r.components},validationErrors:u};if(i&&(f.conditionResults=i),m){const b={...r,...f};f.screenValidity={...r.screenValidity,[m]:Z(b,m)}}const y={...r,...f},g=o.includes(":")?fn(y,o):null,h=[],v=b=>{if(pn(y,b)){const S=y.computedByDependency[b]??[];for(const w of S)h.includes(w)||(h.push(w),v(w))}};v(c),g&&g!==c&&v(g);let C=ye(y,c);if(g&&g!==c){const b=C?{...y,calculationResults:C}:y,S=ye(b,g);S&&(C=S)}for(const b of h){const S=C?{...y,calculationResults:C}:y,w=ye(S,b);w&&(C=w)}C&&(f.calculationResults=C),n(f)},mn=(n,s)=>({updateComponentValue:(o,t)=>{var c,i;const e=s();if(o.includes(":")){const l=o.split(":"),a=l[0],u=parseInt(l[1]),d=parseInt(l[2]),m=e.components[a];if(!((i=(c=m==null?void 0:m.addedComponents)==null?void 0:c[u])!=null&&i[d]))return;const f=m.addedComponents[u][d].value!==t;if(m.addedComponents[u][d]={...m.addedComponents[u][d],value:t},f){_e(n,s,o,m.addedComponents[u][d],a);return}n({components:{...e.components}});return}const r=e.components[o];if(r){if(r.type==="group"||r.type==="repeater"){n({components:{...e.components}});return}if(t===r.value){n({selectionTick:s().selectionTick+1});return}r.value=t,_e(n,s,o,r,o)}},addGroupIteration:o=>{const t=s(),e=t.components[o];if(!e||e.type!=="group"||!e.components)return;e.addedComponents||(e.addedComponents=[]);const r={...t.conditionsByDependency},c=e.components.map((a,u)=>{const d=W(a);if(d.uuid=[o,e.addedComponents.length,u].join(":"),t.groupComponentMap[d.uuid]=a.uuid,d.conditions&&Object.keys(d.conditions).length>0){const f="when"in d.conditions?d.conditions:null;f&&(d.conditions=f,Q(r,d.uuid,f,"component"))}const m=_(d);return d.valid=m.length===0,d});e.addedComponents.push(c);const i=ue(t,o),l={...t.screenValidity};return i&&(l[i]=Z({...t},i)),n({components:{...t.components},groupComponentMap:{...t.groupComponentMap},conditionsByDependency:r,screenValidity:l}),e.addedComponents},addRepeaterIteration:o=>{const t=s(),e=t.components[o];if(!e||e.type!=="repeater"||!e.components)return;e.addedComponents||(e.addedComponents=[]);const r={...t.conditionsByDependency},c=e.components.map((d,m)=>{const f=W(d);if(f.uuid=[o,e.addedComponents.length,m].join(":"),f.conditions&&Object.keys(f.conditions).length>0){const g="when"in f.conditions?f.conditions:null;g&&(f.conditions=g,Q(r,f.uuid,g,"component"))}const y=_(f);return f.valid=y.length===0,f});e.addedComponents.push(c);const i=ue(t,o),l={...t.screenValidity};i&&(l[i]=Z({...t},i));const a={...t,components:{...t.components}};xe(a);const u=be(a);return n({components:{...t.components},conditionsByDependency:r,screenValidity:l,calculationResults:u}),e.addedComponents},removeRepeaterIteration:(o,t)=>{var g;const e=s(),r=e.components[o];if(!r||r.type!=="repeater"||!r.addedComponents)return;const c=((g=r.properties)==null?void 0:g.minIterations)??1;if(r.addedComponents.length<=c)return;const i=r.addedComponents[t],l=new Set(i.map(h=>h.uuid));r.addedComponents.splice(t,1);const a={...e.conditionsByDependency},u={...e.validationErrors};for(const h of l)delete u[h],delete a[h];for(const h of Object.keys(a)){const v=a[h],C=v.filter(b=>!l.has(b.target));C.length===0?delete a[h]:C.length!==v.length&&(a[h]=C)}for(let h=t;h<r.addedComponents.length;h++)r.addedComponents[h].forEach((v,C)=>{const b=v.uuid,S=[o,h,C].join(":");if(b!==S){v.uuid=S,b in u&&(u[S]=u[b],delete u[b]),b in a&&(a[S]=a[b],delete a[b]);for(const w of Object.values(a))for(const O of w)O.target===b&&(O.target=S)}});const d=ue(e,o),m={...e.screenValidity};d&&(m[d]=Z({...e},d));const f={...e,components:{...e.components}};xe(f);const y=be(f);n({components:{...e.components},conditionsByDependency:a,validationErrors:u,screenValidity:m,calculationResults:y})}}),K=(n,s)=>Ge(n.components,s),Q=(n,s,o,t)=>{const e=new Set;for(const c of o.when.rules)e.add(c.source);const r={target:s,type:t,config:o};for(const c of e)n[c]||(n[c]=[]),n[c].push(r)},vn=(n,s)=>{var o,t;return s.includes(":")?(o=K(n,s))==null?void 0:o.value:(t=n.components[s])==null?void 0:t.value},te=(n,s)=>M.evaluateConditionConfig(s,(o,t)=>(t==null?void 0:t.sourceType)==="context"?n.externalContext[t.source]:vn(n,o)),hn=(n,s,o)=>{const t=s(),e=t.conditionsByDependency[o];if(!e||e.length===0)return null;let r=!1;const c={...t.conditionResults};for(const i of e){const l=te(t,i.config);c[i.target]!==l&&(c[i.target]=l,r=!0)}return r?c:null},yn=n=>{const s={},o=new Set;for(const t of Object.values(n.conditionsByDependency))for(const e of t)o.has(e.target)||(o.add(e.target),s[e.target]=te(n,e.config));return s},ge=n=>{if(!n||pe(n.type))return null;const s="label"in n.properties?n.properties.label:"",o={uuid:n.uuid,type:n.type,value:n.value};return s&&(o.label=s),o},Me=n=>{if(n.conditions&&"when"in n.conditions)return n.conditions},gn=n=>{const s={uuid:n.flowUUID,metadata:n.metadata,screens:[]},o=t=>{const e=n.screens[t];if(!e)return!1;const r=e.conditions&&"when"in e.conditions?e.conditions:void 0;return M.isHiddenByCondition(r,n.conditionResults[t])};return s.screens=n.screenOrder.filter(t=>!o(t)).map(t=>{const e=n.screens[t],r={uuid:t,components:e.components.map(c=>{const i=n.components[c.uuid];if(!i)return null;const l=Me(i);if(M.isHiddenByCondition(l,n.conditionResults[c.uuid]))return null;if((i.type==="group"||i.type==="repeater")&&i.addedComponents){const a=ge(i);return a?{...a,components:i.addedComponents.map(u=>u.filter(d=>{const m=Me(d);return!M.isHiddenByCondition(m,n.conditionResults[d.uuid])}).map(d=>ge(d)).filter(d=>d!==null))}:null}return ge(i)}).filter(c=>c!==null)};return e.label&&(r.label=e.label),r}),s},ve=x.createContext(null);function L(n){const s=x.useContext(ve);if(!s)throw new Error("useFBREStore must be used within an FBRE provider");return z.useStore(s,n)}const ie=()=>{const n=x.useContext(ve);if(!n)throw new Error("useFBREStoreApi must be used within an FBRE provider");return n},ce=n=>!n||Object.keys(n).length===0?null:"when"in n?n:null,Cn=[],bn=()=>z.createStore((n,s)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,loadFlow:(o,t,e)=>{var O;const r={},c=[],i={},l={},a={},u={},d={},m={},f={};o.screens.forEach(E=>{const T=ce(E.conditions),V=T?{...E,conditions:T}:{...E};r[E.uuid]=V,c.push(E.uuid),T&&Q(u,E.uuid,T,"screen"),E.components.forEach(j=>{var U;const I=ce(j.conditions),k=W(j);if(I&&(k.conditions=I),i[j.uuid]=k,I&&Q(u,j.uuid,I,"component"),(U=k.properties)!=null&&U.validation&&se(d,j.uuid,k.properties.validation),(j.type==="group"||j.type==="repeater")&&j.components){const A=i[j.uuid];A.addedComponents||(A.addedComponents=[]);const G=j.properties??{},P=j.type==="repeater"?G.initialData:void 0,B=j.type==="repeater"?G.minIterations:void 0,q=P?P.length:j.type==="repeater"&&B&&B>1?B:1;for(let H=0;H<q;H++){const X=j.components.map((R,Y)=>{var ne;const N=W(R);N.uuid=[j.uuid,A.addedComponents.length,Y].join(":"),P&&P[H]&&R.uuid in P[H]&&(N.value=P[H][R.uuid]),j.type==="group"&&(l[N.uuid]=R.uuid),H===0&&(a[R.uuid]=N.uuid);const $=ce(N.conditions);$&&(N.conditions=$,Q(u,N.uuid,$,"component")),(ne=N.properties)!=null&&ne.validation&&se(d,N.uuid,N.properties.validation);const ee=_(N);return N.valid=ee.length===0,ee.length>0&&(m[N.uuid]=ee),N});A.addedComponents.push(X)}}})}),t&&t.screens.forEach(E=>{const T=c.indexOf(E.uuid);T<0||E.components.forEach(V=>{const j=i[V.uuid];if(j)if((j.type==="group"||j.type==="repeater")&&V.components&&j.addedComponents){if(V.components.length>1){const I=j.addedComponents.length,k=V.components.length-I,J=o.screens[T].components.find(U=>U.uuid===j.uuid);for(let U=0;U<k;U++)if(J!=null&&J.components){const A=J.components.map((G,P)=>{var X;const B=W(G);B.uuid=[j.uuid,j.addedComponents.length,P].join(":"),j.type==="group"&&(l[B.uuid]=G.uuid),a[G.uuid]||(a[G.uuid]=B.uuid);const q=ce(B.conditions);q&&(B.conditions=q,Q(u,B.uuid,q,"component")),(X=B.properties)!=null&&X.validation&&se(d,B.uuid,B.properties.validation);const H=_(B);return B.valid=H.length===0,H.length>0&&(m[B.uuid]=H),B});j.addedComponents.push(A)}}V.components.forEach(I=>{I.forEach(k=>{for(const J of j.addedComponents){const U=J.find(A=>A.uuid===k.uuid);if(U){U.value=k.value;const A=_(U);U.valid=A.length===0,m[U.uuid]=A;break}}})})}else{j.value=V.value;const I=_(j);j.valid=I.length===0,m[j.uuid]=I}})});for(const E of Object.keys(i)){const T=i[E];if(!(T.type==="group"||T.type==="repeater"||!((O=T.properties)!=null&&O.validation))&&!(E in m)){const V=_(T);T.valid=V.length===0,V.length>0&&(m[E]=V)}}const y={...s(),externalContext:e??{},screens:r,screenOrder:c,components:i,groupComponentMap:l,templateComponentMap:a,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:d},g=yn(y);y.conditionResults=g,c.forEach(E=>{f[E]=Z(y,E)});const h=dn(i),v={...y,computedByDependency:h,calculationResults:{},screenValidity:f};xe(v);const C=o.calculations??[],b=un(C),S={...v,calculations:C},w=be(S);n({flowUUID:o.uuid,metadata:o.metadata,config:o.config??{},externalContext:e??{},screens:r,screenOrder:c,components:i,groupComponentMap:l,templateComponentMap:a,conditionsByDependency:u,conditionResults:g,screenValidity:f,validationErrors:m,validationsByDependency:d,calculations:C,calculationResults:w,calculationsByDependency:b,computedByDependency:h})},updateContext:o=>{const t=s(),e=t.externalContext,r=[];for(const a of Object.keys(o))e[a]!==o[a]&&r.push(a);for(const a of Object.keys(e))!(a in o)&&!r.includes(a)&&r.push(a);if(r.length===0)return;const c={...t.conditionResults};let i=!1;const l=new Set;for(const a of r){const u=t.conditionsByDependency[a];if(!(!u||u.length===0))for(const d of u){if(l.has(d.target))continue;l.add(d.target);const m={...t,externalContext:o},f=te(m,d.config);c[d.target]!==f&&(c[d.target]=f,i=!0)}}if(i){const a={...t,conditionResults:c},u={};for(const d of t.screenOrder)u[d]=Z(a,d);n({externalContext:o,conditionResults:c,screenValidity:u})}else n({externalContext:o})},...mn(n,s),getFlowData:()=>gn(s()),getScreenByIndex:o=>{const t=s();return o<0||o>=t.screenOrder.length?null:t.screens[t.screenOrder[o]]},getScreenValidity:o=>{const t=s();return o<0||o>=t.screenOrder.length?!0:t.screenValidity[t.screenOrder[o]]??!0},getValidationErrors:o=>s().validationErrors[o]??Cn,evaluateFlowValidation:()=>{const o=s(),t={};let e=!0;return o.screenOrder.forEach(r=>{const c=Z(o,r);t[r]=c,c||(e=!1)}),n({screenValidity:t}),e},getMaxScreenCount:()=>s().screenOrder.length-1,getCalculationResult:o=>s().calculationResults[o]??null})),xn=({uuid:n})=>{var i;const s=L(l=>l.components[n]),o=L(l=>l.conditionResults[n]);if(!s)return null;const t=s.conditions&&"when"in s.conditions?s.conditions:void 0;if(M.isHiddenByCondition(t,o))return null;const e=rn(s.type);if(!e)return console.warn(`FBRE: No renderer for component type "${s.type}"`),null;const r=(i=s.properties)==null?void 0:i.width,c=r&&r!=="full"?`fbre-component fbre-width-${r}`:"fbre-component";return p.jsx("div",{className:c,"data-uuid":n,children:p.jsx(e,{uuid:n})})},Se=({screenIndex:n})=>{const s=L(o=>{const t=o.screenOrder[n];return t?o.screens[t]:null});return s?p.jsx("div",{className:"fbre-screen",children:s.components.map(o=>p.jsx(xn,{uuid:o.uuid},o.uuid))}):null},Ue=({size:n=14})=>p.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:p.jsx("polyline",{points:"4,12 9.5,17.5 20,7"})}),Sn=({size:n=12})=>p.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",children:p.jsx("path",{d:"M7 10l5 5 5-5z"})}),wn=({size:n=16})=>p.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",children:p.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})}),jn=({size:n=16})=>p.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",children:p.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})}),Ae=({position:n,screenIndex:s,maxScreenIndex:o,allowInvalidTransition:t,screenValidity:e,summaryEnabled:r,summaryActive:c,atMaxScreen:i,nextButtonLabel:l,backButtonLabel:a,completionLoading:u,nextScreen:d,prevScreen:m,onFlowComplete:f})=>{const y=u??!1;if(n==="back"){const b=s===0&&!c||y;return p.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--secondary",disabled:b,onClick:m,children:[p.jsx(wn,{}),a||"Back"]})}const g=r?i&&c:i,h=r?i?c?"Done":"Review":"Next":i?"Done":"Next";if(o===0){const b=r?c?"Complete":"Review":"Complete",S=y||!e;return p.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:S,onClick:()=>{r&&!c?d():f()},children:[l||b,y?p.jsx("span",{className:"fbre-btn__spinner"}):p.jsx(Ue,{size:16})]})}const v=y||!t&&!e||h==="Done"&&!e,C=()=>{g?f():d()};return p.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:v,onClick:C,children:[l||h,y?p.jsx("span",{className:"fbre-btn__spinner"}):g?p.jsx(Ue,{size:16}):p.jsx(jn,{})]})},Rn=({current:n,total:s,stepperStyle:o})=>{if(s<=1)return null;const t=s>1?n/(s-1)*100:100,r=!!o&&o!=="default"||s<=6;return p.jsxs(p.Fragment,{children:[r&&p.jsx("div",{className:"fbre-stepper fbre-stepper--dots",children:Array.from({length:s},(c,i)=>p.jsx("div",{className:`fbre-stepper__dot${i===n?" active":i<n?" completed":""}`},i))}),r&&p.jsxs("div",{className:"fbre-stepper fbre-stepper--bar-alt",children:[p.jsx("div",{className:"fbre-stepper__track",children:p.jsx("div",{className:"fbre-stepper__fill",style:{width:`${t}%`}})}),p.jsxs("span",{className:"fbre-stepper__counter",children:[n+1," of ",s]})]}),!r&&p.jsx("div",{className:"fbre-stepper fbre-stepper--bar",children:p.jsx("div",{className:"fbre-stepper__fill",style:{width:`${t}%`}})})]})},En=({current:n,total:s})=>s<=1?null:p.jsxs("div",{className:"fbre-stepper-text",children:["Step ",n+1," of ",s]}),Nn=n=>{const s=n.controlsLayout==="stacked",o=n.showStepper!==!1&&(n.stepperStyle??"default")!=="text";return p.jsxs("div",{className:s?"fbre-controls fbre-controls--stacked":"fbre-controls",children:[n.screenIndex>0||n.summaryActive?p.jsx(Ae,{position:"back",...n}):p.jsx("div",{}),o&&n.maxScreenIndex>0?p.jsx(Rn,{current:n.screenIndex,total:n.maxScreenIndex+1,stepperStyle:n.stepperStyle}):p.jsx("div",{}),p.jsx(Ae,{position:"next",...n})]})},Je=({component:n})=>{const{uuid:s,label:o,type:t,value:e,components:r}=n,c=()=>{if(e!=null)switch(t){case"fileUpload":return e.name;case"inputText":case"inputTextArea":case"inputNumber":case"dropDown":case"radio":case"rating":case"slider":return e.toString();case"computed":return typeof e=="number"?e.toString():"—";case"toggleSwitch":return e?"Yes":"No";case"checkbox":case"dropDownMulti":return e.length===0?"No options selected":e.join(", ")}return"No response given"};if(t==="signature"&&e){const a=typeof e=="string"&&e.startsWith("data:");return p.jsxs("div",{className:"fbre-summary__item",children:[p.jsx("div",{className:"fbre-summary__item-label",children:o}),p.jsx("div",{className:"fbre-summary__item-value",children:a?p.jsx("img",{src:e,alt:"Signature",style:{maxWidth:"100%",maxHeight:80}}):p.jsx("span",{style:{fontFamily:'"Brush Script MT", "Segoe Script", "Dancing Script", cursive',fontSize:24},children:e})})]})}const i=()=>r?r.map((a,u)=>p.jsx("div",{children:a.map(d=>p.jsx(Je,{component:d},d.uuid))},`${s}-${u}`)):null,l=e==null||typeof e=="string"&&e.length===0||Array.isArray(e)&&e.length===0;return p.jsxs("div",{className:`fbre-summary__item${t==="group"||t==="repeater"?" fbre-summary__item--group":""}`,children:[p.jsx("div",{className:"fbre-summary__item-label",children:o}),t!=="group"&&t!=="repeater"&&p.jsx("div",{className:`fbre-summary__item-value${l?" fbre-summary__item-value--empty":""}`,children:c()}),(t==="group"||t==="repeater")&&i()]})},Dn=/\$\{([^}]+)\}/g,In=(n,s)=>n.replace(Dn,(o,t)=>{const e=s.resolveCalculation(t);if(e!==null)return e;const r=s.resolveComponentValue(t);return r!==null?r:""});function kn(){const n=L(e=>e.components),s=L(e=>e.templateComponentMap),o=L(e=>e.calculations),t=L(e=>e.calculationResults);return x.useMemo(()=>{const e=new Map(o.map(c=>[c.uuid,c])),r=c=>{var d,m;const i=n[c];if(i)return i;const l=s[c];if(!l)return;const a=l.split(":"),u=n[a[0]];return(m=(d=u==null?void 0:u.addedComponents)==null?void 0:d[parseInt(a[1])])==null?void 0:m[parseInt(a[2])]};return{resolveComponentValue:c=>{const i=r(c);if(!i)return null;const l=i.value;return l==null||l===""?null:Array.isArray(l)?l.join(", "):String(l)},resolveCalculation:c=>{const i=e.get(c);if(!i)return null;const l=t[c]??null;return M.formatCalculationResult(l,i.format,i.decimalPlaces,i.currencySymbol)}}},[n,s,o,t])}const Bn=({screen:n,showToggle:s})=>{const o=kn(),[t,e]=x.useState(!0);return p.jsxs("div",{children:[p.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>s&&e(!t),children:[n.label&&p.jsx("span",{className:"fbre-summary__screen-label",children:In(n.label,o)}),s&&p.jsx("span",{className:`fbre-summary__screen-toggle${t?"":" collapsed"}`,children:p.jsx(Sn,{size:20})})]}),p.jsx("div",{className:`fbre-summary__screen-body${t?"":" collapsed"}`,children:n.components.map(r=>p.jsx(Je,{component:r},r.uuid))})]})},Fe=()=>{const n=ie(),s=L(e=>e.components),o=x.useMemo(()=>n.getState().getFlowData(),[n,s]),t=o.screens.length;return p.jsxs("div",{className:"fbre-summary",children:[p.jsx("h2",{className:"fbre-summary__title",children:"Review"}),p.jsx("div",{className:"fbre-summary__body",children:o.screens.map(e=>p.jsx(Bn,{screen:e,showToggle:t>1},e.uuid))})]})},ze=(n,s,o)=>s?!M.isHiddenByCondition(s,o[n]):!0,me=(n,s)=>{const o=n.screenOrder.length-1;let t=s+1;for(;t<=o;){const e=n.screenOrder[t],r=n.screens[e],c=r!=null&&r.conditions&&"when"in r.conditions?r.conditions:void 0;if(ze(e,c,n.conditionResults))return t;t++}return null},On=(n,s)=>{let o=s-1;for(;o>=0;){const t=n.screenOrder[o],e=n.screens[t],r=e!=null&&e.conditions&&"when"in e.conditions?e.conditions:void 0;if(ze(t,r,n.conditionResults))return o;o--}return 0},we=new Set(["radio","yesNo","cardSelect","dropDown"]),Tn=500;function We(n,s,o){const t=ie(),e=x.useRef(null),r=x.useRef(""),c=x.useRef(0);x.useEffect(()=>{if(!n)return;const i=t.getState(),l=Le(i,s);l&&(r.current=Pe(i.components,l)),c.current=i.selectionTick},[n,s,t]),x.useEffect(()=>{if(!n)return;const i=t.subscribe(l=>{const a=Le(l,s);if(!a)return;const u=l.selectionTick,d=u!==c.current;d&&(c.current=u);const m=Pe(l.components,a);if(m===r.current&&!d)return;const f=r.current;if(r.current=m,!(m!==f?Vn(l.components,a,f):d&&_n(l.components,a))||me(l,s)===null)return;const h=l.screenOrder[s];h&&l.screenValidity[h]===!1||(e.current&&clearTimeout(e.current),e.current=setTimeout(()=>{e.current=null,o()},Tn))});return()=>{i(),e.current&&(clearTimeout(e.current),e.current=null)}},[n,s,t,o]),x.useEffect(()=>()=>{e.current&&(clearTimeout(e.current),e.current=null)},[s])}function Le(n,s){const o=n.screenOrder[s];if(!o)return null;const t=n.screens[o];return t?t.components.map(e=>e.uuid):null}function Pe(n,s){const o=[];for(const t of s){const e=n[t];!e||!we.has(e.type)||o.push(`${t}=${JSON.stringify(e.value??null)}`)}return o.join("|")}function Vn(n,s,o){const t=new Map;for(const e of o.split("|")){const r=e.indexOf("=");r>0&&t.set(e.slice(0,r),e.slice(r+1))}for(const e of s){const r=n[e];if(!r||!we.has(r.type))continue;const c=JSON.stringify(r.value??null),i=t.get(e)??"null";if(c!==i&&c!=="null")return!0}return!1}function _n(n,s){for(const o of s){const t=n[o];if(!(!t||!we.has(t.type))&&t.value!==null&&t.value!==void 0)return!0}return!1}function Xe(n,s,o){const t=ie();x.useEffect(()=>{if(!n)return;const e=r=>{if(r.key!=="Enter")return;const c=r.target;if(c.tagName!=="INPUT"||!c.closest(".fbre-container"))return;const i=t.getState();if(me(i,s)===null)return;const a=i.screenOrder[s];a&&i.screenValidity[a]===!1||(r.preventDefault(),o())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n,s,o,t])}const de=new Map,Mn=(n,s)=>{de.has(n)||de.set(n,new Set),de.get(n).add(s)},Un=(n,s)=>{var o;(o=de.get(n))==null||o.delete(s)},Ke=x.createContext(null);function An(){return x.useContext(Ke)}class re extends Error{constructor(s,o,t,e){super(s),this.name="ApiError",this.status=o,this.code=t,this.validationErrors=e}}class Qe extends re{constructor(s,o){super(`Request timed out after ${o}ms: ${s}`,0,"TIMEOUT"),this.name="TimeoutError"}}const Fn=new Set([502,503,504]),ae=2,Ln=[500,1500];function Pn(n){return new Promise(s=>setTimeout(s,n))}async function oe(n,s,o={}){const e=`${n.apiEndpoint||""}${s}`,r=n.timeout??3e4,c={...o.body?{"Content-Type":"application/json"}:{},...o.headers};n.apiKey&&(c.Authorization=`Bearer ${n.apiKey}`);let i;for(let l=0;l<=ae;l++){l>0&&await Pn(Ln[l-1]);try{const a=new AbortController,u=setTimeout(()=>a.abort(),r);let d;try{d=await fetch(e,{...o,headers:c,signal:a.signal})}finally{clearTimeout(u)}if(!d.ok){const m=await d.json().catch(()=>({})),f=new re(m.error||`HTTP ${d.status}`,d.status,m.code,m.validationErrors);if(l<ae&&Fn.has(d.status)){i=f;continue}throw f}return d.json()}catch(a){if(a instanceof re)throw a;if(a instanceof DOMException&&a.name==="AbortError"){const u=new Qe(e,r);if(l<ae){i=u;continue}throw u}if(a instanceof TypeError&&l<ae){i=a;continue}throw a}}throw i}async function $n(n,s){return oe(n,`/api/v1/public/flows/${s}`)}async function qn(n,s,o){const t={flowId:s};return o&&Object.keys(o).length>0&&(t.context=o),oe(n,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(t)})}async function Hn(n,s,o){return oe(n,`/api/v1/public/sessions/${s}/next`,{method:"POST",body:JSON.stringify({data:o})})}async function Yn(n,s,o){return oe(n,`/api/v1/public/sessions/${s}/prev`,{method:"POST",body:JSON.stringify({data:o})})}async function Gn(n,s,o){return oe(n,`/api/v1/public/sessions/${s}/complete`,{method:"POST",body:JSON.stringify({data:o})})}async function Jn(n,s){return oe(n,`/api/v1/public/sessions/${s}`)}const zn={clean:"dots",outlined:"dots","refined-clean":"pill","airy-clean":"glow","soft-outlined":"glow","defined-outlined":"bar","centered-minimal":"dots","stacked-cards":"dots","soft-float":"glow","bold-statement":"bar"},Wn=({screenIndex:n,onFlowComplete:s,onScreenChange:o})=>{var je,Re,Ee,Ne,De,Ie,ke,Be,Oe,Te,Ve;const t=L(D=>D.config),e=L(D=>D.screenOrder.length),r=L(D=>Object.keys(D.components).length>0),c=ie(),i=Math.max(0,Math.min(n,e-1)),[l,a]=x.useState(i),[u,d]=x.useState(!!(t!=null&&t.summary&&n>=e)),m=((je=t==null?void 0:t.navigation)==null?void 0:je.transition)??"none",f=m!=="none",[y,g]=x.useState(null),[h,v]=x.useState(!1),[C,b]=x.useState("forward"),[S,w]=x.useState(!1),O=x.useRef(null);x.useEffect(()=>{const D=Math.max(0,Math.min(n,e-1));a(D)},[n]);const E=L(D=>D.screenOrder[l]),T=L(D=>E?D.screenValidity[E]??!0:!0),V=L(D=>{var F;return E?(F=D.screens[E])==null?void 0:F.nextButtonLabel:void 0}),j=L(D=>{var F;return E?(F=D.screens[E])==null?void 0:F.backButtonLabel:void 0}),I=x.useCallback(D=>{o&&o(D,c.getState().getFlowData())},[o,c]),k=x.useCallback(D=>{g(l),v(u),b(D),w(!0),O.current&&(O.current.scrollTop=0)},[l,u]),J=x.useCallback(()=>{w(!1),g(null)},[]),U=x.useCallback(()=>{if(!S)if(u)f&&k("back"),d(!1),I(l);else{const D=c.getState(),F=On(D,l);F!==l&&(f&&k("back"),a(F),I(F))}},[S,u,l,f,k,I,c]),A=x.useCallback(()=>{if(S)return;const D=c.getState(),F=me(D,l);F!==null?(f&&k("forward"),a(F),I(F)):t!=null&&t.summary&&(f&&k("forward"),d(!0),I(l+1))},[S,l,t,f,k,I,c]),[G,P]=x.useState(!1),[B,q]=x.useState(null),H=x.useCallback(()=>{q(null);const D=s(c.getState().getFlowData());D&&typeof D.then=="function"&&(P(!0),D.then(()=>{P(!1)}).catch(F=>{P(!1),q(F instanceof Error?F.message:String(F))}))},[s,c]),X=L(D=>me(D,l)===null),R=((Re=t==null?void 0:t.theme)==null?void 0:Re.darkMode)??!1,N=((t==null?void 0:t.mode)??"standard")==="conversational";We(N&&!u,l,A),Xe(N&&!u,l,A);const $=((Ee=t==null?void 0:t.theme)==null?void 0:Ee.style)??"clean",ee=((Ne=t==null?void 0:t.controls)==null?void 0:Ne.stepperStyle)??"default",ne=ee==="default"?zn[$]??"dots":ee,en=((De=t==null?void 0:t.controls)==null?void 0:De.showStepper)!==!1&&ne==="text",he={};(Ie=t==null?void 0:t.theme)!=null&&Ie.color&&(he["--fbre-theme-color"]=t.theme.color);const nn=()=>h?p.jsx(Fe,{}):y!==null?p.jsx(Se,{screenIndex:y}):null,tn=S?"fbre-screen-wrapper fbre-screen-wrapper--transitioning":"fbre-screen-wrapper";return p.jsxs("div",{className:"fbre-container","data-style":$,"data-mode":R?"dark":"light","data-form-mode":N?"conversational":void 0,"data-stepper":ne!=="text"?ne:void 0,"data-transition":f?m:void 0,style:Object.keys(he).length>0?he:void 0,children:[en&&p.jsx(En,{current:l,total:e}),p.jsxs("div",{className:tn,ref:O,children:[S&&p.jsx("div",{className:"fbre-screen--exiting","data-direction":C,onAnimationEnd:J,children:nn()}),p.jsxs("div",{className:S?"fbre-screen--entering":void 0,"data-direction":S?C:void 0,children:[!u&&p.jsx(Se,{screenIndex:l}),u&&p.jsx(Fe,{})]})]}),B&&p.jsx("div",{className:"fbre-completion-error",children:B}),((ke=t==null?void 0:t.controls)==null?void 0:ke.show)!==!1&&r&&p.jsx(Nn,{screenIndex:l,maxScreenIndex:e-1,allowInvalidTransition:(Be=t==null?void 0:t.navigation)==null?void 0:Be.allowInvalidTransition,screenValidity:T,summaryEnabled:(t==null?void 0:t.summary)??!1,summaryActive:u,atMaxScreen:X,nextButtonLabel:V,backButtonLabel:j,completionLoading:G,showStepper:(Oe=t==null?void 0:t.controls)==null?void 0:Oe.showStepper,stepperStyle:(Te=t==null?void 0:t.controls)==null?void 0:Te.stepperStyle,controlsLayout:(Ve=t==null?void 0:t.controls)==null?void 0:Ve.layout,nextScreen:A,prevScreen:U,onFlowComplete:H})]})},Xn=[],Kn=()=>z.createStore((n,s)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,sessionId:"",navigation:{canGoBack:!1,canGoForward:!1,screenNumber:1,totalScreens:1,progress:0,isLastScreen:!0},loading:!1,error:"",clearError:()=>{n({error:""})},loadFlow:()=>{},updateContext:o=>{n({externalContext:o})},updateComponentValue:(o,t)=>{var m,f;const e=s();if(o.includes(":")){const y=o.split(":"),g=y[0],h=parseInt(y[1]),v=parseInt(y[2]),C=e.components[g];if(!((f=(m=C==null?void 0:C.addedComponents)==null?void 0:m[h])!=null&&f[v]))return;C.addedComponents[h][v]={...C.addedComponents[h][v],value:t};const b=e.groupComponentMap[o]??o,S=e.conditionsByDependency[b];let w=e.conditionResults;if(S&&S.length>0){w={...e.conditionResults};for(const j of S)w[j.target]=te({...e},j.config)}const O={components:e.components,groupComponentMap:e.groupComponentMap},E=_(C.addedComponents[h][v],O);C.addedComponents[h][v].valid=E.length===0;const T={...e.validationErrors,[o]:E},V=e.validationsByDependency[o];if(V)for(const j of V){const I=$e(e,j.target);if(I){const k=_(I,O);I.valid=k.length===0,T[j.target]=k}}n({components:{...e.components},conditionResults:w,validationErrors:T});return}const r=e.components[o];if(!r)return;if(r.type==="group"||r.type==="repeater"){n({components:{...e.components}});return}if(t===r.value){n({selectionTick:(s().selectionTick??0)+1});return}r.value=t;const c=e.conditionsByDependency[o];let i=e.conditionResults;if(c&&c.length>0){i={...e.conditionResults};for(const y of c)i[y.target]=te({...e},y.config)}const l={components:e.components,groupComponentMap:e.groupComponentMap},a=_(r,l);r.valid=a.length===0;const u={...e.validationErrors,[o]:a},d=e.validationsByDependency[o];if(d)for(const y of d){const g=$e(e,y.target);if(g){const h=_(g,l);g.valid=h.length===0,u[y.target]=h}}n({components:{...e.components},conditionResults:i,validationErrors:u})},addGroupIteration:o=>{const t=s(),e=t.components[o];if(!e||e.type!=="group"||!e.components)return;e.addedComponents||(e.addedComponents=[]);const r=e.components.map((c,i)=>{const l=W(c);l.uuid=[o,e.addedComponents.length,i].join(":"),t.groupComponentMap[l.uuid]=c.uuid;const a=_(l);return l.valid=a.length===0,l});return e.addedComponents.push(r),n({components:{...t.components},groupComponentMap:{...t.groupComponentMap}}),e.addedComponents},addRepeaterIteration:o=>{const t=s(),e=t.components[o];if(!e||e.type!=="repeater"||!e.components)return;e.addedComponents||(e.addedComponents=[]);const r=e.components.map((c,i)=>{const l=W(c);l.uuid=[o,e.addedComponents.length,i].join(":");const a=_(l);return l.valid=a.length===0,l});return e.addedComponents.push(r),n({components:{...t.components}}),e.addedComponents},removeRepeaterIteration:(o,t)=>{const e=s(),r=e.components[o];if(!(!r||r.type!=="repeater"||!r.addedComponents||r.addedComponents.length<=1)){r.addedComponents.splice(t,1);for(let c=t;c<r.addedComponents.length;c++)r.addedComponents[c].forEach((i,l)=>{i.uuid=[o,c,l].join(":")});n({components:{...e.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:o=>{const t=s();if(o!==0)return null;const e=t.screenOrder[0];return e?t.screens[e]:null},getScreenValidity:o=>{const t=s();if(o!==0)return!0;const e=t.screenOrder[0];return e?t.screenValidity[e]??!0:!0},getValidationErrors:o=>s().validationErrors[o]??Xn,evaluateFlowValidation:()=>{const o=s(),t=o.screenOrder[0];if(!t)return!0;const e=o.screens[t];if(!e)return!0;let r=!0;const c={components:o.components,groupComponentMap:o.groupComponentMap},i={...o.validationErrors};for(const a of e.components){const u=o.components[a.uuid];if(!u)continue;if((u.type==="group"||u.type==="repeater")&&u.addedComponents){for(const f of u.addedComponents)for(const y of f){const g=y.conditions&&"when"in y.conditions?y.conditions:void 0;if(g){const v=o.conditionResults[y.uuid]??!1;if(g.action==="show"&&!v||g.action==="hide"&&v)continue}const h=_(y,c);y.valid=h.length===0,i[y.uuid]=h,h.length>0&&(r=!1)}continue}const d=u.conditions&&"when"in u.conditions?u.conditions:void 0;if(d){const f=o.conditionResults[u.uuid]??!1;if(d.action==="show"&&!f||d.action==="hide"&&f)continue}const m=_(u,c);u.valid=m.length===0,i[u.uuid]=m,m.length>0&&(r=!1)}const l={...o.screenValidity,[t]:r};return n({components:{...o.components},validationErrors:i,screenValidity:l}),r},getMaxScreenCount:()=>0,getCalculationResult:o=>s().calculationResults[o]??null})),le=(n,s)=>{var y,g;const o={},t={},e={},r={},c={},i={},l=s.screen.uuid;for(const h of s.screen.components){const v=W(h);if(o[v.uuid]=v,(v.type==="group"||v.type==="repeater")&&h.components){v.addedComponents||(v.addedComponents=[]);const C=h.components.map((b,S)=>{var O;const w=W(b);if(w.uuid=[v.uuid,0,S].join(":"),v.type==="group"&&(t[w.uuid]=b.uuid),e[b.uuid]=w.uuid,(O=w.properties)!=null&&O.validation){const E=w.properties.validation;E.rules&&E.rules.length>0&&se(c,w.uuid,E)}return w});v.addedComponents.push(C)}if((y=v.properties)!=null&&y.validation){const C=v.properties.validation;C.rules&&C.rules.length>0&&se(c,v.uuid,C)}}for(const{targetUUID:h,config:v}of s.conditions)Q(r,h,v,h===l?"screen":"component");if(s.previousData)for(const h of s.previousData){const v=o[h.uuid];v&&(v.value=h.value)}const a={components:o};for(const h of Object.keys(o)){const v=o[h];if(v.type==="group"||v.type==="repeater"){if(v.addedComponents)for(const b of v.addedComponents)for(const S of b){const w=_(S,a);S.valid=w.length===0,w.length>0&&(i[S.uuid]=w)}continue}if(!((g=v.properties)!=null&&g.validation))continue;const C=_(v,a);v.valid=C.length===0,C.length>0&&(i[h]=C)}const u={},d={components:o},m=new Set;for(const h of Object.values(r))for(const v of h)m.has(v.target)||(m.add(v.target),u[v.target]=te(d,v.config));let f=!0;for(const h of s.screen.components){const v=o[h.uuid];if(v)if((v.type==="group"||v.type==="repeater")&&v.addedComponents)for(const C of v.addedComponents){for(const b of C)if(!b.valid){f=!1;break}if(!f)break}else v.valid===!1&&(f=!1)}n.setState({screenOrder:[l],screens:{[l]:{uuid:l,label:s.screen.label,components:s.screen.components,nextButtonLabel:s.screen.nextButtonLabel,backButtonLabel:s.screen.backButtonLabel}},screenValidity:{[l]:f},components:o,groupComponentMap:t,templateComponentMap:e,conditionsByDependency:r,conditionResults:u,validationErrors:i,validationsByDependency:c,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:s.sessionId,navigation:s.navigation,loading:!1,error:"",externalContext:s.context??{},config:s.config??{}})},Ce=n=>{var r;const s=n.getState(),o=s.screenOrder[0];if(!o)return[];const t=s.screens[o];if(!t)return[];const e=[];for(const c of t.components){const i=s.components[c.uuid];if(!i||pe(i.type))continue;const l={uuid:i.uuid,type:i.type,value:i.value};(r=i.properties)!=null&&r.label&&(l.label=i.properties.label),(i.type==="group"||i.type==="repeater")&&i.addedComponents&&(l.components=i.addedComponents.map(a=>a.filter(u=>!pe(u.type)).map(u=>({uuid:u.uuid,type:u.type,value:u.value})))),e.push(l)}return e},$e=(n,s)=>Ge(n.components,s),Qn=6e4,Zn=({sessionEndpoint:n,flowId:s,apiKey:o,mode:t,theme:e,context:r,onFlowComplete:c,onScreenChange:i})=>{const l=x.useRef(null);l.current||(l.current=Kn());const a=l.current,u=z.useStore(a,R=>R.loading),d=z.useStore(a,R=>R.error),m=z.useStore(a,R=>R.navigation),f=z.useStore(a,R=>R.config),y=z.useStore(a,R=>{var Y;return(Y=R.config)==null?void 0:Y.mode}),g=z.useStore(a,R=>R.screenOrder),h=z.useStore(a,R=>R.screens),[v,C]=x.useState(""),b=x.useRef(null),S=x.useRef(Date.now()),w=x.useMemo(()=>({apiEndpoint:n,apiKey:o}),[n,o]),O=x.useCallback(R=>{C(R),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>C(""),8e3)},[]),E=x.useCallback(()=>{C(""),b.current&&(clearTimeout(b.current),b.current=null)},[]),T=x.useCallback(async()=>{a.setState({loading:!0,error:""});try{const R=await qn(w,s,r);le(a,R)}catch(R){a.setState({loading:!1,error:R.message})}},[s,n,o,r]);x.useEffect(()=>{T()},[T]),x.useEffect(()=>{const R=async()=>{if(document.visibilityState!=="visible")return;const Y=a.getState();if(!(!Y.sessionId||Date.now()-S.current<Qn))try{const $=await Jn(w,Y.sessionId);le(a,$)}catch($){$ instanceof re&&$.status===404&&a.setState({loading:!1,error:"Session expired. Please start over.",screenOrder:[],screens:{}})}};return document.addEventListener("visibilitychange",R),()=>document.removeEventListener("visibilitychange",R)},[n,o]);const V=x.useCallback(async()=>{const R=a.getState();if(!(R.loading||!R.evaluateFlowValidation())){a.setState({loading:!0}),a.getState().clearError(),E();try{const N=Ce(a),$=await Hn(w,R.sessionId,N);le(a,$),S.current=Date.now(),i==null||i($.navigation.screenNumber)}catch(N){a.setState({loading:!1}),O(N.message)}}},[w,a,i,O,E]),j=x.useCallback(async()=>{const R=a.getState();if(!R.loading){a.setState({loading:!0}),a.getState().clearError(),E();try{const Y=Ce(a),N=await Yn(w,R.sessionId,Y);le(a,N),S.current=Date.now(),i==null||i(N.navigation.screenNumber)}catch(Y){a.setState({loading:!1}),O(Y.message)}}},[w,a,i,O,E]),I=x.useCallback(async()=>{const R=a.getState();if(!(R.loading||!R.evaluateFlowValidation())){a.setState({loading:!0}),a.getState().clearError(),E();try{const N=Ce(a),$=await Gn(w,R.sessionId,N);S.current=Date.now(),c($)}catch(N){a.setState({loading:!1}),O(N.message)}}},[w,a,c,O,E]),k={...f==null?void 0:f.theme,...e},U=(t??y??"standard")==="conversational",A=U&&!m.isLastScreen;We(A,0,V),Xe(A,0,V);const G=k.darkMode??!1,P={};k.color&&(P["--fbre-theme-color"]=k.color);const B=g[0],q=B?h[B]:void 0,H=q==null?void 0:q.nextButtonLabel,X=q==null?void 0:q.backButtonLabel;return u&&g.length===0?p.jsx("div",{className:"fbre-container",children:p.jsxs("div",{className:"fbre-remote-loading",children:[p.jsx("div",{className:"fbre-spinner"}),p.jsx("p",{children:"Loading form..."})]})}):d&&g.length===0?p.jsx("div",{className:"fbre-container",children:p.jsxs("div",{className:"fbre-remote-error",children:[p.jsx("p",{children:"Failed to load form"}),p.jsx("p",{className:"fbre-remote-error__detail",children:d}),p.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:T,style:{marginTop:12},children:"Retry"})]})}):g.length===0?null:p.jsx(ve.Provider,{value:a,children:p.jsxs("div",{className:"fbre-container","data-style":k.style??"clean","data-mode":G?"dark":"light","data-form-mode":U?"conversational":void 0,style:Object.keys(P).length>0?P:void 0,children:[p.jsx("div",{className:"fbre-screen-wrapper",children:p.jsx(Se,{screenIndex:0})}),p.jsx(et,{navigation:m,loading:u,onPrev:j,onNext:V,onComplete:I,nextButtonLabel:H,backButtonLabel:X}),p.jsxs("div",{className:`fbre-toast${v?" visible":""}`,children:[p.jsx("span",{children:v}),p.jsx("button",{type:"button",className:"fbre-toast__close",onClick:E,"aria-label":"Dismiss",children:"×"})]})]})})},et=({navigation:n,loading:s,onPrev:o,onNext:t,onComplete:e,nextButtonLabel:r,backButtonLabel:c})=>p.jsxs("div",{className:"fbre-controls",children:[p.jsx("div",{className:"fbre-controls__left",children:n.canGoBack&&p.jsx("button",{type:"button",className:"fbre-btn fbre-btn--back",onClick:o,disabled:s,children:c||"Back"})}),p.jsx("div",{className:"fbre-controls__center",children:p.jsxs("span",{className:"fbre-controls__progress",children:[n.screenNumber," / ",n.totalScreens]})}),p.jsx("div",{className:"fbre-controls__right",children:n.isLastScreen?p.jsx("button",{type:"button",className:"fbre-btn fbre-btn--complete",onClick:e,disabled:s,children:s?"Submitting...":r||"Complete"}):p.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:t,disabled:s,children:s?"Loading...":r||"Next"})})]});function nt(n,s,o,t,e){return!s&&!o&&!t&&!e?n:{...n,...e&&{mode:e},...s&&{theme:{...n.theme,...s}},...o&&{navigation:{...n.navigation,...o}},...t&&{controls:{...n.controls,...t}}}}const Ze=({flow:n,data:s,mode:o,theme:t,navigation:e,controls:r,screenIndex:c,context:i,storeRef:l,onFlowComplete:a,onScreenChange:u,onScreenValidationChange:d,apiCtx:m})=>{const f=x.useRef(null);f.current||(f.current=bn(),f.current.getState().loadFlow(n,s,i)),l&&(l.current=f.current),x.useEffect(()=>{f.current&&f.current.getState().loadFlow(n,s,i)},[n.uuid]),x.useEffect(()=>{if(f.current){const h=f.current.getState(),v=nt(h.config,t,e,r,o);v!==h.config&&f.current.setState({config:v})}},[o,t,e,r]);const y=i?JSON.stringify(i):"";x.useEffect(()=>{f.current&&i&&f.current.getState().updateContext(i)},[y]);const g=p.jsx(ve.Provider,{value:f.current,children:p.jsx(Wn,{screenIndex:c??0,onFlowComplete:a,onScreenChange:u,onScreenValidationChange:d})});return m?p.jsx(Ke.Provider,{value:m,children:g}):g},tt=({flowId:n,apiEndpoint:s,apiKey:o,data:t,mode:e,theme:r,navigation:c,controls:i,screenIndex:l,context:a,storeRef:u,onFlowComplete:d,onScreenChange:m,onScreenValidationChange:f})=>{const[y,g]=x.useState(null),[h,v]=x.useState(""),[C,b]=x.useState(null);return x.useEffect(()=>{g(null),v("");const S={apiEndpoint:s,apiKey:o};$n(S,n).then(w=>{g(w.data),b({config:S,flowId:w.id,flowVersionId:w.versionId,tenantId:w.tenantId})}).catch(w=>v(w.message))},[n,s,o]),h?p.jsx("div",{className:"fbre-container",children:p.jsxs("div",{className:"fbre-remote-error",children:[p.jsx("p",{children:"Failed to load form"}),p.jsx("p",{className:"fbre-remote-error__detail",children:h})]})}):!y||!C?p.jsx("div",{className:"fbre-container",children:p.jsxs("div",{className:"fbre-remote-loading",children:[p.jsx("div",{className:"fbre-spinner"}),p.jsx("p",{children:"Loading form..."})]})}):p.jsx(Ze,{flow:y,data:t,mode:e,theme:r,navigation:c,controls:i,screenIndex:l,context:a,storeRef:u,onFlowComplete:d,onScreenChange:m,onScreenValidationChange:f,apiCtx:C})},ot=n=>"sessionEndpoint"in n?p.jsx(Zn,{...n}):"flowId"in n&&n.flowId?p.jsx(tt,{...n}):p.jsx(Ze,{...n});exports.ApiError=re;exports.FBRE=ot;exports.TimeoutError=Qe;exports.addFBREEventListener=Mn;exports.removeFBREEventListener=Un;exports.useFBREApi=An;exports.useFBREStore=L;exports.useFBREStoreApi=ie;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),j=require("react"),K=require("zustand"),zt=require("@sonata-innovations/fiber-types"),U=require("@sonata-innovations/fiber-shared"),Wt=require("react-dom"),jt=new Map,$=(e,t)=>{jt.set(e,t)},_t=e=>jt.get(e),Yt=new Set(["header","text","divider","callout","table"]),Ne=e=>Yt.has(e),Gt=(e,t)=>{var o,l,r,i;if(t.includes(":")){const s=t.split(":"),a=e.components[s[0]];return(r=(l=(o=a==null?void 0:a.addedComponents)==null?void 0:o[parseInt(s[1])])==null?void 0:l[parseInt(s[2])])==null?void 0:r.value}return(i=e.components[t])==null?void 0:i.value},z=(e,t)=>{var l;const o=(l=e.properties)==null?void 0:l.validation;return!o||!o.rules||o.rules.length===0?[]:U.validateValue(e.value,o,t?r=>Gt(t,r):void 0)},Jt=e=>{var o;const t=(o=e.properties)==null?void 0:o.validation;return!t||!t.rules?!1:t.rules.some(l=>l.type==="required")},Q=e=>{var o,l;const t={...e};return Array.isArray((o=t.properties)==null?void 0:o.options)&&(t.properties={...t.properties,options:zt.normalizeOptions(t.properties.options)}),e.type==="computed"?(t.value=null,t.valid=!0):!Ne(e.type)&&e.type!=="group"&&e.type!=="repeater"&&(t.value=null,t.valid=!Jt(e)),(e.type==="checkbox"||e.type==="dropDownMulti")&&(t.value=[]),e.type==="radio"&&"options"in e.properties&&e.properties.options.length>0&&(t.value=e.properties.options[0].value),e.type==="toggleSwitch"&&(t.value=!1),e.type==="colorPicker"&&((l=e.properties)!=null&&l.defaultValue)&&(t.value=e.properties.defaultValue),e.type==="slider"&&(t.value="initValue"in e.properties?e.properties.initValue:"min"in e.properties?e.properties.min:0),t},me=(e,t,o)=>{var l;for(const r of o.rules)if(r.type==="matchesField"&&((l=r.params)!=null&&l.field)){const i=r.params.field;e[i]||(e[i]=[]),e[i].push({target:t,config:o})}},oe=(e,t)=>{const o=e.screens[t];return o?!o.components.some(r=>{var a;const i=e.components[r.uuid];if(!i)return!1;if(i.type==="group"||i.type==="repeater")return(a=i.addedComponents)==null?void 0:a.some(c=>c.some(d=>{const u=d.conditions&&"when"in d.conditions?d.conditions:void 0;return u&&U.isHiddenByCondition(u,e.conditionResults[d.uuid])?!1:!d.valid}));const s=i.conditions&&"when"in i.conditions?i.conditions:void 0;return U.isHiddenByCondition(s,e.conditionResults[i.uuid])?!1:i&&"valid"in i&&!i.valid}):!0};function Xt(e){const t={};for(const o of e){const l=U.extractFormulaReferences(o.formula);for(const r of l)t[r]||(t[r]=[]),t[r].includes(o.uuid)||t[r].push(o.uuid)}return t}function wt(e,t){return{resolveValue:o=>{if(o in t)return t[o];const l=te(e,o);if(!l)return null;const r=l.value;if(r==null||r==="")return null;const i=Number(r);return isNaN(i)?null:i},resolveOptionMetadata:(o,l)=>{var u;const r=te(e,o);if(!r)return null;const i=r.value;if(!i)return null;const s=(u=r.properties)==null?void 0:u.options;if(!Array.isArray(s))return null;const a=s.find(p=>p.value===i||p.label===i);if(!(a!=null&&a.metadata))return null;const c=a.metadata[l];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:o=>{for(const l of Object.keys(e.components)){const r=e.components[l];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const i=r.components.findIndex(a=>a.uuid===o);if(i===-1)continue;const s=[];for(const a of r.addedComponents){const c=a[i];if(!c)continue;const d=c.value;if(d==null||d==="")continue;const u=Number(d);isNaN(u)||s.push(u)}return s.length>0?s:null}return null}}}function qe(e){const t=e.calculations??[];if(t.length===0)return{};const o=U.topologicalSortCalculations(t),l={},r=wt(e,l);for(const i of o)l[i.uuid]=U.evaluateFormula(i.formula,r);return l}function $e(e,t){const o=e.calculationsByDependency,l=e.calculations??[];if(l.length===0||!o)return null;const r=new Set,i=[t];for(;i.length>0;){const u=i.shift(),p=o[u];if(p)for(const m of p)r.has(m)||(r.add(m),i.push(m))}if(r.size===0)return null;const s=U.topologicalSortCalculations(l),a={...e.calculationResults},c=wt(e,a);let d=!1;for(const u of s)if(r.has(u.uuid)){const p=U.evaluateFormula(u.formula,c);a[u.uuid]!==p&&(a[u.uuid]=p,d=!0)}return d?a:null}function Kt(e){const t={},o=l=>{var i;if(l.type!=="computed"||!((i=l.properties)!=null&&i.formula))return;const r=U.extractFormulaReferences(l.properties.formula);for(const s of r)t[s]||(t[s]=[]),t[s].includes(l.uuid)||t[s].push(l.uuid)};for(const l of Object.values(e))if(o(l),(l.type==="repeater"||l.type==="group")&&l.components)for(const r of l.components)o(r);return t}function Ct(e,t,o,l){var c,d;const r=e.components[o],i=((c=r==null?void 0:r.components)==null?void 0:c.map(u=>u.uuid))??[],s=(d=r==null?void 0:r.addedComponents)==null?void 0:d[l],a=new Map;if(s)for(let u=0;u<s.length;u++){const p=i[u];p&&a.set(p,s[u])}return{resolveValue:u=>{if(u in t)return t[u];const p=a.get(u);if(p){const g=p.value;if(g==null||g==="")return null;const b=Number(g);return isNaN(b)?null:b}const m=te(e,u);if(!m)return null;const f=m.value;if(f==null||f==="")return null;const h=Number(f);return isNaN(h)?null:h},resolveOptionMetadata:(u,p)=>{var _;const f=a.get(u)??te(e,u);if(!f)return null;const h=f.value;if(!h)return null;const g=(_=f.properties)==null?void 0:_.options;if(!Array.isArray(g))return null;const b=g.find(N=>N.value===h||N.label===h);if(!(b!=null&&b.metadata))return null;const v=b.metadata[p];if(v==null)return null;const x=Number(v);return isNaN(x)?null:x},resolveRepeaterValues:u=>{for(const p of Object.keys(e.components)){const m=e.components[p];if(m.type!=="repeater"||!m.addedComponents||!m.components)continue;const f=m.components.findIndex(g=>g.uuid===u);if(f===-1)continue;const h=[];for(const g of m.addedComponents){const b=g[f];if(!b)continue;const v=b.value;if(v==null||v==="")continue;const x=Number(v);isNaN(x)||h.push(x)}return h.length>0?h:null}return null}}}function Se(e,t){return{resolveValue:o=>{if(o in t)return t[o];const l=te(e,o);if(!l)return null;const r=l.value;if(r==null||r==="")return null;const i=Number(r);return isNaN(i)?null:i},resolveOptionMetadata:(o,l)=>{var u;const r=te(e,o);if(!r)return null;const i=r.value;if(!i)return null;const s=(u=r.properties)==null?void 0:u.options;if(!Array.isArray(s))return null;const a=s.find(p=>p.value===i||p.label===i);if(!(a!=null&&a.metadata))return null;const c=a.metadata[l];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:o=>{for(const l of Object.keys(e.components)){const r=e.components[l];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const i=r.components.findIndex(a=>a.uuid===o);if(i===-1)continue;const s=[];for(const a of r.addedComponents){const c=a[i];if(!c)continue;const d=c.value;if(d==null||d==="")continue;const u=Number(d);isNaN(u)||s.push(u)}return s.length>0?s:null}return null}}}function ze(e){var o,l;const t=e.calculationResults??{};for(const r of Object.values(e.components))if(r.type==="computed"&&((o=r.properties)!=null&&o.formula)){const i=Se(e,t),s=U.evaluateFormula(r.properties.formula,i);r.value=s}for(const r of Object.values(e.components))if((r.type==="repeater"||r.type==="group")&&r.addedComponents&&r.components)for(let i=0;i<r.addedComponents.length;i++){const s=r.addedComponents[i];for(let a=0;a<s.length;a++){const c=s[a],d=r.components[a];if((d==null?void 0:d.type)==="computed"&&((l=d.properties)!=null&&l.formula)){const u=r.type==="repeater"?Ct(e,t,r.uuid,i):Se(e,t),p=U.evaluateFormula(d.properties.formula,u);c.value=p}}}}function Zt(e,t){var s,a;const o=e.computedByDependency;if(!o)return!1;const l=o[t];if(!l||l.length===0)return!1;const r=e.calculationResults??{};let i=!1;for(const c of l){const d=e.components[c];if(d&&d.type==="computed"&&((s=d.properties)!=null&&s.formula)){const u=Se(e,r),p=U.evaluateFormula(d.properties.formula,u);d.value!==p&&(e.components[c]={...d,value:p},i=!0);continue}for(const u of Object.values(e.components))if((u.type==="repeater"||u.type==="group")&&u.components&&u.addedComponents){const p=u.components.findIndex(f=>f.uuid===c);if(p===-1)continue;const m=u.components[p];if((m==null?void 0:m.type)!=="computed"||!((a=m.properties)!=null&&a.formula))continue;for(let f=0;f<u.addedComponents.length;f++){const h=u.addedComponents[f][p];if(!h)continue;const g=u.type==="repeater"?Ct(e,r,u.uuid,f):Se(e,r),b=U.evaluateFormula(m.properties.formula,g);h.value!==b&&(u.addedComponents[f][p]={...h,value:b},i=!0)}}}return i}const Nt=(e,t)=>{var o,l;if(t.includes(":")){const r=t.split(":"),i=e[r[0]];return(l=(o=i==null?void 0:i.addedComponents)==null?void 0:o[parseInt(r[1])])==null?void 0:l[parseInt(r[2])]}return e[t]},Ce=(e,t)=>{for(const o of e.screenOrder)if(e.screens[o].components.some(r=>r.uuid===t))return o;return null},Qt=(e,t)=>{if(!t.includes(":"))return null;const o=t.split(":");if(o.length!==3)return null;const l=o[0],r=parseInt(o[2]),i=e.components[l];if(!i||i.type!=="repeater"||!i.components)return null;const s=i.components[r];return(s==null?void 0:s.uuid)??null},at=(e,t,o,l,r)=>{const i=t(),s=i.groupComponentMap[o]??o,a=nn(e,t,s),c={components:i.components,groupComponentMap:i.groupComponentMap},d=z(l,c);l.valid=d.length===0;const u={...i.validationErrors,[o]:d},p=i.validationsByDependency[o];if(p)for(const _ of p){const N=te(i,_.target);if(N){const S=z(N,c);N.valid=S.length===0,u[_.target]=S}}const m=Ce(i,r),f={components:{...i.components},validationErrors:u};if(a&&(f.conditionResults=a),m){const _={...i,...f};f.screenValidity={...i.screenValidity,[m]:oe(_,m)}}const h={...i,...f},g=o.includes(":")?Qt(h,o):null,b=[],v=_=>{if(Zt(h,_)){const N=h.computedByDependency[_]??[];for(const S of N)b.includes(S)||(b.push(S),v(S))}};v(s),g&&g!==s&&v(g);let x=$e(h,s);if(g&&g!==s){const _=x?{...h,calculationResults:x}:h,N=$e(_,g);N&&(x=N)}for(const _ of b){const N=x?{...h,calculationResults:x}:h,S=$e(N,_);S&&(x=S)}x&&(f.calculationResults=x),e(f)},en=(e,t)=>({updateComponentValue:(o,l)=>{var s,a;const r=t();if(o.includes(":")){const c=o.split(":"),d=c[0],u=parseInt(c[1]),p=parseInt(c[2]),m=r.components[d];if(!((a=(s=m==null?void 0:m.addedComponents)==null?void 0:s[u])!=null&&a[p]))return;const f=m.addedComponents[u][p].value!==l;if(m.addedComponents[u][p]={...m.addedComponents[u][p],value:l},f){at(e,t,o,m.addedComponents[u][p],d);return}e({components:{...r.components}});return}const i=r.components[o];if(i){if(i.type==="group"||i.type==="repeater"){e({components:{...r.components}});return}if(l===i.value){e({selectionTick:t().selectionTick+1});return}i.value=l,at(e,t,o,i,o)}},addGroupIteration:o=>{const l=t(),r=l.components[o];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const i={...l.conditionsByDependency},s=r.components.map((d,u)=>{const p=Q(d);if(p.uuid=[o,r.addedComponents.length,u].join(":"),l.groupComponentMap[p.uuid]=d.uuid,p.conditions&&Object.keys(p.conditions).length>0){const f="when"in p.conditions?p.conditions:null;f&&(p.conditions=f,re(i,p.uuid,f,"component"))}const m=z(p);return p.valid=m.length===0,p});r.addedComponents.push(s);const a=Ce(l,o),c={...l.screenValidity};return a&&(c[a]=oe({...l},a)),e({components:{...l.components},groupComponentMap:{...l.groupComponentMap},conditionsByDependency:i,screenValidity:c}),r.addedComponents},addRepeaterIteration:o=>{const l=t(),r=l.components[o];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const i={...l.conditionsByDependency},s=r.components.map((p,m)=>{const f=Q(p);if(f.uuid=[o,r.addedComponents.length,m].join(":"),f.conditions&&Object.keys(f.conditions).length>0){const g="when"in f.conditions?f.conditions:null;g&&(f.conditions=g,re(i,f.uuid,g,"component"))}const h=z(f);return f.valid=h.length===0,f});r.addedComponents.push(s);const a=Ce(l,o),c={...l.screenValidity};a&&(c[a]=oe({...l},a));const d={...l,components:{...l.components}};ze(d);const u=qe(d);return e({components:{...l.components},conditionsByDependency:i,screenValidity:c,calculationResults:u}),r.addedComponents},removeRepeaterIteration:(o,l)=>{var g;const r=t(),i=r.components[o];if(!i||i.type!=="repeater"||!i.addedComponents)return;const s=((g=i.properties)==null?void 0:g.minIterations)??1;if(i.addedComponents.length<=s)return;const a=i.addedComponents[l],c=new Set(a.map(b=>b.uuid));i.addedComponents.splice(l,1);const d={...r.conditionsByDependency},u={...r.validationErrors};for(const b of c)delete u[b],delete d[b];for(const b of Object.keys(d)){const v=d[b],x=v.filter(_=>!c.has(_.target));x.length===0?delete d[b]:x.length!==v.length&&(d[b]=x)}for(let b=l;b<i.addedComponents.length;b++)i.addedComponents[b].forEach((v,x)=>{const _=v.uuid,N=[o,b,x].join(":");if(_!==N){v.uuid=N,_ in u&&(u[N]=u[_],delete u[_]),_ in d&&(d[N]=d[_],delete d[_]);for(const S of Object.values(d))for(const R of S)R.target===_&&(R.target=N)}});const p=Ce(r,o),m={...r.screenValidity};p&&(m[p]=oe({...r},p));const f={...r,components:{...r.components}};ze(f);const h=qe(f);e({components:{...r.components},conditionsByDependency:d,validationErrors:u,screenValidity:m,calculationResults:h})}}),te=(e,t)=>Nt(e.components,t),re=(e,t,o,l)=>{const r=new Set;for(const s of o.when.rules)r.add(s.source);const i={target:t,type:l,config:o};for(const s of r)e[s]||(e[s]=[]),e[s].push(i)},tn=(e,t)=>{var o,l;return t.includes(":")?(o=te(e,t))==null?void 0:o.value:(l=e.components[t])==null?void 0:l.value},ce=(e,t)=>U.evaluateConditionConfig(t,(o,l)=>(l==null?void 0:l.sourceType)==="context"?e.externalContext[l.source]:tn(e,o)),nn=(e,t,o)=>{const l=t(),r=l.conditionsByDependency[o];if(!r||r.length===0)return null;let i=!1;const s={...l.conditionResults};for(const a of r){const c=ce(l,a.config);s[a.target]!==c&&(s[a.target]=c,i=!0)}return i?s:null},sn=e=>{const t={},o=new Set;for(const l of Object.values(e.conditionsByDependency))for(const r of l)o.has(r.target)||(o.add(r.target),t[r.target]=ce(e,r.config));return t},Ve=e=>{if(!e||Ne(e.type))return null;const t="label"in e.properties?e.properties.label:"",o={uuid:e.uuid,type:e.type,value:e.value};return t&&(o.label=t),o},ct=e=>{if(e.conditions&&"when"in e.conditions)return e.conditions},rn=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},o=r=>{const i=e.screens[r];if(!i)return!1;const s=i.conditions&&"when"in i.conditions?i.conditions:void 0;return U.isHiddenByCondition(s,e.conditionResults[r])};t.screens=e.screenOrder.filter(r=>!o(r)).map(r=>{const i=e.screens[r],s={uuid:r,components:i.components.map(a=>{const c=e.components[a.uuid];if(!c)return null;const d=ct(c);if(U.isHiddenByCondition(d,e.conditionResults[a.uuid]))return null;if((c.type==="group"||c.type==="repeater")&&c.addedComponents){const u=Ve(c);return u?{...u,components:c.addedComponents.map(p=>p.filter(m=>{const f=ct(m);return!U.isHiddenByCondition(f,e.conditionResults[m.uuid])}).map(m=>Ve(m)).filter(m=>m!==null))}:null}return Ve(c)}).filter(a=>a!==null)};return i.label&&(s.label=i.label),s});const l=e.calculations??[];if(l.length>0){const r=e.calculationResults??{};t.calculations=l.map(i=>{const s=r[i.uuid]??null,a={uuid:i.uuid,label:i.label,value:s};return s!==null&&(a.formattedValue=U.formatCalculationResult(s,i.format,i.decimalPlaces,i.currencySymbol)),a})}return t},Te=j.createContext(null);function B(e){const t=j.useContext(Te);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return K.useStore(t,e)}const ve=()=>{const e=j.useContext(Te);if(!e)throw new Error("useFBREStoreApi must be used within an FBRE provider");return e},ge=e=>!e||Object.keys(e).length===0?null:"when"in e?e:null,on=[],ln=()=>K.createStore((e,t)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,loadFlow:(o,l,r)=>{var R;const i={},s=[],a={},c={},d={},u={},p={},m={},f={};o.screens.forEach(C=>{const k=ge(C.conditions),y=k?{...C,conditions:k}:{...C};i[C.uuid]=y,s.push(C.uuid),k&&re(u,C.uuid,k,"screen"),C.components.forEach(w=>{var I;const E=ge(w.conditions),T=Q(w);if(E&&(T.conditions=E),a[w.uuid]=T,E&&re(u,w.uuid,E,"component"),(I=T.properties)!=null&&I.validation&&me(p,w.uuid,T.properties.validation),(w.type==="group"||w.type==="repeater")&&w.components){const L=a[w.uuid];L.addedComponents||(L.addedComponents=[]);const F=w.properties??{},H=w.type==="repeater"?F.initialData:void 0,P=w.type==="repeater"?F.minIterations:void 0,G=H?H.length:w.type==="repeater"&&P&&P>1?P:1;for(let J=0;J<G;J++){const ee=w.components.map((M,X)=>{var ae;const O=Q(M);O.uuid=[w.uuid,L.addedComponents.length,X].join(":"),H&&H[J]&&M.uuid in H[J]&&(O.value=H[J][M.uuid]),w.type==="group"&&(c[O.uuid]=M.uuid),J===0&&(d[M.uuid]=O.uuid);const Y=ge(O.conditions);Y&&(O.conditions=Y,re(u,O.uuid,Y,"component")),(ae=O.properties)!=null&&ae.validation&&me(p,O.uuid,O.properties.validation);const ie=z(O);return O.valid=ie.length===0,ie.length>0&&(m[O.uuid]=ie),O});L.addedComponents.push(ee)}}})}),l&&l.screens.forEach(C=>{const k=s.indexOf(C.uuid);k<0||C.components.forEach(y=>{const w=a[y.uuid];if(w)if((w.type==="group"||w.type==="repeater")&&y.components&&w.addedComponents){if(y.components.length>1){const E=w.addedComponents.length,T=y.components.length-E,D=o.screens[k].components.find(I=>I.uuid===w.uuid);for(let I=0;I<T;I++)if(D!=null&&D.components){const L=D.components.map((F,H)=>{var ee;const P=Q(F);P.uuid=[w.uuid,w.addedComponents.length,H].join(":"),w.type==="group"&&(c[P.uuid]=F.uuid),d[F.uuid]||(d[F.uuid]=P.uuid);const G=ge(P.conditions);G&&(P.conditions=G,re(u,P.uuid,G,"component")),(ee=P.properties)!=null&&ee.validation&&me(p,P.uuid,P.properties.validation);const J=z(P);return P.valid=J.length===0,J.length>0&&(m[P.uuid]=J),P});w.addedComponents.push(L)}}y.components.forEach(E=>{E.forEach(T=>{for(const D of w.addedComponents){const I=D.find(L=>L.uuid===T.uuid);if(I){I.value=T.value;const L=z(I);I.valid=L.length===0,m[I.uuid]=L;break}}})})}else{w.value=y.value;const E=z(w);w.valid=E.length===0,m[w.uuid]=E}})});for(const C of Object.keys(a)){const k=a[C];if(!(k.type==="group"||k.type==="repeater"||!((R=k.properties)!=null&&R.validation))&&!(C in m)){const y=z(k);k.valid=y.length===0,y.length>0&&(m[C]=y)}}const h={...t(),externalContext:r??{},screens:i,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},g=sn(h);h.conditionResults=g,s.forEach(C=>{f[C]=oe(h,C)});const b=Kt(a),v={...h,computedByDependency:b,calculationResults:{},screenValidity:f};ze(v);const x=o.calculations??[],_=Xt(x),N={...v,calculations:x},S=qe(N);e({flowUUID:o.uuid,metadata:o.metadata,config:o.config??{},externalContext:r??{},screens:i,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:g,screenValidity:f,validationErrors:m,validationsByDependency:p,calculations:x,calculationResults:S,calculationsByDependency:_,computedByDependency:b})},updateContext:o=>{const l=t(),r=l.externalContext,i=[];for(const d of Object.keys(o))r[d]!==o[d]&&i.push(d);for(const d of Object.keys(r))!(d in o)&&!i.includes(d)&&i.push(d);if(i.length===0)return;const s={...l.conditionResults};let a=!1;const c=new Set;for(const d of i){const u=l.conditionsByDependency[d];if(!(!u||u.length===0))for(const p of u){if(c.has(p.target))continue;c.add(p.target);const m={...l,externalContext:o},f=ce(m,p.config);s[p.target]!==f&&(s[p.target]=f,a=!0)}}if(a){const d={...l,conditionResults:s},u={};for(const p of l.screenOrder)u[p]=oe(d,p);e({externalContext:o,conditionResults:s,screenValidity:u})}else e({externalContext:o})},...en(e,t),getFlowData:()=>rn(t()),getScreenByIndex:o=>{const l=t();return o<0||o>=l.screenOrder.length?null:l.screens[l.screenOrder[o]]},getScreenValidity:o=>{const l=t();return o<0||o>=l.screenOrder.length?!0:l.screenValidity[l.screenOrder[o]]??!0},getValidationErrors:o=>t().validationErrors[o]??on,evaluateFlowValidation:()=>{const o=t(),l={};let r=!0;return o.screenOrder.forEach(i=>{const s=oe(o,i);l[i]=s,s||(r=!1)}),e({screenValidity:l}),r},getMaxScreenCount:()=>t().screenOrder.length-1,getCalculationResult:o=>t().calculationResults[o]??null})),an=({uuid:e})=>{var a;const t=B(c=>c.components[e]),o=B(c=>c.conditionResults[e]);if(!t)return null;const l=t.conditions&&"when"in t.conditions?t.conditions:void 0;if(U.isHiddenByCondition(l,o))return null;const r=_t(t.type);if(!r)return console.warn(`FBRE: No renderer for component type "${t.type}"`),null;const i=(a=t.properties)==null?void 0:a.width,s=i&&i!=="full"?`fbre-component fbre-width-${i}`:"fbre-component";return n.jsx("div",{className:s,"data-uuid":e,children:n.jsx(r,{uuid:e})})},We=({screenIndex:e})=>{const t=B(o=>{const l=o.screenOrder[e];return l?o.screens[l]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(o=>n.jsx(an,{uuid:o.uuid},o.uuid))}):null},Z=({size:e=14})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"4,12 9.5,17.5 20,7"})}),de=({size:e=14})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[n.jsx("rect",{x:"2",y:"3",width:"12",height:"11",rx:"1"}),n.jsx("line",{x1:"2",y1:"7",x2:"14",y2:"7"}),n.jsx("line",{x1:"5",y1:"1",x2:"5",y2:"4"}),n.jsx("line",{x1:"11",y1:"1",x2:"11",y2:"4"})]}),Ye=({size:e=14})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[n.jsx("circle",{cx:"8",cy:"8",r:"6"}),n.jsx("line",{x1:"8",y1:"4.5",x2:"8",y2:"8"}),n.jsx("line",{x1:"8",y1:"8",x2:"11",y2:"10"})]}),xe=({size:e=12})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M7 10l5 5 5-5z"})}),cn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"})}),dn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"})}),un=({size:e=16})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})}),pn=({size:e=16})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})}),fn=({size:e=20})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"})}),Je=({size:e=28})=>n.jsx("svg",{viewBox:"0 0 24 24",width:e,height:e,children:n.jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})}),mn=({size:e=16})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"})}),hn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),n.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),bn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("polyline",{points:"9,12 11.5,14.5 16,9.5"})]}),vn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),xn=({size:e=16})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3,6 5,6 21,6"}),n.jsx("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"})]}),gn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 18h6"}),n.jsx("path",{d:"M10 22h4"}),n.jsx("path",{d:"M12 2a7 7 0 00-4 12.7V17h8v-2.3A7 7 0 0012 2z"})]}),yn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M3 11l18-5v12L3 13v-2z"}),n.jsx("path",{d:"M11.6 16.8a3 3 0 11-5.8-1.6"})]}),jn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"}),n.jsx("path",{d:"M13.73 21a2 2 0 01-3.46 0"})]}),_n=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),wn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0110 0v4"})]}),St=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"})}),Cn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"}),n.jsx("line",{x1:"4",y1:"22",x2:"4",y2:"15"})]}),Nn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z"})}),Sn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polygon",{points:"13,2 3,14 12,14 11,22 21,10 12,10 13,2"})}),kn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M12 20h9"}),n.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 013 3L7 19l-4 1 1-4L16.5 3.5z"})]}),En=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("path",{d:"M9.09 9a3 3 0 015.83 1c0 2-3 3-3 3"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),Rn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3H14z"}),n.jsx("path",{d:"M7 22H4a2 2 0 01-2-2v-7a2 2 0 012-2h3"})]}),Tn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("circle",{cx:"12",cy:"12",r:"10"})}),Ln=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("rect",{x:"12",y:"1",width:"15.56",height:"15.56",rx:"2",transform:"rotate(45 12 1)"})}),Ae={info:hn,check:bn,warning:vn,question:En,lightbulb:gn,megaphone:yn,bell:jn,shield:_n,lock:wn,heart:St,flag:Cn,bookmark:Nn,zap:Sn,pencil:kn,star:Je},Mn={star:Je,heart:St,thumbsUp:Rn,circle:Tn,diamond:Ln},ye=({position:e,screenIndex:t,maxScreenIndex:o,allowInvalidTransition:l,screenValidity:r,summaryEnabled:i,summaryActive:s,atMaxScreen:a,nextButtonLabel:c,backButtonLabel:d,completionLoading:u,nextScreen:p,prevScreen:m,onFlowComplete:f})=>{const h=u??!1;if(e==="back"){const _=t===0&&!s||h;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--secondary",disabled:_,onClick:m,children:[n.jsx(un,{}),d||"Back"]})}const g=i?a&&s:a,b=i?a?s?"Done":"Review":"Next":a?"Done":"Next";if(o===0){const _=i?s?"Complete":"Review":"Complete",N=h||!r;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:N,onClick:()=>{i&&!s?p():f()},children:[c||_,h?n.jsx("span",{className:"fbre-btn__spinner"}):n.jsx(Z,{size:16})]})}const v=h||!l&&!r||b==="Done"&&!r,x=()=>{g?f():p()};return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:v,onClick:x,children:[c||b,h?n.jsx("span",{className:"fbre-btn__spinner"}):g?n.jsx(Z,{size:16}):n.jsx(pn,{})]})},In=({current:e,total:t,stepperStyle:o})=>{if(t<=1)return null;const l=t>1?e/(t-1)*100:100,i=!!o&&o!=="default"||t<=6;return n.jsxs(n.Fragment,{children:[i&&n.jsx("div",{className:"fbre-stepper fbre-stepper--dots",children:Array.from({length:t},(s,a)=>n.jsx("div",{className:`fbre-stepper__dot${a===e?" active":a<e?" completed":""}`},a))}),i&&n.jsxs("div",{className:"fbre-stepper fbre-stepper--bar-alt",children:[n.jsx("div",{className:"fbre-stepper__track",children:n.jsx("div",{className:"fbre-stepper__fill",style:{width:`${l}%`}})}),n.jsxs("span",{className:"fbre-stepper__counter",children:[e+1," of ",t]})]}),!i&&n.jsx("div",{className:"fbre-stepper fbre-stepper--bar",children:n.jsx("div",{className:"fbre-stepper__fill",style:{width:`${l}%`}})})]})},Dn=({current:e,total:t})=>t<=1?null:n.jsxs("div",{className:"fbre-stepper-text",children:["Step ",e+1," of ",t]}),Bn=e=>{const t=e.controlsLayout??"default",l=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text"&&e.maxScreenIndex>0,r=e.screenIndex>0||e.summaryActive,i=r?2:1,s=l?n.jsx(In,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):null;if(t==="default"){const a=!r&&!l;return n.jsxs("div",{className:"fbre-controls fbre-controls--default","data-button-count":i,"data-solo":a?"true":void 0,children:[r?n.jsx(ye,{position:"back",...e}):n.jsx("div",{}),s??n.jsx("div",{}),n.jsx(ye,{position:"next",...e})]})}return n.jsxs("div",{className:`fbre-controls fbre-controls--${t}`,"data-button-count":i,children:[s&&n.jsx("div",{className:"fbre-controls__stepper",children:s}),n.jsxs("div",{className:"fbre-controls__row",children:[r&&n.jsx(ye,{position:"back",...e}),n.jsx(ye,{position:"next",...e})]})]})},kt=({component:e})=>{const{uuid:t,label:o,type:l,value:r,components:i}=e,s=()=>{if(r!=null)switch(l){case"fileUpload":return r.name;case"inputText":case"inputTextArea":case"inputNumber":case"dropDown":case"radio":case"rating":case"slider":return r.toString();case"computed":return typeof r=="number"?r.toString():"—";case"toggleSwitch":return r?"Yes":"No";case"checkbox":case"dropDownMulti":return r.length===0?"No options selected":r.join(", ")}return"No response given"};if(l==="signature"&&r){const d=typeof r=="string"&&r.startsWith("data:");return n.jsxs("div",{className:"fbre-summary__item",children:[n.jsx("div",{className:"fbre-summary__item-label",children:o}),n.jsx("div",{className:"fbre-summary__item-value",children:d?n.jsx("img",{src:r,alt:"Signature",style:{maxWidth:"100%",maxHeight:80}}):n.jsx("span",{style:{fontFamily:'"Brush Script MT", "Segoe Script", "Dancing Script", cursive',fontSize:24},children:r})})]})}const a=()=>i?i.map((d,u)=>n.jsx("div",{children:d.map(p=>n.jsx(kt,{component:p},p.uuid))},`${t}-${u}`)):null,c=r==null||typeof r=="string"&&r.length===0||Array.isArray(r)&&r.length===0;return n.jsxs("div",{className:`fbre-summary__item${l==="group"||l==="repeater"?" fbre-summary__item--group":""}`,children:[n.jsx("div",{className:"fbre-summary__item-label",children:o}),l!=="group"&&l!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${c?" fbre-summary__item-value--empty":""}`,children:s()}),(l==="group"||l==="repeater")&&a()]})},On={sm:"12px",lg:"18px",xl:"24px"},Et=/\$\{([^}]+)\}/g,Le=(e,t)=>{const o=e.replace(Et,(l,r)=>{const i=t.resolveCalculation(r);if(i!==null)return dt(i);const s=t.resolveComponentValue(r);return s!==null?dt(s):""});return Rt(o)},le=(e,t)=>e.replace(Et,(o,l)=>{const r=t.resolveCalculation(l);if(r!==null)return r;const i=t.resolveComponentValue(l);return i!==null?i:""}),dt=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Rt=e=>{let t=e;const o=/\[b.*?\]([\s\S]*?)\[\/b\]/g,l=/\[i.*?\]([\s\S]*?)\[\/i\]/g,r=/\[s\s+size=["'](sm|lg|xl)["']\]([\s\S]*?)\[\/s\]/g,i=/\[l.*?href=["']([\s\S]*?)["'].*?\]([\s\S]*?)\[\/l\]/g;return t=t.replace(o,"<strong>$1</strong>"),t=t.replace(l,"<em>$1</em>"),t=t.replace(r,(s,a,c)=>{const d=On[a];return d?`<span style="font-size:${d}">${c}</span>`:c}),t=t.replace(i,'<a href="$1" target="_blank" rel="noopener noreferrer nofollow">$2</a>'),t=t.replace(/\n/g,"<br>"),t};function ue(){const e=B(r=>r.components),t=B(r=>r.templateComponentMap),o=B(r=>r.calculations),l=B(r=>r.calculationResults);return j.useMemo(()=>{const r=new Map(o.map(s=>[s.uuid,s])),i=s=>{var p,m;const a=e[s];if(a)return a;const c=t[s];if(!c)return;const d=c.split(":"),u=e[d[0]];return(m=(p=u==null?void 0:u.addedComponents)==null?void 0:p[parseInt(d[1])])==null?void 0:m[parseInt(d[2])]};return{resolveComponentValue:s=>{const a=i(s);if(!a)return null;const c=a.value;return c==null||c===""?null:Array.isArray(c)?c.join(", "):String(c)},resolveCalculation:s=>{const a=r.get(s);if(!a)return null;const c=l[s]??null;return U.formatCalculationResult(c,a.format,a.decimalPlaces,a.currencySymbol)}}},[e,t,o,l])}const $n=({screen:e,showToggle:t})=>{const o=ue(),[l,r]=j.useState(!0);return n.jsxs("div",{children:[n.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>t&&r(!l),children:[e.label&&n.jsx("span",{className:"fbre-summary__screen-label",children:le(e.label,o)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${l?"":" collapsed"}`,children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${l?"":" collapsed"}`,children:e.components.map(i=>n.jsx(kt,{component:i},i.uuid))})]})},ut=()=>{const e=ve(),t=B(r=>r.components),o=j.useMemo(()=>e.getState().getFlowData(),[e,t]),l=o.screens.length;return n.jsxs("div",{className:"fbre-summary",children:[n.jsx("h2",{className:"fbre-summary__title",children:"Review"}),n.jsx("div",{className:"fbre-summary__body",children:o.screens.map(r=>n.jsx($n,{screen:r,showToggle:l>1},r.uuid))})]})},Tt=(e,t,o)=>t?!U.isHiddenByCondition(t,o[e]):!0,ke=(e,t)=>{const o=e.screenOrder.length-1;let l=t+1;for(;l<=o;){const r=e.screenOrder[l],i=e.screens[r],s=i!=null&&i.conditions&&"when"in i.conditions?i.conditions:void 0;if(Tt(r,s,e.conditionResults))return l;l++}return null},Vn=(e,t)=>{let o=t-1;for(;o>=0;){const l=e.screenOrder[o],r=e.screens[l],i=r!=null&&r.conditions&&"when"in r.conditions?r.conditions:void 0;if(Tt(l,i,e.conditionResults))return o;o--}return 0},Xe=new Set(["radio","yesNo","cardSelect","dropDown"]),An=500;function Lt(e,t,o){const l=ve(),r=j.useRef(null),i=j.useRef(""),s=j.useRef(0);j.useEffect(()=>{if(!e)return;const a=l.getState(),c=pt(a,t);c&&(i.current=ft(a.components,c)),s.current=a.selectionTick},[e,t,l]),j.useEffect(()=>{if(!e)return;const a=l.subscribe(c=>{const d=pt(c,t);if(!d)return;const u=c.selectionTick,p=u!==s.current;p&&(s.current=u);const m=ft(c.components,d);if(m===i.current&&!p)return;const f=i.current;if(i.current=m,!(m!==f?Fn(c.components,d,f):p&&Pn(c.components,d))||ke(c,t)===null)return;const b=c.screenOrder[t];b&&c.screenValidity[b]===!1||(r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{r.current=null,o()},An))});return()=>{a(),r.current&&(clearTimeout(r.current),r.current=null)}},[e,t,l,o]),j.useEffect(()=>()=>{r.current&&(clearTimeout(r.current),r.current=null)},[t])}function pt(e,t){const o=e.screenOrder[t];if(!o)return null;const l=e.screens[o];return l?l.components.map(r=>r.uuid):null}function ft(e,t){const o=[];for(const l of t){const r=e[l];!r||!Xe.has(r.type)||o.push(`${l}=${JSON.stringify(r.value??null)}`)}return o.join("|")}function Fn(e,t,o){const l=new Map;for(const r of o.split("|")){const i=r.indexOf("=");i>0&&l.set(r.slice(0,i),r.slice(i+1))}for(const r of t){const i=e[r];if(!i||!Xe.has(i.type))continue;const s=JSON.stringify(i.value??null),a=l.get(r)??"null";if(s!==a&&s!=="null")return!0}return!1}function Pn(e,t){for(const o of t){const l=e[o];if(!(!l||!Xe.has(l.type))&&l.value!==null&&l.value!==void 0)return!0}return!1}function Mt(e,t,o){const l=ve();j.useEffect(()=>{if(!e)return;const r=i=>{if(i.key!=="Enter")return;const s=i.target;if(s.tagName!=="INPUT"||!s.closest(".fbre-container"))return;const a=l.getState();if(ke(a,t)===null)return;const d=a.screenOrder[t];d&&a.screenValidity[d]===!1||(i.preventDefault(),o())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,o,l])}const It=j.createContext(null),mt=[],A=e=>{const t=j.useContext(It),o=B(a=>{var c;return(c=a.components[e])==null?void 0:c.value}),l=B(a=>{var c;return(c=a.components[e])==null?void 0:c.properties}),r=B(a=>{var c;return(c=a.components[e])==null?void 0:c.valid}),i=B(a=>a.validationErrors[e]??mt),s=B(a=>a.updateComponentValue);return t?{value:t.value,properties:t.properties,valid:t.valid,validationErrors:mt,updateValue:s}:{value:o,properties:l,valid:r,validationErrors:i,updateValue:s}},Un=({uuid:e})=>{const{properties:t}=A(e),o=ue(),l=t==null?void 0:t.value;if(!l)return null;const r=le(l,o);return n.jsx("h2",{className:"fbre-header",children:r})};$("header",Un);const Hn=({uuid:e})=>{const{properties:t}=A(e),o=ue(),l=t==null?void 0:t.value;return l==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:Le(l,o)}})};$("text",Hn);const qn=({uuid:e})=>{const{properties:t}=A(e),o=(t==null?void 0:t.textAlign)??"center",l=o==="left"?" fbre-divider--left":o==="right"?" fbre-divider--right":"";return n.jsx("div",{className:`fbre-divider${l}`,children:t!=null&&t.value?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fbre-divider__line"}),n.jsx("span",{className:"fbre-divider__label",children:t.value}),n.jsx("div",{className:"fbre-divider__line"})]}):n.jsx("div",{className:"fbre-divider__line"})})};$("divider",qn);const zn={info:"info",success:"check",warning:"warning",neutral:void 0},Wn=({uuid:e})=>{const{properties:t}=A(e),o=ue(),l=t==null?void 0:t.value,r=t==null?void 0:t.title,i=(t==null?void 0:t.variant)||"info",s=t==null?void 0:t.icon;if(!l&&!r)return null;let a;if(s==="none")a=void 0;else if(s&&Ae[s])a=Ae[s];else{const d=zn[i];a=d?Ae[d]:void 0}const c=`fbre-callout fbre-callout--${i}`;return n.jsxs("div",{className:c,children:[a&&n.jsx("span",{className:"fbre-callout__icon",children:n.jsx(a,{})}),n.jsxs("div",{className:"fbre-callout__content",children:[r&&n.jsx("div",{className:"fbre-callout__title",children:le(r,o)}),l&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:Le(l,o)}})]})]})};$("callout",Wn);const Yn=({uuid:e})=>{const{properties:t}=A(e),o=t==null?void 0:t.label,l=t==null?void 0:t.columns,r=t==null?void 0:t.rows,i=t==null?void 0:t.highlightColumn,s=i?i-1:-1;return!l||!r||l.length===0?null:n.jsxs("div",{className:"fbre-table",children:[o&&n.jsx("div",{className:"fbre-table__label",children:o}),n.jsxs("table",{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"fbre-table__row-label"}),l.map((a,c)=>n.jsx("th",{className:s===c?"fbre-table__col fbre-table__col--highlight":"fbre-table__col",children:a.label},c))]})}),n.jsx("tbody",{children:r.map((a,c)=>n.jsxs("tr",{children:[n.jsx("td",{className:"fbre-table__row-label",children:a.label}),l.map((d,u)=>n.jsx("td",{className:s===u?"fbre-table__cell fbre-table__cell--highlight":"fbre-table__cell",children:a.values[u]??""},u))]},c))})]})]})};$("table",Yn);const Gn=({uuid:e})=>{const{properties:t,value:o}=A(e),l=t==null?void 0:t.label,r=(t==null?void 0:t.showLabel)!==!1,i=t==null?void 0:t.detail,s=t==null?void 0:t.format,a=t==null?void 0:t.decimalPlaces,c=t==null?void 0:t.currencySymbol,d=U.formatCalculationResult(typeof o=="number"?o:null,s,a,c);return n.jsxs("div",{className:"fbre-computed",children:[r&&l&&n.jsx("div",{className:"fbre-computed__label",children:l}),n.jsx("div",{className:"fbre-computed__value",children:d||"—"}),i&&n.jsx("div",{className:"fbre-computed__detail",children:i})]})};$("computed",Gn);const Dt=({text:e})=>{var c;const[t,o]=j.useState(!1),l=j.useRef(null),r=j.useRef(null),[i,s]=j.useState(null),a=j.useCallback(()=>{if(!l.current)return;const d=l.current.getBoundingClientRect();s({top:d.bottom+4,left:d.right})},[]);return j.useEffect(()=>{if(!t)return;a();const d=p=>{const m=p.target;l.current&&!l.current.contains(m)&&r.current&&!r.current.contains(m)&&o(!1)},u=()=>a();return document.addEventListener("mousedown",d),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{document.removeEventListener("mousedown",d),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[t,a]),n.jsxs(n.Fragment,{children:[n.jsx("button",{ref:l,type:"button",className:"fbre-tooltip-trigger",onClick:()=>o(!t),"aria-label":"Help",children:n.jsx(fn,{})}),t&&i&&Wt.createPortal(n.jsx("div",{ref:r,className:"fbre-tooltip-popover open",style:{top:i.top,left:i.left},children:n.jsx("span",{dangerouslySetInnerHTML:{__html:Rt(e)}})}),((c=l.current)==null?void 0:c.closest(".fbre-container"))??document.body)]})},q=({label:e,detail:t,showLabel:o,required:l,helperText:r,tooltip:i,inputId:s,externalFocused:a,error:c,errorMessages:d,children:u})=>{const p=ue(),[m,f]=j.useState(!1);j.useEffect(()=>{a!==void 0&&f(a)},[a]);const h=["fbre-field",m&&"fbre-field--focused",c&&"fbre-field--error"].filter(Boolean).join(" ");return n.jsxs("div",{className:h,children:[t&&n.jsx("div",{className:"fbre-field__prompt",dangerouslySetInnerHTML:{__html:Le(t,p)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[e&&(!t||t.length===0||o)&&n.jsxs("label",{className:"fbre-field__label",htmlFor:s,children:[le(e,p),l&&n.jsx("span",{className:"required",children:"*"})]}),u({focused:m,setFocused:f}),n.jsxs("div",{className:"fbre-enter-hint",children:["Press ",n.jsx("kbd",{children:"Enter ↵"})," to continue"]}),r&&n.jsx("div",{className:"fbre-field__helper",children:le(r,p)}),(()=>{const g=d==null?void 0:d.filter(b=>b);return c&&g&&g.length>0&&n.jsxs("div",{className:"fbre-field__errors",children:[n.jsx("span",{className:"fbre-field__error-message",children:g[0]}),g.length>1&&n.jsxs("span",{className:"fbre-field__error-more",children:["(and ",g.length-1," more)"]})]})})()]}),i&&n.jsx(Dt,{text:i})]})]})},Jn=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,a=j.useRef(null),[c,d]=j.useState(!1);if(!s)return null;const u=t!=null&&l===!1,p=s.inputType==="password",m=p&&c?"text":s.inputType??"text",f=`fbre-input-${e}`;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:f,error:u,errorMessages:u?r:void 0,children:({setFocused:h})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[s.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:s.startAdornment}),n.jsx("input",{ref:a,id:f,className:`fbre-field__input${s.readOnly?" fbre-field__input--readonly":""}`,type:m,defaultValue:t??"",placeholder:s.placeholder,maxLength:s.maxlength,readOnly:s.readOnly,autoComplete:s.autocomplete??(p?"new-password":void 0),onChange:g=>i(e,g.target.value),onFocus:()=>h(!0),onBlur:()=>h(!1)}),p&&s.showPasswordToggle&&n.jsx("button",{type:"button",className:"fbre-field__password-toggle",onClick:()=>d(!c),tabIndex:-1,children:c?n.jsx(cn,{}):n.jsx(dn,{})})]})})};$("inputText",Jn);const Xn=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o;if(!s)return null;const a=t!=null&&l===!1,c=`fbre-input-${e}`;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:c,error:a,errorMessages:a?r:void 0,children:({setFocused:d})=>n.jsx("textarea",{id:c,className:`fbre-field__textarea${s.readOnly?" fbre-field__textarea--readonly":""}`,defaultValue:t??"",placeholder:s.placeholder,maxLength:s.maxlength,readOnly:s.readOnly,autoComplete:s.autocomplete,onChange:u=>i(e,u.target.value),onFocus:()=>d(!0),onBlur:()=>d(!1)})})};$("inputTextArea",Xn);const Kn=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(t??"");if(!s)return null;const d=t!=null&&l===!1,u=s.decimalPlaces,p=`fbre-input-${e}`,m=h=>{if(h==="")return h;const g=parseFloat(h);return isNaN(g)?h:s.min!==void 0&&g<s.min?String(s.min):s.max!==void 0&&g>s.max?String(s.max):h};if(u!==void 0){const h=new RegExp(`^-?[0-9]*\\.?[0-9]{0,${u}}$`),g=x=>{const _=["Backspace","Delete","ArrowLeft","ArrowRight","Tab","Home","End","Enter"];u>0&&_.push("."),!(_.includes(x.key)||x.ctrlKey||x.metaKey)&&(/^[0-9]$/.test(x.key)||x.preventDefault())},b=x=>{if(x.target.value.length===0){c(""),i(e,"");return}h.test(x.target.value)&&(c(x.target.value),i(e,x.target.value))},v=x=>{x(!1);const _=m(String(a));_!==String(a)&&(c(_),i(e,_))};return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:p,error:d,errorMessages:d?r:void 0,children:({setFocused:x})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[s.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:s.startAdornment}),n.jsx("input",{id:p,className:`fbre-field__input${s.readOnly?" fbre-field__input--readonly":""}`,type:"text",value:a,placeholder:s.placeholder,maxLength:s.maxlength,readOnly:s.readOnly,autoComplete:"off",onKeyDown:g,onChange:b,onFocus:()=>x(!0),onBlur:()=>v(x)})]})})}const f=(h,g)=>{g(!1);const b=m(h.target.value);b!==h.target.value&&(h.target.value=b,i(e,b))};return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:p,error:d,errorMessages:d?r:void 0,children:({setFocused:h})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[s.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:s.startAdornment}),n.jsx("input",{id:p,className:`fbre-field__input${s.readOnly?" fbre-field__input--readonly":""}`,type:"number",defaultValue:t??"",placeholder:s.placeholder,min:s.min,max:s.max,readOnly:s.readOnly,autoComplete:s.autocomplete,onChange:g=>i(e,g.target.value),onFocus:()=>h(!0),onBlur:g=>f(g,h)})]})})};$("inputNumber",Kn);function Me(e,t,o){j.useEffect(()=>{if(!t)return;const l=r=>{e.current&&!e.current.contains(r.target)&&o()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[t,e,o])}function Bt(e){let t=e.parentElement;for(;t;){const{overflow:o,overflowY:l}=getComputedStyle(t);if(/(auto|scroll)/.test(o+l))return t;t=t.parentElement}return document.documentElement}function ht(e,t){const o=Bt(e),l=o===document.documentElement?{top:0,bottom:window.innerHeight}:o.getBoundingClientRect(),r=e.getBoundingClientRect(),i=l.bottom-r.bottom,s=r.top-l.top;return i<t&&s>i}function Ie(e,t,o=300){const[l,r]=j.useState(!1);return j.useLayoutEffect(()=>{if(!t||!e.current){r(!1);return}const i=e.current.offsetParent;i&&r(ht(i,o))},[t,o]),j.useEffect(()=>{if(!t||!e.current)return;const i=()=>{var a;const s=(a=e.current)==null?void 0:a.offsetParent;s&&r(ht(s,o))};return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[t,o]),l}const Zn=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1),d=j.useRef(null),u=j.useRef(null);Me(d,a,j.useCallback(()=>c(!1),[]));const p=Ie(u,a,200);if(!s)return null;const m=s.readOnly===!0,f=t!=null&&l===!1,h=s.options.find(g=>g.value.toString()===(t==null?void 0:t.toString()));return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:f,errorMessages:f?r:void 0,children:()=>n.jsxs("div",{className:`fbre-dropdown${m?" fbre-dropdown--readonly":""}`,ref:d,children:[n.jsxs("div",{className:`fbre-dropdown__trigger${m?" fbre-dropdown__trigger--readonly":""}`,onClick:m?void 0:()=>c(!a),children:[h?n.jsx("span",{className:"fbre-dropdown__selected-text",children:h.label}):n.jsx("span",{className:"fbre-dropdown__placeholder",children:"Select..."}),n.jsx("span",{className:`fbre-dropdown__arrow${a?" open":""}`,children:n.jsx(xe,{})})]}),n.jsx("div",{ref:u,className:`fbre-popup fbre-dropdown__panel${a?" fbre-popup--open":""}${p?" fbre-popup--above":""}`,children:s.options.map((g,b)=>{const v=g.value.toString()===(t==null?void 0:t.toString());return n.jsxs("div",{className:`fbre-dropdown__option${v?" fbre-dropdown__option--selected":""}`,onClick:()=>{i(e,g.value),c(!1)},children:[n.jsx("span",{children:g.label}),v&&n.jsx("span",{className:"fbre-dropdown__option-check",children:n.jsx(Z,{})})]},`${e}-${b}`)})})]})})};$("dropDown",Zn);const Qn=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1),d=j.useRef(null),u=j.useRef(null);Me(d,a,j.useCallback(()=>c(!1),[]));const p=Ie(u,a,200);if(!s)return null;const m=s.readOnly===!0,f=t??[],h=t!=null&&l===!1,g=v=>{const x=v.toString(),_=f.includes(x)?f.filter(N=>N!==x):[...f,x];i(e,_)},b=(v,x)=>{x.stopPropagation(),i(e,f.filter(_=>_!==v))};return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:h,errorMessages:h?r:void 0,children:()=>n.jsxs("div",{className:`fbre-dropdown${m?" fbre-dropdown--readonly":""}`,ref:d,children:[n.jsxs("div",{className:`fbre-dropdown__trigger${m?" fbre-dropdown__trigger--readonly":""}`,onClick:m?void 0:()=>c(!a),children:[f.length>0?n.jsx("div",{className:"fbre-dropdown__tags",children:f.map(v=>{const x=s.options.find(_=>_.value.toString()===v);return n.jsxs("span",{className:"fbre-dropdown__tag",children:[(x==null?void 0:x.label)??v,!m&&n.jsx("button",{type:"button",className:"fbre-dropdown__tag-remove",onClick:_=>b(v,_),children:"×"})]},v)})}):n.jsx("span",{className:"fbre-dropdown__placeholder",children:"Select..."}),n.jsx("span",{className:`fbre-dropdown__arrow${a?" open":""}`,children:n.jsx(xe,{})})]}),n.jsx("div",{ref:u,className:`fbre-popup fbre-dropdown__panel${a?" fbre-popup--open":""}${p?" fbre-popup--above":""}`,children:s.options.map((v,x)=>{const _=f.includes(v.value.toString());return n.jsxs("div",{className:"fbre-dropdown__option",onClick:()=>g(v.value),children:[n.jsx("span",{className:"fbre-option-item__box fbre-option-item__box--checkbox",style:{width:16,height:16},children:_&&n.jsx(Z,{size:12})}),n.jsx("span",{children:v.label})]},`${e}-${x}`)})})]})})};$("dropDownMulti",Qn);const Ot=({label:e,detail:t,showLabel:o,required:l,helperText:r,tooltip:i,error:s,errorMessages:a,children:c})=>{const d=ue(),u=["fbre-option-group",s&&"fbre-option-group--error"].filter(Boolean).join(" ");return n.jsxs("div",{className:u,children:[t&&n.jsx("div",{className:"fbre-field__prompt",dangerouslySetInnerHTML:{__html:Le(t,d)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[o!==!1&&(!t||t.length===0)&&n.jsxs("div",{className:"fbre-option-group__label",children:[le(e,d),l&&n.jsx("span",{className:"required",children:"*"})]}),n.jsx("div",{className:"fbre-option-group__items",children:c}),r&&n.jsx("div",{className:"fbre-option-group__helper",children:le(r,d)}),(()=>{const p=a==null?void 0:a.filter(m=>m);return s&&p&&p.length>0&&n.jsxs("div",{className:"fbre-field__errors",children:[n.jsx("span",{className:"fbre-field__error-message",children:p[0]}),p.length>1&&n.jsxs("span",{className:"fbre-field__error-more",children:["(and ",p.length-1," more)"]})]})})()]}),i&&n.jsx(Dt,{text:i})]})]})},es=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o;if(!s)return null;const a=s.readOnly===!0,c=t??[],d=t!=null&&l===!1,u=p=>{const m=p.toString(),f=c.includes(m)?c.filter(h=>h!==m):[...c,m];i(e,f)};return n.jsx(Ot,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:d,errorMessages:d?r:void 0,children:s.options.map((p,m)=>{const f=c.includes(p.value.toString());return n.jsxs("label",{className:`fbre-option-item${a?" fbre-option-item--readonly":""}`,children:[n.jsx("input",{type:"checkbox",checked:f,disabled:a,onChange:()=>u(p.value)}),n.jsx("span",{className:"fbre-option-item__box fbre-option-item__box--checkbox",children:n.jsx(Z,{})}),n.jsx("span",{className:"fbre-option-item__text",children:p.label})]},`${e}-${m}`)})})};$("checkbox",es);const ts=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,a=B(p=>{var m,f,h;return((m=p.config)==null?void 0:m.mode)==="conversational"&&((h=(f=p.config)==null?void 0:f.theme)==null?void 0:h.style)==="soft-float"});if(!s)return null;const c=s.readOnly===!0,d=t??(s.options.length>0?s.options[0].value:""),u=t!=null&&l===!1;return n.jsx(Ot,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:u,errorMessages:u?r:void 0,children:s.options.map((p,m)=>{const f=(d==null?void 0:d.toString())===p.value.toString();return n.jsxs("label",{className:`fbre-option-item${c?" fbre-option-item--readonly":""}`,onClick:()=>{f&&i(e,p.value.toString())},children:[n.jsx("input",{type:"radio",name:e,checked:f,disabled:c,value:p.value.toString(),onChange:h=>i(e,h.target.value)}),n.jsx("span",{className:"fbre-option-item__box fbre-option-item__box--radio",children:a?n.jsx(Z,{}):n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",children:n.jsx("circle",{cx:"5",cy:"5",r:"5"})})}),n.jsx("span",{className:"fbre-option-item__text",children:p.label})]},`${e}-${m}`)})})};$("radio",ts);const ns=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o;if(!s)return null;const a=s.columns??2,c=t!=null&&l===!1;return n.jsxs("div",{className:`fbre-card-select${c?" fbre-card-select--error":""}`,children:[s.showLabel!==!1&&s.label&&n.jsx("div",{className:"fbre-card-select__label",children:s.label}),n.jsx("div",{className:"fbre-card-select__grid",style:{gridTemplateColumns:`repeat(${a}, 1fr)`},children:s.options.map(d=>{const u=t===d.value;return n.jsxs("button",{type:"button",className:`fbre-card-select__card${u?" fbre-card-select__card--selected":""}`,onClick:()=>i(e,d.value),children:[d.badge&&n.jsx("span",{className:"fbre-card-select__badge",children:d.badge}),(d.title??d.label)&&n.jsx("div",{className:"fbre-card-select__title",children:d.title??d.label}),d.description&&n.jsx("div",{className:"fbre-card-select__desc",children:d.description}),d.features&&d.features.length>0&&n.jsx("ul",{className:"fbre-card-select__features",children:d.features.map((p,m)=>n.jsx("li",{children:p},m))})]},d.value)})}),c&&r&&r.length>0&&n.jsx("div",{className:"fbre-field__errors",children:r.map((d,u)=>n.jsx("span",{className:"fbre-field__error-message",children:d},u))})]})};$("cardSelect",ns);const ss=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=t,a=o,[c,d]=j.useState(null);if(!a)return null;const u=a.max??5,p=a.precision??1,m=c??s??0,f=s!=null&&l===!1,h=a.icon&&Mn[a.icon]||Je,g=(x,_)=>{const N=_&&p<=.5?x+.5:x+1;i(e,N)},b=(x,_)=>{const N=_.currentTarget.getBoundingClientRect(),R=_.clientX-N.left<N.width/2&&p<=.5?x+.5:x+1;d(R)},v=[];for(let x=0;x<u;x++){const _=m>=x+1,N=!_&&m>=x+.5,S=`fbre-rating__star${_?" fbre-rating__star--full":N?" fbre-rating__star--half":""}`;v.push(n.jsx("div",{className:S,onMouseMove:R=>b(x,R),onMouseLeave:()=>d(null),onClick:R=>{const C=R.currentTarget.getBoundingClientRect(),k=R.clientX-C.left<C.width/2;g(x,k)},children:n.jsx(h,{})},x))}return n.jsx(q,{label:a.label,detail:a.detail,showLabel:a.showLabel,required:a.required,helperText:a.helperText,error:f,errorMessages:f?r:void 0,children:()=>n.jsxs("div",{className:"fbre-rating",children:[n.jsx("div",{className:"fbre-rating__stars",children:v}),s!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[s," / ",u]})]})})};$("rating",ss);const rs=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=t,a=o;if(!a)return null;const c=a.readOnly===!0,d=a.min??0,u=a.max??100,p=a.steps??1,m=(s-d)/(u-d)*100,f=l===!1;return n.jsx(q,{label:a.label,detail:a.detail,showLabel:a.showLabel,required:a.required,helperText:a.helperText,error:f,errorMessages:f?r:void 0,children:()=>n.jsxs("div",{className:`fbre-slider${c?" fbre-slider--readonly":""}`,children:[n.jsxs("div",{className:"fbre-slider__track-wrap",children:[n.jsx("input",{className:"fbre-slider__input",type:"range",min:d,max:u,step:p,value:s,disabled:c,style:{"--fill":`${m}%`},onChange:h=>i(e,Number(h.target.value))}),n.jsx("span",{className:"fbre-slider__value",children:s})]}),a.marks&&n.jsxs("div",{className:"fbre-slider__marks",children:[n.jsx("span",{className:"fbre-slider__mark",children:d}),n.jsx("span",{className:"fbre-slider__mark",children:u})]})]})})};$("slider",rs);const os=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o;if(!s)return null;const a=l===!1;return n.jsx(q,{detail:s.detail,helperText:s.helperText,error:a,errorMessages:a?r:void 0,children:()=>n.jsxs("label",{className:"fbre-toggle",children:[n.jsx("input",{type:"checkbox",checked:t??!1,onChange:c=>i(e,c.target.checked)}),n.jsx("span",{className:"fbre-toggle__track",children:n.jsx("span",{className:"fbre-toggle__thumb"})}),(!s.detail||s.detail.length===0||s.showLabel)&&n.jsx("span",{className:"fbre-toggle__label",children:s.label})]})})};$("toggleSwitch",os);const he=new Map,ls=(e,t)=>{he.has(e)||he.set(e,new Set),he.get(e).add(t)},is=(e,t)=>{var o;(o=he.get(e))==null||o.delete(t)},bt=(e,t,o)=>{var l;(l=he.get(e))==null||l.forEach(r=>{r(t,o)})},$t=j.createContext(null);function Vt(){return j.useContext($t)}class be extends Error{constructor(t,o,l,r){super(t),this.name="ApiError",this.status=o,this.code=l,this.validationErrors=r}}class At extends be{constructor(t,o){super(`Request timed out after ${o}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const as=new Set([502,503,504]),je=2,cs=[500,1500];function ds(e){return new Promise(t=>setTimeout(t,e))}async function se(e,t,o={}){const r=`${e.apiEndpoint||""}${t}`,i=e.timeout??3e4,s={...o.body?{"Content-Type":"application/json"}:{},...o.headers};e.apiKey&&(s.Authorization=`Bearer ${e.apiKey}`);let a;for(let c=0;c<=je;c++){c>0&&await ds(cs[c-1]);try{const d=new AbortController,u=setTimeout(()=>d.abort(),i);let p;try{p=await fetch(r,{...o,headers:s,signal:d.signal})}finally{clearTimeout(u)}if(!p.ok){const m=await p.json().catch(()=>({})),f=new be(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(c<je&&as.has(p.status)&&f.code!=="INTEGRATION_HOOK_FAILED"){a=f;continue}throw f.code==="INTEGRATION_HOOK_FAILED"&&(f.message="An external service request failed. Please try again."),f}return p.json()}catch(d){if(d instanceof be)throw d;if(d instanceof DOMException&&d.name==="AbortError"){const u=new At(r,i);if(c<je){a=u;continue}throw u}if(d instanceof TypeError&&c<je){a=d;continue}throw d}}throw a}async function us(e,t){return se(e,`/api/v1/public/flows/${t}`)}async function ps(e,t,o,l,r,i){return se(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:o,contentType:l,size:r,componentUuid:i})})}async function fs(e,t,o){return se(e,`/api/v1/public/flows/${t}/files/${o}/confirm`,{method:"POST"})}async function ms(e,t,o){const l={flowId:t};return o&&Object.keys(o).length>0&&(l.context=o),se(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(l)})}async function hs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:o})})}async function bs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:o})})}async function vs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:o})})}async function xs(e,t){return se(e,`/api/v1/public/sessions/${t}`)}const gs=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1),[d,u]=j.useState(!1),p=j.useRef(null),m=Vt();if(!s)return null;const f=t!=null&&l===!1,h=async g=>{if(g.preventDefault(),!g.target.files)return;const b=g.target.files[0];if(!b)return;if(s.maxSize&&b.size>s.maxSize){c(!0),setTimeout(()=>c(!1),5e3);return}if(c(!1),m){u(!0);try{const{fileId:x,uploadUrl:_}=await ps(m.config,m.flowId,b.name,b.type,b.size,e);await fetch(_,{method:"PUT",headers:{"Content-Type":b.type},body:b}),await fs(m.config,m.flowId,x);const N={mode:"s3",fileId:x,name:b.name,type:b.type,size:b.size};i(e,N),bt("file-upload",e,N)}catch(x){console.error("File upload failed:",x),c(!0),setTimeout(()=>c(!1),5e3)}finally{u(!1)}return}const v=new FileReader;v.addEventListener("load",()=>{const x={name:b.name,type:b.type,size:b.size,lastModified:b.lastModified,data:v.result};"lastModifiedDate"in b&&(x.lastModifiedDate=b.lastModifiedDate),i(e,x),bt("file-upload",e,x)}),v.readAsDataURL(b)};return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,error:f,errorMessages:f?r:void 0,children:()=>n.jsxs("div",{className:"fbre-file",children:[n.jsxs("div",{className:"fbre-file__row",children:[n.jsx("label",{className:`fbre-file__btn${d?" fbre-file__btn--uploading":""}`,children:d?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fbre-spinner fbre-spinner--sm"}),"Uploading..."]}):n.jsxs(n.Fragment,{children:[n.jsx(mn,{}),"Upload file",n.jsx("input",{ref:p,type:"file",accept:s.accept,onChange:h,disabled:d})]})}),n.jsx("span",{className:"fbre-file__name",children:t?t.name:"No file chosen."})]}),n.jsxs("div",{className:`fbre-toast${a?" visible":""}`,children:[m?"File upload failed.":"The uploaded file size was too large.",n.jsx("button",{type:"button",className:"fbre-toast__close",onClick:()=>c(!1),children:"×"})]})]})})};$("fileUpload",gs);const ys=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o;if(!s)return null;const a=t!=null&&l===!1,c=s.labelYes??"Yes",d=s.labelNo??"No";return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:!1,error:a,errorMessages:a?r:void 0,children:()=>n.jsxs("div",{className:`fbre-yesno${s.layout?` fbre-yesno--${s.layout}`:""}`,children:[n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="yes"?" fbre-yesno__btn--active":""}`,onClick:()=>i(e,"yes"),children:c}),n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="no"?" fbre-yesno__btn--active":""}`,onClick:()=>i(e,"no"),children:d})]})})};$("yesNo",ys);const js=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o;if(!s)return null;const a=l===!1,c=t===!0;return n.jsx(q,{detail:s.detail,helperText:s.helperText,tooltip:s.tooltip,error:a,errorMessages:a?r:void 0,children:()=>n.jsxs("label",{className:`fbre-confirm${a?" fbre-confirm--error":""}`,children:[n.jsx("input",{type:"checkbox",className:"fbre-confirm__input",checked:c,onChange:d=>i(e,d.target.checked?!0:void 0)}),n.jsx("span",{className:"fbre-confirm__box","aria-hidden":"true",children:n.jsx("svg",{viewBox:"0 0 16 16",className:"fbre-confirm__check",children:n.jsx("path",{d:"M3 8l3.5 3.5L13 5"})})}),n.jsx("span",{className:"fbre-confirm__label",children:s.label})]})})};$("confirm",js);const vt=e=>{const{h:t,s:o,b:l}=e,r=o/100,i=l/100,s=i*r,a=s*(1-Math.abs(t/60%2-1)),c=i-s;let d=0,u=0,p=0;t<60?(d=s,u=a,p=0):t<120?(d=a,u=s,p=0):t<180?(d=0,u=s,p=a):t<240?(d=0,u=a,p=s):t<300?(d=a,u=0,p=s):(d=s,u=0,p=a);const m=f=>Math.round((f+c)*255).toString(16).padStart(2,"0");return`#${m(d)}${m(u)}${m(p)}`},_e=e=>{const t=e.replace("#",""),o=parseInt(t.substring(0,2),16)/255,l=parseInt(t.substring(2,4),16)/255,r=parseInt(t.substring(4,6),16)/255,i=Math.max(o,l,r),s=Math.min(o,l,r),a=i-s;let c=0;a!==0&&(i===o?c=60*((l-r)/a%6):i===l?c=60*((r-o)/a+2):c=60*((o-l)/a+4)),c<0&&(c+=360);const d=i===0?0:a/i*100,u=i*100;return{h:c,s:d,b:u}},Fe=e=>/^#[0-9a-fA-F]{6}$/.test(e),_s=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1),d=j.useRef(null),u=j.useRef(null),p=j.useRef(null),m=j.useRef(null),[f,h]=j.useState(""),g=typeof t=="string"&&Fe(t)?t:"#1976d2",[b,v]=j.useState(()=>_e(g));Me(d,a,j.useCallback(()=>c(!1),[]));const x=Ie(u,a,320);if(j.useEffect(()=>{typeof t=="string"&&Fe(t)&&(h(t),v(_e(t)))},[t]),!s)return null;const _=t!=null&&l===!1,N=y=>{v(y);const w=vt(y);h(w),i(e,w)},S=y=>{y.preventDefault();const w=(D,I)=>{const L=p.current.getBoundingClientRect(),F=Math.max(0,Math.min(100,(D-L.left)/L.width*100)),H=Math.max(0,Math.min(100,(1-(I-L.top)/L.height)*100));N({...b,s:F,b:H})};w(y.clientX,y.clientY);const E=D=>w(D.clientX,D.clientY),T=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",T)},R=y=>{y.preventDefault();const w=D=>{const I=m.current.getBoundingClientRect(),L=Math.max(0,Math.min(360,(D-I.left)/I.width*360));N({...b,h:L})};w(y.clientX);const E=D=>w(D.clientX),T=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",T)},C=y=>{if(h(y),Fe(y)){const w=_e(y);v(w),i(e,y.toLowerCase())}},k=vt({h:b.h,s:100,b:100});return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:_,errorMessages:_?r:void 0,children:()=>n.jsxs("div",{className:"fbre-colorpicker",ref:d,children:[n.jsxs("div",{className:"fbre-colorpicker__trigger",onClick:()=>c(!a),children:[n.jsx("span",{className:"fbre-colorpicker__swatch",style:{background:g}}),n.jsx("span",{className:"fbre-colorpicker__hex",children:g})]}),n.jsxs("div",{ref:u,className:`fbre-popup fbre-colorpicker__panel${a?" fbre-popup--open":""}${x?" fbre-popup--above":""}`,children:[n.jsxs("div",{className:"fbre-colorpicker__saturation",ref:p,style:{background:k},onMouseDown:S,children:[n.jsx("div",{className:"fbre-colorpicker__saturation-white"}),n.jsx("div",{className:"fbre-colorpicker__saturation-black"}),n.jsx("div",{className:"fbre-colorpicker__cursor",style:{left:`${b.s}%`,top:`${100-b.b}%`}})]}),n.jsx("div",{className:"fbre-colorpicker__hue",ref:m,onMouseDown:R,children:n.jsx("div",{className:"fbre-colorpicker__hue-cursor",style:{left:`${b.h/360*100}%`}})}),n.jsx("div",{className:"fbre-colorpicker__input-row",children:n.jsx("input",{type:"text",className:"fbre-colorpicker__input",value:f,onChange:y=>C(y.target.value),maxLength:7})}),s.swatches&&s.swatches.length>0&&n.jsx("div",{className:"fbre-colorpicker__swatches",children:s.swatches.map((y,w)=>n.jsx("button",{type:"button",className:`fbre-colorpicker__swatch-btn${y.toLowerCase()===g.toLowerCase()?" fbre-colorpicker__swatch-btn--active":""}`,style:{background:y},onClick:()=>{const E=y.toLowerCase();h(E),v(_e(E)),i(e,E)}},w))})]})]})})};$("colorPicker",_s);const ws=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,a=(s==null?void 0:s.mode)??"draw",[c,d]=j.useState(a==="type"?"type":"draw"),u=j.useRef(null),p=j.useRef(null),m=j.useRef(!1),f=j.useRef(null),h=j.useRef(!1),g=t!=null&&l===!1,b=j.useCallback(()=>{const y=u.current,w=p.current;if(!y||!w)return;const E=w.getBoundingClientRect(),T=window.devicePixelRatio||1;y.width=E.width*T,y.height=150*T,y.style.width=`${E.width}px`,y.style.height="150px";const D=y.getContext("2d");D&&(D.scale(T,T),D.lineCap="round",D.lineJoin="round",D.lineWidth=2,D.strokeStyle="var(--fbre-text, #1a1a1a)")},[]);j.useEffect(()=>{if(c==="draw")return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[c,b]);const v=y=>{const E=u.current.getBoundingClientRect();return{x:y.clientX-E.left,y:y.clientY-E.top}},x=j.useCallback((y,w)=>{var D;const E=(D=u.current)==null?void 0:D.getContext("2d");if(!E)return;const T={x:(y.x+w.x)/2,y:(y.y+w.y)/2};E.beginPath(),E.moveTo(y.x,y.y),E.quadraticCurveTo(y.x,y.y,T.x,T.y),E.stroke()},[]),_=j.useCallback(y=>{const w=u.current;w&&(w.setPointerCapture(y.pointerId),m.current=!0,f.current=v(y.nativeEvent),h.current=!0)},[]),N=j.useCallback(y=>{if(!m.current||!f.current)return;const w=v(y.nativeEvent);x(f.current,w),f.current=w},[x]),S=j.useCallback(()=>{if(!m.current)return;m.current=!1,f.current=null;const y=u.current;if(y&&h.current){const w=y.toDataURL("image/png");i(e,w)}},[e,i]),R=()=>{const y=u.current;if(y){const w=y.getContext("2d");w&&w.clearRect(0,0,y.width,y.height)}h.current=!1,i(e,null)},C=y=>{const w=y.target.value;i(e,w||null)},k=y=>{d(y),i(e,null),h.current=!1};return s?n.jsx(q,{label:s.label??"Signature",detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:g,errorMessages:g?r:void 0,children:()=>n.jsxs("div",{className:"fbre-signature",ref:p,children:[a==="both"&&n.jsxs("div",{className:"fbre-signature__toggle",children:[n.jsx("button",{type:"button",className:`fbre-signature__toggle-btn${c==="draw"?" fbre-signature__toggle-btn--active":""}`,onClick:()=>k("draw"),children:"Draw"}),n.jsx("button",{type:"button",className:`fbre-signature__toggle-btn${c==="type"?" fbre-signature__toggle-btn--active":""}`,onClick:()=>k("type"),children:"Type"})]}),c==="draw"&&n.jsxs("div",{className:"fbre-signature__draw-area",children:[n.jsx("canvas",{ref:u,className:"fbre-signature__canvas",onPointerDown:_,onPointerMove:N,onPointerUp:S,onPointerLeave:S}),n.jsx("button",{type:"button",className:"fbre-signature__clear-btn",onClick:R,children:"Clear"})]}),c==="type"&&n.jsxs("div",{className:"fbre-signature__type-area",children:[n.jsx("input",{type:"text",className:"fbre-signature__typed-input",placeholder:"Type your name",value:typeof t=="string"&&!t.startsWith("data:")?t:"",onChange:C}),t&&typeof t=="string"&&!t.startsWith("data:")&&n.jsx("div",{className:"fbre-signature__typed-preview",children:t})]})]})}):null};$("signature",ws);function xt(e){const t=e.offsetParent;if(!t)return 0;const o=Bt(t),l=o===document.documentElement?{left:0,right:window.innerWidth}:o.getBoundingClientRect(),r=t.getBoundingClientRect(),i=e.offsetWidth,s=r.left+i;if(s<=l.right-8)return 0;let a=-(s-l.right+8);return r.left+a<l.left+8&&(a=l.left+8-r.left),a}const pe=({open:e,onClose:t,children:o,estimatedHeight:l=300})=>{const r=j.useRef(null);Me(r,e,j.useCallback(()=>t(),[t]));const i=Ie(r,e,l),[s,a]=j.useState(0);if(j.useLayoutEffect(()=>{if(!e||!r.current){a(0);return}a(xt(r.current))},[e]),j.useEffect(()=>{if(!e||!r.current)return;const d=()=>{r.current&&a(xt(r.current))};return window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[e]),!e)return null;const c="fbre-popup fbre-popup--open"+(i?" fbre-popup--above":"");return n.jsx("div",{ref:r,className:c,style:s?{left:s}:void 0,children:o})},Pe=(e,t)=>new Date(e,t+1,0).getDate(),Cs=(e,t)=>new Date(e,t,1).getDay(),fe=(e,t,o)=>`${e}-${String(t+1).padStart(2,"0")}-${String(o).padStart(2,"0")}`,Ns=e=>{const t=e.split("-");if(t.length!==3)return null;const o=parseInt(t[0],10),l=parseInt(t[1],10)-1,r=parseInt(t[2],10);return isNaN(o)||isNaN(l)||isNaN(r)?null:{year:o,month:l,day:r}},Ee=(e,t)=>{const o=Ns(e);if(!o)return e;const l=String(o.month+1).padStart(2,"0"),r=String(o.day).padStart(2,"0"),i=String(o.year);return t==="DD/MM/YYYY"?`${r}/${l}/${i}`:t==="YYYY-MM-DD"?`${i}-${l}-${r}`:`${l}/${r}/${i}`},Re=e=>{const t=e.split(":");if(t.length!==2)return e;let o=parseInt(t[0],10);const l=t[1],r=o>=12?"PM":"AM";return o===0?o=12:o>12&&(o-=12),`${o}:${l} ${r}`},Ge=(e,t)=>{const o=e.indexOf("T");if(o===-1)return e;const l=e.substring(0,o),r=e.substring(o+1);return`${Ee(l,t)} ${Re(r)}`},Ss=(e,t,o)=>{let l=e;return o==="AM"&&l===12?l=0:o==="PM"&&l!==12&&(l+=12),`${String(l).padStart(2,"0")}:${String(t).padStart(2,"0")}`},ks=e=>{const t=e.split(":");let o=parseInt(t[0],10);const l=parseInt(t[1],10),r=o>=12?"PM":"AM";return o===0?o=12:o>12&&(o-=12),{hour:o,minute:l,ampm:r}},Es=(e,t,o)=>e>=t&&e<=o,ne=e=>{if(!e)return;if(!e.startsWith("today"))return e;const t=e==="today"?0:parseInt(e.slice(5),10),o=new Date;return o.setDate(o.getDate()+(isNaN(t)?0:t)),fe(o.getFullYear(),o.getMonth(),o.getDate())},Rs=["January","February","March","April","May","June","July","August","September","October","November","December"],Ts=e=>Rs[e],Ls=["Su","Mo","Tu","We","Th","Fr","Sa"],De=({selectedDate:e,min:t,max:o,onSelect:l,rangeStart:r,rangeEnd:i,rangeHover:s})=>{const a=new Date,c=fe(a.getFullYear(),a.getMonth(),a.getDate()),d=e?parseInt(e.substring(0,4),10):a.getFullYear(),u=e?parseInt(e.substring(5,7),10)-1:a.getMonth(),[p,m]=j.useState(d),[f,h]=j.useState(u),g=Pe(p,f),b=Cs(p,f),v=()=>{f===0?(m(p-1),h(11)):h(f-1)},x=()=>{f===11?(m(p+1),h(0)):h(f+1)},_=[],N=f===0?Pe(p-1,11):Pe(p,f-1);for(let y=b-1;y>=0;y--){const w=N-y,E=f===0?11:f-1,T=f===0?p-1:p;_.push({day:w,iso:fe(T,E,w),outside:!0})}for(let y=1;y<=g;y++)_.push({day:y,iso:fe(p,f,y),outside:!1});const S=42-_.length;for(let y=1;y<=S;y++){const w=f===11?0:f+1,E=f===11?p+1:p;_.push({day:y,iso:fe(E,w,y),outside:!0})}const R=s??i,C=r&&R&&r<=R?r:R,k=r&&R&&r<=R?R:r;return n.jsxs("div",{className:"fbre-calendar",children:[n.jsxs("div",{className:"fbre-calendar__nav",children:[n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:v,children:"‹"}),n.jsxs("span",{className:"fbre-calendar__nav-title",children:[Ts(f)," ",p]}),n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:x,children:"›"})]}),n.jsx("div",{className:"fbre-calendar__weekdays",children:Ls.map(y=>n.jsx("div",{className:"fbre-calendar__weekday",children:y},y))}),n.jsx("div",{className:"fbre-calendar__grid",children:_.map((y,w)=>{const E=y.iso===e,T=y.iso===c,D=t&&y.iso<t||o&&y.iso>o,I=C&&k&&Es(y.iso,C,k),L=y.iso===C,F=y.iso===k,H=["fbre-calendar__day",y.outside&&"fbre-calendar__day--outside",E&&"fbre-calendar__day--selected",T&&"fbre-calendar__day--today",D&&"fbre-calendar__day--disabled",I&&"fbre-calendar__day--range",L&&"fbre-calendar__day--range-start",F&&"fbre-calendar__day--range-end"].filter(Boolean).join(" ");return n.jsx("div",{className:H,onClick:()=>!D&&!y.outside&&l(y.iso),children:y.day},w)})})]})},Ms=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&l===!1,p=typeof t=="string"?t:"";return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:u,errorMessages:u?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:`fbre-datetime__trigger${d?" fbre-datetime__trigger--readonly":""}`,onClick:d?void 0:()=>c(!a),children:[p?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ee(p,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholder??"Select date..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{})})]}),n.jsx(pe,{open:a,onClose:()=>c(!1),children:n.jsx(De,{selectedDate:p,min:ne(s.min),max:ne(s.max),onSelect:m=>{i(e,m),c(!1)}})})]})})};$("date",Ms);const gt=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const o=parseInt(t[0],10),l=parseInt(t[1],10);return isNaN(o)||isNaN(l)?null:o*60+l},Ue=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,Be=({value:e,min:t,max:o,step:l=15,onChange:r})=>{const i=j.useRef(null),s=j.useRef(null),a=e?ks(e):{hour:12,minute:0,ampm:"AM"},{hour:c,minute:d,ampm:u}=a,p=Array.from({length:12},(C,k)=>k+1),m=[];for(let C=0;C<60;C+=l)m.push(C);const f=["AM","PM"],h=j.useMemo(()=>gt(t),[t]),g=j.useMemo(()=>gt(o),[o]),b=h!==null||g!==null,v=(C,k)=>{const y=C*60+k;return!(h!==null&&y<h||g!==null&&y>g)},x=(C,k)=>{if(!b)return!1;const y=Ue(C,k);for(let w=0;w<60;w+=l)if(v(y,w))return!1;return!0},_=C=>{if(!b)return!1;const k=Ue(c,u);return!v(k,C)},N=C=>{if(!b)return!1;for(const k of p){const y=Ue(k,C);for(let w=0;w<60;w+=l)if(v(y,w))return!1}return!0},S=(C,k,y)=>{r(Ss(C,k,y))};j.useEffect(()=>{const C=k=>{if(!k)return;const y=k.querySelector(".fbre-time-selector__cell--selected");y&&y.scrollIntoView({block:"center",behavior:"instant"})};C(i.current),C(s.current)},[]);const R=(C,k,y)=>{let w=C;return k&&(w+=" fbre-time-selector__cell--selected"),y&&(w+=" fbre-time-selector__cell--disabled"),w};return n.jsxs("div",{className:"fbre-time-selector",children:[n.jsx("div",{className:"fbre-time-selector__column",ref:i,children:p.map(C=>{const k=x(C,u);return n.jsx("div",{className:R("fbre-time-selector__cell",C===c,k),onClick:k?void 0:()=>S(C,d,u),children:C},C)})}),n.jsx("div",{className:"fbre-time-selector__column",ref:s,children:m.map(C=>{const k=_(C);return n.jsx("div",{className:R("fbre-time-selector__cell",C===d,k),onClick:k?void 0:()=>S(c,C,u),children:String(C).padStart(2,"0")},C)})}),n.jsx("div",{className:"fbre-time-selector__column fbre-time-selector__column--ampm",children:f.map(C=>{const k=N(C);return n.jsx("div",{className:R("fbre-time-selector__cell",C===u,k),onClick:k?void 0:()=>S(c,d,C),children:C},C)})})]})},Is=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&l===!1,p=typeof t=="string"?t:"";return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:u,errorMessages:u?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:`fbre-datetime__trigger${d?" fbre-datetime__trigger--readonly":""}`,onClick:d?void 0:()=>c(!a),children:[p?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Re(p)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholder??"Select time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(Ye,{})})]}),n.jsxs(pe,{open:a,onClose:()=>c(!1),children:[n.jsxs("div",{className:"fbre-picker-phase-header",children:[n.jsx("span",{className:"fbre-picker-phase-header__label",children:"Select Time"}),n.jsx("button",{type:"button",className:"fbre-picker-phase-header__confirm",onClick:()=>c(!1),children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:p||void 0,step:s.step,min:s.min,max:s.max,onChange:m=>{i(e,m)}})]})]})})};$("time",Is);const Ds=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(!1),[d,u]=j.useState("date");if(!s)return null;const p=s.readOnly===!0,m=t!=null&&l===!1,f=typeof t=="string"?t:"",h=f.indexOf("T"),g=h!==-1?f.substring(0,h):"",b=h!==-1?f.substring(h+1):"",v=()=>{u(g?"time":"date"),c(!0)},x=()=>{c(!1),u("date")},_=k=>{i(e,`${k}T${b||"12:00"}`),u("time")},N=k=>{const y=g||new Date().toISOString().substring(0,10);i(e,`${y}T${k}`)},S=()=>{u("date")},R=ne(s.min&&s.min.includes("T")?s.min.split("T")[0]:s.min),C=ne(s.max&&s.max.includes("T")?s.max.split("T")[0]:s.max);return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:m,errorMessages:m?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:`fbre-datetime__trigger${p?" fbre-datetime__trigger--readonly":""}`,onClick:p?void 0:v,children:[f?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ge(f,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholder??"Select date & time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{})})]}),n.jsx(pe,{open:a,onClose:x,children:d==="date"?n.jsx(De,{selectedDate:g,min:R,max:C,onSelect:_}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"fbre-picker-phase-header",children:[n.jsx("button",{type:"button",className:"fbre-picker-phase-header__back",onClick:S,children:"‹"}),n.jsx("span",{className:"fbre-picker-phase-header__label",children:"Select Time"}),n.jsx("button",{type:"button",className:"fbre-picker-phase-header__confirm",onClick:x,children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:b||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:N})]})})]})})};$("dateTime",Ds);const Bs=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(null),[d,u]=j.useState();if(!s)return null;const p=t!=null&&l===!1,m=t&&typeof t=="object"&&"start"in t?t:null,f=(m==null?void 0:m.start)??"",h=(m==null?void 0:m.end)??"",g=v=>{if(a==="start"){const x=h&&v>h?"":h;i(e,{start:v,end:x}),c(x?null:"end")}else if(a==="end"){const x=f&&v<f?v:f,_=v<x?x:v;i(e,{start:x||v,end:x?_:""}),x&&_&&c(null)}u(void 0)},b=a!==null;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:b,error:p,errorMessages:p?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:"fbre-date-range__wrap",children:[n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>c(a==="start"?null:"start"),children:[f?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ee(f,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholderStart??"Start date"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{size:12})})]})}),n.jsx("span",{className:"fbre-date-range__separator",children:"→"}),n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>c(a==="end"?null:"end"),children:[h?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ee(h,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholderEnd??"End date"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{size:12})})]})})]}),n.jsx(pe,{open:b,onClose:()=>{c(null),u(void 0)},children:n.jsx(De,{selectedDate:a==="start"?f:h,min:ne(s.min),max:ne(s.max),onSelect:g,rangeStart:f,rangeEnd:h,rangeHover:d})})]})})};$("dateRange",Bs);const Os=({uuid:e})=>{const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(null);if(!s)return null;const d=t!=null&&l===!1,u=t&&typeof t=="object"&&"start"in t?t:null,p=(u==null?void 0:u.start)??"",m=(u==null?void 0:u.end)??"",f=b=>{if(a==="start"){const v=m&&b>m?"":m;i(e,{start:b,end:v})}else if(a==="end"){const v=p&&b<p?p:b;i(e,{start:p,end:v})}},h=()=>{c(null)},g=a!==null;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:g,error:d,errorMessages:d?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:"fbre-date-range__wrap",children:[n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>c(a==="start"?null:"start"),children:[p?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Re(p)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholderStart??"Start time"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(Ye,{size:12})})]})}),n.jsx("span",{className:"fbre-date-range__separator",children:"→"}),n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>c(a==="end"?null:"end"),children:[m?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Re(m)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholderEnd??"End time"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(Ye,{size:12})})]})})]}),n.jsxs(pe,{open:g,onClose:h,children:[n.jsxs("div",{className:"fbre-picker-phase-header",children:[n.jsx("span",{className:"fbre-picker-phase-header__label",children:a==="start"?"Start Time":"End Time"}),n.jsx("button",{type:"button",className:"fbre-picker-phase-header__confirm",onClick:h,children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:a==="start"?p||void 0:m||void 0,step:s.step,min:s.min,max:s.max,onChange:f})]})]})})};$("timeRange",Os);const $s=({uuid:e})=>{var T,D;const{value:t,properties:o,valid:l,validationErrors:r,updateValue:i}=A(e),s=o,[a,c]=j.useState(null),[d,u]=j.useState("date");if(!s)return null;const p=t!=null&&l===!1,m=t&&typeof t=="object"&&"start"in t?t:null,f=(m==null?void 0:m.start)??"",h=(m==null?void 0:m.end)??"",g=I=>{const L=I.indexOf("T");return L!==-1?{date:I.substring(0,L),time:I.substring(L+1)}:{date:"",time:"12:00"}},b=f?g(f):{date:"",time:"12:00"},v=h?g(h):{date:"",time:"12:00"},x=a==="start"?b:v,_=(I,L)=>{const F=I&&L&&L<I?"":L;i(e,{start:I,end:F})},N=I=>{u((I==="start"?b:v).date?"time":"date"),c(I)},S=()=>{c(null),u("date")},R=I=>{const L=x.time||"12:00",F=`${I}T${L}`;a==="start"?_(F,h):_(f,F),u("time")},C=I=>{const L=x.date;if(!L)return;const F=`${L}T${I}`;a==="start"?_(F,h):_(f,F)},k=()=>{u("date")},y=a!==null,w=ne((T=s.min)==null?void 0:T.split("T")[0]),E=ne((D=s.max)==null?void 0:D.split("T")[0]);return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:y,error:p,errorMessages:p?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:"fbre-date-range__wrap",children:[n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>N("start"),children:[f?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ge(f,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholderStart??"Start"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{size:12})})]})}),n.jsx("span",{className:"fbre-date-range__separator",children:"→"}),n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>N("end"),children:[h?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ge(h,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholderEnd??"End"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{size:12})})]})})]}),n.jsx(pe,{open:y,onClose:S,children:d==="date"?n.jsx(De,{selectedDate:x.date,min:w,max:E,onSelect:R}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"fbre-picker-phase-header",children:[n.jsx("button",{type:"button",className:"fbre-picker-phase-header__back",onClick:k,children:"‹"}),n.jsx("span",{className:"fbre-picker-phase-header__label",children:"Select Time"}),n.jsx("button",{type:"button",className:"fbre-picker-phase-header__confirm",onClick:S,children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:x.time||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:C})]})})]})})};$("dateTimeRange",$s);const Ft=({uuid:e})=>{var u;const t=e.split(":")[0],o=parseInt(e.split(":")[1]),l=parseInt(e.split(":")[2]),r=B(p=>{var m,f,h;return(h=(f=(m=p.components[t])==null?void 0:m.addedComponents)==null?void 0:f[o])==null?void 0:h[l]}),i=B(p=>p.conditionResults[e]);if(!r)return null;const s=r.conditions&&"when"in r.conditions?r.conditions:void 0;if(U.isHiddenByCondition(s,i))return null;const a=_t(r.type);if(!a)return null;const c=(u=r.properties)==null?void 0:u.width,d=c&&c!=="full"?`fbre-component fbre-width-${c}`:"fbre-component";return n.jsx("div",{className:d,children:n.jsx(It.Provider,{value:r,children:n.jsx(a,{uuid:e})})})},Vs=({uuid:e})=>{const t=B(a=>{var c;return(c=a.components[e])==null?void 0:c.properties}),o=B(a=>{var c;return(c=a.components[e])==null?void 0:c.addedComponents}),[l,r]=j.useState(!0);if(!t)return null;const i=o??[],s=["fbre-group",t.showBorder===!0&&"fbre-group--bordered",t.showBorder===!1&&"fbre-group--no-border"].filter(Boolean).join(" ");return n.jsx("div",{className:s,children:i.map((a,c)=>n.jsxs("div",{children:[(t.showLabel||t.collapsible)&&n.jsxs("div",{className:"fbre-group__header",children:[t.showLabel&&n.jsx("span",{className:"fbre-group__legend",children:t.label}),t.collapsible&&n.jsx("button",{type:"button",className:`fbre-group__collapse-btn${l?"":" collapsed"}`,onClick:()=>r(!l),"aria-label":"Toggle group",children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${l?"":" collapsed"}`,children:n.jsx("div",{className:"fbre-group__content",children:a.map(d=>n.jsx(Ft,{uuid:d.uuid},d.uuid))})})]},`${e}-${c}`))})};$("group",Vs);const As=({uuid:e})=>{const t=B(f=>{var h;return(h=f.components[e])==null?void 0:h.properties}),o=B(f=>{var h;return(h=f.components[e])==null?void 0:h.addedComponents}),l=B(f=>f.addRepeaterIteration),r=B(f=>f.removeRepeaterIteration),[i,s]=j.useState(new Set([0]));if(!t)return null;const a=o??[],c=1,d=()=>{const f=a.length;l(e),s(new Set([f]))},u=f=>{a.length<=c||(r(e,f),s(h=>{const g=new Set;for(const b of h)b<f?g.add(b):b>f&&g.add(b-1);return g}))},p=f=>{s(h=>{const g=new Set(h);return g.has(f)?g.delete(f):g.add(f),g})},m=["fbre-group","fbre-repeater",t.showBorder===!0&&"fbre-group--bordered",t.showBorder===!1&&"fbre-group--no-border"].filter(Boolean).join(" ");return n.jsxs("div",{className:m,children:[a.map((f,h)=>{const g=i.has(h);return n.jsxs("div",{children:[(t.showLabel||t.collapsible)&&n.jsxs("div",{className:"fbre-group__header",children:[t.showLabel&&n.jsxs("span",{className:"fbre-group__legend",children:[t.label," ",a.length>1?`#${h+1}`:""]}),a.length>c&&n.jsx("button",{type:"button",className:"fbre-repeater__remove-btn",onClick:()=>u(h),title:"Remove","aria-label":"Remove iteration",children:n.jsx(xn,{size:14})}),t.collapsible&&n.jsx("button",{type:"button",className:`fbre-group__collapse-btn${g?"":" collapsed"}`,onClick:()=>p(h),"aria-label":"Toggle repeater",children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${!g&&t.collapsible?" collapsed":""}`,children:n.jsx("div",{className:"fbre-group__content",children:f.map(b=>n.jsx(Ft,{uuid:b.uuid},b.uuid))})})]},`${e}-${h}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:d,children:"Add another"})]})};$("repeater",As);const Fs={clean:"dots",outlined:"dots","refined-clean":"pill","airy-clean":"glow","soft-outlined":"glow","defined-outlined":"bar","centered-minimal":"dots","stacked-cards":"dots","soft-float":"glow","bold-statement":"bar"},Ps=({screenIndex:e,onFlowComplete:t,onScreenChange:o})=>{var Ke,Ze,Qe,et,tt,nt,st,rt,ot,lt,it;const l=B(V=>V.config),r=B(V=>V.screenOrder.length),i=B(V=>Object.keys(V.components).length>0),s=ve(),a=Math.max(0,Math.min(e,r-1)),[c,d]=j.useState(a),[u,p]=j.useState(!!(l!=null&&l.summary&&e>=r)),m=((Ke=l==null?void 0:l.navigation)==null?void 0:Ke.transition)??"none",f=m!=="none",[h,g]=j.useState(null),[b,v]=j.useState(!1),[x,_]=j.useState("forward"),[N,S]=j.useState(!1),R=j.useRef(null);j.useEffect(()=>{const V=Math.max(0,Math.min(e,r-1));d(V)},[e]);const C=B(V=>V.screenOrder[c]),k=B(V=>C?V.screenValidity[C]??!0:!0),y=B(V=>{var W;return C?(W=V.screens[C])==null?void 0:W.nextButtonLabel:void 0}),w=B(V=>{var W;return C?(W=V.screens[C])==null?void 0:W.backButtonLabel:void 0}),E=j.useCallback(V=>{o&&o(V,s.getState().getFlowData())},[o,s]),T=j.useCallback(V=>{g(c),v(u),_(V),S(!0),R.current&&(R.current.scrollTop=0)},[c,u]),D=j.useCallback(()=>{S(!1),g(null)},[]),I=j.useCallback(()=>{if(!N)if(u)f&&T("back"),p(!1),E(c);else{const V=s.getState(),W=Vn(V,c);W!==c&&(f&&T("back"),d(W),E(W))}},[N,u,c,f,T,E,s]),L=j.useCallback(()=>{if(N)return;const V=s.getState(),W=ke(V,c);W!==null?(f&&T("forward"),d(W),E(W)):l!=null&&l.summary&&(f&&T("forward"),p(!0),E(c+1))},[N,c,l,f,T,E,s]),[F,H]=j.useState(!1),[P,G]=j.useState(null),J=j.useCallback(()=>{G(null);const V=t(s.getState().getFlowData());V&&typeof V.then=="function"&&(H(!0),V.then(()=>{H(!1)}).catch(W=>{H(!1),G(W instanceof Error?W.message:String(W))}))},[t,s]),ee=B(V=>ke(V,c)===null),M=((Ze=l==null?void 0:l.theme)==null?void 0:Ze.darkMode)??!1,O=((l==null?void 0:l.mode)??"standard")==="conversational";Lt(O&&!u,c,L),Mt(O&&!u,c,L);const Y=((Qe=l==null?void 0:l.theme)==null?void 0:Qe.style)??"clean",ie=((et=l==null?void 0:l.controls)==null?void 0:et.stepperStyle)??"default",ae=ie==="default"?Fs[Y]??"dots":ie,Ut=((tt=l==null?void 0:l.controls)==null?void 0:tt.showStepper)!==!1&&ae==="text",Oe={};(nt=l==null?void 0:l.theme)!=null&&nt.color&&(Oe["--fbre-theme-color"]=l.theme.color);const Ht=()=>b?n.jsx(ut,{}):h!==null?n.jsx(We,{screenIndex:h}):null,qt=N?"fbre-screen-wrapper fbre-screen-wrapper--transitioning":"fbre-screen-wrapper";return n.jsxs("div",{className:"fbre-container","data-style":Y,"data-mode":M?"dark":"light","data-form-mode":O?"conversational":void 0,"data-stepper":ae!=="text"?ae:void 0,"data-transition":f?m:void 0,style:Object.keys(Oe).length>0?Oe:void 0,children:[Ut&&n.jsx(Dn,{current:c,total:r}),n.jsxs("div",{className:qt,ref:R,children:[N&&n.jsx("div",{className:"fbre-screen-slot fbre-screen--exiting","data-direction":x,onAnimationEnd:D,children:Ht()}),n.jsxs("div",{className:N?"fbre-screen-slot fbre-screen--entering":"fbre-screen-slot","data-direction":N?x:void 0,children:[!u&&n.jsx(We,{screenIndex:c}),u&&n.jsx(ut,{})]})]}),P&&n.jsx("div",{className:"fbre-completion-error",children:P}),((st=l==null?void 0:l.controls)==null?void 0:st.show)!==!1&&i&&n.jsx(Bn,{screenIndex:c,maxScreenIndex:r-1,allowInvalidTransition:(rt=l==null?void 0:l.navigation)==null?void 0:rt.allowInvalidTransition,screenValidity:k,summaryEnabled:(l==null?void 0:l.summary)??!1,summaryActive:u,atMaxScreen:ee,nextButtonLabel:y,backButtonLabel:w,completionLoading:F,showStepper:(ot=l==null?void 0:l.controls)==null?void 0:ot.showStepper,stepperStyle:(lt=l==null?void 0:l.controls)==null?void 0:lt.stepperStyle,controlsLayout:(it=l==null?void 0:l.controls)==null?void 0:it.layout,nextScreen:L,prevScreen:I,onFlowComplete:J})]})},Us=[],Hs=()=>K.createStore((e,t)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,sessionId:"",navigation:{canGoBack:!1,canGoForward:!1,screenNumber:1,totalScreens:1,progress:0,isLastScreen:!0},loading:!1,error:"",clearError:()=>{e({error:""})},loadFlow:()=>{},updateContext:o=>{e({externalContext:o})},updateComponentValue:(o,l)=>{var m,f;const r=t();if(o.includes(":")){const h=o.split(":"),g=h[0],b=parseInt(h[1]),v=parseInt(h[2]),x=r.components[g];if(!((f=(m=x==null?void 0:x.addedComponents)==null?void 0:m[b])!=null&&f[v]))return;x.addedComponents[b][v]={...x.addedComponents[b][v],value:l};const _=r.groupComponentMap[o]??o,N=r.conditionsByDependency[_];let S=r.conditionResults;if(N&&N.length>0){S={...r.conditionResults};for(const w of N)S[w.target]=ce({...r},w.config)}const R={components:r.components,groupComponentMap:r.groupComponentMap},C=z(x.addedComponents[b][v],R);x.addedComponents[b][v].valid=C.length===0;const k={...r.validationErrors,[o]:C},y=r.validationsByDependency[o];if(y)for(const w of y){const E=yt(r,w.target);if(E){const T=z(E,R);E.valid=T.length===0,k[w.target]=T}}e({components:{...r.components},conditionResults:S,validationErrors:k});return}const i=r.components[o];if(!i)return;if(i.type==="group"||i.type==="repeater"){e({components:{...r.components}});return}if(l===i.value){e({selectionTick:(t().selectionTick??0)+1});return}i.value=l;const s=r.conditionsByDependency[o];let a=r.conditionResults;if(s&&s.length>0){a={...r.conditionResults};for(const h of s)a[h.target]=ce({...r},h.config)}const c={components:r.components,groupComponentMap:r.groupComponentMap},d=z(i,c);i.valid=d.length===0;const u={...r.validationErrors,[o]:d},p=r.validationsByDependency[o];if(p)for(const h of p){const g=yt(r,h.target);if(g){const b=z(g,c);g.valid=b.length===0,u[h.target]=b}}e({components:{...r.components},conditionResults:a,validationErrors:u})},addGroupIteration:o=>{const l=t(),r=l.components[o];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const i=r.components.map((s,a)=>{const c=Q(s);c.uuid=[o,r.addedComponents.length,a].join(":"),l.groupComponentMap[c.uuid]=s.uuid;const d=z(c);return c.valid=d.length===0,c});return r.addedComponents.push(i),e({components:{...l.components},groupComponentMap:{...l.groupComponentMap}}),r.addedComponents},addRepeaterIteration:o=>{const l=t(),r=l.components[o];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const i=r.components.map((s,a)=>{const c=Q(s);c.uuid=[o,r.addedComponents.length,a].join(":");const d=z(c);return c.valid=d.length===0,c});return r.addedComponents.push(i),e({components:{...l.components}}),r.addedComponents},removeRepeaterIteration:(o,l)=>{const r=t(),i=r.components[o];if(!(!i||i.type!=="repeater"||!i.addedComponents||i.addedComponents.length<=1)){i.addedComponents.splice(l,1);for(let s=l;s<i.addedComponents.length;s++)i.addedComponents[s].forEach((a,c)=>{a.uuid=[o,s,c].join(":")});e({components:{...r.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:o=>{const l=t();if(o!==0)return null;const r=l.screenOrder[0];return r?l.screens[r]:null},getScreenValidity:o=>{const l=t();if(o!==0)return!0;const r=l.screenOrder[0];return r?l.screenValidity[r]??!0:!0},getValidationErrors:o=>t().validationErrors[o]??Us,evaluateFlowValidation:()=>{const o=t(),l=o.screenOrder[0];if(!l)return!0;const r=o.screens[l];if(!r)return!0;let i=!0;const s={components:o.components,groupComponentMap:o.groupComponentMap},a={...o.validationErrors};for(const d of r.components){const u=o.components[d.uuid];if(!u)continue;if((u.type==="group"||u.type==="repeater")&&u.addedComponents){for(const f of u.addedComponents)for(const h of f){const g=h.conditions&&"when"in h.conditions?h.conditions:void 0;if(g){const v=o.conditionResults[h.uuid]??!1;if(g.action==="show"&&!v||g.action==="hide"&&v)continue}const b=z(h,s);h.valid=b.length===0,a[h.uuid]=b,b.length>0&&(i=!1)}continue}const p=u.conditions&&"when"in u.conditions?u.conditions:void 0;if(p){const f=o.conditionResults[u.uuid]??!1;if(p.action==="show"&&!f||p.action==="hide"&&f)continue}const m=z(u,s);u.valid=m.length===0,a[u.uuid]=m,m.length>0&&(i=!1)}const c={...o.screenValidity,[l]:i};return e({components:{...o.components},validationErrors:a,screenValidity:c}),i},getMaxScreenCount:()=>0,getCalculationResult:o=>t().calculationResults[o]??null})),we=(e,t)=>{var h,g;const o={},l={},r={},i={},s={},a={},c=t.screen.uuid;for(const b of t.screen.components){const v=Q(b);if(o[v.uuid]=v,(v.type==="group"||v.type==="repeater")&&b.components){v.addedComponents||(v.addedComponents=[]);const x=b.components.map((_,N)=>{var R;const S=Q(_);if(S.uuid=[v.uuid,0,N].join(":"),v.type==="group"&&(l[S.uuid]=_.uuid),r[_.uuid]=S.uuid,(R=S.properties)!=null&&R.validation){const C=S.properties.validation;C.rules&&C.rules.length>0&&me(s,S.uuid,C)}return S});v.addedComponents.push(x)}if((h=v.properties)!=null&&h.validation){const x=v.properties.validation;x.rules&&x.rules.length>0&&me(s,v.uuid,x)}}for(const{targetUUID:b,config:v}of t.conditions)re(i,b,v,b===c?"screen":"component");if(t.previousData)for(const b of t.previousData){const v=o[b.uuid];v&&(v.value=b.value)}const d={components:o};for(const b of Object.keys(o)){const v=o[b];if(v.type==="group"||v.type==="repeater"){if(v.addedComponents)for(const _ of v.addedComponents)for(const N of _){const S=z(N,d);N.valid=S.length===0,S.length>0&&(a[N.uuid]=S)}continue}if(!((g=v.properties)!=null&&g.validation))continue;const x=z(v,d);v.valid=x.length===0,x.length>0&&(a[b]=x)}const u={},p={components:o},m=new Set;for(const b of Object.values(i))for(const v of b)m.has(v.target)||(m.add(v.target),u[v.target]=ce(p,v.config));let f=!0;for(const b of t.screen.components){const v=o[b.uuid];if(v)if((v.type==="group"||v.type==="repeater")&&v.addedComponents)for(const x of v.addedComponents){for(const _ of x)if(!_.valid){f=!1;break}if(!f)break}else v.valid===!1&&(f=!1)}e.setState({screenOrder:[c],screens:{[c]:{uuid:c,label:t.screen.label,components:t.screen.components,nextButtonLabel:t.screen.nextButtonLabel,backButtonLabel:t.screen.backButtonLabel}},screenValidity:{[c]:f},components:o,groupComponentMap:l,templateComponentMap:r,conditionsByDependency:i,conditionResults:u,validationErrors:a,validationsByDependency:s,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:t.sessionId,navigation:t.navigation,loading:!1,error:"",externalContext:t.context??{},config:t.config??{}})},He=e=>{var i;const t=e.getState(),o=t.screenOrder[0];if(!o)return[];const l=t.screens[o];if(!l)return[];const r=[];for(const s of l.components){const a=t.components[s.uuid];if(!a||Ne(a.type))continue;const c={uuid:a.uuid,type:a.type,value:a.value};(i=a.properties)!=null&&i.label&&(c.label=a.properties.label),(a.type==="group"||a.type==="repeater")&&a.addedComponents&&(c.components=a.addedComponents.map(d=>d.filter(u=>!Ne(u.type)).map(u=>({uuid:u.uuid,type:u.type,value:u.value})))),r.push(c)}return r},yt=(e,t)=>Nt(e.components,t),qs=6e4,zs=({sessionEndpoint:e,flowId:t,apiKey:o,mode:l,theme:r,context:i,onFlowComplete:s,onScreenChange:a})=>{const c=j.useRef(null);c.current||(c.current=Hs());const d=c.current,u=K.useStore(d,M=>M.loading),p=K.useStore(d,M=>M.error),m=K.useStore(d,M=>M.navigation),f=K.useStore(d,M=>M.config),h=K.useStore(d,M=>{var X;return(X=M.config)==null?void 0:X.mode}),g=K.useStore(d,M=>M.screenOrder),b=K.useStore(d,M=>M.screens),[v,x]=j.useState(""),_=j.useRef(null),N=j.useRef(Date.now()),S=j.useMemo(()=>({apiEndpoint:e,apiKey:o}),[e,o]),R=j.useCallback(M=>{x(M),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>x(""),8e3)},[]),C=j.useCallback(()=>{x(""),_.current&&(clearTimeout(_.current),_.current=null)},[]),k=j.useCallback(async()=>{d.setState({loading:!0,error:""});try{const M=await ms(S,t,i);we(d,M)}catch(M){d.setState({loading:!1,error:M.message})}},[t,e,o,i]);j.useEffect(()=>{k()},[k]),j.useEffect(()=>{const M=async()=>{if(document.visibilityState!=="visible")return;const X=d.getState();if(!(!X.sessionId||Date.now()-N.current<qs))try{const Y=await xs(S,X.sessionId);we(d,Y)}catch(Y){Y instanceof be&&Y.status===404&&d.setState({loading:!1,error:"Session expired. Please start over.",screenOrder:[],screens:{}})}};return document.addEventListener("visibilitychange",M),()=>document.removeEventListener("visibilitychange",M)},[e,o]);const y=j.useCallback(async()=>{const M=d.getState();if(!(M.loading||!M.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),C();try{const O=He(d),Y=await hs(S,M.sessionId,O);we(d,Y),N.current=Date.now(),a==null||a(Y.navigation.screenNumber)}catch(O){d.setState({loading:!1}),R(O.message)}}},[S,d,a,R,C]),w=j.useCallback(async()=>{const M=d.getState();if(!M.loading){d.setState({loading:!0}),d.getState().clearError(),C();try{const X=He(d),O=await bs(S,M.sessionId,X);we(d,O),N.current=Date.now(),a==null||a(O.navigation.screenNumber)}catch(X){d.setState({loading:!1}),R(X.message)}}},[S,d,a,R,C]),E=j.useCallback(async()=>{const M=d.getState();if(!(M.loading||!M.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),C();try{const O=He(d),Y=await vs(S,M.sessionId,O);N.current=Date.now(),s(Y)}catch(O){d.setState({loading:!1}),R(O.message)}}},[S,d,s,R,C]),T={...f==null?void 0:f.theme,...r},I=(l??h??"standard")==="conversational",L=I&&!m.isLastScreen;Lt(L,0,y),Mt(L,0,y);const F=T.darkMode??!1,H={};T.color&&(H["--fbre-theme-color"]=T.color);const P=g[0],G=P?b[P]:void 0,J=G==null?void 0:G.nextButtonLabel,ee=G==null?void 0:G.backButtonLabel;return u&&g.length===0?n.jsx("div",{className:"fbre-container",children:n.jsxs("div",{className:"fbre-remote-loading",children:[n.jsx("div",{className:"fbre-spinner"}),n.jsx("p",{children:"Loading form..."})]})}):p&&g.length===0?n.jsx("div",{className:"fbre-container",children:n.jsxs("div",{className:"fbre-remote-error",children:[n.jsx("p",{children:"Failed to load form"}),n.jsx("p",{className:"fbre-remote-error__detail",children:p}),n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:k,style:{marginTop:12},children:"Retry"})]})}):g.length===0?null:n.jsx(Te.Provider,{value:d,children:n.jsxs("div",{className:"fbre-container","data-style":T.style??"clean","data-mode":F?"dark":"light","data-form-mode":I?"conversational":void 0,style:Object.keys(H).length>0?H:void 0,children:[n.jsx("div",{className:"fbre-screen-wrapper",children:n.jsx(We,{screenIndex:0})}),n.jsx(Ws,{navigation:m,loading:u,onPrev:w,onNext:y,onComplete:E,nextButtonLabel:J,backButtonLabel:ee}),n.jsxs("div",{className:`fbre-toast${v?" visible":""}`,children:[n.jsx("span",{children:v}),n.jsx("button",{type:"button",className:"fbre-toast__close",onClick:C,"aria-label":"Dismiss",children:"×"})]})]})})},Ws=({navigation:e,loading:t,onPrev:o,onNext:l,onComplete:r,nextButtonLabel:i,backButtonLabel:s})=>n.jsxs("div",{className:"fbre-controls fbre-controls--default",children:[n.jsx("div",{className:"fbre-controls__left",children:e.canGoBack&&n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--back",onClick:o,disabled:t,children:s||"Back"})}),n.jsx("div",{className:"fbre-controls__center",children:n.jsxs("span",{className:"fbre-controls__progress",children:[e.screenNumber," / ",e.totalScreens]})}),n.jsx("div",{className:"fbre-controls__right",children:e.isLastScreen?n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--complete",onClick:r,disabled:t,children:t?"Submitting...":i||"Complete"}):n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:l,disabled:t,children:t?"Loading...":i||"Next"})})]});function Ys(e,t,o,l,r){return!t&&!o&&!l&&!r?e:{...e,...r&&{mode:r},...t&&{theme:{...e.theme,...t}},...o&&{navigation:{...e.navigation,...o}},...l&&{controls:{...e.controls,...l}}}}const Pt=({flow:e,data:t,mode:o,theme:l,navigation:r,controls:i,screenIndex:s,context:a,storeRef:c,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p,apiCtx:m})=>{const f=j.useRef(null);f.current||(f.current=ln(),f.current.getState().loadFlow(e,t,a)),c&&(c.current=f.current),j.useEffect(()=>{f.current&&f.current.getState().loadFlow(e,t,a)},[e.uuid]),j.useEffect(()=>{if(f.current){const b=f.current.getState(),v=Ys(b.config,l,r,i,o);v!==b.config&&f.current.setState({config:v})}},[o,l,r,i]);const h=a?JSON.stringify(a):"";j.useEffect(()=>{f.current&&a&&f.current.getState().updateContext(a)},[h]);const g=n.jsx(Te.Provider,{value:f.current,children:n.jsx(Ps,{screenIndex:s??0,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p})});return m?n.jsx($t.Provider,{value:m,children:g}):g},Gs=({flowId:e,apiEndpoint:t,apiKey:o,data:l,mode:r,theme:i,navigation:s,controls:a,screenIndex:c,context:d,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f})=>{const[h,g]=j.useState(null),[b,v]=j.useState(""),[x,_]=j.useState(null);return j.useEffect(()=>{g(null),v("");const N={apiEndpoint:t,apiKey:o};us(N,e).then(S=>{g(S.data),_({config:N,flowId:S.id,flowVersionId:S.versionId,tenantId:S.tenantId})}).catch(S=>v(S.message))},[e,t,o]),b?n.jsx("div",{className:"fbre-container",children:n.jsxs("div",{className:"fbre-remote-error",children:[n.jsx("p",{children:"Failed to load form"}),n.jsx("p",{className:"fbre-remote-error__detail",children:b})]})}):!h||!x?n.jsx("div",{className:"fbre-container",children:n.jsxs("div",{className:"fbre-remote-loading",children:[n.jsx("div",{className:"fbre-spinner"}),n.jsx("p",{children:"Loading form..."})]})}):n.jsx(Pt,{flow:h,data:l,mode:r,theme:i,navigation:s,controls:a,screenIndex:c,context:d,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f,apiCtx:x})},Js=e=>"sessionEndpoint"in e?n.jsx(zs,{...e}):"flowId"in e&&e.flowId?n.jsx(Gs,{...e}):n.jsx(Pt,{...e});exports.ApiError=be;exports.FBRE=Js;exports.TimeoutError=At;exports.addFBREEventListener=ls;exports.removeFBREEventListener=is;exports.useFBREApi=Vt;exports.useFBREStore=B;exports.useFBREStoreApi=ve;