@sonata-innovations/fiber-fbre 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/fiber-fbre.cjs +1 -1
- package/dist/fiber-fbre.css +1 -1
- package/dist/fiber-fbre.js +996 -911
- package/package.json +4 -1
package/dist/fiber-fbre.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),j=require("react"),K=require("zustand"),qt=require("@sonata-innovations/fiber-types"),U=require("@sonata-innovations/fiber-shared"),Wt=require("react-dom"),jt=new Map,V=(e,t)=>{jt.set(e,t)},_t=e=>jt.get(e),Yt=new Set(["header","text","divider","callout","table"]),we=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:qt.normalizeOptions(t.properties.options)}),e.type==="computed"?(t.value=null,t.valid=!0):!we(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 Ct(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 He(e){const t=e.calculations??[];if(t.length===0)return{};const o=U.topologicalSortCalculations(t),l={},r=Ct(e,l);for(const i of o)l[i.uuid]=U.evaluateFormula(i.formula,r);return l}function Oe(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=Ct(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 wt(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 v=Number(g);return isNaN(v)?null:v}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 v=g.find(N=>N.value===h||N.label===h);if(!(v!=null&&v.metadata))return null;const b=v.metadata[p];if(b==null)return null;const x=Number(b);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 v=g[f];if(!v)continue;const b=v.value;if(b==null||b==="")continue;const x=Number(b);isNaN(x)||h.push(x)}return h.length>0?h:null}return null}}}function Ne(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=Ne(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"?wt(e,t,r.uuid,i):Ne(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=Ne(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"?wt(e,r,u.uuid,f):Ne(e,r),v=U.evaluateFormula(m.properties.formula,g);h.value!==v&&(u.addedComponents[f][p]={...h,value:v},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},it=(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,v=[],b=_=>{if(Zt(h,_)){const N=h.computedByDependency[_]??[];for(const S of N)v.includes(S)||(v.push(S),b(S))}};b(s),g&&g!==s&&b(g);let x=Oe(h,s);if(g&&g!==s){const _=x?{...h,calculationResults:x}:h,N=Oe(_,g);N&&(x=N)}for(const _ of v){const N=x?{...h,calculationResults:x}:h,S=Oe(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){it(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,it(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=He(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(v=>v.uuid));i.addedComponents.splice(l,1);const d={...r.conditionsByDependency},u={...r.validationErrors};for(const v of c)delete u[v],delete d[v];for(const v of Object.keys(d)){const b=d[v],x=b.filter(_=>!c.has(_.target));x.length===0?delete d[v]:x.length!==b.length&&(d[v]=x)}for(let v=l;v<i.addedComponents.length;v++)i.addedComponents[v].forEach((b,x)=>{const _=b.uuid,N=[o,v,x].join(":");if(_!==N){b.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=He(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},$e=e=>{if(!e||we(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},at=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=at(c);if(U.isHiddenByCondition(d,e.conditionResults[a.uuid]))return null;if((c.type==="group"||c.type==="repeater")&&c.addedComponents){const u=$e(c);return u?{...u,components:c.addedComponents.map(p=>p.filter(m=>{const f=at(m);return!U.isHiddenByCondition(f,e.conditionResults[m.uuid])}).map(m=>$e(m)).filter(m=>m!==null))}:null}return $e(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},Re=j.createContext(null);function B(e){const t=j.useContext(Re);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return K.useStore(t,e)}const be=()=>{const e=j.useContext(Re);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(w=>{const k=ge(w.conditions),y=k?{...w,conditions:k}:{...w};i[w.uuid]=y,s.push(w.uuid),k&&re(u,w.uuid,k,"screen"),w.components.forEach(C=>{var D;const E=ge(C.conditions),T=Q(C);if(E&&(T.conditions=E),a[C.uuid]=T,E&&re(u,C.uuid,E,"component"),(D=T.properties)!=null&&D.validation&&me(p,C.uuid,T.properties.validation),(C.type==="group"||C.type==="repeater")&&C.components){const L=a[C.uuid];L.addedComponents||(L.addedComponents=[]);const F=C.properties??{},H=C.type==="repeater"?F.initialData:void 0,P=C.type==="repeater"?F.minIterations:void 0,G=H?H.length:C.type==="repeater"&&P&&P>1?P:1;for(let J=0;J<G;J++){const ee=C.components.map((M,X)=>{var ae;const O=Q(M);O.uuid=[C.uuid,L.addedComponents.length,X].join(":"),H&&H[J]&&M.uuid in H[J]&&(O.value=H[J][M.uuid]),C.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(w=>{const k=s.indexOf(w.uuid);k<0||w.components.forEach(y=>{const C=a[y.uuid];if(C)if((C.type==="group"||C.type==="repeater")&&y.components&&C.addedComponents){if(y.components.length>1){const E=C.addedComponents.length,T=y.components.length-E,I=o.screens[k].components.find(D=>D.uuid===C.uuid);for(let D=0;D<T;D++)if(I!=null&&I.components){const L=I.components.map((F,H)=>{var ee;const P=Q(F);P.uuid=[C.uuid,C.addedComponents.length,H].join(":"),C.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});C.addedComponents.push(L)}}y.components.forEach(E=>{E.forEach(T=>{for(const I of C.addedComponents){const D=I.find(L=>L.uuid===T.uuid);if(D){D.value=T.value;const L=z(D);D.valid=L.length===0,m[D.uuid]=L;break}}})})}else{C.value=y.value;const E=z(C);C.valid=E.length===0,m[C.uuid]=E}})});for(const w of Object.keys(a)){const k=a[w];if(!(k.type==="group"||k.type==="repeater"||!((R=k.properties)!=null&&R.validation))&&!(w in m)){const y=z(k);k.valid=y.length===0,y.length>0&&(m[w]=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(w=>{f[w]=oe(h,w)});const v=Kt(a),b={...h,computedByDependency:v,calculationResults:{},screenValidity:f};ze(b);const x=o.calculations??[],_=Xt(x),N={...b,calculations:x},S=He(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:v})},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})})},qe=({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"})]}),We=({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"})}),Ge=({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"})]}),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("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("polyline",{points:"9,12 11.5,14.5 16,9.5"})]}),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("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"})}),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("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"})}),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("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)"})}),Ve={info:hn,check:vn,warning:bn,question:En,lightbulb:gn,megaphone:yn,bell:jn,shield:_n,lock:Cn,heart:St,flag:wn,bookmark:Nn,zap:Sn,pencil:kn,star:Ge},Mn={star:Ge,heart:St,thumbsUp:Rn,circle:Tn,diamond:Ln},ct=({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,v=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 b=h||!l&&!r||v==="Done"&&!r,x=()=>{g?f():p()};return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:b,onClick:x,children:[c||v,h?n.jsx("span",{className:"fbre-btn__spinner"}):g?n.jsx(Z,{size:16}):n.jsx(pn,{})]})},Dn=({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}%`}})})]})},In=({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==="stacked",o=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text";return n.jsxs("div",{className:t?"fbre-controls fbre-controls--stacked":"fbre-controls",children:[e.screenIndex>0||e.summaryActive?n.jsx(ct,{position:"back",...e}):n.jsx("div",{}),o&&e.maxScreenIndex>0?n.jsx(Dn,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):n.jsx("div",{}),n.jsx(ct,{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,Te=(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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),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=be(),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,Se=(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},Je=new Set(["radio","yesNo","cardSelect","dropDown"]),An=500;function Lt(e,t,o){const l=be(),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))||Se(c,t)===null)return;const v=c.screenOrder[t];v&&c.screenValidity[v]===!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||!Je.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||!Je.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||!Je.has(l.type))&&l.value!==null&&l.value!==void 0)return!0}return!1}function Mt(e,t,o){const l=be();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(Se(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 Dt=j.createContext(null),mt=[],A=e=>{const t=j.useContext(Dt),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})};V("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:Te(l,o)}})};V("text",Hn);const zn=({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"})})};V("divider",zn);const qn={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&&Ve[s])a=Ve[s];else{const d=qn[i];a=d?Ve[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:Te(l,o)}})]})]})};V("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))})]})]})};V("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})]})};V("computed",Gn);const It=({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:Te(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(v=>v);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(It,{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,{})})]})})};V("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)})})};V("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())},v=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))},b=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:v,onFocus:()=>x(!0),onBlur:()=>b(x)})]})})}const f=(h,g)=>{g(!1);const v=m(h.target.value);v!==h.target.value&&(h.target.value=v,i(e,v))};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)})]})})};V("inputNumber",Kn);function Le(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 Me(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);Le(d,a,j.useCallback(()=>c(!1),[]));const p=Me(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,v)=>{const b=g.value.toString()===(t==null?void 0:t.toString());return n.jsxs("div",{className:`fbre-dropdown__option${b?" fbre-dropdown__option--selected":""}`,onClick:()=>{i(e,g.value),c(!1)},children:[n.jsx("span",{children:g.label}),b&&n.jsx("span",{className:"fbre-dropdown__option-check",children:n.jsx(Z,{})})]},`${e}-${v}`)})})]})})};V("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);Le(d,a,j.useCallback(()=>c(!1),[]));const p=Me(u,a,200);if(!s)return null;const m=s.readOnly===!0,f=t??[],h=t!=null&&l===!1,g=b=>{const x=b.toString(),_=f.includes(x)?f.filter(N=>N!==x):[...f,x];i(e,_)},v=(b,x)=>{x.stopPropagation(),i(e,f.filter(_=>_!==b))};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(b=>{const x=s.options.find(_=>_.value.toString()===b);return n.jsxs("span",{className:"fbre-dropdown__tag",children:[(x==null?void 0:x.label)??b,!m&&n.jsx("button",{type:"button",className:"fbre-dropdown__tag-remove",onClick:_=>v(b,_),children:"×"})]},b)})}):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((b,x)=>{const _=f.includes(b.value.toString());return n.jsxs("div",{className:"fbre-dropdown__option",onClick:()=>g(b.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:b.label})]},`${e}-${x}`)})})]})})};V("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:Te(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(It,{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}`)})})};V("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}`)})})};V("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&&n.jsx("div",{className:"fbre-card-select__title",children:d.title}),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))})]})};V("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]||Ge,g=(x,_)=>{const N=_&&p<=.5?x+.5:x+1;i(e,N)},v=(x,_)=>{const N=_.currentTarget.getBoundingClientRect(),R=_.clientX-N.left<N.width/2&&p<=.5?x+.5:x+1;d(R)},b=[];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":""}`;b.push(n.jsx("div",{className:S,onMouseMove:R=>v(x,R),onMouseLeave:()=>d(null),onClick:R=>{const w=R.currentTarget.getBoundingClientRect(),k=R.clientX-w.left<w.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:b}),s!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[s," / ",u]})]})})};V("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})]})]})})};V("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})]})})};V("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)},vt=(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 ve extends Error{constructor(t,o,l,r){super(t),this.name="ApiError",this.status=o,this.code=l,this.validationErrors=r}}class At extends ve{constructor(t,o){super(`Request timed out after ${o}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const as=new Set([502,503,504]),ye=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<=ye;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 ve(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(c<ye&&as.has(p.status)){a=f;continue}throw f}return p.json()}catch(d){if(d instanceof ve)throw d;if(d instanceof DOMException&&d.name==="AbortError"){const u=new At(r,i);if(c<ye){a=u;continue}throw u}if(d instanceof TypeError&&c<ye){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 vs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:o})})}async function bs(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 v=g.target.files[0];if(!v)return;if(s.maxSize&&v.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,v.name,v.type,v.size,e);await fetch(_,{method:"PUT",headers:{"Content-Type":v.type},body:v}),await fs(m.config,m.flowId,x);const N={mode:"s3",fileId:x,name:v.name,type:v.type,size:v.size};i(e,N),vt("file-upload",e,N)}catch(x){console.error("File upload failed:",x),c(!0),setTimeout(()=>c(!1),5e3)}finally{u(!1)}return}const b=new FileReader;b.addEventListener("load",()=>{const x={name:v.name,type:v.type,size:v.size,lastModified:v.lastModified,data:b.result};"lastModifiedDate"in v&&(x.lastModifiedDate=v.lastModifiedDate),i(e,x),vt("file-upload",e,x)}),b.readAsDataURL(v)};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:"×"})]})]})})};V("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})]})})};V("yesNo",ys);const bt=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)}`},je=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}},Ae=e=>/^#[0-9a-fA-F]{6}$/.test(e),js=({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"&&Ae(t)?t:"#1976d2",[v,b]=j.useState(()=>je(g));Le(d,a,j.useCallback(()=>c(!1),[]));const x=Me(u,a,320);if(j.useEffect(()=>{typeof t=="string"&&Ae(t)&&(h(t),b(je(t)))},[t]),!s)return null;const _=t!=null&&l===!1,N=y=>{b(y);const C=bt(y);h(C),i(e,C)},S=y=>{y.preventDefault();const C=(I,D)=>{const L=p.current.getBoundingClientRect(),F=Math.max(0,Math.min(100,(I-L.left)/L.width*100)),H=Math.max(0,Math.min(100,(1-(D-L.top)/L.height)*100));N({...v,s:F,b:H})};C(y.clientX,y.clientY);const E=I=>C(I.clientX,I.clientY),T=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",T)},R=y=>{y.preventDefault();const C=I=>{const D=m.current.getBoundingClientRect(),L=Math.max(0,Math.min(360,(I-D.left)/D.width*360));N({...v,h:L})};C(y.clientX);const E=I=>C(I.clientX),T=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",T)},w=y=>{if(h(y),Ae(y)){const C=je(y);b(C),i(e,y.toLowerCase())}},k=bt({h:v.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:`${v.s}%`,top:`${100-v.b}%`}})]}),n.jsx("div",{className:"fbre-colorpicker__hue",ref:m,onMouseDown:R,children:n.jsx("div",{className:"fbre-colorpicker__hue-cursor",style:{left:`${v.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=>w(y.target.value),maxLength:7})}),s.swatches&&s.swatches.length>0&&n.jsx("div",{className:"fbre-colorpicker__swatches",children:s.swatches.map((y,C)=>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),b(je(E)),i(e,E)}},C))})]})]})})};V("colorPicker",js);const _s=({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,v=j.useCallback(()=>{const y=u.current,C=p.current;if(!y||!C)return;const E=C.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 I=y.getContext("2d");I&&(I.scale(T,T),I.lineCap="round",I.lineJoin="round",I.lineWidth=2,I.strokeStyle="var(--fbre-text, #1a1a1a)")},[]);j.useEffect(()=>{if(c==="draw")return v(),window.addEventListener("resize",v),()=>window.removeEventListener("resize",v)},[c,v]);const b=y=>{const E=u.current.getBoundingClientRect();return{x:y.clientX-E.left,y:y.clientY-E.top}},x=j.useCallback((y,C)=>{var I;const E=(I=u.current)==null?void 0:I.getContext("2d");if(!E)return;const T={x:(y.x+C.x)/2,y:(y.y+C.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 C=u.current;C&&(C.setPointerCapture(y.pointerId),m.current=!0,f.current=b(y.nativeEvent),h.current=!0)},[]),N=j.useCallback(y=>{if(!m.current||!f.current)return;const C=b(y.nativeEvent);x(f.current,C),f.current=C},[x]),S=j.useCallback(()=>{if(!m.current)return;m.current=!1,f.current=null;const y=u.current;if(y&&h.current){const C=y.toDataURL("image/png");i(e,C)}},[e,i]),R=()=>{const y=u.current;if(y){const C=y.getContext("2d");C&&C.clearRect(0,0,y.width,y.height)}h.current=!1,i(e,null)},w=y=>{const C=y.target.value;i(e,C||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:w}),t&&typeof t=="string"&&!t.startsWith("data:")&&n.jsx("div",{className:"fbre-signature__typed-preview",children:t})]})]})}):null};V("signature",_s);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);Le(r,e,j.useCallback(()=>t(),[t]));const i=Me(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})},Fe=(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")}`,ws=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}},ke=(e,t)=>{const o=ws(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}`},Ee=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}`},Ye=(e,t)=>{const o=e.indexOf("T");if(o===-1)return e;const l=e.substring(0,o),r=e.substring(o+1);return`${ke(l,t)} ${Ee(r)}`},Ns=(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")}`},Ss=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}},ks=(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())},Es=["January","February","March","April","May","June","July","August","September","October","November","December"],Rs=e=>Es[e],Ts=["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=Fe(p,f),v=Cs(p,f),b=()=>{f===0?(m(p-1),h(11)):h(f-1)},x=()=>{f===11?(m(p+1),h(0)):h(f+1)},_=[],N=f===0?Fe(p-1,11):Fe(p,f-1);for(let y=v-1;y>=0;y--){const C=N-y,E=f===0?11:f-1,T=f===0?p-1:p;_.push({day:C,iso:fe(T,E,C),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 C=f===11?0:f+1,E=f===11?p+1:p;_.push({day:y,iso:fe(E,C,y),outside:!0})}const R=s??i,w=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:b,children:"‹"}),n.jsxs("span",{className:"fbre-calendar__nav-title",children:[Rs(f)," ",p]}),n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:x,children:"›"})]}),n.jsx("div",{className:"fbre-calendar__weekdays",children:Ts.map(y=>n.jsx("div",{className:"fbre-calendar__weekday",children:y},y))}),n.jsx("div",{className:"fbre-calendar__grid",children:_.map((y,C)=>{const E=y.iso===e,T=y.iso===c,I=t&&y.iso<t||o&&y.iso>o,D=w&&k&&ks(y.iso,w,k),L=y.iso===w,F=y.iso===k,H=["fbre-calendar__day",y.outside&&"fbre-calendar__day--outside",E&&"fbre-calendar__day--selected",T&&"fbre-calendar__day--today",I&&"fbre-calendar__day--disabled",D&&"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:()=>!I&&!y.outside&&l(y.iso),children:y.day},C)})})]})},Ls=({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:ke(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)}})})]})})};V("date",Ls);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},Pe=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,Ie=({value:e,min:t,max:o,step:l=15,onChange:r})=>{const i=j.useRef(null),s=j.useRef(null),a=e?Ss(e):{hour:12,minute:0,ampm:"AM"},{hour:c,minute:d,ampm:u}=a,p=Array.from({length:12},(w,k)=>k+1),m=[];for(let w=0;w<60;w+=l)m.push(w);const f=["AM","PM"],h=j.useMemo(()=>gt(t),[t]),g=j.useMemo(()=>gt(o),[o]),v=h!==null||g!==null,b=(w,k)=>{const y=w*60+k;return!(h!==null&&y<h||g!==null&&y>g)},x=(w,k)=>{if(!v)return!1;const y=Pe(w,k);for(let C=0;C<60;C+=l)if(b(y,C))return!1;return!0},_=w=>{if(!v)return!1;const k=Pe(c,u);return!b(k,w)},N=w=>{if(!v)return!1;for(const k of p){const y=Pe(k,w);for(let C=0;C<60;C+=l)if(b(y,C))return!1}return!0},S=(w,k,y)=>{r(Ns(w,k,y))};j.useEffect(()=>{const w=k=>{if(!k)return;const y=k.querySelector(".fbre-time-selector__cell--selected");y&&y.scrollIntoView({block:"center",behavior:"instant"})};w(i.current),w(s.current)},[]);const R=(w,k,y)=>{let C=w;return k&&(C+=" fbre-time-selector__cell--selected"),y&&(C+=" fbre-time-selector__cell--disabled"),C};return n.jsxs("div",{className:"fbre-time-selector",children:[n.jsx("div",{className:"fbre-time-selector__column",ref:i,children:p.map(w=>{const k=x(w,u);return n.jsx("div",{className:R("fbre-time-selector__cell",w===c,k),onClick:k?void 0:()=>S(w,d,u),children:w},w)})}),n.jsx("div",{className:"fbre-time-selector__column",ref:s,children:m.map(w=>{const k=_(w);return n.jsx("div",{className:R("fbre-time-selector__cell",w===d,k),onClick:k?void 0:()=>S(c,w,u),children:String(w).padStart(2,"0")},w)})}),n.jsx("div",{className:"fbre-time-selector__column fbre-time-selector__column--ampm",children:f.map(w=>{const k=N(w);return n.jsx("div",{className:R("fbre-time-selector__cell",w===u,k),onClick:k?void 0:()=>S(c,d,w),children:w},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)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholder??"Select time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(We,{})})]}),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(Ie,{value:p||void 0,step:s.step,min:s.min,max:s.max,onChange:m=>{i(e,m)}})]})]})})};V("time",Ms);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):"",v=h!==-1?f.substring(h+1):"",b=()=>{u(g?"time":"date"),c(!0)},x=()=>{c(!1),u("date")},_=k=>{i(e,`${k}T${v||"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),w=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:b,children:[f?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ye(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:w,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(Ie,{value:v||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:N})]})})]})})};V("dateTime",Ds);const Is=({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=b=>{if(a==="start"){const x=h&&b>h?"":h;i(e,{start:b,end:x}),c(x?null:"end")}else if(a==="end"){const x=f&&b<f?b:f,_=b<x?x:b;i(e,{start:x||b,end:x?_:""}),x&&_&&c(null)}u(void 0)},v=a!==null;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:v,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:ke(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:ke(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:v,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})})]})})};V("dateRange",Is);const Bs=({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=v=>{if(a==="start"){const b=m&&v>m?"":m;i(e,{start:v,end:b})}else if(a==="end"){const b=p&&v<p?p:v;i(e,{start:p,end:b})}},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:Ee(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(We,{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:Ee(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(We,{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(Ie,{value:a==="start"?p||void 0:m||void 0,step:s.step,min:s.min,max:s.max,onChange:f})]})]})})};V("timeRange",Bs);const Os=({uuid:e})=>{var T,I;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=D=>{const L=D.indexOf("T");return L!==-1?{date:D.substring(0,L),time:D.substring(L+1)}:{date:"",time:"12:00"}},v=f?g(f):{date:"",time:"12:00"},b=h?g(h):{date:"",time:"12:00"},x=a==="start"?v:b,_=(D,L)=>{const F=D&&L&&L<D?"":L;i(e,{start:D,end:F})},N=D=>{u((D==="start"?v:b).date?"time":"date"),c(D)},S=()=>{c(null),u("date")},R=D=>{const L=x.time||"12:00",F=`${D}T${L}`;a==="start"?_(F,h):_(f,F),u("time")},w=D=>{const L=x.date;if(!L)return;const F=`${L}T${D}`;a==="start"?_(F,h):_(f,F)},k=()=>{u("date")},y=a!==null,C=ne((T=s.min)==null?void 0:T.split("T")[0]),E=ne((I=s.max)==null?void 0:I.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:Ye(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:Ye(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:C,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(Ie,{value:x.time||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:w})]})})]})})};V("dateTimeRange",Os);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(Dt.Provider,{value:r,children:n.jsx(a,{uuid:e})})})},$s=({uuid:e})=>{const t=B(s=>{var a;return(a=s.components[e])==null?void 0:a.properties}),o=B(s=>{var a;return(a=s.components[e])==null?void 0:a.addedComponents}),[l,r]=j.useState(!0);if(!t)return null;const i=o??[];return n.jsx("div",{className:"fbre-group",children:i.map((s,a)=>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:s.map(c=>n.jsx(Ft,{uuid:c.uuid},c.uuid))})})]},`${e}-${a}`))})};V("group",$s);const Vs=({uuid:e})=>{const t=B(m=>{var f;return(f=m.components[e])==null?void 0:f.properties}),o=B(m=>{var f;return(f=m.components[e])==null?void 0:f.addedComponents}),l=B(m=>m.addRepeaterIteration),r=B(m=>m.removeRepeaterIteration),[i,s]=j.useState(new Set([0]));if(!t)return null;const a=o??[],c=1,d=()=>{const m=a.length;l(e),s(new Set([m]))},u=m=>{a.length<=c||(r(e,m),s(f=>{const h=new Set;for(const g of f)g<m?h.add(g):g>m&&h.add(g-1);return h}))},p=m=>{s(f=>{const h=new Set(f);return h.has(m)?h.delete(m):h.add(m),h})};return n.jsxs("div",{className:"fbre-group fbre-repeater",children:[a.map((m,f)=>{const h=i.has(f);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?`#${f+1}`:""]}),a.length>c&&n.jsx("button",{type:"button",className:"fbre-repeater__remove-btn",onClick:()=>u(f),title:"Remove","aria-label":"Remove iteration",children:n.jsx(xn,{size:14})}),t.collapsible&&n.jsx("button",{type:"button",className:`fbre-group__collapse-btn${h?"":" collapsed"}`,onClick:()=>p(f),"aria-label":"Toggle repeater",children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${!h&&t.collapsible?" collapsed":""}`,children:n.jsx("div",{className:"fbre-group__content",children:m.map(g=>n.jsx(Ft,{uuid:g.uuid},g.uuid))})})]},`${e}-${f}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:d,children:"Add another"})]})};V("repeater",Vs);const As={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"},Fs=({screenIndex:e,onFlowComplete:t,onScreenChange:o})=>{var Xe,Ke,Ze,Qe,et,tt,nt,st,rt,ot,lt;const l=B($=>$.config),r=B($=>$.screenOrder.length),i=B($=>Object.keys($.components).length>0),s=be(),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=((Xe=l==null?void 0:l.navigation)==null?void 0:Xe.transition)??"none",f=m!=="none",[h,g]=j.useState(null),[v,b]=j.useState(!1),[x,_]=j.useState("forward"),[N,S]=j.useState(!1),R=j.useRef(null);j.useEffect(()=>{const $=Math.max(0,Math.min(e,r-1));d($)},[e]);const w=B($=>$.screenOrder[c]),k=B($=>w?$.screenValidity[w]??!0:!0),y=B($=>{var W;return w?(W=$.screens[w])==null?void 0:W.nextButtonLabel:void 0}),C=B($=>{var W;return w?(W=$.screens[w])==null?void 0:W.backButtonLabel:void 0}),E=j.useCallback($=>{o&&o($,s.getState().getFlowData())},[o,s]),T=j.useCallback($=>{g(c),b(u),_($),S(!0),R.current&&(R.current.scrollTop=0)},[c,u]),I=j.useCallback(()=>{S(!1),g(null)},[]),D=j.useCallback(()=>{if(!N)if(u)f&&T("back"),p(!1),E(c);else{const $=s.getState(),W=Vn($,c);W!==c&&(f&&T("back"),d(W),E(W))}},[N,u,c,f,T,E,s]),L=j.useCallback(()=>{if(N)return;const $=s.getState(),W=Se($,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 $=t(s.getState().getFlowData());$&&typeof $.then=="function"&&(H(!0),$.then(()=>{H(!1)}).catch(W=>{H(!1),G(W instanceof Error?W.message:String(W))}))},[t,s]),ee=B($=>Se($,c)===null),M=((Ke=l==null?void 0:l.theme)==null?void 0:Ke.darkMode)??!1,O=((l==null?void 0:l.mode)??"standard")==="conversational";Lt(O&&!u,c,L),Mt(O&&!u,c,L);const Y=((Ze=l==null?void 0:l.theme)==null?void 0:Ze.style)??"clean",ie=((Qe=l==null?void 0:l.controls)==null?void 0:Qe.stepperStyle)??"default",ae=ie==="default"?As[Y]??"dots":ie,Ut=((et=l==null?void 0:l.controls)==null?void 0:et.showStepper)!==!1&&ae==="text",Be={};(tt=l==null?void 0:l.theme)!=null&&tt.color&&(Be["--fbre-theme-color"]=l.theme.color);const Ht=()=>v?n.jsx(ut,{}):h!==null?n.jsx(qe,{screenIndex:h}):null,zt=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(Be).length>0?Be:void 0,children:[Ut&&n.jsx(In,{current:c,total:r}),n.jsxs("div",{className:zt,ref:R,children:[N&&n.jsx("div",{className:"fbre-screen--exiting","data-direction":x,onAnimationEnd:I,children:Ht()}),n.jsxs("div",{className:N?"fbre-screen--entering":void 0,"data-direction":N?x:void 0,children:[!u&&n.jsx(qe,{screenIndex:c}),u&&n.jsx(ut,{})]})]}),P&&n.jsx("div",{className:"fbre-completion-error",children:P}),((nt=l==null?void 0:l.controls)==null?void 0:nt.show)!==!1&&i&&n.jsx(Bn,{screenIndex:c,maxScreenIndex:r-1,allowInvalidTransition:(st=l==null?void 0:l.navigation)==null?void 0:st.allowInvalidTransition,screenValidity:k,summaryEnabled:(l==null?void 0:l.summary)??!1,summaryActive:u,atMaxScreen:ee,nextButtonLabel:y,backButtonLabel:C,completionLoading:F,showStepper:(rt=l==null?void 0:l.controls)==null?void 0:rt.showStepper,stepperStyle:(ot=l==null?void 0:l.controls)==null?void 0:ot.stepperStyle,controlsLayout:(lt=l==null?void 0:l.controls)==null?void 0:lt.layout,nextScreen:L,prevScreen:D,onFlowComplete:J})]})},Ps=[],Us=()=>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],v=parseInt(h[1]),b=parseInt(h[2]),x=r.components[g];if(!((f=(m=x==null?void 0:x.addedComponents)==null?void 0:m[v])!=null&&f[b]))return;x.addedComponents[v][b]={...x.addedComponents[v][b],value:l};const _=r.groupComponentMap[o]??o,N=r.conditionsByDependency[_];let S=r.conditionResults;if(N&&N.length>0){S={...r.conditionResults};for(const C of N)S[C.target]=ce({...r},C.config)}const R={components:r.components,groupComponentMap:r.groupComponentMap},w=z(x.addedComponents[v][b],R);x.addedComponents[v][b].valid=w.length===0;const k={...r.validationErrors,[o]:w},y=r.validationsByDependency[o];if(y)for(const C of y){const E=yt(r,C.target);if(E){const T=z(E,R);E.valid=T.length===0,k[C.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 v=z(g,c);g.valid=v.length===0,u[h.target]=v}}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]??Ps,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 b=o.conditionResults[h.uuid]??!1;if(g.action==="show"&&!b||g.action==="hide"&&b)continue}const v=z(h,s);h.valid=v.length===0,a[h.uuid]=v,v.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})),_e=(e,t)=>{var h,g;const o={},l={},r={},i={},s={},a={},c=t.screen.uuid;for(const v of t.screen.components){const b=Q(v);if(o[b.uuid]=b,(b.type==="group"||b.type==="repeater")&&v.components){b.addedComponents||(b.addedComponents=[]);const x=v.components.map((_,N)=>{var R;const S=Q(_);if(S.uuid=[b.uuid,0,N].join(":"),b.type==="group"&&(l[S.uuid]=_.uuid),r[_.uuid]=S.uuid,(R=S.properties)!=null&&R.validation){const w=S.properties.validation;w.rules&&w.rules.length>0&&me(s,S.uuid,w)}return S});b.addedComponents.push(x)}if((h=b.properties)!=null&&h.validation){const x=b.properties.validation;x.rules&&x.rules.length>0&&me(s,b.uuid,x)}}for(const{targetUUID:v,config:b}of t.conditions)re(i,v,b,v===c?"screen":"component");if(t.previousData)for(const v of t.previousData){const b=o[v.uuid];b&&(b.value=v.value)}const d={components:o};for(const v of Object.keys(o)){const b=o[v];if(b.type==="group"||b.type==="repeater"){if(b.addedComponents)for(const _ of b.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=b.properties)!=null&&g.validation))continue;const x=z(b,d);b.valid=x.length===0,x.length>0&&(a[v]=x)}const u={},p={components:o},m=new Set;for(const v of Object.values(i))for(const b of v)m.has(b.target)||(m.add(b.target),u[b.target]=ce(p,b.config));let f=!0;for(const v of t.screen.components){const b=o[v.uuid];if(b)if((b.type==="group"||b.type==="repeater")&&b.addedComponents)for(const x of b.addedComponents){for(const _ of x)if(!_.valid){f=!1;break}if(!f)break}else b.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??{}})},Ue=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||we(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=>!we(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),Hs=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=Us());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),v=K.useStore(d,M=>M.screens),[b,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)},[]),w=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);_e(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<Hs))try{const Y=await xs(S,X.sessionId);_e(d,Y)}catch(Y){Y instanceof ve&&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(),w();try{const O=Ue(d),Y=await hs(S,M.sessionId,O);_e(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,w]),C=j.useCallback(async()=>{const M=d.getState();if(!M.loading){d.setState({loading:!0}),d.getState().clearError(),w();try{const X=Ue(d),O=await vs(S,M.sessionId,X);_e(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,w]),E=j.useCallback(async()=>{const M=d.getState();if(!(M.loading||!M.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),w();try{const O=Ue(d),Y=await bs(S,M.sessionId,O);N.current=Date.now(),s(Y)}catch(O){d.setState({loading:!1}),R(O.message)}}},[S,d,s,R,w]),T={...f==null?void 0:f.theme,...r},D=(l??h??"standard")==="conversational",L=D&&!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?v[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(Re.Provider,{value:d,children:n.jsxs("div",{className:"fbre-container","data-style":T.style??"clean","data-mode":F?"dark":"light","data-form-mode":D?"conversational":void 0,style:Object.keys(H).length>0?H:void 0,children:[n.jsx("div",{className:"fbre-screen-wrapper",children:n.jsx(qe,{screenIndex:0})}),n.jsx(qs,{navigation:m,loading:u,onPrev:C,onNext:y,onComplete:E,nextButtonLabel:J,backButtonLabel:ee}),n.jsxs("div",{className:`fbre-toast${b?" visible":""}`,children:[n.jsx("span",{children:b}),n.jsx("button",{type:"button",className:"fbre-toast__close",onClick:w,"aria-label":"Dismiss",children:"×"})]})]})})},qs=({navigation:e,loading:t,onPrev:o,onNext:l,onComplete:r,nextButtonLabel:i,backButtonLabel:s})=>n.jsxs("div",{className:"fbre-controls",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 Ws(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 v=f.current.getState(),b=Ws(v.config,l,r,i,o);b!==v.config&&f.current.setState({config:b})}},[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(Re.Provider,{value:f.current,children:n.jsx(Fs,{screenIndex:s??0,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p})});return m?n.jsx($t.Provider,{value:m,children:g}):g},Ys=({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),[v,b]=j.useState(""),[x,_]=j.useState(null);return j.useEffect(()=>{g(null),b("");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=>b(S.message))},[e,t,o]),v?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:v})]})}):!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})},Gs=e=>"sessionEndpoint"in e?n.jsx(zs,{...e}):"flowId"in e&&e.flowId?n.jsx(Ys,{...e}):n.jsx(Pt,{...e});exports.ApiError=ve;exports.FBRE=Gs;exports.TimeoutError=At;exports.addFBREEventListener=ls;exports.removeFBREEventListener=is;exports.useFBREApi=Vt;exports.useFBREStore=B;exports.useFBREStoreApi=be;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),j=require("react"),K=require("zustand"),Wt=require("@sonata-innovations/fiber-types"),F=require("@sonata-innovations/fiber-shared"),Yt=require("react-dom"),jt=new Map,$=(e,t)=>{jt.set(e,t)},_t=e=>jt.get(e),Gt=new Set(["header","text","divider","callout","table"]),Ne=e=>Gt.has(e),Jt=(e,t)=>{var o,i,r,l;if(t.includes(":")){const s=t.split(":"),a=e.components[s[0]];return(r=(i=(o=a==null?void 0:a.addedComponents)==null?void 0:o[parseInt(s[1])])==null?void 0:i[parseInt(s[2])])==null?void 0:r.value}return(l=e.components[t])==null?void 0:l.value},z=(e,t)=>{var i;const o=(i=e.properties)==null?void 0:i.validation;return!o||!o.rules||o.rules.length===0?[]:F.validateValue(e.value,o,t?r=>Jt(t,r):void 0)},Xt=e=>{var o;const t=(o=e.properties)==null?void 0:o.validation;return!t||!t.rules?!1:t.rules.some(i=>i.type==="required")},Q=e=>{var o,i;const t={...e};return Array.isArray((o=t.properties)==null?void 0:o.options)&&(t.properties={...t.properties,options:Wt.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=!Xt(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"&&((i=e.properties)!=null&&i.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 i;for(const r of o.rules)if(r.type==="matchesField"&&((i=r.params)!=null&&i.field)){const l=r.params.field;e[l]||(e[l]=[]),e[l].push({target:t,config:o})}},oe=(e,t)=>{const o=e.screens[t];return o?!o.components.some(r=>{var a;const l=e.components[r.uuid];if(!l)return!1;if(l.type==="group"||l.type==="repeater")return(a=l.addedComponents)==null?void 0:a.some(c=>c.some(d=>{const u=d.conditions&&"when"in d.conditions?d.conditions:void 0;return u&&F.isHiddenByCondition(u,e.conditionResults[d.uuid])?!1:!d.valid}));const s=l.conditions&&"when"in l.conditions?l.conditions:void 0;return F.isHiddenByCondition(s,e.conditionResults[l.uuid])?!1:l&&"valid"in l&&!l.valid}):!0};function Kt(e){const t={};for(const o of e){const i=F.extractFormulaReferences(o.formula);for(const r of i)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 i=te(e,o);if(!i)return null;const r=i.value;if(r==null||r==="")return null;const l=Number(r);return isNaN(l)?null:l},resolveOptionMetadata:(o,i)=>{var u;const r=te(e,o);if(!r)return null;const l=r.value;if(!l)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===l||p.label===l);if(!(a!=null&&a.metadata))return null;const c=a.metadata[i];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:o=>{for(const i of Object.keys(e.components)){const r=e.components[i];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const l=r.components.findIndex(a=>a.uuid===o);if(l===-1)continue;const s=[];for(const a of r.addedComponents){const c=a[l];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=F.topologicalSortCalculations(t),i={},r=wt(e,i);for(const l of o)i[l.uuid]=F.evaluateFormula(l.formula,r);return i}function $e(e,t){const o=e.calculationsByDependency,i=e.calculations??[];if(i.length===0||!o)return null;const r=new Set,l=[t];for(;l.length>0;){const u=l.shift(),p=o[u];if(p)for(const m of p)r.has(m)||(r.add(m),l.push(m))}if(r.size===0)return null;const s=F.topologicalSortCalculations(i),a={...e.calculationResults},c=wt(e,a);let d=!1;for(const u of s)if(r.has(u.uuid)){const p=F.evaluateFormula(u.formula,c);a[u.uuid]!==p&&(a[u.uuid]=p,d=!0)}return d?a:null}function Zt(e){const t={},o=i=>{var l;if(i.type!=="computed"||!((l=i.properties)!=null&&l.formula))return;const r=F.extractFormulaReferences(i.properties.formula);for(const s of r)t[s]||(t[s]=[]),t[s].includes(i.uuid)||t[s].push(i.uuid)};for(const i of Object.values(e))if(o(i),(i.type==="repeater"||i.type==="group")&&i.components)for(const r of i.components)o(r);return t}function Ct(e,t,o,i){var c,d;const r=e.components[o],l=((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[i],a=new Map;if(s)for(let u=0;u<s.length;u++){const p=l[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 v=Number(g);return isNaN(v)?null:v}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 v=g.find(N=>N.value===h||N.label===h);if(!(v!=null&&v.metadata))return null;const b=v.metadata[p];if(b==null)return null;const x=Number(b);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 v=g[f];if(!v)continue;const b=v.value;if(b==null||b==="")continue;const x=Number(b);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 i=te(e,o);if(!i)return null;const r=i.value;if(r==null||r==="")return null;const l=Number(r);return isNaN(l)?null:l},resolveOptionMetadata:(o,i)=>{var u;const r=te(e,o);if(!r)return null;const l=r.value;if(!l)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===l||p.label===l);if(!(a!=null&&a.metadata))return null;const c=a.metadata[i];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:o=>{for(const i of Object.keys(e.components)){const r=e.components[i];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const l=r.components.findIndex(a=>a.uuid===o);if(l===-1)continue;const s=[];for(const a of r.addedComponents){const c=a[l];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,i;const t=e.calculationResults??{};for(const r of Object.values(e.components))if(r.type==="computed"&&((o=r.properties)!=null&&o.formula)){const l=Se(e,t),s=F.evaluateFormula(r.properties.formula,l);r.value=s}for(const r of Object.values(e.components))if((r.type==="repeater"||r.type==="group")&&r.addedComponents&&r.components)for(let l=0;l<r.addedComponents.length;l++){const s=r.addedComponents[l];for(let a=0;a<s.length;a++){const c=s[a],d=r.components[a];if((d==null?void 0:d.type)==="computed"&&((i=d.properties)!=null&&i.formula)){const u=r.type==="repeater"?Ct(e,t,r.uuid,l):Se(e,t),p=F.evaluateFormula(d.properties.formula,u);c.value=p}}}}function Qt(e,t){var s,a;const o=e.computedByDependency;if(!o)return!1;const i=o[t];if(!i||i.length===0)return!1;const r=e.calculationResults??{};let l=!1;for(const c of i){const d=e.components[c];if(d&&d.type==="computed"&&((s=d.properties)!=null&&s.formula)){const u=Se(e,r),p=F.evaluateFormula(d.properties.formula,u);d.value!==p&&(e.components[c]={...d,value:p},l=!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),v=F.evaluateFormula(m.properties.formula,g);h.value!==v&&(u.addedComponents[f][p]={...h,value:v},l=!0)}}}return l}const Nt=(e,t)=>{var o,i;if(t.includes(":")){const r=t.split(":"),l=e[r[0]];return(i=(o=l==null?void 0:l.addedComponents)==null?void 0:o[parseInt(r[1])])==null?void 0:i[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},en=(e,t)=>{if(!t.includes(":"))return null;const o=t.split(":");if(o.length!==3)return null;const i=o[0],r=parseInt(o[2]),l=e.components[i];if(!l||l.type!=="repeater"||!l.components)return null;const s=l.components[r];return(s==null?void 0:s.uuid)??null},at=(e,t,o,i,r)=>{const l=t(),s=l.groupComponentMap[o]??o,a=sn(e,t,s),c={components:l.components,groupComponentMap:l.groupComponentMap},d=z(i,c);i.valid=d.length===0;const u={...l.validationErrors,[o]:d},p=l.validationsByDependency[o];if(p)for(const _ of p){const N=te(l,_.target);if(N){const S=z(N,c);N.valid=S.length===0,u[_.target]=S}}const m=Ce(l,r),f={components:{...l.components},validationErrors:u};if(a&&(f.conditionResults=a),m){const _={...l,...f};f.screenValidity={...l.screenValidity,[m]:oe(_,m)}}const h={...l,...f},g=o.includes(":")?en(h,o):null,v=[],b=_=>{if(Qt(h,_)){const N=h.computedByDependency[_]??[];for(const S of N)v.includes(S)||(v.push(S),b(S))}};b(s),g&&g!==s&&b(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 v){const N=x?{...h,calculationResults:x}:h,S=$e(N,_);S&&(x=S)}x&&(f.calculationResults=x),e(f)},tn=(e,t)=>({updateComponentValue:(o,i)=>{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!==i;if(m.addedComponents[u][p]={...m.addedComponents[u][p],value:i},f){at(e,t,o,m.addedComponents[u][p],d);return}e({components:{...r.components}});return}const l=r.components[o];if(l){if(l.type==="group"||l.type==="repeater"){e({components:{...r.components}});return}if(i===l.value){e({selectionTick:t().selectionTick+1});return}l.value=i,at(e,t,o,l,o)}},addGroupIteration:o=>{const i=t(),r=i.components[o];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l={...i.conditionsByDependency},s=r.components.map((d,u)=>{const p=Q(d);if(p.uuid=[o,r.addedComponents.length,u].join(":"),i.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(l,p.uuid,f,"component"))}const m=z(p);return p.valid=m.length===0,p});r.addedComponents.push(s);const a=Ce(i,o),c={...i.screenValidity};return a&&(c[a]=oe({...i},a)),e({components:{...i.components},groupComponentMap:{...i.groupComponentMap},conditionsByDependency:l,screenValidity:c}),r.addedComponents},addRepeaterIteration:o=>{const i=t(),r=i.components[o];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l={...i.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(l,f.uuid,g,"component"))}const h=z(f);return f.valid=h.length===0,f});r.addedComponents.push(s);const a=Ce(i,o),c={...i.screenValidity};a&&(c[a]=oe({...i},a));const d={...i,components:{...i.components}};ze(d);const u=qe(d);return e({components:{...i.components},conditionsByDependency:l,screenValidity:c,calculationResults:u}),r.addedComponents},removeRepeaterIteration:(o,i)=>{var g;const r=t(),l=r.components[o];if(!l||l.type!=="repeater"||!l.addedComponents)return;const s=((g=l.properties)==null?void 0:g.minIterations)??1;if(l.addedComponents.length<=s)return;const a=l.addedComponents[i],c=new Set(a.map(v=>v.uuid));l.addedComponents.splice(i,1);const d={...r.conditionsByDependency},u={...r.validationErrors};for(const v of c)delete u[v],delete d[v];for(const v of Object.keys(d)){const b=d[v],x=b.filter(_=>!c.has(_.target));x.length===0?delete d[v]:x.length!==b.length&&(d[v]=x)}for(let v=i;v<l.addedComponents.length;v++)l.addedComponents[v].forEach((b,x)=>{const _=b.uuid,N=[o,v,x].join(":");if(_!==N){b.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,i)=>{const r=new Set;for(const s of o.when.rules)r.add(s.source);const l={target:t,type:i,config:o};for(const s of r)e[s]||(e[s]=[]),e[s].push(l)},nn=(e,t)=>{var o,i;return t.includes(":")?(o=te(e,t))==null?void 0:o.value:(i=e.components[t])==null?void 0:i.value},ce=(e,t)=>F.evaluateConditionConfig(t,(o,i)=>(i==null?void 0:i.sourceType)==="context"?e.externalContext[i.source]:nn(e,o)),sn=(e,t,o)=>{const i=t(),r=i.conditionsByDependency[o];if(!r||r.length===0)return null;let l=!1;const s={...i.conditionResults};for(const a of r){const c=ce(i,a.config);s[a.target]!==c&&(s[a.target]=c,l=!0)}return l?s:null},rn=e=>{const t={},o=new Set;for(const i of Object.values(e.conditionsByDependency))for(const r of i)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},on=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},o=r=>{const l=e.screens[r];if(!l)return!1;const s=l.conditions&&"when"in l.conditions?l.conditions:void 0;return F.isHiddenByCondition(s,e.conditionResults[r])};t.screens=e.screenOrder.filter(r=>!o(r)).map(r=>{const l=e.screens[r],s={uuid:r,components:l.components.map(a=>{const c=e.components[a.uuid];if(!c)return null;const d=ct(c);if(F.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!F.isHiddenByCondition(f,e.conditionResults[m.uuid])}).map(m=>Ve(m)).filter(m=>m!==null))}:null}return Ve(c)}).filter(a=>a!==null)};return l.label&&(s.label=l.label),s});const i=e.calculations??[];if(i.length>0){const r=e.calculationResults??{};t.calculations=i.map(l=>{const s=r[l.uuid]??null,a={uuid:l.uuid,label:l.label,value:s};return s!==null&&(a.formattedValue=F.formatCalculationResult(s,l.format,l.decimalPlaces,l.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 be=()=>{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,ln=[],an=()=>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,i,r)=>{var R;const l={},s=[],a={},c={},d={},u={},p={},m={},f={};o.screens.forEach(C=>{const k=ge(C.conditions),y=k?{...C,conditions:k}:{...C};l[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 P=w.properties??{},H=w.type==="repeater"?P.initialData:void 0,U=w.type==="repeater"?P.minIterations:void 0,G=H?H.length:w.type==="repeater"&&U&&U>1?U: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 le=z(O);return O.valid=le.length===0,le.length>0&&(m[O.uuid]=le),O});L.addedComponents.push(ee)}}})}),i&&i.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((P,H)=>{var ee;const U=Q(P);U.uuid=[w.uuid,w.addedComponents.length,H].join(":"),w.type==="group"&&(c[U.uuid]=P.uuid),d[P.uuid]||(d[P.uuid]=U.uuid);const G=ge(U.conditions);G&&(U.conditions=G,re(u,U.uuid,G,"component")),(ee=U.properties)!=null&&ee.validation&&me(p,U.uuid,U.properties.validation);const J=z(U);return U.valid=J.length===0,J.length>0&&(m[U.uuid]=J),U});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:l,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},g=rn(h);h.conditionResults=g,s.forEach(C=>{f[C]=oe(h,C)});const v=Zt(a),b={...h,computedByDependency:v,calculationResults:{},screenValidity:f};ze(b);const x=o.calculations??[],_=Kt(x),N={...b,calculations:x},S=qe(N);e({flowUUID:o.uuid,metadata:o.metadata,config:o.config??{},externalContext:r??{},screens:l,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:g,screenValidity:f,validationErrors:m,validationsByDependency:p,calculations:x,calculationResults:S,calculationsByDependency:_,computedByDependency:v})},updateContext:o=>{const i=t(),r=i.externalContext,l=[];for(const d of Object.keys(o))r[d]!==o[d]&&l.push(d);for(const d of Object.keys(r))!(d in o)&&!l.includes(d)&&l.push(d);if(l.length===0)return;const s={...i.conditionResults};let a=!1;const c=new Set;for(const d of l){const u=i.conditionsByDependency[d];if(!(!u||u.length===0))for(const p of u){if(c.has(p.target))continue;c.add(p.target);const m={...i,externalContext:o},f=ce(m,p.config);s[p.target]!==f&&(s[p.target]=f,a=!0)}}if(a){const d={...i,conditionResults:s},u={};for(const p of i.screenOrder)u[p]=oe(d,p);e({externalContext:o,conditionResults:s,screenValidity:u})}else e({externalContext:o})},...tn(e,t),getFlowData:()=>on(t()),getScreenByIndex:o=>{const i=t();return o<0||o>=i.screenOrder.length?null:i.screens[i.screenOrder[o]]},getScreenValidity:o=>{const i=t();return o<0||o>=i.screenOrder.length?!0:i.screenValidity[i.screenOrder[o]]??!0},getValidationErrors:o=>t().validationErrors[o]??ln,evaluateFlowValidation:()=>{const o=t(),i={};let r=!0;return o.screenOrder.forEach(l=>{const s=oe(o,l);i[l]=s,s||(r=!1)}),e({screenValidity:i}),r},getMaxScreenCount:()=>t().screenOrder.length-1,getCalculationResult:o=>t().calculationResults[o]??null})),cn=({uuid:e})=>{var a;const t=B(c=>c.components[e]),o=B(c=>c.conditionResults[e]);if(!t)return null;const i=t.conditions&&"when"in t.conditions?t.conditions:void 0;if(F.isHiddenByCondition(i,o))return null;const r=_t(t.type);if(!r)return console.warn(`FBRE: No renderer for component type "${t.type}"`),null;const l=(a=t.properties)==null?void 0:a.width,s=l&&l!=="full"?`fbre-component fbre-width-${l}`:"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 i=o.screenOrder[e];return i?o.screens[i]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(o=>n.jsx(cn,{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"})}),dn=({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"})}),un=({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"})}),pn=({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"})}),fn=({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"})}),mn=({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"})}),hn=({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"})}),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("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"})]}),xn=({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"})]}),gn=({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"})]}),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:"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"})]}),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:"M3 11l18-5v12L3 13v-2z"}),n.jsx("path",{d:"M11.6 16.8a3 3 0 11-5.8-1.6"})]}),_n=({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"})]}),wn=({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"})}),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("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"})}),Nn=({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"})]}),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("path",{d:"M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z"})}),kn=({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"})}),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("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"})]}),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("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"})]}),Tn=({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"})]}),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("circle",{cx:"12",cy:"12",r:"10"})}),Mn=({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:vn,check:bn,warning:xn,question:Rn,lightbulb:yn,megaphone:jn,bell:_n,shield:wn,lock:Cn,heart:St,flag:Nn,bookmark:Sn,zap:kn,pencil:En,star:Je},In={star:Je,heart:St,thumbsUp:Tn,circle:Ln,diamond:Mn},ye=({position:e,screenIndex:t,maxScreenIndex:o,allowInvalidTransition:i,screenValidity:r,summaryEnabled:l,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(pn,{}),d||"Back"]})}const g=l?a&&s:a,v=l?a?s?"Done":"Review":"Next":a?"Done":"Next";if(o===0){const _=l?s?"Complete":"Review":"Complete",N=h||!r;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:N,onClick:()=>{l&&!s?p():f()},children:[c||_,h?n.jsx("span",{className:"fbre-btn__spinner"}):n.jsx(Z,{size:16})]})}const b=h||!i&&!r||v==="Done"&&!r,x=()=>{g?f():p()};return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:b,onClick:x,children:[c||v,h?n.jsx("span",{className:"fbre-btn__spinner"}):g?n.jsx(Z,{size:16}):n.jsx(fn,{})]})},Dn=({current:e,total:t,stepperStyle:o})=>{if(t<=1)return null;const i=t>1?e/(t-1)*100:100,l=!!o&&o!=="default"||t<=6;return n.jsxs(n.Fragment,{children:[l&&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))}),l&&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:`${i}%`}})}),n.jsxs("span",{className:"fbre-stepper__counter",children:[e+1," of ",t]})]}),!l&&n.jsx("div",{className:"fbre-stepper fbre-stepper--bar",children:n.jsx("div",{className:"fbre-stepper__fill",style:{width:`${i}%`}})})]})},Bn=({current:e,total:t})=>t<=1?null:n.jsxs("div",{className:"fbre-stepper-text",children:["Step ",e+1," of ",t]}),On=e=>{const t=e.controlsLayout??"default",i=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text"&&e.maxScreenIndex>0,r=e.screenIndex>0||e.summaryActive,l=r?2:1,s=i?n.jsx(Dn,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):null;if(t==="default"){const a=!r&&!i;return n.jsxs("div",{className:"fbre-controls fbre-controls--default","data-button-count":l,"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":l,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:i,value:r,components:l}=e,s=()=>{if(r!=null)switch(i){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(i==="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=()=>l?l.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${i==="group"||i==="repeater"?" fbre-summary__item--group":""}`,children:[n.jsx("div",{className:"fbre-summary__item-label",children:o}),i!=="group"&&i!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${c?" fbre-summary__item-value--empty":""}`,children:s()}),(i==="group"||i==="repeater")&&a()]})},$n={sm:"12px",lg:"18px",xl:"24px"},Et=/\$\{([^}]+)\}/g,Le=(e,t)=>{const o=e.replace(Et,(i,r)=>{const l=t.resolveCalculation(r);if(l!==null)return dt(l);const s=t.resolveComponentValue(r);return s!==null?dt(s):""});return Rt(o)},ie=(e,t)=>e.replace(Et,(o,i)=>{const r=t.resolveCalculation(i);if(r!==null)return r;const l=t.resolveComponentValue(i);return l!==null?l:""}),dt=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Rt=e=>{let t=e;const o=/\[b.*?\]([\s\S]*?)\[\/b\]/g,i=/\[i.*?\]([\s\S]*?)\[\/i\]/g,r=/\[s\s+size=["'](sm|lg|xl)["']\]([\s\S]*?)\[\/s\]/g,l=/\[l.*?href=["']([\s\S]*?)["'].*?\]([\s\S]*?)\[\/l\]/g;return t=t.replace(o,"<strong>$1</strong>"),t=t.replace(i,"<em>$1</em>"),t=t.replace(r,(s,a,c)=>{const d=$n[a];return d?`<span style="font-size:${d}">${c}</span>`:c}),t=t.replace(l,'<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),i=B(r=>r.calculationResults);return j.useMemo(()=>{const r=new Map(o.map(s=>[s.uuid,s])),l=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=l(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=i[s]??null;return F.formatCalculationResult(c,a.format,a.decimalPlaces,a.currencySymbol)}}},[e,t,o,i])}const Vn=({screen:e,showToggle:t})=>{const o=ue(),[i,r]=j.useState(!0);return n.jsxs("div",{children:[n.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>t&&r(!i),children:[e.label&&n.jsx("span",{className:"fbre-summary__screen-label",children:ie(e.label,o)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${i?"":" collapsed"}`,children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${i?"":" collapsed"}`,children:e.components.map(l=>n.jsx(kt,{component:l},l.uuid))})]})},ut=()=>{const e=be(),t=B(r=>r.components),o=j.useMemo(()=>e.getState().getFlowData(),[e,t]),i=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(Vn,{screen:r,showToggle:i>1},r.uuid))})]})},Tt=(e,t,o)=>t?!F.isHiddenByCondition(t,o[e]):!0,ke=(e,t)=>{const o=e.screenOrder.length-1;let i=t+1;for(;i<=o;){const r=e.screenOrder[i],l=e.screens[r],s=l!=null&&l.conditions&&"when"in l.conditions?l.conditions:void 0;if(Tt(r,s,e.conditionResults))return i;i++}return null},An=(e,t)=>{let o=t-1;for(;o>=0;){const i=e.screenOrder[o],r=e.screens[i],l=r!=null&&r.conditions&&"when"in r.conditions?r.conditions:void 0;if(Tt(i,l,e.conditionResults))return o;o--}return 0},Fn=new Set(["text","header","callout","divider","table","computed"]);function Lt(e,t){const o=e.screenOrder[t];if(!o)return 0;const i=e.screens[o];if(!i)return 0;let r=0;for(const l of i.components){const s=e.components[l.uuid];if(!s||Fn.has(s.type))continue;const a=s.conditions&&"when"in s.conditions?s.conditions:void 0;F.isHiddenByCondition(a,e.conditionResults[l.uuid])||(r+=1)}return r}const Xe=new Set(["radio","yesNo","cardSelect","dropDown"]),Pn=500;function Mt(e,t,o){const i=be(),r=j.useRef(null),l=j.useRef(""),s=j.useRef(0);j.useEffect(()=>{if(!e)return;const a=i.getState(),c=pt(a,t);c&&(l.current=ft(a.components,c)),s.current=a.selectionTick},[e,t,i]),j.useEffect(()=>{if(!e)return;const a=i.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===l.current&&!p)return;const f=l.current;if(l.current=m,!(m!==f?Un(c.components,d,f):p&&Hn(c.components,d))||ke(c,t)===null)return;const v=c.screenOrder[t];v&&c.screenValidity[v]===!1||Lt(c,t)===1&&(r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{r.current=null,o()},Pn))});return()=>{a(),r.current&&(clearTimeout(r.current),r.current=null)}},[e,t,i,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 i=e.screens[o];return i?i.components.map(r=>r.uuid):null}function ft(e,t){const o=[];for(const i of t){const r=e[i];!r||!Xe.has(r.type)||o.push(`${i}=${JSON.stringify(r.value??null)}`)}return o.join("|")}function Un(e,t,o){const i=new Map;for(const r of o.split("|")){const l=r.indexOf("=");l>0&&i.set(r.slice(0,l),r.slice(l+1))}for(const r of t){const l=e[r];if(!l||!Xe.has(l.type))continue;const s=JSON.stringify(l.value??null),a=i.get(r)??"null";if(s!==a&&s!=="null")return!0}return!1}function Hn(e,t){for(const o of t){const i=e[o];if(!(!i||!Xe.has(i.type))&&i.value!==null&&i.value!==void 0)return!0}return!1}function It(e,t,o){const i=be();j.useEffect(()=>{if(!e)return;const r=l=>{if(l.key!=="Enter")return;const s=l.target;if(s.tagName!=="INPUT"||!s.closest(".fbre-container"))return;const a=i.getState();if(ke(a,t)===null)return;const d=a.screenOrder[t];d&&a.screenValidity[d]===!1||Lt(a,t)===1&&(l.preventDefault(),o())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,o,i])}const Dt=j.createContext(null),mt=[],A=e=>{const t=j.useContext(Dt),o=B(a=>{var c;return(c=a.components[e])==null?void 0:c.value}),i=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}),l=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:i,valid:r,validationErrors:l,updateValue:s}},qn=({uuid:e})=>{const{properties:t}=A(e),o=ue(),i=t==null?void 0:t.value;if(!i)return null;const r=ie(i,o);return n.jsx("h2",{className:"fbre-header",children:r})};$("header",qn);const zn=({uuid:e})=>{const{properties:t}=A(e),o=ue(),i=t==null?void 0:t.value;return i==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:Le(i,o)}})};$("text",zn);const Wn=({uuid:e})=>{const{properties:t}=A(e),o=(t==null?void 0:t.textAlign)??"center",i=o==="left"?" fbre-divider--left":o==="right"?" fbre-divider--right":"";return n.jsx("div",{className:`fbre-divider${i}`,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",Wn);const Yn={info:"info",success:"check",warning:"warning",neutral:void 0},Gn=({uuid:e})=>{const{properties:t}=A(e),o=ue(),i=t==null?void 0:t.value,r=t==null?void 0:t.title,l=(t==null?void 0:t.variant)||"info",s=t==null?void 0:t.icon;if(!i&&!r)return null;let a;if(s==="none")a=void 0;else if(s&&Ae[s])a=Ae[s];else{const d=Yn[l];a=d?Ae[d]:void 0}const c=`fbre-callout fbre-callout--${l}`;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:ie(r,o)}),i&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:Le(i,o)}})]})]})};$("callout",Gn);const Jn=({uuid:e})=>{const{properties:t}=A(e),o=t==null?void 0:t.label,i=t==null?void 0:t.columns,r=t==null?void 0:t.rows,l=t==null?void 0:t.highlightColumn,s=l?l-1:-1;return!i||!r||i.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"}),i.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}),i.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",Jn);const Xn=({uuid:e})=>{const{properties:t,value:o}=A(e),i=t==null?void 0:t.label,r=(t==null?void 0:t.showLabel)!==!1,l=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=F.formatCalculationResult(typeof o=="number"?o:null,s,a,c);return n.jsxs("div",{className:"fbre-computed",children:[r&&i&&n.jsx("div",{className:"fbre-computed__label",children:i}),n.jsx("div",{className:"fbre-computed__value",children:d||"—"}),l&&n.jsx("div",{className:"fbre-computed__detail",children:l})]})};$("computed",Xn);const Bt=({text:e})=>{var c;const[t,o]=j.useState(!1),i=j.useRef(null),r=j.useRef(null),[l,s]=j.useState(null),a=j.useCallback(()=>{if(!i.current)return;const d=i.current.getBoundingClientRect();s({top:d.bottom+4,left:d.right})},[]);return j.useEffect(()=>{if(!t)return;a();const d=p=>{const m=p.target;i.current&&!i.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:i,type:"button",className:"fbre-tooltip-trigger",onClick:()=>o(!t),"aria-label":"Help",children:n.jsx(mn,{})}),t&&l&&Yt.createPortal(n.jsx("div",{ref:r,className:"fbre-tooltip-popover open",style:{top:l.top,left:l.left},children:n.jsx("span",{dangerouslySetInnerHTML:{__html:Rt(e)}})}),((c=i.current)==null?void 0:c.closest(".fbre-container"))??document.body)]})},q=({label:e,detail:t,showLabel:o,required:i,helperText:r,tooltip:l,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:[ie(e,p),i&&n.jsx("span",{className:"required",children:"*"})]}),u({focused:m,setFocused:f}),r&&n.jsx("div",{className:"fbre-field__helper",children:ie(r,p)}),(()=>{const g=d==null?void 0:d.filter(v=>v);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)"]})]})})()]}),l&&n.jsx(Bt,{text:l})]})]})},Kn=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,a=j.useRef(null),[c,d]=j.useState(!1);if(!s)return null;const u=t!=null&&i===!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=>l(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(dn,{}):n.jsx(un,{})})]})})};$("inputText",Kn);const Zn=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o;if(!s)return null;const a=t!=null&&i===!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=>l(e,u.target.value),onFocus:()=>d(!0),onBlur:()=>d(!1)})})};$("inputTextArea",Zn);const Qn=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(t??"");if(!s)return null;const d=t!=null&&i===!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())},v=x=>{if(x.target.value.length===0){c(""),l(e,"");return}h.test(x.target.value)&&(c(x.target.value),l(e,x.target.value))},b=x=>{x(!1);const _=m(String(a));_!==String(a)&&(c(_),l(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:v,onFocus:()=>x(!0),onBlur:()=>b(x)})]})})}const f=(h,g)=>{g(!1);const v=m(h.target.value);v!==h.target.value&&(h.target.value=v,l(e,v))};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=>l(e,g.target.value),onFocus:()=>h(!0),onBlur:g=>f(g,h)})]})})};$("inputNumber",Qn);function Me(e,t,o){j.useEffect(()=>{if(!t)return;const i=r=>{e.current&&!e.current.contains(r.target)&&o()};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[t,e,o])}function Ot(e){let t=e.parentElement;for(;t;){const{overflow:o,overflowY:i}=getComputedStyle(t);if(/(auto|scroll)/.test(o+i))return t;t=t.parentElement}return document.documentElement}function ht(e,t){const o=Ot(e),i=o===document.documentElement?{top:0,bottom:window.innerHeight}:o.getBoundingClientRect(),r=e.getBoundingClientRect(),l=i.bottom-r.bottom,s=r.top-i.top;return l<t&&s>l}function Ie(e,t,o=300){const[i,r]=j.useState(!1);return j.useLayoutEffect(()=>{if(!t||!e.current){r(!1);return}const l=e.current.offsetParent;l&&r(ht(l,o))},[t,o]),j.useEffect(()=>{if(!t||!e.current)return;const l=()=>{var a;const s=(a=e.current)==null?void 0:a.offsetParent;s&&r(ht(s,o))};return window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[t,o]),i}const es=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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&&i===!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,v)=>{const b=g.value.toString()===(t==null?void 0:t.toString());return n.jsxs("div",{className:`fbre-dropdown__option${b?" fbre-dropdown__option--selected":""}`,onClick:()=>{l(e,g.value),c(!1)},children:[n.jsx("span",{children:g.label}),b&&n.jsx("span",{className:"fbre-dropdown__option-check",children:n.jsx(Z,{})})]},`${e}-${v}`)})})]})})};$("dropDown",es);const ts=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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&&i===!1,g=b=>{const x=b.toString(),_=f.includes(x)?f.filter(N=>N!==x):[...f,x];l(e,_)},v=(b,x)=>{x.stopPropagation(),l(e,f.filter(_=>_!==b))};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(b=>{const x=s.options.find(_=>_.value.toString()===b);return n.jsxs("span",{className:"fbre-dropdown__tag",children:[(x==null?void 0:x.label)??b,!m&&n.jsx("button",{type:"button",className:"fbre-dropdown__tag-remove",onClick:_=>v(b,_),children:"×"})]},b)})}):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((b,x)=>{const _=f.includes(b.value.toString());return n.jsxs("div",{className:"fbre-dropdown__option",onClick:()=>g(b.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:b.label})]},`${e}-${x}`)})})]})})};$("dropDownMulti",ts);const $t=({label:e,detail:t,showLabel:o,required:i,helperText:r,tooltip:l,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:[ie(e,d),i&&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:ie(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)"]})]})})()]}),l&&n.jsx(Bt,{text:l})]})]})},ns=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o;if(!s)return null;const a=s.readOnly===!0,c=t??[],d=t!=null&&i===!1,u=p=>{const m=p.toString(),f=c.includes(m)?c.filter(h=>h!==m):[...c,m];l(e,f)};return n.jsx($t,{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",ns);const ss=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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&&i===!1;return n.jsx($t,{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&&l(e,p.value.toString())},children:[n.jsx("input",{type:"radio",name:e,checked:f,disabled:c,value:p.value.toString(),onChange:h=>l(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",ss);const rs=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o;if(!s)return null;const a=s.columns??2,c=t!=null&&i===!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:()=>l(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",rs);const os=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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&&i===!1,h=a.icon&&In[a.icon]||Je,g=(x,_)=>{const N=_&&p<=.5?x+.5:x+1;l(e,N)},v=(x,_)=>{const N=_.currentTarget.getBoundingClientRect(),R=_.clientX-N.left<N.width/2&&p<=.5?x+.5:x+1;d(R)},b=[];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":""}`;b.push(n.jsx("div",{className:S,onMouseMove:R=>v(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:b}),s!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[s," / ",u]})]})})};$("rating",os);const is=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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=i===!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=>l(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",is);const ls=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o;if(!s)return null;const a=i===!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=>l(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",ls);const he=new Map,as=(e,t)=>{he.has(e)||he.set(e,new Set),he.get(e).add(t)},cs=(e,t)=>{var o;(o=he.get(e))==null||o.delete(t)},vt=(e,t,o)=>{var i;(i=he.get(e))==null||i.forEach(r=>{r(t,o)})},Vt=j.createContext(null);function At(){return j.useContext(Vt)}class ve extends Error{constructor(t,o,i,r){super(t),this.name="ApiError",this.status=o,this.code=i,this.validationErrors=r}}class Ft extends ve{constructor(t,o){super(`Request timed out after ${o}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const ds=new Set([502,503,504]),je=2,us=[500,1500];function ps(e){return new Promise(t=>setTimeout(t,e))}async function se(e,t,o={}){const r=`${e.apiEndpoint||""}${t}`,l=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 ps(us[c-1]);try{const d=new AbortController,u=setTimeout(()=>d.abort(),l);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 ve(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(c<je&&ds.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 ve)throw d;if(d instanceof DOMException&&d.name==="AbortError"){const u=new Ft(r,l);if(c<je){a=u;continue}throw u}if(d instanceof TypeError&&c<je){a=d;continue}throw d}}throw a}async function fs(e,t){return se(e,`/api/v1/public/flows/${t}`)}async function ms(e,t,o,i,r,l){return se(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:o,contentType:i,size:r,componentUuid:l})})}async function hs(e,t,o){return se(e,`/api/v1/public/flows/${t}/files/${o}/confirm`,{method:"POST"})}async function vs(e,t,o){const i={flowId:t};return o&&Object.keys(o).length>0&&(i.context=o),se(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(i)})}async function bs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:o})})}async function xs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:o})})}async function gs(e,t,o){return se(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:o})})}async function ys(e,t){return se(e,`/api/v1/public/sessions/${t}`)}const js=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(!1),[d,u]=j.useState(!1),p=j.useRef(null),m=At();if(!s)return null;const f=t!=null&&i===!1,h=async g=>{if(g.preventDefault(),!g.target.files)return;const v=g.target.files[0];if(!v)return;if(s.maxSize&&v.size>s.maxSize){c(!0),setTimeout(()=>c(!1),5e3);return}if(c(!1),m){u(!0);try{const{fileId:x,uploadUrl:_}=await ms(m.config,m.flowId,v.name,v.type,v.size,e);await fetch(_,{method:"PUT",headers:{"Content-Type":v.type},body:v}),await hs(m.config,m.flowId,x);const N={mode:"s3",fileId:x,name:v.name,type:v.type,size:v.size};l(e,N),vt("file-upload",e,N)}catch(x){console.error("File upload failed:",x),c(!0),setTimeout(()=>c(!1),5e3)}finally{u(!1)}return}const b=new FileReader;b.addEventListener("load",()=>{const x={name:v.name,type:v.type,size:v.size,lastModified:v.lastModified,data:b.result};"lastModifiedDate"in v&&(x.lastModifiedDate=v.lastModifiedDate),l(e,x),vt("file-upload",e,x)}),b.readAsDataURL(v)};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(hn,{}),"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",js);const _s=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o;if(!s)return null;const a=t!=null&&i===!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:()=>l(e,"yes"),children:c}),n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="no"?" fbre-yesno__btn--active":""}`,onClick:()=>l(e,"no"),children:d})]})})};$("yesNo",_s);const ws=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o;if(!s)return null;const a=i===!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=>l(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",ws);const bt=e=>{const{h:t,s:o,b:i}=e,r=o/100,l=i/100,s=l*r,a=s*(1-Math.abs(t/60%2-1)),c=l-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,i=parseInt(t.substring(2,4),16)/255,r=parseInt(t.substring(4,6),16)/255,l=Math.max(o,i,r),s=Math.min(o,i,r),a=l-s;let c=0;a!==0&&(l===o?c=60*((i-r)/a%6):l===i?c=60*((r-o)/a+2):c=60*((o-i)/a+4)),c<0&&(c+=360);const d=l===0?0:a/l*100,u=l*100;return{h:c,s:d,b:u}},Fe=e=>/^#[0-9a-fA-F]{6}$/.test(e),Cs=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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",[v,b]=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),b(_e(t)))},[t]),!s)return null;const _=t!=null&&i===!1,N=y=>{b(y);const w=bt(y);h(w),l(e,w)},S=y=>{y.preventDefault();const w=(D,I)=>{const L=p.current.getBoundingClientRect(),P=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({...v,s:P,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({...v,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);b(w),l(e,y.toLowerCase())}},k=bt({h:v.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:`${v.s}%`,top:`${100-v.b}%`}})]}),n.jsx("div",{className:"fbre-colorpicker__hue",ref:m,onMouseDown:R,children:n.jsx("div",{className:"fbre-colorpicker__hue-cursor",style:{left:`${v.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),b(_e(E)),l(e,E)}},w))})]})]})})};$("colorPicker",Cs);const Ns=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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&&i===!1,v=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 v(),window.addEventListener("resize",v),()=>window.removeEventListener("resize",v)},[c,v]);const b=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=b(y.nativeEvent),h.current=!0)},[]),N=j.useCallback(y=>{if(!m.current||!f.current)return;const w=b(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");l(e,w)}},[e,l]),R=()=>{const y=u.current;if(y){const w=y.getContext("2d");w&&w.clearRect(0,0,y.width,y.height)}h.current=!1,l(e,null)},C=y=>{const w=y.target.value;l(e,w||null)},k=y=>{d(y),l(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",Ns);function xt(e){const t=e.offsetParent;if(!t)return 0;const o=Ot(t),i=o===document.documentElement?{left:0,right:window.innerWidth}:o.getBoundingClientRect(),r=t.getBoundingClientRect(),l=e.offsetWidth,s=r.left+l;if(s<=i.right-8)return 0;let a=-(s-i.right+8);return r.left+a<i.left+8&&(a=i.left+8-r.left),a}const pe=({open:e,onClose:t,children:o,estimatedHeight:i=300})=>{const r=j.useRef(null);Me(r,e,j.useCallback(()=>t(),[t]));const l=Ie(r,e,i),[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"+(l?" 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(),Ss=(e,t)=>new Date(e,t,1).getDay(),fe=(e,t,o)=>`${e}-${String(t+1).padStart(2,"0")}-${String(o).padStart(2,"0")}`,ks=e=>{const t=e.split("-");if(t.length!==3)return null;const o=parseInt(t[0],10),i=parseInt(t[1],10)-1,r=parseInt(t[2],10);return isNaN(o)||isNaN(i)||isNaN(r)?null:{year:o,month:i,day:r}},Ee=(e,t)=>{const o=ks(e);if(!o)return e;const i=String(o.month+1).padStart(2,"0"),r=String(o.day).padStart(2,"0"),l=String(o.year);return t==="DD/MM/YYYY"?`${r}/${i}/${l}`:t==="YYYY-MM-DD"?`${l}-${i}-${r}`:`${i}/${r}/${l}`},Re=e=>{const t=e.split(":");if(t.length!==2)return e;let o=parseInt(t[0],10);const i=t[1],r=o>=12?"PM":"AM";return o===0?o=12:o>12&&(o-=12),`${o}:${i} ${r}`},Ge=(e,t)=>{const o=e.indexOf("T");if(o===-1)return e;const i=e.substring(0,o),r=e.substring(o+1);return`${Ee(i,t)} ${Re(r)}`},Es=(e,t,o)=>{let i=e;return o==="AM"&&i===12?i=0:o==="PM"&&i!==12&&(i+=12),`${String(i).padStart(2,"0")}:${String(t).padStart(2,"0")}`},Rs=e=>{const t=e.split(":");let o=parseInt(t[0],10);const i=parseInt(t[1],10),r=o>=12?"PM":"AM";return o===0?o=12:o>12&&(o-=12),{hour:o,minute:i,ampm:r}},Ts=(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())},Ls=["January","February","March","April","May","June","July","August","September","October","November","December"],Ms=e=>Ls[e],Is=["Su","Mo","Tu","We","Th","Fr","Sa"],De=({selectedDate:e,min:t,max:o,onSelect:i,rangeStart:r,rangeEnd:l,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),v=Ss(p,f),b=()=>{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=v-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??l,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:b,children:"‹"}),n.jsxs("span",{className:"fbre-calendar__nav-title",children:[Ms(f)," ",p]}),n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:x,children:"›"})]}),n.jsx("div",{className:"fbre-calendar__weekdays",children:Is.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&&Ts(y.iso,C,k),L=y.iso===C,P=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",P&&"fbre-calendar__day--range-end"].filter(Boolean).join(" ");return n.jsx("div",{className:H,onClick:()=>!D&&!y.outside&&i(y.iso),children:y.day},w)})})]})},Ds=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&i===!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=>{l(e,m),c(!1)}})})]})})};$("date",Ds);const gt=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const o=parseInt(t[0],10),i=parseInt(t[1],10);return isNaN(o)||isNaN(i)?null:o*60+i},Ue=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,Be=({value:e,min:t,max:o,step:i=15,onChange:r})=>{const l=j.useRef(null),s=j.useRef(null),a=e?Rs(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+=i)m.push(C);const f=["AM","PM"],h=j.useMemo(()=>gt(t),[t]),g=j.useMemo(()=>gt(o),[o]),v=h!==null||g!==null,b=(C,k)=>{const y=C*60+k;return!(h!==null&&y<h||g!==null&&y>g)},x=(C,k)=>{if(!v)return!1;const y=Ue(C,k);for(let w=0;w<60;w+=i)if(b(y,w))return!1;return!0},_=C=>{if(!v)return!1;const k=Ue(c,u);return!b(k,C)},N=C=>{if(!v)return!1;for(const k of p){const y=Ue(k,C);for(let w=0;w<60;w+=i)if(b(y,w))return!1}return!0},S=(C,k,y)=>{r(Es(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(l.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:l,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)})})]})},Bs=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&i===!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=>{l(e,m)}})]})]})})};$("time",Bs);const Os=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=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&&i===!1,f=typeof t=="string"?t:"",h=f.indexOf("T"),g=h!==-1?f.substring(0,h):"",v=h!==-1?f.substring(h+1):"",b=()=>{u(g?"time":"date"),c(!0)},x=()=>{c(!1),u("date")},_=k=>{l(e,`${k}T${v||"12:00"}`),u("time")},N=k=>{const y=g||new Date().toISOString().substring(0,10);l(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:b,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:v||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:N})]})})]})})};$("dateTime",Os);const $s=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(null),[d,u]=j.useState();if(!s)return null;const p=t!=null&&i===!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=b=>{if(a==="start"){const x=h&&b>h?"":h;l(e,{start:b,end:x}),c(x?null:"end")}else if(a==="end"){const x=f&&b<f?b:f,_=b<x?x:b;l(e,{start:x||b,end:x?_:""}),x&&_&&c(null)}u(void 0)},v=a!==null;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:v,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:v,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",$s);const Vs=({uuid:e})=>{const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(null);if(!s)return null;const d=t!=null&&i===!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=v=>{if(a==="start"){const b=m&&v>m?"":m;l(e,{start:v,end:b})}else if(a==="end"){const b=p&&v<p?p:v;l(e,{start:p,end:b})}},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",Vs);const As=({uuid:e})=>{var T,D;const{value:t,properties:o,valid:i,validationErrors:r,updateValue:l}=A(e),s=o,[a,c]=j.useState(null),[d,u]=j.useState("date");if(!s)return null;const p=t!=null&&i===!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"}},v=f?g(f):{date:"",time:"12:00"},b=h?g(h):{date:"",time:"12:00"},x=a==="start"?v:b,_=(I,L)=>{const P=I&&L&&L<I?"":L;l(e,{start:I,end:P})},N=I=>{u((I==="start"?v:b).date?"time":"date"),c(I)},S=()=>{c(null),u("date")},R=I=>{const L=x.time||"12:00",P=`${I}T${L}`;a==="start"?_(P,h):_(f,P),u("time")},C=I=>{const L=x.date;if(!L)return;const P=`${L}T${I}`;a==="start"?_(P,h):_(f,P)},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",As);const Pt=({uuid:e})=>{var u;const t=e.split(":")[0],o=parseInt(e.split(":")[1]),i=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[i]}),l=B(p=>p.conditionResults[e]);if(!r)return null;const s=r.conditions&&"when"in r.conditions?r.conditions:void 0;if(F.isHiddenByCondition(s,l))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(Dt.Provider,{value:r,children:n.jsx(a,{uuid:e})})})},Fs=({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}),[i,r]=j.useState(!0);if(!t)return null;const l=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:l.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${i?"":" collapsed"}`,onClick:()=>r(!i),"aria-label":"Toggle group",children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${i?"":" collapsed"}`,children:n.jsx("div",{className:"fbre-group__content",children:a.map(d=>n.jsx(Pt,{uuid:d.uuid},d.uuid))})})]},`${e}-${c}`))})};$("group",Fs);const Ps=({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}),i=B(f=>f.addRepeaterIteration),r=B(f=>f.removeRepeaterIteration),[l,s]=j.useState(new Set([0]));if(!t)return null;const a=o??[],c=1,d=()=>{const f=a.length;i(e),s(new Set([f]))},u=f=>{a.length<=c||(r(e,f),s(h=>{const g=new Set;for(const v of h)v<f?g.add(v):v>f&&g.add(v-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=l.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(gn,{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(v=>n.jsx(Pt,{uuid:v.uuid},v.uuid))})})]},`${e}-${h}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:d,children:"Add another"})]})};$("repeater",Ps);const Us={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"},Hs=({screenIndex:e,onFlowComplete:t,onScreenChange:o})=>{var Ke,Ze,Qe,et,tt,nt,st,rt,ot,it,lt;const i=B(V=>V.config),r=B(V=>V.screenOrder.length),l=B(V=>Object.keys(V.components).length>0),s=be(),a=Math.max(0,Math.min(e,r-1)),[c,d]=j.useState(a),[u,p]=j.useState(!!(i!=null&&i.summary&&e>=r)),m=((Ke=i==null?void 0:i.navigation)==null?void 0:Ke.transition)??"none",f=m!=="none",[h,g]=j.useState(null),[v,b]=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),b(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=An(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)):i!=null&&i.summary&&(f&&T("forward"),p(!0),E(c+1))},[N,c,i,f,T,E,s]),[P,H]=j.useState(!1),[U,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=i==null?void 0:i.theme)==null?void 0:Ze.darkMode)??!1,O=((i==null?void 0:i.mode)??"standard")==="conversational";Mt(O&&!u,c,L),It(O&&!u,c,L);const Y=((Qe=i==null?void 0:i.theme)==null?void 0:Qe.style)??"clean",le=((et=i==null?void 0:i.controls)==null?void 0:et.stepperStyle)??"default",ae=le==="default"?Us[Y]??"dots":le,Ht=((tt=i==null?void 0:i.controls)==null?void 0:tt.showStepper)!==!1&&ae==="text",Oe={};(nt=i==null?void 0:i.theme)!=null&&nt.color&&(Oe["--fbre-theme-color"]=i.theme.color);const qt=()=>v?n.jsx(ut,{}):h!==null?n.jsx(We,{screenIndex:h}):null,zt=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:[Ht&&n.jsx(Bn,{current:c,total:r}),n.jsxs("div",{className:zt,ref:R,children:[N&&n.jsx("div",{className:"fbre-screen-slot fbre-screen--exiting","data-direction":x,onAnimationEnd:D,children:qt()}),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,{})]})]}),U&&n.jsx("div",{className:"fbre-completion-error",children:U}),((st=i==null?void 0:i.controls)==null?void 0:st.show)!==!1&&l&&n.jsx(On,{screenIndex:c,maxScreenIndex:r-1,allowInvalidTransition:(rt=i==null?void 0:i.navigation)==null?void 0:rt.allowInvalidTransition,screenValidity:k,summaryEnabled:(i==null?void 0:i.summary)??!1,summaryActive:u,atMaxScreen:ee,nextButtonLabel:y,backButtonLabel:w,completionLoading:P,showStepper:(ot=i==null?void 0:i.controls)==null?void 0:ot.showStepper,stepperStyle:(it=i==null?void 0:i.controls)==null?void 0:it.stepperStyle,controlsLayout:(lt=i==null?void 0:i.controls)==null?void 0:lt.layout,nextScreen:L,prevScreen:I,onFlowComplete:J})]})},qs=[],zs=()=>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,i)=>{var m,f;const r=t();if(o.includes(":")){const h=o.split(":"),g=h[0],v=parseInt(h[1]),b=parseInt(h[2]),x=r.components[g];if(!((f=(m=x==null?void 0:x.addedComponents)==null?void 0:m[v])!=null&&f[b]))return;x.addedComponents[v][b]={...x.addedComponents[v][b],value:i};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[v][b],R);x.addedComponents[v][b].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 l=r.components[o];if(!l)return;if(l.type==="group"||l.type==="repeater"){e({components:{...r.components}});return}if(i===l.value){e({selectionTick:(t().selectionTick??0)+1});return}l.value=i;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(l,c);l.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 v=z(g,c);g.valid=v.length===0,u[h.target]=v}}e({components:{...r.components},conditionResults:a,validationErrors:u})},addGroupIteration:o=>{const i=t(),r=i.components[o];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l=r.components.map((s,a)=>{const c=Q(s);c.uuid=[o,r.addedComponents.length,a].join(":"),i.groupComponentMap[c.uuid]=s.uuid;const d=z(c);return c.valid=d.length===0,c});return r.addedComponents.push(l),e({components:{...i.components},groupComponentMap:{...i.groupComponentMap}}),r.addedComponents},addRepeaterIteration:o=>{const i=t(),r=i.components[o];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l=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(l),e({components:{...i.components}}),r.addedComponents},removeRepeaterIteration:(o,i)=>{const r=t(),l=r.components[o];if(!(!l||l.type!=="repeater"||!l.addedComponents||l.addedComponents.length<=1)){l.addedComponents.splice(i,1);for(let s=i;s<l.addedComponents.length;s++)l.addedComponents[s].forEach((a,c)=>{a.uuid=[o,s,c].join(":")});e({components:{...r.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:o=>{const i=t();if(o!==0)return null;const r=i.screenOrder[0];return r?i.screens[r]:null},getScreenValidity:o=>{const i=t();if(o!==0)return!0;const r=i.screenOrder[0];return r?i.screenValidity[r]??!0:!0},getValidationErrors:o=>t().validationErrors[o]??qs,evaluateFlowValidation:()=>{const o=t(),i=o.screenOrder[0];if(!i)return!0;const r=o.screens[i];if(!r)return!0;let l=!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 b=o.conditionResults[h.uuid]??!1;if(g.action==="show"&&!b||g.action==="hide"&&b)continue}const v=z(h,s);h.valid=v.length===0,a[h.uuid]=v,v.length>0&&(l=!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&&(l=!1)}const c={...o.screenValidity,[i]:l};return e({components:{...o.components},validationErrors:a,screenValidity:c}),l},getMaxScreenCount:()=>0,getCalculationResult:o=>t().calculationResults[o]??null})),we=(e,t)=>{var h,g;const o={},i={},r={},l={},s={},a={},c=t.screen.uuid;for(const v of t.screen.components){const b=Q(v);if(o[b.uuid]=b,(b.type==="group"||b.type==="repeater")&&v.components){b.addedComponents||(b.addedComponents=[]);const x=v.components.map((_,N)=>{var R;const S=Q(_);if(S.uuid=[b.uuid,0,N].join(":"),b.type==="group"&&(i[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});b.addedComponents.push(x)}if((h=b.properties)!=null&&h.validation){const x=b.properties.validation;x.rules&&x.rules.length>0&&me(s,b.uuid,x)}}for(const{targetUUID:v,config:b}of t.conditions)re(l,v,b,v===c?"screen":"component");if(t.previousData)for(const v of t.previousData){const b=o[v.uuid];b&&(b.value=v.value)}const d={components:o};for(const v of Object.keys(o)){const b=o[v];if(b.type==="group"||b.type==="repeater"){if(b.addedComponents)for(const _ of b.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=b.properties)!=null&&g.validation))continue;const x=z(b,d);b.valid=x.length===0,x.length>0&&(a[v]=x)}const u={},p={components:o},m=new Set;for(const v of Object.values(l))for(const b of v)m.has(b.target)||(m.add(b.target),u[b.target]=ce(p,b.config));let f=!0;for(const v of t.screen.components){const b=o[v.uuid];if(b)if((b.type==="group"||b.type==="repeater")&&b.addedComponents)for(const x of b.addedComponents){for(const _ of x)if(!_.valid){f=!1;break}if(!f)break}else b.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:i,templateComponentMap:r,conditionsByDependency:l,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 l;const t=e.getState(),o=t.screenOrder[0];if(!o)return[];const i=t.screens[o];if(!i)return[];const r=[];for(const s of i.components){const a=t.components[s.uuid];if(!a||Ne(a.type))continue;const c={uuid:a.uuid,type:a.type,value:a.value};(l=a.properties)!=null&&l.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),Ws=6e4,Ys=({sessionEndpoint:e,flowId:t,apiKey:o,mode:i,theme:r,context:l,onFlowComplete:s,onScreenChange:a})=>{const c=j.useRef(null);c.current||(c.current=zs());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),v=K.useStore(d,M=>M.screens),[b,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 vs(S,t,l);we(d,M)}catch(M){d.setState({loading:!1,error:M.message})}},[t,e,o,l]);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<Ws))try{const Y=await ys(S,X.sessionId);we(d,Y)}catch(Y){Y instanceof ve&&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 bs(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 xs(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 gs(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=(i??h??"standard")==="conversational",L=I&&!m.isLastScreen;Mt(L,0,y),It(L,0,y);const P=T.darkMode??!1,H={};T.color&&(H["--fbre-theme-color"]=T.color);const U=g[0],G=U?v[U]: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":P?"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(Gs,{navigation:m,loading:u,onPrev:w,onNext:y,onComplete:E,nextButtonLabel:J,backButtonLabel:ee}),n.jsxs("div",{className:`fbre-toast${b?" visible":""}`,children:[n.jsx("span",{children:b}),n.jsx("button",{type:"button",className:"fbre-toast__close",onClick:C,"aria-label":"Dismiss",children:"×"})]})]})})},Gs=({navigation:e,loading:t,onPrev:o,onNext:i,onComplete:r,nextButtonLabel:l,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...":l||"Complete"}):n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:i,disabled:t,children:t?"Loading...":l||"Next"})})]});function Js(e,t,o,i,r){return!t&&!o&&!i&&!r?e:{...e,...r&&{mode:r},...t&&{theme:{...e.theme,...t}},...o&&{navigation:{...e.navigation,...o}},...i&&{controls:{...e.controls,...i}}}}const Ut=({flow:e,data:t,mode:o,theme:i,navigation:r,controls:l,screenIndex:s,context:a,storeRef:c,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p,apiCtx:m})=>{const f=j.useRef(null);f.current||(f.current=an(),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 v=f.current.getState(),b=Js(v.config,i,r,l,o);b!==v.config&&f.current.setState({config:b})}},[o,i,r,l]);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(Hs,{screenIndex:s??0,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p})});return m?n.jsx(Vt.Provider,{value:m,children:g}):g},Xs=({flowId:e,apiEndpoint:t,apiKey:o,data:i,mode:r,theme:l,navigation:s,controls:a,screenIndex:c,context:d,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f})=>{const[h,g]=j.useState(null),[v,b]=j.useState(""),[x,_]=j.useState(null);return j.useEffect(()=>{g(null),b("");const N={apiEndpoint:t,apiKey:o};fs(N,e).then(S=>{g(S.data),_({config:N,flowId:S.id,flowVersionId:S.versionId,tenantId:S.tenantId})}).catch(S=>b(S.message))},[e,t,o]),v?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:v})]})}):!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(Ut,{flow:h,data:i,mode:r,theme:l,navigation:s,controls:a,screenIndex:c,context:d,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f,apiCtx:x})},Ks=e=>"sessionEndpoint"in e?n.jsx(Ys,{...e}):"flowId"in e&&e.flowId?n.jsx(Xs,{...e}):n.jsx(Ut,{...e});exports.ApiError=ve;exports.FBRE=Ks;exports.TimeoutError=Ft;exports.addFBREEventListener=as;exports.removeFBREEventListener=cs;exports.useFBREApi=At;exports.useFBREStore=B;exports.useFBREStoreApi=be;
|