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