@sonata-innovations/fiber-fbre 3.2.1 → 3.4.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("react"),ee=require("zustand"),Z=require("@sonata-innovations/fiber-types"),P=require("@sonata-innovations/fiber-shared"),nn=require("react-dom"),Tt=new Map,$=(e,t)=>{Tt.set(e,t)},It=e=>Tt.get(e),Te=e=>Z.DISPLAY_ONLY_TYPES.has(e),rn=(e,t)=>{var o,a,s,i;if(t.includes(":")){const r=t.split(":"),l=e.components[r[0]];return(s=(a=(o=l==null?void 0:l.addedComponents)==null?void 0:o[parseInt(r[1])])==null?void 0:a[parseInt(r[2])])==null?void 0:s.value}return(i=e.components[t])==null?void 0:i.value},J=(e,t)=>{const o=Z.getValidationConfig(e);return!o||!o.rules||o.rules.length===0?[]:P.validateValue(e.value,o,t?a=>rn(t,a):void 0)},sn=e=>{const t=Z.getValidationConfig(e);return!t||!t.rules?!1:t.rules.some(o=>o.type==="required")},ne=e=>{var a;const t={...e};if("options"in t.properties&&Array.isArray(t.properties.options)&&(t.properties={...t.properties,options:Z.normalizeOptions(t.properties.options)}),e.type==="computed"?(t.value=null,t.valid=!0):!Te(e.type)&&e.type!=="group"&&e.type!=="repeater"&&(t.value=null,t.valid=!sn(e)),(e.type==="checkbox"||e.type==="dropDownMulti")&&(t.value=[]),["yesNo","radio","cardSelect","dropDown"].includes(e.type)){const s=e.properties??{},i=s.defaultValue;if(e.type==="yesNo")(i==="yes"||i==="no")&&(t.value=i,t.valid=!0);else{const l=(Array.isArray(s.options)?s.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"&&((a=e.properties)!=null&&a.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},be=(e,t,o)=>{var a;for(const s of o.rules)if(s.type==="matchesField"&&((a=s.params)!=null&&a.field)){const i=s.params.field;e[i]||(e[i]=[]),e[i].push({target:t,config:o})}},Lt=(e,t)=>{var o,a;if(t.includes(":")){const s=t.split(":"),i=e[s[0]];return(a=(o=i==null?void 0:i.addedComponents)==null?void 0:o[parseInt(s[1])])==null?void 0:a[parseInt(s[2])]}return e[t]},Je=(e,t,o)=>{const a={components:e.components,groupComponentMap:e.groupComponentMap},s=J(o,a);o.valid=s.length===0;const i={...e.validationErrors,[t]:s},r=e.validationsByDependency[t];if(r)for(const l of r){const d=Lt(e.components,l.target);if(d){const c=J(d,a);d.valid=c.length===0,i[l.target]=c}}return i},ie=(e,t)=>{const o=e.screens[t];return o?!o.components.some(s=>{var l;const i=e.components[s.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 r=i.conditions&&"when"in i.conditions?i.conditions:void 0;return P.isHiddenByCondition(r,e.conditionResults[i.uuid])?!1:i&&"valid"in i&&!i.valid}):!0};function on(e){const t={};for(const o of e){const a=P.extractFormulaReferences(o.formula);for(const s of a)t[s]||(t[s]=[]),t[s].includes(o.uuid)||t[s].push(o.uuid)}return t}function Mt(e,t){return{resolveValue:o=>{if(o in t)return t[o];const a=ce(e,o);if(!a)return null;const s=a.value;if(s==null||s==="")return null;const i=Number(s);return isNaN(i)?null:i},resolveOptionMetadata:(o,a)=>{const s=ce(e,o);if(!s)return null;const i=s.value;if(!i)return null;const r="options"in s.properties?s.properties.options:void 0;if(!Array.isArray(r))return null;const l=r.find(u=>u.value===i||u.label===i);if(!(l!=null&&l.metadata))return null;const d=l.metadata[a];if(d==null)return null;const c=Number(d);return isNaN(c)?null:c},resolveRepeaterValues:o=>{for(const a of Object.keys(e.components)){const s=e.components[a];if(s.type!=="repeater"||!s.addedComponents||!s.components)continue;const i=s.components.findIndex(l=>l.uuid===o);if(i===-1)continue;const r=[];for(const l of s.addedComponents){const d=l[i];if(!d)continue;const c=d.value;if(c==null||c==="")continue;const u=Number(c);isNaN(u)||r.push(u)}return r.length>0?r:null}return null}}}function Qe(e){const t=e.calculations??[];if(t.length===0)return{};const o=P.topologicalSortCalculations(t),a={},s=Mt(e,a);for(const i of o)a[i.uuid]=P.evaluateFormula(i.formula,s);return a}function ze(e,t){const o=e.calculationsByDependency,a=e.calculations??[];if(a.length===0||!o)return null;const s=new Set,i=[t];for(;i.length>0;){const u=i.shift(),p=o[u];if(p)for(const m of p)s.has(m)||(s.add(m),i.push(m))}if(s.size===0)return null;const r=P.topologicalSortCalculations(a),l={...e.calculationResults},d=Mt(e,l);let c=!1;for(const u of r)if(s.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 an(e){const t={},o=a=>{var i;if(a.type!=="computed"||!((i=a.properties)!=null&&i.formula))return;const s=P.extractFormulaReferences(a.properties.formula);for(const r of s)t[r]||(t[r]=[]),t[r].includes(a.uuid)||t[r].push(a.uuid)};for(const a of Object.values(e))if(o(a),(a.type==="repeater"||a.type==="group")&&a.components)for(const s of a.components)o(s);return t}function Bt(e,t,o,a){var d,c;const s=e.components[o],i=((d=s==null?void 0:s.components)==null?void 0:d.map(u=>u.uuid))??[],r=(c=s==null?void 0:s.addedComponents)==null?void 0:c[a],l=new Map;if(r)for(let u=0;u<r.length;u++){const p=i[u];p&&l.set(p,r[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=ce(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)??ce(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 Ie(e,t){return{resolveValue:o=>{if(o in t)return t[o];const a=ce(e,o);if(!a)return null;const s=a.value;if(s==null||s==="")return null;const i=Number(s);return isNaN(i)?null:i},resolveOptionMetadata:(o,a)=>{const s=ce(e,o);if(!s)return null;const i=s.value;if(!i)return null;const r="options"in s.properties?s.properties.options:void 0;if(!Array.isArray(r))return null;const l=r.find(u=>u.value===i||u.label===i);if(!(l!=null&&l.metadata))return null;const d=l.metadata[a];if(d==null)return null;const c=Number(d);return isNaN(c)?null:c},resolveRepeaterValues:o=>{for(const a of Object.keys(e.components)){const s=e.components[a];if(s.type!=="repeater"||!s.addedComponents||!s.components)continue;const i=s.components.findIndex(l=>l.uuid===o);if(i===-1)continue;const r=[];for(const l of s.addedComponents){const d=l[i];if(!d)continue;const c=d.value;if(c==null||c==="")continue;const u=Number(c);isNaN(u)||r.push(u)}return r.length>0?r:null}return null}}}function Ze(e){var o,a;const t=e.calculationResults??{};for(const s of Object.values(e.components))if(s.type==="computed"&&((o=s.properties)!=null&&o.formula)){const i=Ie(e,t),r=P.evaluateFormula(s.properties.formula,i);s.value=r}for(const s of Object.values(e.components))if((s.type==="repeater"||s.type==="group")&&s.addedComponents&&s.components)for(let i=0;i<s.addedComponents.length;i++){const r=s.addedComponents[i];for(let l=0;l<r.length;l++){const d=r[l],c=s.components[l];if((c==null?void 0:c.type)==="computed"&&((a=c.properties)!=null&&a.formula)){const u=s.type==="repeater"?Bt(e,t,s.uuid,i):Ie(e,t),p=P.evaluateFormula(c.properties.formula,u);d.value=p}}}}function ln(e,t){var r,l;const o=e.computedByDependency;if(!o)return!1;const a=o[t];if(!a||a.length===0)return!1;const s=e.calculationResults??{};let i=!1;for(const d of a){const c=e.components[d];if(c&&c.type==="computed"&&((r=c.properties)!=null&&r.formula)){const u=Ie(e,s),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"?Bt(e,s,u.uuid,f):Ie(e,s),b=P.evaluateFormula(m.properties.formula,y);v.value!==b&&(u.addedComponents[f][p]={...v,value:b},i=!0)}}}return i}const Re=(e,t)=>{for(const o of e.screenOrder)if(e.screens[o].components.some(s=>s.uuid===t))return o;return null},cn=(e,t)=>{if(!t.includes(":"))return null;const o=t.split(":");if(o.length!==3)return null;const a=o[0],s=parseInt(o[2]),i=e.components[a];if(!i||i.type!=="repeater"||!i.components)return null;const r=i.components[s];return(r==null?void 0:r.uuid)??null},gt=(e,t,o,a,s)=>{const i=t(),r=i.groupComponentMap[o]??o,l=et(e,t,r),d=Je(i,o,a),c=Re(i,s),u={components:{...i.components},validationErrors:d};if(l&&(u.conditionResults=l),c){const b={...i,...u};u.screenValidity={...i.screenValidity,[c]:ie(b,c)}}const p={...i,...u},m=o.includes(":")?cn(p,o):null,f=[],v=b=>{if(ln(p,b)){const _=p.computedByDependency[b]??[];for(const w of _)f.includes(w)||(f.push(w),v(w))}};v(r),m&&m!==r&&v(m);let y=ze(p,r);if(m&&m!==r){const b=y?{...p,calculationResults:y}:p,_=ze(b,m);_&&(y=_)}for(const b of f){const _=y?{...p,calculationResults:y}:p,w=ze(_,b);w&&(y=w)}y&&(u.calculationResults=y),e(u)},dn=(e,t)=>({updateComponentValue:(o,a)=>{var r,l;const s=t();if(o.includes(":")){const d=o.split(":"),c=d[0],u=parseInt(d[1]),p=parseInt(d[2]),m=s.components[c];if(!((l=(r=m==null?void 0:m.addedComponents)==null?void 0:r[u])!=null&&l[p]))return;const f=m.addedComponents[u][p].value!==a;if(m.addedComponents[u][p]={...m.addedComponents[u][p],value:a},f){gt(e,t,o,m.addedComponents[u][p],c);return}e({components:{...s.components}});return}const i=s.components[o];if(i){if(i.type==="group"||i.type==="repeater"){e({components:{...s.components}});return}if(a===i.value){e({selectionTick:t().selectionTick+1});return}i.value=a,gt(e,t,o,i,o)}},addGroupIteration:o=>{const a=t(),s=a.components[o];if(!s||s.type!=="group"||!s.components)return;s.addedComponents||(s.addedComponents=[]);const i={...a.conditionsByDependency},r=s.components.map((c,u)=>{const p=ne(c);if(p.uuid=[o,s.addedComponents.length,u].join(":"),a.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,ae(i,p.uuid,f,"component"))}const m=J(p);return p.valid=m.length===0,p});s.addedComponents.push(r);const l=Re(a,o),d={...a.screenValidity};return l&&(d[l]=ie({...a},l)),e({components:{...a.components},groupComponentMap:{...a.groupComponentMap},conditionsByDependency:i,screenValidity:d}),s.addedComponents},addRepeaterIteration:o=>{const a=t(),s=a.components[o];if(!s||s.type!=="repeater"||!s.components)return;s.addedComponents||(s.addedComponents=[]);const i={...a.conditionsByDependency},r=s.components.map((p,m)=>{const f=ne(p);if(f.uuid=[o,s.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,ae(i,f.uuid,y,"component"))}const v=J(f);return f.valid=v.length===0,f});s.addedComponents.push(r);const l=Re(a,o),d={...a.screenValidity};l&&(d[l]=ie({...a},l));const c={...a,components:{...a.components}};Ze(c);const u=Qe(c);return e({components:{...a.components},conditionsByDependency:i,screenValidity:d,calculationResults:u}),s.addedComponents},removeRepeaterIteration:(o,a)=>{var y;const s=t(),i=s.components[o];if(!i||i.type!=="repeater"||!i.addedComponents)return;const r=((y=i.properties)==null?void 0:y.minIterations)??1;if(i.addedComponents.length<=r)return;const l=i.addedComponents[a],d=new Set(l.map(b=>b.uuid));i.addedComponents.splice(a,1);const c={...s.conditionsByDependency},u={...s.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=a;b<i.addedComponents.length;b++)i.addedComponents[b].forEach((_,w)=>{const C=_.uuid,E=[o,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=Re(s,o),m={...s.screenValidity};p&&(m[p]=ie({...s},p));const f={...s,components:{...s.components}};Ze(f);const v=Qe(f);e({components:{...s.components},conditionsByDependency:c,validationErrors:u,screenValidity:m,calculationResults:v})}}),ce=(e,t)=>Lt(e.components,t),ae=(e,t,o,a)=>{const s=new Set;for(const r of o.when.rules)s.add(r.source);const i={target:t,type:a,config:o};for(const r of s)e[r]||(e[r]=[]),e[r].push(i)},un=(e,t)=>{var o,a;return t.includes(":")?(o=ce(e,t))==null?void 0:o.value:(a=e.components[t])==null?void 0:a.value},Oe=(e,t)=>P.evaluateConditionConfig(t,(o,a)=>(a==null?void 0:a.sourceType)==="context"?e.externalContext[a.source]:un(e,o)),et=(e,t,o)=>{const a=t(),s=a.conditionsByDependency[o];if(!s||s.length===0)return null;let i=!1;const r={...a.conditionResults};for(const l of s){const d=Oe(a,l.config);r[l.target]!==d&&(r[l.target]=d,i=!0)}return i?r:null},pn=e=>{const t={},o=new Set;for(const a of Object.values(e.conditionsByDependency))for(const s of a)o.has(s.target)||(o.add(s.target),t[s.target]=Oe(e,s.config));return t},Ke=e=>{if(!e||Te(e.type))return null;const t="label"in e.properties?e.properties.label:"",o={uuid:e.uuid,type:e.type,value:e.value};return t&&(o.label=t),o},yt=e=>{if(e.conditions&&"when"in e.conditions)return e.conditions},fn=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},o=s=>{const i=e.screens[s];if(!i)return!1;const r=i.conditions&&"when"in i.conditions?i.conditions:void 0;return P.isHiddenByCondition(r,e.conditionResults[s])};t.screens=e.screenOrder.filter(s=>!o(s)).map(s=>{const i=e.screens[s],r={uuid:s,components:i.components.map(l=>{const d=e.components[l.uuid];if(!d)return null;const c=yt(d);if(P.isHiddenByCondition(c,e.conditionResults[l.uuid]))return null;if((d.type==="group"||d.type==="repeater")&&d.addedComponents){const u=Ke(d);return u?{...u,components:d.addedComponents.map(p=>p.filter(m=>{const f=yt(m);return!P.isHiddenByCondition(f,e.conditionResults[m.uuid])}).map(m=>Ke(m)).filter(m=>m!==null))}:null}return Ke(d)}).filter(l=>l!==null)};return i.label&&(r.label=i.label),r});const a=e.calculations??[];if(a.length>0){const s=e.calculationResults??{};t.calculations=a.map(i=>{const r=s[i.uuid]??null,l={uuid:i.uuid,label:i.label,value:r};return r!==null&&(l.formattedValue=P.formatCalculationResult(r,i.format,i.decimalPlaces,i.currencySymbol)),l})}return t},Ve=g.createContext(null);function A(e){const t=g.useContext(Ve);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return ee.useStore(t,e)}const ye=()=>{const e=g.useContext(Ve);if(!e)throw new Error("useFBREStoreApi must be used within an FBRE provider");return e},_e=e=>!e||Object.keys(e).length===0?null:"when"in e?e:null,mn=[],hn=()=>ee.createStore((e,t)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,loadFlow:(o,a,s)=>{const i={},r=[],l={},d={},c={},u={},p={},m={},f={};o.screens.forEach(S=>{const R=_e(S.conditions),I=R?{...S,conditions:R}:{...S};i[S.uuid]=I,r.push(S.uuid),R&&ae(u,S.uuid,R,"screen"),S.components.forEach(x=>{const h=_e(x.conditions),j=ne(x);h&&(j.conditions=h),l[x.uuid]=j,h&&ae(u,x.uuid,h,"component");const N=Z.getValidationConfig(j);if(N&&be(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 W=x.components.map((G,oe)=>{const T=ne(G);T.uuid=[x.uuid,M.addedComponents.length,oe].join(":"),B&&B[F]&&G.uuid in B[F]&&(T.value=B[F][G.uuid]),x.type==="group"&&(d[T.uuid]=G.uuid),F===0&&(c[G.uuid]=T.uuid);const z=_e(T.conditions);z&&(T.conditions=z,ae(u,T.uuid,z,"component"));const Y=Z.getValidationConfig(T);Y&&be(p,T.uuid,Y);const X=J(T);return T.valid=X.length===0,X.length>0&&(m[T.uuid]=X),T});M.addedComponents.push(W)}}})}),a&&a.screens.forEach(S=>{const R=r.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=o.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=ne(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=_e(O.conditions);F&&(O.conditions=F,ae(u,O.uuid,F,"component"));const W=Z.getValidationConfig(O);W&&be(p,O.uuid,W);const G=J(O);return O.valid=G.length===0,G.length>0&&(m[O.uuid]=G),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")&&Z.getValidationConfig(R)&&!(S in m)){const I=J(R);R.valid=I.length===0,I.length>0&&(m[S]=I)}}const v={...t(),externalContext:s??{},screens:i,screenOrder:r,components:l,groupComponentMap:d,templateComponentMap:c,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},y=pn(v);v.conditionResults=y,r.forEach(S=>{f[S]=ie(v,S)});const b=an(l),_={...v,computedByDependency:b,calculationResults:{},screenValidity:f};Ze(_);const w=o.calculations??[],C=on(w),E={..._,calculations:w},k=Qe(E);e({flowUUID:o.uuid,metadata:o.metadata,config:o.config??{},externalContext:s??{},screens:i,screenOrder:r,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:o=>{const a=t(),s=a.externalContext,i=[];for(const c of Object.keys(o))s[c]!==o[c]&&i.push(c);for(const c of Object.keys(s))!(c in o)&&!i.includes(c)&&i.push(c);if(i.length===0)return;const r={...a.conditionResults};let l=!1;const d=new Set;for(const c of i){const u=a.conditionsByDependency[c];if(!(!u||u.length===0))for(const p of u){if(d.has(p.target))continue;d.add(p.target);const m={...a,externalContext:o},f=Oe(m,p.config);r[p.target]!==f&&(r[p.target]=f,l=!0)}}if(l){const c={...a,conditionResults:r},u={};for(const p of a.screenOrder)u[p]=ie(c,p);e({externalContext:o,conditionResults:r,screenValidity:u})}else e({externalContext:o})},...dn(e,t),getFlowData:()=>fn(t()),getScreenByIndex:o=>{const a=t();return o<0||o>=a.screenOrder.length?null:a.screens[a.screenOrder[o]]},getScreenValidity:o=>{const a=t();return o<0||o>=a.screenOrder.length?!0:a.screenValidity[a.screenOrder[o]]??!0},getValidationErrors:o=>t().validationErrors[o]??mn,evaluateFlowValidation:()=>{const o=t(),a={};let s=!0;return o.screenOrder.forEach(i=>{const r=ie(o,i);a[i]=r,r||(s=!1)}),e({screenValidity:a}),s},getMaxScreenCount:()=>t().screenOrder.length-1,getCalculationResult:o=>t().calculationResults[o]??null})),bn=({uuid:e})=>{var l;const t=A(d=>d.components[e]),o=A(d=>d.conditionResults[e]);if(!t)return null;const a=t.conditions&&"when"in t.conditions?t.conditions:void 0;if(P.isHiddenByCondition(a,o))return null;const s=It(t.type);if(!s)return console.warn(`FBRE: No renderer for component type "${t.type}"`),null;const i=(l=t.properties)==null?void 0:l.width,r=i&&i!=="full"?`fbre-component fbre-width-${i}`:"fbre-component";return n.jsx("div",{className:r,"data-uuid":e,children:n.jsx(s,{uuid:e})})},tt=({screenIndex:e})=>{const t=A(o=>{const a=o.screenOrder[e];return a?o.screens[a]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(o=>n.jsx(bn,{uuid:o.uuid},o.uuid))}):null},te=({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"})}),pe=({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"})]}),nt=({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"})]}),je=({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"})}),vn=({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"})}),xn=({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"})}),gn=({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"})}),yn=({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"})}),jn=({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"})}),st=({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"})}),_n=({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"})}),wn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("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"})]}),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("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("polyline",{points:"9,12 11.5,14.5 16,9.5"})]}),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:"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"})]}),kn=({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"})]}),Sn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"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"})]}),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:"M3 11l18-5v12L3 13v-2z"}),n.jsx("path",{d:"M11.6 16.8a3 3 0 11-5.8-1.6"})]}),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:"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"})]}),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:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),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("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0110 0v4"})]}),Ot=({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"})}),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:"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"})]}),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("path",{d:"M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z"})}),Mn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polygon",{points:"13,2 3,14 12,14 11,22 21,10 12,10 13,2"})}),Bn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M12 20h9"}),n.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 013 3L7 19l-4 1 1-4L16.5 3.5z"})]}),On=({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"})]}),Vn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"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"})]}),An=({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"})}),$n=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("rect",{x:"12",y:"1",width:"15.56",height:"15.56",rx:"2",transform:"rotate(45 12 1)"})}),We={info:wn,check:Cn,warning:Nn,question:On,lightbulb:Sn,megaphone:En,bell:Rn,shield:Dn,lock:Tn,heart:Ot,flag:In,bookmark:Ln,zap:Mn,pencil:Bn,star:st},Pn={star:st,heart:Ot,thumbsUp:Vn,circle:An,diamond:$n},we=({position:e,screenIndex:t,maxScreenIndex:o,allowInvalidTransition:a,screenValidity:s,summaryEnabled:i,summaryActive:r,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&&!r||v;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--secondary",disabled:C,onClick:m,children:[n.jsx(gn,{}),c||"Back"]})}const y=i?l&&r:l,b=i?l?r?"Done":"Review":"Next":l?"Done":"Next";if(o===0){const C=i?r?"Complete":"Review":"Complete",E=v||!s;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:E,onClick:()=>{i&&!r?p():f()},children:[d||C,v?n.jsx("span",{className:"fbre-btn__spinner"}):n.jsx(te,{size:16})]})}const _=v||!a&&!s||b==="Done"&&!s,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(te,{size:16}):n.jsx(yn,{})]})},Fn=({current:e,total:t,stepperStyle:o})=>{if(t<=1)return null;const a=t>1?e/(t-1)*100:100,i=!!o&&o!=="default"||t<=6;return n.jsxs(n.Fragment,{children:[i&&n.jsx("div",{className:"fbre-stepper fbre-stepper--dots",children:Array.from({length:t},(r,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:`${a}%`}})}),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:`${a}%`}})})]})},Un=({current:e,total:t})=>t<=1?null:n.jsxs("div",{className:"fbre-stepper-text",children:["Step ",e+1," of ",t]}),Hn=e=>{const t=e.controlsLayout??"default",a=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text"&&e.maxScreenIndex>0,s=e.screenIndex>0||e.summaryActive,i=s?2:1,r=a?n.jsx(Fn,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):null;if(t==="default"){const l=!s&&!a;return n.jsxs("div",{className:"fbre-controls fbre-controls--default","data-button-count":i,"data-solo":l?"true":void 0,children:[s?n.jsx(we,{position:"back",...e}):n.jsx("div",{}),r??n.jsx("div",{}),n.jsx(we,{position:"next",...e})]})}return n.jsxs("div",{className:`fbre-controls fbre-controls--${t}`,"data-button-count":i,children:[r&&n.jsx("div",{className:"fbre-controls__stepper",children:r}),n.jsxs("div",{className:"fbre-controls__row",children:[s&&n.jsx(we,{position:"back",...e}),n.jsx(we,{position:"next",...e})]})]})},Vt=({component:e})=>{const{uuid:t,label:o,type:a,value:s,components:i}=e,r=()=>{if(s!=null)switch(a){case"fileUpload":return s.name;case"inputText":case"inputTextArea":case"inputNumber":case"dropDown":case"radio":case"rating":case"slider":return s.toString();case"computed":return typeof s=="number"?s.toString():"—";case"toggleSwitch":return s?"Yes":"No";case"checkbox":case"dropDownMulti":return s.length===0?"No options selected":s.join(", ")}return"No response given"};if(a==="signature"&&s){const c=typeof s=="string"&&s.startsWith("data:");return n.jsxs("div",{className:"fbre-summary__item",children:[n.jsx("div",{className:"fbre-summary__item-label",children:o}),n.jsx("div",{className:"fbre-summary__item-value",children:c?n.jsx("img",{src:s,alt:"Signature",style:{maxWidth:"100%",maxHeight:80}}):n.jsx("span",{style:{fontFamily:'"Brush Script MT", "Segoe Script", "Dancing Script", cursive',fontSize:24},children:s})})]})}const l=()=>i?i.map((c,u)=>n.jsx("div",{children:c.map(p=>n.jsx(Vt,{component:p},p.uuid))},`${t}-${u}`)):null,d=s==null||typeof s=="string"&&s.length===0||Array.isArray(s)&&s.length===0;return n.jsxs("div",{className:`fbre-summary__item${a==="group"||a==="repeater"?" fbre-summary__item--group":""}`,children:[n.jsx("div",{className:"fbre-summary__item-label",children:o}),a!=="group"&&a!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${d?" fbre-summary__item-value--empty":""}`,children:r()}),(a==="group"||a==="repeater")&&l()]})},jt=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Ae=(e,t)=>{const o=e.replace(P.REF_REGEX,(a,s)=>{const i=t.resolveCalculation(s);if(i!==null)return jt(i);const r=t.resolveComponentValue(s);return r!==null?jt(r):""});return P.convertMarkupToHTML(o)},de=(e,t)=>e.replace(P.REF_REGEX,(o,a)=>{const s=t.resolveCalculation(a);if(s!==null)return s;const i=t.resolveComponentValue(a);return i!==null?i:""});function fe(){const e=A(s=>s.components),t=A(s=>s.templateComponentMap),o=A(s=>s.calculations),a=A(s=>s.calculationResults);return g.useMemo(()=>{const s=new Map(o.map(r=>[r.uuid,r])),i=r=>{var p,m;const l=e[r];if(l)return l;const d=t[r];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:r=>{const l=i(r);if(!l)return null;const d=l.value;return d==null||d===""?null:Array.isArray(d)?d.join(", "):String(d)},resolveCalculation:r=>{const l=s.get(r);if(!l)return null;const d=a[r]??null;return P.formatCalculationResult(d,l.format,l.decimalPlaces,l.currencySymbol)}}},[e,t,o,a])}const qn=({screen:e,showToggle:t})=>{const o=fe(),[a,s]=g.useState(!0);return n.jsxs("div",{children:[n.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>t&&s(!a),children:[e.label&&n.jsx("span",{className:"fbre-summary__screen-label",children:de(e.label,o)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${a?"":" collapsed"}`,children:n.jsx(je,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${a?"":" collapsed"}`,children:e.components.map(i=>n.jsx(Vt,{component:i},i.uuid))})]})},_t=()=>{const e=ye(),t=A(s=>s.components),o=g.useMemo(()=>e.getState().getFlowData(),[e,t]),a=o.screens.length;return n.jsxs("div",{className:"fbre-summary",children:[n.jsx("h2",{className:"fbre-summary__title",children:"Review"}),n.jsx("div",{className:"fbre-summary__body",children:o.screens.map(s=>n.jsx(qn,{screen:s,showToggle:a>1},s.uuid))})]})},At=(e,t,o)=>t?!P.isHiddenByCondition(t,o[e]):!0,Le=(e,t)=>{const o=e.screenOrder.length-1;let a=t+1;for(;a<=o;){const s=e.screenOrder[a],i=e.screens[s],r=i!=null&&i.conditions&&"when"in i.conditions?i.conditions:void 0;if(At(s,r,e.conditionResults))return a;a++}return null},zn=(e,t)=>{let o=t-1;for(;o>=0;){const a=e.screenOrder[o],s=e.screens[a],i=s!=null&&s.conditions&&"when"in s.conditions?s.conditions:void 0;if(At(a,i,e.conditionResults))return o;o--}return 0};function K(e,t,o){return`color-mix(in srgb, ${e} ${t}%, ${o})`}const Q="var(--fbre-bg)",Ce="var(--fbre-text)";function $t(e){const t={};if(!e)return t;if(e.color){const o="var(--fbre-theme-color)";t["--fbre-theme-color"]=e.color,t["--fbre-theme-light"]=K(o,14,Q),t["--fbre-theme-dark"]=K(o,82,"#000")}if(e.background&&(t["--fbre-bg"]=e.background),e.surface){const o="var(--fbre-surface)";t["--fbre-surface"]=e.surface,t["--fbre-surface-hover"]=K(o,96,Ce),t["--fbre-surface-subtle"]=K(o,90,Ce),t["--fbre-surface-alt"]=K(o,82,Ce),t["--fbre-control-surface"]=o,t["--fbre-input-bg"]=o,t["--fbre-input-bg-focus"]=K(o,60,Q)}if(e.text){const o="var(--fbre-text)";t["--fbre-text"]=e.text,t["--fbre-text-secondary"]=K(o,64,Q),t["--fbre-label"]=K(o,64,Q),t["--fbre-text-placeholder"]=K(o,42,Q),t["--fbre-text-disabled"]=K(o,34,Q)}if(e.border){const o="var(--fbre-border)";t["--fbre-border"]=e.border,t["--fbre-border-hover"]=K(o,70,Ce),t["--fbre-border-light"]=K(o,60,Q),t["--fbre-border-subtle"]=K(o,35,Q)}return e.radius&&(t["--fbre-radius"]=e.radius),e.fontFamily&&(t["--fbre-font"]=e.fontFamily),e.error&&(t["--fbre-error"]=e.error,t["--fbre-error-light"]=K("var(--fbre-error)",14,Q)),e.success&&(t["--fbre-success"]=e.success,t["--fbre-success-bg"]=K("var(--fbre-success)",14,Q),t["--fbre-success-border"]=K("var(--fbre-success)",40,Q)),e.warning&&(t["--fbre-warning"]=e.warning,t["--fbre-warning-bg"]=K("var(--fbre-warning)",14,Q),t["--fbre-warning-border"]=K("var(--fbre-warning)",40,Q)),t}const Kn=new Set(["text","header","callout","divider","table","computed"]);function Pt(e,t){const o=e.screenOrder[t];if(!o)return 0;const a=e.screens[o];if(!a)return 0;let s=0;for(const i of a.components){const r=e.components[i.uuid];if(!r||Kn.has(r.type))continue;const l=r.conditions&&"when"in r.conditions?r.conditions:void 0;P.isHiddenByCondition(l,e.conditionResults[i.uuid])||(s+=1)}return s}const ot=new Set(["radio","yesNo","cardSelect","dropDown"]),Wn=500;function Ft(e,t,o){const a=ye(),s=g.useRef(null),i=g.useRef(""),r=g.useRef(0);g.useEffect(()=>{if(!e)return;const l=a.getState(),d=wt(l,t);d&&(i.current=Ct(l.components,d)),r.current=l.selectionTick},[e,t,a]),g.useEffect(()=>{if(!e)return;const l=a.subscribe(d=>{const c=wt(d,t);if(!c)return;const u=d.selectionTick,p=u!==r.current;p&&(r.current=u);const m=Ct(d.components,c);if(m===i.current&&!p)return;const f=i.current;if(i.current=m,!(m!==f?Yn(d.components,c,f):p&&Gn(d.components,c))||Le(d,t)===null)return;const b=d.screenOrder[t];b&&d.screenValidity[b]===!1||Pt(d,t)===1&&(s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,o()},Wn))});return()=>{l(),s.current&&(clearTimeout(s.current),s.current=null)}},[e,t,a,o]),g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[t])}function wt(e,t){const o=e.screenOrder[t];if(!o)return null;const a=e.screens[o];return a?a.components.map(s=>s.uuid):null}function Ct(e,t){const o=[];for(const a of t){const s=e[a];!s||!ot.has(s.type)||o.push(`${a}=${JSON.stringify(s.value??null)}`)}return o.join("|")}function Yn(e,t,o){const a=new Map;for(const s of o.split("|")){const i=s.indexOf("=");i>0&&a.set(s.slice(0,i),s.slice(i+1))}for(const s of t){const i=e[s];if(!i||!ot.has(i.type))continue;const r=JSON.stringify(i.value??null),l=a.get(s)??"null";if(r!==l&&r!=="null")return!0}return!1}function Gn(e,t){for(const o of t){const a=e[o];if(!(!a||!ot.has(a.type))&&a.value!==null&&a.value!==void 0)return!0}return!1}function Ut(e,t,o){const a=ye();g.useEffect(()=>{if(!e)return;const s=i=>{if(i.key!=="Enter")return;const r=i.target;if(r.tagName!=="INPUT"||!r.closest(".fbre-container"))return;const l=a.getState();if(Le(l,t)===null)return;const c=l.screenOrder[t];c&&l.screenValidity[c]===!1||Pt(l,t)===1&&(i.preventDefault(),o())};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t,o,a])}const Ht=g.createContext(null),Nt=[],U=e=>{const t=g.useContext(Ht),o=A(l=>{var d;return(d=l.components[e])==null?void 0:d.value}),a=A(l=>{var d;return(d=l.components[e])==null?void 0:d.properties}),s=A(l=>{var d;return(d=l.components[e])==null?void 0:d.valid}),i=A(l=>l.validationErrors[e]??Nt),r=A(l=>l.updateComponentValue);return t?{value:t.value,properties:t.properties,valid:t.valid,validationErrors:Nt,updateValue:r}:{value:o,properties:a,valid:s,validationErrors:i,updateValue:r}},me=(e,t)=>U(e),Xn=({uuid:e})=>{const{properties:t}=me(e),o=fe(),a=t==null?void 0:t.value;if(!a)return null;const s=de(a,o);return n.jsx("h2",{className:"fbre-header",children:s})};$("header",Xn);const Jn=({uuid:e})=>{const{properties:t}=me(e),o=fe(),a=t==null?void 0:t.value;return a==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:Ae(a,o)}})};$("text",Jn);const Qn=({uuid:e})=>{const{properties:t}=me(e),o=(t==null?void 0:t.textAlign)??"center",a=o==="left"?" fbre-divider--left":o==="right"?" fbre-divider--right":"";return n.jsx("div",{className:`fbre-divider${a}`,children:t!=null&&t.value?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fbre-divider__line"}),n.jsx("span",{className:"fbre-divider__label",children:t.value}),n.jsx("div",{className:"fbre-divider__line"})]}):n.jsx("div",{className:"fbre-divider__line"})})};$("divider",Qn);const Zn={info:"info",success:"check",warning:"warning",neutral:void 0},er=({uuid:e})=>{const{properties:t}=me(e),o=fe(),a=t==null?void 0:t.value,s=t==null?void 0:t.title,i=(t==null?void 0:t.variant)??"info",r=t==null?void 0:t.icon;if(!a&&!s)return null;let l;if(r==="none")l=void 0;else if(r&&We[r])l=We[r];else{const c=Zn[i];l=c?We[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:[s&&n.jsx("div",{className:"fbre-callout__title",children:de(s,o)}),a&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:Ae(a,o)}})]})]})};$("callout",er);const tr=({uuid:e})=>{const{properties:t}=me(e),o=t==null?void 0:t.label,a=t==null?void 0:t.columns,s=t==null?void 0:t.rows,i=t==null?void 0:t.highlightColumn,r=i?i-1:-1;return!a||!s||a.length===0?null:n.jsxs("div",{className:"fbre-table",children:[o&&n.jsx("div",{className:"fbre-table__label",children:o}),n.jsxs("table",{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"fbre-table__row-label"}),a.map((l,d)=>n.jsx("th",{className:r===d?"fbre-table__col fbre-table__col--highlight":"fbre-table__col",children:l.label},d))]})}),n.jsx("tbody",{children:s.map((l,d)=>n.jsxs("tr",{children:[n.jsx("td",{className:"fbre-table__row-label",children:l.label}),a.map((c,u)=>n.jsx("td",{className:r===u?"fbre-table__cell fbre-table__cell--highlight":"fbre-table__cell",children:l.values[u]??""},u))]},d))})]})]})};$("table",tr);const nr=({uuid:e})=>{const{properties:t,value:o}=me(e),a=t==null?void 0:t.label,s=(t==null?void 0:t.showLabel)!==!1,i=t==null?void 0:t.detail,r=t==null?void 0:t.format,l=t==null?void 0:t.decimalPlaces,d=t==null?void 0:t.currencySymbol,c=P.formatCalculationResult(typeof o=="number"?o:null,r,l,d);return n.jsxs("div",{className:"fbre-computed",children:[s&&a&&n.jsx("div",{className:"fbre-computed__label",children:a}),n.jsx("div",{className:"fbre-computed__value",children:c||"—"}),i&&n.jsx("div",{className:"fbre-computed__detail",children:i})]})};$("computed",nr);const qt=({text:e})=>{var d;const[t,o]=g.useState(!1),a=g.useRef(null),s=g.useRef(null),[i,r]=g.useState(null),l=g.useCallback(()=>{if(!a.current)return;const c=a.current.getBoundingClientRect();r({top:c.bottom+4,left:c.right})},[]);return g.useEffect(()=>{if(!t)return;l();const c=p=>{const m=p.target;a.current&&!a.current.contains(m)&&s.current&&!s.current.contains(m)&&o(!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:a,type:"button",className:"fbre-tooltip-trigger",onClick:()=>o(!t),"aria-label":"Help",children:n.jsx(jn,{})}),t&&i&&nn.createPortal(n.jsx("div",{ref:s,className:"fbre-tooltip-popover open",style:{top:i.top,left:i.left},children:n.jsx("span",{dangerouslySetInnerHTML:{__html:P.convertMarkupToHTML(e)}})}),((d=a.current)==null?void 0:d.closest(".fbre-container"))??document.body)]})},q=({label:e,detail:t,showLabel:o,required:a,helperText:s,tooltip:i,inputId:r,externalFocused:l,error:d,errorMessages:c,children:u})=>{const p=fe(),[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:Ae(t,p)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[e&&(!t||t.length===0||o)&&n.jsxs("label",{className:"fbre-field__label",htmlFor:r,children:[de(e,p),a&&n.jsx("span",{className:"required",children:"*"})]}),u({focused:m,setFocused:f}),s&&n.jsx("div",{className:"fbre-field__helper",children:de(s,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(qt,{text:i})]})]})},rr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,l=g.useRef(null),[d,c]=g.useState(!1);if(!r)return null;const u=t!=null&&a===!1,p=r.inputType==="password",m=p&&d?"text":r.inputType??"text",f=`fbre-input-${e}`;return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,inputId:f,error:u,errorMessages:u?s:void 0,children:({setFocused:v})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[r.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:r.startAdornment}),n.jsx("input",{ref:l,id:f,className:`fbre-field__input${r.readOnly?" fbre-field__input--readonly":""}`,type:m,defaultValue:t??"",placeholder:r.placeholder,maxLength:r.maxlength,readOnly:r.readOnly,autoComplete:r.autocomplete??(p?"new-password":void 0),onChange:y=>i(e,y.target.value),onFocus:()=>v(!0),onBlur:()=>v(!1)}),p&&r.showPasswordToggle&&n.jsx("button",{type:"button",className:"fbre-field__password-toggle",onClick:()=>c(!d),tabIndex:-1,children:d?n.jsx(vn,{}):n.jsx(xn,{})})]})})};$("inputText",rr);const sr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o;if(!r)return null;const l=t!=null&&a===!1,d=`fbre-input-${e}`;return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,inputId:d,error:l,errorMessages:l?s:void 0,children:({setFocused:c})=>n.jsx("textarea",{id:d,className:`fbre-field__textarea${r.readOnly?" fbre-field__textarea--readonly":""}`,defaultValue:t??"",placeholder:r.placeholder,maxLength:r.maxlength,readOnly:r.readOnly,autoComplete:r.autocomplete,onChange:u=>i(e,u.target.value),onFocus:()=>c(!0),onBlur:()=>c(!1)})})};$("inputTextArea",sr);const or=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(t??"");if(!r)return null;const c=t!=null&&a===!1,u=r.decimalPlaces,p=`fbre-input-${e}`,m=v=>{if(v==="")return v;const y=parseFloat(v);return isNaN(y)?v:r.min!==void 0&&y<r.min?String(r.min):r.max!==void 0&&y>r.max?String(r.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:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,inputId:p,error:c,errorMessages:c?s:void 0,children:({setFocused:w})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[r.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:r.startAdornment}),n.jsx("input",{id:p,className:`fbre-field__input${r.readOnly?" fbre-field__input--readonly":""}`,type:"text",value:l,placeholder:r.placeholder,maxLength:r.maxlength,readOnly:r.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:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,inputId:p,error:c,errorMessages:c?s:void 0,children:({setFocused:v})=>n.jsxs("div",{className:"fbre-field__input-wrap",children:[r.startAdornment&&n.jsx("span",{className:"fbre-field__adornment",children:r.startAdornment}),n.jsx("input",{id:p,className:`fbre-field__input${r.readOnly?" fbre-field__input--readonly":""}`,type:"number",defaultValue:t??"",placeholder:r.placeholder,min:r.min,max:r.max,readOnly:r.readOnly,autoComplete:r.autocomplete,onChange:y=>i(e,y.target.value),onFocus:()=>v(!0),onBlur:y=>f(y,v)})]})})};$("inputNumber",or);function $e(e,t,o){g.useEffect(()=>{if(!t)return;const a=s=>{e.current&&!e.current.contains(s.target)&&o()};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[t,e,o])}function zt(e){let t=e.parentElement;for(;t;){const{overflow:o,overflowY:a}=getComputedStyle(t);if(/(auto|scroll)/.test(o+a))return t;t=t.parentElement}return document.documentElement}function kt(e,t){const o=zt(e),a=o===document.documentElement?{top:0,bottom:window.innerHeight}:o.getBoundingClientRect(),s=e.getBoundingClientRect(),i=a.bottom-s.bottom,r=s.top-a.top;return i<t&&r>i}function Pe(e,t,o=300){const[a,s]=g.useState(!1);return g.useLayoutEffect(()=>{if(!t||!e.current){s(!1);return}const i=e.current.offsetParent;i&&s(kt(i,o))},[t,o]),g.useEffect(()=>{if(!t||!e.current)return;const i=()=>{var l;const r=(l=e.current)==null?void 0:l.offsetParent;r&&s(kt(r,o))};return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[t,o]),a}const ar=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[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([]);$e(p,l,g.useCallback(()=>d(!1),[]));const y=Pe(f,l,200);if(g.useEffect(()=>{var h;l&&c>=0&&((h=v.current[c])==null||h.focus())},[l,c]),!r)return null;const b=r.readOnly===!0,_=r.options,w=t!=null&&a===!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:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,externalFocused:l,error:w,errorMessages:w?s: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(je,{})})]}),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(te,{})})]},`${e}-${j}`)})})]})})};$("dropDown",ar);const lr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[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([]);$e(p,l,g.useCallback(()=>d(!1),[]));const y=Pe(f,l,200);if(g.useEffect(()=>{var h;l&&c>=0&&((h=v.current[c])==null||h.focus())},[l,c]),!r)return null;const b=r.readOnly===!0,_=r.options,w=t??[],C=t!=null&&a===!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:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,externalFocused:l,error:C,errorMessages:C?s: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(je,{})})]}),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(te,{size:12})}),n.jsx("span",{children:h.label})]},`${e}-${j}`)})})]})})};$("dropDownMulti",lr);const Kt=({label:e,detail:t,showLabel:o,required:a,helperText:s,tooltip:i,error:r,errorMessages:l,children:d})=>{const c=fe(),u=["fbre-option-group",r&&"fbre-option-group--error"].filter(Boolean).join(" ");return n.jsxs("div",{className:u,children:[t&&n.jsx("div",{className:"fbre-field__prompt",dangerouslySetInnerHTML:{__html:Ae(t,c)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[o!==!1&&(!t||t.length===0)&&n.jsxs("div",{className:"fbre-option-group__label",children:[de(e,c),a&&n.jsx("span",{className:"required",children:"*"})]}),n.jsx("div",{className:"fbre-option-group__items",children:d}),s&&n.jsx("div",{className:"fbre-option-group__helper",children:de(s,c)}),(()=>{const p=l==null?void 0:l.filter(m=>m);return r&&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(qt,{text:i})]})]})},ir=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o;if(!r)return null;const l=r.readOnly===!0,d=t??[],c=t!=null&&a===!1,u=p=>{const m=p.toString(),f=d.includes(m)?d.filter(v=>v!==m):[...d,m];i(e,f)};return n.jsx(Kt,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,error:c,errorMessages:c?s:void 0,children:r.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(te,{})}),n.jsx("span",{className:"fbre-option-item__text",children:p.label})]},`${e}-${m}`)})})};$("checkbox",ir);const cr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,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(!r)return null;const d=r.readOnly===!0,c=t,u=t!=null&&a===!1;return n.jsx(Kt,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,error:u,errorMessages:u?s:void 0,children:r.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(te,{}):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",cr);const dr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o;if(!r)return null;const l=r.columns??(r.options.length<4?1:2),d=t!=null&&a===!1;return n.jsxs("div",{className:`fbre-card-select${d?" fbre-card-select--error":""}`,children:[r.showLabel!==!1&&r.label&&n.jsx("div",{className:"fbre-card-select__label",children:r.label}),n.jsx("div",{className:"fbre-card-select__grid",style:{gridTemplateColumns:`repeat(${l}, 1fr)`},children:r.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&&s&&s.length>0&&n.jsx("div",{className:"fbre-field__errors",children:s.map((c,u)=>n.jsx("span",{className:"fbre-field__error-message",children:c},u))})]})};$("cardSelect",dr);const ur=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=t,l=o,[d,c]=g.useState(null);if(!l)return null;const u=l.max??5,p=l.precision??1,m=d??r??0,f=r!=null&&a===!1,v=l.icon&&Pn[l.icon]||st,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=r??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?s: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":r??0,onKeyDown:E,children:_}),r!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[r," / ",u]})]})})};$("rating",ur);const pr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=t,l=o;if(!l)return null;const d=l.readOnly===!0,c=l.min??0,u=l.max??100,p=l.steps??1,m=(r-c)/(u-c)*100,f=a===!1;return n.jsx(q,{label:l.label,detail:l.detail,showLabel:l.showLabel,required:l.required,helperText:l.helperText,error:f,errorMessages:f?s: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:r,disabled:d,style:{"--fill":`${m}%`},onChange:v=>i(e,Number(v.target.value))}),n.jsx("span",{className:"fbre-slider__value",children:r})]}),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",pr);const fr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o;if(!r)return null;const l=a===!1;return n.jsx(q,{detail:r.detail,helperText:r.helperText,error:l,errorMessages:l?s: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"})}),(!r.detail||r.detail.length===0||r.showLabel)&&n.jsx("span",{className:"fbre-toggle__label",children:r.label})]})})};$("toggleSwitch",fr);const ve=new Map,mr=(e,t)=>{ve.has(e)||ve.set(e,new Set),ve.get(e).add(t)},hr=(e,t)=>{var o;(o=ve.get(e))==null||o.delete(t)},St=(e,t,o)=>{var a;(a=ve.get(e))==null||a.forEach(s=>{s(t,o)})},Wt=g.createContext(null);function Yt(){return g.useContext(Wt)}class ge extends Error{constructor(t,o,a,s){super(t),this.name="ApiError",this.status=o,this.code=a,this.validationErrors=s}}class Gt extends ge{constructor(t,o){super(`Request timed out after ${o}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const br=new Set([502,503,504]),Ne=2,vr=[500,1500];function xr(e){return new Promise(t=>setTimeout(t,e))}async function se(e,t,o={}){const s=`${e.apiEndpoint||""}${t}`,i=e.timeout??3e4,r={...o.body?{"Content-Type":"application/json"}:{},...o.headers};e.apiKey&&(r.Authorization=`Bearer ${e.apiKey}`);let l;for(let d=0;d<=Ne;d++){d>0&&await xr(vr[d-1]);try{const c=new AbortController,u=setTimeout(()=>c.abort(),i);let p;try{p=await fetch(s,{...o,headers:r,signal:c.signal})}finally{clearTimeout(u)}if(!p.ok){const m=await p.json().catch(()=>({})),f=new ge(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(d<Ne&&br.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 ge)throw c;if(c instanceof DOMException&&c.name==="AbortError"){const u=new Gt(s,i);if(d<Ne){l=u;continue}throw u}if(c instanceof TypeError&&d<Ne){l=c;continue}throw c}}throw l}async function gr(e,t){return se(e,`/api/v1/public/flows/${t}`)}async function yr(e,t,o,a,s,i){return se(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:o,contentType:a,size:s,componentUuid:i})})}async function jr(e,t,o){return se(e,`/api/v1/public/flows/${t}/files/${o}/confirm`,{method:"POST"})}async function _r(e,t,o){const a={flowId:t};return o&&Object.keys(o).length>0&&(a.context=o),se(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(a)})}async function wr(e,t,o){return se(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:o})})}async function Cr(e,t,o){return se(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:o})})}async function Nr(e,t,o){return se(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:o})})}async function kr(e,t){return se(e,`/api/v1/public/sessions/${t}`)}const Sr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(!1),[c,u]=g.useState(!1),p=g.useRef(null),m=Yt();if(!r)return null;const f=t!=null&&a===!1,v=async y=>{if(y.preventDefault(),!y.target.files)return;const b=y.target.files[0];if(!b)return;if(r.maxSize&&b.size>r.maxSize){d(!0),setTimeout(()=>d(!1),5e3);return}if(d(!1),m){u(!0);try{const{fileId:w,uploadUrl:C}=await yr(m.config,m.flowId,b.name,b.type,b.size,e);await fetch(C,{method:"PUT",headers:{"Content-Type":b.type},body:b}),await jr(m.config,m.flowId,w);const E={mode:"s3",fileId:w,name:b.name,type:b.type,size:b.size};i(e,E),St("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),St("file-upload",e,w)}),_.readAsDataURL(b)};return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,error:f,errorMessages:f?s: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(_n,{}),"Upload file",n.jsx("input",{ref:p,type:"file",accept:r.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",Sr);const Er=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o;if(!r)return null;const l=t!=null&&a===!1,d=r.labelYes??"Yes",c=r.labelNo??"No";return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:!1,error:l,errorMessages:l?s:void 0,children:()=>n.jsxs("div",{className:`fbre-yesno${r.layout?` fbre-yesno--${r.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",Er);const Rr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o;if(!r)return null;const l=a===!1,d=t===!0;return n.jsx(q,{detail:r.detail,helperText:r.helperText,tooltip:r.tooltip,error:l,errorMessages:l?s: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:r.label})]})})};$("confirm",Rr);const Et=e=>{const{h:t,s:o,b:a}=e,s=o/100,i=a/100,r=i*s,l=r*(1-Math.abs(t/60%2-1)),d=i-r;let c=0,u=0,p=0;t<60?(c=r,u=l,p=0):t<120?(c=l,u=r,p=0):t<180?(c=0,u=r,p=l):t<240?(c=0,u=l,p=r):t<300?(c=l,u=0,p=r):(c=r,u=0,p=l);const m=f=>Math.round((f+d)*255).toString(16).padStart(2,"0");return`#${m(c)}${m(u)}${m(p)}`},ke=e=>{const t=e.replace("#",""),o=parseInt(t.substring(0,2),16)/255,a=parseInt(t.substring(2,4),16)/255,s=parseInt(t.substring(4,6),16)/255,i=Math.max(o,a,s),r=Math.min(o,a,s),l=i-r;let d=0;l!==0&&(i===o?d=60*((a-s)/l%6):i===a?d=60*((s-o)/l+2):d=60*((o-a)/l+4)),d<0&&(d+=360);const c=i===0?0:l/i*100,u=i*100;return{h:d,s:c,b:u}},Ye=e=>/^#[0-9a-fA-F]{6}$/.test(e),Dr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[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"&&Ye(t)?t:"#1976d2",[_,w]=g.useState(()=>ke(b));$e(c,l,g.useCallback(()=>d(!1),[]));const C=Pe(p,l,320);if(g.useEffect(()=>{typeof t=="string"&&Ye(t)&&(y(t),w(ke(t)))},[t]),!r)return null;const E=t!=null&&a===!1,k=h=>{w(h);const j=Et(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),Ye(h)){const j=ke(h);w(j),i(e,h.toLowerCase())}},x=Et({h:_.h,s:100,b:100});return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:l,error:E,errorMessages:E?s: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})}),r.swatches&&r.swatches.length>0&&n.jsx("div",{className:"fbre-colorpicker__swatches",children:r.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(ke(N)),i(e,N)}},j))})]})]})})};$("colorPicker",Dr);const Tr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,l=(r==null?void 0:r.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&&a===!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 r?n.jsx(q,{label:r.label??"Signature",detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,error:y,errorMessages:y?s: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",Tr);function Rt(e){const t=e.offsetParent;if(!t)return 0;const o=zt(t),a=o===document.documentElement?{left:0,right:window.innerWidth}:o.getBoundingClientRect(),s=t.getBoundingClientRect(),i=e.offsetWidth,r=s.left+i;if(r<=a.right-8)return 0;let l=-(r-a.right+8);return s.left+l<a.left+8&&(l=a.left+8-s.left),l}const he=({open:e,onClose:t,children:o,estimatedHeight:a=300,triggerRef:s})=>{const i=g.useRef(null);$e(i,e,g.useCallback(()=>t(),[t]));const r=Pe(i,e,a),[l,d]=g.useState(0);if(g.useLayoutEffect(()=>{if(!e||!i.current){d(0);return}d(Rt(i.current))},[e]),g.useEffect(()=>{if(!e||!i.current)return;const p=()=>{i.current&&d(Rt(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"+(r?" fbre-popup--above":""),u=p=>{var m;p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),t(),(m=s==null?void 0:s.current)==null||m.focus())};return n.jsx("div",{ref:i,className:c,role:"dialog",onKeyDown:u,style:l?{left:l}:void 0,children:o})},De=(e,t)=>new Date(e,t+1,0).getDate(),Ir=(e,t)=>new Date(e,t,1).getDay(),le=(e,t,o)=>`${e}-${String(t+1).padStart(2,"0")}-${String(o).padStart(2,"0")}`,Lr=e=>{const t=e.split("-");if(t.length!==3)return null;const o=parseInt(t[0],10),a=parseInt(t[1],10)-1,s=parseInt(t[2],10);return isNaN(o)||isNaN(a)||isNaN(s)?null:{year:o,month:a,day:s}},Me=(e,t)=>{const o=Lr(e);if(!o)return e;const a=String(o.month+1).padStart(2,"0"),s=String(o.day).padStart(2,"0"),i=String(o.year);return t==="DD/MM/YYYY"?`${s}/${a}/${i}`:t==="YYYY-MM-DD"?`${i}-${a}-${s}`:`${a}/${s}/${i}`},Be=e=>{const t=e.split(":");if(t.length!==2)return e;let o=parseInt(t[0],10);const a=t[1],s=o>=12?"PM":"AM";return o===0?o=12:o>12&&(o-=12),`${o}:${a} ${s}`},rt=(e,t)=>{const o=e.indexOf("T");if(o===-1)return e;const a=e.substring(0,o),s=e.substring(o+1);return`${Me(a,t)} ${Be(s)}`},Mr=(e,t,o)=>{let a=e;return o==="AM"&&a===12?a=0:o==="PM"&&a!==12&&(a+=12),`${String(a).padStart(2,"0")}:${String(t).padStart(2,"0")}`},Br=e=>{const t=e.split(":");let o=parseInt(t[0],10);const a=parseInt(t[1],10),s=o>=12?"PM":"AM";return o===0?o=12:o>12&&(o-=12),{hour:o,minute:a,ampm:s}},Or=(e,t,o)=>e>=t&&e<=o,re=e=>{if(!e)return;if(!e.startsWith("today"))return e;const t=e==="today"?0:parseInt(e.slice(5),10),o=new Date;return o.setDate(o.getDate()+(isNaN(t)?0:t)),le(o.getFullYear(),o.getMonth(),o.getDate())},Vr=["January","February","March","April","May","June","July","August","September","October","November","December"],Ar=e=>Vr[e],$r=["Su","Mo","Tu","We","Th","Fr","Sa"],xe=e=>[parseInt(e.substring(0,4),10),parseInt(e.substring(5,7),10)-1,parseInt(e.substring(8,10),10)],ue=(e,t)=>{const[o,a,s]=xe(e),i=new Date(o,a,s+t);return le(i.getFullYear(),i.getMonth(),i.getDate())},Se=(e,t)=>{let[o,a,s]=xe(e);for(a+=t;a<0;)a+=12,o--;for(;a>11;)a-=12,o++;return le(o,a,Math.min(s,De(o,a)))},Fe=({selectedDate:e,min:t,max:o,onSelect:a,rangeStart:s,rangeEnd:i,rangeHover:r})=>{const l=new Date,d=le(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]=xe(c),b=()=>u(Se(c,-1)),_=()=>u(Se(c,1)),w=j=>{let N=null;switch(j.key){case"ArrowLeft":N=ue(c,-1);break;case"ArrowRight":N=ue(c,1);break;case"ArrowUp":N=ue(c,-7);break;case"ArrowDown":N=ue(c,7);break;case"Home":{const[D,M,B]=xe(c);N=ue(c,-new Date(D,M,B).getDay());break}case"End":{const[D,M,B]=xe(c);N=ue(c,6-new Date(D,M,B).getDay());break}case"PageUp":N=Se(c,-1);break;case"PageDown":N=Se(c,1);break}N&&(j.preventDefault(),f(N))},C=De(v,y),E=Ir(v,y),k=[],S=y===0?De(v-1,11):De(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:le(M,D,N),outside:!0})}for(let j=1;j<=C;j++)k.push({day:j,iso:le(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:le(D,N,j),outside:!0})}const I=r??i,x=s&&I&&s<=I?s:I,h=s&&I&&s<=I?I:s;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:[Ar(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:$r.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||o&&j.iso>o,L=x&&h&&Or(j.iso,x,h),O=j.iso===x,F=j.iso===h,W=["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:G=>{p.current[j.iso]=G},className:W,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&&a(j.iso),children:j.day},N)})})]})},Pr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(!1),c=g.useRef(null);if(!r)return null;const u=r.readOnly===!0,p=t!=null&&a===!1,m=typeof t=="string"?t:"";return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:l,error:p,errorMessages:p?s: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:Me(m,r.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholder??"Select date..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(pe,{})})]}),n.jsx(he,{open:l,onClose:()=>d(!1),triggerRef:c,children:n.jsx(Fe,{selectedDate:m,min:re(r.min),max:re(r.max),onSelect:f=>{i(e,f),d(!1)}})})]})})};$("date",Pr);const Dt=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const o=parseInt(t[0],10),a=parseInt(t[1],10);return isNaN(o)||isNaN(a)?null:o*60+a},Ge=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,Ue=({value:e,min:t,max:o,step:a=15,onChange:s})=>{const i=g.useRef(null),r=g.useRef(null),l=e?Br(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+=a)m.push(x);const f=["AM","PM"],v=g.useMemo(()=>Dt(t),[t]),y=g.useMemo(()=>Dt(o),[o]),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=Ge(x,h);for(let N=0;N<60;N+=a)if(_(j,N))return!1;return!0},C=x=>{if(!b)return!1;const h=Ge(d,u);return!_(h,x)},E=x=>{if(!b)return!1;for(const h of p){const j=Ge(h,x);for(let N=0;N<60;N+=a)if(_(j,N))return!1}return!0},k=(x,h,j)=>{s(Mr(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(r.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:r,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)})})]})},Fr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(!1),c=g.useRef(null);if(!r)return null;const u=r.readOnly===!0,p=t!=null&&a===!1,m=typeof t=="string"?t:"";return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:l,error:p,errorMessages:p?s: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:Be(m)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholder??"Select time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(nt,{})})]}),n.jsxs(he,{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(te,{size:12})})]}),n.jsx(Ue,{value:m||void 0,step:r.step,min:r.min,max:r.max,onChange:f=>{i(e,f)}})]})]})})};$("time",Fr);const Ur=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(!1),[c,u]=g.useState("date"),p=g.useRef(null);if(!r)return null;const m=r.readOnly===!0,f=t!=null&&a===!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=re(r.min&&r.min.includes("T")?r.min.split("T")[0]:r.min),I=re(r.max&&r.max.includes("T")?r.max.split("T")[0]:r.max);return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:l,error:f,errorMessages:f?s: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:rt(v,r.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholder??"Select date & time..."}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(pe,{})})]}),n.jsx(he,{open:l,onClose:C,triggerRef:p,children:c==="date"?n.jsx(Fe,{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(te,{size:12})})]}),n.jsx(Ue,{value:_||void 0,step:r.step,min:r.minTime,max:r.maxTime,onChange:k})]})})]})})};$("dateTime",Ur);const Hr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(null),[c,u]=g.useState(),p=g.useRef(null),m=g.useRef(null);if(!r)return null;const f=t!=null&&a===!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:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:w,error:f,errorMessages:f?s: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:Me(y,r.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholderStart??"Start date"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(pe,{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:Me(b,r.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholderEnd??"End date"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(pe,{size:12})})]})})]}),n.jsx(he,{open:w,triggerRef:l==="start"?p:m,onClose:()=>{d(null),u(void 0)},children:n.jsx(Fe,{selectedDate:l==="start"?y:b,min:re(r.min),max:re(r.max),onSelect:_,rangeStart:y,rangeEnd:b,rangeHover:c})})]})})};$("dateRange",Hr);const qr=({uuid:e})=>{const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(null),c=g.useRef(null),u=g.useRef(null);if(!r)return null;const p=t!=null&&a===!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:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:_,error:p,errorMessages:p?s: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:Be(f)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholderStart??"Start time"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(nt,{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:Be(v)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholderEnd??"End time"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(nt,{size:12})})]})})]}),n.jsxs(he,{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(te,{size:12})})]}),n.jsx(Ue,{value:l==="start"?f||void 0:v||void 0,step:r.step,min:r.min,max:r.max,onChange:y})]})]})})};$("timeRange",qr);const zr=({uuid:e})=>{var M,B;const{value:t,properties:o,valid:a,validationErrors:s,updateValue:i}=U(e),r=o,[l,d]=g.useState(null),[c,u]=g.useState("date"),p=g.useRef(null),m=g.useRef(null);if(!r)return null;const f=t!=null&&a===!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=re((M=r.min)==null?void 0:M.split("T")[0]),D=re((B=r.max)==null?void 0:B.split("T")[0]);return n.jsx(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.tooltip,externalFocused:j,error:f,errorMessages:f?s: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:rt(y,r.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholderStart??"Start"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(pe,{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:rt(b,r.dateFormat)}):n.jsx("span",{className:"fbre-datetime__trigger-placeholder",children:r.placeholderEnd??"End"}),n.jsx("span",{className:"fbre-datetime__trigger-icon",children:n.jsx(pe,{size:12})})]})})]}),n.jsx(he,{open:j,triggerRef:l==="start"?p:m,onClose:R,children:c==="date"?n.jsx(Fe,{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(te,{size:12})})]}),n.jsx(Ue,{value:E.time||void 0,step:r.step,min:r.minTime,max:r.maxTime,onChange:x})]})})]})})};$("dateTimeRange",zr);const Xt=({uuid:e})=>{var u;const t=e.split(":")[0],o=parseInt(e.split(":")[1]),a=parseInt(e.split(":")[2]),s=A(p=>{var m,f,v;return(v=(f=(m=p.components[t])==null?void 0:m.addedComponents)==null?void 0:f[o])==null?void 0:v[a]}),i=A(p=>p.conditionResults[e]);if(!s)return null;const r=s.conditions&&"when"in s.conditions?s.conditions:void 0;if(P.isHiddenByCondition(r,i))return null;const l=It(s.type);if(!l)return null;const d=(u=s.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(Ht.Provider,{value:s,children:n.jsx(l,{uuid:e})})})},Kr=({uuid:e})=>{const t=A(l=>{var d;return(d=l.components[e])==null?void 0:d.properties}),o=A(l=>{var d;return(d=l.components[e])==null?void 0:d.addedComponents}),[a,s]=g.useState(!0);if(!t)return null;const i=o??[],r=["fbre-group",t.showBorder===!0&&"fbre-group--bordered",t.showBorder===!1&&"fbre-group--no-border"].filter(Boolean).join(" ");return n.jsx("div",{className:r,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${a?"":" collapsed"}`,onClick:()=>s(!a),"aria-label":"Toggle group",children:n.jsx(je,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${a?"":" collapsed"}`,children:n.jsx("div",{className:"fbre-group__content",children:l.map(c=>n.jsx(Xt,{uuid:c.uuid},c.uuid))})})]},`${e}-${d}`))})};$("group",Kr);const Wr=({uuid:e})=>{const t=A(f=>{var v;return(v=f.components[e])==null?void 0:v.properties}),o=A(f=>{var v;return(v=f.components[e])==null?void 0:v.addedComponents}),a=A(f=>f.addRepeaterIteration),s=A(f=>f.removeRepeaterIteration),[i,r]=g.useState(new Set([0]));if(!t)return null;const l=o??[],d=t.minIterations??1,c=()=>{const f=l.length;a(e),r(new Set([f]))},u=f=>{l.length<=d||(s(e,f),r(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=>{r(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(kn,{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(je,{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(Xt,{uuid:b.uuid},b.uuid))})})]},`${e}-${v}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:c,children:"Add another"})]})};$("repeater",Wr);const Yr={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"},Gr=({screenIndex:e,onFlowComplete:t,onScreenChange:o})=>{var ct,dt,ut,pt,ft,mt,ht,bt,vt,xt;const a=A(V=>V.config),s=A(V=>V.screenOrder.length),i=A(V=>Object.keys(V.components).length>0),r=ye(),l=Math.max(0,Math.min(e,s-1)),[d,c]=g.useState(l),[u,p]=g.useState(!!(a!=null&&a.summary&&e>=s)),m=((ct=a==null?void 0:a.navigation)==null?void 0:ct.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,s-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=>{o&&o(V,r.getState().getFlowData())},[o,r]),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=r.getState(),H=zn(V,d);H!==d&&(f&&L("back"),c(H),B(H))}},[E,u,d,f,L,B,r]),W=g.useCallback(()=>{if(E)return;const V=r.getState(),H=Le(V,d);H!==null?(f&&L("forward"),c(H),B(H)):a!=null&&a.summary&&(f&&L("forward"),p(!0),B(d+1))},[E,d,a,f,L,B,r]),[G,oe]=g.useState(!1),[T,z]=g.useState(null),Y=g.useCallback(()=>{z(null);const V=t(r.getState().getFlowData());V&&typeof V.then=="function"&&(oe(!0),V.then(()=>{oe(!1)}).catch(H=>{oe(!1),z(H instanceof Error?H.message:String(H))}))},[t,r]),X=A(V=>Le(V,d)===null),Qt=((dt=a==null?void 0:a.theme)==null?void 0:dt.colorScheme)??"light",He=((a==null?void 0:a.mode)??"standard")==="conversational";Ft(He&&!u,d,W),Ut(He&&!u,d,W);const at=((ut=a==null?void 0:a.theme)==null?void 0:ut.style)??"clean",lt=((pt=a==null?void 0:a.controls)==null?void 0:pt.stepperStyle)??"default",qe=lt==="default"?Yr[at]??"dots":lt,Zt=((ft=a==null?void 0:a.controls)==null?void 0:ft.showStepper)!==!1&&qe==="text",it=$t(a==null?void 0:a.theme),en=()=>b?n.jsx(_t,{}):v!==null?n.jsx(tt,{screenIndex:v}):null,tn=E?"fbre-screen-wrapper fbre-screen-wrapper--transitioning":"fbre-screen-wrapper";return n.jsxs("div",{className:"fbre-container","data-style":at,"data-mode":Qt,"data-form-mode":He?"conversational":void 0,"data-stepper":qe!=="text"?qe:void 0,"data-transition":f?m:void 0,style:Object.keys(it).length>0?it:void 0,children:[Zt&&n.jsx(Un,{current:d,total:s}),n.jsxs("div",{className:tn,ref:S,children:[E&&n.jsx("div",{ref:x,className:"fbre-screen-slot fbre-screen--exiting","data-direction":w,onAnimationEnd:O,children:en()}),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 ${s}`,children:[!u&&n.jsx(tt,{screenIndex:d}),u&&n.jsx(_t,{})]})]}),T&&n.jsx("div",{className:"fbre-completion-error",children:T}),((mt=a==null?void 0:a.controls)==null?void 0:mt.show)!==!1&&i&&n.jsx(Hn,{screenIndex:d,maxScreenIndex:s-1,allowInvalidTransition:(ht=a==null?void 0:a.navigation)==null?void 0:ht.allowInvalidTransition,screenValidity:N,summaryEnabled:(a==null?void 0:a.summary)??!1,summaryActive:u,atMaxScreen:X,nextButtonLabel:D,backButtonLabel:M,completionLoading:G,showStepper:(bt=a==null?void 0:a.controls)==null?void 0:bt.showStepper,stepperStyle:(vt=a==null?void 0:a.controls)==null?void 0:vt.stepperStyle,controlsLayout:(xt=a==null?void 0:a.controls)==null?void 0:xt.layout,nextScreen:W,prevScreen:F,onFlowComplete:Y})]})},Xr=[],Jr=()=>ee.createStore((e,t)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,sessionId:"",navigation:{canGoBack:!1,canGoForward:!1,screenNumber:1,totalScreens:1,progress:0,isLastScreen:!0},loading:!1,error:"",clearError:()=>{e({error:""})},loadFlow:()=>{},updateContext:o=>{e({externalContext:o})},updateComponentValue:(o,a)=>{var d,c;const s=t();if(o.includes(":")){const u=o.split(":"),p=u[0],m=parseInt(u[1]),f=parseInt(u[2]),v=s.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:a};const y=s.groupComponentMap[o]??o,b=et(e,t,y),_=Je(s,o,v.addedComponents[m][f]);e({components:{...s.components},conditionResults:b??s.conditionResults,validationErrors:_});return}const i=s.components[o];if(!i)return;if(i.type==="group"||i.type==="repeater"){e({components:{...s.components}});return}if(a===i.value){e({selectionTick:(t().selectionTick??0)+1});return}i.value=a;const r=et(e,t,o),l=Je(s,o,i);e({components:{...s.components},conditionResults:r??s.conditionResults,validationErrors:l})},addGroupIteration:o=>{const a=t(),s=a.components[o];if(!s||s.type!=="group"||!s.components)return;s.addedComponents||(s.addedComponents=[]);const i=s.components.map((r,l)=>{const d=ne(r);d.uuid=[o,s.addedComponents.length,l].join(":"),a.groupComponentMap[d.uuid]=r.uuid;const c=J(d);return d.valid=c.length===0,d});return s.addedComponents.push(i),e({components:{...a.components},groupComponentMap:{...a.groupComponentMap}}),s.addedComponents},addRepeaterIteration:o=>{const a=t(),s=a.components[o];if(!s||s.type!=="repeater"||!s.components)return;s.addedComponents||(s.addedComponents=[]);const i=s.components.map((r,l)=>{const d=ne(r);d.uuid=[o,s.addedComponents.length,l].join(":");const c=J(d);return d.valid=c.length===0,d});return s.addedComponents.push(i),e({components:{...a.components}}),s.addedComponents},removeRepeaterIteration:(o,a)=>{const s=t(),i=s.components[o];if(!(!i||i.type!=="repeater"||!i.addedComponents||i.addedComponents.length<=1)){i.addedComponents.splice(a,1);for(let r=a;r<i.addedComponents.length;r++)i.addedComponents[r].forEach((l,d)=>{l.uuid=[o,r,d].join(":")});e({components:{...s.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:o=>{const a=t();if(o!==0)return null;const s=a.screenOrder[0];return s?a.screens[s]:null},getScreenValidity:o=>{const a=t();if(o!==0)return!0;const s=a.screenOrder[0];return s?a.screenValidity[s]??!0:!0},getValidationErrors:o=>t().validationErrors[o]??Xr,evaluateFlowValidation:()=>{const o=t(),a=o.screenOrder[0];if(!a)return!0;const s=o.screens[a];if(!s)return!0;let i=!0;const r={components:o.components,groupComponentMap:o.groupComponentMap},l={...o.validationErrors};for(const c of s.components){const u=o.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 _=o.conditionResults[v.uuid]??!1;if(y.action==="show"&&!_||y.action==="hide"&&_)continue}const b=J(v,r);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=o.conditionResults[u.uuid]??!1;if(p.action==="show"&&!f||p.action==="hide"&&f)continue}const m=J(u,r);u.valid=m.length===0,l[u.uuid]=m,m.length>0&&(i=!1)}const d={...o.screenValidity,[a]:i};return e({components:{...o.components},validationErrors:l,screenValidity:d}),i},getMaxScreenCount:()=>0,getCalculationResult:o=>t().calculationResults[o]??null})),Ee=(e,t)=>{const o={},a={},s={},i={},r={},l={},d=t.screen.uuid;for(const b of t.screen.components){const _=ne(b);if(o[_.uuid]=_,(_.type==="group"||_.type==="repeater")&&b.components){_.addedComponents||(_.addedComponents=[]);const C=b.components.map((E,k)=>{const S=ne(E);S.uuid=[_.uuid,0,k].join(":"),_.type==="group"&&(a[S.uuid]=E.uuid),s[E.uuid]=S.uuid;const R=Z.getValidationConfig(S);return R&&R.rules&&R.rules.length>0&&be(r,S.uuid,R),S});_.addedComponents.push(C)}const w=Z.getValidationConfig(_);w&&w.rules&&w.rules.length>0&&be(r,_.uuid,w)}for(const{targetUUID:b,config:_}of t.conditions)ae(i,b,_,b===d?"screen":"component");if(t.previousData)for(const b of t.previousData){const _=o[b.uuid];_&&(_.value=b.value)}const c={components:o};for(const b of Object.keys(o)){const _=o[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(!Z.getValidationConfig(_))continue;const w=J(_,c);_.valid=w.length===0,w.length>0&&(l[b]=w)}const u={},p={components:o},m=new Set;for(const b of Object.values(i))for(const _ of b)m.has(_.target)||(m.add(_.target),u[_.target]=Oe(p,_.config));let f=!0;for(const b of t.screen.components){const _=o[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:o,groupComponentMap:a,templateComponentMap:s,conditionsByDependency:i,conditionResults:u,validationErrors:l,validationsByDependency:r,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:t.sessionId,navigation:t.navigation,loading:!1,error:y,externalContext:t.context??{},config:t.config??{}})},Xe=e=>{const t=e.getState(),o=t.screenOrder[0];if(!o)return[];const a=t.screens[o];if(!a)return[];const s=[];for(const i of a.components){const r=t.components[i.uuid];if(!r||Te(r.type))continue;const l={uuid:r.uuid,type:r.type,value:r.value};"label"in r.properties&&typeof r.properties.label=="string"&&(l.label=r.properties.label),(r.type==="group"||r.type==="repeater")&&r.addedComponents&&(l.components=r.addedComponents.map(d=>d.filter(c=>!Te(c.type)).map(c=>({uuid:c.uuid,type:c.type,value:c.value})))),s.push(l)}return s},Qr=6e4,Zr=({sessionEndpoint:e,flowId:t,apiKey:o,mode:a,theme:s,context:i,onFlowComplete:r,onScreenChange:l})=>{const d=g.useRef(null);d.current||(d.current=Jr());const c=d.current,u=ee.useStore(c,T=>T.loading),p=ee.useStore(c,T=>T.error),m=ee.useStore(c,T=>T.navigation),f=ee.useStore(c,T=>T.config),v=ee.useStore(c,T=>{var z;return(z=T.config)==null?void 0:z.mode}),y=ee.useStore(c,T=>T.screenOrder),b=ee.useStore(c,T=>T.screens),[_,w]=g.useState(""),C=g.useRef(null),E=g.useRef(Date.now()),k=g.useMemo(()=>({apiEndpoint:e,apiKey:o}),[e,o]),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 _r(k,t,i);Ee(c,T)}catch(T){c.setState({loading:!1,error:T.message})}},[t,e,o,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<Qr))try{const X=await kr(k,z.sessionId);Ee(c,X)}catch(X){X instanceof ge&&X.status===404&&c.setState({loading:!1,error:"Session expired. Please start over.",screenOrder:[],screens:{}})}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[e,o]);const x=g.useCallback(async()=>{const T=c.getState();if(!(T.loading||!T.evaluateFlowValidation())){c.setState({loading:!0}),c.getState().clearError(),R();try{const Y=Xe(c),X=await wr(k,T.sessionId,Y);Ee(c,X),E.current=Date.now(),l==null||l(X.navigation.screenNumber)}catch(Y){c.setState({loading:!1}),S(Y.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=Xe(c),Y=await Cr(k,T.sessionId,z);Ee(c,Y),E.current=Date.now(),l==null||l(Y.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 Y=Xe(c),X=await Nr(k,T.sessionId,Y);E.current=Date.now(),r(X)}catch(Y){c.setState({loading:!1}),S(Y.message)}}},[k,c,r,S,R]),N={...f==null?void 0:f.theme,...s},M=(a??v??"standard")==="conversational",B=M&&!m.isLastScreen;Ft(B,0,x),Ut(B,0,x);const L=N.colorScheme??"light",O=$t(N),F=y[0],W=F?b[F]:void 0,G=W==null?void 0:W.nextButtonLabel,oe=W==null?void 0:W.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(Ve.Provider,{value:c,children:n.jsxs("div",{className:"fbre-container","data-style":N.style??"clean","data-mode":L,"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(tt,{screenIndex:0})}),n.jsx(es,{navigation:m,loading:u,onPrev:h,onNext:x,onComplete:j,nextButtonLabel:G,backButtonLabel:oe}),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:"×"})]})]})})},es=({navigation:e,loading:t,onPrev:o,onNext:a,onComplete:s,nextButtonLabel:i,backButtonLabel:r})=>n.jsxs("div",{className:"fbre-controls fbre-controls--default",children:[n.jsx("div",{className:"fbre-controls__left",children:e.canGoBack&&n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--back",onClick:o,disabled:t,children:r||"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:s,disabled:t,children:t?"Submitting...":i||"Complete"}):n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:a,disabled:t,children:t?"Loading...":i||"Next"})})]});function ts(e,t,o,a,s){return!t&&!o&&!a&&!s?e:{...e,...s&&{mode:s},...t&&{theme:{...e.theme,...t}},...o&&{navigation:{...e.navigation,...o}},...a&&{controls:{...e.controls,...a}}}}const Jt=({flow:e,data:t,mode:o,theme:a,navigation:s,controls:i,screenIndex:r,context:l,storeRef:d,onFlowComplete:c,onScreenChange:u,onScreenValidationChange:p,apiCtx:m})=>{const f=g.useRef(null);f.current||(f.current=hn(),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(),_=ts(b.config,a,s,i,o);_!==b.config&&f.current.setState({config:_})}},[o,a,s,i]);const v=l?JSON.stringify(l):"";g.useEffect(()=>{f.current&&l&&f.current.getState().updateContext(l)},[v]);const y=n.jsx(Ve.Provider,{value:f.current,children:n.jsx(Gr,{screenIndex:r??0,onFlowComplete:c,onScreenChange:u,onScreenValidationChange:p})});return m?n.jsx(Wt.Provider,{value:m,children:y}):y},ns=({flowId:e,apiEndpoint:t,apiKey:o,data:a,mode:s,theme:i,navigation:r,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:o};gr(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,o]),b?n.jsx("div",{className:"fbre-container",children:n.jsxs("div",{className:"fbre-remote-error",children:[n.jsx("p",{children:"Failed to load form"}),n.jsx("p",{className:"fbre-remote-error__detail",children:b})]})}):!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(Jt,{flow:v,data:a,mode:s,theme:i,navigation:r,controls:l,screenIndex:d,context:c,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f,apiCtx:w})},rs=e=>"sessionEndpoint"in e?n.jsx(Zr,{...e}):"flowId"in e&&e.flowId?n.jsx(ns,{...e}):n.jsx(Jt,{...e});exports.ApiError=ge;exports.FBRE=rs;exports.TimeoutError=Gt;exports.addFBREEventListener=mr;exports.removeFBREEventListener=hr;exports.useFBREApi=Yt;exports.useFBREStore=A;exports.useFBREStoreApi=ye;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("react"),ne=require("zustand"),te=require("@sonata-innovations/fiber-types"),P=require("@sonata-innovations/fiber-shared"),fn=require("react-dom"),Ot=new Map,$=(e,t)=>{Ot.set(e,t)},Bt=e=>Ot.get(e),Ae=e=>te.DISPLAY_ONLY_TYPES.has(e),mn=(e,t)=>{var r,a,o,l;if(t.includes(":")){const s=t.split(":"),i=e.components[s[0]];return(o=(a=(r=i==null?void 0:i.addedComponents)==null?void 0:r[parseInt(s[1])])==null?void 0:a[parseInt(s[2])])==null?void 0:o.value}return(l=e.components[t])==null?void 0:l.value},J=(e,t)=>{const r=te.getValidationConfig(e);return!r||!r.rules||r.rules.length===0?[]:P.validateValue(e.value,r,t?a=>mn(t,a):void 0)},hn=e=>{const t=te.getValidationConfig(e);return!t||!t.rules?!1:t.rules.some(r=>r.type==="required")},oe=e=>{var a;const t={...e};if("options"in t.properties&&Array.isArray(t.properties.options)&&(t.properties={...t.properties,options:te.normalizeOptions(t.properties.options)}),e.type==="computed"?(t.value=null,t.valid=!0):!Ae(e.type)&&e.type!=="group"&&e.type!=="repeater"&&(t.value=null,t.valid=!hn(e)),(e.type==="checkbox"||e.type==="dropDownMulti")&&(t.value=[]),["yesNo","radio","cardSelect","dropDown"].includes(e.type)){const o=e.properties??{},l=o.defaultValue;if(e.type==="yesNo")(l==="yes"||l==="no")&&(t.value=l,t.valid=!0);else{const i=(Array.isArray(o.options)?o.options:[]).find(d=>d&&d.value===l);i&&(t.value=i.value,t.valid=!0)}}return e.type==="toggleSwitch"&&(t.value=!1),e.type==="colorPicker"&&((a=e.properties)!=null&&a.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},ye=(e,t,r)=>{var a;for(const o of r.rules)if(o.type==="matchesField"&&((a=o.params)!=null&&a.field)){const l=o.params.field;e[l]||(e[l]=[]),e[l].push({target:t,config:r})}},Vt=(e,t)=>{var r,a;if(t.includes(":")){const o=t.split(":"),l=e[o[0]];return(a=(r=l==null?void 0:l.addedComponents)==null?void 0:r[parseInt(o[1])])==null?void 0:a[parseInt(o[2])]}return e[t]},nt=(e,t,r)=>{const a={components:e.components,groupComponentMap:e.groupComponentMap},o=J(r,a);r.valid=o.length===0;const l={...e.validationErrors,[t]:o},s=e.validationsByDependency[t];if(s)for(const i of s){const d=Vt(e.components,i.target);if(d){const c=J(d,a);d.valid=c.length===0,l[i.target]=c}}return l},ue=(e,t)=>{const r=e.screens[t];return r?!r.components.some(o=>{var i;const l=e.components[o.uuid];if(!l)return!1;if(l.type==="group"||l.type==="repeater")return(i=l.addedComponents)==null?void 0:i.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=l.conditions&&"when"in l.conditions?l.conditions:void 0;return P.isHiddenByCondition(s,e.conditionResults[l.uuid])?!1:l&&"valid"in l&&!l.valid}):!0};function bn(e){const t={};for(const r of e){const a=P.extractFormulaReferences(r.formula);for(const o of a)t[o]||(t[o]=[]),t[o].includes(r.uuid)||t[o].push(r.uuid)}return t}function At(e,t){return{resolveValue:r=>{if(r in t)return t[r];const a=pe(e,r);if(!a)return null;const o=a.value;if(o==null||o==="")return null;const l=Number(o);return isNaN(l)?null:l},resolveOptionMetadata:(r,a)=>{const o=pe(e,r);if(!o)return null;const l=o.value;if(!l)return null;const s="options"in o.properties?o.properties.options:void 0;if(!Array.isArray(s))return null;const i=s.find(u=>u.value===l||u.label===l);if(!(i!=null&&i.metadata))return null;const d=i.metadata[a];if(d==null)return null;const c=Number(d);return isNaN(c)?null:c},resolveRepeaterValues:r=>{for(const a of Object.keys(e.components)){const o=e.components[a];if(o.type!=="repeater"||!o.addedComponents||!o.components)continue;const l=o.components.findIndex(i=>i.uuid===r);if(l===-1)continue;const s=[];for(const i of o.addedComponents){const d=i[l];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 st(e){const t=e.calculations??[];if(t.length===0)return{};const r=P.topologicalSortCalculations(t),a={},o=At(e,a);for(const l of r)a[l.uuid]=P.evaluateFormula(l.formula,o);return a}function Xe(e,t){const r=e.calculationsByDependency,a=e.calculations??[];if(a.length===0||!r)return null;const o=new Set,l=[t];for(;l.length>0;){const u=l.shift(),p=r[u];if(p)for(const m of p)o.has(m)||(o.add(m),l.push(m))}if(o.size===0)return null;const s=P.topologicalSortCalculations(a),i={...e.calculationResults},d=At(e,i);let c=!1;for(const u of s)if(o.has(u.uuid)){const p=P.evaluateFormula(u.formula,d);i[u.uuid]!==p&&(i[u.uuid]=p,c=!0)}return c?i:null}function vn(e){const t={},r=a=>{var l;if(a.type!=="computed"||!((l=a.properties)!=null&&l.formula))return;const o=P.extractFormulaReferences(a.properties.formula);for(const s of o)t[s]||(t[s]=[]),t[s].includes(a.uuid)||t[s].push(a.uuid)};for(const a of Object.values(e))if(r(a),(a.type==="repeater"||a.type==="group")&&a.components)for(const o of a.components)r(o);return t}function $t(e,t,r,a){var d,c;const o=e.components[r],l=((d=o==null?void 0:o.components)==null?void 0:d.map(u=>u.uuid))??[],s=(c=o==null?void 0:o.addedComponents)==null?void 0:c[a],i=new Map;if(s)for(let u=0;u<s.length;u++){const p=l[u];p&&i.set(p,s[u])}return{resolveValue:u=>{if(u in t)return t[u];const p=i.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=pe(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=i.get(u)??pe(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 $e(e,t){return{resolveValue:r=>{if(r in t)return t[r];const a=pe(e,r);if(!a)return null;const o=a.value;if(o==null||o==="")return null;const l=Number(o);return isNaN(l)?null:l},resolveOptionMetadata:(r,a)=>{const o=pe(e,r);if(!o)return null;const l=o.value;if(!l)return null;const s="options"in o.properties?o.properties.options:void 0;if(!Array.isArray(s))return null;const i=s.find(u=>u.value===l||u.label===l);if(!(i!=null&&i.metadata))return null;const d=i.metadata[a];if(d==null)return null;const c=Number(d);return isNaN(c)?null:c},resolveRepeaterValues:r=>{for(const a of Object.keys(e.components)){const o=e.components[a];if(o.type!=="repeater"||!o.addedComponents||!o.components)continue;const l=o.components.findIndex(i=>i.uuid===r);if(l===-1)continue;const s=[];for(const i of o.addedComponents){const d=i[l];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 rt(e){var r,a;const t=e.calculationResults??{};for(const o of Object.values(e.components))if(o.type==="computed"&&((r=o.properties)!=null&&r.formula)){const l=$e(e,t),s=P.evaluateFormula(o.properties.formula,l);o.value=s}for(const o of Object.values(e.components))if((o.type==="repeater"||o.type==="group")&&o.addedComponents&&o.components)for(let l=0;l<o.addedComponents.length;l++){const s=o.addedComponents[l];for(let i=0;i<s.length;i++){const d=s[i],c=o.components[i];if((c==null?void 0:c.type)==="computed"&&((a=c.properties)!=null&&a.formula)){const u=o.type==="repeater"?$t(e,t,o.uuid,l):$e(e,t),p=P.evaluateFormula(c.properties.formula,u);d.value=p}}}}function xn(e,t){var s,i;const r=e.computedByDependency;if(!r)return!1;const a=r[t];if(!a||a.length===0)return!1;const o=e.calculationResults??{};let l=!1;for(const d of a){const c=e.components[d];if(c&&c.type==="computed"&&((s=c.properties)!=null&&s.formula)){const u=$e(e,o),p=P.evaluateFormula(c.properties.formula,u);c.value!==p&&(e.components[d]={...c,value:p},l=!0);continue}for(const u of Object.values(e.components))if((u.type==="repeater"||u.type==="group")&&u.components&&u.addedComponents){const p=u.components.findIndex(f=>f.uuid===d);if(p===-1)continue;const m=u.components[p];if((m==null?void 0:m.type)!=="computed"||!((i=m.properties)!=null&&i.formula))continue;for(let f=0;f<u.addedComponents.length;f++){const v=u.addedComponents[f][p];if(!v)continue;const y=u.type==="repeater"?$t(e,o,u.uuid,f):$e(e,o),b=P.evaluateFormula(m.properties.formula,y);v.value!==b&&(u.addedComponents[f][p]={...v,value:b},l=!0)}}}return l}const Be=(e,t)=>{for(const r of e.screenOrder)if(e.screens[r].components.some(o=>o.uuid===t))return r;return null},gn=(e,t)=>{if(!t.includes(":"))return null;const r=t.split(":");if(r.length!==3)return null;const a=r[0],o=parseInt(r[2]),l=e.components[a];if(!l||l.type!=="repeater"||!l.components)return null;const s=l.components[o];return(s==null?void 0:s.uuid)??null},Ct=(e,t,r,a,o)=>{const l=t(),s=l.groupComponentMap[r]??r,i=ot(e,t,s),d=nt(l,r,a),c=Be(l,o),u={components:{...l.components},validationErrors:d};if(i&&(u.conditionResults=i),c){const b={...l,...u};u.screenValidity={...l.screenValidity,[c]:ue(b,c)}}const p={...l,...u},m=r.includes(":")?gn(p,r):null,f=[],v=b=>{if(xn(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=Xe(p,s);if(m&&m!==s){const b=y?{...p,calculationResults:y}:p,_=Xe(b,m);_&&(y=_)}for(const b of f){const _=y?{...p,calculationResults:y}:p,w=Xe(_,b);w&&(y=w)}y&&(u.calculationResults=y),e(u)},yn=(e,t)=>({updateComponentValue:(r,a)=>{var s,i;const o=t();if(r.includes(":")){const d=r.split(":"),c=d[0],u=parseInt(d[1]),p=parseInt(d[2]),m=o.components[c];if(!((i=(s=m==null?void 0:m.addedComponents)==null?void 0:s[u])!=null&&i[p]))return;const f=m.addedComponents[u][p].value!==a;if(m.addedComponents[u][p]={...m.addedComponents[u][p],value:a},f){Ct(e,t,r,m.addedComponents[u][p],c);return}e({components:{...o.components}});return}const l=o.components[r];if(l){if(l.type==="group"||l.type==="repeater"){e({components:{...o.components}});return}if(a===l.value){e({selectionTick:t().selectionTick+1});return}l.value=a,Ct(e,t,r,l,r)}},addGroupIteration:r=>{const a=t(),o=a.components[r];if(!o||o.type!=="group"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l={...a.conditionsByDependency},s=o.components.map((c,u)=>{const p=oe(c);if(p.uuid=[r,o.addedComponents.length,u].join(":"),a.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,ce(l,p.uuid,f,"component"))}const m=J(p);return p.valid=m.length===0,p});o.addedComponents.push(s);const i=Be(a,r),d={...a.screenValidity};return i&&(d[i]=ue({...a},i)),e({components:{...a.components},groupComponentMap:{...a.groupComponentMap},conditionsByDependency:l,screenValidity:d}),o.addedComponents},addRepeaterIteration:r=>{const a=t(),o=a.components[r];if(!o||o.type!=="repeater"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l={...a.conditionsByDependency},s=o.components.map((p,m)=>{const f=oe(p);if(f.uuid=[r,o.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,ce(l,f.uuid,y,"component"))}const v=J(f);return f.valid=v.length===0,f});o.addedComponents.push(s);const i=Be(a,r),d={...a.screenValidity};i&&(d[i]=ue({...a},i));const c={...a,components:{...a.components}};rt(c);const u=st(c);return e({components:{...a.components},conditionsByDependency:l,screenValidity:d,calculationResults:u}),o.addedComponents},removeRepeaterIteration:(r,a)=>{var y;const o=t(),l=o.components[r];if(!l||l.type!=="repeater"||!l.addedComponents)return;const s=((y=l.properties)==null?void 0:y.minIterations)??1;if(l.addedComponents.length<=s)return;const i=l.addedComponents[a],d=new Set(i.map(b=>b.uuid));l.addedComponents.splice(a,1);const c={...o.conditionsByDependency},u={...o.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=a;b<l.addedComponents.length;b++)l.addedComponents[b].forEach((_,w)=>{const C=_.uuid,k=[r,b,w].join(":");if(C!==k){_.uuid=k,C in u&&(u[k]=u[C],delete u[C]),C in c&&(c[k]=c[C],delete c[C]);for(const E of Object.values(c))for(const S of E)S.target===C&&(S.target=k)}});const p=Be(o,r),m={...o.screenValidity};p&&(m[p]=ue({...o},p));const f={...o,components:{...o.components}};rt(f);const v=st(f);e({components:{...o.components},conditionsByDependency:c,validationErrors:u,screenValidity:m,calculationResults:v})}}),pe=(e,t)=>Vt(e.components,t),ce=(e,t,r,a)=>{const o=new Set;for(const s of r.when.rules)o.add(s.source);const l={target:t,type:a,config:r};for(const s of o)e[s]||(e[s]=[]),e[s].push(l)},jn=(e,t)=>{var r,a;return t.includes(":")?(r=pe(e,t))==null?void 0:r.value:(a=e.components[t])==null?void 0:a.value},He=(e,t)=>P.evaluateConditionConfig(t,(r,a)=>(a==null?void 0:a.sourceType)==="context"?e.externalContext[a.source]:jn(e,r)),ot=(e,t,r)=>{const a=t(),o=a.conditionsByDependency[r];if(!o||o.length===0)return null;let l=!1;const s={...a.conditionResults};for(const i of o){const d=He(a,i.config);s[i.target]!==d&&(s[i.target]=d,l=!0)}return l?s:null},_n=e=>{const t={},r=new Set;for(const a of Object.values(e.conditionsByDependency))for(const o of a)r.has(o.target)||(r.add(o.target),t[o.target]=He(e,o.config));return t},wn=e=>{if(!e||Ae(e.type))return null;const t="label"in e.properties?e.properties.label:"",r={uuid:e.uuid,type:e.type,value:e.value};return t&&(r.label=t),r},Pt=e=>{if(e.conditions&&"when"in e.conditions)return e.conditions},Ft=(e,t)=>{const r=wn(e);return r?((e.type==="group"||e.type==="repeater")&&e.addedComponents&&(r.components=e.addedComponents.map(a=>a.filter(o=>!P.isHiddenByCondition(Pt(o),t.conditionResults[o.uuid])).map(o=>Ft(o,t)).filter(o=>o!==null))),r):null},Cn=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},r=o=>{const l=e.screens[o];if(!l)return!1;const s=l.conditions&&"when"in l.conditions?l.conditions:void 0;return P.isHiddenByCondition(s,e.conditionResults[o])};t.screens=e.screenOrder.filter(o=>!r(o)).map(o=>{const l=e.screens[o],s={uuid:o,components:l.components.map(i=>{const d=e.components[i.uuid];if(!d)return null;const c=Pt(d);return P.isHiddenByCondition(c,e.conditionResults[i.uuid])?null:Ft(d,e)}).filter(i=>i!==null)};return l.label&&(s.label=l.label),s});const a=e.calculations??[];if(a.length>0){const o=e.calculationResults??{};t.calculations=a.map(l=>{const s=o[l.uuid]??null,i={uuid:l.uuid,label:l.label,value:s};return s!==null&&(i.formattedValue=P.formatCalculationResult(s,l.format,l.decimalPlaces,l.currencySymbol)),i})}return t},we=g.createContext(null);function A(e){const t=g.useContext(we);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return ne.useStore(t,e)}const Ne=()=>{const e=g.useContext(we);if(!e)throw new Error("useFBREStoreApi must be used within an FBRE provider");return e},Re=e=>!e||Object.keys(e).length===0?null:"when"in e?e:null,Nn=[],kn=()=>ne.createStore((e,t)=>({flowUUID:"",metadata:{},config:{},externalContext:{},screenOrder:[],screens:{},screenValidity:{},components:{},groupComponentMap:{},templateComponentMap:{},conditionsByDependency:{},conditionResults:{},validationErrors:{},validationsByDependency:{},calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},selectionTick:0,loadFlow:(r,a,o)=>{const l={},s=[],i={},d={},c={},u={},p={},m={},f={};r.screens.forEach(S=>{const R=Re(S.conditions),I=R?{...S,conditions:R}:{...S};l[S.uuid]=I,s.push(S.uuid),R&&ce(u,S.uuid,R,"screen"),S.components.forEach(x=>{const h=Re(x.conditions),j=oe(x);h&&(j.conditions=h),i[x.uuid]=j,h&&ce(u,x.uuid,h,"component");const N=te.getValidationConfig(j);if(N&&ye(p,x.uuid,N),(x.type==="group"||x.type==="repeater")&&x.components){const L=i[x.uuid];L.addedComponents||(L.addedComponents=[]);const V=x.type==="repeater"?x.properties.initialData:void 0,M=x.type==="repeater"?x.properties.minIterations:void 0,B=V?V.length:x.type==="repeater"&&M&&M>1?M:1;for(let F=0;F<B;F++){const X=x.components.map((Y,Z)=>{const K=oe(Y);K.uuid=[x.uuid,L.addedComponents.length,Z].join(":"),V&&V[F]&&Y.uuid in V[F]&&(K.value=V[F][Y.uuid]),x.type==="group"&&(d[K.uuid]=Y.uuid),F===0&&(c[Y.uuid]=K.uuid);const ae=Re(K.conditions);ae&&(K.conditions=ae,ce(u,K.uuid,ae,"component"));const T=te.getValidationConfig(K);T&&ye(p,K.uuid,T);const q=J(K);return K.valid=q.length===0,q.length>0&&(m[K.uuid]=q),K});L.addedComponents.push(X)}}})}),a&&a.screens.forEach(S=>{const R=s.indexOf(S.uuid);R<0||S.components.forEach(I=>{const x=i[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=r.screens[R].components.find(D=>D.uuid===x.uuid);for(let D=0;D<j;D++)if(N!=null&&N.components){const L=N.components.map((V,M)=>{const B=oe(V);B.uuid=[x.uuid,x.addedComponents.length,M].join(":"),x.type==="group"&&(d[B.uuid]=V.uuid),c[V.uuid]||(c[V.uuid]=B.uuid);const F=Re(B.conditions);F&&(B.conditions=F,ce(u,B.uuid,F,"component"));const X=te.getValidationConfig(B);X&&ye(p,B.uuid,X);const Y=J(B);return B.valid=Y.length===0,Y.length>0&&(m[B.uuid]=Y),B});x.addedComponents.push(L)}}I.components.forEach(h=>{h.forEach(j=>{for(const N of x.addedComponents){const D=N.find(L=>L.uuid===j.uuid);if(D){D.value=j.value;const L=J(D);D.valid=L.length===0,m[D.uuid]=L;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(i)){const R=i[S];if(!(R.type==="group"||R.type==="repeater")&&te.getValidationConfig(R)&&!(S in m)){const I=J(R);R.valid=I.length===0,I.length>0&&(m[S]=I)}}const v={...t(),externalContext:o??{},screens:l,screenOrder:s,components:i,groupComponentMap:d,templateComponentMap:c,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},y=_n(v);v.conditionResults=y,s.forEach(S=>{f[S]=ue(v,S)});const b=vn(i),_={...v,computedByDependency:b,calculationResults:{},screenValidity:f};rt(_);const w=r.calculations??[],C=bn(w),k={..._,calculations:w},E=st(k);e({flowUUID:r.uuid,metadata:r.metadata,config:r.config??{},externalContext:o??{},screens:l,screenOrder:s,components:i,groupComponentMap:d,templateComponentMap:c,conditionsByDependency:u,conditionResults:y,screenValidity:f,validationErrors:m,validationsByDependency:p,calculations:w,calculationResults:E,calculationsByDependency:C,computedByDependency:b})},updateContext:r=>{const a=t(),o=a.externalContext,l=[];for(const c of Object.keys(r))o[c]!==r[c]&&l.push(c);for(const c of Object.keys(o))!(c in r)&&!l.includes(c)&&l.push(c);if(l.length===0)return;const s={...a.conditionResults};let i=!1;const d=new Set;for(const c of l){const u=a.conditionsByDependency[c];if(!(!u||u.length===0))for(const p of u){if(d.has(p.target))continue;d.add(p.target);const m={...a,externalContext:r},f=He(m,p.config);s[p.target]!==f&&(s[p.target]=f,i=!0)}}if(i){const c={...a,conditionResults:s},u={};for(const p of a.screenOrder)u[p]=ue(c,p);e({externalContext:r,conditionResults:s,screenValidity:u})}else e({externalContext:r})},...yn(e,t),getFlowData:()=>Cn(t()),getScreenByIndex:r=>{const a=t();return r<0||r>=a.screenOrder.length?null:a.screens[a.screenOrder[r]]},getScreenValidity:r=>{const a=t();return r<0||r>=a.screenOrder.length?!0:a.screenValidity[a.screenOrder[r]]??!0},getValidationErrors:r=>t().validationErrors[r]??Nn,evaluateFlowValidation:()=>{const r=t(),a={};let o=!0;return r.screenOrder.forEach(l=>{const s=ue(r,l);a[l]=s,s||(o=!1)}),e({screenValidity:a}),o},getMaxScreenIndex:()=>t().screenOrder.length-1,getCalculationResult:r=>t().calculationResults[r]??null})),Sn=({uuid:e})=>{var i;const t=A(d=>d.components[e]),r=A(d=>d.conditionResults[e]);if(!t)return null;const a=t.conditions&&"when"in t.conditions?t.conditions:void 0;if(P.isHiddenByCondition(a,r))return null;const o=Bt(t.type);if(!o)return console.warn(`FBRE: No renderer for component type "${t.type}"`),null;const l=(i=t.properties)==null?void 0:i.width,s=l&&l!=="full"?`fbre-component fbre-width-${l}`:"fbre-component";return n.jsx("div",{className:s,"data-uuid":e,children:n.jsx(o,{uuid:e})})},at=({screenIndex:e})=>{const t=A(r=>{const a=r.screenOrder[e];return a?r.screens[a]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(r=>n.jsx(Sn,{uuid:r.uuid},r.uuid))}):null},se=({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"})}),be=({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"})]}),lt=({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"})]}),ke=({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"})}),En=({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"})}),Rn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"})}),Dn=({size:e=16})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})}),Tn=({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"})}),In=({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"})}),ct=({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"})}),Ln=({size:e=16})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"})}),Mn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),n.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),On=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("polyline",{points:"9,12 11.5,14.5 16,9.5"})]}),Bn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),Vn=({size:e=16})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3,6 5,6 21,6"}),n.jsx("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"})]}),An=({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"})]}),$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:"M3 11l18-5v12L3 13v-2z"}),n.jsx("path",{d:"M11.6 16.8a3 3 0 11-5.8-1.6"})]}),Pn=({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"})]}),Fn=({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"})}),Un=({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"})]}),Ut=({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"})}),Hn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("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"})]}),qn=({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"})}),zn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polygon",{points:"13,2 3,14 12,14 11,22 21,10 12,10 13,2"})}),Kn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M12 20h9"}),n.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 013 3L7 19l-4 1 1-4L16.5 3.5z"})]}),Wn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("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"})]}),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:"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"})]}),Gn=({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"})}),Xn=({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)"})}),Je={info:Mn,check:On,warning:Bn,question:Wn,lightbulb:An,megaphone:$n,bell:Pn,shield:Fn,lock:Un,heart:Ut,flag:Hn,bookmark:qn,zap:zn,pencil:Kn,star:ct},Jn={star:ct,heart:Ut,thumbsUp:Yn,circle:Gn,diamond:Xn},De=({position:e,screenIndex:t,maxScreenIndex:r,allowInvalidTransition:a,screenValidity:o,summaryEnabled:l,summaryActive:s,atMaxScreen:i,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(Dn,{}),c||"Back"]})}const y=l?i&&s:i,b=l?i?s?"Done":"Review":"Next":i?"Done":"Next";if(r===0){const C=l?s?"Complete":"Review":"Complete",k=v||!o;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:k,onClick:()=>{l&&!s?p():f()},children:[d||C,v?n.jsx("span",{className:"fbre-btn__spinner"}):n.jsx(se,{size:16})]})}const _=v||!a&&!o||b==="Done"&&!o,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(se,{size:16}):n.jsx(Tn,{})]})},Qn=({current:e,total:t,stepperStyle:r})=>{if(t<=1)return null;const a=t>1?e/(t-1)*100:100,l=!!r&&r!=="default"||t<=6;return n.jsxs(n.Fragment,{children:[l&&n.jsx("div",{className:"fbre-stepper fbre-stepper--dots",children:Array.from({length:t},(s,i)=>n.jsx("div",{className:`fbre-stepper__dot${i===e?" active":i<e?" completed":""}`},i))}),l&&n.jsxs("div",{className:"fbre-stepper fbre-stepper--bar-alt",children:[n.jsx("div",{className:"fbre-stepper__track",children:n.jsx("div",{className:"fbre-stepper__fill",style:{width:`${a}%`}})}),n.jsxs("span",{className:"fbre-stepper__counter",children:[e+1," of ",t]})]}),!l&&n.jsx("div",{className:"fbre-stepper fbre-stepper--bar",children:n.jsx("div",{className:"fbre-stepper__fill",style:{width:`${a}%`}})})]})},Zn=({current:e,total:t})=>t<=1?null:n.jsxs("div",{className:"fbre-stepper-text",children:["Step ",e+1," of ",t]}),es=e=>{const t=e.controlsLayout??"default",a=e.showStepper!==!1&&(e.stepperStyle??"default")!=="text"&&e.maxScreenIndex>0,o=e.screenIndex>0||e.summaryActive,l=o?2:1,s=a?n.jsx(Qn,{current:e.screenIndex,total:e.maxScreenIndex+1,stepperStyle:e.stepperStyle}):null;if(t==="default"){const i=!o&&!a;return n.jsxs("div",{className:"fbre-controls fbre-controls--default","data-button-count":l,"data-solo":i?"true":void 0,children:[o?n.jsx(De,{position:"back",...e}):n.jsx("div",{}),s??n.jsx("div",{}),n.jsx(De,{position:"next",...e})]})}return n.jsxs("div",{className:`fbre-controls fbre-controls--${t}`,"data-button-count":l,children:[s&&n.jsx("div",{className:"fbre-controls__stepper",children:s}),n.jsxs("div",{className:"fbre-controls__row",children:[o&&n.jsx(De,{position:"back",...e}),n.jsx(De,{position:"next",...e})]})]})},Ht=({component:e})=>{const{uuid:t,label:r,type:a,value:o,components:l}=e,s=()=>{if(o!=null)switch(a){case"fileUpload":return o.name;case"inputText":case"inputTextArea":case"inputNumber":case"dropDown":case"radio":case"rating":case"slider":return o.toString();case"computed":return typeof o=="number"?o.toString():"—";case"toggleSwitch":return o?"Yes":"No";case"checkbox":case"dropDownMulti":return o.length===0?"No options selected":o.join(", ")}return"No response given"};if(a==="signature"&&o){const c=typeof o=="string"&&o.startsWith("data:");return n.jsxs("div",{className:"fbre-summary__item",children:[n.jsx("div",{className:"fbre-summary__item-label",children:r}),n.jsx("div",{className:"fbre-summary__item-value",children:c?n.jsx("img",{src:o,alt:"Signature",style:{maxWidth:"100%",maxHeight:80}}):n.jsx("span",{style:{fontFamily:'"Brush Script MT", "Segoe Script", "Dancing Script", cursive',fontSize:24},children:o})})]})}const i=()=>l?l.map((c,u)=>n.jsx("div",{children:c.map(p=>n.jsx(Ht,{component:p},p.uuid))},`${t}-${u}`)):null,d=o==null||typeof o=="string"&&o.length===0||Array.isArray(o)&&o.length===0;return n.jsxs("div",{className:`fbre-summary__item${a==="group"||a==="repeater"?" fbre-summary__item--group":""}`,children:[n.jsx("div",{className:"fbre-summary__item-label",children:r}),a!=="group"&&a!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${d?" fbre-summary__item-value--empty":""}`,children:s()}),(a==="group"||a==="repeater")&&i()]})},Qe=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ve=(e,t)=>{const r=e.replace(P.REF_REGEX,(a,o)=>{const l=t.resolveCalculation(o);if(l!==null)return Qe(l);const s=t.resolveComponentValue(o);if(s!==null)return Qe(s);const i=t.resolveContext(o);return i!==null?Qe(i):""});return P.convertMarkupToHTML(r)},fe=(e,t)=>e.replace(P.REF_REGEX,(r,a)=>{const o=t.resolveCalculation(a);if(o!==null)return o;const l=t.resolveComponentValue(a);if(l!==null)return l;const s=t.resolveContext(a);return s!==null?s:""});function me(){const e=A(l=>l.components),t=A(l=>l.templateComponentMap),r=A(l=>l.calculations),a=A(l=>l.calculationResults),o=A(l=>l.externalContext);return g.useMemo(()=>{const l=new Map(r.map(i=>[i.uuid,i])),s=i=>{var m,f;const d=e[i];if(d)return d;const c=t[i];if(!c)return;const u=c.split(":"),p=e[u[0]];return(f=(m=p==null?void 0:p.addedComponents)==null?void 0:m[parseInt(u[1])])==null?void 0:f[parseInt(u[2])]};return{resolveComponentValue:i=>{const d=s(i);if(!d)return null;const c=d.value;return c==null||c===""?null:Array.isArray(c)?c.join(", "):String(c)},resolveCalculation:i=>{const d=l.get(i);if(!d)return null;const c=a[i]??null;return P.formatCalculationResult(c,d.format,d.decimalPlaces,d.currencySymbol)},resolveContext:i=>{const d=o[i];return d==null||d===""?null:String(d)}}},[e,t,r,a,o])}const ts=({screen:e,showToggle:t})=>{const r=me(),[a,o]=g.useState(!0);return n.jsxs("div",{children:[n.jsxs("div",{className:"fbre-summary__screen-header",onClick:()=>t&&o(!a),children:[e.label&&n.jsx("span",{className:"fbre-summary__screen-label",children:fe(e.label,r)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${a?"":" collapsed"}`,children:n.jsx(ke,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${a?"":" collapsed"}`,children:e.components.map(l=>n.jsx(Ht,{component:l},l.uuid))})]})},Nt=()=>{const e=Ne(),t=A(o=>o.components),r=g.useMemo(()=>e.getState().getFlowData(),[e,t]),a=r.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:r.screens.map(o=>n.jsx(ts,{screen:o,showToggle:a>1},o.uuid))})]})},qt=({title:e,body:t})=>{const r=me();return n.jsxs("div",{className:"fbre-confirmation",children:[e&&n.jsx("h2",{className:"fbre-confirmation__title",dangerouslySetInnerHTML:{__html:ve(e,r)}}),t&&n.jsx("div",{className:"fbre-confirmation__body",dangerouslySetInnerHTML:{__html:ve(t,r)}})]})},zt=(e,t,r)=>t?!P.isHiddenByCondition(t,r[e]):!0,Pe=(e,t)=>{const r=e.screenOrder.length-1;let a=t+1;for(;a<=r;){const o=e.screenOrder[a],l=e.screens[o],s=l!=null&&l.conditions&&"when"in l.conditions?l.conditions:void 0;if(zt(o,s,e.conditionResults))return a;a++}return null},ns=(e,t)=>{let r=t-1;for(;r>=0;){const a=e.screenOrder[r],o=e.screens[a],l=o!=null&&o.conditions&&"when"in o.conditions?o.conditions:void 0;if(zt(a,l,e.conditionResults))return r;r--}return 0};function W(e,t,r){return`color-mix(in srgb, ${e} ${t}%, ${r})`}const Q="var(--fbre-bg)",Te="var(--fbre-text)";function Kt(e){const t={};if(!e)return t;if(e.color){const r="var(--fbre-theme-color)";t["--fbre-theme-color"]=e.color,t["--fbre-theme-light"]=W(r,14,Q),t["--fbre-theme-dark"]=W(r,82,"#000")}if(e.background&&(t["--fbre-bg"]=e.background),e.surface){const r="var(--fbre-surface)";t["--fbre-surface"]=e.surface,t["--fbre-surface-hover"]=W(r,96,Te),t["--fbre-surface-subtle"]=W(r,90,Te),t["--fbre-surface-alt"]=W(r,82,Te),t["--fbre-control-surface"]=r,t["--fbre-input-bg"]=r,t["--fbre-input-bg-focus"]=W(r,60,Q)}if(e.text){const r="var(--fbre-text)";t["--fbre-text"]=e.text,t["--fbre-text-secondary"]=W(r,64,Q),t["--fbre-label"]=W(r,64,Q),t["--fbre-text-placeholder"]=W(r,42,Q),t["--fbre-text-disabled"]=W(r,34,Q)}if(e.border){const r="var(--fbre-border)";t["--fbre-border"]=e.border,t["--fbre-border-hover"]=W(r,70,Te),t["--fbre-border-light"]=W(r,60,Q),t["--fbre-border-subtle"]=W(r,35,Q)}return e.radius&&(t["--fbre-radius"]=e.radius),e.fontFamily&&(t["--fbre-font"]=e.fontFamily),e.error&&(t["--fbre-error"]=e.error,t["--fbre-error-light"]=W("var(--fbre-error)",14,Q)),e.success&&(t["--fbre-success"]=e.success,t["--fbre-success-bg"]=W("var(--fbre-success)",14,Q),t["--fbre-success-border"]=W("var(--fbre-success)",40,Q)),e.warning&&(t["--fbre-warning"]=e.warning,t["--fbre-warning-bg"]=W("var(--fbre-warning)",14,Q),t["--fbre-warning-border"]=W("var(--fbre-warning)",40,Q)),t}const ss=new Set(["text","header","callout","divider","table","computed"]);function Wt(e,t){const r=e.screenOrder[t];if(!r)return 0;const a=e.screens[r];if(!a)return 0;let o=0;for(const l of a.components){const s=e.components[l.uuid];if(!s||ss.has(s.type))continue;const i=s.conditions&&"when"in s.conditions?s.conditions:void 0;P.isHiddenByCondition(i,e.conditionResults[l.uuid])||(o+=1)}return o}const dt=new Set(["radio","yesNo","cardSelect","dropDown"]),rs=500;function Yt(e,t,r){const a=Ne(),o=g.useRef(null),l=g.useRef(""),s=g.useRef(0);g.useEffect(()=>{if(!e)return;const i=a.getState(),d=kt(i,t);d&&(l.current=St(i.components,d)),s.current=i.selectionTick},[e,t,a]),g.useEffect(()=>{if(!e)return;const i=a.subscribe(d=>{const c=kt(d,t);if(!c)return;const u=d.selectionTick,p=u!==s.current;p&&(s.current=u);const m=St(d.components,c);if(m===l.current&&!p)return;const f=l.current;if(l.current=m,!(m!==f?os(d.components,c,f):p&&as(d.components,c))||Pe(d,t)===null)return;const b=d.screenOrder[t];b&&d.screenValidity[b]===!1||Wt(d,t)===1&&(o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{o.current=null,r()},rs))});return()=>{i(),o.current&&(clearTimeout(o.current),o.current=null)}},[e,t,a,r]),g.useEffect(()=>()=>{o.current&&(clearTimeout(o.current),o.current=null)},[t])}function kt(e,t){const r=e.screenOrder[t];if(!r)return null;const a=e.screens[r];return a?a.components.map(o=>o.uuid):null}function St(e,t){const r=[];for(const a of t){const o=e[a];!o||!dt.has(o.type)||r.push(`${a}=${JSON.stringify(o.value??null)}`)}return r.join("|")}function os(e,t,r){const a=new Map;for(const o of r.split("|")){const l=o.indexOf("=");l>0&&a.set(o.slice(0,l),o.slice(l+1))}for(const o of t){const l=e[o];if(!l||!dt.has(l.type))continue;const s=JSON.stringify(l.value??null),i=a.get(o)??"null";if(s!==i&&s!=="null")return!0}return!1}function as(e,t){for(const r of t){const a=e[r];if(!(!a||!dt.has(a.type))&&a.value!==null&&a.value!==void 0)return!0}return!1}function Gt(e,t,r){const a=Ne();g.useEffect(()=>{if(!e)return;const o=l=>{if(l.key!=="Enter")return;const s=l.target;if(s.tagName!=="INPUT"||!s.closest(".fbre-container"))return;const i=a.getState();if(Pe(i,t)===null)return;const c=i.screenOrder[t];c&&i.screenValidity[c]===!1||Wt(i,t)===1&&(l.preventDefault(),r())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[e,t,r,a])}const Xt=g.createContext(null),Et=[],U=e=>{const t=g.useContext(Xt),r=A(i=>{var d;return(d=i.components[e])==null?void 0:d.value}),a=A(i=>{var d;return(d=i.components[e])==null?void 0:d.properties}),o=A(i=>{var d;return(d=i.components[e])==null?void 0:d.valid}),l=A(i=>i.validationErrors[e]??Et),s=A(i=>i.updateComponentValue);return t?{value:t.value,properties:t.properties,valid:t.valid,validationErrors:Et,updateValue:s}:{value:r,properties:a,valid:o,validationErrors:l,updateValue:s}},xe=(e,t)=>U(e),ls=({uuid:e})=>{const{properties:t}=xe(e),r=me(),a=t==null?void 0:t.value;if(!a)return null;const o=fe(a,r);return n.jsx("h2",{className:"fbre-header",children:o})};$("header",ls);const is=({uuid:e})=>{const{properties:t}=xe(e),r=me(),a=t==null?void 0:t.value;return a==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:ve(a,r)}})};$("text",is);const cs=({uuid:e})=>{const{properties:t}=xe(e),r=(t==null?void 0:t.textAlign)??"center",a=r==="left"?" fbre-divider--left":r==="right"?" fbre-divider--right":"";return n.jsx("div",{className:`fbre-divider${a}`,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",cs);const ds={info:"info",success:"check",warning:"warning",neutral:void 0},us=({uuid:e})=>{const{properties:t}=xe(e),r=me(),a=t==null?void 0:t.value,o=t==null?void 0:t.title,l=(t==null?void 0:t.variant)??"info",s=t==null?void 0:t.icon;if(!a&&!o)return null;let i;if(s==="none")i=void 0;else if(s&&Je[s])i=Je[s];else{const c=ds[l];i=c?Je[c]:void 0}const d=`fbre-callout fbre-callout--${l}`;return n.jsxs("div",{className:d,children:[i&&n.jsx("span",{className:"fbre-callout__icon",children:n.jsx(i,{})}),n.jsxs("div",{className:"fbre-callout__content",children:[o&&n.jsx("div",{className:"fbre-callout__title",children:fe(o,r)}),a&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:ve(a,r)}})]})]})};$("callout",us);const ps=({uuid:e})=>{const{properties:t}=xe(e),r=t==null?void 0:t.label,a=t==null?void 0:t.columns,o=t==null?void 0:t.rows,l=t==null?void 0:t.highlightColumn,s=l?l-1:-1;return!a||!o||a.length===0?null:n.jsxs("div",{className:"fbre-table",children:[r&&n.jsx("div",{className:"fbre-table__label",children:r}),n.jsxs("table",{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"fbre-table__row-label"}),a.map((i,d)=>n.jsx("th",{className:s===d?"fbre-table__col fbre-table__col--highlight":"fbre-table__col",children:i.label},d))]})}),n.jsx("tbody",{children:o.map((i,d)=>n.jsxs("tr",{children:[n.jsx("td",{className:"fbre-table__row-label",children:i.label}),a.map((c,u)=>n.jsx("td",{className:s===u?"fbre-table__cell fbre-table__cell--highlight":"fbre-table__cell",children:i.values[u]??""},u))]},d))})]})]})};$("table",ps);const fs=({uuid:e})=>{const{properties:t,value:r}=xe(e),a=t==null?void 0:t.label,o=(t==null?void 0:t.showLabel)!==!1,l=t==null?void 0:t.detail,s=t==null?void 0:t.format,i=t==null?void 0:t.decimalPlaces,d=t==null?void 0:t.currencySymbol,c=P.formatCalculationResult(typeof r=="number"?r:null,s,i,d);return n.jsxs("div",{className:"fbre-computed",children:[o&&a&&n.jsx("div",{className:"fbre-computed__label",children:a}),n.jsx("div",{className:"fbre-computed__value",children:c||"—"}),l&&n.jsx("div",{className:"fbre-computed__detail",children:l})]})};$("computed",fs);const Jt=({text:e})=>{var d;const[t,r]=g.useState(!1),a=g.useRef(null),o=g.useRef(null),[l,s]=g.useState(null),i=g.useCallback(()=>{if(!a.current)return;const c=a.current.getBoundingClientRect();s({top:c.bottom+4,left:c.right})},[]);return g.useEffect(()=>{if(!t)return;i();const c=p=>{const m=p.target;a.current&&!a.current.contains(m)&&o.current&&!o.current.contains(m)&&r(!1)},u=()=>i();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,i]),n.jsxs(n.Fragment,{children:[n.jsx("button",{ref:a,type:"button",className:"fbre-tooltip-trigger",onClick:()=>r(!t),"aria-label":"Help",children:n.jsx(In,{})}),t&&l&&fn.createPortal(n.jsx("div",{ref:o,className:"fbre-tooltip-popover open",style:{top:l.top,left:l.left},children:n.jsx("span",{dangerouslySetInnerHTML:{__html:P.convertMarkupToHTML(e)}})}),((d=a.current)==null?void 0:d.closest(".fbre-container"))??document.body)]})},z=({label:e,detail:t,showLabel:r,required:a,helperText:o,tooltip:l,inputId:s,externalFocused:i,error:d,errorMessages:c,children:u})=>{const p=me(),[m,f]=g.useState(!1);g.useEffect(()=>{i!==void 0&&f(i)},[i]);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:ve(t,p)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[e&&(!t||t.length===0||r)&&n.jsxs("label",{className:"fbre-field__label",htmlFor:s,children:[fe(e,p),a&&n.jsx("span",{className:"required",children:"*"})]}),u({focused:m,setFocused:f}),o&&n.jsx("div",{className:"fbre-field__helper",children:fe(o,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)"]})]})})()]}),l&&n.jsx(Jt,{text:l})]})]})},ms=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,i=g.useRef(null),[d,c]=g.useState(!1);if(!s)return null;const u=t!=null&&a===!1,p=s.inputType==="password",m=p&&d?"text":s.inputType??"text",f=`fbre-input-${e}`;return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:f,error:u,errorMessages:u?o: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:i,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=>l(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(En,{}):n.jsx(Rn,{})})]})})};$("inputText",ms);const hs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r;if(!s)return null;const i=t!=null&&a===!1,d=`fbre-input-${e}`;return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:d,error:i,errorMessages:i?o: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=>l(e,u.target.value),onFocus:()=>c(!0),onBlur:()=>c(!1)})})};$("inputTextArea",hs);const bs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(t??"");if(!s)return null;const c=t!=null&&a===!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(""),l(e,"");return}v.test(w.target.value)&&(d(w.target.value),l(e,w.target.value))},_=w=>{w(!1);const C=m(String(i));C!==String(i)&&(d(C),l(e,C))};return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:p,error:c,errorMessages:c?o: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:i,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,l(e,b))};return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,inputId:p,error:c,errorMessages:c?o: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=>l(e,y.target.value),onFocus:()=>v(!0),onBlur:y=>f(y,v)})]})})};$("inputNumber",bs);function qe(e,t,r){g.useEffect(()=>{if(!t)return;const a=o=>{e.current&&!e.current.contains(o.target)&&r()};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[t,e,r])}function Qt(e){let t=e.parentElement;for(;t;){const{overflow:r,overflowY:a}=getComputedStyle(t);if(/(auto|scroll)/.test(r+a))return t;t=t.parentElement}return document.documentElement}function Rt(e,t){const r=Qt(e),a=r===document.documentElement?{top:0,bottom:window.innerHeight}:r.getBoundingClientRect(),o=e.getBoundingClientRect(),l=a.bottom-o.bottom,s=o.top-a.top;return l<t&&s>l}function ze(e,t,r=300){const[a,o]=g.useState(!1);return g.useLayoutEffect(()=>{if(!t||!e.current){o(!1);return}const l=e.current.offsetParent;l&&o(Rt(l,r))},[t,r]),g.useEffect(()=>{if(!t||!e.current)return;const l=()=>{var i;const s=(i=e.current)==null?void 0:i.offsetParent;s&&o(Rt(s,r))};return window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[t,r]),a}const vs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(!1),[c,u]=g.useState(-1),p=g.useRef(null),m=g.useRef(null),f=g.useRef(null),v=g.useRef([]);qe(p,i,g.useCallback(()=>d(!1),[]));const y=ze(f,i,200);if(g.useEffect(()=>{var h;i&&c>=0&&((h=v.current[c])==null||h.focus())},[i,c]),!s)return null;const b=s.readOnly===!0,_=s.options,w=t!=null&&a===!1,C=_.findIndex(h=>h.value.toString()===(t==null?void 0:t.toString())),k=C>=0?_[C]:void 0,E=()=>{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=>{l(e,_[h].value),S(!0)},I=h=>{b||(h.key==="ArrowDown"||h.key==="ArrowUp"||h.key==="Enter"||h.key===" "?(h.preventDefault(),E()):h.key==="Escape"&&i&&(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(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,externalFocused:i,error:w,errorMessages:w?o: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":i,onClick:()=>i?S(!1):E(),onKeyDown:I,children:[k?n.jsx("span",{className:"fbre-dropdown__selected-text",children:k.label}):n.jsx("span",{className:"fbre-dropdown__placeholder",children:"Select..."}),n.jsx("span",{className:`fbre-dropdown__arrow${i?" open":""}`,children:n.jsx(ke,{})})]}),n.jsx("div",{ref:f,role:"listbox",tabIndex:-1,onKeyDown:x,className:`fbre-popup fbre-dropdown__panel${i?" 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:i&&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(se,{})})]},`${e}-${j}`)})})]})})};$("dropDown",vs);const xs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(!1),[c,u]=g.useState(-1),p=g.useRef(null),m=g.useRef(null),f=g.useRef(null),v=g.useRef([]);qe(p,i,g.useCallback(()=>d(!1),[]));const y=ze(f,i,200);if(g.useEffect(()=>{var h;i&&c>=0&&((h=v.current[c])==null||h.focus())},[i,c]),!s)return null;const b=s.readOnly===!0,_=s.options,w=t??[],C=t!=null&&a===!1,k=h=>{const j=h.toString(),N=w.includes(j)?w.filter(D=>D!==j):[...w,j];l(e,N)},E=(h,j)=>{j.stopPropagation(),l(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"&&i&&(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&&k(_[c].value);break;case"Escape":h.preventDefault(),R(!0);break;case"Tab":R(!0);break}};return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,externalFocused:i,error:C,errorMessages:C?o: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":i,tabIndex:b?void 0:0,className:`fbre-dropdown__trigger${b?" fbre-dropdown__trigger--readonly":""}`,onClick:b?void 0:()=>i?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=>E(h,N),children:"×"})]},h)})}):n.jsx("span",{className:"fbre-dropdown__placeholder",children:"Select..."}),n.jsx("span",{className:`fbre-dropdown__arrow${i?" open":""}`,children:n.jsx(ke,{})})]}),n.jsx("div",{ref:f,role:"listbox","aria-multiselectable":"true",tabIndex:-1,onKeyDown:x,className:`fbre-popup fbre-dropdown__panel${i?" 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:i&&j===c?0:-1,className:"fbre-dropdown__option",onClick:()=>k(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(se,{size:12})}),n.jsx("span",{children:h.label})]},`${e}-${j}`)})})]})})};$("dropDownMulti",xs);const Zt=({label:e,detail:t,showLabel:r,required:a,helperText:o,tooltip:l,error:s,errorMessages:i,children:d})=>{const c=me(),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:ve(t,c)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[r!==!1&&(!t||t.length===0)&&n.jsxs("div",{className:"fbre-option-group__label",children:[fe(e,c),a&&n.jsx("span",{className:"required",children:"*"})]}),n.jsx("div",{className:"fbre-option-group__items",children:d}),o&&n.jsx("div",{className:"fbre-option-group__helper",children:fe(o,c)}),(()=>{const p=i==null?void 0:i.filter(m=>m);return s&&p&&p.length>0&&n.jsxs("div",{className:"fbre-field__errors",children:[n.jsx("span",{className:"fbre-field__error-message",children:p[0]}),p.length>1&&n.jsxs("span",{className:"fbre-field__error-more",children:["(and ",p.length-1," more)"]})]})})()]}),l&&n.jsx(Jt,{text:l})]})]})},gs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r;if(!s)return null;const i=s.readOnly===!0,d=t??[],c=t!=null&&a===!1,u=p=>{const m=p.toString(),f=d.includes(m)?d.filter(v=>v!==m):[...d,m];l(e,f)};return n.jsx(Zt,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:c,errorMessages:c?o:void 0,children:s.options.map((p,m)=>{const f=d.includes(p.value.toString());return n.jsxs("label",{className:`fbre-option-item${i?" fbre-option-item--readonly":""}`,children:[n.jsx("input",{type:"checkbox",checked:f,disabled:i,onChange:()=>u(p.value)}),n.jsx("span",{className:"fbre-option-item__box fbre-option-item__box--checkbox",children:n.jsx(se,{})}),n.jsx("span",{className:"fbre-option-item__text",children:p.label})]},`${e}-${m}`)})})};$("checkbox",gs);const ys=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,i=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&&a===!1;return n.jsx(Zt,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:u,errorMessages:u?o: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&&l(e,p.value.toString())},children:[n.jsx("input",{type:"radio",name:e,checked:f,disabled:d,value:p.value.toString(),onChange:v=>l(e,v.target.value)}),n.jsx("span",{className:"fbre-option-item__box fbre-option-item__box--radio",children:i?n.jsx(se,{}):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",ys);const js=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r;if(!s)return null;const i=s.columns??(s.options.length<4?1:2),d=t!=null&&a===!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(${i}, 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:()=>l(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&&o&&o.length>0&&n.jsx("div",{className:"fbre-field__errors",children:o.map((c,u)=>n.jsx("span",{className:"fbre-field__error-message",children:c},u))})]})};$("cardSelect",js);const _s=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=t,i=r,[d,c]=g.useState(null);if(!i)return null;const u=i.max??5,p=i.precision??1,m=d??s??0,f=s!=null&&a===!1,v=i.icon&&Jn[i.icon]||ct,y=(E,S)=>{const R=S&&p<=.5?E+.5:E+1;l(e,R)},b=(E,S)=>{const R=S.currentTarget.getBoundingClientRect(),x=S.clientX-R.left<R.width/2&&p<=.5?E+.5:E+1;c(x)},_=[];for(let E=0;E<u;E++){const S=m>=E+1,R=!S&&m>=E+.5,I=`fbre-rating__star${S?" fbre-rating__star--full":R?" fbre-rating__star--half":""}`;_.push(n.jsx("div",{className:I,onMouseMove:x=>b(E,x),onMouseLeave:()=>c(null),onClick:x=>{const h=x.currentTarget.getBoundingClientRect(),j=x.clientX-h.left<h.width/2;y(E,j)},children:n.jsx(v,{})},E))}const w=p<=.5?.5:1,C=E=>Math.max(0,Math.min(u,E)),k=E=>{const S=s??0;let R=null;switch(E.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&&(E.preventDefault(),l(e,R))};return n.jsx(z,{label:i.label,detail:i.detail,showLabel:i.showLabel,required:i.required,helperText:i.helperText,error:f,errorMessages:f?o:void 0,children:()=>n.jsxs("div",{className:"fbre-rating",children:[n.jsx("div",{className:"fbre-rating__stars",role:"slider",tabIndex:0,"aria-label":i.label??"Rating","aria-valuemin":0,"aria-valuemax":u,"aria-valuenow":s??0,onKeyDown:k,children:_}),s!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[s," / ",u]})]})})};$("rating",_s);const ws=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=t,i=r;if(!i)return null;const d=i.readOnly===!0,c=i.min??0,u=i.max??100,p=i.steps??1,m=(s-c)/(u-c)*100,f=a===!1;return n.jsx(z,{label:i.label,detail:i.detail,showLabel:i.showLabel,required:i.required,helperText:i.helperText,error:f,errorMessages:f?o: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=>l(e,Number(v.target.value))}),n.jsx("span",{className:"fbre-slider__value",children:s})]}),i.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",ws);const Cs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r;if(!s)return null;const i=a===!1;return n.jsx(z,{detail:s.detail,helperText:s.helperText,error:i,errorMessages:i?o:void 0,children:()=>n.jsxs("label",{className:"fbre-toggle",children:[n.jsx("input",{type:"checkbox",checked:t??!1,onChange:d=>l(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",Cs);const je=new Map,Ns=(e,t)=>{je.has(e)||je.set(e,new Set),je.get(e).add(t)},ks=(e,t)=>{var r;(r=je.get(e))==null||r.delete(t)},Dt=(e,t,r)=>{var a;(a=je.get(e))==null||a.forEach(o=>{o(t,r)})},en=g.createContext(null);function tn(){return g.useContext(en)}class Ce extends Error{constructor(t,r,a,o){super(t),this.name="ApiError",this.status=r,this.code=a,this.validationErrors=o}}class nn extends Ce{constructor(t,r){super(`Request timed out after ${r}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const Ss=new Set([502,503,504]),Ie=2,Es=[500,1500];function Rs(e){return new Promise(t=>setTimeout(t,e))}async function ie(e,t,r={}){const o=`${e.apiEndpoint||""}${t}`,l=e.timeout??3e4,s={...r.body?{"Content-Type":"application/json"}:{},...r.headers};e.apiKey&&(s.Authorization=`Bearer ${e.apiKey}`);let i;for(let d=0;d<=Ie;d++){d>0&&await Rs(Es[d-1]);try{const c=new AbortController,u=setTimeout(()=>c.abort(),l);let p;try{p=await fetch(o,{...r,headers:s,signal:c.signal})}finally{clearTimeout(u)}if(!p.ok){const m=await p.json().catch(()=>({})),f=new Ce(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(d<Ie&&Ss.has(p.status)&&f.code!=="INTEGRATION_HOOK_FAILED"){i=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 Ce)throw c;if(c instanceof DOMException&&c.name==="AbortError"){const u=new nn(o,l);if(d<Ie){i=u;continue}throw u}if(c instanceof TypeError&&d<Ie){i=c;continue}throw c}}throw i}async function Ds(e,t){return ie(e,`/api/v1/public/flows/${t}`)}async function Ts(e,t,r,a,o,l){return ie(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:r,contentType:a,size:o,componentUuid:l})})}async function Is(e,t,r){return ie(e,`/api/v1/public/flows/${t}/files/${r}/confirm`,{method:"POST"})}async function Ls(e,t,r){const a={flowId:t};return r&&Object.keys(r).length>0&&(a.context=r),ie(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(a)})}async function Ms(e,t,r){return ie(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:r})})}async function Os(e,t,r){return ie(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:r})})}async function Bs(e,t,r){return ie(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:r})})}async function Vs(e,t){return ie(e,`/api/v1/public/sessions/${t}`)}const As=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(!1),[c,u]=g.useState(!1),p=g.useRef(null),m=tn();if(!s)return null;const f=t!=null&&a===!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 Ts(m.config,m.flowId,b.name,b.type,b.size,e);await fetch(C,{method:"PUT",headers:{"Content-Type":b.type},body:b}),await Is(m.config,m.flowId,w);const k={mode:"s3",fileId:w,name:b.name,type:b.type,size:b.size};l(e,k),Dt("file-upload",e,k)}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},C=b.lastModifiedDate;C instanceof Date&&!Number.isNaN(C.getTime())?w.lastModifiedDate=C.toISOString():typeof C=="string"&&(w.lastModifiedDate=C),l(e,w),Dt("file-upload",e,w)}),_.readAsDataURL(b)};return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,error:f,errorMessages:f?o: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(Ln,{}),"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${i?" 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",As);const $s=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r;if(!s)return null;const i=t!=null&&a===!1,d=s.labelYes??"Yes",c=s.labelNo??"No";return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:!1,error:i,errorMessages:i?o:void 0,children:()=>n.jsxs("div",{className:`fbre-yesno${s.layout?` fbre-yesno--${s.layout}`:""}`,children:[n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="yes"?" fbre-yesno__btn--active":""}`,onClick:()=>l(e,"yes"),children:d}),n.jsx("button",{type:"button",className:`fbre-yesno__btn${t==="no"?" fbre-yesno__btn--active":""}`,onClick:()=>l(e,"no"),children:c})]})})};$("yesNo",$s);const Ps=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r;if(!s)return null;const i=a===!1,d=t===!0;return n.jsx(z,{detail:s.detail,helperText:s.helperText,tooltip:s.tooltip,error:i,errorMessages:i?o:void 0,children:()=>n.jsxs("label",{className:`fbre-confirm${i?" fbre-confirm--error":""}`,children:[n.jsx("input",{type:"checkbox",className:"fbre-confirm__input",checked:d,onChange:c=>l(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",Ps);const Tt=e=>{const{h:t,s:r,b:a}=e,o=r/100,l=a/100,s=l*o,i=s*(1-Math.abs(t/60%2-1)),d=l-s;let c=0,u=0,p=0;t<60?(c=s,u=i,p=0):t<120?(c=i,u=s,p=0):t<180?(c=0,u=s,p=i):t<240?(c=0,u=i,p=s):t<300?(c=i,u=0,p=s):(c=s,u=0,p=i);const m=f=>Math.round((f+d)*255).toString(16).padStart(2,"0");return`#${m(c)}${m(u)}${m(p)}`},Le=e=>{const t=e.replace("#",""),r=parseInt(t.substring(0,2),16)/255,a=parseInt(t.substring(2,4),16)/255,o=parseInt(t.substring(4,6),16)/255,l=Math.max(r,a,o),s=Math.min(r,a,o),i=l-s;let d=0;i!==0&&(l===r?d=60*((a-o)/i%6):l===a?d=60*((o-r)/i+2):d=60*((r-a)/i+4)),d<0&&(d+=360);const c=l===0?0:i/l*100,u=l*100;return{h:d,s:c,b:u}},Ze=e=>/^#[0-9a-fA-F]{6}$/.test(e),Fs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,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"&&Ze(t)?t:"#1976d2",[_,w]=g.useState(()=>Le(b));qe(c,i,g.useCallback(()=>d(!1),[]));const C=ze(p,i,320);if(g.useEffect(()=>{typeof t=="string"&&Ze(t)&&(y(t),w(Le(t)))},[t]),!s)return null;const k=t!=null&&a===!1,E=h=>{w(h);const j=Tt(h);y(j),l(e,j)},S=h=>{h.preventDefault();const j=(L,V)=>{const M=m.current.getBoundingClientRect(),B=Math.max(0,Math.min(100,(L-M.left)/M.width*100)),F=Math.max(0,Math.min(100,(1-(V-M.top)/M.height)*100));E({..._,s:B,b:F})};j(h.clientX,h.clientY);const N=L=>j(L.clientX,L.clientY),D=()=>{document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",D)};document.addEventListener("mousemove",N),document.addEventListener("mouseup",D)},R=h=>{h.preventDefault();const j=L=>{const V=f.current.getBoundingClientRect(),M=Math.max(0,Math.min(360,(L-V.left)/V.width*360));E({..._,h:M})};j(h.clientX);const N=L=>j(L.clientX),D=()=>{document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",D)};document.addEventListener("mousemove",N),document.addEventListener("mouseup",D)},I=h=>{if(y(h),Ze(h)){const j=Le(h);w(j),l(e,h.toLowerCase())}},x=Tt({h:_.h,s:100,b:100});return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:i,error:k,errorMessages:k?o: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":i,onClick:()=>d(!i),onKeyDown:h=>{h.key==="Escape"&&i&&(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${i?" 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(Le(N)),l(e,N)}},j))})]})]})})};$("colorPicker",Fs);const Us=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,i=(s==null?void 0:s.mode)??"draw",[d,c]=g.useState(i==="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&&a===!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)},[]),k=g.useCallback(x=>{if(!m.current||!f.current)return;const h=_(x.nativeEvent);w(f.current,h),f.current=h},[w]),E=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");l(e,h)}},[e,l]),S=()=>{const x=u.current;if(x){const h=x.getContext("2d");h&&h.clearRect(0,0,x.width,x.height)}v.current=!1,l(e,null)},R=x=>{const h=x.target.value;l(e,h||null)},I=x=>{c(x),l(e,null),v.current=!1};return s?n.jsx(z,{label:s.label??"Signature",detail:s.detail,showLabel:s.showLabel,required:s.required,helperText:s.helperText,tooltip:s.tooltip,error:y,errorMessages:y?o:void 0,children:()=>n.jsxs("div",{className:"fbre-signature",ref:p,children:[i==="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:k,onPointerUp:E,onPointerLeave:E}),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",Us);function It(e){const t=e.offsetParent;if(!t)return 0;const r=Qt(t),a=r===document.documentElement?{left:0,right:window.innerWidth}:r.getBoundingClientRect(),o=t.getBoundingClientRect(),l=e.offsetWidth,s=o.left+l;if(s<=a.right-8)return 0;let i=-(s-a.right+8);return o.left+i<a.left+8&&(i=a.left+8-o.left),i}const ge=({open:e,onClose:t,children:r,estimatedHeight:a=300,triggerRef:o})=>{const l=g.useRef(null);qe(l,e,g.useCallback(()=>t(),[t]));const s=ze(l,e,a),[i,d]=g.useState(0);if(g.useLayoutEffect(()=>{if(!e||!l.current){d(0);return}d(It(l.current))},[e]),g.useEffect(()=>{if(!e||!l.current)return;const p=()=>{l.current&&d(It(l.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=o==null?void 0:o.current)==null||m.focus())};return n.jsx("div",{ref:l,className:c,role:"dialog",onKeyDown:u,style:i?{left:i}:void 0,children:r})},Ve=(e,t)=>new Date(e,t+1,0).getDate(),Hs=(e,t)=>new Date(e,t,1).getDay(),de=(e,t,r)=>`${e}-${String(t+1).padStart(2,"0")}-${String(r).padStart(2,"0")}`,qs=e=>{const t=e.split("-");if(t.length!==3)return null;const r=parseInt(t[0],10),a=parseInt(t[1],10)-1,o=parseInt(t[2],10);return isNaN(r)||isNaN(a)||isNaN(o)?null:{year:r,month:a,day:o}},Fe=(e,t)=>{const r=qs(e);if(!r)return e;const a=String(r.month+1).padStart(2,"0"),o=String(r.day).padStart(2,"0"),l=String(r.year);return t==="DD/MM/YYYY"?`${o}/${a}/${l}`:t==="YYYY-MM-DD"?`${l}-${a}-${o}`:`${a}/${o}/${l}`},Ue=e=>{const t=e.split(":");if(t.length!==2)return e;let r=parseInt(t[0],10);const a=t[1],o=r>=12?"PM":"AM";return r===0?r=12:r>12&&(r-=12),`${r}:${a} ${o}`},it=(e,t)=>{const r=e.indexOf("T");if(r===-1)return e;const a=e.substring(0,r),o=e.substring(r+1);return`${Fe(a,t)} ${Ue(o)}`},zs=(e,t,r)=>{let a=e;return r==="AM"&&a===12?a=0:r==="PM"&&a!==12&&(a+=12),`${String(a).padStart(2,"0")}:${String(t).padStart(2,"0")}`},Ks=e=>{const t=e.split(":");let r=parseInt(t[0],10);const a=parseInt(t[1],10),o=r>=12?"PM":"AM";return r===0?r=12:r>12&&(r-=12),{hour:r,minute:a,ampm:o}},Ws=(e,t,r)=>e>=t&&e<=r,le=e=>{if(!e)return;if(!e.startsWith("today"))return e;const t=e==="today"?0:parseInt(e.slice(5),10),r=new Date;return r.setDate(r.getDate()+(isNaN(t)?0:t)),de(r.getFullYear(),r.getMonth(),r.getDate())},Ys=["January","February","March","April","May","June","July","August","September","October","November","December"],Gs=e=>Ys[e],Xs=["Su","Mo","Tu","We","Th","Fr","Sa"],_e=e=>[parseInt(e.substring(0,4),10),parseInt(e.substring(5,7),10)-1,parseInt(e.substring(8,10),10)],he=(e,t)=>{const[r,a,o]=_e(e),l=new Date(r,a,o+t);return de(l.getFullYear(),l.getMonth(),l.getDate())},Me=(e,t)=>{let[r,a,o]=_e(e);for(a+=t;a<0;)a+=12,r--;for(;a>11;)a-=12,r++;return de(r,a,Math.min(o,Ve(r,a)))},Ke=({selectedDate:e,min:t,max:r,onSelect:a,rangeStart:o,rangeEnd:l,rangeHover:s})=>{const i=new Date,d=de(i.getFullYear(),i.getMonth(),i.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]=_e(c),b=()=>u(Me(c,-1)),_=()=>u(Me(c,1)),w=j=>{let N=null;switch(j.key){case"ArrowLeft":N=he(c,-1);break;case"ArrowRight":N=he(c,1);break;case"ArrowUp":N=he(c,-7);break;case"ArrowDown":N=he(c,7);break;case"Home":{const[D,L,V]=_e(c);N=he(c,-new Date(D,L,V).getDay());break}case"End":{const[D,L,V]=_e(c);N=he(c,6-new Date(D,L,V).getDay());break}case"PageUp":N=Me(c,-1);break;case"PageDown":N=Me(c,1);break}N&&(j.preventDefault(),f(N))},C=Ve(v,y),k=Hs(v,y),E=[],S=y===0?Ve(v-1,11):Ve(v,y-1);for(let j=k-1;j>=0;j--){const N=S-j,D=y===0?11:y-1,L=y===0?v-1:v;E.push({day:N,iso:de(L,D,N),outside:!0})}for(let j=1;j<=C;j++)E.push({day:j,iso:de(v,y,j),outside:!1});const R=42-E.length;for(let j=1;j<=R;j++){const N=y===11?0:y+1,D=y===11?v+1:v;E.push({day:j,iso:de(D,N,j),outside:!0})}const I=s??l,x=o&&I&&o<=I?o:I,h=o&&I&&o<=I?I:o;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:[Gs(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:Xs.map(j=>n.jsx("div",{className:"fbre-calendar__weekday",children:j},j))}),n.jsx("div",{className:"fbre-calendar__grid",role:"grid",onKeyDown:w,children:E.map((j,N)=>{const D=j.iso===e,L=j.iso===d,V=t&&j.iso<t||r&&j.iso>r,M=x&&h&&Ws(j.iso,x,h),B=j.iso===x,F=j.iso===h,X=["fbre-calendar__day",j.outside&&"fbre-calendar__day--outside",D&&"fbre-calendar__day--selected",L&&"fbre-calendar__day--today",V&&"fbre-calendar__day--disabled",M&&"fbre-calendar__day--range",B&&"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:X,role:"gridcell","aria-selected":D||void 0,"aria-current":L?"date":void 0,"aria-disabled":V?!0:void 0,tabIndex:!j.outside&&j.iso===c?0:-1,onClick:()=>!j.outside&&!V&&a(j.iso),children:j.day},N)})})]})},Js=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(!1),c=g.useRef(null);if(!s)return null;const u=s.readOnly===!0,p=t!=null&&a===!1,m=typeof t=="string"?t:"";return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:i,error:p,errorMessages:p?o: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":i,onClick:()=>d(!i),onKeyDown:f=>{f.key==="Escape"&&i&&(f.preventDefault(),d(!1))},children:[m?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Fe(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(be,{})})]}),n.jsx(ge,{open:i,onClose:()=>d(!1),triggerRef:c,children:n.jsx(Ke,{selectedDate:m,min:le(s.min),max:le(s.max),onSelect:f=>{l(e,f),d(!1)}})})]})})};$("date",Js);const Lt=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const r=parseInt(t[0],10),a=parseInt(t[1],10);return isNaN(r)||isNaN(a)?null:r*60+a},et=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,We=({value:e,min:t,max:r,step:a=15,onChange:o})=>{const l=g.useRef(null),s=g.useRef(null),i=e?Ks(e):{hour:12,minute:0,ampm:"AM"},{hour:d,minute:c,ampm:u}=i,p=Array.from({length:12},(x,h)=>h+1),m=[];for(let x=0;x<60;x+=a)m.push(x);const f=["AM","PM"],v=g.useMemo(()=>Lt(t),[t]),y=g.useMemo(()=>Lt(r),[r]),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=et(x,h);for(let N=0;N<60;N+=a)if(_(j,N))return!1;return!0},C=x=>{if(!b)return!1;const h=et(d,u);return!_(h,x)},k=x=>{if(!b)return!1;for(const h of p){const j=et(h,x);for(let N=0;N<60;N+=a)if(_(j,N))return!1}return!0},E=(x,h,j)=>{o(zs(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(l.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 L=N.indexOf(h)+D;L>=0&&L<N.length;L+=D)if(N[L].getAttribute("aria-disabled")!=="true"){N[L].focus();break}};return n.jsxs("div",{className:"fbre-time-selector",children:[n.jsx("div",{className:"fbre-time-selector__column",ref:l,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&&E(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&&E(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=k(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&&E(d,c,x),children:x},x)})})]})},Qs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(!1),c=g.useRef(null);if(!s)return null;const u=s.readOnly===!0,p=t!=null&&a===!1,m=typeof t=="string"?t:"";return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:i,error:p,errorMessages:p?o: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":i,onClick:()=>d(!i),onKeyDown:f=>{f.key==="Escape"&&i&&(f.preventDefault(),d(!1))},children:[m?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ue(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(lt,{})})]}),n.jsxs(ge,{open:i,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(se,{size:12})})]}),n.jsx(We,{value:m||void 0,step:s.step,min:s.min,max:s.max,onChange:f=>{l(e,f)}})]})]})})};$("time",Qs);const Zs=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,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&&a===!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")},k=x=>{l(e,`${x}T${_||"12:00"}`),u("time")},E=x=>{const h=b||new Date().toISOString().substring(0,10);l(e,`${h}T${x}`)},S=()=>{u("date")},R=le(s.min&&s.min.includes("T")?s.min.split("T")[0]:s.min),I=le(s.max&&s.max.includes("T")?s.max.split("T")[0]:s.max);return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:i,error:f,errorMessages:f?o: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":i,onClick:w,onKeyDown:x=>{x.key==="Escape"&&i&&(x.preventDefault(),C())},children:[v?n.jsx("span",{className:"fbre-datetime__trigger-text",children:it(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(be,{})})]}),n.jsx(ge,{open:i,onClose:C,triggerRef:p,children:c==="date"?n.jsx(Ke,{selectedDate:b,min:R,max:I,onSelect:k}):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(se,{size:12})})]}),n.jsx(We,{value:_||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:E})]})})]})})};$("dateTime",Zs);const er=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(null),[c,u]=g.useState(),p=g.useRef(null),m=g.useRef(null);if(!s)return null;const f=t!=null&&a===!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(i==="start"){const k=b&&C>b?"":b;l(e,{start:C,end:k}),d(k?null:"end")}else if(i==="end"){const k=y&&C<y?C:y,E=C<k?k:C;l(e,{start:k||C,end:k?E:""}),k&&E&&d(null)}u(void 0)},w=i!==null;return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:w,error:f,errorMessages:f?o: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":i==="start",onClick:()=>d(i==="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:Fe(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(be,{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":i==="end",onClick:()=>d(i==="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:Fe(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(be,{size:12})})]})})]}),n.jsx(ge,{open:w,triggerRef:i==="start"?p:m,onClose:()=>{d(null),u(void 0)},children:n.jsx(Ke,{selectedDate:i==="start"?y:b,min:le(s.min),max:le(s.max),onSelect:_,rangeStart:y,rangeEnd:b,rangeHover:c})})]})})};$("dateRange",er);const tr=({uuid:e})=>{const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,d]=g.useState(null),c=g.useRef(null),u=g.useRef(null);if(!s)return null;const p=t!=null&&a===!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(i==="start"){const C=v&&w>v?"":v;l(e,{start:w,end:C})}else if(i==="end"){const C=f&&w<f?f:w;l(e,{start:f,end:C})}},b=()=>{d(null)},_=i!==null;return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:_,error:p,errorMessages:p?o: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":i==="start",onClick:()=>d(i==="start"?null:"start"),onKeyDown:w=>{w.key==="Escape"&&_&&(w.preventDefault(),b())},children:[f?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ue(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(lt,{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":i==="end",onClick:()=>d(i==="end"?null:"end"),onKeyDown:w=>{w.key==="Escape"&&_&&(w.preventDefault(),b())},children:[v?n.jsx("span",{className:"fbre-datetime__trigger-text",children:Ue(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(lt,{size:12})})]})})]}),n.jsxs(ge,{open:_,triggerRef:i==="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:i==="start"?"Start Time":"End Time"}),n.jsx("button",{type:"button",className:"fbre-picker-phase-header__confirm",onClick:b,children:n.jsx(se,{size:12})})]}),n.jsx(We,{value:i==="start"?f||void 0:v||void 0,step:s.step,min:s.min,max:s.max,onChange:y})]})]})})};$("timeRange",tr);const nr=({uuid:e})=>{var L,V;const{value:t,properties:r,valid:a,validationErrors:o,updateValue:l}=U(e),s=r,[i,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&&a===!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)??"",_=M=>{const B=M.indexOf("T");return B!==-1?{date:M.substring(0,B),time:M.substring(B+1)}:{date:"",time:"12:00"}},w=y?_(y):{date:"",time:"12:00"},C=b?_(b):{date:"",time:"12:00"},k=i==="start"?w:C,E=(M,B)=>{const F=M&&B&&B<M?"":B;l(e,{start:M,end:F})},S=M=>{u((M==="start"?w:C).date?"time":"date"),d(M)},R=()=>{d(null),u("date")},I=M=>{const B=k.time||"12:00",F=`${M}T${B}`;i==="start"?E(F,b):E(y,F),u("time")},x=M=>{const B=k.date;if(!B)return;const F=`${B}T${M}`;i==="start"?E(F,b):E(y,F)},h=()=>{u("date")},j=i!==null,N=le((L=s.min)==null?void 0:L.split("T")[0]),D=le((V=s.max)==null?void 0:V.split("T")[0]);return n.jsx(z,{label:s.label,detail:s.detail,showLabel:s.showLabel,helperText:s.helperText,tooltip:s.tooltip,externalFocused:j,error:f,errorMessages:f?o: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":i==="start",onClick:()=>S("start"),onKeyDown:M=>{M.key==="Escape"&&j&&(M.preventDefault(),R())},children:[y?n.jsx("span",{className:"fbre-datetime__trigger-text",children:it(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(be,{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":i==="end",onClick:()=>S("end"),onKeyDown:M=>{M.key==="Escape"&&j&&(M.preventDefault(),R())},children:[b?n.jsx("span",{className:"fbre-datetime__trigger-text",children:it(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(be,{size:12})})]})})]}),n.jsx(ge,{open:j,triggerRef:i==="start"?p:m,onClose:R,children:c==="date"?n.jsx(Ke,{selectedDate:k.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(se,{size:12})})]}),n.jsx(We,{value:k.time||void 0,step:s.step,min:s.minTime,max:s.maxTime,onChange:x})]})})]})})};$("dateTimeRange",nr);const sn=({uuid:e})=>{var u;const t=e.split(":")[0],r=parseInt(e.split(":")[1]),a=parseInt(e.split(":")[2]),o=A(p=>{var m,f,v;return(v=(f=(m=p.components[t])==null?void 0:m.addedComponents)==null?void 0:f[r])==null?void 0:v[a]}),l=A(p=>p.conditionResults[e]);if(!o)return null;const s=o.conditions&&"when"in o.conditions?o.conditions:void 0;if(P.isHiddenByCondition(s,l))return null;const i=Bt(o.type);if(!i)return null;const d=(u=o.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(Xt.Provider,{value:o,children:n.jsx(i,{uuid:e})})})},sr=({uuid:e})=>{const t=A(i=>{var d;return(d=i.components[e])==null?void 0:d.properties}),r=A(i=>{var d;return(d=i.components[e])==null?void 0:d.addedComponents}),[a,o]=g.useState(!0);if(!t)return null;const l=r??[],s=["fbre-group",t.showBorder===!0&&"fbre-group--bordered",t.showBorder===!1&&"fbre-group--no-border"].filter(Boolean).join(" ");return n.jsx("div",{className:s,children:l.map((i,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${a?"":" collapsed"}`,onClick:()=>o(!a),"aria-label":"Toggle group",children:n.jsx(ke,{size:20})})]}),n.jsx("div",{className:`fbre-group__body${a?"":" collapsed"}`,children:n.jsx("div",{className:"fbre-group__content",children:i.map(c=>n.jsx(sn,{uuid:c.uuid},c.uuid))})})]},`${e}-${d}`))})};$("group",sr);const rr=({uuid:e})=>{const t=A(f=>{var v;return(v=f.components[e])==null?void 0:v.properties}),r=A(f=>{var v;return(v=f.components[e])==null?void 0:v.addedComponents}),a=A(f=>f.addRepeaterIteration),o=A(f=>f.removeRepeaterIteration),[l,s]=g.useState(new Set([0]));if(!t)return null;const i=r??[],d=t.minIterations??1,c=()=>{const f=i.length;a(e),s(new Set([f]))},u=f=>{i.length<=d||(o(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:[i.map((f,v)=>{const y=l.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," ",i.length>1?`#${v+1}`:""]}),i.length>d&&n.jsx("button",{type:"button",className:"fbre-repeater__remove-btn",onClick:()=>u(v),title:"Remove","aria-label":"Remove iteration",children:n.jsx(Vn,{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(ke,{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(sn,{uuid:b.uuid},b.uuid))})})]},`${e}-${v}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:c,children:"Add another"})]})};$("repeater",rr);const Mt=e=>e&&typeof e=="object"&&("title"in e||"body"in e)?e:null,or={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"},ar=({screenIndex:e,onFlowComplete:t,onScreenChange:r})=>{var mt,ht,bt,vt,xt,gt,yt,jt,_t,wt;const a=A(O=>O.config),o=A(O=>O.screenOrder.length),l=A(O=>Object.keys(O.components).length>0),s=Ne(),i=Math.max(0,Math.min(e,o-1)),[d,c]=g.useState(i),[u,p]=g.useState(!!(a!=null&&a.summary&&e>=o)),m=((mt=a==null?void 0:a.navigation)==null?void 0:mt.transition)??"none",f=m!=="none",[v,y]=g.useState(null),[b,_]=g.useState(!1),[w,C]=g.useState("forward"),[k,E]=g.useState(!1),S=g.useRef(null),R=g.useRef(null),I=g.useRef(!1),x=g.useCallback(O=>{O&&(O.inert=!0)},[]);g.useEffect(()=>{const O=Math.max(0,Math.min(e,o-1));c(O)},[e]),g.useEffect(()=>{var O;if(!I.current){I.current=!0;return}k||(O=R.current)==null||O.focus({preventScroll:!0})},[d,u,k]);const h=A(O=>O.screenOrder[d]),j=A(O=>{var H;return h?(H=O.screens[h])==null?void 0:H.label:void 0}),N=A(O=>h?O.screenValidity[h]??!0:!0),D=A(O=>{var H;return h?(H=O.screens[h])==null?void 0:H.nextButtonLabel:void 0}),L=A(O=>{var H;return h?(H=O.screens[h])==null?void 0:H.backButtonLabel:void 0}),V=g.useCallback(O=>{r&&r(O,s.getState().getFlowData())},[r,s]),M=g.useCallback(O=>{y(d),_(u),C(O),E(!0),S.current&&(S.current.scrollTop=0)},[d,u]),B=g.useCallback(()=>{E(!1),y(null)},[]),F=g.useCallback(()=>{if(!k)if(u)f&&M("back"),p(!1),V(d);else{const O=s.getState(),H=ns(O,d);H!==d&&(f&&M("back"),c(H),V(H))}},[k,u,d,f,M,V,s]),X=g.useCallback(()=>{if(k)return;const O=s.getState(),H=Pe(O,d);H!==null?(f&&M("forward"),c(H),V(H)):a!=null&&a.summary&&(f&&M("forward"),p(!0),V(d+1))},[k,d,a,f,M,V,s]),[Y,Z]=g.useState(!1),[K,ae]=g.useState(null),[T,q]=g.useState(!1),[G,ee]=g.useState(null),on=g.useCallback(()=>{ae(null);const O=t(s.getState().getFlowData());O&&typeof O.then=="function"?(Z(!0),O.then(H=>{Z(!1),ee(Mt(H)),q(!0)}).catch(H=>{Z(!1),ae(H instanceof Error?H.message:String(H))})):(ee(Mt(O)),q(!0))},[t,s]),an=A(O=>Pe(O,d)===null),ln=((ht=a==null?void 0:a.theme)==null?void 0:ht.colorScheme)??"light",Ye=((a==null?void 0:a.mode)??"standard")==="conversational";Yt(Ye&&!u,d,X),Gt(Ye&&!u,d,X);const ut=((bt=a==null?void 0:a.theme)==null?void 0:bt.style)??"clean",pt=((vt=a==null?void 0:a.controls)==null?void 0:vt.stepperStyle)??"default",Ge=pt==="default"?or[ut]??"dots":pt,cn=((xt=a==null?void 0:a.controls)==null?void 0:xt.showStepper)!==!1&&Ge==="text",ft=Kt(a==null?void 0:a.theme),Se=a==null?void 0:a.confirmation,re=G??Se??null,dn=G?!0:(Se==null?void 0:Se.show)!==!1,Ee=T&&!!re&&dn&&!!(re.title||re.body),un=()=>b?n.jsx(Nt,{}):v!==null?n.jsx(at,{screenIndex:v}):null,pn=k?"fbre-screen-wrapper fbre-screen-wrapper--transitioning":"fbre-screen-wrapper";return n.jsxs("div",{className:"fbre-container","data-style":ut,"data-mode":ln,"data-form-mode":Ye?"conversational":void 0,"data-stepper":Ge!=="text"?Ge:void 0,"data-transition":f?m:void 0,style:Object.keys(ft).length>0?ft:void 0,children:[cn&&!Ee&&n.jsx(Zn,{current:d,total:o}),n.jsxs("div",{className:pn,ref:S,children:[k&&n.jsx("div",{ref:x,className:"fbre-screen-slot fbre-screen--exiting","data-direction":w,onAnimationEnd:B,children:un()}),n.jsx("div",{ref:R,className:k?"fbre-screen-slot fbre-screen--entering":"fbre-screen-slot","data-direction":k?w:void 0,tabIndex:-1,role:"group","aria-label":Ee?"Confirmation":u?"Summary":j??`Step ${d+1} of ${o}`,children:Ee?n.jsx(qt,{title:re==null?void 0:re.title,body:re==null?void 0:re.body}):n.jsxs(n.Fragment,{children:[!u&&n.jsx(at,{screenIndex:d}),u&&n.jsx(Nt,{})]})})]}),K&&n.jsx("div",{className:"fbre-completion-error",children:K}),((gt=a==null?void 0:a.controls)==null?void 0:gt.show)!==!1&&l&&!Ee&&n.jsx(es,{screenIndex:d,maxScreenIndex:o-1,allowInvalidTransition:(yt=a==null?void 0:a.navigation)==null?void 0:yt.allowInvalidTransition,screenValidity:N,summaryEnabled:(a==null?void 0:a.summary)??!1,summaryActive:u,atMaxScreen:an,nextButtonLabel:D,backButtonLabel:L,completionLoading:Y,showStepper:(jt=a==null?void 0:a.controls)==null?void 0:jt.showStepper,stepperStyle:(_t=a==null?void 0:a.controls)==null?void 0:_t.stepperStyle,controlsLayout:(wt=a==null?void 0:a.controls)==null?void 0:wt.layout,nextScreen:X,prevScreen:F,onFlowComplete:on})]})},lr=[],ir=()=>ne.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:r=>{e({externalContext:r})},updateComponentValue:(r,a)=>{var d,c;const o=t();if(r.includes(":")){const u=r.split(":"),p=u[0],m=parseInt(u[1]),f=parseInt(u[2]),v=o.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:a};const y=o.groupComponentMap[r]??r,b=ot(e,t,y),_=nt(o,r,v.addedComponents[m][f]);e({components:{...o.components},conditionResults:b??o.conditionResults,validationErrors:_});return}const l=o.components[r];if(!l)return;if(l.type==="group"||l.type==="repeater"){e({components:{...o.components}});return}if(a===l.value){e({selectionTick:(t().selectionTick??0)+1});return}l.value=a;const s=ot(e,t,r),i=nt(o,r,l);e({components:{...o.components},conditionResults:s??o.conditionResults,validationErrors:i})},addGroupIteration:r=>{const a=t(),o=a.components[r];if(!o||o.type!=="group"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l=o.components.map((s,i)=>{const d=oe(s);d.uuid=[r,o.addedComponents.length,i].join(":"),a.groupComponentMap[d.uuid]=s.uuid;const c=J(d);return d.valid=c.length===0,d});return o.addedComponents.push(l),e({components:{...a.components},groupComponentMap:{...a.groupComponentMap}}),o.addedComponents},addRepeaterIteration:r=>{const a=t(),o=a.components[r];if(!o||o.type!=="repeater"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l=o.components.map((s,i)=>{const d=oe(s);d.uuid=[r,o.addedComponents.length,i].join(":");const c=J(d);return d.valid=c.length===0,d});return o.addedComponents.push(l),e({components:{...a.components}}),o.addedComponents},removeRepeaterIteration:(r,a)=>{const o=t(),l=o.components[r];if(!(!l||l.type!=="repeater"||!l.addedComponents||l.addedComponents.length<=1)){l.addedComponents.splice(a,1);for(let s=a;s<l.addedComponents.length;s++)l.addedComponents[s].forEach((i,d)=>{i.uuid=[r,s,d].join(":")});e({components:{...o.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:r=>{const a=t();if(r!==0)return null;const o=a.screenOrder[0];return o?a.screens[o]:null},getScreenValidity:r=>{const a=t();if(r!==0)return!0;const o=a.screenOrder[0];return o?a.screenValidity[o]??!0:!0},getValidationErrors:r=>t().validationErrors[r]??lr,evaluateFlowValidation:()=>{const r=t(),a=r.screenOrder[0];if(!a)return!0;const o=r.screens[a];if(!o)return!0;let l=!0;const s={components:r.components,groupComponentMap:r.groupComponentMap},i={...r.validationErrors};for(const c of o.components){const u=r.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 _=r.conditionResults[v.uuid]??!1;if(y.action==="show"&&!_||y.action==="hide"&&_)continue}const b=J(v,s);v.valid=b.length===0,i[v.uuid]=b,b.length>0&&(l=!1)}continue}const p=u.conditions&&"when"in u.conditions?u.conditions:void 0;if(p){const f=r.conditionResults[u.uuid]??!1;if(p.action==="show"&&!f||p.action==="hide"&&f)continue}const m=J(u,s);u.valid=m.length===0,i[u.uuid]=m,m.length>0&&(l=!1)}const d={...r.screenValidity,[a]:l};return e({components:{...r.components},validationErrors:i,screenValidity:d}),l},getMaxScreenIndex:()=>0,getCalculationResult:r=>t().calculationResults[r]??null})),Oe=(e,t)=>{const r={},a={},o={},l={},s={},i={},d=t.screen.uuid;for(const b of t.screen.components){const _=oe(b);if(r[_.uuid]=_,(_.type==="group"||_.type==="repeater")&&b.components){_.addedComponents||(_.addedComponents=[]);const C=b.components.map((k,E)=>{const S=oe(k);S.uuid=[_.uuid,0,E].join(":"),_.type==="group"&&(a[S.uuid]=k.uuid),o[k.uuid]=S.uuid;const R=te.getValidationConfig(S);return R&&R.rules&&R.rules.length>0&&ye(s,S.uuid,R),S});_.addedComponents.push(C)}const w=te.getValidationConfig(_);w&&w.rules&&w.rules.length>0&&ye(s,_.uuid,w)}for(const{targetUUID:b,config:_}of t.conditions)ce(l,b,_,b===d?"screen":"component");if(t.previousData)for(const b of t.previousData){const _=r[b.uuid];_&&(_.value=b.value)}const c={components:r};for(const b of Object.keys(r)){const _=r[b];if(_.type==="group"||_.type==="repeater"){if(_.addedComponents)for(const C of _.addedComponents)for(const k of C){const E=J(k,c);k.valid=E.length===0,E.length>0&&(i[k.uuid]=E)}continue}if(!te.getValidationConfig(_))continue;const w=J(_,c);_.valid=w.length===0,w.length>0&&(i[b]=w)}const u={},p={components:r},m=new Set;for(const b of Object.values(l))for(const _ of b)m.has(_.target)||(m.add(_.target),u[_.target]=He(p,_.config));let f=!0;for(const b of t.screen.components){const _=r[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:r,groupComponentMap:a,templateComponentMap:o,conditionsByDependency:l,conditionResults:u,validationErrors:i,validationsByDependency:s,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:t.sessionId,navigation:t.navigation,loading:!1,error:y,externalContext:t.context??{},config:t.config??{}})},tt=e=>{const t=e.getState(),r=t.screenOrder[0];if(!r)return[];const a=t.screens[r];if(!a)return[];const o=[];for(const l of a.components){const s=t.components[l.uuid];if(!s||Ae(s.type))continue;const i={uuid:s.uuid,type:s.type,value:s.value};"label"in s.properties&&typeof s.properties.label=="string"&&(i.label=s.properties.label),(s.type==="group"||s.type==="repeater")&&s.addedComponents&&(i.components=s.addedComponents.map(d=>d.filter(c=>!Ae(c.type)).map(c=>({uuid:c.uuid,type:c.type,value:c.value})))),o.push(i)}return o},cr=6e4,dr=({sessionEndpoint:e,flowId:t,apiKey:r,mode:a,theme:o,context:l,onFlowComplete:s,onScreenChange:i})=>{const d=g.useRef(null);d.current||(d.current=ir());const c=d.current,u=ne.useStore(c,T=>T.loading),p=ne.useStore(c,T=>T.error),m=ne.useStore(c,T=>T.navigation),f=ne.useStore(c,T=>T.config),v=ne.useStore(c,T=>{var q;return(q=T.config)==null?void 0:q.mode}),y=ne.useStore(c,T=>T.screenOrder),b=ne.useStore(c,T=>T.screens),[_,w]=g.useState(!1),[C,k]=g.useState(""),E=g.useRef(null),S=g.useRef(Date.now()),R=g.useMemo(()=>({apiEndpoint:e,apiKey:r}),[e,r]),I=g.useCallback(T=>{k(T),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>k(""),8e3)},[]),x=g.useCallback(()=>{k(""),E.current&&(clearTimeout(E.current),E.current=null)},[]),h=g.useCallback(async()=>{c.setState({loading:!0,error:""});try{const T=await Ls(R,t,l);Oe(c,T)}catch(T){c.setState({loading:!1,error:T.message})}},[t,e,r,l]);g.useEffect(()=>{h()},[h]),g.useEffect(()=>{const T=async()=>{if(document.visibilityState!=="visible")return;const q=c.getState();if(!(!q.sessionId||Date.now()-S.current<cr))try{const ee=await Vs(R,q.sessionId);Oe(c,ee)}catch(ee){ee instanceof Ce&&ee.status===404&&c.setState({loading:!1,error:"Session expired. Please start over.",screenOrder:[],screens:{}})}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[e,r]);const j=g.useCallback(async()=>{const T=c.getState();if(!(T.loading||!T.evaluateFlowValidation())){c.setState({loading:!0}),c.getState().clearError(),x();try{const G=tt(c),ee=await Ms(R,T.sessionId,G);Oe(c,ee),S.current=Date.now(),i==null||i(ee.navigation.screenNumber)}catch(G){c.setState({loading:!1}),I(G.message)}}},[R,c,i,I,x]),N=g.useCallback(async()=>{const T=c.getState();if(!T.loading){c.setState({loading:!0}),c.getState().clearError(),x();try{const q=tt(c),G=await Os(R,T.sessionId,q);Oe(c,G),S.current=Date.now(),i==null||i(G.navigation.screenNumber)}catch(q){c.setState({loading:!1}),I(q.message)}}},[R,c,i,I,x]),D=g.useCallback(async()=>{const T=c.getState();if(!(T.loading||!T.evaluateFlowValidation())){c.setState({loading:!0}),c.getState().clearError(),x();try{const G=tt(c),ee=await Bs(R,T.sessionId,G);S.current=Date.now(),c.setState({loading:!1}),w(!0),s(ee)}catch(G){c.setState({loading:!1}),I(G.message)}}},[R,c,s,I,x]),L={...f==null?void 0:f.theme,...o},M=(a??v??"standard")==="conversational",B=M&&!m.isLastScreen;Yt(B,0,j),Gt(B,0,j);const F=L.colorScheme??"light",X=Kt(L),Y=y[0],Z=Y?b[Y]:void 0,K=Z==null?void 0:Z.nextButtonLabel,ae=Z==null?void 0:Z.backButtonLabel;if(u&&y.length===0)return 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..."})]})});if(p&&y.length===0)return 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:h,style:{marginTop:12},children:"Retry"})]})});if(_){const T=f==null?void 0:f.confirmation,q=(T==null?void 0:T.show)!==!1&&(T!=null&&T.title)?T.title:"Thank you",G=(T==null?void 0:T.show)!==!1?T==null?void 0:T.body:void 0;return n.jsx(we.Provider,{value:c,children:n.jsx("div",{className:"fbre-container","data-style":L.style??"clean","data-mode":F,style:Object.keys(X).length>0?X:void 0,children:n.jsx("div",{className:"fbre-screen-wrapper",children:n.jsx(qt,{title:q,body:G})})})})}return y.length===0?null:n.jsx(we.Provider,{value:c,children:n.jsxs("div",{className:"fbre-container","data-style":L.style??"clean","data-mode":F,"data-form-mode":M?"conversational":void 0,style:Object.keys(X).length>0?X:void 0,children:[n.jsx("div",{className:"fbre-screen-wrapper",children:n.jsx(at,{screenIndex:0})}),n.jsx(ur,{navigation:m,loading:u,onPrev:N,onNext:j,onComplete:D,nextButtonLabel:K,backButtonLabel:ae}),n.jsxs("div",{className:`fbre-toast${C?" visible":""}`,children:[n.jsx("span",{children:C}),n.jsx("button",{type:"button",className:"fbre-toast__close",onClick:x,"aria-label":"Dismiss",children:"×"})]})]})})},ur=({navigation:e,loading:t,onPrev:r,onNext:a,onComplete:o,nextButtonLabel:l,backButtonLabel:s})=>n.jsxs("div",{className:"fbre-controls fbre-controls--default",children:[n.jsx("div",{className:"fbre-controls__left",children:e.canGoBack&&n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--back",onClick:r,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:o,disabled:t,children:t?"Submitting...":l||"Complete"}):n.jsx("button",{type:"button",className:"fbre-btn fbre-btn--next",onClick:a,disabled:t,children:t?"Loading...":l||"Next"})})]});function pr(e,t,r,a,o){return!t&&!r&&!a&&!o?e:{...e,...o&&{mode:o},...t&&{theme:{...e.theme,...t}},...r&&{navigation:{...e.navigation,...r}},...a&&{controls:{...e.controls,...a}}}}const rn=({flow:e,data:t,mode:r,theme:a,navigation:o,controls:l,screenIndex:s,context:i,storeRef:d,onFlowComplete:c,onScreenChange:u,apiCtx:p})=>{const m=g.useRef(null);m.current||(m.current=kn(),m.current.getState().loadFlow(e,t,i)),d&&(d.current=m.current),g.useEffect(()=>{m.current&&m.current.getState().loadFlow(e,t,i)},[e.uuid]),g.useEffect(()=>{if(m.current){const y=m.current.getState(),b=pr(y.config,a,o,l,r);b!==y.config&&m.current.setState({config:b})}},[r,a,o,l]);const f=i?JSON.stringify(i):"";g.useEffect(()=>{m.current&&i&&m.current.getState().updateContext(i)},[f]);const v=n.jsx(we.Provider,{value:m.current,children:n.jsx(ar,{screenIndex:s??0,onFlowComplete:c,onScreenChange:u})});return p?n.jsx(en.Provider,{value:p,children:v}):v},fr=({flowId:e,apiEndpoint:t,apiKey:r,data:a,mode:o,theme:l,navigation:s,controls:i,screenIndex:d,context:c,storeRef:u,onFlowComplete:p,onScreenChange:m})=>{const[f,v]=g.useState(null),[y,b]=g.useState(""),[_,w]=g.useState(null);return g.useEffect(()=>{v(null),b("");const C={apiEndpoint:t,apiKey:r};Ds(C,e).then(k=>{v(k.data),w({config:C,flowId:k.id,flowVersionId:k.versionId,tenantId:k.tenantId})}).catch(k=>b(k.message))},[e,t,r]),y?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:y})]})}):!f||!_?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(rn,{flow:f,data:a,mode:o,theme:l,navigation:s,controls:i,screenIndex:d,context:c,storeRef:u,onFlowComplete:p,onScreenChange:m,apiCtx:_})},mr=e=>"sessionEndpoint"in e?n.jsx(dr,{...e}):"flowId"in e&&e.flowId?n.jsx(fr,{...e}):n.jsx(rn,{...e});exports.ApiError=Ce;exports.FBRE=mr;exports.TimeoutError=nn;exports.addFBREEventListener=Ns;exports.removeFBREEventListener=ks;exports.useFBREApi=tn;exports.useFBREStore=A;exports.useFBREStoreApi=Ne;