@sonata-innovations/fiber-fbre 3.2.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -3
- package/dist/fiber-fbre.cjs +1 -1
- package/dist/fiber-fbre.css +1 -1
- package/dist/fiber-fbre.js +1346 -1299
- package/dist/index.d.ts +26 -1
- package/package.json +1 -1
package/dist/fiber-fbre.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),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"),ee=require("zustand"),Z=require("@sonata-innovations/fiber-types"),P=require("@sonata-innovations/fiber-shared"),pn=require("react-dom"),Vt=new Map,$=(e,t)=>{Vt.set(e,t)},At=e=>Vt.get(e),Oe=e=>Z.DISPLAY_ONLY_TYPES.has(e),fn=(e,t)=>{var s,a,o,l;if(t.includes(":")){const r=t.split(":"),i=e.components[r[0]];return(o=(a=(s=i==null?void 0:i.addedComponents)==null?void 0:s[parseInt(r[1])])==null?void 0:a[parseInt(r[2])])==null?void 0:o.value}return(l=e.components[t])==null?void 0:l.value},J=(e,t)=>{const s=Z.getValidationConfig(e);return!s||!s.rules||s.rules.length===0?[]:P.validateValue(e.value,s,t?a=>fn(t,a):void 0)},mn=e=>{const t=Z.getValidationConfig(e);return!t||!t.rules?!1:t.rules.some(s=>s.type==="required")},re=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):!Oe(e.type)&&e.type!=="group"&&e.type!=="repeater"&&(t.value=null,t.valid=!mn(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},xe=(e,t,s)=>{var a;for(const o of s.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:s})}},$t=(e,t)=>{var s,a;if(t.includes(":")){const o=t.split(":"),l=e[o[0]];return(a=(s=l==null?void 0:l.addedComponents)==null?void 0:s[parseInt(o[1])])==null?void 0:a[parseInt(o[2])]}return e[t]},tt=(e,t,s)=>{const a={components:e.components,groupComponentMap:e.groupComponentMap},o=J(s,a);s.valid=o.length===0;const l={...e.validationErrors,[t]:o},r=e.validationsByDependency[t];if(r)for(const i of r){const d=$t(e.components,i.target);if(d){const c=J(d,a);d.valid=c.length===0,l[i.target]=c}}return l},ce=(e,t)=>{const s=e.screens[t];return s?!s.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 r=l.conditions&&"when"in l.conditions?l.conditions:void 0;return P.isHiddenByCondition(r,e.conditionResults[l.uuid])?!1:l&&"valid"in l&&!l.valid}):!0};function hn(e){const t={};for(const s of e){const a=P.extractFormulaReferences(s.formula);for(const o of a)t[o]||(t[o]=[]),t[o].includes(s.uuid)||t[o].push(s.uuid)}return t}function Pt(e,t){return{resolveValue:s=>{if(s in t)return t[s];const a=de(e,s);if(!a)return null;const o=a.value;if(o==null||o==="")return null;const l=Number(o);return isNaN(l)?null:l},resolveOptionMetadata:(s,a)=>{const o=de(e,s);if(!o)return null;const l=o.value;if(!l)return null;const r="options"in o.properties?o.properties.options:void 0;if(!Array.isArray(r))return null;const i=r.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:s=>{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===s);if(l===-1)continue;const r=[];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)||r.push(u)}return r.length>0?r:null}return null}}}function nt(e){const t=e.calculations??[];if(t.length===0)return{};const s=P.topologicalSortCalculations(t),a={},o=Pt(e,a);for(const l of s)a[l.uuid]=P.evaluateFormula(l.formula,o);return a}function Ye(e,t){const s=e.calculationsByDependency,a=e.calculations??[];if(a.length===0||!s)return null;const o=new Set,l=[t];for(;l.length>0;){const u=l.shift(),p=s[u];if(p)for(const m of p)o.has(m)||(o.add(m),l.push(m))}if(o.size===0)return null;const r=P.topologicalSortCalculations(a),i={...e.calculationResults},d=Pt(e,i);let c=!1;for(const u of r)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 bn(e){const t={},s=a=>{var l;if(a.type!=="computed"||!((l=a.properties)!=null&&l.formula))return;const o=P.extractFormulaReferences(a.properties.formula);for(const r of o)t[r]||(t[r]=[]),t[r].includes(a.uuid)||t[r].push(a.uuid)};for(const a of Object.values(e))if(s(a),(a.type==="repeater"||a.type==="group")&&a.components)for(const o of a.components)s(o);return t}function Ft(e,t,s,a){var d,c;const o=e.components[s],l=((d=o==null?void 0:o.components)==null?void 0:d.map(u=>u.uuid))??[],r=(c=o==null?void 0:o.addedComponents)==null?void 0:c[a],i=new Map;if(r)for(let u=0;u<r.length;u++){const p=l[u];p&&i.set(p,r[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=de(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)??de(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 Be(e,t){return{resolveValue:s=>{if(s in t)return t[s];const a=de(e,s);if(!a)return null;const o=a.value;if(o==null||o==="")return null;const l=Number(o);return isNaN(l)?null:l},resolveOptionMetadata:(s,a)=>{const o=de(e,s);if(!o)return null;const l=o.value;if(!l)return null;const r="options"in o.properties?o.properties.options:void 0;if(!Array.isArray(r))return null;const i=r.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:s=>{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===s);if(l===-1)continue;const r=[];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)||r.push(u)}return r.length>0?r:null}return null}}}function rt(e){var s,a;const t=e.calculationResults??{};for(const o of Object.values(e.components))if(o.type==="computed"&&((s=o.properties)!=null&&s.formula)){const l=Be(e,t),r=P.evaluateFormula(o.properties.formula,l);o.value=r}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 r=o.addedComponents[l];for(let i=0;i<r.length;i++){const d=r[i],c=o.components[i];if((c==null?void 0:c.type)==="computed"&&((a=c.properties)!=null&&a.formula)){const u=o.type==="repeater"?Ft(e,t,o.uuid,l):Be(e,t),p=P.evaluateFormula(c.properties.formula,u);d.value=p}}}}function vn(e,t){var r,i;const s=e.computedByDependency;if(!s)return!1;const a=s[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"&&((r=c.properties)!=null&&r.formula)){const u=Be(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"?Ft(e,o,u.uuid,f):Be(e,o),b=P.evaluateFormula(m.properties.formula,y);v.value!==b&&(u.addedComponents[f][p]={...v,value:b},l=!0)}}}return l}const Le=(e,t)=>{for(const s of e.screenOrder)if(e.screens[s].components.some(o=>o.uuid===t))return s;return null},xn=(e,t)=>{if(!t.includes(":"))return null;const s=t.split(":");if(s.length!==3)return null;const a=s[0],o=parseInt(s[2]),l=e.components[a];if(!l||l.type!=="repeater"||!l.components)return null;const r=l.components[o];return(r==null?void 0:r.uuid)??null},Nt=(e,t,s,a,o)=>{const l=t(),r=l.groupComponentMap[s]??s,i=st(e,t,r),d=tt(l,s,a),c=Le(l,o),u={components:{...l.components},validationErrors:d};if(i&&(u.conditionResults=i),c){const b={...l,...u};u.screenValidity={...l.screenValidity,[c]:ce(b,c)}}const p={...l,...u},m=s.includes(":")?xn(p,s):null,f=[],v=b=>{if(vn(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=Ye(p,r);if(m&&m!==r){const b=y?{...p,calculationResults:y}:p,_=Ye(b,m);_&&(y=_)}for(const b of f){const _=y?{...p,calculationResults:y}:p,w=Ye(_,b);w&&(y=w)}y&&(u.calculationResults=y),e(u)},gn=(e,t)=>({updateComponentValue:(s,a)=>{var r,i;const o=t();if(s.includes(":")){const d=s.split(":"),c=d[0],u=parseInt(d[1]),p=parseInt(d[2]),m=o.components[c];if(!((i=(r=m==null?void 0:m.addedComponents)==null?void 0:r[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){Nt(e,t,s,m.addedComponents[u][p],c);return}e({components:{...o.components}});return}const l=o.components[s];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,Nt(e,t,s,l,s)}},addGroupIteration:s=>{const a=t(),o=a.components[s];if(!o||o.type!=="group"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l={...a.conditionsByDependency},r=o.components.map((c,u)=>{const p=re(c);if(p.uuid=[s,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,le(l,p.uuid,f,"component"))}const m=J(p);return p.valid=m.length===0,p});o.addedComponents.push(r);const i=Le(a,s),d={...a.screenValidity};return i&&(d[i]=ce({...a},i)),e({components:{...a.components},groupComponentMap:{...a.groupComponentMap},conditionsByDependency:l,screenValidity:d}),o.addedComponents},addRepeaterIteration:s=>{const a=t(),o=a.components[s];if(!o||o.type!=="repeater"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l={...a.conditionsByDependency},r=o.components.map((p,m)=>{const f=re(p);if(f.uuid=[s,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,le(l,f.uuid,y,"component"))}const v=J(f);return f.valid=v.length===0,f});o.addedComponents.push(r);const i=Le(a,s),d={...a.screenValidity};i&&(d[i]=ce({...a},i));const c={...a,components:{...a.components}};rt(c);const u=nt(c);return e({components:{...a.components},conditionsByDependency:l,screenValidity:d,calculationResults:u}),o.addedComponents},removeRepeaterIteration:(s,a)=>{var y;const o=t(),l=o.components[s];if(!l||l.type!=="repeater"||!l.addedComponents)return;const r=((y=l.properties)==null?void 0:y.minIterations)??1;if(l.addedComponents.length<=r)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,E=[s,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=Le(o,s),m={...o.screenValidity};p&&(m[p]=ce({...o},p));const f={...o,components:{...o.components}};rt(f);const v=nt(f);e({components:{...o.components},conditionsByDependency:c,validationErrors:u,screenValidity:m,calculationResults:v})}}),de=(e,t)=>$t(e.components,t),le=(e,t,s,a)=>{const o=new Set;for(const r of s.when.rules)o.add(r.source);const l={target:t,type:a,config:s};for(const r of o)e[r]||(e[r]=[]),e[r].push(l)},yn=(e,t)=>{var s,a;return t.includes(":")?(s=de(e,t))==null?void 0:s.value:(a=e.components[t])==null?void 0:a.value},Pe=(e,t)=>P.evaluateConditionConfig(t,(s,a)=>(a==null?void 0:a.sourceType)==="context"?e.externalContext[a.source]:yn(e,s)),st=(e,t,s)=>{const a=t(),o=a.conditionsByDependency[s];if(!o||o.length===0)return null;let l=!1;const r={...a.conditionResults};for(const i of o){const d=Pe(a,i.config);r[i.target]!==d&&(r[i.target]=d,l=!0)}return l?r:null},jn=e=>{const t={},s=new Set;for(const a of Object.values(e.conditionsByDependency))for(const o of a)s.has(o.target)||(s.add(o.target),t[o.target]=Pe(e,o.config));return t},Ge=e=>{if(!e||Oe(e.type))return null;const t="label"in e.properties?e.properties.label:"",s={uuid:e.uuid,type:e.type,value:e.value};return t&&(s.label=t),s},kt=e=>{if(e.conditions&&"when"in e.conditions)return e.conditions},_n=e=>{const t={uuid:e.flowUUID,metadata:e.metadata,screens:[]},s=o=>{const l=e.screens[o];if(!l)return!1;const r=l.conditions&&"when"in l.conditions?l.conditions:void 0;return P.isHiddenByCondition(r,e.conditionResults[o])};t.screens=e.screenOrder.filter(o=>!s(o)).map(o=>{const l=e.screens[o],r={uuid:o,components:l.components.map(i=>{const d=e.components[i.uuid];if(!d)return null;const c=kt(d);if(P.isHiddenByCondition(c,e.conditionResults[i.uuid]))return null;if((d.type==="group"||d.type==="repeater")&&d.addedComponents){const u=Ge(d);return u?{...u,components:d.addedComponents.map(p=>p.filter(m=>{const f=kt(m);return!P.isHiddenByCondition(f,e.conditionResults[m.uuid])}).map(m=>Ge(m)).filter(m=>m!==null))}:null}return Ge(d)}).filter(i=>i!==null)};return l.label&&(r.label=l.label),r});const a=e.calculations??[];if(a.length>0){const o=e.calculationResults??{};t.calculations=a.map(l=>{const r=o[l.uuid]??null,i={uuid:l.uuid,label:l.label,value:r};return r!==null&&(i.formattedValue=P.formatCalculationResult(r,l.format,l.decimalPlaces,l.currencySymbol)),i})}return t},Fe=g.createContext(null);function A(e){const t=g.useContext(Fe);if(!t)throw new Error("useFBREStore must be used within an FBRE provider");return ee.useStore(t,e)}const _e=()=>{const e=g.useContext(Fe);if(!e)throw new Error("useFBREStoreApi must be used within an FBRE provider");return e},ke=e=>!e||Object.keys(e).length===0?null:"when"in e?e:null,wn=[],Cn=()=>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:(s,a,o)=>{const l={},r=[],i={},d={},c={},u={},p={},m={},f={};s.screens.forEach(S=>{const R=ke(S.conditions),I=R?{...S,conditions:R}:{...S};l[S.uuid]=I,r.push(S.uuid),R&&le(u,S.uuid,R,"screen"),S.components.forEach(x=>{const h=ke(x.conditions),j=re(x);h&&(j.conditions=h),i[x.uuid]=j,h&&le(u,x.uuid,h,"component");const N=Z.getValidationConfig(j);if(N&&xe(p,x.uuid,N),(x.type==="group"||x.type==="repeater")&&x.components){const M=i[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,V=B?B.length:x.type==="repeater"&&L&&L>1?L:1;for(let F=0;F<V;F++){const W=x.components.map((X,ae)=>{const T=re(X);T.uuid=[x.uuid,M.addedComponents.length,ae].join(":"),B&&B[F]&&X.uuid in B[F]&&(T.value=B[F][X.uuid]),x.type==="group"&&(d[T.uuid]=X.uuid),F===0&&(c[X.uuid]=T.uuid);const z=ke(T.conditions);z&&(T.conditions=z,le(u,T.uuid,z,"component"));const Y=Z.getValidationConfig(T);Y&&xe(p,T.uuid,Y);const G=J(T);return T.valid=G.length===0,G.length>0&&(m[T.uuid]=G),T});M.addedComponents.push(W)}}})}),a&&a.screens.forEach(S=>{const R=r.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=s.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 V=re(B);V.uuid=[x.uuid,x.addedComponents.length,L].join(":"),x.type==="group"&&(d[V.uuid]=B.uuid),c[B.uuid]||(c[B.uuid]=V.uuid);const F=ke(V.conditions);F&&(V.conditions=F,le(u,V.uuid,F,"component"));const W=Z.getValidationConfig(V);W&&xe(p,V.uuid,W);const X=J(V);return V.valid=X.length===0,X.length>0&&(m[V.uuid]=X),V});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(i)){const R=i[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:o??{},screens:l,screenOrder:r,components:i,groupComponentMap:d,templateComponentMap:c,conditionsByDependency:u,conditionResults:{},validationErrors:m,validationsByDependency:p},y=jn(v);v.conditionResults=y,r.forEach(S=>{f[S]=ce(v,S)});const b=bn(i),_={...v,computedByDependency:b,calculationResults:{},screenValidity:f};rt(_);const w=s.calculations??[],C=hn(w),E={..._,calculations:w},k=nt(E);e({flowUUID:s.uuid,metadata:s.metadata,config:s.config??{},externalContext:o??{},screens:l,screenOrder:r,components:i,groupComponentMap:d,templateComponentMap:c,conditionsByDependency:u,conditionResults:y,screenValidity:f,validationErrors:m,validationsByDependency:p,calculations:w,calculationResults:k,calculationsByDependency:C,computedByDependency:b})},updateContext:s=>{const a=t(),o=a.externalContext,l=[];for(const c of Object.keys(s))o[c]!==s[c]&&l.push(c);for(const c of Object.keys(o))!(c in s)&&!l.includes(c)&&l.push(c);if(l.length===0)return;const r={...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:s},f=Pe(m,p.config);r[p.target]!==f&&(r[p.target]=f,i=!0)}}if(i){const c={...a,conditionResults:r},u={};for(const p of a.screenOrder)u[p]=ce(c,p);e({externalContext:s,conditionResults:r,screenValidity:u})}else e({externalContext:s})},...gn(e,t),getFlowData:()=>_n(t()),getScreenByIndex:s=>{const a=t();return s<0||s>=a.screenOrder.length?null:a.screens[a.screenOrder[s]]},getScreenValidity:s=>{const a=t();return s<0||s>=a.screenOrder.length?!0:a.screenValidity[a.screenOrder[s]]??!0},getValidationErrors:s=>t().validationErrors[s]??wn,evaluateFlowValidation:()=>{const s=t(),a={};let o=!0;return s.screenOrder.forEach(l=>{const r=ce(s,l);a[l]=r,r||(o=!1)}),e({screenValidity:a}),o},getMaxScreenCount:()=>t().screenOrder.length-1,getCalculationResult:s=>t().calculationResults[s]??null})),Nn=({uuid:e})=>{var i;const t=A(d=>d.components[e]),s=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,s))return null;const o=At(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,r=l&&l!=="full"?`fbre-component fbre-width-${l}`:"fbre-component";return n.jsx("div",{className:r,"data-uuid":e,children:n.jsx(o,{uuid:e})})},ot=({screenIndex:e})=>{const t=A(s=>{const a=s.screenOrder[e];return a?s.screens[a]:null});return t?n.jsx("div",{className:"fbre-screen",children:t.components.map(s=>n.jsx(Nn,{uuid:s.uuid},s.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"})}),me=({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"})]}),at=({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"})]}),we=({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"})}),kn=({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"})}),Sn=({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"})}),En=({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"})}),Rn=({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"})}),Dn=({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"})}),it=({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"})}),Tn=({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"})}),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("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"})]}),Ln=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("polyline",{points:"9,12 11.5,14.5 16,9.5"})]}),Mn=({size:e=18})=>n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"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"})]}),On=({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"})]}),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:"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"})]}),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:"M3 11l18-5v12L3 13v-2z"}),n.jsx("path",{d:"M11.6 16.8a3 3 0 11-5.8-1.6"})]}),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:"M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"}),n.jsx("path",{d:"M13.73 21a2 2 0 01-3.46 0"})]}),$n=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),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("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"})}),Fn=({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"})]}),Un=({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"})}),Hn=({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"})}),qn=({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"})]}),zn=({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"})]}),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:"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"})]}),Wn=({size:e=18})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("circle",{cx:"12",cy:"12",r:"10"})}),Yn=({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)"})}),Xe={info:In,check:Ln,warning:Mn,question:zn,lightbulb:Bn,megaphone:Vn,bell:An,shield:$n,lock:Pn,heart:Ut,flag:Fn,bookmark:Un,zap:Hn,pencil:qn,star:it},Gn={star:it,heart:Ut,thumbsUp:Kn,circle:Wn,diamond:Yn},Se=({position:e,screenIndex:t,maxScreenIndex:s,allowInvalidTransition:a,screenValidity:o,summaryEnabled:l,summaryActive:r,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&&!r||v;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--secondary",disabled:C,onClick:m,children:[n.jsx(En,{}),c||"Back"]})}const y=l?i&&r:i,b=l?i?r?"Done":"Review":"Next":i?"Done":"Next";if(s===0){const C=l?r?"Complete":"Review":"Complete",E=v||!o;return n.jsxs("button",{type:"button",className:"fbre-btn fbre-btn--primary",disabled:E,onClick:()=>{l&&!r?p():f()},children:[d||C,v?n.jsx("span",{className:"fbre-btn__spinner"}):n.jsx(te,{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(te,{size:16}):n.jsx(Rn,{})]})},Xn=({current:e,total:t,stepperStyle:s})=>{if(t<=1)return null;const a=t>1?e/(t-1)*100:100,l=!!s&&s!=="default"||t<=6;return n.jsxs(n.Fragment,{children:[l&&n.jsx("div",{className:"fbre-stepper fbre-stepper--dots",children:Array.from({length:t},(r,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}%`}})})]})},Jn=({current:e,total:t})=>t<=1?null:n.jsxs("div",{className:"fbre-stepper-text",children:["Step ",e+1," of ",t]}),Qn=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,r=a?n.jsx(Xn,{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(Se,{position:"back",...e}):n.jsx("div",{}),r??n.jsx("div",{}),n.jsx(Se,{position:"next",...e})]})}return n.jsxs("div",{className:`fbre-controls fbre-controls--${t}`,"data-button-count":l,children:[r&&n.jsx("div",{className:"fbre-controls__stepper",children:r}),n.jsxs("div",{className:"fbre-controls__row",children:[o&&n.jsx(Se,{position:"back",...e}),n.jsx(Se,{position:"next",...e})]})]})},Ht=({component:e})=>{const{uuid:t,label:s,type:a,value:o,components:l}=e,r=()=>{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:s}),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:s}),a!=="group"&&a!=="repeater"&&n.jsx("div",{className:`fbre-summary__item-value${d?" fbre-summary__item-value--empty":""}`,children:r()}),(a==="group"||a==="repeater")&&i()]})},Je=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),he=(e,t)=>{const s=e.replace(P.REF_REGEX,(a,o)=>{const l=t.resolveCalculation(o);if(l!==null)return Je(l);const r=t.resolveComponentValue(o);if(r!==null)return Je(r);const i=t.resolveContext(o);return i!==null?Je(i):""});return P.convertMarkupToHTML(s)},ue=(e,t)=>e.replace(P.REF_REGEX,(s,a)=>{const o=t.resolveCalculation(a);if(o!==null)return o;const l=t.resolveComponentValue(a);if(l!==null)return l;const r=t.resolveContext(a);return r!==null?r:""});function pe(){const e=A(l=>l.components),t=A(l=>l.templateComponentMap),s=A(l=>l.calculations),a=A(l=>l.calculationResults),o=A(l=>l.externalContext);return g.useMemo(()=>{const l=new Map(s.map(i=>[i.uuid,i])),r=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=r(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,s,a,o])}const Zn=({screen:e,showToggle:t})=>{const s=pe(),[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:ue(e.label,s)}),t&&n.jsx("span",{className:`fbre-summary__screen-toggle${a?"":" collapsed"}`,children:n.jsx(we,{size:20})})]}),n.jsx("div",{className:`fbre-summary__screen-body${a?"":" collapsed"}`,children:e.components.map(l=>n.jsx(Ht,{component:l},l.uuid))})]})},St=()=>{const e=_e(),t=A(o=>o.components),s=g.useMemo(()=>e.getState().getFlowData(),[e,t]),a=s.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:s.screens.map(o=>n.jsx(Zn,{screen:o,showToggle:a>1},o.uuid))})]})},er=({title:e,body:t})=>{const s=pe();return n.jsxs("div",{className:"fbre-confirmation",children:[e&&n.jsx("h2",{className:"fbre-confirmation__title",dangerouslySetInnerHTML:{__html:he(e,s)}}),t&&n.jsx("div",{className:"fbre-confirmation__body",dangerouslySetInnerHTML:{__html:he(t,s)}})]})},qt=(e,t,s)=>t?!P.isHiddenByCondition(t,s[e]):!0,Ve=(e,t)=>{const s=e.screenOrder.length-1;let a=t+1;for(;a<=s;){const o=e.screenOrder[a],l=e.screens[o],r=l!=null&&l.conditions&&"when"in l.conditions?l.conditions:void 0;if(qt(o,r,e.conditionResults))return a;a++}return null},tr=(e,t)=>{let s=t-1;for(;s>=0;){const a=e.screenOrder[s],o=e.screens[a],l=o!=null&&o.conditions&&"when"in o.conditions?o.conditions:void 0;if(qt(a,l,e.conditionResults))return s;s--}return 0};function K(e,t,s){return`color-mix(in srgb, ${e} ${t}%, ${s})`}const Q="var(--fbre-bg)",Ee="var(--fbre-text)";function zt(e){const t={};if(!e)return t;if(e.color){const s="var(--fbre-theme-color)";t["--fbre-theme-color"]=e.color,t["--fbre-theme-light"]=K(s,14,Q),t["--fbre-theme-dark"]=K(s,82,"#000")}if(e.background&&(t["--fbre-bg"]=e.background),e.surface){const s="var(--fbre-surface)";t["--fbre-surface"]=e.surface,t["--fbre-surface-hover"]=K(s,96,Ee),t["--fbre-surface-subtle"]=K(s,90,Ee),t["--fbre-surface-alt"]=K(s,82,Ee),t["--fbre-control-surface"]=s,t["--fbre-input-bg"]=s,t["--fbre-input-bg-focus"]=K(s,60,Q)}if(e.text){const s="var(--fbre-text)";t["--fbre-text"]=e.text,t["--fbre-text-secondary"]=K(s,64,Q),t["--fbre-label"]=K(s,64,Q),t["--fbre-text-placeholder"]=K(s,42,Q),t["--fbre-text-disabled"]=K(s,34,Q)}if(e.border){const s="var(--fbre-border)";t["--fbre-border"]=e.border,t["--fbre-border-hover"]=K(s,70,Ee),t["--fbre-border-light"]=K(s,60,Q),t["--fbre-border-subtle"]=K(s,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 nr=new Set(["text","header","callout","divider","table","computed"]);function Kt(e,t){const s=e.screenOrder[t];if(!s)return 0;const a=e.screens[s];if(!a)return 0;let o=0;for(const l of a.components){const r=e.components[l.uuid];if(!r||nr.has(r.type))continue;const i=r.conditions&&"when"in r.conditions?r.conditions:void 0;P.isHiddenByCondition(i,e.conditionResults[l.uuid])||(o+=1)}return o}const ct=new Set(["radio","yesNo","cardSelect","dropDown"]),rr=500;function Wt(e,t,s){const a=_e(),o=g.useRef(null),l=g.useRef(""),r=g.useRef(0);g.useEffect(()=>{if(!e)return;const i=a.getState(),d=Et(i,t);d&&(l.current=Rt(i.components,d)),r.current=i.selectionTick},[e,t,a]),g.useEffect(()=>{if(!e)return;const i=a.subscribe(d=>{const c=Et(d,t);if(!c)return;const u=d.selectionTick,p=u!==r.current;p&&(r.current=u);const m=Rt(d.components,c);if(m===l.current&&!p)return;const f=l.current;if(l.current=m,!(m!==f?sr(d.components,c,f):p&&or(d.components,c))||Ve(d,t)===null)return;const b=d.screenOrder[t];b&&d.screenValidity[b]===!1||Kt(d,t)===1&&(o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{o.current=null,s()},rr))});return()=>{i(),o.current&&(clearTimeout(o.current),o.current=null)}},[e,t,a,s]),g.useEffect(()=>()=>{o.current&&(clearTimeout(o.current),o.current=null)},[t])}function Et(e,t){const s=e.screenOrder[t];if(!s)return null;const a=e.screens[s];return a?a.components.map(o=>o.uuid):null}function Rt(e,t){const s=[];for(const a of t){const o=e[a];!o||!ct.has(o.type)||s.push(`${a}=${JSON.stringify(o.value??null)}`)}return s.join("|")}function sr(e,t,s){const a=new Map;for(const o of s.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||!ct.has(l.type))continue;const r=JSON.stringify(l.value??null),i=a.get(o)??"null";if(r!==i&&r!=="null")return!0}return!1}function or(e,t){for(const s of t){const a=e[s];if(!(!a||!ct.has(a.type))&&a.value!==null&&a.value!==void 0)return!0}return!1}function Yt(e,t,s){const a=_e();g.useEffect(()=>{if(!e)return;const o=l=>{if(l.key!=="Enter")return;const r=l.target;if(r.tagName!=="INPUT"||!r.closest(".fbre-container"))return;const i=a.getState();if(Ve(i,t)===null)return;const c=i.screenOrder[t];c&&i.screenValidity[c]===!1||Kt(i,t)===1&&(l.preventDefault(),s())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[e,t,s,a])}const Gt=g.createContext(null),Dt=[],U=e=>{const t=g.useContext(Gt),s=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]??Dt),r=A(i=>i.updateComponentValue);return t?{value:t.value,properties:t.properties,valid:t.valid,validationErrors:Dt,updateValue:r}:{value:s,properties:a,valid:o,validationErrors:l,updateValue:r}},be=(e,t)=>U(e),ar=({uuid:e})=>{const{properties:t}=be(e),s=pe(),a=t==null?void 0:t.value;if(!a)return null;const o=ue(a,s);return n.jsx("h2",{className:"fbre-header",children:o})};$("header",ar);const lr=({uuid:e})=>{const{properties:t}=be(e),s=pe(),a=t==null?void 0:t.value;return a==null?null:n.jsx("div",{className:"fbre-text",dangerouslySetInnerHTML:{__html:he(a,s)}})};$("text",lr);const ir=({uuid:e})=>{const{properties:t}=be(e),s=(t==null?void 0:t.textAlign)??"center",a=s==="left"?" fbre-divider--left":s==="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",ir);const cr={info:"info",success:"check",warning:"warning",neutral:void 0},dr=({uuid:e})=>{const{properties:t}=be(e),s=pe(),a=t==null?void 0:t.value,o=t==null?void 0:t.title,l=(t==null?void 0:t.variant)??"info",r=t==null?void 0:t.icon;if(!a&&!o)return null;let i;if(r==="none")i=void 0;else if(r&&Xe[r])i=Xe[r];else{const c=cr[l];i=c?Xe[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:ue(o,s)}),a&&n.jsx("div",{className:"fbre-callout__body",dangerouslySetInnerHTML:{__html:he(a,s)}})]})]})};$("callout",dr);const ur=({uuid:e})=>{const{properties:t}=be(e),s=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,r=l?l-1:-1;return!a||!o||a.length===0?null:n.jsxs("div",{className:"fbre-table",children:[s&&n.jsx("div",{className:"fbre-table__label",children:s}),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:r===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:r===u?"fbre-table__cell fbre-table__cell--highlight":"fbre-table__cell",children:i.values[u]??""},u))]},d))})]})]})};$("table",ur);const pr=({uuid:e})=>{const{properties:t,value:s}=be(e),a=t==null?void 0:t.label,o=(t==null?void 0:t.showLabel)!==!1,l=t==null?void 0:t.detail,r=t==null?void 0:t.format,i=t==null?void 0:t.decimalPlaces,d=t==null?void 0:t.currencySymbol,c=P.formatCalculationResult(typeof s=="number"?s:null,r,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",pr);const Xt=({text:e})=>{var d;const[t,s]=g.useState(!1),a=g.useRef(null),o=g.useRef(null),[l,r]=g.useState(null),i=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;i();const c=p=>{const m=p.target;a.current&&!a.current.contains(m)&&o.current&&!o.current.contains(m)&&s(!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:()=>s(!t),"aria-label":"Help",children:n.jsx(Dn,{})}),t&&l&&pn.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)]})},q=({label:e,detail:t,showLabel:s,required:a,helperText:o,tooltip:l,inputId:r,externalFocused:i,error:d,errorMessages:c,children:u})=>{const p=pe(),[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:he(t,p)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[e&&(!t||t.length===0||s)&&n.jsxs("label",{className:"fbre-field__label",htmlFor:r,children:[ue(e,p),a&&n.jsx("span",{className:"required",children:"*"})]}),u({focused:m,setFocused:f}),o&&n.jsx("div",{className:"fbre-field__helper",children:ue(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(Xt,{text:l})]})]})},fr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,i=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?o: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:i,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=>l(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(kn,{}):n.jsx(Sn,{})})]})})};$("inputText",fr);const mr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s;if(!r)return null;const i=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:i,errorMessages:i?o: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=>l(e,u.target.value),onFocus:()=>c(!0),onBlur:()=>c(!1)})})};$("inputTextArea",mr);const hr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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(""),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(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?o: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:i,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,l(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?o: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=>l(e,y.target.value),onFocus:()=>v(!0),onBlur:y=>f(y,v)})]})})};$("inputNumber",hr);function Ue(e,t,s){g.useEffect(()=>{if(!t)return;const a=o=>{e.current&&!e.current.contains(o.target)&&s()};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[t,e,s])}function Jt(e){let t=e.parentElement;for(;t;){const{overflow:s,overflowY:a}=getComputedStyle(t);if(/(auto|scroll)/.test(s+a))return t;t=t.parentElement}return document.documentElement}function Tt(e,t){const s=Jt(e),a=s===document.documentElement?{top:0,bottom:window.innerHeight}:s.getBoundingClientRect(),o=e.getBoundingClientRect(),l=a.bottom-o.bottom,r=o.top-a.top;return l<t&&r>l}function He(e,t,s=300){const[a,o]=g.useState(!1);return g.useLayoutEffect(()=>{if(!t||!e.current){o(!1);return}const l=e.current.offsetParent;l&&o(Tt(l,s))},[t,s]),g.useEffect(()=>{if(!t||!e.current)return;const l=()=>{var i;const r=(i=e.current)==null?void 0:i.offsetParent;r&&o(Tt(r,s))};return window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[t,s]),a}const br=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[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([]);Ue(p,i,g.useCallback(()=>d(!1),[]));const y=He(f,i,200);if(g.useEffect(()=>{var h;i&&c>=0&&((h=v.current[c])==null||h.focus())},[i,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=>{l(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"&&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(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.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):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${i?" open":""}`,children:n.jsx(we,{})})]}),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(te,{})})]},`${e}-${j}`)})})]})})};$("dropDown",br);const vr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[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([]);Ue(p,i,g.useCallback(()=>d(!1),[]));const y=He(f,i,200);if(g.useEffect(()=>{var h;i&&c>=0&&((h=v.current[c])==null||h.focus())},[i,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];l(e,N)},k=(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&&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: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=>k(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(we,{})})]}),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:()=>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",vr);const Qt=({label:e,detail:t,showLabel:s,required:a,helperText:o,tooltip:l,error:r,errorMessages:i,children:d})=>{const c=pe(),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:he(t,c)}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start"},children:[n.jsxs("div",{style:{flex:1},children:[s!==!1&&(!t||t.length===0)&&n.jsxs("div",{className:"fbre-option-group__label",children:[ue(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:ue(o,c)}),(()=>{const p=i==null?void 0:i.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)"]})]})})()]}),l&&n.jsx(Xt,{text:l})]})]})},xr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s;if(!r)return null;const i=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];l(e,f)};return n.jsx(Qt,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,error:c,errorMessages:c?o:void 0,children:r.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(te,{})}),n.jsx("span",{className:"fbre-option-item__text",children:p.label})]},`${e}-${m}`)})})};$("checkbox",xr);const gr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,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(!r)return null;const d=r.readOnly===!0,c=t,u=t!=null&&a===!1;return n.jsx(Qt,{label:r.label,detail:r.detail,showLabel:r.showLabel,required:r.required,helperText:r.helperText,tooltip:r.tooltip,error:u,errorMessages:u?o: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&&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(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",gr);const yr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s;if(!r)return null;const i=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(${i}, 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:()=>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",yr);const jr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=t,i=s,[d,c]=g.useState(null);if(!i)return null;const u=i.max??5,p=i.precision??1,m=d??r??0,f=r!=null&&a===!1,v=i.icon&&Gn[i.icon]||it,y=(k,S)=>{const R=S&&p<=.5?k+.5:k+1;l(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(),l(e,R))};return n.jsx(q,{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":r??0,onKeyDown:E,children:_}),r!=null&&n.jsxs("div",{className:"fbre-rating__value",children:[r," / ",u]})]})})};$("rating",jr);const _r=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=t,i=s;if(!i)return null;const d=i.readOnly===!0,c=i.min??0,u=i.max??100,p=i.steps??1,m=(r-c)/(u-c)*100,f=a===!1;return n.jsx(q,{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:r,disabled:d,style:{"--fill":`${m}%`},onChange:v=>l(e,Number(v.target.value))}),n.jsx("span",{className:"fbre-slider__value",children:r})]}),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",_r);const wr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s;if(!r)return null;const i=a===!1;return n.jsx(q,{detail:r.detail,helperText:r.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"})}),(!r.detail||r.detail.length===0||r.showLabel)&&n.jsx("span",{className:"fbre-toggle__label",children:r.label})]})})};$("toggleSwitch",wr);const ge=new Map,Cr=(e,t)=>{ge.has(e)||ge.set(e,new Set),ge.get(e).add(t)},Nr=(e,t)=>{var s;(s=ge.get(e))==null||s.delete(t)},It=(e,t,s)=>{var a;(a=ge.get(e))==null||a.forEach(o=>{o(t,s)})},Zt=g.createContext(null);function en(){return g.useContext(Zt)}class je extends Error{constructor(t,s,a,o){super(t),this.name="ApiError",this.status=s,this.code=a,this.validationErrors=o}}class tn extends je{constructor(t,s){super(`Request timed out after ${s}ms: ${t}`,0,"TIMEOUT"),this.name="TimeoutError"}}const kr=new Set([502,503,504]),Re=2,Sr=[500,1500];function Er(e){return new Promise(t=>setTimeout(t,e))}async function oe(e,t,s={}){const o=`${e.apiEndpoint||""}${t}`,l=e.timeout??3e4,r={...s.body?{"Content-Type":"application/json"}:{},...s.headers};e.apiKey&&(r.Authorization=`Bearer ${e.apiKey}`);let i;for(let d=0;d<=Re;d++){d>0&&await Er(Sr[d-1]);try{const c=new AbortController,u=setTimeout(()=>c.abort(),l);let p;try{p=await fetch(o,{...s,headers:r,signal:c.signal})}finally{clearTimeout(u)}if(!p.ok){const m=await p.json().catch(()=>({})),f=new je(m.error||`HTTP ${p.status}`,p.status,m.code,m.validationErrors);if(d<Re&&kr.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 je)throw c;if(c instanceof DOMException&&c.name==="AbortError"){const u=new tn(o,l);if(d<Re){i=u;continue}throw u}if(c instanceof TypeError&&d<Re){i=c;continue}throw c}}throw i}async function Rr(e,t){return oe(e,`/api/v1/public/flows/${t}`)}async function Dr(e,t,s,a,o,l){return oe(e,`/api/v1/public/flows/${t}/files/presign`,{method:"POST",body:JSON.stringify({fileName:s,contentType:a,size:o,componentUuid:l})})}async function Tr(e,t,s){return oe(e,`/api/v1/public/flows/${t}/files/${s}/confirm`,{method:"POST"})}async function Ir(e,t,s){const a={flowId:t};return s&&Object.keys(s).length>0&&(a.context=s),oe(e,"/api/v1/public/sessions",{method:"POST",body:JSON.stringify(a)})}async function Lr(e,t,s){return oe(e,`/api/v1/public/sessions/${t}/next`,{method:"POST",body:JSON.stringify({data:s})})}async function Mr(e,t,s){return oe(e,`/api/v1/public/sessions/${t}/prev`,{method:"POST",body:JSON.stringify({data:s})})}async function Or(e,t,s){return oe(e,`/api/v1/public/sessions/${t}/complete`,{method:"POST",body:JSON.stringify({data:s})})}async function Br(e,t){return oe(e,`/api/v1/public/sessions/${t}`)}const Vr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,d]=g.useState(!1),[c,u]=g.useState(!1),p=g.useRef(null),m=en();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 Dr(m.config,m.flowId,b.name,b.type,b.size,e);await fetch(C,{method:"PUT",headers:{"Content-Type":b.type},body:b}),await Tr(m.config,m.flowId,w);const E={mode:"s3",fileId:w,name:b.name,type:b.type,size:b.size};l(e,E),It("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),l(e,w),It("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?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(Tn,{}),"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${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",Vr);const Ar=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s;if(!r)return null;const i=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:i,errorMessages:i?o: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:()=>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",Ar);const $r=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s;if(!r)return null;const i=a===!1,d=t===!0;return n.jsx(q,{detail:r.detail,helperText:r.helperText,tooltip:r.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:r.label})]})})};$("confirm",$r);const Lt=e=>{const{h:t,s,b:a}=e,o=s/100,l=a/100,r=l*o,i=r*(1-Math.abs(t/60%2-1)),d=l-r;let c=0,u=0,p=0;t<60?(c=r,u=i,p=0):t<120?(c=i,u=r,p=0):t<180?(c=0,u=r,p=i):t<240?(c=0,u=i,p=r):t<300?(c=i,u=0,p=r):(c=r,u=0,p=i);const m=f=>Math.round((f+d)*255).toString(16).padStart(2,"0");return`#${m(c)}${m(u)}${m(p)}`},De=e=>{const t=e.replace("#",""),s=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(s,a,o),r=Math.min(s,a,o),i=l-r;let d=0;i!==0&&(l===s?d=60*((a-o)/i%6):l===a?d=60*((o-s)/i+2):d=60*((s-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}},Qe=e=>/^#[0-9a-fA-F]{6}$/.test(e),Pr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[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"&&Qe(t)?t:"#1976d2",[_,w]=g.useState(()=>De(b));Ue(c,i,g.useCallback(()=>d(!1),[]));const C=He(p,i,320);if(g.useEffect(()=>{typeof t=="string"&&Qe(t)&&(y(t),w(De(t)))},[t]),!r)return null;const E=t!=null&&a===!1,k=h=>{w(h);const j=Lt(h);y(j),l(e,j)},S=h=>{h.preventDefault();const j=(M,B)=>{const L=m.current.getBoundingClientRect(),V=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:V,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),Qe(h)){const j=De(h);w(j),l(e,h.toLowerCase())}},x=Lt({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:i,error:E,errorMessages:E?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})}),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(De(N)),l(e,N)}},j))})]})]})})};$("colorPicker",Pr);const Fr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,i=(r==null?void 0:r.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)},[]),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");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 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?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: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",Fr);function Mt(e){const t=e.offsetParent;if(!t)return 0;const s=Jt(t),a=s===document.documentElement?{left:0,right:window.innerWidth}:s.getBoundingClientRect(),o=t.getBoundingClientRect(),l=e.offsetWidth,r=o.left+l;if(r<=a.right-8)return 0;let i=-(r-a.right+8);return o.left+i<a.left+8&&(i=a.left+8-o.left),i}const ve=({open:e,onClose:t,children:s,estimatedHeight:a=300,triggerRef:o})=>{const l=g.useRef(null);Ue(l,e,g.useCallback(()=>t(),[t]));const r=He(l,e,a),[i,d]=g.useState(0);if(g.useLayoutEffect(()=>{if(!e||!l.current){d(0);return}d(Mt(l.current))},[e]),g.useEffect(()=>{if(!e||!l.current)return;const p=()=>{l.current&&d(Mt(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"+(r?" 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:s})},Me=(e,t)=>new Date(e,t+1,0).getDate(),Ur=(e,t)=>new Date(e,t,1).getDay(),ie=(e,t,s)=>`${e}-${String(t+1).padStart(2,"0")}-${String(s).padStart(2,"0")}`,Hr=e=>{const t=e.split("-");if(t.length!==3)return null;const s=parseInt(t[0],10),a=parseInt(t[1],10)-1,o=parseInt(t[2],10);return isNaN(s)||isNaN(a)||isNaN(o)?null:{year:s,month:a,day:o}},Ae=(e,t)=>{const s=Hr(e);if(!s)return e;const a=String(s.month+1).padStart(2,"0"),o=String(s.day).padStart(2,"0"),l=String(s.year);return t==="DD/MM/YYYY"?`${o}/${a}/${l}`:t==="YYYY-MM-DD"?`${l}-${a}-${o}`:`${a}/${o}/${l}`},$e=e=>{const t=e.split(":");if(t.length!==2)return e;let s=parseInt(t[0],10);const a=t[1],o=s>=12?"PM":"AM";return s===0?s=12:s>12&&(s-=12),`${s}:${a} ${o}`},lt=(e,t)=>{const s=e.indexOf("T");if(s===-1)return e;const a=e.substring(0,s),o=e.substring(s+1);return`${Ae(a,t)} ${$e(o)}`},qr=(e,t,s)=>{let a=e;return s==="AM"&&a===12?a=0:s==="PM"&&a!==12&&(a+=12),`${String(a).padStart(2,"0")}:${String(t).padStart(2,"0")}`},zr=e=>{const t=e.split(":");let s=parseInt(t[0],10);const a=parseInt(t[1],10),o=s>=12?"PM":"AM";return s===0?s=12:s>12&&(s-=12),{hour:s,minute:a,ampm:o}},Kr=(e,t,s)=>e>=t&&e<=s,se=e=>{if(!e)return;if(!e.startsWith("today"))return e;const t=e==="today"?0:parseInt(e.slice(5),10),s=new Date;return s.setDate(s.getDate()+(isNaN(t)?0:t)),ie(s.getFullYear(),s.getMonth(),s.getDate())},Wr=["January","February","March","April","May","June","July","August","September","October","November","December"],Yr=e=>Wr[e],Gr=["Su","Mo","Tu","We","Th","Fr","Sa"],ye=e=>[parseInt(e.substring(0,4),10),parseInt(e.substring(5,7),10)-1,parseInt(e.substring(8,10),10)],fe=(e,t)=>{const[s,a,o]=ye(e),l=new Date(s,a,o+t);return ie(l.getFullYear(),l.getMonth(),l.getDate())},Te=(e,t)=>{let[s,a,o]=ye(e);for(a+=t;a<0;)a+=12,s--;for(;a>11;)a-=12,s++;return ie(s,a,Math.min(o,Me(s,a)))},qe=({selectedDate:e,min:t,max:s,onSelect:a,rangeStart:o,rangeEnd:l,rangeHover:r})=>{const i=new Date,d=ie(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]=ye(c),b=()=>u(Te(c,-1)),_=()=>u(Te(c,1)),w=j=>{let N=null;switch(j.key){case"ArrowLeft":N=fe(c,-1);break;case"ArrowRight":N=fe(c,1);break;case"ArrowUp":N=fe(c,-7);break;case"ArrowDown":N=fe(c,7);break;case"Home":{const[D,M,B]=ye(c);N=fe(c,-new Date(D,M,B).getDay());break}case"End":{const[D,M,B]=ye(c);N=fe(c,6-new Date(D,M,B).getDay());break}case"PageUp":N=Te(c,-1);break;case"PageDown":N=Te(c,1);break}N&&(j.preventDefault(),f(N))},C=Me(v,y),E=Ur(v,y),k=[],S=y===0?Me(v-1,11):Me(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:ie(M,D,N),outside:!0})}for(let j=1;j<=C;j++)k.push({day:j,iso:ie(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:ie(D,N,j),outside:!0})}const I=r??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:[Yr(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:Gr.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||s&&j.iso>s,L=x&&h&&Kr(j.iso,x,h),V=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",V&&"fbre-calendar__day--range-start",F&&"fbre-calendar__day--range-end"].filter(Boolean).join(" ");return n.jsx("button",{type:"button",ref:X=>{p.current[j.iso]=X},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)})})]})},Xr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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: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:Ae(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(me,{})})]}),n.jsx(ve,{open:i,onClose:()=>d(!1),triggerRef:c,children:n.jsx(qe,{selectedDate:m,min:se(r.min),max:se(r.max),onSelect:f=>{l(e,f),d(!1)}})})]})})};$("date",Xr);const Ot=e=>{if(!e)return null;const t=e.split(":");if(t.length!==2)return null;const s=parseInt(t[0],10),a=parseInt(t[1],10);return isNaN(s)||isNaN(a)?null:s*60+a},Ze=(e,t)=>t==="AM"&&e===12?0:t==="PM"&&e!==12?e+12:e,ze=({value:e,min:t,max:s,step:a=15,onChange:o})=>{const l=g.useRef(null),r=g.useRef(null),i=e?zr(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(()=>Ot(t),[t]),y=g.useMemo(()=>Ot(s),[s]),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=Ze(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=Ze(d,u);return!_(h,x)},E=x=>{if(!b)return!1;for(const h of p){const j=Ze(h,x);for(let N=0;N<60;N+=a)if(_(j,N))return!1}return!0},k=(x,h,j)=>{o(qr(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(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: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&&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)})})]})},Jr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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: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:$e(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(at,{})})]}),n.jsxs(ve,{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(te,{size:12})})]}),n.jsx(ze,{value:m||void 0,step:r.step,min:r.min,max:r.max,onChange:f=>{l(e,f)}})]})]})})};$("time",Jr);const Qr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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=>{l(e,`${x}T${_||"12:00"}`),u("time")},k=x=>{const h=b||new Date().toISOString().substring(0,10);l(e,`${h}T${x}`)},S=()=>{u("date")},R=se(r.min&&r.min.includes("T")?r.min.split("T")[0]:r.min),I=se(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: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:lt(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(me,{})})]}),n.jsx(ve,{open:i,onClose:C,triggerRef:p,children:c==="date"?n.jsx(qe,{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(ze,{value:_||void 0,step:r.step,min:r.minTime,max:r.maxTime,onChange:k})]})})]})})};$("dateTime",Qr);const Zr=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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(i==="start"){const E=b&&C>b?"":b;l(e,{start:C,end:E}),d(E?null:"end")}else if(i==="end"){const E=y&&C<y?C:y,k=C<E?E:C;l(e,{start:E||C,end:E?k:""}),E&&k&&d(null)}u(void 0)},w=i!==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?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:Ae(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(me,{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:Ae(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(me,{size:12})})]})})]}),n.jsx(ve,{open:w,triggerRef:i==="start"?p:m,onClose:()=>{d(null),u(void 0)},children:n.jsx(qe,{selectedDate:i==="start"?y:b,min:se(r.min),max:se(r.max),onSelect:_,rangeStart:y,rangeEnd:b,rangeHover:c})})]})})};$("dateRange",Zr);const es=({uuid:e})=>{const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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(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(q,{label:r.label,detail:r.detail,showLabel:r.showLabel,helperText:r.helperText,tooltip:r.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:$e(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(at,{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:$e(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(at,{size:12})})]})})]}),n.jsxs(ve,{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(te,{size:12})})]}),n.jsx(ze,{value:i==="start"?f||void 0:v||void 0,step:r.step,min:r.min,max:r.max,onChange:y})]})]})})};$("timeRange",es);const ts=({uuid:e})=>{var M,B;const{value:t,properties:s,valid:a,validationErrors:o,updateValue:l}=U(e),r=s,[i,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 V=L.indexOf("T");return V!==-1?{date:L.substring(0,V),time:L.substring(V+1)}:{date:"",time:"12:00"}},w=y?_(y):{date:"",time:"12:00"},C=b?_(b):{date:"",time:"12:00"},E=i==="start"?w:C,k=(L,V)=>{const F=L&&V&&V<L?"":V;l(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 V=E.time||"12:00",F=`${L}T${V}`;i==="start"?k(F,b):k(y,F),u("time")},x=L=>{const V=E.date;if(!V)return;const F=`${V}T${L}`;i==="start"?k(F,b):k(y,F)},h=()=>{u("date")},j=i!==null,N=se((M=r.min)==null?void 0:M.split("T")[0]),D=se((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?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:L=>{L.key==="Escape"&&j&&(L.preventDefault(),R())},children:[y?n.jsx("span",{className:"fbre-datetime__trigger-text",children:lt(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(me,{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:L=>{L.key==="Escape"&&j&&(L.preventDefault(),R())},children:[b?n.jsx("span",{className:"fbre-datetime__trigger-text",children:lt(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(me,{size:12})})]})})]}),n.jsx(ve,{open:j,triggerRef:i==="start"?p:m,onClose:R,children:c==="date"?n.jsx(qe,{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(ze,{value:E.time||void 0,step:r.step,min:r.minTime,max:r.maxTime,onChange:x})]})})]})})};$("dateTimeRange",ts);const nn=({uuid:e})=>{var u;const t=e.split(":")[0],s=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[s])==null?void 0:v[a]}),l=A(p=>p.conditionResults[e]);if(!o)return null;const r=o.conditions&&"when"in o.conditions?o.conditions:void 0;if(P.isHiddenByCondition(r,l))return null;const i=At(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(Gt.Provider,{value:o,children:n.jsx(i,{uuid:e})})})},ns=({uuid:e})=>{const t=A(i=>{var d;return(d=i.components[e])==null?void 0:d.properties}),s=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=s??[],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: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(we,{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(nn,{uuid:c.uuid},c.uuid))})})]},`${e}-${d}`))})};$("group",ns);const rs=({uuid:e})=>{const t=A(f=>{var v;return(v=f.components[e])==null?void 0:v.properties}),s=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,r]=g.useState(new Set([0]));if(!t)return null;const i=s??[],d=t.minIterations??1,c=()=>{const f=i.length;a(e),r(new Set([f]))},u=f=>{i.length<=d||(o(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:[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(On,{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(we,{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(nn,{uuid:b.uuid},b.uuid))})})]},`${e}-${v}`)}),n.jsx("button",{type:"button",className:"fbre-group__add-btn",onClick:c,children:"Add another"})]})};$("repeater",rs);const Bt=e=>e&&typeof e=="object"&&("title"in e||"body"in e)?e:null,ss={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"},os=({screenIndex:e,onFlowComplete:t,onScreenChange:s})=>{var ht,bt,vt,xt,gt,yt,jt,_t,wt,Ct;const a=A(O=>O.config),o=A(O=>O.screenOrder.length),l=A(O=>Object.keys(O.components).length>0),r=_e(),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=((ht=a==null?void 0:a.navigation)==null?void 0:ht.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(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}E||(O=R.current)==null||O.focus({preventScroll:!0})},[d,u,E]);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}),M=A(O=>{var H;return h?(H=O.screens[h])==null?void 0:H.backButtonLabel:void 0}),B=g.useCallback(O=>{s&&s(O,r.getState().getFlowData())},[s,r]),L=g.useCallback(O=>{y(d),_(u),C(O),k(!0),S.current&&(S.current.scrollTop=0)},[d,u]),V=g.useCallback(()=>{k(!1),y(null)},[]),F=g.useCallback(()=>{if(!E)if(u)f&&L("back"),p(!1),B(d);else{const O=r.getState(),H=tr(O,d);H!==d&&(f&&L("back"),c(H),B(H))}},[E,u,d,f,L,B,r]),W=g.useCallback(()=>{if(E)return;const O=r.getState(),H=Ve(O,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]),[X,ae]=g.useState(!1),[T,z]=g.useState(null),[Y,G]=g.useState(!1),[dt,ut]=g.useState(null),sn=g.useCallback(()=>{z(null);const O=t(r.getState().getFlowData());O&&typeof O.then=="function"?(ae(!0),O.then(H=>{ae(!1),ut(Bt(H)),G(!0)}).catch(H=>{ae(!1),z(H instanceof Error?H.message:String(H))})):(ut(Bt(O)),G(!0))},[t,r]),on=A(O=>Ve(O,d)===null),an=((bt=a==null?void 0:a.theme)==null?void 0:bt.colorScheme)??"light",Ke=((a==null?void 0:a.mode)??"standard")==="conversational";Wt(Ke&&!u,d,W),Yt(Ke&&!u,d,W);const pt=((vt=a==null?void 0:a.theme)==null?void 0:vt.style)??"clean",ft=((xt=a==null?void 0:a.controls)==null?void 0:xt.stepperStyle)??"default",We=ft==="default"?ss[pt]??"dots":ft,ln=((gt=a==null?void 0:a.controls)==null?void 0:gt.showStepper)!==!1&&We==="text",mt=zt(a==null?void 0:a.theme),Ce=a==null?void 0:a.confirmation,ne=dt??Ce??null,cn=dt?!0:(Ce==null?void 0:Ce.show)!==!1,Ne=Y&&!!ne&&cn&&!!(ne.title||ne.body),dn=()=>b?n.jsx(St,{}):v!==null?n.jsx(ot,{screenIndex:v}):null,un=E?"fbre-screen-wrapper fbre-screen-wrapper--transitioning":"fbre-screen-wrapper";return n.jsxs("div",{className:"fbre-container","data-style":pt,"data-mode":an,"data-form-mode":Ke?"conversational":void 0,"data-stepper":We!=="text"?We:void 0,"data-transition":f?m:void 0,style:Object.keys(mt).length>0?mt:void 0,children:[ln&&!Ne&&n.jsx(Jn,{current:d,total:o}),n.jsxs("div",{className:un,ref:S,children:[E&&n.jsx("div",{ref:x,className:"fbre-screen-slot fbre-screen--exiting","data-direction":w,onAnimationEnd:V,children:dn()}),n.jsx("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":Ne?"Confirmation":u?"Summary":j??`Step ${d+1} of ${o}`,children:Ne?n.jsx(er,{title:ne==null?void 0:ne.title,body:ne==null?void 0:ne.body}):n.jsxs(n.Fragment,{children:[!u&&n.jsx(ot,{screenIndex:d}),u&&n.jsx(St,{})]})})]}),T&&n.jsx("div",{className:"fbre-completion-error",children:T}),((yt=a==null?void 0:a.controls)==null?void 0:yt.show)!==!1&&l&&!Ne&&n.jsx(Qn,{screenIndex:d,maxScreenIndex:o-1,allowInvalidTransition:(jt=a==null?void 0:a.navigation)==null?void 0:jt.allowInvalidTransition,screenValidity:N,summaryEnabled:(a==null?void 0:a.summary)??!1,summaryActive:u,atMaxScreen:on,nextButtonLabel:D,backButtonLabel:M,completionLoading:X,showStepper:(_t=a==null?void 0:a.controls)==null?void 0:_t.showStepper,stepperStyle:(wt=a==null?void 0:a.controls)==null?void 0:wt.stepperStyle,controlsLayout:(Ct=a==null?void 0:a.controls)==null?void 0:Ct.layout,nextScreen:W,prevScreen:F,onFlowComplete:sn})]})},as=[],ls=()=>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:s=>{e({externalContext:s})},updateComponentValue:(s,a)=>{var d,c;const o=t();if(s.includes(":")){const u=s.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[s]??s,b=st(e,t,y),_=tt(o,s,v.addedComponents[m][f]);e({components:{...o.components},conditionResults:b??o.conditionResults,validationErrors:_});return}const l=o.components[s];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 r=st(e,t,s),i=tt(o,s,l);e({components:{...o.components},conditionResults:r??o.conditionResults,validationErrors:i})},addGroupIteration:s=>{const a=t(),o=a.components[s];if(!o||o.type!=="group"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l=o.components.map((r,i)=>{const d=re(r);d.uuid=[s,o.addedComponents.length,i].join(":"),a.groupComponentMap[d.uuid]=r.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:s=>{const a=t(),o=a.components[s];if(!o||o.type!=="repeater"||!o.components)return;o.addedComponents||(o.addedComponents=[]);const l=o.components.map((r,i)=>{const d=re(r);d.uuid=[s,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:(s,a)=>{const o=t(),l=o.components[s];if(!(!l||l.type!=="repeater"||!l.addedComponents||l.addedComponents.length<=1)){l.addedComponents.splice(a,1);for(let r=a;r<l.addedComponents.length;r++)l.addedComponents[r].forEach((i,d)=>{i.uuid=[s,r,d].join(":")});e({components:{...o.components}})}},getFlowData:()=>({uuid:"",metadata:{},screens:[]}),getScreenByIndex:s=>{const a=t();if(s!==0)return null;const o=a.screenOrder[0];return o?a.screens[o]:null},getScreenValidity:s=>{const a=t();if(s!==0)return!0;const o=a.screenOrder[0];return o?a.screenValidity[o]??!0:!0},getValidationErrors:s=>t().validationErrors[s]??as,evaluateFlowValidation:()=>{const s=t(),a=s.screenOrder[0];if(!a)return!0;const o=s.screens[a];if(!o)return!0;let l=!0;const r={components:s.components,groupComponentMap:s.groupComponentMap},i={...s.validationErrors};for(const c of o.components){const u=s.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 _=s.conditionResults[v.uuid]??!1;if(y.action==="show"&&!_||y.action==="hide"&&_)continue}const b=J(v,r);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=s.conditionResults[u.uuid]??!1;if(p.action==="show"&&!f||p.action==="hide"&&f)continue}const m=J(u,r);u.valid=m.length===0,i[u.uuid]=m,m.length>0&&(l=!1)}const d={...s.screenValidity,[a]:l};return e({components:{...s.components},validationErrors:i,screenValidity:d}),l},getMaxScreenCount:()=>0,getCalculationResult:s=>t().calculationResults[s]??null})),Ie=(e,t)=>{const s={},a={},o={},l={},r={},i={},d=t.screen.uuid;for(const b of t.screen.components){const _=re(b);if(s[_.uuid]=_,(_.type==="group"||_.type==="repeater")&&b.components){_.addedComponents||(_.addedComponents=[]);const C=b.components.map((E,k)=>{const S=re(E);S.uuid=[_.uuid,0,k].join(":"),_.type==="group"&&(a[S.uuid]=E.uuid),o[E.uuid]=S.uuid;const R=Z.getValidationConfig(S);return R&&R.rules&&R.rules.length>0&&xe(r,S.uuid,R),S});_.addedComponents.push(C)}const w=Z.getValidationConfig(_);w&&w.rules&&w.rules.length>0&&xe(r,_.uuid,w)}for(const{targetUUID:b,config:_}of t.conditions)le(l,b,_,b===d?"screen":"component");if(t.previousData)for(const b of t.previousData){const _=s[b.uuid];_&&(_.value=b.value)}const c={components:s};for(const b of Object.keys(s)){const _=s[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&&(i[E.uuid]=k)}continue}if(!Z.getValidationConfig(_))continue;const w=J(_,c);_.valid=w.length===0,w.length>0&&(i[b]=w)}const u={},p={components:s},m=new Set;for(const b of Object.values(l))for(const _ of b)m.has(_.target)||(m.add(_.target),u[_.target]=Pe(p,_.config));let f=!0;for(const b of t.screen.components){const _=s[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:s,groupComponentMap:a,templateComponentMap:o,conditionsByDependency:l,conditionResults:u,validationErrors:i,validationsByDependency:r,calculations:[],calculationResults:{},calculationsByDependency:{},computedByDependency:{},sessionId:t.sessionId,navigation:t.navigation,loading:!1,error:y,externalContext:t.context??{},config:t.config??{}})},et=e=>{const t=e.getState(),s=t.screenOrder[0];if(!s)return[];const a=t.screens[s];if(!a)return[];const o=[];for(const l of a.components){const r=t.components[l.uuid];if(!r||Oe(r.type))continue;const i={uuid:r.uuid,type:r.type,value:r.value};"label"in r.properties&&typeof r.properties.label=="string"&&(i.label=r.properties.label),(r.type==="group"||r.type==="repeater")&&r.addedComponents&&(i.components=r.addedComponents.map(d=>d.filter(c=>!Oe(c.type)).map(c=>({uuid:c.uuid,type:c.type,value:c.value})))),o.push(i)}return o},is=6e4,cs=({sessionEndpoint:e,flowId:t,apiKey:s,mode:a,theme:o,context:l,onFlowComplete:r,onScreenChange:i})=>{const d=g.useRef(null);d.current||(d.current=ls());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:s}),[e,s]),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 Ir(k,t,l);Ie(c,T)}catch(T){c.setState({loading:!1,error:T.message})}},[t,e,s,l]);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<is))try{const G=await Br(k,z.sessionId);Ie(c,G)}catch(G){G instanceof je&&G.status===404&&c.setState({loading:!1,error:"Session expired. Please start over.",screenOrder:[],screens:{}})}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[e,s]);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=et(c),G=await Lr(k,T.sessionId,Y);Ie(c,G),E.current=Date.now(),i==null||i(G.navigation.screenNumber)}catch(Y){c.setState({loading:!1}),S(Y.message)}}},[k,c,i,S,R]),h=g.useCallback(async()=>{const T=c.getState();if(!T.loading){c.setState({loading:!0}),c.getState().clearError(),R();try{const z=et(c),Y=await Mr(k,T.sessionId,z);Ie(c,Y),E.current=Date.now(),i==null||i(Y.navigation.screenNumber)}catch(z){c.setState({loading:!1}),S(z.message)}}},[k,c,i,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=et(c),G=await Or(k,T.sessionId,Y);E.current=Date.now(),r(G)}catch(Y){c.setState({loading:!1}),S(Y.message)}}},[k,c,r,S,R]),N={...f==null?void 0:f.theme,...o},M=(a??v??"standard")==="conversational",B=M&&!m.isLastScreen;Wt(B,0,x),Yt(B,0,x);const L=N.colorScheme??"light",V=zt(N),F=y[0],W=F?b[F]:void 0,X=W==null?void 0:W.nextButtonLabel,ae=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(Fe.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(V).length>0?V:void 0,children:[n.jsx("div",{className:"fbre-screen-wrapper",children:n.jsx(ot,{screenIndex:0})}),n.jsx(ds,{navigation:m,loading:u,onPrev:h,onNext:x,onComplete:j,nextButtonLabel:X,backButtonLabel:ae}),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:"×"})]})]})})},ds=({navigation:e,loading:t,onPrev:s,onNext:a,onComplete:o,nextButtonLabel:l,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:s,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: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 us(e,t,s,a,o){return!t&&!s&&!a&&!o?e:{...e,...o&&{mode:o},...t&&{theme:{...e.theme,...t}},...s&&{navigation:{...e.navigation,...s}},...a&&{controls:{...e.controls,...a}}}}const rn=({flow:e,data:t,mode:s,theme:a,navigation:o,controls:l,screenIndex:r,context:i,storeRef:d,onFlowComplete:c,onScreenChange:u,onScreenValidationChange:p,apiCtx:m})=>{const f=g.useRef(null);f.current||(f.current=Cn(),f.current.getState().loadFlow(e,t,i)),d&&(d.current=f.current),g.useEffect(()=>{f.current&&f.current.getState().loadFlow(e,t,i)},[e.uuid]),g.useEffect(()=>{if(f.current){const b=f.current.getState(),_=us(b.config,a,o,l,s);_!==b.config&&f.current.setState({config:_})}},[s,a,o,l]);const v=i?JSON.stringify(i):"";g.useEffect(()=>{f.current&&i&&f.current.getState().updateContext(i)},[v]);const y=n.jsx(Fe.Provider,{value:f.current,children:n.jsx(os,{screenIndex:r??0,onFlowComplete:c,onScreenChange:u,onScreenValidationChange:p})});return m?n.jsx(Zt.Provider,{value:m,children:y}):y},ps=({flowId:e,apiEndpoint:t,apiKey:s,data:a,mode:o,theme:l,navigation:r,controls:i,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:s};Rr(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,s]),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(rn,{flow:v,data:a,mode:o,theme:l,navigation:r,controls:i,screenIndex:d,context:c,storeRef:u,onFlowComplete:p,onScreenChange:m,onScreenValidationChange:f,apiCtx:w})},fs=e=>"sessionEndpoint"in e?n.jsx(cs,{...e}):"flowId"in e&&e.flowId?n.jsx(ps,{...e}):n.jsx(rn,{...e});exports.ApiError=je;exports.FBRE=fs;exports.TimeoutError=tn;exports.addFBREEventListener=Cr;exports.removeFBREEventListener=Nr;exports.useFBREApi=en;exports.useFBREStore=A;exports.useFBREStoreApi=_e;
|