@sonata-innovations/fiber-fbre 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fiber-fbre.cjs +1 -1
- package/dist/fiber-fbre.js +1376 -1441
- package/dist/index.d.ts +69 -0
- package/package.json +5 -3
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"),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 l,o,r,i;if(t.includes(":")){const s=t.split(":"),a=e.components[s[0]];return(r=(o=(l=a==null?void 0:a.addedComponents)==null?void 0:l[parseInt(s[1])])==null?void 0:o[parseInt(s[2])])==null?void 0:r.value}return(i=e.components[t])==null?void 0:i.value},z=(e,t)=>{var o;const l=(o=e.properties)==null?void 0:o.validation;return!l||!l.rules||l.rules.length===0?[]:F.validateValue(e.value,l,t?r=>Jt(t,r):void 0)},Xt=e=>{var l;const t=(l=e.properties)==null?void 0:l.validation;return!t||!t.rules?!1:t.rules.some(o=>o.type==="required")},Q=e=>{var o,r;const t={...e};if(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=[]),["yesNo","radio","cardSelect","dropDown"].includes(e.type)){const i=e.properties??{},s=i.defaultValue;if(e.type==="yesNo")(s==="yes"||s==="no")&&(t.value=s,t.valid=!0);else{const c=(Array.isArray(i.options)?i.options:[]).find(d=>d&&d.value===s);c&&(t.value=c.value,t.valid=!0)}}return e.type==="toggleSwitch"&&(t.value=!1),e.type==="colorPicker"&&((r=e.properties)!=null&&r.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,l)=>{var o;for(const r of l.rules)if(r.type==="matchesField"&&((o=r.params)!=null&&o.field)){const i=r.params.field;e[i]||(e[i]=[]),e[i].push({target:t,config:l})}},oe=(e,t)=>{const l=e.screens[t];return l?!l.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&&F.isHiddenByCondition(u,e.conditionResults[d.uuid])?!1:!d.valid}));const s=i.conditions&&"when"in i.conditions?i.conditions:void 0;return F.isHiddenByCondition(s,e.conditionResults[i.uuid])?!1:i&&"valid"in i&&!i.valid}):!0};function Kt(e){const t={};for(const l of e){const o=F.extractFormulaReferences(l.formula);for(const r of o)t[r]||(t[r]=[]),t[r].includes(l.uuid)||t[r].push(l.uuid)}return t}function wt(e,t){return{resolveValue:l=>{if(l in t)return t[l];const o=te(e,l);if(!o)return null;const r=o.value;if(r==null||r==="")return null;const i=Number(r);return isNaN(i)?null:i},resolveOptionMetadata:(l,o)=>{var u;const r=te(e,l);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[o];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:l=>{for(const o of Object.keys(e.components)){const r=e.components[o];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const i=r.components.findIndex(a=>a.uuid===l);if(i===-1)continue;const s=[];for(const a of r.addedComponents){const c=a[i];if(!c)continue;const d=c.value;if(d==null||d==="")continue;const u=Number(d);isNaN(u)||s.push(u)}return s.length>0?s:null}return null}}}function qe(e){const t=e.calculations??[];if(t.length===0)return{};const l=F.topologicalSortCalculations(t),o={},r=wt(e,o);for(const i of l)o[i.uuid]=F.evaluateFormula(i.formula,r);return o}function $e(e,t){const l=e.calculationsByDependency,o=e.calculations??[];if(o.length===0||!l)return null;const r=new Set,i=[t];for(;i.length>0;){const u=i.shift(),p=l[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=F.topologicalSortCalculations(o),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={},l=o=>{var i;if(o.type!=="computed"||!((i=o.properties)!=null&&i.formula))return;const r=F.extractFormulaReferences(o.properties.formula);for(const s of r)t[s]||(t[s]=[]),t[s].includes(o.uuid)||t[s].push(o.uuid)};for(const o of Object.values(e))if(l(o),(o.type==="repeater"||o.type==="group")&&o.components)for(const r of o.components)l(r);return t}function Ct(e,t,l,o){var c,d;const r=e.components[l],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[o],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 Se(e,t){return{resolveValue:l=>{if(l in t)return t[l];const o=te(e,l);if(!o)return null;const r=o.value;if(r==null||r==="")return null;const i=Number(r);return isNaN(i)?null:i},resolveOptionMetadata:(l,o)=>{var u;const r=te(e,l);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[o];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:l=>{for(const o of Object.keys(e.components)){const r=e.components[o];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const i=r.components.findIndex(a=>a.uuid===l);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 l,o;const t=e.calculationResults??{};for(const r of Object.values(e.components))if(r.type==="computed"&&((l=r.properties)!=null&&l.formula)){const i=Se(e,t),s=F.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"&&((o=d.properties)!=null&&o.formula)){const u=r.type==="repeater"?Ct(e,t,r.uuid,i):Se(e,t),p=F.evaluateFormula(d.properties.formula,u);c.value=p}}}}function Qt(e,t){var s,a;const l=e.computedByDependency;if(!l)return!1;const o=l[t];if(!o||o.length===0)return!1;const r=e.calculationResults??{};let i=!1;for(const c of o){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},i=!0);continue}for(const u of Object.values(e.components))if((u.type==="repeater"||u.type==="group")&&u.components&&u.addedComponents){const p=u.components.findIndex(f=>f.uuid===c);if(p===-1)continue;const m=u.components[p];if((m==null?void 0:m.type)!=="computed"||!((a=m.properties)!=null&&a.formula))continue;for(let f=0;f<u.addedComponents.length;f++){const h=u.addedComponents[f][p];if(!h)continue;const g=u.type==="repeater"?Ct(e,r,u.uuid,f):Se(e,r),v=F.evaluateFormula(m.properties.formula,g);h.value!==v&&(u.addedComponents[f][p]={...h,value:v},i=!0)}}}return i}const Nt=(e,t)=>{var l,o;if(t.includes(":")){const r=t.split(":"),i=e[r[0]];return(o=(l=i==null?void 0:i.addedComponents)==null?void 0:l[parseInt(r[1])])==null?void 0:o[parseInt(r[2])]}return e[t]},Ce=(e,t)=>{for(const l of e.screenOrder)if(e.screens[l].components.some(r=>r.uuid===t))return l;return null},en=(e,t)=>{if(!t.includes(":"))return null;const l=t.split(":");if(l.length!==3)return null;const o=l[0],r=parseInt(l[2]),i=e.components[o];if(!i||i.type!=="repeater"||!i.components)return null;const s=i.components[r];return(s==null?void 0:s.uuid)??null},at=(e,t,l,o,r)=>{const i=t(),s=i.groupComponentMap[l]??l,a=sn(e,t,s),c={components:i.components,groupComponentMap:i.groupComponentMap},d=z(o,c);o.valid=d.length===0;const u={...i.validationErrors,[l]:d},p=i.validationsByDependency[l];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=l.includes(":")?en(h,l):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:(l,o)=>{var s,a;const r=t();if(l.includes(":")){const c=l.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!==o;if(m.addedComponents[u][p]={...m.addedComponents[u][p],value:o},f){at(e,t,l,m.addedComponents[u][p],d);return}e({components:{...r.components}});return}const i=r.components[l];if(i){if(i.type==="group"||i.type==="repeater"){e({components:{...r.components}});return}if(o===i.value){e({selectionTick:t().selectionTick+1});return}i.value=o,at(e,t,l,i,l)}},addGroupIteration:l=>{const o=t(),r=o.components[l];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const i={...o.conditionsByDependency},s=r.components.map((d,u)=>{const p=Q(d);if(p.uuid=[l,r.addedComponents.length,u].join(":"),o.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(o,l),c={...o.screenValidity};return a&&(c[a]=oe({...o},a)),e({components:{...o.components},groupComponentMap:{...o.groupComponentMap},conditionsByDependency:i,screenValidity:c}),r.addedComponents},addRepeaterIteration:l=>{const o=t(),r=o.components[l];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const i={...o.conditionsByDependency},s=r.components.map((p,m)=>{const f=Q(p);if(f.uuid=[l,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(o,l),c={...o.screenValidity};a&&(c[a]=oe({...o},a));const d={...o,components:{...o.components}};ze(d);const u=qe(d);return e({components:{...o.components},conditionsByDependency:i,screenValidity:c,calculationResults:u}),r.addedComponents},removeRepeaterIteration:(l,o)=>{var g;const r=t(),i=r.components[l];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[o],c=new Set(a.map(v=>v.uuid));i.addedComponents.splice(o,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=o;v<i.addedComponents.length;v++)i.addedComponents[v].forEach((b,x)=>{const _=b.uuid,N=[l,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,l),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,l,o)=>{const r=new Set;for(const s of l.when.rules)r.add(s.source);const i={target:t,type:o,config:l};for(const s of r)e[s]||(e[s]=[]),e[s].push(i)},nn=(e,t)=>{var l,o;return t.includes(":")?(l=te(e,t))==null?void 0:l.value:(o=e.components[t])==null?void 0:o.value},ce=(e,t)=>F.evaluateConditionConfig(t,(l,o)=>(o==null?void 0:o.sourceType)==="context"?e.externalContext[o.source]:nn(e,l)),sn=(e,t,l)=>{const o=t(),r=o.conditionsByDependency[l];if(!r||r.length===0)return null;let i=!1;const s={...o.conditionResults};for(const a of r){const c=ce(o,a.config);s[a.target]!==c&&(s[a.target]=c,i=!0)}return i?s:null},rn=e=>{const t={},l=new Set;for(const o of Object.values(e.conditionsByDependency))for(const r of o)l.has(r.target)||(l.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:"",l={uuid:e.uuid,type:e.type,value:e.value};return t&&(l.label=t),l},ct=e=>{if(e.conditions&&"when"in e.conditions)return e.conditions},on=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},l=r=>{const i=e.screens[r];if(!i)return!1;const s=i.conditions&&"when"in i.conditions?i.conditions:void 0;return F.isHiddenByCondition(s,e.conditionResults[r])};t.screens=e.screenOrder.filter(r=>!l(r)).map(r=>{const i=e.screens[r],s={uuid:r,components:i.components.map(a=>{const c=e.components[a.uuid];if(!c)return null;const d=ct(c);if(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 i.label&&(s.label=i.label),s});const o=e.calculations??[];if(o.length>0){const r=e.calculationResults??{};t.calculations=o.map(i=>{const s=r[i.uuid]??null,a={uuid:i.uuid,label:i.label,value:s};return s!==null&&(a.formattedValue=F.formatCalculationResult(s,i.format,i.decimalPlaces,i.currencySymbol)),a})}return t},Te=j.createContext(null);function B(e){const t=j.useContext(Te);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return K.useStore(t,e)}const 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:(l,o,r)=>{var R;const i={},s=[],a={},c={},d={},u={},p={},m={},f={};l.screens.forEach(C=>{const k=ge(C.conditions),y=k?{...C,conditions:k}:{...C};i[C.uuid]=y,s.push(C.uuid),k&&re(u,C.uuid,k,"screen"),C.components.forEach(w=>{var M;const E=ge(w.conditions),T=Q(w);if(E&&(T.conditions=E),a[w.uuid]=T,E&&re(u,w.uuid,E,"component"),(M=T.properties)!=null&&M.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((I,X)=>{var ae;const O=Q(I);O.uuid=[w.uuid,L.addedComponents.length,X].join(":"),H&&H[J]&&I.uuid in H[J]&&(O.value=H[J][I.uuid]),w.type==="group"&&(c[O.uuid]=I.uuid),J===0&&(d[I.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)}}})}),o&&o.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=l.screens[k].components.find(M=>M.uuid===w.uuid);for(let M=0;M<T;M++)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 M=D.find(L=>L.uuid===T.uuid);if(M){M.value=T.value;const L=z(M);M.valid=L.length===0,m[M.uuid]=L;break}}})})}else{w.value=y.value;const E=z(w);w.valid=E.length===0,m[w.uuid]=E}})});for(const C of Object.keys(a)){const k=a[C];if(!(k.type==="group"||k.type==="repeater"||!((R=k.properties)!=null&&R.validation))&&!(C in m)){const y=z(k);k.valid=y.length===0,y.length>0&&(m[C]=y)}}const h={...t(),externalContext:r??{},screens:i,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},g=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=l.calculations??[],_=Kt(x),N={...b,calculations:x},S=qe(N);e({flowUUID:l.uuid,metadata:l.metadata,config:l.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:l=>{const o=t(),r=o.externalContext,i=[];for(const d of Object.keys(l))r[d]!==l[d]&&i.push(d);for(const d of Object.keys(r))!(d in l)&&!i.includes(d)&&i.push(d);if(i.length===0)return;const s={...o.conditionResults};let a=!1;const c=new Set;for(const d of i){const u=o.conditionsByDependency[d];if(!(!u||u.length===0))for(const p of u){if(c.has(p.target))continue;c.add(p.target);const m={...o,externalContext:l},f=ce(m,p.config);s[p.target]!==f&&(s[p.target]=f,a=!0)}}if(a){const d={...o,conditionResults:s},u={};for(const p of o.screenOrder)u[p]=oe(d,p);e({externalContext:l,conditionResults:s,screenValidity:u})}else e({externalContext:l})},...tn(e,t),getFlowData:()=>on(t()),getScreenByIndex:l=>{const o=t();return l<0||l>=o.screenOrder.length?null:o.screens[o.screenOrder[l]]},getScreenValidity:l=>{const o=t();return l<0||l>=o.screenOrder.length?!0:o.screenValidity[o.screenOrder[l]]??!0},getValidationErrors:l=>t().validationErrors[l]??ln,evaluateFlowValidation:()=>{const l=t(),o={};let r=!0;return l.screenOrder.forEach(i=>{const s=oe(l,i);o[i]=s,s||(r=!1)}),e({screenValidity:o}),r},getMaxScreenCount:()=>t().screenOrder.length-1,getCalculationResult:l=>t().calculationResults[l]??null})),cn=({uuid:e})=>{var a;const t=B(c=>c.components[e]),l=B(c=>c.conditionResults[e]);if(!t)return null;const o=t.conditions&&"when"in t.conditions?t.conditions:void 0;if(F.isHiddenByCondition(o,l))return null;const r=_t(t.type);if(!r)return console.warn(`FBRE: No renderer for component type "${t.type}"`),null;const i=(a=t.properties)==null?void 0:a.width,s=i&&i!=="full"?`fbre-component fbre-width-${i}`:"fbre-component";return n.jsx("div",{className:s,"data-uuid":e,children:n.jsx(r,{uuid:e})})},We=({screenIndex:e})=>{const t=B(l=>{const o=l.screenOrder[e];return o?l.screens[o]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(l=>n.jsx(cn,{uuid:l.uuid},l.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"})}),In=({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},Mn={star:Je,heart:St,thumbsUp:Tn,circle:Ln,diamond:In},ye=({position:e,screenIndex:t,maxScreenIndex:l,allowInvalidTransition:o,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(pn,{}),d||"Back"]})}const g=i?a&&s:a,v=i?a?s?"Done":"Review":"Next":a?"Done":"Next";if(l===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||!o&&!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:l})=>{if(t<=1)return null;const o=t>1?e/(t-1)*100:100,i=!!l&&l!=="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:`${o}%`}})}),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:`${o}%`}})})]})},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",o=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text"&&e.maxScreenIndex>0,r=e.screenIndex>0||e.summaryActive,i=r?2:1,s=o?n.jsx(Dn,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):null;if(t==="default"){const a=!r&&!o;return n.jsxs("div",{className:"fbre-controls fbre-controls--default","data-button-count":i,"data-solo":a?"true":void 0,children:[r?n.jsx(ye,{position:"back",...e}):n.jsx("div",{}),s??n.jsx("div",{}),n.jsx(ye,{position:"next",...e})]})}return n.jsxs("div",{className:`fbre-controls fbre-controls--${t}`,"data-button-count":i,children:[s&&n.jsx("div",{className:"fbre-controls__stepper",children:s}),n.jsxs("div",{className:"fbre-controls__row",children:[r&&n.jsx(ye,{position:"back",...e}),n.jsx(ye,{position:"next",...e})]})]})},kt=({component:e})=>{const{uuid:t,label:l,type:o,value:r,components:i}=e,s=()=>{if(r!=null)switch(o){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(o==="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:l}),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${o==="group"||o==="repeater"?" fbre-summary__item--group":""}`,children:[n.jsx("div",{className:"fbre-summary__item-label",children:l}),o!=="group"&&o!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${c?" fbre-summary__item-value--empty":""}`,children:s()}),(o==="group"||o==="repeater")&&a()]})},$n={sm:"12px",lg:"18px",xl:"24px"},Et=/\$\{([^}]+)\}/g,Le=(e,t)=>{const l=e.replace(Et,(o,r)=>{const i=t.resolveCalculation(r);if(i!==null)return dt(i);const s=t.resolveComponentValue(r);return s!==null?dt(s):""});return Rt(l)},le=(e,t)=>e.replace(Et,(l,o)=>{const r=t.resolveCalculation(o);if(r!==null)return r;const i=t.resolveComponentValue(o);return i!==null?i:""}),dt=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Rt=e=>{let t=e;const l=/\[b.*?\]([\s\S]*?)\[\/b\]/g,o=/\[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(l,"<strong>$1</strong>"),t=t.replace(o,"<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(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),l=B(r=>r.calculations),o=B(r=>r.calculationResults);return j.useMemo(()=>{const r=new Map(l.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=o[s]??null;return F.formatCalculationResult(c,a.format,a.decimalPlaces,a.currencySymbol)}}},[e,t,l,o])}const Vn=({screen:e,showToggle:t})=>{const l=ue(),[o,r]=j.useState(!0);return n.jsxs("div",{children:[n.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>t&&r(!o),children:[e.label&&n.jsx("span",{className:"fbre-summary__screen-label",children:le(e.label,l)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${o?"":" collapsed"}`,children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${o?"":" collapsed"}`,children:e.components.map(i=>n.jsx(kt,{component:i},i.uuid))})]})},ut=()=>{const e=be(),t=B(r=>r.components),l=j.useMemo(()=>e.getState().getFlowData(),[e,t]),o=l.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:l.screens.map(r=>n.jsx(Vn,{screen:r,showToggle:o>1},r.uuid))})]})},Tt=(e,t,l)=>t?!F.isHiddenByCondition(t,l[e]):!0,ke=(e,t)=>{const l=e.screenOrder.length-1;let o=t+1;for(;o<=l;){const r=e.screenOrder[o],i=e.screens[r],s=i!=null&&i.conditions&&"when"in i.conditions?i.conditions:void 0;if(Tt(r,s,e.conditionResults))return o;o++}return null},An=(e,t)=>{let l=t-1;for(;l>=0;){const o=e.screenOrder[l],r=e.screens[o],i=r!=null&&r.conditions&&"when"in r.conditions?r.conditions:void 0;if(Tt(o,i,e.conditionResults))return l;l--}return 0},Fn=new Set(["text","header","callout","divider","table","computed"]);function Lt(e,t){const l=e.screenOrder[t];if(!l)return 0;const o=e.screens[l];if(!o)return 0;let r=0;for(const i of o.components){const s=e.components[i.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[i.uuid])||(r+=1)}return r}const Xe=new Set(["radio","yesNo","cardSelect","dropDown"]),Pn=500;function It(e,t,l){const o=be(),r=j.useRef(null),i=j.useRef(""),s=j.useRef(0);j.useEffect(()=>{if(!e)return;const a=o.getState(),c=pt(a,t);c&&(i.current=ft(a.components,c)),s.current=a.selectionTick},[e,t,o]),j.useEffect(()=>{if(!e)return;const a=o.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?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,l()},Pn))});return()=>{a(),r.current&&(clearTimeout(r.current),r.current=null)}},[e,t,o,l]),j.useEffect(()=>()=>{r.current&&(clearTimeout(r.current),r.current=null)},[t])}function pt(e,t){const l=e.screenOrder[t];if(!l)return null;const o=e.screens[l];return o?o.components.map(r=>r.uuid):null}function ft(e,t){const l=[];for(const o of t){const r=e[o];!r||!Xe.has(r.type)||l.push(`${o}=${JSON.stringify(r.value??null)}`)}return l.join("|")}function Un(e,t,l){const o=new Map;for(const r of l.split("|")){const i=r.indexOf("=");i>0&&o.set(r.slice(0,i),r.slice(i+1))}for(const r of t){const i=e[r];if(!i||!Xe.has(i.type))continue;const s=JSON.stringify(i.value??null),a=o.get(r)??"null";if(s!==a&&s!=="null")return!0}return!1}function Hn(e,t){for(const l of t){const o=e[l];if(!(!o||!Xe.has(o.type))&&o.value!==null&&o.value!==void 0)return!0}return!1}function Mt(e,t,l){const o=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=o.getState();if(ke(a,t)===null)return;const d=a.screenOrder[t];d&&a.screenValidity[d]===!1||Lt(a,t)===1&&(i.preventDefault(),l())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,l,o])}const Dt=j.createContext(null),mt=[],A=e=>{const t=j.useContext(Dt),l=B(a=>{var c;return(c=a.components[e])==null?void 0:c.value}),o=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:l,properties:o,valid:r,validationErrors:i,updateValue:s}},qn=({uuid:e})=>{const{properties:t}=A(e),l=ue(),o=t==null?void 0:t.value;if(!o)return null;const r=le(o,l);return n.jsx("h2",{className:"fbre-header",children:r})};$("header",qn);const zn=({uuid:e})=>{const{properties:t}=A(e),l=ue(),o=t==null?void 0:t.value;return o==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:Le(o,l)}})};$("text",zn);const Wn=({uuid:e})=>{const{properties:t}=A(e),l=(t==null?void 0:t.textAlign)??"center",o=l==="left"?" fbre-divider--left":l==="right"?" fbre-divider--right":"";return n.jsx("div",{className:`fbre-divider${o}`,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),l=ue(),o=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(!o&&!r)return null;let a;if(s==="none")a=void 0;else if(s&&Ae[s])a=Ae[s];else{const d=Yn[i];a=d?Ae[d]:void 0}const c=`fbre-callout fbre-callout--${i}`;return n.jsxs("div",{className:c,children:[a&&n.jsx("span",{className:"fbre-callout__icon",children:n.jsx(a,{})}),n.jsxs("div",{className:"fbre-callout__content",children:[r&&n.jsx("div",{className:"fbre-callout__title",children:le(r,l)}),o&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:Le(o,l)}})]})]})};$("callout",Gn);const Jn=({uuid:e})=>{const{properties:t}=A(e),l=t==null?void 0:t.label,o=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!o||!r||o.length===0?null:n.jsxs("div",{className:"fbre-table",children:[l&&n.jsx("div",{className:"fbre-table__label",children:l}),n.jsxs("table",{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"fbre-table__row-label"}),o.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}),o.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:l}=A(e),o=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=F.formatCalculationResult(typeof l=="number"?l:null,s,a,c);return n.jsxs("div",{className:"fbre-computed",children:[r&&o&&n.jsx("div",{className:"fbre-computed__label",children:o}),n.jsx("div",{className:"fbre-computed__value",children:d||"—"}),i&&n.jsx("div",{className:"fbre-computed__detail",children:i})]})};$("computed",Xn);const Bt=({text:e})=>{var c;const[t,l]=j.useState(!1),o=j.useRef(null),r=j.useRef(null),[i,s]=j.useState(null),a=j.useCallback(()=>{if(!o.current)return;const d=o.current.getBoundingClientRect();s({top:d.bottom+4,left:d.right})},[]);return j.useEffect(()=>{if(!t)return;a();const d=p=>{const m=p.target;o.current&&!o.current.contains(m)&&r.current&&!r.current.contains(m)&&l(!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:o,type:"button",className:"fbre-tooltip-trigger",onClick:()=>l(!t),"aria-label":"Help",children:n.jsx(mn,{})}),t&&i&&Yt.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=o.current)==null?void 0:c.closest(".fbre-container"))??document.body)]})},q=({label:e,detail:t,showLabel:l,required:o,helperText:r,tooltip:i,inputId:s,externalFocused:a,error:c,errorMessages:d,children:u})=>{const p=ue(),[m,f]=j.useState(!1);j.useEffect(()=>{a!==void 0&&f(a)},[a]);const h=["fbre-field",m&&"fbre-field--focused",c&&"fbre-field--error"].filter(Boolean).join(" ");return n.jsxs("div",{className:h,children:[t&&n.jsx("div",{className:"fbre-field__prompt",dangerouslySetInnerHTML:{__html:Le(t,p)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[e&&(!t||t.length===0||l)&&n.jsxs("label",{className:"fbre-field__label",htmlFor:s,children:[le(e,p),o&&n.jsx("span",{className:"required",children:"*"})]}),u({focused:m,setFocused:f}),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(Bt,{text:i})]})]})},Kn=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,a=j.useRef(null),[c,d]=j.useState(!1);if(!s)return null;const u=t!=null&&o===!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(dn,{}):n.jsx(un,{})})]})})};$("inputText",Kn);const Zn=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l;if(!s)return null;const a=t!=null&&o===!1,c=`fbre-input-${e}`;return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:c,error:a,errorMessages:a?r:void 0,children:({setFocused:d})=>n.jsx("textarea",{id:c,className:`fbre-field__textarea${s.readOnly?" fbre-field__textarea--readonly":""}`,defaultValue:t??"",placeholder:s.placeholder,maxLength:s.maxlength,readOnly:s.readOnly,autoComplete:s.autocomplete,onChange:u=>i(e,u.target.value),onFocus:()=>d(!0),onBlur:()=>d(!1)})})};$("inputTextArea",Zn);const Qn=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(t??"");if(!s)return null;const d=t!=null&&o===!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)})]})})};$("inputNumber",Qn);function Ie(e,t,l){j.useEffect(()=>{if(!t)return;const o=r=>{e.current&&!e.current.contains(r.target)&&l()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[t,e,l])}function Ot(e){let t=e.parentElement;for(;t;){const{overflow:l,overflowY:o}=getComputedStyle(t);if(/(auto|scroll)/.test(l+o))return t;t=t.parentElement}return document.documentElement}function ht(e,t){const l=Ot(e),o=l===document.documentElement?{top:0,bottom:window.innerHeight}:l.getBoundingClientRect(),r=e.getBoundingClientRect(),i=o.bottom-r.bottom,s=r.top-o.top;return i<t&&s>i}function Me(e,t,l=300){const[o,r]=j.useState(!1);return j.useLayoutEffect(()=>{if(!t||!e.current){r(!1);return}const i=e.current.offsetParent;i&&r(ht(i,l))},[t,l]),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,l))};return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[t,l]),o}const es=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(!1),d=j.useRef(null),u=j.useRef(null);Ie(d,a,j.useCallback(()=>c(!1),[]));const p=Me(u,a,200);if(!s)return null;const m=s.readOnly===!0,f=t!=null&&o===!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}`)})})]})})};$("dropDown",es);const ts=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(!1),d=j.useRef(null),u=j.useRef(null);Ie(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&&o===!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}`)})})]})})};$("dropDownMulti",ts);const $t=({label:e,detail:t,showLabel:l,required:o,helperText:r,tooltip:i,error:s,errorMessages:a,children:c})=>{const d=ue(),u=["fbre-option-group",s&&"fbre-option-group--error"].filter(Boolean).join(" ");return n.jsxs("div",{className:u,children:[t&&n.jsx("div",{className:"fbre-field__prompt",dangerouslySetInnerHTML:{__html:Le(t,d)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[l!==!1&&(!t||t.length===0)&&n.jsxs("div",{className:"fbre-option-group__label",children:[le(e,d),o&&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(Bt,{text:i})]})]})},ns=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l;if(!s)return null;const a=s.readOnly===!0,c=t??[],d=t!=null&&o===!1,u=p=>{const m=p.toString(),f=c.includes(m)?c.filter(h=>h!==m):[...c,m];i(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:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,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,u=t!=null&&o===!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&&i(e,p.value.toString())},children:[n.jsx("input",{type:"radio",name:e,checked:f,disabled:c,value:p.value.toString(),onChange:h=>i(e,h.target.value)}),n.jsx("span",{className:"fbre-option-item__box fbre-option-item__box--radio",children:a?n.jsx(Z,{}):n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",children:n.jsx("circle",{cx:"5",cy:"5",r:"5"})})}),n.jsx("span",{className:"fbre-option-item__text",children:p.label})]},`${e}-${m}`)})})};$("radio",ss);const rs=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l;if(!s)return null;const a=s.columns??(s.options.length<4?1:2),c=t!=null&&o===!1;return n.jsxs("div",{className:`fbre-card-select${c?" fbre-card-select--error":""}`,children:[s.showLabel!==!1&&s.label&&n.jsx("div",{className:"fbre-card-select__label",children:s.label}),n.jsx("div",{className:"fbre-card-select__grid",style:{gridTemplateColumns:`repeat(${a}, 1fr)`},children:s.options.map(d=>{const u=t===d.value;return n.jsxs("button",{type:"button",className:`fbre-card-select__card${u?" fbre-card-select__card--selected":""}`,onClick:()=>i(e,d.value),children:[d.badge&&n.jsx("span",{className:"fbre-card-select__badge",children:d.badge}),(d.title??d.label)&&n.jsx("div",{className:"fbre-card-select__title",children:d.title??d.label}),d.description&&n.jsx("div",{className:"fbre-card-select__desc",children:d.description}),d.features&&d.features.length>0&&n.jsx("ul",{className:"fbre-card-select__features",children:d.features.map((p,m)=>n.jsx("li",{children:p},m))})]},d.value)})}),c&&r&&r.length>0&&n.jsx("div",{className:"fbre-field__errors",children:r.map((d,u)=>n.jsx("span",{className:"fbre-field__error-message",children:d},u))})]})};$("cardSelect",rs);const os=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=t,a=l,[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&&o===!1,h=a.icon&&Mn[a.icon]||Je,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 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 ls=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=t,a=l;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=o===!1;return n.jsx(q,{label:a.label,detail:a.detail,showLabel:a.showLabel,required:a.required,helperText:a.helperText,error:f,errorMessages:f?r:void 0,children:()=>n.jsxs("div",{className:`fbre-slider${c?" fbre-slider--readonly":""}`,children:[n.jsxs("div",{className:"fbre-slider__track-wrap",children:[n.jsx("input",{className:"fbre-slider__input",type:"range",min:d,max:u,step:p,value:s,disabled:c,style:{"--fill":`${m}%`},onChange:h=>i(e,Number(h.target.value))}),n.jsx("span",{className:"fbre-slider__value",children:s})]}),a.marks&&n.jsxs("div",{className:"fbre-slider__marks",children:[n.jsx("span",{className:"fbre-slider__mark",children:d}),n.jsx("span",{className:"fbre-slider__mark",children:u})]})]})})};$("slider",ls);const is=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l;if(!s)return null;const a=o===!1;return n.jsx(q,{detail:s.detail,helperText:s.helperText,error:a,errorMessages:a?r:void 0,children:()=>n.jsxs("label",{className:"fbre-toggle",children:[n.jsx("input",{type:"checkbox",checked:t??!1,onChange:c=>i(e,c.target.checked)}),n.jsx("span",{className:"fbre-toggle__track",children:n.jsx("span",{className:"fbre-toggle__thumb"})}),(!s.detail||s.detail.length===0||s.showLabel)&&n.jsx("span",{className:"fbre-toggle__label",children:s.label})]})})};$("toggleSwitch",is);const he=new Map,as=(e,t)=>{he.has(e)||he.set(e,new Set),he.get(e).add(t)},cs=(e,t)=>{var l;(l=he.get(e))==null||l.delete(t)},vt=(e,t,l)=>{var o;(o=he.get(e))==null||o.forEach(r=>{r(t,l)})},Vt=j.createContext(null);function At(){return j.useContext(Vt)}class ve extends Error{constructor(t,l,o,r){super(t),this.name="ApiError",this.status=l,this.code=o,this.validationErrors=r}}class Ft extends ve{constructor(t,l){super(`Request timed out after ${l}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,l={}){const r=`${e.apiEndpoint||""}${t}`,i=e.timeout??3e4,s={...l.body?{"Content-Type":"application/json"}:{},...l.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(),i);let p;try{p=await fetch(r,{...l,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,i);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,l,o,r,i){return se(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:l,contentType:o,size:r,componentUuid:i})})}async function hs(e,t,l){return se(e,`/api/v1/public/flows/${t}/files/${l}/confirm`,{method:"POST"})}async function vs(e,t,l){const o={flowId:t};return l&&Object.keys(l).length>0&&(o.context=l),se(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(o)})}async function bs(e,t,l){return se(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:l})})}async function xs(e,t,l){return se(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:l})})}async function gs(e,t,l){return se(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:l})})}async function ys(e,t){return se(e,`/api/v1/public/sessions/${t}`)}const js=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(!1),[d,u]=j.useState(!1),p=j.useRef(null),m=At();if(!s)return null;const f=t!=null&&o===!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};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(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:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l;if(!s)return null;const a=t!=null&&o===!1,c=s.labelYes??"Yes",d=s.labelNo??"No";return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:!1,error:a,errorMessages:a?r:void 0,children:()=>n.jsxs("div",{className:`fbre-yesno${s.layout?` fbre-yesno--${s.layout}`:""}`,children:[n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="yes"?" fbre-yesno__btn--active":""}`,onClick:()=>i(e,"yes"),children:c}),n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="no"?" fbre-yesno__btn--active":""}`,onClick:()=>i(e,"no"),children:d})]})})};$("yesNo",_s);const ws=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l;if(!s)return null;const a=o===!1,c=t===!0;return n.jsx(q,{detail:s.detail,helperText:s.helperText,tooltip:s.tooltip,error:a,errorMessages:a?r:void 0,children:()=>n.jsxs("label",{className:`fbre-confirm${a?" fbre-confirm--error":""}`,children:[n.jsx("input",{type:"checkbox",className:"fbre-confirm__input",checked:c,onChange:d=>i(e,d.target.checked?!0:void 0)}),n.jsx("span",{className:"fbre-confirm__box","aria-hidden":"true",children:n.jsx("svg",{viewBox:"0 0 16 16",className:"fbre-confirm__check",children:n.jsx("path",{d:"M3 8l3.5 3.5L13 5"})})}),n.jsx("span",{className:"fbre-confirm__label",children:s.label})]})})};$("confirm",ws);const bt=e=>{const{h:t,s:l,b:o}=e,r=l/100,i=o/100,s=i*r,a=s*(1-Math.abs(t/60%2-1)),c=i-s;let d=0,u=0,p=0;t<60?(d=s,u=a,p=0):t<120?(d=a,u=s,p=0):t<180?(d=0,u=s,p=a):t<240?(d=0,u=a,p=s):t<300?(d=a,u=0,p=s):(d=s,u=0,p=a);const m=f=>Math.round((f+c)*255).toString(16).padStart(2,"0");return`#${m(d)}${m(u)}${m(p)}`},_e=e=>{const t=e.replace("#",""),l=parseInt(t.substring(0,2),16)/255,o=parseInt(t.substring(2,4),16)/255,r=parseInt(t.substring(4,6),16)/255,i=Math.max(l,o,r),s=Math.min(l,o,r),a=i-s;let c=0;a!==0&&(i===l?c=60*((o-r)/a%6):i===o?c=60*((r-l)/a+2):c=60*((l-o)/a+4)),c<0&&(c+=360);const d=i===0?0:a/i*100,u=i*100;return{h:c,s:d,b:u}},Fe=e=>/^#[0-9a-fA-F]{6}$/.test(e),Cs=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[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));Ie(d,a,j.useCallback(()=>c(!1),[]));const x=Me(u,a,320);if(j.useEffect(()=>{typeof t=="string"&&Fe(t)&&(h(t),b(_e(t)))},[t]),!s)return null;const _=t!=null&&o===!1,N=y=>{b(y);const w=bt(y);h(w),i(e,w)},S=y=>{y.preventDefault();const w=(D,M)=>{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-(M-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 M=m.current.getBoundingClientRect(),L=Math.max(0,Math.min(360,(D-M.left)/M.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),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=>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)),i(e,E)}},w))})]})]})})};$("colorPicker",Cs);const Ns=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,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&&o===!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");i(e,w)}},[e,i]),R=()=>{const y=u.current;if(y){const w=y.getContext("2d");w&&w.clearRect(0,0,y.width,y.height)}h.current=!1,i(e,null)},C=y=>{const w=y.target.value;i(e,w||null)},k=y=>{d(y),i(e,null),h.current=!1};return s?n.jsx(q,{label:s.label??"Signature",detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:g,errorMessages:g?r:void 0,children:()=>n.jsxs("div",{className:"fbre-signature",ref:p,children:[a==="both"&&n.jsxs("div",{className:"fbre-signature__toggle",children:[n.jsx("button",{type:"button",className:`fbre-signature__toggle-btn${c==="draw"?" fbre-signature__toggle-btn--active":""}`,onClick:()=>k("draw"),children:"Draw"}),n.jsx("button",{type:"button",className:`fbre-signature__toggle-btn${c==="type"?" fbre-signature__toggle-btn--active":""}`,onClick:()=>k("type"),children:"Type"})]}),c==="draw"&&n.jsxs("div",{className:"fbre-signature__draw-area",children:[n.jsx("canvas",{ref:u,className:"fbre-signature__canvas",onPointerDown:_,onPointerMove:N,onPointerUp:S,onPointerLeave:S}),n.jsx("button",{type:"button",className:"fbre-signature__clear-btn",onClick:R,children:"Clear"})]}),c==="type"&&n.jsxs("div",{className:"fbre-signature__type-area",children:[n.jsx("input",{type:"text",className:"fbre-signature__typed-input",placeholder:"Type your name",value:typeof t=="string"&&!t.startsWith("data:")?t:"",onChange:C}),t&&typeof t=="string"&&!t.startsWith("data:")&&n.jsx("div",{className:"fbre-signature__typed-preview",children:t})]})]})}):null};$("signature",Ns);function xt(e){const t=e.offsetParent;if(!t)return 0;const l=Ot(t),o=l===document.documentElement?{left:0,right:window.innerWidth}:l.getBoundingClientRect(),r=t.getBoundingClientRect(),i=e.offsetWidth,s=r.left+i;if(s<=o.right-8)return 0;let a=-(s-o.right+8);return r.left+a<o.left+8&&(a=o.left+8-r.left),a}const pe=({open:e,onClose:t,children:l,estimatedHeight:o=300})=>{const r=j.useRef(null);Ie(r,e,j.useCallback(()=>t(),[t]));const i=Me(r,e,o),[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:l})},Pe=(e,t)=>new Date(e,t+1,0).getDate(),Ss=(e,t)=>new Date(e,t,1).getDay(),fe=(e,t,l)=>`${e}-${String(t+1).padStart(2,"0")}-${String(l).padStart(2,"0")}`,ks=e=>{const t=e.split("-");if(t.length!==3)return null;const l=parseInt(t[0],10),o=parseInt(t[1],10)-1,r=parseInt(t[2],10);return isNaN(l)||isNaN(o)||isNaN(r)?null:{year:l,month:o,day:r}},Ee=(e,t)=>{const l=ks(e);if(!l)return e;const o=String(l.month+1).padStart(2,"0"),r=String(l.day).padStart(2,"0"),i=String(l.year);return t==="DD/MM/YYYY"?`${r}/${o}/${i}`:t==="YYYY-MM-DD"?`${i}-${o}-${r}`:`${o}/${r}/${i}`},Re=e=>{const t=e.split(":");if(t.length!==2)return e;let l=parseInt(t[0],10);const o=t[1],r=l>=12?"PM":"AM";return l===0?l=12:l>12&&(l-=12),`${l}:${o} ${r}`},Ge=(e,t)=>{const l=e.indexOf("T");if(l===-1)return e;const o=e.substring(0,l),r=e.substring(l+1);return`${Ee(o,t)} ${Re(r)}`},Es=(e,t,l)=>{let o=e;return l==="AM"&&o===12?o=0:l==="PM"&&o!==12&&(o+=12),`${String(o).padStart(2,"0")}:${String(t).padStart(2,"0")}`},Rs=e=>{const t=e.split(":");let l=parseInt(t[0],10);const o=parseInt(t[1],10),r=l>=12?"PM":"AM";return l===0?l=12:l>12&&(l-=12),{hour:l,minute:o,ampm:r}},Ts=(e,t,l)=>e>=t&&e<=l,ne=e=>{if(!e)return;if(!e.startsWith("today"))return e;const t=e==="today"?0:parseInt(e.slice(5),10),l=new Date;return l.setDate(l.getDate()+(isNaN(t)?0:t)),fe(l.getFullYear(),l.getMonth(),l.getDate())},Ls=["January","February","March","April","May","June","July","August","September","October","November","December"],Is=e=>Ls[e],Ms=["Su","Mo","Tu","We","Th","Fr","Sa"],De=({selectedDate:e,min:t,max:l,onSelect:o,rangeStart:r,rangeEnd:i,rangeHover:s})=>{const a=new Date,c=fe(a.getFullYear(),a.getMonth(),a.getDate()),d=e?parseInt(e.substring(0,4),10):a.getFullYear(),u=e?parseInt(e.substring(5,7),10)-1:a.getMonth(),[p,m]=j.useState(d),[f,h]=j.useState(u),g=Pe(p,f),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??i,C=r&&R&&r<=R?r:R,k=r&&R&&r<=R?R:r;return n.jsxs("div",{className:"fbre-calendar",children:[n.jsxs("div",{className:"fbre-calendar__nav",children:[n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:b,children:"‹"}),n.jsxs("span",{className:"fbre-calendar__nav-title",children:[Is(f)," ",p]}),n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:x,children:"›"})]}),n.jsx("div",{className:"fbre-calendar__weekdays",children:Ms.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||l&&y.iso>l,M=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",M&&"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&&o(y.iso),children:y.day},w)})})]})},Ds=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&o===!1,p=typeof t=="string"?t:"";return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:u,errorMessages:u?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:`fbre-datetime__trigger${d?" fbre-datetime__trigger--readonly":""}`,onClick:d?void 0:()=>c(!a),children:[p?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ee(p,s.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholder??"Select date..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(de,{})})]}),n.jsx(pe,{open:a,onClose:()=>c(!1),children:n.jsx(De,{selectedDate:p,min:ne(s.min),max:ne(s.max),onSelect:m=>{i(e,m),c(!1)}})})]})})};$("date",Ds);const gt=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const l=parseInt(t[0],10),o=parseInt(t[1],10);return isNaN(l)||isNaN(o)?null:l*60+o},Ue=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,Be=({value:e,min:t,max:l,step:o=15,onChange:r})=>{const i=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+=o)m.push(C);const f=["AM","PM"],h=j.useMemo(()=>gt(t),[t]),g=j.useMemo(()=>gt(l),[l]),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+=o)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+=o)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(i.current),C(s.current)},[]);const R=(C,k,y)=>{let w=C;return k&&(w+=" fbre-time-selector__cell--selected"),y&&(w+=" fbre-time-selector__cell--disabled"),w};return n.jsxs("div",{className:"fbre-time-selector",children:[n.jsx("div",{className:"fbre-time-selector__column",ref:i,children:p.map(C=>{const k=x(C,u);return n.jsx("div",{className:R("fbre-time-selector__cell",C===c,k),onClick:k?void 0:()=>S(C,d,u),children:C},C)})}),n.jsx("div",{className:"fbre-time-selector__column",ref:s,children:m.map(C=>{const k=_(C);return n.jsx("div",{className:R("fbre-time-selector__cell",C===d,k),onClick:k?void 0:()=>S(c,C,u),children:String(C).padStart(2,"0")},C)})}),n.jsx("div",{className:"fbre-time-selector__column fbre-time-selector__column--ampm",children:f.map(C=>{const k=N(C);return n.jsx("div",{className:R("fbre-time-selector__cell",C===u,k),onClick:k?void 0:()=>S(c,d,C),children:C},C)})})]})},Bs=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&o===!1,p=typeof t=="string"?t:"";return n.jsx(q,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:a,error:u,errorMessages:u?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:`fbre-datetime__trigger${d?" fbre-datetime__trigger--readonly":""}`,onClick:d?void 0:()=>c(!a),children:[p?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Re(p)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:s.placeholder??"Select time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(Ye,{})})]}),n.jsxs(pe,{open:a,onClose:()=>c(!1),children:[n.jsxs("div",{className:"fbre-picker-phase-header",children:[n.jsx("span",{className:"fbre-picker-phase-header__label",children:"Select Time"}),n.jsx("button",{type:"button",className:"fbre-picker-phase-header__confirm",onClick:()=>c(!1),children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:p||void 0,step:s.step,min:s.min,max:s.max,onChange:m=>{i(e,m)}})]})]})})};$("time",Bs);const Os=({uuid:e})=>{const{value:t,properties:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(!1),[d,u]=j.useState("date");if(!s)return null;const p=s.readOnly===!0,m=t!=null&&o===!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),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:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(null),[d,u]=j.useState();if(!s)return null;const p=t!=null&&o===!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: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:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(null);if(!s)return null;const d=t!=null&&o===!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: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:l,valid:o,validationErrors:r,updateValue:i}=A(e),s=l,[a,c]=j.useState(null),[d,u]=j.useState("date");if(!s)return null;const p=t!=null&&o===!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=M=>{const L=M.indexOf("T");return L!==-1?{date:M.substring(0,L),time:M.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,_=(M,L)=>{const P=M&&L&&L<M?"":L;i(e,{start:M,end:P})},N=M=>{u((M==="start"?v:b).date?"time":"date"),c(M)},S=()=>{c(null),u("date")},R=M=>{const L=x.time||"12:00",P=`${M}T${L}`;a==="start"?_(P,h):_(f,P),u("time")},C=M=>{const L=x.date;if(!L)return;const P=`${L}T${M}`;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],l=parseInt(e.split(":")[1]),o=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[l])==null?void 0:h[o]}),i=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,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})})})},Fs=({uuid:e})=>{const t=B(a=>{var c;return(c=a.components[e])==null?void 0:c.properties}),l=B(a=>{var c;return(c=a.components[e])==null?void 0:c.addedComponents}),[o,r]=j.useState(!0);if(!t)return null;const i=l??[],s=["fbre-group",t.showBorder===!0&&"fbre-group--bordered",t.showBorder===!1&&"fbre-group--no-border"].filter(Boolean).join(" ");return n.jsx("div",{className:s,children:i.map((a,c)=>n.jsxs("div",{children:[(t.showLabel||t.collapsible)&&n.jsxs("div",{className:"fbre-group__header",children:[t.showLabel&&n.jsx("span",{className:"fbre-group__legend",children:t.label}),t.collapsible&&n.jsx("button",{type:"button",className:`fbre-group__collapse-btn${o?"":" collapsed"}`,onClick:()=>r(!o),"aria-label":"Toggle group",children:n.jsx(xe,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${o?"":" 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}),l=B(f=>{var h;return(h=f.components[e])==null?void 0:h.addedComponents}),o=B(f=>f.addRepeaterIteration),r=B(f=>f.removeRepeaterIteration),[i,s]=j.useState(new Set([0]));if(!t)return null;const a=l??[],c=1,d=()=>{const f=a.length;o(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=i.has(h);return n.jsxs("div",{children:[(t.showLabel||t.collapsible)&&n.jsxs("div",{className:"fbre-group__header",children:[t.showLabel&&n.jsxs("span",{className:"fbre-group__legend",children:[t.label," ",a.length>1?`#${h+1}`:""]}),a.length>c&&n.jsx("button",{type:"button",className:"fbre-repeater__remove-btn",onClick:()=>u(h),title:"Remove","aria-label":"Remove iteration",children:n.jsx(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:l})=>{var Ke,Ze,Qe,et,tt,nt,st,rt,ot,lt,it;const o=B(V=>V.config),r=B(V=>V.screenOrder.length),i=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(!!(o!=null&&o.summary&&e>=r)),m=((Ke=o==null?void 0:o.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=>{l&&l(V,s.getState().getFlowData())},[l,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)},[]),M=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)):o!=null&&o.summary&&(f&&T("forward"),p(!0),E(c+1))},[N,c,o,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),I=((Ze=o==null?void 0:o.theme)==null?void 0:Ze.darkMode)??!1,O=((o==null?void 0:o.mode)??"standard")==="conversational";It(O&&!u,c,L),Mt(O&&!u,c,L);const Y=((Qe=o==null?void 0:o.theme)==null?void 0:Qe.style)??"clean",ie=((et=o==null?void 0:o.controls)==null?void 0:et.stepperStyle)??"default",ae=ie==="default"?Us[Y]??"dots":ie,Ht=((tt=o==null?void 0:o.controls)==null?void 0:tt.showStepper)!==!1&&ae==="text",Oe={};(nt=o==null?void 0:o.theme)!=null&&nt.color&&(Oe["--fbre-theme-color"]=o.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":I?"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=o==null?void 0:o.controls)==null?void 0:st.show)!==!1&&i&&n.jsx(On,{screenIndex:c,maxScreenIndex:r-1,allowInvalidTransition:(rt=o==null?void 0:o.navigation)==null?void 0:rt.allowInvalidTransition,screenValidity:k,summaryEnabled:(o==null?void 0:o.summary)??!1,summaryActive:u,atMaxScreen:ee,nextButtonLabel:y,backButtonLabel:w,completionLoading:P,showStepper:(ot=o==null?void 0:o.controls)==null?void 0:ot.showStepper,stepperStyle:(lt=o==null?void 0:o.controls)==null?void 0:lt.stepperStyle,controlsLayout:(it=o==null?void 0:o.controls)==null?void 0:it.layout,nextScreen:L,prevScreen:M,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:l=>{e({externalContext:l})},updateComponentValue:(l,o)=>{var m,f;const r=t();if(l.includes(":")){const h=l.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:o};const _=r.groupComponentMap[l]??l,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,[l]:C},y=r.validationsByDependency[l];if(y)for(const w of y){const E=yt(r,w.target);if(E){const T=z(E,R);E.valid=T.length===0,k[w.target]=T}}e({components:{...r.components},conditionResults:S,validationErrors:k});return}const i=r.components[l];if(!i)return;if(i.type==="group"||i.type==="repeater"){e({components:{...r.components}});return}if(o===i.value){e({selectionTick:(t().selectionTick??0)+1});return}i.value=o;const s=r.conditionsByDependency[l];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,[l]:d},p=r.validationsByDependency[l];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:l=>{const o=t(),r=o.components[l];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=[l,r.addedComponents.length,a].join(":"),o.groupComponentMap[c.uuid]=s.uuid;const d=z(c);return c.valid=d.length===0,c});return r.addedComponents.push(i),e({components:{...o.components},groupComponentMap:{...o.groupComponentMap}}),r.addedComponents},addRepeaterIteration:l=>{const o=t(),r=o.components[l];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=[l,r.addedComponents.length,a].join(":");const d=z(c);return c.valid=d.length===0,c});return r.addedComponents.push(i),e({components:{...o.components}}),r.addedComponents},removeRepeaterIteration:(l,o)=>{const r=t(),i=r.components[l];if(!(!i||i.type!=="repeater"||!i.addedComponents||i.addedComponents.length<=1)){i.addedComponents.splice(o,1);for(let s=o;s<i.addedComponents.length;s++)i.addedComponents[s].forEach((a,c)=>{a.uuid=[l,s,c].join(":")});e({components:{...r.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:l=>{const o=t();if(l!==0)return null;const r=o.screenOrder[0];return r?o.screens[r]:null},getScreenValidity:l=>{const o=t();if(l!==0)return!0;const r=o.screenOrder[0];return r?o.screenValidity[r]??!0:!0},getValidationErrors:l=>t().validationErrors[l]??qs,evaluateFlowValidation:()=>{const l=t(),o=l.screenOrder[0];if(!o)return!0;const r=l.screens[o];if(!r)return!0;let i=!0;const s={components:l.components,groupComponentMap:l.groupComponentMap},a={...l.validationErrors};for(const d of r.components){const u=l.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=l.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=l.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={...l.screenValidity,[o]:i};return e({components:{...l.components},validationErrors:a,screenValidity:c}),i},getMaxScreenCount:()=>0,getCalculationResult:l=>t().calculationResults[l]??null})),we=(e,t)=>{var h,g;const l={},o={},r={},i={},s={},a={},c=t.screen.uuid;for(const v of t.screen.components){const b=Q(v);if(l[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"&&(o[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(i,v,b,v===c?"screen":"component");if(t.previousData)for(const v of t.previousData){const b=l[v.uuid];b&&(b.value=v.value)}const d={components:l};for(const v of Object.keys(l)){const b=l[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:l},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=l[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:l,groupComponentMap:o,templateComponentMap:r,conditionsByDependency:i,conditionResults:u,validationErrors:a,validationsByDependency:s,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:t.sessionId,navigation:t.navigation,loading:!1,error:"",externalContext:t.context??{},config:t.config??{}})},He=e=>{var i;const t=e.getState(),l=t.screenOrder[0];if(!l)return[];const o=t.screens[l];if(!o)return[];const r=[];for(const s of o.components){const a=t.components[s.uuid];if(!a||Ne(a.type))continue;const c={uuid:a.uuid,type:a.type,value:a.value};(i=a.properties)!=null&&i.label&&(c.label=a.properties.label),(a.type==="group"||a.type==="repeater")&&a.addedComponents&&(c.components=a.addedComponents.map(d=>d.filter(u=>!Ne(u.type)).map(u=>({uuid:u.uuid,type:u.type,value:u.value})))),r.push(c)}return r},yt=(e,t)=>Nt(e.components,t),Ws=6e4,Ys=({sessionEndpoint:e,flowId:t,apiKey:l,mode:o,theme:r,context:i,onFlowComplete:s,onScreenChange:a})=>{const c=j.useRef(null);c.current||(c.current=zs());const d=c.current,u=K.useStore(d,I=>I.loading),p=K.useStore(d,I=>I.error),m=K.useStore(d,I=>I.navigation),f=K.useStore(d,I=>I.config),h=K.useStore(d,I=>{var X;return(X=I.config)==null?void 0:X.mode}),g=K.useStore(d,I=>I.screenOrder),v=K.useStore(d,I=>I.screens),[b,x]=j.useState(""),_=j.useRef(null),N=j.useRef(Date.now()),S=j.useMemo(()=>({apiEndpoint:e,apiKey:l}),[e,l]),R=j.useCallback(I=>{x(I),_.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 I=await vs(S,t,i);we(d,I)}catch(I){d.setState({loading:!1,error:I.message})}},[t,e,l,i]);j.useEffect(()=>{k()},[k]),j.useEffect(()=>{const I=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",I),()=>document.removeEventListener("visibilitychange",I)},[e,l]);const y=j.useCallback(async()=>{const I=d.getState();if(!(I.loading||!I.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),C();try{const O=He(d),Y=await bs(S,I.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 I=d.getState();if(!I.loading){d.setState({loading:!0}),d.getState().clearError(),C();try{const X=He(d),O=await xs(S,I.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 I=d.getState();if(!(I.loading||!I.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),C();try{const O=He(d),Y=await gs(S,I.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},M=(o??h??"standard")==="conversational",L=M&&!m.isLastScreen;It(L,0,y),Mt(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":M?"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:l,onNext:o,onComplete:r,nextButtonLabel:i,backButtonLabel:s})=>n.jsxs("div",{className:"fbre-controls fbre-controls--default",children:[n.jsx("div",{className:"fbre-controls__left",children:e.canGoBack&&n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--back",onClick:l,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:o,disabled:t,children:t?"Loading...":i||"Next"})})]});function Js(e,t,l,o,r){return!t&&!l&&!o&&!r?e:{...e,...r&&{mode:r},...t&&{theme:{...e.theme,...t}},...l&&{navigation:{...e.navigation,...l}},...o&&{controls:{...e.controls,...o}}}}const Ut=({flow:e,data:t,mode:l,theme:o,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=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,o,r,i,l);b!==v.config&&f.current.setState({config:b})}},[l,o,r,i]);const h=a?JSON.stringify(a):"";j.useEffect(()=>{f.current&&a&&f.current.getState().updateContext(a)},[h]);const g=n.jsx(Te.Provider,{value:f.current,children:n.jsx(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:l,data:o,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:l};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,l]),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:o,mode:r,theme:i,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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),y=require("react"),Q=require("zustand"),K=require("@sonata-innovations/fiber-types"),$=require("@sonata-innovations/fiber-shared"),Wt=require("react-dom"),wt=new Map,O=(e,t)=>{wt.set(e,t)},Nt=e=>wt.get(e),we=e=>K.DISPLAY_ONLY_TYPES.has(e),Gt=(e,t)=>{var i,o,r,l;if(t.includes(":")){const s=t.split(":"),a=e.components[s[0]];return(r=(o=(i=a==null?void 0:a.addedComponents)==null?void 0:i[parseInt(s[1])])==null?void 0:o[parseInt(s[2])])==null?void 0:r.value}return(l=e.components[t])==null?void 0:l.value},G=(e,t)=>{const i=K.getValidationConfig(e);return!i||!i.rules||i.rules.length===0?[]:$.validateValue(e.value,i,t?o=>Gt(t,o):void 0)},Jt=e=>{const t=K.getValidationConfig(e);return!t||!t.rules?!1:t.rules.some(i=>i.type==="required")},ee=e=>{var o;const t={...e};if("options"in t.properties&&Array.isArray(t.properties.options)&&(t.properties={...t.properties,options:K.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=[]),["yesNo","radio","cardSelect","dropDown"].includes(e.type)){const r=e.properties??{},l=r.defaultValue;if(e.type==="yesNo")(l==="yes"||l==="no")&&(t.value=l,t.valid=!0);else{const a=(Array.isArray(r.options)?r.options:[]).find(c=>c&&c.value===l);a&&(t.value=a.value,t.valid=!0)}}return e.type==="toggleSwitch"&&(t.value=!1),e.type==="colorPicker"&&((o=e.properties)!=null&&o.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},fe=(e,t,i)=>{var o;for(const r of i.rules)if(r.type==="matchesField"&&((o=r.params)!=null&&o.field)){const l=r.params.field;e[l]||(e[l]=[]),e[l].push({target:t,config:i})}},St=(e,t)=>{var i,o;if(t.includes(":")){const r=t.split(":"),l=e[r[0]];return(o=(i=l==null?void 0:l.addedComponents)==null?void 0:i[parseInt(r[1])])==null?void 0:o[parseInt(r[2])]}return e[t]},ze=(e,t,i)=>{const o={components:e.components,groupComponentMap:e.groupComponentMap},r=G(i,o);i.valid=r.length===0;const l={...e.validationErrors,[t]:r},s=e.validationsByDependency[t];if(s)for(const a of s){const c=St(e.components,a.target);if(c){const d=G(c,o);c.valid=d.length===0,l[a.target]=d}}return l},re=(e,t)=>{const i=e.screens[t];return i?!i.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&&$.isHiddenByCondition(u,e.conditionResults[d.uuid])?!1:!d.valid}));const s=l.conditions&&"when"in l.conditions?l.conditions:void 0;return $.isHiddenByCondition(s,e.conditionResults[l.uuid])?!1:l&&"valid"in l&&!l.valid}):!0};function Xt(e){const t={};for(const i of e){const o=$.extractFormulaReferences(i.formula);for(const r of o)t[r]||(t[r]=[]),t[r].includes(i.uuid)||t[r].push(i.uuid)}return t}function kt(e,t){return{resolveValue:i=>{if(i in t)return t[i];const o=oe(e,i);if(!o)return null;const r=o.value;if(r==null||r==="")return null;const l=Number(r);return isNaN(l)?null:l},resolveOptionMetadata:(i,o)=>{const r=oe(e,i);if(!r)return null;const l=r.value;if(!l)return null;const s="options"in r.properties?r.properties.options:void 0;if(!Array.isArray(s))return null;const a=s.find(u=>u.value===l||u.label===l);if(!(a!=null&&a.metadata))return null;const c=a.metadata[o];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:i=>{for(const o of Object.keys(e.components)){const r=e.components[o];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const l=r.components.findIndex(a=>a.uuid===i);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 Ye(e){const t=e.calculations??[];if(t.length===0)return{};const i=$.topologicalSortCalculations(t),o={},r=kt(e,o);for(const l of i)o[l.uuid]=$.evaluateFormula(l.formula,r);return o}function $e(e,t){const i=e.calculationsByDependency,o=e.calculations??[];if(o.length===0||!i)return null;const r=new Set,l=[t];for(;l.length>0;){const u=l.shift(),p=i[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=$.topologicalSortCalculations(o),a={...e.calculationResults},c=kt(e,a);let d=!1;for(const u of s)if(r.has(u.uuid)){const p=$.evaluateFormula(u.formula,c);a[u.uuid]!==p&&(a[u.uuid]=p,d=!0)}return d?a:null}function Kt(e){const t={},i=o=>{var l;if(o.type!=="computed"||!((l=o.properties)!=null&&l.formula))return;const r=$.extractFormulaReferences(o.properties.formula);for(const s of r)t[s]||(t[s]=[]),t[s].includes(o.uuid)||t[s].push(o.uuid)};for(const o of Object.values(e))if(i(o),(o.type==="repeater"||o.type==="group")&&o.components)for(const r of o.components)i(r);return t}function Et(e,t,i,o){var c,d;const r=e.components[i],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[o],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 b=Number(g);return isNaN(b)?null:b}const m=oe(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)=>{const f=a.get(u)??oe(e,u);if(!f)return null;const h=f.value;if(!h)return null;const g="options"in f.properties?f.properties.options:void 0;if(!Array.isArray(g))return null;const b=g.find(_=>_.value===h||_.label===h);if(!(b!=null&&b.metadata))return null;const x=b.metadata[p];if(x==null)return null;const j=Number(x);return isNaN(j)?null:j},resolveRepeaterValues:u=>{for(const p of Object.keys(e.components)){const m=e.components[p];if(m.type!=="repeater"||!m.addedComponents||!m.components)continue;const f=m.components.findIndex(g=>g.uuid===u);if(f===-1)continue;const h=[];for(const g of m.addedComponents){const b=g[f];if(!b)continue;const x=b.value;if(x==null||x==="")continue;const j=Number(x);isNaN(j)||h.push(j)}return h.length>0?h:null}return null}}}function Ne(e,t){return{resolveValue:i=>{if(i in t)return t[i];const o=oe(e,i);if(!o)return null;const r=o.value;if(r==null||r==="")return null;const l=Number(r);return isNaN(l)?null:l},resolveOptionMetadata:(i,o)=>{const r=oe(e,i);if(!r)return null;const l=r.value;if(!l)return null;const s="options"in r.properties?r.properties.options:void 0;if(!Array.isArray(s))return null;const a=s.find(u=>u.value===l||u.label===l);if(!(a!=null&&a.metadata))return null;const c=a.metadata[o];if(c==null)return null;const d=Number(c);return isNaN(d)?null:d},resolveRepeaterValues:i=>{for(const o of Object.keys(e.components)){const r=e.components[o];if(r.type!=="repeater"||!r.addedComponents||!r.components)continue;const l=r.components.findIndex(a=>a.uuid===i);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 We(e){var i,o;const t=e.calculationResults??{};for(const r of Object.values(e.components))if(r.type==="computed"&&((i=r.properties)!=null&&i.formula)){const l=Ne(e,t),s=$.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"&&((o=d.properties)!=null&&o.formula)){const u=r.type==="repeater"?Et(e,t,r.uuid,l):Ne(e,t),p=$.evaluateFormula(d.properties.formula,u);c.value=p}}}}function Qt(e,t){var s,a;const i=e.computedByDependency;if(!i)return!1;const o=i[t];if(!o||o.length===0)return!1;const r=e.calculationResults??{};let l=!1;for(const c of o){const d=e.components[c];if(d&&d.type==="computed"&&((s=d.properties)!=null&&s.formula)){const u=Ne(e,r),p=$.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"?Et(e,r,u.uuid,f):Ne(e,r),b=$.evaluateFormula(m.properties.formula,g);h.value!==b&&(u.addedComponents[f][p]={...h,value:b},l=!0)}}}return l}const Ce=(e,t)=>{for(const i of e.screenOrder)if(e.screens[i].components.some(r=>r.uuid===t))return i;return null},Zt=(e,t)=>{if(!t.includes(":"))return null;const i=t.split(":");if(i.length!==3)return null;const o=i[0],r=parseInt(i[2]),l=e.components[o];if(!l||l.type!=="repeater"||!l.components)return null;const s=l.components[r];return(s==null?void 0:s.uuid)??null},pt=(e,t,i,o,r)=>{const l=t(),s=l.groupComponentMap[i]??i,a=Ge(e,t,s),c=ze(l,i,o),d=Ce(l,r),u={components:{...l.components},validationErrors:c};if(a&&(u.conditionResults=a),d){const b={...l,...u};u.screenValidity={...l.screenValidity,[d]:re(b,d)}}const p={...l,...u},m=i.includes(":")?Zt(p,i):null,f=[],h=b=>{if(Qt(p,b)){const x=p.computedByDependency[b]??[];for(const j of x)f.includes(j)||(f.push(j),h(j))}};h(s),m&&m!==s&&h(m);let g=$e(p,s);if(m&&m!==s){const b=g?{...p,calculationResults:g}:p,x=$e(b,m);x&&(g=x)}for(const b of f){const x=g?{...p,calculationResults:g}:p,j=$e(x,b);j&&(g=j)}g&&(u.calculationResults=g),e(u)},en=(e,t)=>({updateComponentValue:(i,o)=>{var s,a;const r=t();if(i.includes(":")){const c=i.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!==o;if(m.addedComponents[u][p]={...m.addedComponents[u][p],value:o},f){pt(e,t,i,m.addedComponents[u][p],d);return}e({components:{...r.components}});return}const l=r.components[i];if(l){if(l.type==="group"||l.type==="repeater"){e({components:{...r.components}});return}if(o===l.value){e({selectionTick:t().selectionTick+1});return}l.value=o,pt(e,t,i,l,i)}},addGroupIteration:i=>{const o=t(),r=o.components[i];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l={...o.conditionsByDependency},s=r.components.map((d,u)=>{const p=ee(d);if(p.uuid=[i,r.addedComponents.length,u].join(":"),o.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,se(l,p.uuid,f,"component"))}const m=G(p);return p.valid=m.length===0,p});r.addedComponents.push(s);const a=Ce(o,i),c={...o.screenValidity};return a&&(c[a]=re({...o},a)),e({components:{...o.components},groupComponentMap:{...o.groupComponentMap},conditionsByDependency:l,screenValidity:c}),r.addedComponents},addRepeaterIteration:i=>{const o=t(),r=o.components[i];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l={...o.conditionsByDependency},s=r.components.map((p,m)=>{const f=ee(p);if(f.uuid=[i,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,se(l,f.uuid,g,"component"))}const h=G(f);return f.valid=h.length===0,f});r.addedComponents.push(s);const a=Ce(o,i),c={...o.screenValidity};a&&(c[a]=re({...o},a));const d={...o,components:{...o.components}};We(d);const u=Ye(d);return e({components:{...o.components},conditionsByDependency:l,screenValidity:c,calculationResults:u}),r.addedComponents},removeRepeaterIteration:(i,o)=>{var g;const r=t(),l=r.components[i];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[o],c=new Set(a.map(b=>b.uuid));l.addedComponents.splice(o,1);const d={...r.conditionsByDependency},u={...r.validationErrors};for(const b of c)delete u[b],delete d[b];for(const b of Object.keys(d)){const x=d[b],j=x.filter(_=>!c.has(_.target));j.length===0?delete d[b]:j.length!==x.length&&(d[b]=j)}for(let b=o;b<l.addedComponents.length;b++)l.addedComponents[b].forEach((x,j)=>{const _=x.uuid,S=[i,b,j].join(":");if(_!==S){x.uuid=S,_ in u&&(u[S]=u[_],delete u[_]),_ in d&&(d[S]=d[_],delete d[_]);for(const R of Object.values(d))for(const N of R)N.target===_&&(N.target=S)}});const p=Ce(r,i),m={...r.screenValidity};p&&(m[p]=re({...r},p));const f={...r,components:{...r.components}};We(f);const h=Ye(f);e({components:{...r.components},conditionsByDependency:d,validationErrors:u,screenValidity:m,calculationResults:h})}}),oe=(e,t)=>St(e.components,t),se=(e,t,i,o)=>{const r=new Set;for(const s of i.when.rules)r.add(s.source);const l={target:t,type:o,config:i};for(const s of r)e[s]||(e[s]=[]),e[s].push(l)},tn=(e,t)=>{var i,o;return t.includes(":")?(i=oe(e,t))==null?void 0:i.value:(o=e.components[t])==null?void 0:o.value},Re=(e,t)=>$.evaluateConditionConfig(t,(i,o)=>(o==null?void 0:o.sourceType)==="context"?e.externalContext[o.source]:tn(e,i)),Ge=(e,t,i)=>{const o=t(),r=o.conditionsByDependency[i];if(!r||r.length===0)return null;let l=!1;const s={...o.conditionResults};for(const a of r){const c=Re(o,a.config);s[a.target]!==c&&(s[a.target]=c,l=!0)}return l?s:null},nn=e=>{const t={},i=new Set;for(const o of Object.values(e.conditionsByDependency))for(const r of o)i.has(r.target)||(i.add(r.target),t[r.target]=Re(e,r.config));return t},Ae=e=>{if(!e||we(e.type))return null;const t="label"in e.properties?e.properties.label:"",i={uuid:e.uuid,type:e.type,value:e.value};return t&&(i.label=t),i},ft=e=>{if(e.conditions&&"when"in e.conditions)return e.conditions},sn=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},i=r=>{const l=e.screens[r];if(!l)return!1;const s=l.conditions&&"when"in l.conditions?l.conditions:void 0;return $.isHiddenByCondition(s,e.conditionResults[r])};t.screens=e.screenOrder.filter(r=>!i(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=ft(c);if($.isHiddenByCondition(d,e.conditionResults[a.uuid]))return null;if((c.type==="group"||c.type==="repeater")&&c.addedComponents){const u=Ae(c);return u?{...u,components:c.addedComponents.map(p=>p.filter(m=>{const f=ft(m);return!$.isHiddenByCondition(f,e.conditionResults[m.uuid])}).map(m=>Ae(m)).filter(m=>m!==null))}:null}return Ae(c)}).filter(a=>a!==null)};return l.label&&(s.label=l.label),s});const o=e.calculations??[];if(o.length>0){const r=e.calculationResults??{};t.calculations=o.map(l=>{const s=r[l.uuid]??null,a={uuid:l.uuid,label:l.label,value:s};return s!==null&&(a.formattedValue=$.formatCalculationResult(s,l.format,l.decimalPlaces,l.currencySymbol)),a})}return t},Te=y.createContext(null);function B(e){const t=y.useContext(Te);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return Q.useStore(t,e)}const be=()=>{const e=y.useContext(Te);if(!e)throw new Error("useFBREStoreApi must be used within an FBRE provider");return e},xe=e=>!e||Object.keys(e).length===0?null:"when"in e?e:null,rn=[],on=()=>Q.createStore((e,t)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,loadFlow:(i,o,r)=>{const l={},s=[],a={},c={},d={},u={},p={},m={},f={};i.screens.forEach(N=>{const C=xe(N.conditions),k=C?{...N,conditions:C}:{...N};l[N.uuid]=k,s.push(N.uuid),C&&se(u,N.uuid,C,"screen"),N.components.forEach(v=>{const w=xe(v.conditions),T=ee(v);w&&(T.conditions=w),a[v.uuid]=T,w&&se(u,v.uuid,w,"component");const L=K.getValidationConfig(T);if(L&&fe(p,v.uuid,L),(v.type==="group"||v.type==="repeater")&&v.components){const D=a[v.uuid];D.addedComponents||(D.addedComponents=[]);const I=v.type==="repeater"?v.properties.initialData:void 0,P=v.type==="repeater"?v.properties.minIterations:void 0,A=I?I.length:v.type==="repeater"&&P&&P>1?P:1;for(let z=0;z<A;z++){const J=v.components.map((X,ue)=>{const E=ee(X);E.uuid=[v.uuid,D.addedComponents.length,ue].join(":"),I&&I[z]&&X.uuid in I[z]&&(E.value=I[z][X.uuid]),v.type==="group"&&(c[E.uuid]=X.uuid),z===0&&(d[X.uuid]=E.uuid);const Y=xe(E.conditions);Y&&(E.conditions=Y,se(u,E.uuid,Y,"component"));const H=K.getValidationConfig(E);H&&fe(p,E.uuid,H);const W=G(E);return E.valid=W.length===0,W.length>0&&(m[E.uuid]=W),E});D.addedComponents.push(J)}}})}),o&&o.screens.forEach(N=>{const C=s.indexOf(N.uuid);C<0||N.components.forEach(k=>{const v=a[k.uuid];if(v)if((v.type==="group"||v.type==="repeater")&&k.components&&v.addedComponents){if(k.components.length>1){const w=v.addedComponents.length,T=k.components.length-w,L=i.screens[C].components.find(M=>M.uuid===v.uuid);for(let M=0;M<T;M++)if(L!=null&&L.components){const D=L.components.map((I,P)=>{const A=ee(I);A.uuid=[v.uuid,v.addedComponents.length,P].join(":"),v.type==="group"&&(c[A.uuid]=I.uuid),d[I.uuid]||(d[I.uuid]=A.uuid);const z=xe(A.conditions);z&&(A.conditions=z,se(u,A.uuid,z,"component"));const J=K.getValidationConfig(A);J&&fe(p,A.uuid,J);const X=G(A);return A.valid=X.length===0,X.length>0&&(m[A.uuid]=X),A});v.addedComponents.push(D)}}k.components.forEach(w=>{w.forEach(T=>{for(const L of v.addedComponents){const M=L.find(D=>D.uuid===T.uuid);if(M){M.value=T.value;const D=G(M);M.valid=D.length===0,m[M.uuid]=D;break}}})})}else{v.value=k.value;const w=G(v);v.valid=w.length===0,m[v.uuid]=w}})});for(const N of Object.keys(a)){const C=a[N];if(!(C.type==="group"||C.type==="repeater")&&K.getValidationConfig(C)&&!(N in m)){const k=G(C);C.valid=k.length===0,k.length>0&&(m[N]=k)}}const h={...t(),externalContext:r??{},screens:l,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},g=nn(h);h.conditionResults=g,s.forEach(N=>{f[N]=re(h,N)});const b=Kt(a),x={...h,computedByDependency:b,calculationResults:{},screenValidity:f};We(x);const j=i.calculations??[],_=Xt(j),S={...x,calculations:j},R=Ye(S);e({flowUUID:i.uuid,metadata:i.metadata,config:i.config??{},externalContext:r??{},screens:l,screenOrder:s,components:a,groupComponentMap:c,templateComponentMap:d,conditionsByDependency:u,conditionResults:g,screenValidity:f,validationErrors:m,validationsByDependency:p,calculations:j,calculationResults:R,calculationsByDependency:_,computedByDependency:b})},updateContext:i=>{const o=t(),r=o.externalContext,l=[];for(const d of Object.keys(i))r[d]!==i[d]&&l.push(d);for(const d of Object.keys(r))!(d in i)&&!l.includes(d)&&l.push(d);if(l.length===0)return;const s={...o.conditionResults};let a=!1;const c=new Set;for(const d of l){const u=o.conditionsByDependency[d];if(!(!u||u.length===0))for(const p of u){if(c.has(p.target))continue;c.add(p.target);const m={...o,externalContext:i},f=Re(m,p.config);s[p.target]!==f&&(s[p.target]=f,a=!0)}}if(a){const d={...o,conditionResults:s},u={};for(const p of o.screenOrder)u[p]=re(d,p);e({externalContext:i,conditionResults:s,screenValidity:u})}else e({externalContext:i})},...en(e,t),getFlowData:()=>sn(t()),getScreenByIndex:i=>{const o=t();return i<0||i>=o.screenOrder.length?null:o.screens[o.screenOrder[i]]},getScreenValidity:i=>{const o=t();return i<0||i>=o.screenOrder.length?!0:o.screenValidity[o.screenOrder[i]]??!0},getValidationErrors:i=>t().validationErrors[i]??rn,evaluateFlowValidation:()=>{const i=t(),o={};let r=!0;return i.screenOrder.forEach(l=>{const s=re(i,l);o[l]=s,s||(r=!1)}),e({screenValidity:o}),r},getMaxScreenCount:()=>t().screenOrder.length-1,getCalculationResult:i=>t().calculationResults[i]??null})),ln=({uuid:e})=>{var a;const t=B(c=>c.components[e]),i=B(c=>c.conditionResults[e]);if(!t)return null;const o=t.conditions&&"when"in t.conditions?t.conditions:void 0;if($.isHiddenByCondition(o,i))return null;const r=Nt(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})})},Je=({screenIndex:e})=>{const t=B(i=>{const o=i.screenOrder[e];return o?i.screens[o]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(i=>n.jsx(ln,{uuid:i.uuid},i.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"})}),le=({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"})]}),Xe=({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"})]}),ve=({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"})}),an=({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"})}),cn=({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"})}),dn=({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"})}),un=({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"})}),pn=({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"})}),Qe=({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"})}),fn=({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"})}),mn=({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"})]}),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("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"})]}),vn=({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"})]}),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:"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"})]}),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:"M3 11l18-5v12L3 13v-2z"}),n.jsx("path",{d:"M11.6 16.8a3 3 0 11-5.8-1.6"})]}),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:"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"})]}),jn=({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"})}),_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("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0110 0v4"})]}),Rt=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"})}),Cn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"}),n.jsx("line",{x1:"4",y1:"22",x2:"4",y2:"15"})]}),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:"M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z"})}),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("polygon",{points:"13,2 3,14 12,14 11,22 21,10 12,10 13,2"})}),Sn=({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"})]}),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("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"})]}),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:"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"})]}),Rn=({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"})}),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("rect",{x:"12",y:"1",width:"15.56",height:"15.56",rx:"2",transform:"rotate(45 12 1)"})}),Fe={info:mn,check:hn,warning:bn,question:kn,lightbulb:xn,megaphone:gn,bell:yn,shield:jn,lock:_n,heart:Rt,flag:Cn,bookmark:wn,zap:Nn,pencil:Sn,star:Qe},Ln={star:Qe,heart:Rt,thumbsUp:En,circle:Rn,diamond:Tn},ge=({position:e,screenIndex:t,maxScreenIndex:i,allowInvalidTransition:o,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(dn,{}),d||"Back"]})}const g=l?a&&s:a,b=l?a?s?"Done":"Review":"Next":a?"Done":"Next";if(i===0){const _=l?s?"Complete":"Review":"Complete",S=h||!r;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:S,onClick:()=>{l&&!s?p():f()},children:[c||_,h?n.jsx("span",{className:"fbre-btn__spinner"}):n.jsx(Z,{size:16})]})}const x=h||!o&&!r||b==="Done"&&!r,j=()=>{g?f():p()};return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:x,onClick:j,children:[c||b,h?n.jsx("span",{className:"fbre-btn__spinner"}):g?n.jsx(Z,{size:16}):n.jsx(un,{})]})},In=({current:e,total:t,stepperStyle:i})=>{if(t<=1)return null;const o=t>1?e/(t-1)*100:100,l=!!i&&i!=="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:`${o}%`}})}),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:`${o}%`}})})]})},Mn=({current:e,total:t})=>t<=1?null:n.jsxs("div",{className:"fbre-stepper-text",children:["Step ",e+1," of ",t]}),Dn=e=>{const t=e.controlsLayout??"default",o=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text"&&e.maxScreenIndex>0,r=e.screenIndex>0||e.summaryActive,l=r?2:1,s=o?n.jsx(In,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):null;if(t==="default"){const a=!r&&!o;return n.jsxs("div",{className:"fbre-controls fbre-controls--default","data-button-count":l,"data-solo":a?"true":void 0,children:[r?n.jsx(ge,{position:"back",...e}):n.jsx("div",{}),s??n.jsx("div",{}),n.jsx(ge,{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(ge,{position:"back",...e}),n.jsx(ge,{position:"next",...e})]})]})},Tt=({component:e})=>{const{uuid:t,label:i,type:o,value:r,components:l}=e,s=()=>{if(r!=null)switch(o){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(o==="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:i}),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(Tt,{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${o==="group"||o==="repeater"?" fbre-summary__item--group":""}`,children:[n.jsx("div",{className:"fbre-summary__item-label",children:i}),o!=="group"&&o!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${c?" fbre-summary__item-value--empty":""}`,children:s()}),(o==="group"||o==="repeater")&&a()]})},mt=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Le=(e,t)=>{const i=e.replace($.REF_REGEX,(o,r)=>{const l=t.resolveCalculation(r);if(l!==null)return mt(l);const s=t.resolveComponentValue(r);return s!==null?mt(s):""});return $.convertMarkupToHTML(i)},ie=(e,t)=>e.replace($.REF_REGEX,(i,o)=>{const r=t.resolveCalculation(o);if(r!==null)return r;const l=t.resolveComponentValue(o);return l!==null?l:""});function ae(){const e=B(r=>r.components),t=B(r=>r.templateComponentMap),i=B(r=>r.calculations),o=B(r=>r.calculationResults);return y.useMemo(()=>{const r=new Map(i.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=o[s]??null;return $.formatCalculationResult(c,a.format,a.decimalPlaces,a.currencySymbol)}}},[e,t,i,o])}const Bn=({screen:e,showToggle:t})=>{const i=ae(),[o,r]=y.useState(!0);return n.jsxs("div",{children:[n.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>t&&r(!o),children:[e.label&&n.jsx("span",{className:"fbre-summary__screen-label",children:ie(e.label,i)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${o?"":" collapsed"}`,children:n.jsx(ve,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${o?"":" collapsed"}`,children:e.components.map(l=>n.jsx(Tt,{component:l},l.uuid))})]})},ht=()=>{const e=be(),t=B(r=>r.components),i=y.useMemo(()=>e.getState().getFlowData(),[e,t]),o=i.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:i.screens.map(r=>n.jsx(Bn,{screen:r,showToggle:o>1},r.uuid))})]})},Lt=(e,t,i)=>t?!$.isHiddenByCondition(t,i[e]):!0,Se=(e,t)=>{const i=e.screenOrder.length-1;let o=t+1;for(;o<=i;){const r=e.screenOrder[o],l=e.screens[r],s=l!=null&&l.conditions&&"when"in l.conditions?l.conditions:void 0;if(Lt(r,s,e.conditionResults))return o;o++}return null},On=(e,t)=>{let i=t-1;for(;i>=0;){const o=e.screenOrder[i],r=e.screens[o],l=r!=null&&r.conditions&&"when"in r.conditions?r.conditions:void 0;if(Lt(o,l,e.conditionResults))return i;i--}return 0},Vn=new Set(["text","header","callout","divider","table","computed"]);function It(e,t){const i=e.screenOrder[t];if(!i)return 0;const o=e.screens[i];if(!o)return 0;let r=0;for(const l of o.components){const s=e.components[l.uuid];if(!s||Vn.has(s.type))continue;const a=s.conditions&&"when"in s.conditions?s.conditions:void 0;$.isHiddenByCondition(a,e.conditionResults[l.uuid])||(r+=1)}return r}const Ze=new Set(["radio","yesNo","cardSelect","dropDown"]),$n=500;function Mt(e,t,i){const o=be(),r=y.useRef(null),l=y.useRef(""),s=y.useRef(0);y.useEffect(()=>{if(!e)return;const a=o.getState(),c=bt(a,t);c&&(l.current=vt(a.components,c)),s.current=a.selectionTick},[e,t,o]),y.useEffect(()=>{if(!e)return;const a=o.subscribe(c=>{const d=bt(c,t);if(!d)return;const u=c.selectionTick,p=u!==s.current;p&&(s.current=u);const m=vt(c.components,d);if(m===l.current&&!p)return;const f=l.current;if(l.current=m,!(m!==f?An(c.components,d,f):p&&Fn(c.components,d))||Se(c,t)===null)return;const b=c.screenOrder[t];b&&c.screenValidity[b]===!1||It(c,t)===1&&(r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{r.current=null,i()},$n))});return()=>{a(),r.current&&(clearTimeout(r.current),r.current=null)}},[e,t,o,i]),y.useEffect(()=>()=>{r.current&&(clearTimeout(r.current),r.current=null)},[t])}function bt(e,t){const i=e.screenOrder[t];if(!i)return null;const o=e.screens[i];return o?o.components.map(r=>r.uuid):null}function vt(e,t){const i=[];for(const o of t){const r=e[o];!r||!Ze.has(r.type)||i.push(`${o}=${JSON.stringify(r.value??null)}`)}return i.join("|")}function An(e,t,i){const o=new Map;for(const r of i.split("|")){const l=r.indexOf("=");l>0&&o.set(r.slice(0,l),r.slice(l+1))}for(const r of t){const l=e[r];if(!l||!Ze.has(l.type))continue;const s=JSON.stringify(l.value??null),a=o.get(r)??"null";if(s!==a&&s!=="null")return!0}return!1}function Fn(e,t){for(const i of t){const o=e[i];if(!(!o||!Ze.has(o.type))&&o.value!==null&&o.value!==void 0)return!0}return!1}function Dt(e,t,i){const o=be();y.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=o.getState();if(Se(a,t)===null)return;const d=a.screenOrder[t];d&&a.screenValidity[d]===!1||It(a,t)===1&&(l.preventDefault(),i())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,i,o])}const Bt=y.createContext(null),xt=[],F=e=>{const t=y.useContext(Bt),i=B(a=>{var c;return(c=a.components[e])==null?void 0:c.value}),o=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]??xt),s=B(a=>a.updateComponentValue);return t?{value:t.value,properties:t.properties,valid:t.valid,validationErrors:xt,updateValue:s}:{value:i,properties:o,valid:r,validationErrors:l,updateValue:s}},ce=(e,t)=>F(e),Pn=({uuid:e})=>{const{properties:t}=ce(e),i=ae(),o=t==null?void 0:t.value;if(!o)return null;const r=ie(o,i);return n.jsx("h2",{className:"fbre-header",children:r})};O("header",Pn);const Un=({uuid:e})=>{const{properties:t}=ce(e),i=ae(),o=t==null?void 0:t.value;return o==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:Le(o,i)}})};O("text",Un);const Hn=({uuid:e})=>{const{properties:t}=ce(e),i=(t==null?void 0:t.textAlign)??"center",o=i==="left"?" fbre-divider--left":i==="right"?" fbre-divider--right":"";return n.jsx("div",{className:`fbre-divider${o}`,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"})})};O("divider",Hn);const qn={info:"info",success:"check",warning:"warning",neutral:void 0},zn=({uuid:e})=>{const{properties:t}=ce(e),i=ae(),o=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(!o&&!r)return null;let a;if(s==="none")a=void 0;else if(s&&Fe[s])a=Fe[s];else{const d=qn[l];a=d?Fe[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,i)}),o&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:Le(o,i)}})]})]})};O("callout",zn);const Yn=({uuid:e})=>{const{properties:t}=ce(e),i=t==null?void 0:t.label,o=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!o||!r||o.length===0?null:n.jsxs("div",{className:"fbre-table",children:[i&&n.jsx("div",{className:"fbre-table__label",children:i}),n.jsxs("table",{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"fbre-table__row-label"}),o.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}),o.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))})]})]})};O("table",Yn);const Wn=({uuid:e})=>{const{properties:t,value:i}=ce(e),o=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=$.formatCalculationResult(typeof i=="number"?i:null,s,a,c);return n.jsxs("div",{className:"fbre-computed",children:[r&&o&&n.jsx("div",{className:"fbre-computed__label",children:o}),n.jsx("div",{className:"fbre-computed__value",children:d||"—"}),l&&n.jsx("div",{className:"fbre-computed__detail",children:l})]})};O("computed",Wn);const Ot=({text:e})=>{var c;const[t,i]=y.useState(!1),o=y.useRef(null),r=y.useRef(null),[l,s]=y.useState(null),a=y.useCallback(()=>{if(!o.current)return;const d=o.current.getBoundingClientRect();s({top:d.bottom+4,left:d.right})},[]);return y.useEffect(()=>{if(!t)return;a();const d=p=>{const m=p.target;o.current&&!o.current.contains(m)&&r.current&&!r.current.contains(m)&&i(!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:o,type:"button",className:"fbre-tooltip-trigger",onClick:()=>i(!t),"aria-label":"Help",children:n.jsx(pn,{})}),t&&l&&Wt.createPortal(n.jsx("div",{ref:r,className:"fbre-tooltip-popover open",style:{top:l.top,left:l.left},children:n.jsx("span",{dangerouslySetInnerHTML:{__html:$.convertMarkupToHTML(e)}})}),((c=o.current)==null?void 0:c.closest(".fbre-container"))??document.body)]})},U=({label:e,detail:t,showLabel:i,required:o,helperText:r,tooltip:l,inputId:s,externalFocused:a,error:c,errorMessages:d,children:u})=>{const p=ae(),[m,f]=y.useState(!1);y.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||i)&&n.jsxs("label",{className:"fbre-field__label",htmlFor:s,children:[ie(e,p),o&&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(b=>b);return c&&g&&g.length>0&&n.jsxs("div",{className:"fbre-field__errors",children:[n.jsx("span",{className:"fbre-field__error-message",children:g[0]}),g.length>1&&n.jsxs("span",{className:"fbre-field__error-more",children:["(and ",g.length-1," more)"]})]})})()]}),l&&n.jsx(Ot,{text:l})]})]})},Gn=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,a=y.useRef(null),[c,d]=y.useState(!1);if(!s)return null;const u=t!=null&&o===!1,p=s.inputType==="password",m=p&&c?"text":s.inputType??"text",f=`fbre-input-${e}`;return n.jsx(U,{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(an,{}):n.jsx(cn,{})})]})})};O("inputText",Gn);const Jn=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i;if(!s)return null;const a=t!=null&&o===!1,c=`fbre-input-${e}`;return n.jsx(U,{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)})})};O("inputTextArea",Jn);const Xn=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(t??"");if(!s)return null;const d=t!=null&&o===!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=j=>{const _=["Backspace","Delete","ArrowLeft","ArrowRight","Tab","Home","End","Enter"];u>0&&_.push("."),!(_.includes(j.key)||j.ctrlKey||j.metaKey)&&(/^[0-9]$/.test(j.key)||j.preventDefault())},b=j=>{if(j.target.value.length===0){c(""),l(e,"");return}h.test(j.target.value)&&(c(j.target.value),l(e,j.target.value))},x=j=>{j(!1);const _=m(String(a));_!==String(a)&&(c(_),l(e,_))};return n.jsx(U,{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:j})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[s.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:s.startAdornment}),n.jsx("input",{id:p,className:`fbre-field__input${s.readOnly?" fbre-field__input--readonly":""}`,type:"text",value:a,placeholder:s.placeholder,maxLength:s.maxlength,readOnly:s.readOnly,autoComplete:"off",onKeyDown:g,onChange:b,onFocus:()=>j(!0),onBlur:()=>x(j)})]})})}const f=(h,g)=>{g(!1);const b=m(h.target.value);b!==h.target.value&&(h.target.value=b,l(e,b))};return n.jsx(U,{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)})]})})};O("inputNumber",Xn);function Ie(e,t,i){y.useEffect(()=>{if(!t)return;const o=r=>{e.current&&!e.current.contains(r.target)&&i()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[t,e,i])}function Vt(e){let t=e.parentElement;for(;t;){const{overflow:i,overflowY:o}=getComputedStyle(t);if(/(auto|scroll)/.test(i+o))return t;t=t.parentElement}return document.documentElement}function gt(e,t){const i=Vt(e),o=i===document.documentElement?{top:0,bottom:window.innerHeight}:i.getBoundingClientRect(),r=e.getBoundingClientRect(),l=o.bottom-r.bottom,s=r.top-o.top;return l<t&&s>l}function Me(e,t,i=300){const[o,r]=y.useState(!1);return y.useLayoutEffect(()=>{if(!t||!e.current){r(!1);return}const l=e.current.offsetParent;l&&r(gt(l,i))},[t,i]),y.useEffect(()=>{if(!t||!e.current)return;const l=()=>{var a;const s=(a=e.current)==null?void 0:a.offsetParent;s&&r(gt(s,i))};return window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[t,i]),o}const Kn=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1),d=y.useRef(null),u=y.useRef(null);Ie(d,a,y.useCallback(()=>c(!1),[]));const p=Me(u,a,200);if(!s)return null;const m=s.readOnly===!0,f=t!=null&&o===!1,h=s.options.find(g=>g.value.toString()===(t==null?void 0:t.toString()));return n.jsx(U,{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(ve,{})})]}),n.jsx("div",{ref:u,className:`fbre-popup fbre-dropdown__panel${a?" fbre-popup--open":""}${p?" fbre-popup--above":""}`,children:s.options.map((g,b)=>{const x=g.value.toString()===(t==null?void 0:t.toString());return n.jsxs("div",{className:`fbre-dropdown__option${x?" fbre-dropdown__option--selected":""}`,onClick:()=>{l(e,g.value),c(!1)},children:[n.jsx("span",{children:g.label}),x&&n.jsx("span",{className:"fbre-dropdown__option-check",children:n.jsx(Z,{})})]},`${e}-${b}`)})})]})})};O("dropDown",Kn);const Qn=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1),d=y.useRef(null),u=y.useRef(null);Ie(d,a,y.useCallback(()=>c(!1),[]));const p=Me(u,a,200);if(!s)return null;const m=s.readOnly===!0,f=t??[],h=t!=null&&o===!1,g=x=>{const j=x.toString(),_=f.includes(j)?f.filter(S=>S!==j):[...f,j];l(e,_)},b=(x,j)=>{j.stopPropagation(),l(e,f.filter(_=>_!==x))};return n.jsx(U,{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(x=>{const j=s.options.find(_=>_.value.toString()===x);return n.jsxs("span",{className:"fbre-dropdown__tag",children:[(j==null?void 0:j.label)??x,!m&&n.jsx("button",{type:"button",className:"fbre-dropdown__tag-remove",onClick:_=>b(x,_),children:"×"})]},x)})}):n.jsx("span",{className:"fbre-dropdown__placeholder",children:"Select..."}),n.jsx("span",{className:`fbre-dropdown__arrow${a?" open":""}`,children:n.jsx(ve,{})})]}),n.jsx("div",{ref:u,className:`fbre-popup fbre-dropdown__panel${a?" fbre-popup--open":""}${p?" fbre-popup--above":""}`,children:s.options.map((x,j)=>{const _=f.includes(x.value.toString());return n.jsxs("div",{className:"fbre-dropdown__option",onClick:()=>g(x.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:x.label})]},`${e}-${j}`)})})]})})};O("dropDownMulti",Qn);const $t=({label:e,detail:t,showLabel:i,required:o,helperText:r,tooltip:l,error:s,errorMessages:a,children:c})=>{const d=ae(),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:[i!==!1&&(!t||t.length===0)&&n.jsxs("div",{className:"fbre-option-group__label",children:[ie(e,d),o&&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(Ot,{text:l})]})]})},Zn=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i;if(!s)return null;const a=s.readOnly===!0,c=t??[],d=t!=null&&o===!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}`)})})};O("checkbox",Zn);const es=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,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,u=t!=null&&o===!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}`)})})};O("radio",es);const ts=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i;if(!s)return null;const a=s.columns??(s.options.length<4?1:2),c=t!=null&&o===!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))})]})};O("cardSelect",ts);const ns=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=t,a=i,[c,d]=y.useState(null);if(!a)return null;const u=a.max??5,p=a.precision??1,m=c??s??0,f=s!=null&&o===!1,h=a.icon&&Ln[a.icon]||Qe,g=(j,_)=>{const S=_&&p<=.5?j+.5:j+1;l(e,S)},b=(j,_)=>{const S=_.currentTarget.getBoundingClientRect(),N=_.clientX-S.left<S.width/2&&p<=.5?j+.5:j+1;d(N)},x=[];for(let j=0;j<u;j++){const _=m>=j+1,S=!_&&m>=j+.5,R=`fbre-rating__star${_?" fbre-rating__star--full":S?" fbre-rating__star--half":""}`;x.push(n.jsx("div",{className:R,onMouseMove:N=>b(j,N),onMouseLeave:()=>d(null),onClick:N=>{const C=N.currentTarget.getBoundingClientRect(),k=N.clientX-C.left<C.width/2;g(j,k)},children:n.jsx(h,{})},j))}return n.jsx(U,{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:x}),s!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[s," / ",u]})]})})};O("rating",ns);const ss=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=t,a=i;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=o===!1;return n.jsx(U,{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})]})]})})};O("slider",ss);const rs=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i;if(!s)return null;const a=o===!1;return n.jsx(U,{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})]})})};O("toggleSwitch",rs);const me=new Map,os=(e,t)=>{me.has(e)||me.set(e,new Set),me.get(e).add(t)},is=(e,t)=>{var i;(i=me.get(e))==null||i.delete(t)},yt=(e,t,i)=>{var o;(o=me.get(e))==null||o.forEach(r=>{r(t,i)})},At=y.createContext(null);function Ft(){return y.useContext(At)}class he extends Error{constructor(t,i,o,r){super(t),this.name="ApiError",this.status=i,this.code=o,this.validationErrors=r}}class Pt extends he{constructor(t,i){super(`Request timed out after ${i}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const ls=new Set([502,503,504]),ye=2,as=[500,1500];function cs(e){return new Promise(t=>setTimeout(t,e))}async function ne(e,t,i={}){const r=`${e.apiEndpoint||""}${t}`,l=e.timeout??3e4,s={...i.body?{"Content-Type":"application/json"}:{},...i.headers};e.apiKey&&(s.Authorization=`Bearer ${e.apiKey}`);let a;for(let c=0;c<=ye;c++){c>0&&await cs(as[c-1]);try{const d=new AbortController,u=setTimeout(()=>d.abort(),l);let p;try{p=await fetch(r,{...i,headers:s,signal:d.signal})}finally{clearTimeout(u)}if(!p.ok){const m=await p.json().catch(()=>({})),f=new he(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(c<ye&&ls.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 he)throw d;if(d instanceof DOMException&&d.name==="AbortError"){const u=new Pt(r,l);if(c<ye){a=u;continue}throw u}if(d instanceof TypeError&&c<ye){a=d;continue}throw d}}throw a}async function ds(e,t){return ne(e,`/api/v1/public/flows/${t}`)}async function us(e,t,i,o,r,l){return ne(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:i,contentType:o,size:r,componentUuid:l})})}async function ps(e,t,i){return ne(e,`/api/v1/public/flows/${t}/files/${i}/confirm`,{method:"POST"})}async function fs(e,t,i){const o={flowId:t};return i&&Object.keys(i).length>0&&(o.context=i),ne(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(o)})}async function ms(e,t,i){return ne(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:i})})}async function hs(e,t,i){return ne(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:i})})}async function bs(e,t,i){return ne(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:i})})}async function vs(e,t){return ne(e,`/api/v1/public/sessions/${t}`)}const xs=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1),[d,u]=y.useState(!1),p=y.useRef(null),m=Ft();if(!s)return null;const f=t!=null&&o===!1,h=async g=>{if(g.preventDefault(),!g.target.files)return;const b=g.target.files[0];if(!b)return;if(s.maxSize&&b.size>s.maxSize){c(!0),setTimeout(()=>c(!1),5e3);return}if(c(!1),m){u(!0);try{const{fileId:j,uploadUrl:_}=await us(m.config,m.flowId,b.name,b.type,b.size,e);await fetch(_,{method:"PUT",headers:{"Content-Type":b.type},body:b}),await ps(m.config,m.flowId,j);const S={mode:"s3",fileId:j,name:b.name,type:b.type,size:b.size};l(e,S),yt("file-upload",e,S)}catch(j){console.error("File upload failed:",j),c(!0),setTimeout(()=>c(!1),5e3)}finally{u(!1)}return}const x=new FileReader;x.addEventListener("load",()=>{const j={name:b.name,type:b.type,size:b.size,lastModified:b.lastModified,data:x.result};"lastModifiedDate"in b&&(j.lastModifiedDate=b.lastModifiedDate),l(e,j),yt("file-upload",e,j)}),x.readAsDataURL(b)};return n.jsx(U,{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(fn,{}),"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:"×"})]})]})})};O("fileUpload",xs);const gs=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i;if(!s)return null;const a=t!=null&&o===!1,c=s.labelYes??"Yes",d=s.labelNo??"No";return n.jsx(U,{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})]})})};O("yesNo",gs);const ys=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i;if(!s)return null;const a=o===!1,c=t===!0;return n.jsx(U,{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})]})})};O("confirm",ys);const jt=e=>{const{h:t,s:i,b:o}=e,r=i/100,l=o/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)}`},je=e=>{const t=e.replace("#",""),i=parseInt(t.substring(0,2),16)/255,o=parseInt(t.substring(2,4),16)/255,r=parseInt(t.substring(4,6),16)/255,l=Math.max(i,o,r),s=Math.min(i,o,r),a=l-s;let c=0;a!==0&&(l===i?c=60*((o-r)/a%6):l===o?c=60*((r-i)/a+2):c=60*((i-o)/a+4)),c<0&&(c+=360);const d=l===0?0:a/l*100,u=l*100;return{h:c,s:d,b:u}},Pe=e=>/^#[0-9a-fA-F]{6}$/.test(e),js=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1),d=y.useRef(null),u=y.useRef(null),p=y.useRef(null),m=y.useRef(null),[f,h]=y.useState(""),g=typeof t=="string"&&Pe(t)?t:"#1976d2",[b,x]=y.useState(()=>je(g));Ie(d,a,y.useCallback(()=>c(!1),[]));const j=Me(u,a,320);if(y.useEffect(()=>{typeof t=="string"&&Pe(t)&&(h(t),x(je(t)))},[t]),!s)return null;const _=t!=null&&o===!1,S=v=>{x(v);const w=jt(v);h(w),l(e,w)},R=v=>{v.preventDefault();const w=(M,D)=>{const I=p.current.getBoundingClientRect(),P=Math.max(0,Math.min(100,(M-I.left)/I.width*100)),A=Math.max(0,Math.min(100,(1-(D-I.top)/I.height)*100));S({...b,s:P,b:A})};w(v.clientX,v.clientY);const T=M=>w(M.clientX,M.clientY),L=()=>{document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",L)};document.addEventListener("mousemove",T),document.addEventListener("mouseup",L)},N=v=>{v.preventDefault();const w=M=>{const D=m.current.getBoundingClientRect(),I=Math.max(0,Math.min(360,(M-D.left)/D.width*360));S({...b,h:I})};w(v.clientX);const T=M=>w(M.clientX),L=()=>{document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",L)};document.addEventListener("mousemove",T),document.addEventListener("mouseup",L)},C=v=>{if(h(v),Pe(v)){const w=je(v);x(w),l(e,v.toLowerCase())}},k=jt({h:b.h,s:100,b:100});return n.jsx(U,{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":""}${j?" fbre-popup--above":""}`,children:[n.jsxs("div",{className:"fbre-colorpicker__saturation",ref:p,style:{background:k},onMouseDown:R,children:[n.jsx("div",{className:"fbre-colorpicker__saturation-white"}),n.jsx("div",{className:"fbre-colorpicker__saturation-black"}),n.jsx("div",{className:"fbre-colorpicker__cursor",style:{left:`${b.s}%`,top:`${100-b.b}%`}})]}),n.jsx("div",{className:"fbre-colorpicker__hue",ref:m,onMouseDown:N,children:n.jsx("div",{className:"fbre-colorpicker__hue-cursor",style:{left:`${b.h/360*100}%`}})}),n.jsx("div",{className:"fbre-colorpicker__input-row",children:n.jsx("input",{type:"text",className:"fbre-colorpicker__input",value:f,onChange:v=>C(v.target.value),maxLength:7})}),s.swatches&&s.swatches.length>0&&n.jsx("div",{className:"fbre-colorpicker__swatches",children:s.swatches.map((v,w)=>n.jsx("button",{type:"button",className:`fbre-colorpicker__swatch-btn${v.toLowerCase()===g.toLowerCase()?" fbre-colorpicker__swatch-btn--active":""}`,style:{background:v},onClick:()=>{const T=v.toLowerCase();h(T),x(je(T)),l(e,T)}},w))})]})]})})};O("colorPicker",js);const _s=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,a=(s==null?void 0:s.mode)??"draw",[c,d]=y.useState(a==="type"?"type":"draw"),u=y.useRef(null),p=y.useRef(null),m=y.useRef(!1),f=y.useRef(null),h=y.useRef(!1),g=t!=null&&o===!1,b=y.useCallback(()=>{const v=u.current,w=p.current;if(!v||!w)return;const T=w.getBoundingClientRect(),L=window.devicePixelRatio||1;v.width=T.width*L,v.height=150*L,v.style.width=`${T.width}px`,v.style.height="150px";const M=v.getContext("2d");M&&(M.scale(L,L),M.lineCap="round",M.lineJoin="round",M.lineWidth=2,M.strokeStyle="var(--fbre-text, #1a1a1a)")},[]);y.useEffect(()=>{if(c==="draw")return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[c,b]);const x=v=>{const T=u.current.getBoundingClientRect();return{x:v.clientX-T.left,y:v.clientY-T.top}},j=y.useCallback((v,w)=>{var M;const T=(M=u.current)==null?void 0:M.getContext("2d");if(!T)return;const L={x:(v.x+w.x)/2,y:(v.y+w.y)/2};T.beginPath(),T.moveTo(v.x,v.y),T.quadraticCurveTo(v.x,v.y,L.x,L.y),T.stroke()},[]),_=y.useCallback(v=>{const w=u.current;w&&(w.setPointerCapture(v.pointerId),m.current=!0,f.current=x(v.nativeEvent),h.current=!0)},[]),S=y.useCallback(v=>{if(!m.current||!f.current)return;const w=x(v.nativeEvent);j(f.current,w),f.current=w},[j]),R=y.useCallback(()=>{if(!m.current)return;m.current=!1,f.current=null;const v=u.current;if(v&&h.current){const w=v.toDataURL("image/png");l(e,w)}},[e,l]),N=()=>{const v=u.current;if(v){const w=v.getContext("2d");w&&w.clearRect(0,0,v.width,v.height)}h.current=!1,l(e,null)},C=v=>{const w=v.target.value;l(e,w||null)},k=v=>{d(v),l(e,null),h.current=!1};return s?n.jsx(U,{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:S,onPointerUp:R,onPointerLeave:R}),n.jsx("button",{type:"button",className:"fbre-signature__clear-btn",onClick:N,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};O("signature",_s);function _t(e){const t=e.offsetParent;if(!t)return 0;const i=Vt(t),o=i===document.documentElement?{left:0,right:window.innerWidth}:i.getBoundingClientRect(),r=t.getBoundingClientRect(),l=e.offsetWidth,s=r.left+l;if(s<=o.right-8)return 0;let a=-(s-o.right+8);return r.left+a<o.left+8&&(a=o.left+8-r.left),a}const de=({open:e,onClose:t,children:i,estimatedHeight:o=300})=>{const r=y.useRef(null);Ie(r,e,y.useCallback(()=>t(),[t]));const l=Me(r,e,o),[s,a]=y.useState(0);if(y.useLayoutEffect(()=>{if(!e||!r.current){a(0);return}a(_t(r.current))},[e]),y.useEffect(()=>{if(!e||!r.current)return;const d=()=>{r.current&&a(_t(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:i})},Ue=(e,t)=>new Date(e,t+1,0).getDate(),Cs=(e,t)=>new Date(e,t,1).getDay(),pe=(e,t,i)=>`${e}-${String(t+1).padStart(2,"0")}-${String(i).padStart(2,"0")}`,ws=e=>{const t=e.split("-");if(t.length!==3)return null;const i=parseInt(t[0],10),o=parseInt(t[1],10)-1,r=parseInt(t[2],10);return isNaN(i)||isNaN(o)||isNaN(r)?null:{year:i,month:o,day:r}},ke=(e,t)=>{const i=ws(e);if(!i)return e;const o=String(i.month+1).padStart(2,"0"),r=String(i.day).padStart(2,"0"),l=String(i.year);return t==="DD/MM/YYYY"?`${r}/${o}/${l}`:t==="YYYY-MM-DD"?`${l}-${o}-${r}`:`${o}/${r}/${l}`},Ee=e=>{const t=e.split(":");if(t.length!==2)return e;let i=parseInt(t[0],10);const o=t[1],r=i>=12?"PM":"AM";return i===0?i=12:i>12&&(i-=12),`${i}:${o} ${r}`},Ke=(e,t)=>{const i=e.indexOf("T");if(i===-1)return e;const o=e.substring(0,i),r=e.substring(i+1);return`${ke(o,t)} ${Ee(r)}`},Ns=(e,t,i)=>{let o=e;return i==="AM"&&o===12?o=0:i==="PM"&&o!==12&&(o+=12),`${String(o).padStart(2,"0")}:${String(t).padStart(2,"0")}`},Ss=e=>{const t=e.split(":");let i=parseInt(t[0],10);const o=parseInt(t[1],10),r=i>=12?"PM":"AM";return i===0?i=12:i>12&&(i-=12),{hour:i,minute:o,ampm:r}},ks=(e,t,i)=>e>=t&&e<=i,te=e=>{if(!e)return;if(!e.startsWith("today"))return e;const t=e==="today"?0:parseInt(e.slice(5),10),i=new Date;return i.setDate(i.getDate()+(isNaN(t)?0:t)),pe(i.getFullYear(),i.getMonth(),i.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:i,onSelect:o,rangeStart:r,rangeEnd:l,rangeHover:s})=>{const a=new Date,c=pe(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]=y.useState(d),[f,h]=y.useState(u),g=Ue(p,f),b=Cs(p,f),x=()=>{f===0?(m(p-1),h(11)):h(f-1)},j=()=>{f===11?(m(p+1),h(0)):h(f+1)},_=[],S=f===0?Ue(p-1,11):Ue(p,f-1);for(let v=b-1;v>=0;v--){const w=S-v,T=f===0?11:f-1,L=f===0?p-1:p;_.push({day:w,iso:pe(L,T,w),outside:!0})}for(let v=1;v<=g;v++)_.push({day:v,iso:pe(p,f,v),outside:!1});const R=42-_.length;for(let v=1;v<=R;v++){const w=f===11?0:f+1,T=f===11?p+1:p;_.push({day:v,iso:pe(T,w,v),outside:!0})}const N=s??l,C=r&&N&&r<=N?r:N,k=r&&N&&r<=N?N: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:x,children:"‹"}),n.jsxs("span",{className:"fbre-calendar__nav-title",children:[Rs(f)," ",p]}),n.jsx("button",{type:"button",className:"fbre-calendar__nav-btn",onClick:j,children:"›"})]}),n.jsx("div",{className:"fbre-calendar__weekdays",children:Ts.map(v=>n.jsx("div",{className:"fbre-calendar__weekday",children:v},v))}),n.jsx("div",{className:"fbre-calendar__grid",children:_.map((v,w)=>{const T=v.iso===e,L=v.iso===c,M=t&&v.iso<t||i&&v.iso>i,D=C&&k&&ks(v.iso,C,k),I=v.iso===C,P=v.iso===k,A=["fbre-calendar__day",v.outside&&"fbre-calendar__day--outside",T&&"fbre-calendar__day--selected",L&&"fbre-calendar__day--today",M&&"fbre-calendar__day--disabled",D&&"fbre-calendar__day--range",I&&"fbre-calendar__day--range-start",P&&"fbre-calendar__day--range-end"].filter(Boolean).join(" ");return n.jsx("div",{className:A,onClick:()=>!M&&!v.outside&&o(v.iso),children:v.day},w)})})]})},Ls=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&o===!1,p=typeof t=="string"?t:"";return n.jsx(U,{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(le,{})})]}),n.jsx(de,{open:a,onClose:()=>c(!1),children:n.jsx(De,{selectedDate:p,min:te(s.min),max:te(s.max),onSelect:m=>{l(e,m),c(!1)}})})]})})};O("date",Ls);const Ct=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const i=parseInt(t[0],10),o=parseInt(t[1],10);return isNaN(i)||isNaN(o)?null:i*60+o},He=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,Be=({value:e,min:t,max:i,step:o=15,onChange:r})=>{const l=y.useRef(null),s=y.useRef(null),a=e?Ss(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+=o)m.push(C);const f=["AM","PM"],h=y.useMemo(()=>Ct(t),[t]),g=y.useMemo(()=>Ct(i),[i]),b=h!==null||g!==null,x=(C,k)=>{const v=C*60+k;return!(h!==null&&v<h||g!==null&&v>g)},j=(C,k)=>{if(!b)return!1;const v=He(C,k);for(let w=0;w<60;w+=o)if(x(v,w))return!1;return!0},_=C=>{if(!b)return!1;const k=He(c,u);return!x(k,C)},S=C=>{if(!b)return!1;for(const k of p){const v=He(k,C);for(let w=0;w<60;w+=o)if(x(v,w))return!1}return!0},R=(C,k,v)=>{r(Ns(C,k,v))};y.useEffect(()=>{const C=k=>{if(!k)return;const v=k.querySelector(".fbre-time-selector__cell--selected");v&&v.scrollIntoView({block:"center",behavior:"instant"})};C(l.current),C(s.current)},[]);const N=(C,k,v)=>{let w=C;return k&&(w+=" fbre-time-selector__cell--selected"),v&&(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=j(C,u);return n.jsx("div",{className:N("fbre-time-selector__cell",C===c,k),onClick:k?void 0:()=>R(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:N("fbre-time-selector__cell",C===d,k),onClick:k?void 0:()=>R(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=S(C);return n.jsx("div",{className:N("fbre-time-selector__cell",C===u,k),onClick:k?void 0:()=>R(c,d,C),children:C},C)})})]})},Is=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1);if(!s)return null;const d=s.readOnly===!0,u=t!=null&&o===!1,p=typeof t=="string"?t:"";return n.jsx(U,{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(Xe,{})})]}),n.jsxs(de,{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)}})]})]})})};O("time",Is);const Ms=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(!1),[d,u]=y.useState("date");if(!s)return null;const p=s.readOnly===!0,m=t!=null&&o===!1,f=typeof t=="string"?t:"",h=f.indexOf("T"),g=h!==-1?f.substring(0,h):"",b=h!==-1?f.substring(h+1):"",x=()=>{u(g?"time":"date"),c(!0)},j=()=>{c(!1),u("date")},_=k=>{l(e,`${k}T${b||"12:00"}`),u("time")},S=k=>{const v=g||new Date().toISOString().substring(0,10);l(e,`${v}T${k}`)},R=()=>{u("date")},N=te(s.min&&s.min.includes("T")?s.min.split("T")[0]:s.min),C=te(s.max&&s.max.includes("T")?s.max.split("T")[0]:s.max);return n.jsx(U,{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:x,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.placeholder??"Select date & time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(le,{})})]}),n.jsx(de,{open:a,onClose:j,children:d==="date"?n.jsx(De,{selectedDate:g,min:N,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:R,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:j,children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:b||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:S})]})})]})})};O("dateTime",Ms);const Ds=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(null),[d,u]=y.useState();if(!s)return null;const p=t!=null&&o===!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=x=>{if(a==="start"){const j=h&&x>h?"":h;l(e,{start:x,end:j}),c(j?null:"end")}else if(a==="end"){const j=f&&x<f?x:f,_=x<j?j:x;l(e,{start:j||x,end:j?_:""}),j&&_&&c(null)}u(void 0)},b=a!==null;return n.jsx(U,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:b,error:p,errorMessages:p?r:void 0,children:()=>n.jsxs("div",{style:{position:"relative"},children:[n.jsxs("div",{className:"fbre-date-range__wrap",children:[n.jsx("div",{className:"fbre-date-range__field",children:n.jsxs("div",{className:"fbre-datetime__trigger",onClick:()=>c(a==="start"?null:"start"),children:[f?n.jsx("span",{className:"fbre-datetime__trigger-text",children: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(le,{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(le,{size:12})})]})})]}),n.jsx(de,{open:b,onClose:()=>{c(null),u(void 0)},children:n.jsx(De,{selectedDate:a==="start"?f:h,min:te(s.min),max:te(s.max),onSelect:g,rangeStart:f,rangeEnd:h,rangeHover:d})})]})})};O("dateRange",Ds);const Bs=({uuid:e})=>{const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(null);if(!s)return null;const d=t!=null&&o===!1,u=t&&typeof t=="object"&&"start"in t?t:null,p=(u==null?void 0:u.start)??"",m=(u==null?void 0:u.end)??"",f=b=>{if(a==="start"){const x=m&&b>m?"":m;l(e,{start:b,end:x})}else if(a==="end"){const x=p&&b<p?p:b;l(e,{start:p,end:x})}},h=()=>{c(null)},g=a!==null;return n.jsx(U,{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(Xe,{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(Xe,{size:12})})]})})]}),n.jsxs(de,{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})]})]})})};O("timeRange",Bs);const Os=({uuid:e})=>{var L,M;const{value:t,properties:i,valid:o,validationErrors:r,updateValue:l}=F(e),s=i,[a,c]=y.useState(null),[d,u]=y.useState("date");if(!s)return null;const p=t!=null&&o===!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 I=D.indexOf("T");return I!==-1?{date:D.substring(0,I),time:D.substring(I+1)}:{date:"",time:"12:00"}},b=f?g(f):{date:"",time:"12:00"},x=h?g(h):{date:"",time:"12:00"},j=a==="start"?b:x,_=(D,I)=>{const P=D&&I&&I<D?"":I;l(e,{start:D,end:P})},S=D=>{u((D==="start"?b:x).date?"time":"date"),c(D)},R=()=>{c(null),u("date")},N=D=>{const I=j.time||"12:00",P=`${D}T${I}`;a==="start"?_(P,h):_(f,P),u("time")},C=D=>{const I=j.date;if(!I)return;const P=`${I}T${D}`;a==="start"?_(P,h):_(f,P)},k=()=>{u("date")},v=a!==null,w=te((L=s.min)==null?void 0:L.split("T")[0]),T=te((M=s.max)==null?void 0:M.split("T")[0]);return n.jsx(U,{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:()=>S("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"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(le,{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:()=>S("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"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(le,{size:12})})]})})]}),n.jsx(de,{open:v,onClose:R,children:d==="date"?n.jsx(De,{selectedDate:j.date,min:w,max:T,onSelect:N}):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:R,children:n.jsx(Z,{size:12})})]}),n.jsx(Be,{value:j.time||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:C})]})})]})})};O("dateTimeRange",Os);const Ut=({uuid:e})=>{var u;const t=e.split(":")[0],i=parseInt(e.split(":")[1]),o=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[i])==null?void 0:h[o]}),l=B(p=>p.conditionResults[e]);if(!r)return null;const s=r.conditions&&"when"in r.conditions?r.conditions:void 0;if($.isHiddenByCondition(s,l))return null;const a=Nt(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(Bt.Provider,{value:r,children:n.jsx(a,{uuid:e})})})},Vs=({uuid:e})=>{const t=B(a=>{var c;return(c=a.components[e])==null?void 0:c.properties}),i=B(a=>{var c;return(c=a.components[e])==null?void 0:c.addedComponents}),[o,r]=y.useState(!0);if(!t)return null;const l=i??[],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${o?"":" collapsed"}`,onClick:()=>r(!o),"aria-label":"Toggle group",children:n.jsx(ve,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${o?"":" collapsed"}`,children:n.jsx("div",{className:"fbre-group__content",children:a.map(d=>n.jsx(Ut,{uuid:d.uuid},d.uuid))})})]},`${e}-${c}`))})};O("group",Vs);const $s=({uuid:e})=>{const t=B(f=>{var h;return(h=f.components[e])==null?void 0:h.properties}),i=B(f=>{var h;return(h=f.components[e])==null?void 0:h.addedComponents}),o=B(f=>f.addRepeaterIteration),r=B(f=>f.removeRepeaterIteration),[l,s]=y.useState(new Set([0]));if(!t)return null;const a=i??[],c=t.minIterations??1,d=()=>{const f=a.length;o(e),s(new Set([f]))},u=f=>{a.length<=c||(r(e,f),s(h=>{const g=new Set;for(const b of h)b<f?g.add(b):b>f&&g.add(b-1);return g}))},p=f=>{s(h=>{const g=new Set(h);return g.has(f)?g.delete(f):g.add(f),g})},m=["fbre-group","fbre-repeater",t.showBorder===!0&&"fbre-group--bordered",t.showBorder===!1&&"fbre-group--no-border"].filter(Boolean).join(" ");return n.jsxs("div",{className:m,children:[a.map((f,h)=>{const g=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(vn,{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(ve,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${!g&&t.collapsible?" collapsed":""}`,children:n.jsx("div",{className:"fbre-group__content",children:f.map(b=>n.jsx(Ut,{uuid:b.uuid},b.uuid))})})]},`${e}-${h}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:d,children:"Add another"})]})};O("repeater",$s);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:i})=>{var tt,nt,st,rt,ot,it,lt,at,ct,dt,ut;const o=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]=y.useState(a),[u,p]=y.useState(!!(o!=null&&o.summary&&e>=r)),m=((tt=o==null?void 0:o.navigation)==null?void 0:tt.transition)??"none",f=m!=="none",[h,g]=y.useState(null),[b,x]=y.useState(!1),[j,_]=y.useState("forward"),[S,R]=y.useState(!1),N=y.useRef(null);y.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),v=B(V=>{var q;return C?(q=V.screens[C])==null?void 0:q.nextButtonLabel:void 0}),w=B(V=>{var q;return C?(q=V.screens[C])==null?void 0:q.backButtonLabel:void 0}),T=y.useCallback(V=>{i&&i(V,s.getState().getFlowData())},[i,s]),L=y.useCallback(V=>{g(c),x(u),_(V),R(!0),N.current&&(N.current.scrollTop=0)},[c,u]),M=y.useCallback(()=>{R(!1),g(null)},[]),D=y.useCallback(()=>{if(!S)if(u)f&&L("back"),p(!1),T(c);else{const V=s.getState(),q=On(V,c);q!==c&&(f&&L("back"),d(q),T(q))}},[S,u,c,f,L,T,s]),I=y.useCallback(()=>{if(S)return;const V=s.getState(),q=Se(V,c);q!==null?(f&&L("forward"),d(q),T(q)):o!=null&&o.summary&&(f&&L("forward"),p(!0),T(c+1))},[S,c,o,f,L,T,s]),[P,A]=y.useState(!1),[z,J]=y.useState(null),X=y.useCallback(()=>{J(null);const V=t(s.getState().getFlowData());V&&typeof V.then=="function"&&(A(!0),V.then(()=>{A(!1)}).catch(q=>{A(!1),J(q instanceof Error?q.message:String(q))}))},[t,s]),ue=B(V=>Se(V,c)===null),E=((nt=o==null?void 0:o.theme)==null?void 0:nt.darkMode)??!1,H=((o==null?void 0:o.mode)??"standard")==="conversational";Mt(H&&!u,c,I),Dt(H&&!u,c,I);const W=((st=o==null?void 0:o.theme)==null?void 0:st.style)??"clean",et=((rt=o==null?void 0:o.controls)==null?void 0:rt.stepperStyle)??"default",Oe=et==="default"?As[W]??"dots":et,qt=((ot=o==null?void 0:o.controls)==null?void 0:ot.showStepper)!==!1&&Oe==="text",Ve={};(it=o==null?void 0:o.theme)!=null&&it.color&&(Ve["--fbre-theme-color"]=o.theme.color);const zt=()=>b?n.jsx(ht,{}):h!==null?n.jsx(Je,{screenIndex:h}):null,Yt=S?"fbre-screen-wrapper fbre-screen-wrapper--transitioning":"fbre-screen-wrapper";return n.jsxs("div",{className:"fbre-container","data-style":W,"data-mode":E?"dark":"light","data-form-mode":H?"conversational":void 0,"data-stepper":Oe!=="text"?Oe:void 0,"data-transition":f?m:void 0,style:Object.keys(Ve).length>0?Ve:void 0,children:[qt&&n.jsx(Mn,{current:c,total:r}),n.jsxs("div",{className:Yt,ref:N,children:[S&&n.jsx("div",{className:"fbre-screen-slot fbre-screen--exiting","data-direction":j,onAnimationEnd:M,children:zt()}),n.jsxs("div",{className:S?"fbre-screen-slot fbre-screen--entering":"fbre-screen-slot","data-direction":S?j:void 0,children:[!u&&n.jsx(Je,{screenIndex:c}),u&&n.jsx(ht,{})]})]}),z&&n.jsx("div",{className:"fbre-completion-error",children:z}),((lt=o==null?void 0:o.controls)==null?void 0:lt.show)!==!1&&l&&n.jsx(Dn,{screenIndex:c,maxScreenIndex:r-1,allowInvalidTransition:(at=o==null?void 0:o.navigation)==null?void 0:at.allowInvalidTransition,screenValidity:k,summaryEnabled:(o==null?void 0:o.summary)??!1,summaryActive:u,atMaxScreen:ue,nextButtonLabel:v,backButtonLabel:w,completionLoading:P,showStepper:(ct=o==null?void 0:o.controls)==null?void 0:ct.showStepper,stepperStyle:(dt=o==null?void 0:o.controls)==null?void 0:dt.stepperStyle,controlsLayout:(ut=o==null?void 0:o.controls)==null?void 0:ut.layout,nextScreen:I,prevScreen:D,onFlowComplete:X})]})},Ps=[],Us=()=>Q.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:i=>{e({externalContext:i})},updateComponentValue:(i,o)=>{var c,d;const r=t();if(i.includes(":")){const u=i.split(":"),p=u[0],m=parseInt(u[1]),f=parseInt(u[2]),h=r.components[p];if(!((d=(c=h==null?void 0:h.addedComponents)==null?void 0:c[m])!=null&&d[f]))return;h.addedComponents[m][f]={...h.addedComponents[m][f],value:o};const g=r.groupComponentMap[i]??i,b=Ge(e,t,g),x=ze(r,i,h.addedComponents[m][f]);e({components:{...r.components},conditionResults:b??r.conditionResults,validationErrors:x});return}const l=r.components[i];if(!l)return;if(l.type==="group"||l.type==="repeater"){e({components:{...r.components}});return}if(o===l.value){e({selectionTick:(t().selectionTick??0)+1});return}l.value=o;const s=Ge(e,t,i),a=ze(r,i,l);e({components:{...r.components},conditionResults:s??r.conditionResults,validationErrors:a})},addGroupIteration:i=>{const o=t(),r=o.components[i];if(!r||r.type!=="group"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l=r.components.map((s,a)=>{const c=ee(s);c.uuid=[i,r.addedComponents.length,a].join(":"),o.groupComponentMap[c.uuid]=s.uuid;const d=G(c);return c.valid=d.length===0,c});return r.addedComponents.push(l),e({components:{...o.components},groupComponentMap:{...o.groupComponentMap}}),r.addedComponents},addRepeaterIteration:i=>{const o=t(),r=o.components[i];if(!r||r.type!=="repeater"||!r.components)return;r.addedComponents||(r.addedComponents=[]);const l=r.components.map((s,a)=>{const c=ee(s);c.uuid=[i,r.addedComponents.length,a].join(":");const d=G(c);return c.valid=d.length===0,c});return r.addedComponents.push(l),e({components:{...o.components}}),r.addedComponents},removeRepeaterIteration:(i,o)=>{const r=t(),l=r.components[i];if(!(!l||l.type!=="repeater"||!l.addedComponents||l.addedComponents.length<=1)){l.addedComponents.splice(o,1);for(let s=o;s<l.addedComponents.length;s++)l.addedComponents[s].forEach((a,c)=>{a.uuid=[i,s,c].join(":")});e({components:{...r.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:i=>{const o=t();if(i!==0)return null;const r=o.screenOrder[0];return r?o.screens[r]:null},getScreenValidity:i=>{const o=t();if(i!==0)return!0;const r=o.screenOrder[0];return r?o.screenValidity[r]??!0:!0},getValidationErrors:i=>t().validationErrors[i]??Ps,evaluateFlowValidation:()=>{const i=t(),o=i.screenOrder[0];if(!o)return!0;const r=i.screens[o];if(!r)return!0;let l=!0;const s={components:i.components,groupComponentMap:i.groupComponentMap},a={...i.validationErrors};for(const d of r.components){const u=i.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 x=i.conditionResults[h.uuid]??!1;if(g.action==="show"&&!x||g.action==="hide"&&x)continue}const b=G(h,s);h.valid=b.length===0,a[h.uuid]=b,b.length>0&&(l=!1)}continue}const p=u.conditions&&"when"in u.conditions?u.conditions:void 0;if(p){const f=i.conditionResults[u.uuid]??!1;if(p.action==="show"&&!f||p.action==="hide"&&f)continue}const m=G(u,s);u.valid=m.length===0,a[u.uuid]=m,m.length>0&&(l=!1)}const c={...i.screenValidity,[o]:l};return e({components:{...i.components},validationErrors:a,screenValidity:c}),l},getMaxScreenCount:()=>0,getCalculationResult:i=>t().calculationResults[i]??null})),_e=(e,t)=>{const i={},o={},r={},l={},s={},a={},c=t.screen.uuid;for(const b of t.screen.components){const x=ee(b);if(i[x.uuid]=x,(x.type==="group"||x.type==="repeater")&&b.components){x.addedComponents||(x.addedComponents=[]);const _=b.components.map((S,R)=>{const N=ee(S);N.uuid=[x.uuid,0,R].join(":"),x.type==="group"&&(o[N.uuid]=S.uuid),r[S.uuid]=N.uuid;const C=K.getValidationConfig(N);return C&&C.rules&&C.rules.length>0&&fe(s,N.uuid,C),N});x.addedComponents.push(_)}const j=K.getValidationConfig(x);j&&j.rules&&j.rules.length>0&&fe(s,x.uuid,j)}for(const{targetUUID:b,config:x}of t.conditions)se(l,b,x,b===c?"screen":"component");if(t.previousData)for(const b of t.previousData){const x=i[b.uuid];x&&(x.value=b.value)}const d={components:i};for(const b of Object.keys(i)){const x=i[b];if(x.type==="group"||x.type==="repeater"){if(x.addedComponents)for(const _ of x.addedComponents)for(const S of _){const R=G(S,d);S.valid=R.length===0,R.length>0&&(a[S.uuid]=R)}continue}if(!K.getValidationConfig(x))continue;const j=G(x,d);x.valid=j.length===0,j.length>0&&(a[b]=j)}const u={},p={components:i},m=new Set;for(const b of Object.values(l))for(const x of b)m.has(x.target)||(m.add(x.target),u[x.target]=Re(p,x.config));let f=!0;for(const b of t.screen.components){const x=i[b.uuid];if(x)if((x.type==="group"||x.type==="repeater")&&x.addedComponents)for(const j of x.addedComponents){for(const _ of j)if(!_.valid){f=!1;break}if(!f)break}else x.valid===!1&&(f=!1)}const g=t.screen.components.some(b=>b.type==="computed"||(b.type==="group"||b.type==="repeater")&&(b.components??[]).some(x=>x.type==="computed"))?"This screen uses a computed component, which is not supported in server-driven (session) mode.":"";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:i,groupComponentMap:o,templateComponentMap:r,conditionsByDependency:l,conditionResults:u,validationErrors:a,validationsByDependency:s,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:t.sessionId,navigation:t.navigation,loading:!1,error:g,externalContext:t.context??{},config:t.config??{}})},qe=e=>{const t=e.getState(),i=t.screenOrder[0];if(!i)return[];const o=t.screens[i];if(!o)return[];const r=[];for(const l of o.components){const s=t.components[l.uuid];if(!s||we(s.type))continue;const a={uuid:s.uuid,type:s.type,value:s.value};"label"in s.properties&&typeof s.properties.label=="string"&&(a.label=s.properties.label),(s.type==="group"||s.type==="repeater")&&s.addedComponents&&(a.components=s.addedComponents.map(c=>c.filter(d=>!we(d.type)).map(d=>({uuid:d.uuid,type:d.type,value:d.value})))),r.push(a)}return r},Hs=6e4,qs=({sessionEndpoint:e,flowId:t,apiKey:i,mode:o,theme:r,context:l,onFlowComplete:s,onScreenChange:a})=>{const c=y.useRef(null);c.current||(c.current=Us());const d=c.current,u=Q.useStore(d,E=>E.loading),p=Q.useStore(d,E=>E.error),m=Q.useStore(d,E=>E.navigation),f=Q.useStore(d,E=>E.config),h=Q.useStore(d,E=>{var Y;return(Y=E.config)==null?void 0:Y.mode}),g=Q.useStore(d,E=>E.screenOrder),b=Q.useStore(d,E=>E.screens),[x,j]=y.useState(""),_=y.useRef(null),S=y.useRef(Date.now()),R=y.useMemo(()=>({apiEndpoint:e,apiKey:i}),[e,i]),N=y.useCallback(E=>{j(E),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>j(""),8e3)},[]),C=y.useCallback(()=>{j(""),_.current&&(clearTimeout(_.current),_.current=null)},[]),k=y.useCallback(async()=>{d.setState({loading:!0,error:""});try{const E=await fs(R,t,l);_e(d,E)}catch(E){d.setState({loading:!1,error:E.message})}},[t,e,i,l]);y.useEffect(()=>{k()},[k]),y.useEffect(()=>{const E=async()=>{if(document.visibilityState!=="visible")return;const Y=d.getState();if(!(!Y.sessionId||Date.now()-S.current<Hs))try{const W=await vs(R,Y.sessionId);_e(d,W)}catch(W){W instanceof he&&W.status===404&&d.setState({loading:!1,error:"Session expired. Please start over.",screenOrder:[],screens:{}})}};return document.addEventListener("visibilitychange",E),()=>document.removeEventListener("visibilitychange",E)},[e,i]);const v=y.useCallback(async()=>{const E=d.getState();if(!(E.loading||!E.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),C();try{const H=qe(d),W=await ms(R,E.sessionId,H);_e(d,W),S.current=Date.now(),a==null||a(W.navigation.screenNumber)}catch(H){d.setState({loading:!1}),N(H.message)}}},[R,d,a,N,C]),w=y.useCallback(async()=>{const E=d.getState();if(!E.loading){d.setState({loading:!0}),d.getState().clearError(),C();try{const Y=qe(d),H=await hs(R,E.sessionId,Y);_e(d,H),S.current=Date.now(),a==null||a(H.navigation.screenNumber)}catch(Y){d.setState({loading:!1}),N(Y.message)}}},[R,d,a,N,C]),T=y.useCallback(async()=>{const E=d.getState();if(!(E.loading||!E.evaluateFlowValidation())){d.setState({loading:!0}),d.getState().clearError(),C();try{const H=qe(d),W=await bs(R,E.sessionId,H);S.current=Date.now(),s(W)}catch(H){d.setState({loading:!1}),N(H.message)}}},[R,d,s,N,C]),L={...f==null?void 0:f.theme,...r},D=(o??h??"standard")==="conversational",I=D&&!m.isLastScreen;Mt(I,0,v),Dt(I,0,v);const P=L.darkMode??!1,A={};L.color&&(A["--fbre-theme-color"]=L.color);const z=g[0],J=z?b[z]:void 0,X=J==null?void 0:J.nextButtonLabel,ue=J==null?void 0:J.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":L.style??"clean","data-mode":P?"dark":"light","data-form-mode":D?"conversational":void 0,style:Object.keys(A).length>0?A:void 0,children:[n.jsx("div",{className:"fbre-screen-wrapper",children:n.jsx(Je,{screenIndex:0})}),n.jsx(zs,{navigation:m,loading:u,onPrev:w,onNext:v,onComplete:T,nextButtonLabel:X,backButtonLabel:ue}),n.jsxs("div",{className:`fbre-toast${x?" visible":""}`,children:[n.jsx("span",{children:x}),n.jsx("button",{type:"button",className:"fbre-toast__close",onClick:C,"aria-label":"Dismiss",children:"×"})]})]})})},zs=({navigation:e,loading:t,onPrev:i,onNext:o,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:i,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:o,disabled:t,children:t?"Loading...":l||"Next"})})]});function Ys(e,t,i,o,r){return!t&&!i&&!o&&!r?e:{...e,...r&&{mode:r},...t&&{theme:{...e.theme,...t}},...i&&{navigation:{...e.navigation,...i}},...o&&{controls:{...e.controls,...o}}}}const Ht=({flow:e,data:t,mode:i,theme:o,navigation:r,controls:l,screenIndex:s,context:a,storeRef:c,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p,apiCtx:m})=>{const f=y.useRef(null);f.current||(f.current=on(),f.current.getState().loadFlow(e,t,a)),c&&(c.current=f.current),y.useEffect(()=>{f.current&&f.current.getState().loadFlow(e,t,a)},[e.uuid]),y.useEffect(()=>{if(f.current){const b=f.current.getState(),x=Ys(b.config,o,r,l,i);x!==b.config&&f.current.setState({config:x})}},[i,o,r,l]);const h=a?JSON.stringify(a):"";y.useEffect(()=>{f.current&&a&&f.current.getState().updateContext(a)},[h]);const g=n.jsx(Te.Provider,{value:f.current,children:n.jsx(Fs,{screenIndex:s??0,onFlowComplete:d,onScreenChange:u,onScreenValidationChange:p})});return m?n.jsx(At.Provider,{value:m,children:g}):g},Ws=({flowId:e,apiEndpoint:t,apiKey:i,data:o,mode:r,theme:l,navigation:s,controls:a,screenIndex:c,context:d,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f})=>{const[h,g]=y.useState(null),[b,x]=y.useState(""),[j,_]=y.useState(null);return y.useEffect(()=>{g(null),x("");const S={apiEndpoint:t,apiKey:i};ds(S,e).then(R=>{g(R.data),_({config:S,flowId:R.id,flowVersionId:R.versionId,tenantId:R.tenantId})}).catch(R=>x(R.message))},[e,t,i]),b?n.jsx("div",{className:"fbre-container",children:n.jsxs("div",{className:"fbre-remote-error",children:[n.jsx("p",{children:"Failed to load form"}),n.jsx("p",{className:"fbre-remote-error__detail",children:b})]})}):!h||!j?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(Ht,{flow:h,data:o,mode:r,theme:l,navigation:s,controls:a,screenIndex:c,context:d,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f,apiCtx:j})},Gs=e=>"sessionEndpoint"in e?n.jsx(qs,{...e}):"flowId"in e&&e.flowId?n.jsx(Ws,{...e}):n.jsx(Ht,{...e});exports.ApiError=he;exports.FBRE=Gs;exports.TimeoutError=Pt;exports.addFBREEventListener=os;exports.removeFBREEventListener=is;exports.useFBREApi=Ft;exports.useFBREStore=B;exports.useFBREStoreApi=be;
|