reactaform 1.3.0 → 1.4.2
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 +60 -0
- package/dist/index.d.ts +6 -1
- package/dist/reactaform.cjs.js +5 -5
- package/dist/reactaform.es.js +2075 -1890
- package/package.json +5 -5
package/dist/reactaform.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),_=require("react"),jr=require("react-dom");function Ye(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const i=Ye(_),ke=Ye(jr),Rr=`/* ReactaForm CSS Custom Properties (CSS Variables) */\r
|
|
2
2
|
\r
|
|
3
3
|
/* Default Light Theme */\r
|
|
4
4
|
:root {\r
|
|
@@ -284,9 +284,9 @@
|
|
|
284
284
|
\r
|
|
285
285
|
\r
|
|
286
286
|
}\r
|
|
287
|
-
`,je=W.createContext(void 0),$=()=>{const e=W.useContext(je);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class le{map={};register(r,n){this.map[r]=n}get(r){return this.map[r]}has(r){return r in this.map}list(){return Object.keys(this.map)}entries(){return Object.entries(this.map)}values(){return Object.values(this.map)}size(){return Object.keys(this.map).length}unregister(r){return r in this.map?(delete this.map[r],!0):!1}clear(){this.map={}}registerAll(r){Array.isArray(r)?r.forEach(([n,o])=>this.register(n,o)):Object.entries(r).forEach(([n,o])=>this.register(n,o))}getOrDefault(r,n){return this.get(r)??n}}function Ue(e,r=300,n){const o=W.useRef(void 0),t=W.useRef(e),a=W.useRef(null),c=W.useRef(!1);W.useEffect(()=>{t.current=e},[e]),W.useEffect(()=>()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0)},[]);const u=W.useCallback(()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current=null,c.current=!1},[]),i=W.useCallback(()=>{if(o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current)try{t.current(...a.current)}finally{a.current=null,c.current=!1}},[]);return{callback:W.useCallback((...m)=>{if(n?.leading===!0&&!c.current){c.current=!0,t.current(...m),window.clearTimeout(o.current),o.current=window.setTimeout(()=>{c.current=!1,o.current=void 0},r);return}a.current=m,window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=void 0,a.current&&(t.current(...a.current),a.current=null,c.current=!1)},r)},[r,n?.leading]),cancel:u,flush:i}}const N={field:"reactaform-field",label:"reactaform-label",input:"reactaform-input",textInput:"reactaform-input--text",inputNumber:"reactaform-input--number",inputSelect:"reactaform-select",rangeInput:"reactaform-input--range",button:"reactaform-button"},B=(...e)=>{const r=[];for(const n of e)n&&(typeof n=="string"?r.push(n):typeof n=="object"&&Object.entries(n).forEach(([o,t])=>{t&&r.push(o)}));return r.join(" ")},We=({content:e,size:r="medium",animation:n=!0})=>{const{t:o,darkMode:t,formStyle:a,fieldStyle:c}=$(),[u,i]=s.useState(!1),[d,m]=s.useState({x:0,y:0}),[f,l]=s.useState(!1),h=s.useRef(null),b=s.useRef(null),p=s.useRef(null),y=s.useMemo(()=>{const R={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.06)",color:t?"#f0f0f0":"#333",border:`1px solid ${t?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.1)"}`,cursor:"pointer",transition:n?"all 0.2s ease":void 0,marginLeft:"0.3em"},text:{...{small:{padding:"4px 8px",fontSize:"11px",maxWidth:"200px"},medium:{padding:"6px 10px",fontSize:"12px",maxWidth:"240px"},large:{padding:"8px 12px",fontSize:"13px",maxWidth:"280px"}}[r],position:"absolute",backgroundColor:`var(--reactaform-tooltip-color-bg, ${t?"rgba(45,45,45,0.95)":"rgba(60,60,60,0.92)"})`,color:`var(--reactaform-tooltip-color, ${t?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:t?"0 8px 16px rgba(0,0,0,0.4)":"0 6px 18px rgba(0,0,0,0.12)",zIndex:2147483647,opacity:0,visibility:"hidden",transition:n?"opacity 0.2s ease, visibility 0.2s ease":void 0,pointerEvents:"none",whiteSpace:"normal",wordBreak:"break-word",boxSizing:"border-box"},textVisible:{opacity:1,visibility:"visible"}},v=(E,k,j)=>{const M=E?.[k];return(j&&M?M[j]:void 0)??{}};return{icon:{...R.icon,...v(a,"tooltip","icon"),...v(c,"tooltip","icon")},text:{...R.text,...v(a,"tooltip","text"),...v(c,"tooltip","text")},textVisible:R.textVisible}},[t,r,n,a,c]);s.useEffect(()=>{if(u){const C=requestAnimationFrame(()=>l(!1)),R=requestAnimationFrame(()=>{if(h.current){const v=h.current.getBoundingClientRect(),w=8;p.current=v;const E=v.right+w,k=v.top;m({x:E,y:k}),l(!0)}});return()=>{cancelAnimationFrame(R),cancelAnimationFrame(C)}}else requestAnimationFrame(()=>l(!1))},[u]),s.useEffect(()=>{if(!f)return;const C=requestAnimationFrame(()=>{if(!b.current)return;const R=b.current.getBoundingClientRect(),v=8,w=typeof window<"u"?window.innerWidth:1024,E=typeof window<"u"?window.innerHeight:768;let k=d.x,j=d.y;const I=p.current;I&&(k=I.right+v,j=I.top+I.height/2-R.height/2+-4,k+R.width>w-v&&(k=I.left-v-R.width)),k+R.width>w-v&&(k=Math.max(v,w-R.width-v)),k<v&&(k=v),j+R.height>E-v&&(j=Math.max(v,E-R.height-v)),j<v&&(j=v),(k!==d.x||j!==d.y)&&m({x:k,y:j})});return()=>cancelAnimationFrame(C)},[f,d.x,d.y]);const S=typeof document<"u"?document.getElementById("popup-root"):null,x=g.jsx("div",{ref:b,style:{...y.text,transform:f?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...f?y.textVisible:{},top:d.y,left:d.x},"data-reactaform-theme":t?"dark":"light",children:o(e)});return g.jsxs(g.Fragment,{children:[g.jsx("span",{"data-testid":"tooltip-icon",ref:h,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{...y.icon},children:"?"}),u&&(S?Ce.createPortal(x,S):x)]})},be=s.memo(({field:e,error:r,children:n,showLabel:o=!0})=>{const{t}=$(),a=e?.labelLayout==="column-center"?"center":"left";return g.jsxs("div",{className:`${N.field} column-layout`,style:{display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)","--label-align":a},children:[o&&g.jsx("div",{style:{textAlign:a,width:"100%"},children:g.jsx("label",{id:`${e.name}-label`,className:N.label,htmlFor:e.name,style:{textAlign:a,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"},children:t(e.displayName)})}),g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"},children:[g.jsx("div",{style:{flex:1,minWidth:0,maxWidth:"100%"},children:g.jsx("div",{style:{width:"100%"},children:n})}),e.tooltip&&g.jsx(We,{content:e.tooltip})]}),r&&g.jsx(Re,{id:`${e.name}-error`,children:r})]})});be.displayName="ColumnFieldLayout";const _e=s.memo(({field:e,error:r,children:n,rightAlign:o=!1})=>{const{t}=$(),a=s.useMemo(()=>({display:"flex",flexDirection:"column",gap:0}),[]),c=s.useMemo(()=>({display:"flex",flexDirection:"row",alignItems:"center",gap:"3px"}),[]);return g.jsxs("div",{className:`${N.field} row-layout`,children:[g.jsx("label",{id:`${e.name}-label`,className:N.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:t(e.displayName)}),g.jsxs("div",{style:a,children:[g.jsxs("div",{style:c,children:[o?g.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)"},children:n}):n,e.tooltip&&g.jsx(We,{content:e.tooltip})]}),r&&g.jsx(Re,{id:`${e.name}-error`,children:r})]})]})});_e.displayName="RowFieldLayout";const P=({field:e,error:r,children:n,rightAlign:o=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?g.jsx(be,{field:e,error:r,showLabel:!0,children:n}):e.type==="checkbox"||e.type==="switch"?g.jsx(be,{field:e,error:r,showLabel:!1,children:n}):g.jsx(_e,{field:e,error:r,rightAlign:o,children:n}),Re=s.memo(({children:e,id:r})=>{const n=s.useMemo(()=>({color:"var(--reactaform-error-color)",fontSize:"13px",marginTop:"4px",fontWeight:"var(--reactaform-font-weight)",display:"flex",flex:1,justifyContent:"flex-start",alignItems:"flex-start"}),[]);return g.jsx("div",{id:r,style:n,children:e})});Re.displayName="ErrorDiv";const Ke=s.memo(({name:e,onChange:r})=>{const{t:n}=$();return g.jsxs("div",{style:{marginBottom:16},children:[g.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[g.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:n("Instance Name")}),g.jsx("input",{id:"instance-name-input",type:"text",value:e,onChange:o=>r(o.target.value),style:{width:"100%",padding:"var(--reactaform-input-padding, 8px 12px)",fontSize:"var(--reactaform-input-font-size, 14px)",border:"1px solid var(--reactaform-input-border, #ddd)",borderRadius:"var(--reactaform-border-radius, 4px)",backgroundColor:"var(--reactaform-input-bg, #fff)",color:"var(--reactaform-text-color, #333)",boxSizing:"border-box"},placeholder:n("Enter instance name")})]}),g.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});Ke.displayName="InstanceName";class yr extends le{registerInCategory(r,n,o){this.get(r)||this.register(r,{});const t=this.get(r);t[n]=o}getFromCategory(r,n){return this.get(r)?.[n]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const Je=new le,Ge=new yr;function xr(e,r){Je.register(e,r)}function vr(e,r,n){Ge.registerInCategory(e,r,n)}function wr(e,r){return Ge.getFromCategory(e,r)||null}function Sr(e){return Je.get(e)||null}function Ye(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const pe=new Map,ge=new Map;function L(e,r,n,o){if(r&&typeof r.validationHandlerName=="string"){const t=`${e}:${r.validationHandlerName}`;if(!pe.has(t)){const c=wr(e,r.validationHandlerName);pe.set(t,c)}const a=pe.get(t);if(a)try{const c=a(n,o);return Ye(c)?null:c||null}catch(c){return String(c instanceof Error?c.message:c)}}return null}async function Xe(e,r,n){if(e&&typeof e.validationHandlerName=="string"){const o=e.validationHandlerName;if(!ge.has(o)){const a=Sr(o);ge.set(o,a)}const t=ge.get(o);if(t)try{const a=t(r,n);return Ye(a)?await a||null:a||null}catch(a){return[String(a instanceof Error?a.message:a)]}}return null}function X(e){return typeof e=="object"&&e!==null}function Ee(e){if(!X(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function Ze(e){if(!X(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(n=>Ee(n))}function ye(e){try{return typeof File<"u"&&e instanceof File}catch{const r=X(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Cr(e,r,n={}){try{const{includeMetadata:o=!1,dateFormat:t="iso",fileHandling:a="metadata",prettify:c=!1,excludeFields:u=[],includeOnlyFields:i=[]}=n;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const d=[],m=[],f={},h=(Ze(r)||X(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ee),b=new Map(h.map(y=>[y.name,y]));for(const[y,S]of Object.entries(e)){if(u.includes(y)){m.push(y);continue}if(i.length>0&&!i.includes(y)){m.push(y);continue}if(S===void 0)continue;const x=b.get(y);try{f[y]=jr(S,x,{dateFormat:t,fileHandling:a})}catch(C){d.push(`Error serializing field '${y}': ${String(C)}`),f[y]=null}}return o&&(f._metadata={serializedAt:new Date().toISOString(),version:(X(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(f).length-1}),{success:!0,data:c?JSON.stringify(f,null,2):JSON.stringify(f),metadata:{fieldCount:Object.keys(f).length,excludedFields:m,warnings:d}}}catch(o){return{success:!1,error:`Serialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function jr(e,r,n={}){const{dateFormat:o="iso",fileHandling:t="metadata"}=n;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Ve(e,o);case"file":return De(e,t);case"int":case"integer":return typeof e=="string"?parseInt(e,10):e;case"float":case"number":return typeof e=="string"?parseFloat(e):e;case"boolean":return typeof e=="string"?e==="true":!!e;case"int-array":case"float-array":return Array.isArray(e)?e.map(a=>typeof a=="string"?Number(a):a):e;default:return e}return e instanceof Date?Ve(e,o):ye(e)||Array.isArray(e)&&ye(e[0])?De(e,t):e}function Ve(e,r){let n=null;if(e instanceof Date)n=e;else if(typeof e=="string"){const o=new Date(e);if(!isNaN(o.getTime()))n=o;else return e}else return e;switch(r){case"timestamp":return n.getTime();case"locale":return n.toLocaleString();case"iso":default:return n.toISOString()}}function De(e,r){return r==="skip"?null:Array.isArray(e)?e.map(n=>ze(n,r)):ze(e,r)}function ze(e,r){if(!ye(e))return e;const n=e;return r==="metadata"?{name:n.name,size:n.size,type:n.type,lastModified:n.lastModified}:{name:n.name,size:n.size,type:n.type,lastModified:n.lastModified,_note:"Base64 encoding requires async implementation"}}function Rr(e,r,n={}){try{const{strict:o=!1,validateTypes:t=!0,preserveUnknownFields:a=!0,dateFormat:c="auto"}=n;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let u;try{u=JSON.parse(e)}catch(p){return{success:!1,error:`Invalid JSON: ${p instanceof Error?p.message:"Unknown parsing error"}`}}if(!u||typeof u!="object")return{success:!1,error:"Parsed data must be an object"};const i=[],d=[],m={},l=(Ze(r)||X(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ee),h=new Map(l.map(p=>[p.name,p]));for(const p of l){const y=p.name,S=u[y];if(S===void 0){o&&p.required&&d.push(`Required field '${y}' is missing`);continue}try{m[y]=Er(S,p,{validateTypes:t,dateFormat:c})}catch(x){const C=`Error deserializing field '${y}': ${String(x)}`;o?d.push(C):(i.push(C),m[y]=S)}}if(a)for(const[p,y]of Object.entries(u))!h.has(p)&&p!=="_metadata"&&(o&&i.push(`Unknown field '${p}' preserved`),m[p]=y);const b=d.length>0;return{success:!b,data:m,warnings:i.length>0?i:void 0,validationErrors:b?d:void 0}}catch(o){return{success:!1,error:`Deserialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Er(e,r,n={}){const{validateTypes:o=!0,dateFormat:t="auto"}=n;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Ir(e,t,o);case"int":case"integer":return xe(e,o);case"float":case"number":return ve(e,o);case"boolean":return Fr(e,o);case"int-array":return Le(e,"integer",o);case"float-array":return Le(e,"number",o);case"string":case"text":case"email":case"url":case"phone":return o?String(e):e;default:return e}}catch(a){if(o)throw new Error(`Type conversion failed: ${String(a)}`);return e}}function kr(e,r={}){try{const{prettify:n=!0,includeMetadata:o=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const t={...e};return o&&(t._metadata={serializedAt:new Date().toISOString(),version:t.version||"1.0.0",propertyCount:(Array.isArray(t.properties)?t.properties.length:0)||0}),{success:!0,data:n?JSON.stringify(t,null,2):JSON.stringify(t),metadata:{fieldCount:(Array.isArray(t.properties)?t.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(n){return{success:!1,error:`Definition serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Nr(e,r={}){try{const{strict:n=!1,validateTypes:o=!0}=r;let t;if(typeof e=="string")try{t=JSON.parse(e)}catch(m){return{success:!1,error:`Invalid JSON for definition: ${m instanceof Error?m.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")t={...e};else return{success:!1,error:"Input must be a string or object"};const a=[],c=[],u=["name","version","displayName"];for(const m of u)if(!t[m])if(n)c.push(`Required field '${m}' is missing`);else switch(a.push(`Missing field '${m}', using default`),m){case"name":t.name="unnamed-definition";break;case"version":t.version="1.0.0";break;case"displayName":t.displayName=t.name||"Unnamed Definition";break}const i=Array.isArray(t.properties)?t.properties:null;i?t.properties=i.map((m,f)=>{const l=X(m)?m:{},h={...l};if(!l.name){const b=`Property at index ${f} missing 'name'`;n?c.push(b):(a.push(`${b}, using 'field_${f}'`),h.name=`field_${f}`)}return l.displayName||(h.displayName=l.name||`Field ${f}`),l.type||(n&&o?c.push(`Property '${l.name||f}' missing 'type'`):(a.push(`Property '${l.name||f}' missing 'type', using 'string'`),h.type="string")),l.defaultValue===void 0&&(h.defaultValue=null),l.required===void 0&&(h.required=!1),h}):n?c.push("Properties must be an array"):(a.push("Properties not found or invalid, using empty array"),t.properties=[]);const d=c.length>0;return{success:!d,data:t,warnings:a.length>0?a:void 0,validationErrors:d?c:void 0}}catch(n){return{success:!1,error:`Definition deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Ir(e,r,n){if(e instanceof Date)return e;if(typeof e=="number"){const o=new Date(e);if(n&&isNaN(o.getTime()))throw new Error(`Invalid timestamp: ${e}`);return o}if(typeof e=="string"){const o=new Date(e);if(n&&isNaN(o.getTime()))throw new Error(`Invalid date string: ${e}`);return o}if(n)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function xe(e,r){if(typeof e=="number"&&Number.isInteger(e))return e;if(typeof e=="string"&&e.trim()!==""){const n=parseInt(e,10);if(r&&isNaN(n))throw new Error(`Cannot convert "${e}" to integer`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to integer`);return e}function ve(e,r){if(typeof e=="number")return e;if(typeof e=="string"&&e.trim()!==""){const n=parseFloat(e);if(r&&isNaN(n))throw new Error(`Cannot convert "${e}" to number`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Fr(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="0")return!1;if(r)throw new Error(`Cannot convert "${e}" to boolean`)}if(typeof e=="number")return!!e;if(r)throw new Error(`Cannot convert ${typeof e} to boolean`);return e}function Le(e,r,n){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>r==="integer"?xe(t,n):ve(t,n));if(n)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((o,t)=>{try{return r==="integer"?xe(o,n):ve(o,n)}catch(a){if(n)throw new Error(`Array element ${t}: ${a}`);return o}})}const Mr=(e,r)=>{const n=new Map;let o=null,t=null,a=0;for(const c of e){const u=c.group;if(!u){o=null,t=null;continue}if(u===o)r[c.name].group=t??u;else{if(!n.has(u))n.set(u,1),t=null,r[c.name].group=u;else{const i=n.get(u),d=`${u}(${i})`;n.set(u,i+1),t=d,r[c.name].group=d,a++}o=u}}return a},$r=(e,r={})=>{const{includeEmpty:n=!0}=r,o=[];let t=null,a=[],c=0;for(const i of e){const d=i.group||null;d!==t?((a.length>0||n)&&(a.length===0&&c++,o.push({name:t,fields:a})),t=d,a=[i]):a.push(i)}(a.length>0||n)&&(a.length===0&&c++,o.push({name:t,fields:a}));const u=Math.max(0,...o.map(i=>i.fields.length));return{groups:o,metadata:{totalGroups:o.length,emptyGroups:c,largestGroup:u}}},he=new Map,ce=new Map,Y=new Set,we=new Map,Ar=async e=>{try{let r;switch(e.toLowerCase()){case"fr":r=(await Promise.resolve().then(()=>require("./common-DLr0UoG9.js"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-Crb-me6O.js"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-DRIndE7S.js"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-BeJOG7Z0.js"))).default;break;case"en":r={};break;default:r={}}return{success:!0,translations:r,fromCache:!1}}catch(r){return{success:!1,translations:{},error:`Failed to load common translations for ${e}: ${r}`}}},Vr=async e=>{if(!e)return{success:!1,translations:{},error:"Language is required"};const r=e.toLowerCase();if(r==="en")return{success:!0,translations:{},fromCache:!1};if(he.has(r))return{success:!0,translations:he.get(r)||{},fromCache:!0};const n=await Ar(r);return n.success&&(he.set(r,n.translations),we.set(r,{loadedAt:new Date,size:Object.keys(n.translations).length,source:"common"})),n},Dr=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const n=`${e.toLowerCase()}/${r}`;if(Y.has(n))return{success:!1,translations:{},error:"Previously failed to load",fromCache:!0};if(ce.has(n))return{success:!0,translations:ce.get(n)||{},fromCache:!0};try{let o=r;!r.includes("/")&&!r.includes(".")&&(o=`/locales/${e}/${r}.json`);const t=await fetch(o);if(!t.ok){const d=`HTTP ${t.status}: ${t.statusText}`;return t.status===404?(ce.set(n,{}),we.set(n,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(Y.add(n),{success:!1,translations:{},error:d})}const a=t.headers.get("content-type")||"";!a.includes("application/json")&&!a.includes("text/json")&&Qe()&&console.warn(`Translation file at ${o} has unexpected content-type: ${a}`);const c=await t.text();if(!c){const d="Empty translation file";return Y.add(n),{success:!1,translations:{},error:d}}let u;try{u=JSON.parse(c)}catch(d){const m=`Invalid JSON in translation file: ${d instanceof Error?d.message:String(d)}`;return Y.add(n),{success:!1,translations:{},error:m}}if(!u||typeof u!="object"){const d="Invalid translation file format";return Y.add(n),{success:!1,translations:{},error:d}}const i=Object.fromEntries(Object.entries(u).map(([d,m])=>[d,typeof m=="string"?m:String(m)]));if(!i||typeof i!="object"){const d="Invalid translation file format";return Y.add(n),{success:!1,translations:{},error:d}}return ce.set(n,i),we.set(n,{loadedAt:new Date,size:Object.keys(i).length,source:"user"}),{success:!0,translations:i,fromCache:!1}}catch(o){const t=`Failed to load user translations: ${o instanceof Error?o.message:"Unknown error"}`;return Y.add(n),{success:!1,translations:{},error:t}}};function Qe(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function zr(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(n,o)=>{const t=parseInt(o,10)-1,a=r[t];if(a==null)return n;try{return String(a)}catch{return n}})}const Lr=(e,r,n)=>(o,...t)=>{let a=o,c=!1;return!o||typeof o!="string"?String(o||""):(e.toLowerCase()==="en"?(a=o,c=!0):Object.prototype.hasOwnProperty.call(n,o)?(a=n[o],c=!0):Object.prototype.hasOwnProperty.call(r,o)?(a=r[o],c=!0):a=o,a=zr(a,t),!c&&Qe()&&console.debug(`Missing translation for "${o}" in language "${e}"`),a)},ke={length:["m","cm","mm","km","in","ft","yd","mi"],area:["m^2","cm^2","mm^2","in^2","ft^2","yd^2"],volume:["L","m^3","cm^3","mL","in^3","ft^3","yd^3"],weight:["kg","g","mg","t","lb","oz"],time:["min","s","h","ms","d"],temperature:["C","F","K"],angle:["deg","rad","rev"]},Ne={length:{m:"Meter (m)",mm:"Millimeter (mm)",cm:"Centimeter (cm)",km:"Kilometer (km)",in:"Inch (in)",ft:"Foot (ft)",yd:"Yard (yd)",mi:"Mile (mi)"},area:{"m^2":"Square meter (m^2)","mm^2":"Square millimeter (mm^2)","cm^2":"Square centimeter (cm^2)","in^2":"Square inch (in^2)","ft^2":"Square foot (ft^2)","yd^2":"Square yard (yd^2)"},volume:{L:"Liter (L)","cm^3":"Cubic centimeter (cm^3)","m^3":"Cubic meter (m^3)",mL:"Milliliter (mL)","in^3":"Cubic inch (in^3)","ft^3":"Cubic foot (ft^3)","yd^3":"Cubic yard (yd^3)"},weight:{kg:"Kilogram (kg)",g:"Gram (g)",mg:"Milligram (mg)",t:"Tonne (t)",lb:"Pound (lb)",oz:"Ounce (oz)"},time:{s:"Second (s)",min:"Minute (min)",h:"Hour (h)",ms:"Millisecond (ms)",d:"Day (d)",wk:"Week (wk)"},temperature:{C:"Celsius (C)",F:"Fahrenheit (F)",K:"Kelvin (K)"},angle:{deg:"Degree (deg)",rad:"Radian (rad)",rev:"Revolution (rev)"}},Ie={length:{mm:1e3,cm:100,m:1,km:.001,in:100/2.54,ft:100/(2.54*12),yd:100/(2.54*36),mi:1/1609.344},area:{"m^2":1,"mm^2":1e6,"cm^2":1e4,"km^2":1/1e6,"in^2":(100/2.54)**2,"ft^2":(100/(2.54*12))**2,"yd^2":(100/(2.54*36))**2},volume:{"cm^3":1e6,"m^3":1,L:1,mL:1e6,"in^3":(100/2.54)**3,"ft^3":(100/(2.54*12))**3,"yd^3":(100/(2.54*36))**3},weight:{mg:1e6,g:1e3,kg:1,t:.001,lb:1/.45359237,oz:1/.028349523125},time:{ms:1e3,s:1,min:1/60,h:1/3600,d:1/86400,wk:1/604800},temperature:{C:1,F:33.8,K:274.15},angle:{deg:1,rad:Math.PI/180,rev:1/360}},Fe={},Or=new Set([...Object.keys(ke),...Object.keys(Ne),...Object.keys(Ie)]);for(const e of Or){const r={},n=ke[e]??[],o=Ne[e]??{},t=Ie[e]??{};for(const a of n){const c=o[a];r[a]={name:typeof c=="string"?c:String(a),shortName:a,factor:Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0}}for(const[a,c]of Object.entries(o))if(!r[a]){const u=typeof c=="string"?c:String(a);r[a]={name:u,shortName:a,factor:Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0}}for(const[a,c]of Object.entries(t))r[a]||(r[a]={name:String(a),shortName:String(a),factor:c});Fe[e]=r}const qr=Object.freeze(Object.defineProperty({__proto__:null,dimensionUnitDisplayMap:Ne,dimensionUnitsMap:ke,dimensonUnitFactorsMap:Ie,unitsByDimension:Fe},Symbol.toStringTag,{value:"Module"})),Pr=({field:e,value:r,onChange:n,onError:o})=>{const{definitionName:t,t:a}=$(),c=s.useRef(o);s.useEffect(()=>{c.current=o},[o]),s.useEffect(()=>{const f=L(t,e,r??!1,a);c.current?.(f??null)},[r,e,t,a]);const u=f=>{const l=f.target.checked;n?.(l,null)},i=f=>{(f.key===" "||f.key==="Spacebar"||f.key==="Space"||f.key==="Enter")&&(f.preventDefault(),n?.(!r,null))},d=e.name,m=L(t,e,r??!1,a);return g.jsx(P,{field:e,rightAlign:!1,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[g.jsx("label",{className:N.label,htmlFor:d,style:{textAlign:"left",justifyContent:"flex-start"},children:a(e.displayName)}),g.jsx("input",{id:d,"data-testid":"boolean-checkbox",type:"checkbox",checked:!!r,onChange:u,onKeyDown:i,"aria-checked":!!r,"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0,style:{cursor:"pointer",margin:"8px 0 8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",color:"#FFFFFF",accentColor:"#0000FF",opacity:void 0}})]})})},Oe=[{label:"Black",value:"#000000"},{label:"White",value:"#ffffff"},{label:"Red",value:"#ff0000"},{label:"Green",value:"#008000"},{label:"Blue",value:"#0000ff"},{label:"Yellow",value:"#ffff00"},{label:"Cyan",value:"#00ffff"},{label:"Magenta",value:"#ff00ff"},{label:"Orange",value:"#ffa500"},{label:"Purple",value:"#800080"},{label:"Brown",value:"#a52a2a"},{label:"Gray",value:"#808080"},{label:"Light Gray",value:"#d3d3d3"},{label:"Pink",value:"#ffc0cb"}];function er(e){return/^#([0-9A-F]{3}){1,2}$/i.test(e)}function Tr(e){if(!er(e))return null;const r=rr(e),n=parseInt(r.slice(1),16);return{r:n>>16&255,g:n>>8&255,b:n&255}}function rr(e){return e?(e=e.toLowerCase(),/^#([a-f0-9]){3}$/i.test(e)?"#"+e.slice(1).split("").map(r=>r+r).join(""):e):"#000000"}const Br=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),[c,u]=s.useState("#000000"),i=s.useRef(null),d=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const x=r&&er(r)?r:"#000000",C=rr(x);u(C)},[r]),s.useEffect(()=>{const x=L(a,e,r??"#000000",t);m.current?.(x??null)},[r,e,a,t]);const f=L(a,e,r??"#000000",t),l=x=>{const C=x.target.value;u(C),n?.(C,null)},h=x=>{const C=x.target.value;u(C),n?.(C,null)},b=Oe.find(x=>x.value===c),{r:p,g:y,b:S}=Tr(c)||{r:0,g:0,b:0};return g.jsx(P,{field:e,error:f,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[g.jsxs("select",{ref:i,id:e.name,value:c,onChange:l,style:{minWidth:"120px",flex:1},className:B(N.input,N.inputSelect),"aria-invalid":!!f,"aria-describedby":f?`${e.name}-error`:void 0,children:[Oe.map(x=>g.jsx("option",{value:x.value,children:t(x.label)},x.value)),b?null:g.jsxs("option",{value:c,children:["(",p,", ",y,", ",S,")"]},c)]}),g.jsx("label",{style:{width:"2.5em",height:"1.8em",display:"inline-block",border:"1px solid #ccc",borderRadius:"4px",backgroundColor:c,cursor:"pointer",overflow:"hidden",flexShrink:0},children:g.jsx("input",{ref:d,id:`${e.name}-color`,type:"color",value:c,onChange:h,style:{opacity:0,width:"100%",height:"100%",border:"none",padding:0,cursor:"pointer"},"aria-invalid":!!f,"aria-describedby":f?`${e.name}-error`:void 0})})]})})},oe=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},Hr=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return oe(e)?e:"";const n=oe(e);if(n){const o=n.getFullYear(),t=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0");return`${o}-${t}-${a}`}return""},Ur=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),{name:c,required:u}=e,i=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]);const m=s.useCallback(l=>{if(!l||l.trim()==="")return u?t("Value required"):null;if(l){const b=oe(l);if(!b)return t("Invalid date format");if(e.minDate){const p=oe(e.minDate);if(p&&b.getTime()<p.getTime())return t("Date must be on or after {{1}}",e.minDate)}if(e.maxDate){const p=oe(e.maxDate);if(p&&b.getTime()>p.getTime())return t("Date must be on or before {{1}}",e.maxDate)}}return L(a,e,l,t)??null},[e,a,t,u]),f=l=>{const h=l.target.value,b=m(h);n?.(h,b)};return s.useEffect(()=>{const l=m(r);l!==i.current&&(i.current=l,d.current?.(l??null))},[r,m]),g.jsx(P,{field:e,error:m(r),children:g.jsx("input",{id:c,type:"date",value:Hr(r),onChange:f,className:B(N.input,N.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!m(r),"aria-describedby":m(r)?`${c}-error`:void 0})})},Wr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]);const i=s.useCallback(m=>m===""||m===null||m===void 0?t("Value required"):!e.options||e.options.length===0?null:e.options.some(l=>l.value===m)?L(a,e,m,t)??null:t("Invalid option selected"),[e,t,a]);s.useEffect(()=>{const m=r!=null?String(r):"",f=i(m);if(f&&e.options&&e.options.length>0){const l=String(e.options[0].value);c.current&&(c.current.value=l),n?.(l,null),u.current?.(null)}else c.current&&(c.current.value=m),u.current?.(f??null)},[r,i,n,e.options]);const d=m=>{const f=m.target.value,l=i(f);n?.(f,l)};return g.jsx(P,{field:e,error:i(String(r??"")),children:g.jsx("select",{id:e.name,"aria-invalid":!!i(String(r??"")),"aria-describedby":i(String(r??""))?`${e.name}-error`:void 0,defaultValue:String(r??""),ref:c,onChange:d,className:B(N.input,N.inputSelect),children:(e.options??[]).map(m=>g.jsx("option",{value:String(m.value),children:t(m.label)},String(m.value)))})})};function _r(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const Kr=({field:e,value:r,onChange:n,onError:o})=>{const{definitionName:t,t:a}=$(),c=s.useRef(null),u=s.useCallback(f=>{const l=f.trim();return l===""?e.required?a("Value required"):null:_r(l)?e.pattern&&!new RegExp(e.pattern).test(l)?e.patternErrorMessage?a(e.patternErrorMessage):a("Email does not match pattern: {{%1}}",{"%1":`${e.pattern}`}):L(t,e,f,a)??null:a("Must be valid email format")},[e,t,a]),i=f=>{const l=f.target.value,h=u(l);n?.(l,h)},d=s.useRef(null),m=s.useRef(o);return s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const f=r??"",l=u(f);c.current&&c.current.value!==String(f)&&(c.current.value=String(f)),l!==d.current&&(d.current=l,m.current?.(l??null))},[r,u]),g.jsx(P,{field:e,error:u(String(r??"")),children:g.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:c,onChange:i,className:B(N.input,N.textInput),"aria-invalid":!!u(String(r??"")),"aria-describedby":u(String(r??""))?`${e.name}-error`:void 0})})},Jr=({field:e})=>{const{darkMode:r}=$(),{color:n=r?"#444444":"#CCCCCC",thickness:o=1,margin:t="8px 0"}=e;return g.jsx("div",{style:{width:"auto",height:"0",borderTop:`${o}px solid ${n}`,margin:t}})},Gr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),[c,u]=s.useState(!1),i=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]);const m=s.useCallback(x=>e.required&&(!x||Array.isArray(x)&&x.length===0)?t("Value required"):L(a,e,x,t)??null,[e,a,t]),f=s.useMemo(()=>m(r),[r,m]);s.useEffect(()=>{const x=m(r);n?.(r,x),d.current?.(x??null)},[r,m]);const l=x=>{const C=x.target.files;let R=null;if(C&&C.length>0){const w=Array.from(C);e.multiple?R=[...Array.isArray(r)?r:[],...w]:R=w[0]}const v=m(R);n?.(R,v)},h=x=>{x.preventDefault(),x.stopPropagation(),u(!1);const C=x.dataTransfer.files;if(C&&C.length>0){const R=Array.from(C);let v=null;e.multiple?v=[...Array.isArray(r)?r:[],...R]:v=R[0];const w=m(v);n?.(v,w)}},b=x=>{x.preventDefault(),x.stopPropagation(),u(!0)},p=x=>{x.preventDefault(),x.stopPropagation(),u(!1)},y=x=>{if(Array.isArray(r)&&typeof x=="number"){const C=r.filter((w,E)=>E!==x),R=C.length>0?C:null,v=m(R);n?.(R,v)}else{const C=m(null);n?.(null,C)}},S=()=>{const x=Array.isArray(r)?r:r?[r]:[];return x.length===0?null:g.jsx("div",{style:{marginTop:"8px",display:"flex",flexDirection:"column",gap:"6px"},children:x.map((C,R)=>g.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 10px",backgroundColor:"var(--reactaform-input-bg, #fff)",border:"1px solid var(--reactaform-border-color, #d1d5db)",borderRadius:"4px",fontSize:"0.875rem",gap:"8px"},children:[g.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.name}),g.jsx("button",{type:"button",onClick:()=>y(Array.isArray(r)?R:void 0),"aria-label":t("Remove file"),style:{background:"transparent",border:"none",color:"var(--reactaform-color-error, #ef4444)",cursor:"pointer",padding:"2px 6px",fontSize:"1.125rem",lineHeight:1,borderRadius:"4px",transition:"background-color 0.2s",flexShrink:0},onMouseEnter:v=>{v.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:v=>{v.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${C.name}-${R}`))})};return g.jsx(P,{field:e,error:f,children:g.jsxs("div",{style:{width:"100%"},children:[g.jsxs("div",{onDrop:h,onDragOver:b,onDragLeave:p,style:{position:"relative",border:`1px dashed ${c?"var(--reactaform-color-primary, #2563eb)":f?"var(--reactaform-color-error, #ef4444)":"var(--reactaform-border-color, #d1d5db)"}`,borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:c?"var(--reactaform-bg-hover, #f0f9ff)":"var(--reactaform-input-bg, #fff)",transition:"all 0.2s ease",cursor:"pointer",minHeight:"var(--reactaform-input-height, 34px)",width:"100%",maxWidth:"100%",alignSelf:"stretch",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},onClick:()=>i.current?.click(),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),i.current?.click())},role:"button","aria-label":e.multiple?t("Choose Files or Drag & Drop"):t("Choose File or Drag & Drop"),"aria-invalid":!!f,"aria-describedby":f?`${e.name}-error`:void 0,children:[g.jsx("input",{id:e.name,ref:i,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:l}),g.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),g.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:c?t("Drop files here"):e.multiple?t("Choose Files or Drag & Drop"):t("Choose File or Drag & Drop")}),e.accept&&g.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:c?0:1,transition:"opacity 0.15s ease",pointerEvents:c?"none":"auto"},children:e.accept})]}),S()]})})},Yr=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function Xr(e){return e.split(",").map(r=>r.trim()).every(r=>Yr.test(r))}const Zr=e=>!e||e.trim()===""?[]:e.split(",").map(r=>r.trim()).filter(Boolean).map(Number),Qr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),[c,u]=s.useState(Array.isArray(r)?r.join(", "):String(r??"")),i=s.useCallback(l=>{if(l.trim()==="")return e.required?t("Value required"):null;if(!Xr(l))return t("Each value must be a valid float");const h=Zr(l);if(e.minCount!==void 0&&h.length<e.minCount)return t("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&h.length>e.maxCount)return t("Maximum number of values: {{1}}",e.maxCount);for(const p of h){if(e.min!==void 0&&(e.minInclusive?p<e.min:p<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?p>e.max:p>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return L(a,e,h,t)??null},[a,e,t]),d=l=>{const h=l.target.value,b=i(h);u(h),n?.(h,b)},m=s.useRef(null),f=s.useRef(o);return s.useEffect(()=>{f.current=o},[o]),s.useEffect(()=>{const l=Array.isArray(r)?r.join(", "):String(r??""),h=i(l);h!==m.current&&(m.current=h,f.current?.(h??null))},[r,e.required,i,t]),g.jsx(P,{field:e,error:i(c),children:g.jsx("input",{id:e.name,type:"text",value:c,onChange:d,className:B(N.input,N.textInput),style:{flex:1},"aria-invalid":!!i(c),"aria-describedby":i(c)?`${e.name}-error`:void 0})})},et=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,rt=e=>{const r=Number.parseFloat(e);return Number.isNaN(r)?null:r},tt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useCallback(f=>{if(f.trim()==="")return e.required?t("Value required"):null;if(!et.test(f))return t("Must be a valid float");const l=rt(f);return l===null?t("Must be a valid float"):e.min!==void 0&&(e.minInclusive?l<e.min:l<=e.min)?t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min):e.max!==void 0&&(e.maxInclusive?l>e.max:l>=e.max)?t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max):L(a,e,l,t)??null},[e,a,t]),i=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]),s.useEffect(()=>{const f=String(r??""),l=u(f);l!==i.current&&(i.current=l,d.current?.(l??null)),c.current&&document.activeElement!==c.current&&(c.current.value=f)},[r,e,u,t]);const m=f=>{const l=f.target.value,h=u(l);n?.(l,h)};return g.jsx(P,{field:e,error:u(String(r??"")),children:g.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:m,className:B(N.input,N.inputNumber),"aria-invalid":!!u(String(r??"")),"aria-describedby":u(String(r??""))?`${e.name}-error`:void 0})})};function nt(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const ot=({field:e,value:r})=>{const{language:n,t:o}=$(),t=e.alignment||"center",a={left:"flex-start",center:"center",right:"flex-end"},c=typeof r=="string"?r:"";let u=c&&c.trim()!==""?c:typeof e.defaultValue=="string"?e.defaultValue:"";u&&!u.startsWith("/")&&(u=`${nt()}${u}`);const i=e.localized?.split(";").map(y=>y.trim()),[d,m]=s.useState(u||""),f=s.useRef(u||null);if(s.useEffect(()=>{if(!u)return;const y=u.split("/"),S=y.pop(),x=S.lastIndexOf(".");if(x===-1)return;const C=S.substring(0,x),R=S.substring(x);let v=null;i?.includes(n)&&(v=`${C}_${n}${R}`);const w=new AbortController;if(v){const E=[...y,v].join("/");fetch(E,{method:"HEAD",signal:w.signal}).then(k=>{const j=k.ok?E:u;j!==f.current&&(f.current=j,m(j))}).catch(()=>{u!==f.current&&(f.current=u,m(u))})}else{const E=u;E!==f.current&&(f.current=E,requestAnimationFrame(()=>m(E)))}return()=>{w.abort()}},[u,n,i]),!d)return null;const{width:l,height:h}=e,b={},p={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return l&&h?(b.width=l,b.height=h,p.width=`${l}px`,p.height=`${h}px`):l&&!h?(b.width=l,p.width=`${l}px`,p.height="auto"):!l&&h&&(b.height=h,p.width="auto",p.height=`${h}px`),g.jsx(P,{field:e,children:g.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:a[t]||"center",margin:"0 0"},children:g.jsx("img",{src:d,alt:o?.(e.displayName||"Image")||e.displayName||"Image",...b,style:p})})})};function at(e){const r=/^-?\d+$/;return e.split(",").map(n=>n.trim()).every(n=>r.test(n))}const st=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=",",[u,i]=s.useState(Array.isArray(r)?r.join(c+" "):String(r??"")),d=p=>!p||p.trim()===""?[]:p.split(c).map(y=>y.trim()).filter(Boolean).map(y=>Number(y)),m=s.useCallback(p=>{if(p.trim()==="")return e.required?t("Value required"):null;if(!at(p))return t("Each value must be a valid integer");const y=d(p);if(e.minCount!==void 0&&y.length<e.minCount)return t("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&y.length>e.maxCount)return t("Maximum number of values: {{1}}",`${e.maxCount}`);for(const x of y){if(e.min!==void 0&&(e.minInclusive?x<e.min:x<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?x>e.max:x>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return L(a,e,y,t)??null},[a,e,t]),f=p=>{const y=p.target.value,S=m(y);i(y),n?.(y,S)},l=s.useRef(null),h=s.useRef(o);s.useEffect(()=>{h.current=o},[o]),s.useEffect(()=>{const p=Array.isArray(r)?r.join(c+" "):String(r??""),y=m(p);y!==l.current&&(l.current=y,h.current?.(y??null))},[r,e.required,m,t]);const b=m(u);return g.jsx(P,{field:e,error:b,children:g.jsx("input",{id:e.name,type:"text",value:u,onChange:f,className:B(N.input,N.textInput),style:{flex:1},"aria-invalid":!!b,"aria-describedby":b?`${e.name}-error`:void 0})})};function it(e){return/^[-+]?\d*$/.test(e)}const ct=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useCallback(h=>{const b=parseInt(h,10);return Number.isNaN(b)?null:b},[]),i=s.useCallback(h=>{if(h.trim()==="")return e.required?t("Value required"):null;if(!it(h))return t("Must be a valid integer");const b=u(h);if(b===null)return t("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?b<e.min:b<=e.min))return t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?b>e.max:b>=e.max))return t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const y=Number(e.step);if(!Number.isInteger(y))return t("Invalid step value");if(b%y!==0)return t("Must be a multiple of {{1}}",y)}return L(a,e,b,t)??null},[e,a,t,u]),d=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const h=String(r??""),b=i(h);b!==d.current&&(d.current=b,m.current?.(b??null)),c.current&&document.activeElement!==c.current&&(c.current.value=h)},[r,e,i,t]);const f=h=>{const b=h.target.value,p=i(b);n?.(b,p)},l=i(String(r??""));return g.jsx(P,{field:e,error:l,children:g.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:f,className:B(N.input,N.inputNumber),"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0})})},ut=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=e.minHeight??"80px",u=s.useRef(null),i=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]);const m=s.useCallback(b=>b.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&b.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&b.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):L(a,e,b,t),[e,a,t]),f=b=>{const p=b.target.value,y=m(p);n?.(p,y)};s.useEffect(()=>{const b=m(r);b!==i.current&&(i.current=b,d.current?.(b??null)),u.current&&u.current.value!==String(r??"")&&(u.current.value=String(r??""))},[r,m]);const l={id:e.name,defaultValue:String(r??""),ref:u,onChange:f,style:{resize:"vertical",minHeight:c,width:"100%",boxSizing:"border-box"},className:B(N.input,N.textInput)},h=m(r);return g.jsx(P,{field:e,error:h,children:g.jsx("textarea",{...l,"aria-invalid":!!h,"aria-describedby":h?`${e.name}-error`:void 0})})},lt=({field:e,value:r,onChange:n,onError:o})=>{const t=s.useRef(o);s.useEffect(()=>{t.current=o},[o]);const{t:a,darkMode:c,formStyle:u,fieldStyle:i,definitionName:d}=$(),m=(j,I,M)=>{if(!I)return{};const T=j?.[I];return(M&&T?T[M]:void 0)??{}},f=s.useRef(null),[l,h]=s.useState(!1),[b,p]=s.useState(null),y=s.useMemo(()=>e.options.map(j=>({value:j.value,label:a(j.label)})),[e.options,a]),S=s.useMemo(()=>{const j=Array.isArray(r)?r:[],I=new Set(y.map(M=>M.value));return j.filter(M=>I.has(M))},[r,y]),x=j=>{const I=Array.isArray(j)?j:[];return e.required&&I.length===0?a("Value required"):L(d,e,I,a)??null},C=()=>{if(!f.current)return;const j=f.current.getBoundingClientRect();p({x:j.left,y:j.bottom}),h(I=>!I)},R=j=>{const I=S.includes(j)?S.filter(z=>z!==j):[...S,j],M=x(I);t.current?.(M??null),n?.(I,M)},v=s.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",padding:"var(--reactaform-input-padding, 8px)",display:"flex",alignItems:"center",boxSizing:"border-box",cursor:"pointer",position:"relative",borderRadius:"var(--reactaform-border-radius, 4px)",border:"1px solid var(--reactaform-border-color, #ccc)",background:"var(--reactaform-secondary-bg, #fff)",color:"var(--reactaform-text-color, #000)",...m(u,"multiSelect","control"),...m(i,void 0,"control")}),[u,i]),w=s.useMemo(()=>({position:"absolute",right:"1.5em",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",padding:0,...m(u,"multiSelect","clearButton"),...m(i,void 0,"clearButton")}),[u,i]),E=s.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...m(u,"multiSelect","arrow"),...m(i,void 0,"arrow")}),[u,i]),k=x(Array.isArray(r)?r:[]);return g.jsxs("div",{children:[g.jsx(P,{field:e,error:null,children:g.jsx("div",{style:{width:"100%"},children:g.jsxs("div",{ref:f,className:"reactaform-multiselection-control",style:v,onClick:C,tabIndex:0,role:"button","aria-haspopup":"listbox","aria-expanded":l,"aria-invalid":!!k,"aria-describedby":k?`${e.name}-error`:void 0,onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),C())},children:[g.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[S.length," / ",y.length," selected"]}),S.length>0&&g.jsx("button",{type:"button","aria-label":"Clear selections",onClick:j=>{j.stopPropagation(),n?.([],null)},style:w,children:g.jsx("span",{style:w,"aria-hidden":!0,children:"✖"})}),g.jsx("span",{style:E,"aria-hidden":!0,children:"▼"})]})})}),l&&b&&g.jsx(mt,{position:b,options:y,selectedValues:S,onToggleOption:R,onClose:()=>h(!1),controlRef:f,darkMode:c})]})},mt=({position:e,options:r,selectedValues:n,onToggleOption:o,onClose:t,controlRef:a,darkMode:c})=>{const u=s.useRef(null),[i,d]=s.useState(-1),{formStyle:m,fieldStyle:f}=$(),l=(w,E,k)=>{if(!E)return{};const I=w?.[E];return(k&&I?I[k]:void 0)??{}},h=s.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...l(m,"multiSelect","popup"),...l(f,void 0,"popup")}),[m,f]),b=s.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...l(m,"multiSelect","option"),...l(f,void 0,"option")}),[m,f]);s.useEffect(()=>{const w=E=>{const k=E.target;!u.current?.contains(k)&&!a.current?.contains(k)&&t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[t,a]),s.useEffect(()=>{u.current&&r.length>0&&requestAnimationFrame(()=>d(w=>w===-1?0:w))},[r.length]),s.useEffect(()=>{if(!u.current||i<0)return;const w=u.current.querySelector(`#multi-opt-${i}`);w&&requestAnimationFrame(()=>w.focus())},[i]);const p=250,y=200,[S,x]=s.useState(null),[C,R]=s.useState(null);if(s.useEffect(()=>{if(typeof window>"u")return;const w=()=>{let j=e.x,I=e.y,M=p;const z=a?.current;if(z){const T=z.getBoundingClientRect();j=T.left,I=T.bottom,M=Math.max(80,Math.round(T.width))}j=Math.min(j,window.innerWidth-M),I=Math.min(I,window.innerHeight-y),x({left:j,top:I}),R(M)};w(),window.addEventListener("scroll",w,!0),window.addEventListener("resize",w);let E=null;const k=a?.current;return typeof ResizeObserver<"u"&&k&&(E=new ResizeObserver(()=>w()),E.observe(k)),()=>{window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w),E&&k&&E.unobserve(k)}},[a,e.x,e.y]),typeof window>"u")return null;let v=document.getElementById("popup-root");return v||(v=document.createElement("div"),v.id="popup-root",document.body.appendChild(v)),Ce.createPortal(g.jsx("div",{ref:u,role:"listbox","aria-activedescendant":i>=0?`multi-opt-${i}`:void 0,style:{position:"absolute",top:S?S.top:e.y,left:S?S.left:e.x,width:C??p,...h},"data-reactaform-theme":c?"dark":"light",children:r.map((w,E)=>{const k=n.includes(w.value),j=c?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",I={...b,background:E===i?j:b.background};return g.jsxs("div",{id:`multi-opt-${E}`,onMouseDown:M=>{M.stopPropagation(),o(w.value)},onKeyDown:M=>{const z=r.length;switch(M.key){case"ArrowDown":M.preventDefault(),d(T=>(T+1)%z);break;case"ArrowUp":M.preventDefault(),d(T=>(T-1+z)%z);break;case"Home":M.preventDefault(),d(0);break;case"End":M.preventDefault(),d(z-1);break;case"Enter":case" ":M.preventDefault(),M.stopPropagation(),o(w.value);break;case"Escape":M.preventDefault(),t(),a?.current?.focus();break}},tabIndex:E===i?0:-1,role:"option","aria-selected":k,style:I,onMouseEnter:M=>{M.currentTarget.style.background=j,d(E)},onMouseLeave:M=>{M.currentTarget.style.background="transparent",d(z=>z===E?-1:z)},children:[g.jsx("input",{type:"checkbox",checked:k,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:c?"#10b981":"#22c55e",cursor:"pointer"}}),w.label]},w.value)})}),v)},ft=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=e.min??void 0,i=e.max??void 0,d=Math.max(1,Math.round(e.step??1)),m=s.useCallback(y=>isNaN(y)?t("Must be a valid integer"):Number.isInteger(y)?u!==void 0&&y<u?t("Must be �?{{1}}",u):i!==void 0&&y>i?t("Must be �?{{1}}",i):L(a,e,y,t)??null:t("Must be an integer"),[a,e,t,u,i]),f=s.useRef(null),l=s.useRef(o);s.useEffect(()=>{l.current=o},[o]),s.useEffect(()=>{if(document.activeElement===c.current)return;const S=String(r),x=m(r);c.current&&(c.current.value=S),x!==f.current&&(f.current=x,l.current?.(x??null))},[r,m]);const h=y=>{if(y.trim()==="")return e.required?t("Value required"):null;const x=Number(y);return m(x)},b=y=>{const S=y.target.value,x=y.target.valueAsNumber,C=h(S);n?.(x,C)},p=h(String(r??""));return g.jsx(P,{field:e,error:p,children:g.jsx("input",{ref:c,id:e.name,type:"number",defaultValue:String(r??""),min:u,max:i,step:d,onChange:b,style:{width:"100%",height:"100%"},className:N.input,"aria-invalid":!!p,"aria-describedby":p?`${e.name}-error`:void 0})})},dt=({field:e,value:r,onChange:n,onError:o})=>{const{t}=$(),a=s.useRef(null),{definitionName:c}=$(),u=s.useCallback(f=>{const l=String(f??"").trim();if(l==="")return e.required?t("Value required"):null;if(e.pattern)try{if(!new RegExp(e.pattern).test(l))return e.patternErrorMessage?t(e.patternErrorMessage):t("Phone number does not match pattern: {{1}}",`${e.pattern}`)}catch{}return L(c,e,l,t)},[c,e,t]),i=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]),s.useEffect(()=>{const f=String(r??""),l=u(f);a.current&&a.current.value!==String(f)&&(a.current.value=String(f)),l!==i.current&&(i.current=l,d.current?.(l??null))},[r,u]);const m=f=>{const l=f.target.value,h=l.trim();let b=null;if(h===""){b=e.required?t("Value required"):null,n?.(l,b);return}b||(b=u(l)),n?.(l,b)};return g.jsx(P,{field:e,error:u(String(r??"")),children:g.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:a,onChange:m,className:B(N.input,N.textInput),"aria-invalid":!!u(String(r??"")),"aria-describedby":u(String(r??""))?`${e.name}-error`:void 0})})},pt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=e.layout?.toLowerCase()==="horizontal"?"row":"column",u=s.useRef(null),i=s.useRef(o);s.useEffect(()=>{i.current=o},[o]);const d=s.useCallback(f=>f===""||f===null||f===void 0?t("Value required"):!e.options||e.options.length===0?null:e.options.some(h=>h.value===f)?L(a,e,f,t)??null:t("Invalid option selected"),[e,t,a]);s.useEffect(()=>{const f=r!=null?String(r):"",l=d(f);if(i.current?.(l??null),u.current){const h=Array.from(u.current.querySelectorAll("input[type=radio]"));if(l&&e.options&&e.options.length>0){const b=String(e.options[0].value);h.forEach(p=>p.checked=p.value===b),n?.(b,null)}else h.forEach(b=>b.checked=b.value===f)}},[r,d,n,e.options]);const m=f=>{const l=f.target.value,h=d(l);i.current?.(h??null),n?.(l,h)};return g.jsx(P,{field:e,error:d(String(r??"")),children:g.jsx("div",{className:N.input,role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!d(String(r??"")),style:{display:"flex",flexDirection:c,flexWrap:c==="row"?"wrap":"nowrap",gap:c==="row"?"12px":"4px",alignItems:c==="row"?"center":"stretch",width:"100%",padding:c==="row"?"8px":void 0,boxSizing:"border-box"},ref:u,children:(e.options??[]).map(f=>g.jsxs("label",{className:B(N.label),style:{display:c==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:c==="column"?6:0,cursor:"pointer",width:c==="column"?"100%":void 0,justifyContent:"flex-start"},children:[g.jsx("input",{type:"radio",name:e.name,value:String(f.value),defaultChecked:String(r??"")===String(f.value),onChange:m,style:{width:"1.1em",height:"1.1em"}}),g.jsx("span",{style:{userSelect:"none",textAlign:c==="column"?"left":void 0,flex:c==="column"?1:void 0,fontWeight:400},children:t(f.label)})]},String(f.value)))})})},gt={display:"flex",gap:4},ht={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},bt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),[c,u]=s.useState(null),i=s.useRef([]),d=e.max||5,m=s.useCallback(p=>e.required&&p===0?t("Value required"):L(a,e,p,t)??null,[e,t,a]),f=s.useRef(null),l=s.useRef(o);s.useEffect(()=>{l.current=o},[o]),s.useEffect(()=>{let p=r||0;r<0&&(p=0),r>d&&(p=d);const y=m(p);y!==f.current&&(f.current=y,l.current?.(y??null))},[r,m,d]);const h=p=>{const y=m(p);n?.(p,y)},b=(()=>{let p=r||0;return p<0&&(p=0),p>d&&(p=d),p})();return g.jsx(P,{field:e,error:m(b),children:g.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,style:gt,"aria-invalid":!!m(b),"aria-describedby":m(b)?`${e.name}-error`:void 0,children:(()=>{const p=e.icon,y=p&&String(p).trim()?String(p):"★";return[...Array(d)].map((S,x)=>{const C=x<b,v=c!==null&&x<=c||C?"gold":"lightgray";return g.jsx("span",{ref:w=>i.current[x]=w,role:"radio",tabIndex:b>0?x===b-1?0:-1:x===0?0:-1,"aria-checked":C,onClick:()=>h(x+1),onKeyDown:w=>{if(w.key==="Enter"||w.key===" ")w.preventDefault(),h(x+1);else if(w.key==="ArrowRight"||w.key==="ArrowUp"){w.preventDefault();const E=Math.min(d-1,x+1);i.current[E]?.focus()}else if(w.key==="ArrowLeft"||w.key==="ArrowDown"){w.preventDefault();const E=Math.max(0,x-1);i.current[E]?.focus()}},onMouseEnter:()=>u(x),onMouseLeave:()=>u(null),style:{...ht,color:v},"aria-label":`Rating ${x+1}`,title:t(`${e.displayName} ${x+1}`),children:y},x)})})()})})},yt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useRef(null),i=s.useRef(o);s.useEffect(()=>{i.current=o},[o]);const d=s.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),m=s.useCallback(p=>p===""?e.required?t("Value required"):null:e.minLength!==void 0&&p.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&p.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):d&&!d.test(p)?e.patternErrorMessage?t(e.patternErrorMessage):t("Input does not match pattern: {{1}}",e.pattern):L(a,e,p,t),[e,a,t,d]),f=p=>{const y=p.target.value,S=m(y);n?.(y,S)};s.useEffect(()=>{const p=m(r??"");c.current&&c.current.value!==String(r??"")&&(c.current.value=String(r??"")),p!==u.current&&(u.current=p,i.current?.(p??null))},[r,m]);const[l,h]=s.useState(!1),b=()=>h(p=>!p);return g.jsx(P,{field:e,error:m(String(r??"")),children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[g.jsx("input",{id:e.name,type:l?"text":"password",defaultValue:String(r??""),ref:c,onChange:f,className:B(N.input,N.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!m(String(r??"")),"aria-describedby":m(String(r??""))?`${e.name}-error`:void 0}),g.jsx("button",{type:"button",onClick:b,"aria-label":t(l?"Hide password":"Show password"),style:{background:"transparent",border:"none",cursor:"pointer",fontSize:16,lineHeight:1,padding:"4px 6px",flexShrink:0},children:l?"🙈":"👁️"})]})})},xt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function vt(e){return xt.test(e)}const wt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useRef(null),i=s.useCallback(b=>{let p=null;if(b.trim()==="")return t("Value required");if(!vt(b))return t("Invalid number");const y=Number(b);return typeof e.min=="number"&&y<e.min?t("Value should be at least {{1}}",e.min):typeof e.max=="number"&&y>e.max?t("Value should be at most {{1}}",e.max):(p||(p=L(a,e,y,t)),p)},[a,e,t]),d=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const b=String(r),p=i(b);u.current&&document.activeElement!==u.current&&(u.current.value=isNaN(Number(b))?String(e.min??0):String(Number(b))),c.current&&document.activeElement!==c.current&&(c.current.value=b),p!==d.current&&(d.current=p,m.current?.(p??null))},[r,i,e.min]);const f=e.min??0,l=e.max??100,h=b=>{const p=b.target.value,y=i(p);n?.(p,y)};return g.jsx(P,{field:e,error:i(String(r??"")),children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[g.jsx("input",{ref:u,id:`${e.name}-range`,type:"range",defaultValue:isNaN(Number(r))?String(f):String(Number(r)),onChange:h,min:f,max:l,style:{padding:"0px, 0px",flex:1},className:N.rangeInput,"aria-invalid":!!i(String(r??"")),"aria-describedby":i(String(r??""))?`${e.name}-error`:void 0}),g.jsx("input",{id:e.name,ref:c,type:"text",defaultValue:String(r??""),onChange:h,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:B(N.input,N.textInput),"aria-invalid":!!i(String(r??"")),"aria-describedby":i(String(r??""))?`${e.name}-error`:void 0})]})})},St=({field:e,value:r,onChange:n,onError:o})=>{const{t,formStyle:a,fieldStyle:c,definitionName:u}=$(),i=a,d=c,m=(v,w,E)=>{if(!w)return{};const k=v?.[w];return(E&&k?k[E]:void 0)??{}},f=s.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...m(i,"switch","label"),...m(d,void 0,"label")}),[i,d]),l=s.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...m(i,"switch","hiddenInput"),...m(d,void 0,"hiddenInput")}),[i,d]),h=s.useMemo(()=>({position:"absolute",cursor:"pointer",top:0,left:0,right:0,bottom:0,backgroundColor:"var(--reactaform-switch-off-bg, #ccc)",transition:"0.3s",borderRadius:24,borderWidth:2,borderStyle:"solid",borderColor:"transparent",...m(i,"switch","slider"),...m(d,void 0,"slider")}),[i,d]),b=s.useMemo(()=>({position:"absolute",height:16,width:16,left:2,bottom:2,backgroundColor:"white",transition:"0.3s",borderRadius:"50%",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.3)",...m(i,"switch","knob"),...m(d,void 0,"knob")}),[i,d]),p=!!r,y=s.useRef(null),S=s.useRef(o),x=s.useCallback(v=>v?L(u,e,v,t)??null:e.required?t("Value required"):null,[e,t,u]),C=()=>{const v=!p,w=x(v);n?.(v,w)};s.useEffect(()=>{S.current=o},[o]),s.useEffect(()=>{const v=x(p);v!==y.current&&(y.current=v,S.current?.(v??null))},[p,e,x]);const R=e.name;return g.jsx(P,{field:e,error:x(p),rightAlign:!1,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[g.jsx("label",{className:N.label,htmlFor:R,style:{textAlign:"left",justifyContent:"flex-start"},children:t(e.displayName)}),g.jsxs("label",{style:f,children:[g.jsx("input",{id:e.name,type:"checkbox",checked:p,readOnly:!0,"aria-label":t(e.displayName),"aria-invalid":!!x(p),"aria-describedby":x(p)?`${e.name}-error`:void 0,style:l,tabIndex:-1}),g.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":p,"aria-invalid":!!x(p),"aria-describedby":x(p)?`${e.name}-error`:void 0,onClick:C,onKeyDown:v=>{(v.key===" "||v.key==="Spacebar"||v.key==="Space"||v.key==="Enter")&&(v.preventDefault(),C())},className:`reactaform-switch ${p?"active checked on":""} `,style:p?{...h,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:h,children:g.jsx("span",{style:{...b,transform:p?"translateX(20px)":void 0}})})]})]})})},qe=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useRef(null),i=s.useRef(o);s.useEffect(()=>{i.current=o},[o]);const d=s.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),m=s.useCallback(l=>l.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&l.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&l.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):d&&!d.test(l)?e.patternErrorMessage?t(e.patternErrorMessage):t("Input does not match pattern: {{1}}",e.pattern):L(a,e,l,t),[e,a,t,d]),f=l=>{const h=l.target.value,b=m(h);n?.(h,b)};return s.useEffect(()=>{const l=m(r);c.current&&c.current.value!==String(r??"")&&(c.current.value=String(r??"")),l!==u.current&&(u.current=l,i.current?.(l??null))},[r,m]),g.jsx(P,{field:e,error:m(String(r??"")),children:g.jsx("input",{id:e.name,"aria-invalid":!!m(String(r??"")),"aria-describedby":m(String(r??""))?`${e.name}-error`:void 0,type:"text",defaultValue:String(r??""),ref:c,onChange:f,className:B(N.input,N.textInput)})})},Ct=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useRef(o),i=e.includeSeconds??!0;s.useEffect(()=>{u.current=o},[o]);const d=s.useCallback(f=>{if(!f||f.trim()==="")return e.required||e.min||e.max?t("Value required"):null;const l=p=>{const y=p.split(":").map(x=>parseInt(x,10));if(y.some(x=>Number.isNaN(x)))return NaN;let S=0;if(y.length===3)S=y[0]*3600+y[1]*60+y[2];else if(y.length===2)S=y[0]*3600+y[1]*60;else if(y.length===1)S=y[0]*3600;else return NaN;return S},h=l(f);if(Number.isNaN(h))return t("Invalid time format");if(e.min&&typeof e.min=="string"){const p=l(e.min);if(!Number.isNaN(p)&&h<p)return t("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const p=l(e.max);if(!Number.isNaN(p)&&h>p)return t("Time must be on or before {{1}}",e.max)}return L(a,e,f,t)??null},[e,a,t]),m=f=>{const l=f.target.value,h=d(l);n?.(l,h)};return s.useEffect(()=>{const f=d(r);f!==c.current&&(c.current=f,u.current?.(f??null))},[r,d]),g.jsx(P,{field:e,error:d(r),children:g.jsx("input",{id:e.name,type:"time",value:r,step:i?1:60,onChange:m,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:B(N.input,N.textInput),"aria-invalid":!!d(r),"aria-describedby":d(r)?`${e.name}-error`:void 0})})};function jt({pos:e,options:r,onClose:n,onClickOption:o}){const t=s.useRef(null),a=s.useRef(!1),c=typeof window<"u"?document.getElementById("popup-root")||document.body:null;if(s.useEffect(()=>{function h(b){a.current||b.target.dataset?.popupMenu==="item"||t.current&&b.target instanceof Node&&!t.current.contains(b.target)&&n()}return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[n]),!c||r===void 0||r.length===0||!e||e.x==null||e.y==null)return null;const u=e.x,i=e.y,d=typeof window<"u"?window.innerWidth:1024,m=Math.max(0,d-160),f=Math.max(0,Math.min(u,m)),l=Math.max(0,i);return Ce.createPortal(g.jsx("div",{ref:t,onMouseDown:h=>{h.stopPropagation()},style:{position:"fixed",top:l,left:f,backgroundColor:"var(--reactaform-primary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:"var(--reactaform-border-radius, 4px)",boxShadow:"var(--reactaform-shadow, 0 2px 10px rgba(0,0,0,0.2))",zIndex:9999,minWidth:"var(--reactaform-menu-min-width, 150px)",pointerEvents:"auto"},children:r.map((h,b)=>g.jsx("div",{"data-popup-menu":"item",onMouseDown:p=>{p.stopPropagation(),a.current=!0},onClick:p=>{p.stopPropagation(),p.preventDefault(),o(h),n(),setTimeout(()=>{a.current=!1},100)},style:{padding:"var(--reactaform-menu-item-padding, 8px 12px)",cursor:"pointer",fontSize:"var(--reactaform-menu-item-font-size, 0.8em)",borderBottom:b<r.length-1?"1px solid var(--reactaform-border-light, #eee)":void 0,transition:"background-color 0.15s ease"},onMouseEnter:p=>{p.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:p=>{p.currentTarget.style.backgroundColor="transparent"},children:h.label},h.label??b))}),c)}const ae={};function Rt(e,r){if(e in ae)return;const n=Fe[e]??{},o={},t={},a={};for(const[u,i]of Object.entries(n))typeof i.factor=="number"&&(o[u]=i.factor),t[u]=r(u),a[r(u)]=u;const c=Object.keys(n)[0]??"";ae[e]={default:c,factors:o,labels:t,reverseLabels:a}}function Et(e,r,n){if(e==="C"){if(r==="F")return n*(9/5)+32;if(r==="K")return n+273.15}else if(e==="F"){if(r==="C")return(n-32)*5/9;if(r==="K")return(n-32)*5/9+273.15}else if(e==="K"){if(r==="C")return n-273.15;if(r==="F")return(n-273.15)*9/5+32}return n}function kt(e,r,n){if(!Number.isFinite(e))return[];if(n===ae.temperature)return Object.keys(n.labels).map(a=>{const c=Et(r,a,e);return Number.isFinite(c)?{label:`${c.toFixed(6)} ${a}`,value:c.toString(),unit:a}:{label:`${String(c)} ${a}`,value:String(c),unit:a}});const t=n.factors[r];return t===void 0?[]:Object.entries(n.factors).map(([a,c])=>{const u=e/t*c;return Number.isFinite(u)?{label:`${u.toFixed(6)} ${a}`,value:u.toString(),unit:a}:{label:`${String(u)} ${a}`,value:String(u),unit:a}})}function ue(e,r){return e in r.labels?e:r.reverseLabels&&r.reverseLabels[e]?r.reverseLabels[e]:null}const Nt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,It=({unitFactors:e,field:r,value:n,onChange:o,onError:t})=>{const{t:a,definitionName:c}=$(),u=s.useRef(null),i=s.useRef(null),d=s.useRef(null),[m,f]=s.useState(null),[l,h]=s.useState(null),[b,p]=s.useState(!1),[y,S]=s.useState(null),[x,C]=s.useState([]),R=s.useCallback((V,F)=>{if(!V||V.trim()==="")return r.required?a("Value required"):null;if(!Nt.test(V))return a("Must be a valid number");const D=L(c,r,[V,F],a);return D||null},[c,r,a]),v=e.reverseLabels!==void 0?e.reverseLabels:Object.fromEntries(Object.entries(e.labels).map(([V,F])=>[F,V]));s.useEffect(()=>{const V=String(n[0]);let F=n[1]??e.default;F=ue(F,e)||F;const D=document.activeElement;D===u.current||D===i.current||(u.current&&(u.current.value=V),i.current&&(i.current.value=F),d.current!==null&&(cancelAnimationFrame(d.current),d.current=null),d.current=requestAnimationFrame(()=>{d.current=null,f(null),h(null)}))},[n,e]),s.useEffect(()=>()=>{d.current!==null&&(cancelAnimationFrame(d.current),d.current=null)},[]);const w=s.useRef(null),E=s.useRef(t);s.useEffect(()=>{E.current=t},[t]),s.useEffect(()=>{const V=String(n[0]);let F=n[1]??e.default;F=ue(F,e)||F;const D=R(V,F);D!==w.current&&(w.current=D,E.current?.(D??null))},[n,e,R]);const k=(V,F,D)=>{const U=v[F]||F;o?.([V,U],D)},j=V=>{const F=V.target.value,D=i.current?i.current.value:e.default,U=R(F,D);f(F),k(F,D,U)},I=V=>{const F=V.target.value,D=u.current?u.current.value:String(n[0]??""),U=R(D,F);h(F),i.current&&(i.current.value=F),k(D,F,U)},M=V=>{const F=u.current?u.current.value:String(n[0]??""),D=parseFloat(F),U=i.current?i.current.value:e.default;if(R(F,U)||!F.trim()||!Number.isFinite(D))return;const ie=V.currentTarget.getBoundingClientRect(),fe=ie.left,Z=ie.bottom;S({x:fe,y:Z});const A=kt(D,U,e);if(A.length===0){C([]),p(!1);return}C(A),p(O=>!O)},z=V=>{const{value:F,unit:D}=V;p(!1),S(null),u.current&&(u.current.value=F),i.current&&(i.current.value=D),f(F),h(D);const U=R(F,D);k(F,D,U)},T=String(n[0]??""),ee=ue(n[1]??e.default,e)||(n[1]??e.default),re=m??T,G=!!R(re,l??ee)||!re.trim(),se={width:"var(--reactaform-unit-btn-width, 2.5em)",height:"var(--reactaform-unit-btn-height, 2.5em)",padding:"var(--reactaform-unit-btn-padding, 0)",border:"none",borderRadius:"var(--reactaform-button-border-radius, var(--reactaform-border-radius, 0.25em))",backgroundColor:G?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:G?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",opacity:G?+"var(--reactaform-button-disabled-opacity, 0.6)":1,display:"flex",alignItems:"center",justifyContent:"center"},J=R(T,ee);return g.jsx(P,{field:r,error:J,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[g.jsx("input",{id:r.name,type:"text",ref:u,defaultValue:String(n[0]??""),onChange:j,style:{width:"var(--reactaform-unit-input-width, 100px)"},className:B(N.input,N.textInput),"aria-invalid":!!J,"aria-describedby":J?`${r.name}-error`:void 0}),g.jsx("select",{id:`${r.name}-unit`,ref:i,defaultValue:ue(n[1]??e.default,e)||(n[1]??e.default),onChange:I,className:B(N.input,N.inputSelect),"aria-invalid":!!J,"aria-describedby":J?`${r.name}-error`:void 0,children:Object.keys(e.labels).map(V=>g.jsx("option",{value:V,children:e.labels[V]??V},V))}),g.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[g.jsx("button",{onClick:M,"aria-disabled":G,disabled:G,style:se,className:N.button,children:g.jsx("span",{style:{fontSize:"var(--reactaform-unit-btn-icon-size, 1em)",lineHeight:"1",transform:"translateY(-1px)",pointerEvents:"none"},children:"⟷"})}),b&&x&&g.jsx(jt,{pos:y,options:x,onClose:()=>{S(null),p(!1)},onClickOption:z})]})]})})};function Ft({field:e,value:r,onChange:n}){const{t:o}=$(),t=e.dimension;if(!t)return null;ae[t]||Rt(t,o);const a=ae[t];return a?g.jsx(It,{unitFactors:a,field:e,value:r,onChange:n}):null}const Pe=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,Te=e=>{try{return new URL(e),!0}catch{return!1}},Mt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=$(),c=s.useRef(null),u=s.useCallback(f=>{const l=f.trim();if(l==="")return e.required?t("Value required"):null;if(!Pe.test(l)&&!Te(l)){const b=e.allowRelative===!0;let p=!1;if(Pe.test(l)||Te(l))p=!0;else if(b)try{new URL(l,"http://example.com"),p=!0}catch{p=!1}if(!p)return t("Must be a valid URL")}return L(a,e,l,t)??null},[a,e,t]),i=f=>{const l=f.target.value,h=u(l);n?.(l.trim(),h)},d=s.useRef(null),m=s.useRef(o);return s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const f=r??"",l=u(f);c.current&&c.current.value!==String(f)&&(c.current.value=String(f)),l!==d.current&&(d.current=l,m.current?.(l??null))},[r,u]),g.jsx(P,{field:e,error:u(String(r??"")),children:g.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:c,onChange:i,style:{alignItems:"left"},className:B(N.input,N.textInput),placeholder:"https://example.com","aria-invalid":!!u(String(r??"")),"aria-describedby":u(String(r??""))?`${e.name}-error`:void 0})})},Se=new le,$t=new Set(["checkbox","switch","dropdown","radio","multi-selection","slider","stepper","color","rating"]),tr={checkbox:Pr,color:Br,date:Ur,dropdown:Wr,email:Kr,file:Gr,float:tt,"float-array":Qr,image:ot,int:ct,"int-array":st,"multi-selection":lt,multiline:ut,password:yt,phone:dt,radio:pt,rating:bt,separator:Jr,slider:wt,string:qe,stepper:ft,switch:St,text:qe,time:Ct,unit:Ft,url:Mt};function nr(e,r,n){const o=r;if(!n&&e in tr){console.warn(`Can't Overwrite Base Component type "${e}".`);return}if($t.has(e)){Se.register(e,o);return}const t=a=>{const{callback:u,cancel:i}=Ue((...d)=>{const m=a.onChange;typeof m=="function"&&m(...d)},200);return s.useEffect(()=>()=>{i()},[i]),s.createElement(o,{...a,onChange:u})};Se.register(e,t)}function At(e,r){nr(e,r,!1)}function or(e){return Se.get(e)}let Be=!1;function ar(){Be||(Object.entries(tr).forEach(([e,r])=>{nr(e,r,!0)}),Be=!0)}const sr=new le;function ir(e,r){sr.register(e,r)}function Vt(e){return sr.get(e)}ir("Preset_AlertSubmitHandler",(e,r,n)=>{const o={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:n},t=JSON.stringify(o,null,2);alert(t)});const cr=s.memo(({field:e,value:r,handleChange:n,handleError:o})=>{const t=or(e.type),a=s.useCallback((u,i)=>n(e.name,u,i),[n,e.name]),c=s.useCallback(u=>o?.(e.name,u),[o,e.name]);return t?g.jsx(t,{field:e,value:r,onChange:a,onError:c}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError);cr.displayName="FieldWrapper";const ur=(e,r,n,o)=>g.jsx(cr,{field:e,value:r[e.name],handleChange:n,handleError:o},e.name),lr=s.memo(({groupName:e,isOpen:r,fields:n,valuesMap:o,handleChange:t,handleError:a,toggleGroup:c,t:u})=>{const i=s.useCallback(()=>c(e),[c,e]),{formStyle:d,fieldStyle:m}=$(),f=s.useMemo(()=>({border:"1px solid var(--reactaform-border-color, #bbb)",padding:"var(--reactaform-fieldset-padding, 0.5em)",borderRadius:"var(--reactaform-border-radius, 4px)",marginBottom:"var(--reactaform-space, 8px)",...d?.fieldset||{},...m?.fieldset||{}}),[d,m]),l=s.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...d?.legend||{},...m?.legend||{}}),[d,m]);return g.jsxs("fieldset",{style:f,children:[g.jsxs("legend",{onClick:i,style:l,children:[g.jsx("span",{children:u(e)}),g.jsx("span",{children:r?"▼":"▶"})]}),r&&n.map(h=>g.jsx("div",{children:ur(h,o,t,a)},h.name))]})});lr.displayName="FieldGroup";const Dt=(e,r,n,o,t,a,c,u,i)=>{const d=r.slice(0,u).filter(h=>c[h.name]),f=$r(d).groups,l=[];return f.forEach(h=>{if(h.name){const b=e[h.name]??!0;l.push(g.jsx(lr,{groupName:h.name,isOpen:b,fields:h.fields,valuesMap:n,handleChange:t,handleError:a,toggleGroup:i,t:o},h.name))}else h.fields.forEach(b=>l.push(g.jsx("div",{children:ur(b,n,t,a)},b.name)))}),l},zt=e=>{const r={};return e.forEach(n=>{r[n.name]=!1}),r},Me=(e,r,n,o)=>{const t=r[e];if(!t?.children)return;const a=n[e],c=a!=null?String(a):"";(t.children[c]||[]).forEach(i=>{o[i]=!0,Me(i,r,n,o)})},mr=(e,r,n)=>{const o=r[e];o?.children&&Object.values(o.children).flat().forEach(t=>{n[t]=!1,mr(t,r,n)})},Lt=(e,r,n,o)=>{const t={...n};return e.forEach(a=>{(!a.parents||Object.keys(a.parents).length===0)&&(t[a.name]=!0,Me(a.name,o,r,t))}),t},Ot=(e,r,n,o,t)=>{const a={...e};if(mr(o,r,a),t!=null){const c=r[o];if(c?.children){const u=String(t);(c.children[u]||[]).forEach(d=>{a[d]=!0,Me(d,r,n,a)})}}return a};async function qt(e,r,n,o,t){const a=Object.values(t).filter(Boolean);if(a.length>0)return{success:!1,message:o("Please fix validation errors before submitting."),errors:a};const c={...n},u=[];if(e&&Array.isArray(e.properties))for(const d of e.properties){const m=d.name,f=c[m];if(f==null)continue;const l=d.type;try{if(l==="int"||l==="number"||l==="float"){const h=Number(String(f).trim());isNaN(h)?u.push(o(`Invalid number format for field ${d.displayName||m}`)):c[m]=h}else if(l==="int-array"||l==="float-array"){const b=String(f).split(",").map(p=>p.trim()).filter(Boolean).map(p=>{const y=Number(p);return isNaN(y)?(u.push(o(`Invalid number "${p}" in array for field ${d.displayName||m}`)),0):y});u.length===0&&(c[m]=b)}}catch(h){u.push(o(`Error processing field ${d.displayName||m}: ${h}`))}}if(u.length>0)return{success:!1,message:o("Data transformation errors occurred."),errors:u};const i=await Xe(e,c,o);if(i&&i.length>0)return{success:!1,message:"Validation Fail",errors:i};if(e&&typeof e.submitHandlerName=="string"){const d=Vt(e.submitHandlerName);if(d)try{const m=await d(e,r?.name??null,c,o);if(m&&m.length>0)return{success:!1,message:o("Submission failed."),errors:Array.isArray(m)?m:[m]}}catch(m){return{success:!1,message:o("Submission handler error occurred."),errors:[String(m)]}}}return{success:!0,message:o("Form submitted successfully."),data:c}}const fr=({definition:e,instance:r,chunkSize:n=50,chunkDelay:o=50})=>{const{properties:t,displayName:a}=e,c=$(),{t:u,formStyle:i,language:d}=c,m={...c,definitionName:e?.name??c.definitionName},[f,l]=s.useState("en"),[h,b]=s.useState([]),[p,y]=s.useState({}),[S,x]=s.useState({}),[C,R]=s.useState({}),[v,w]=s.useState({}),[E,k]=s.useState({}),[j,I]=s.useState(null),[M,z]=s.useState(null),[T,ee]=s.useState(0),[re,$e]=s.useState(!1),[G,se]=s.useState(!1),[J,V]=s.useState(r.name||""),F=s.useRef(r),D=s.useRef(!1);s.useEffect(()=>{const A=Object.fromEntries(t.map(q=>[q.name,{...q,children:{}}]));t.forEach(q=>{q.parents&&Object.entries(q.parents).forEach(([te,de])=>{const ne=A[te];ne&&de.forEach(gr=>{ne.children||(ne.children={});const Ae=String(gr);ne.children[Ae]=[...ne.children[Ae]||[],q.name]})})}),Mr(t,A);const O=Object.values(A),H={};O.forEach(q=>{if(q.type==="unit"){const te=typeof q.defaultValue=="number"?String(q.defaultValue):"",de=typeof q.defaultUnit=="string"?q.defaultUnit:String(q.defaultUnit??"m");H[q.name]=[te,de]}else H[q.name]=q.defaultValue}),F.current=r,Object.keys(r.values).forEach(q=>{A[q]!==void 0&&(H[q]=r.values[q])});const _=zt(O),K={};O.forEach(q=>{q.group&&!(q.group in K)&&(K[q.group]=!0)});const Q=requestAnimationFrame(()=>{b(O),y(A),x(H),R(Lt(O,H,_,A)),w(K),$e(!0),V(r.name)});return()=>cancelAnimationFrame(Q)},[t,r,e]),s.useEffect(()=>{if(!re||T>=h.length)return;const A=setTimeout(()=>{ee(O=>Math.min(O+n,h.length))},o);return()=>clearTimeout(A)},[re,T,h.length,n,o]);const U=s.useCallback((A,O,H)=>{I(null),z(null),x(_=>{const K={..._,[A]:O},Q=p[A];return Q&&["checkbox","dropdown","multi-select","radio","switch"].includes(Q.type)&&R(te=>Ot(te,p,K,A,String(O))),K}),k(_=>H?{..._,[A]:H}:Object.fromEntries(Object.entries(_).filter(([Q])=>Q!==A)))},[p,I,z]);s.useEffect(()=>{let A=0;return A=requestAnimationFrame(()=>{d!==f&&(l(d||"en"),I(null),z(null))}),()=>cancelAnimationFrame(A)},[d,f]),s.useEffect(()=>{let A=0;return A=requestAnimationFrame(()=>{if(D.current){D.current=!1,F.current=r,V(r.name||"");return}F.current=r,I(null),z(null),V(r.name||"")}),()=>cancelAnimationFrame(A)},[r,r.name]);const me=s.useCallback((A,O)=>{k(H=>O?{...H,[A]:String(O)}:Object.fromEntries(Object.entries(H).filter(([K])=>K!==A)))},[]),ie=async()=>{D.current=!0;const A=F.current?.name;F.current.name=J;const O=await qt(e,F.current,S,u,E),H=typeof O.message=="string"?O.message:String(O.message),_=Object.values(O.errors??{}).join(`
|
|
288
|
-
`);
|
|
289
|
-
`+
|
|
287
|
+
`,Ee=_.createContext(void 0),F=()=>{const e=_.useContext(Ee);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class de{map={};register(r,t){this.map[r]=t}get(r){return this.map[r]}has(r){return r in this.map}list(){return Object.keys(this.map)}entries(){return Object.entries(this.map)}values(){return Object.values(this.map)}size(){return Object.keys(this.map).length}unregister(r){return r in this.map?(delete this.map[r],!0):!1}clear(){this.map={}}registerAll(r){Array.isArray(r)?r.forEach(([t,o])=>this.register(t,o)):Object.entries(r).forEach(([t,o])=>this.register(t,o))}getOrDefault(r,t){return this.get(r)??t}}function Xe(e,r=300,t){const o=_.useRef(void 0),n=_.useRef(e),a=_.useRef(null),l=_.useRef(!1);_.useEffect(()=>{n.current=e},[e]),_.useEffect(()=>()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0)},[]);const c=_.useCallback(()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current=null,l.current=!1},[]),s=_.useCallback(()=>{if(o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current)try{n.current(...a.current)}finally{a.current=null,l.current=!1}},[]);return{callback:_.useCallback((...u)=>{if(t?.leading===!0&&!l.current){l.current=!0,n.current(...u),window.clearTimeout(o.current),o.current=window.setTimeout(()=>{l.current=!1,o.current=void 0},r);return}a.current=u,window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=void 0,a.current&&(n.current(...a.current),a.current=null,l.current=!1)},r)},[r,t?.leading]),cancel:c,flush:s}}const k={field:"reactaform-field",label:"reactaform-label",input:"reactaform-input",textInput:"reactaform-input--text",inputNumber:"reactaform-input--number",inputSelect:"reactaform-select",rangeInput:"reactaform-input--range",button:"reactaform-button"},T=(...e)=>{const r=[];for(const t of e)t&&(typeof t=="string"?r.push(t):typeof t=="object"&&Object.entries(t).forEach(([o,n])=>{n&&r.push(o)}));return r.join(" ")},Ze=({content:e,size:r="medium",animation:t=!0})=>{const{t:o,darkMode:n,formStyle:a,fieldStyle:l}=F(),[c,s]=i.useState(!1),[m,u]=i.useState({x:0,y:0}),[d,f]=i.useState(!1),g=i.useRef(null),b=i.useRef(null),p=i.useRef(null),y=i.useId(),S=i.useMemo(()=>{const w={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.06)",color:n?"#f0f0f0":"#333",border:`1px solid ${n?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.1)"}`,cursor:"pointer",transition:t?"all 0.2s ease":void 0,marginLeft:"0.3em"},text:{...{small:{padding:"4px 8px",fontSize:"11px",maxWidth:"200px"},medium:{padding:"6px 10px",fontSize:"12px",maxWidth:"240px"},large:{padding:"8px 12px",fontSize:"13px",maxWidth:"280px"}}[r],position:"fixed",backgroundColor:`var(--reactaform-tooltip-color-bg, ${n?"rgba(45,45,45,0.95)":"rgba(60,60,60,0.92)"})`,color:`var(--reactaform-tooltip-color, ${n?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:n?"0 8px 16px rgba(0,0,0,0.4)":"0 6px 18px rgba(0,0,0,0.12)",zIndex:2147483647,opacity:0,pointerEvents:"none",transition:t?"opacity 0.2s ease":void 0,whiteSpace:"normal",wordBreak:"break-word",boxSizing:"border-box"},textVisible:{opacity:1,pointerEvents:"auto"}},v=($,R,E)=>{const D=$?.[R];return(E&&D?D[E]:void 0)??{}};return{icon:{...w.icon,...v(a,"tooltip","icon"),...v(l,"tooltip","icon")},text:{...w.text,...v(a,"tooltip","text"),...v(l,"tooltip","text")},textVisible:w.textVisible}},[n,r,t,a,l]);i.useLayoutEffect(()=>{if(!c||!g.current||!b.current){f(!1);return}const N=g.current.getBoundingClientRect();p.current=N;const w=b.current.getBoundingClientRect(),v=8,j=window.innerWidth,$=window.innerHeight,R=-4;let E=N.right+v,I=N.top+N.height/2-w.height/2+R;E+w.width>j-v&&(E=N.left-v-w.width),E=Math.max(v,Math.min(E,j-w.width-v)),I=Math.max(v,Math.min(I,$-w.height-v)),u({x:E,y:I}),f(!0)},[c]);const x=typeof document<"u"?document.getElementById("popup-root"):null,C=h.jsx("div",{ref:b,"data-tooltip-id":y,style:{...S.text,transform:d?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...d?S.textVisible:{},top:m.y,left:m.x},"data-reactaform-theme":n?"dark":"light",children:o(e)});return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-testid":"tooltip-icon",ref:g,"aria-describedby":c?y:void 0,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{...S.icon},children:"?"}),c&&(x?ke.createPortal(C,x):C)]})},ve=i.memo(({field:e,error:r,children:t,showLabel:o=!0})=>{const{t:n}=F(),a=e?.labelLayout==="column-center"?"center":"left";return h.jsxs("div",{className:`${k.field} column-layout`,style:{display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)","--label-align":a},children:[o&&h.jsx("div",{style:{textAlign:a,width:"100%"},children:h.jsx("label",{id:`${e.name}-label`,className:k.label,htmlFor:e.name,style:{textAlign:a,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"},children:n(e.displayName)})}),h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"},children:[h.jsx("div",{style:{flex:1,minWidth:0,maxWidth:"100%"},children:h.jsx("div",{style:{width:"100%"},children:t})}),e.tooltip&&h.jsx(Ze,{content:e.tooltip})]}),r&&h.jsx(Ne,{id:`${e.name}-error`,children:r})]})});ve.displayName="ColumnFieldLayout";const Qe=i.memo(({field:e,error:r,children:t,rightAlign:o=!1})=>{const{t:n}=F(),a=i.useMemo(()=>({display:"flex",flexDirection:"column",gap:0}),[]),l=i.useMemo(()=>({display:"flex",flexDirection:"row",alignItems:"center",gap:"3px"}),[]);return h.jsxs("div",{className:`${k.field} row-layout`,children:[h.jsx("label",{id:`${e.name}-label`,className:k.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:n(e.displayName)}),h.jsxs("div",{style:a,children:[h.jsxs("div",{style:l,children:[o?h.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)"},children:t}):t,e.tooltip&&h.jsx(Ze,{content:e.tooltip})]}),r&&h.jsx(Ne,{id:`${e.name}-error`,children:r})]})]})});Qe.displayName="RowFieldLayout";const q=({field:e,error:r,children:t,rightAlign:o=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?h.jsx(ve,{field:e,error:r,showLabel:!0,children:t}):e.type==="checkbox"||e.type==="switch"?h.jsx(ve,{field:e,error:r,showLabel:!1,children:t}):h.jsx(Qe,{field:e,error:r,rightAlign:o,children:t}),Ne=i.memo(({children:e,id:r})=>{const t=i.useMemo(()=>({color:"var(--reactaform-error-color)",fontSize:"13px",marginTop:"4px",fontWeight:"var(--reactaform-font-weight)",display:"flex",flex:1,justifyContent:"flex-start",alignItems:"flex-start"}),[]);return h.jsx("div",{id:r,style:t,children:e})});Ne.displayName="ErrorDiv";const er=i.memo(({name:e,onChange:r})=>{const{t}=F();return h.jsxs("div",{style:{marginBottom:16},children:[h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[h.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:t("Instance Name")}),h.jsx("input",{id:"instance-name-input",type:"text",value:e,onChange:o=>r(o.target.value),style:{width:"100%",padding:"var(--reactaform-input-padding, 8px 12px)",fontSize:"var(--reactaform-input-font-size, 14px)",border:"1px solid var(--reactaform-input-border, #ddd)",borderRadius:"var(--reactaform-border-radius, 4px)",backgroundColor:"var(--reactaform-input-bg, #fff)",color:"var(--reactaform-text-color, #333)",boxSizing:"border-box"},placeholder:t("Enter instance name")})]}),h.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});er.displayName="InstanceName";class kr extends de{registerInCategory(r,t,o){this.get(r)||this.register(r,{});const n=this.get(r);n[t]=o}getFromCategory(r,t){return this.get(r)?.[t]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const rr=new de,tr=new kr;function nr(e,r){rr.register(e,r)}function or(e,r,t){tr.registerInCategory(e,r,t)}function ar(e,r){return tr.getFromCategory(e,r)||null}function sr(e){return rr.get(e)||null}function Er(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const be=new Map,ye=new Map;function z(e,r,t,o){if(!r)return null;let n=null,a=null;if(typeof r.validationHandlerName=="string")n=e,a=r.validationHandlerName;else if(Array.isArray(r.validationHandlerName)){const[s,m]=r.validationHandlerName;m?(n=s,a=m):s&&(n=e,a=s)}if(n===null||a===null)return null;const l=`${n}:${a}`;if(!be.has(l)){const s=ar(n,a);be.set(l,s)}const c=be.get(l);if(c)try{return c(r.name,t,o)||null}catch(s){return String(s instanceof Error?s.message:s)}return null}async function Nr(e,r,t){if(e&&typeof e.validationHandlerName=="string"){const o=e.validationHandlerName;if(!ye.has(o)){const a=sr(o);ye.set(o,a)}const n=ye.get(o);if(n)try{const a=n(r,t);return Er(a)?await a||null:a||null}catch(a){return[String(a instanceof Error?a.message:a)]}}return null}function Z(e){return typeof e=="object"&&e!==null}function Ie(e){if(!Z(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function ir(e){if(!Z(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(t=>Ie(t))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=Z(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Ir(e,r,t={}){try{const{includeMetadata:o=!1,dateFormat:n="iso",fileHandling:a="metadata",prettify:l=!1,excludeFields:c=[],includeOnlyFields:s=[]}=t;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const m=[],u=[],d={},g=(ir(r)||Z(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),b=new Map(g.map(y=>[y.name,y]));for(const[y,S]of Object.entries(e)){if(c.includes(y)){u.push(y);continue}if(s.length>0&&!s.includes(y)){u.push(y);continue}if(S===void 0)continue;const x=b.get(y);try{d[y]=Mr(S,x,{dateFormat:n,fileHandling:a})}catch(C){m.push(`Error serializing field '${y}': ${String(C)}`),d[y]=null}}return o&&(d._metadata={serializedAt:new Date().toISOString(),version:(Z(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(d).length-1}),{success:!0,data:l?JSON.stringify(d,null,2):JSON.stringify(d),metadata:{fieldCount:Object.keys(d).length,excludedFields:u,warnings:m}}}catch(o){return{success:!1,error:`Serialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Mr(e,r,t={}){const{dateFormat:o="iso",fileHandling:n="metadata"}=t;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return He(e,o);case"file":return Te(e,n);case"int":case"integer":return typeof e=="string"?parseInt(e,10):e;case"float":case"number":return typeof e=="string"?parseFloat(e):e;case"boolean":return typeof e=="string"?e==="true":!!e;case"int-array":case"float-array":return Array.isArray(e)?e.map(a=>typeof a=="string"?Number(a):a):e;default:return e}return e instanceof Date?He(e,o):we(e)||Array.isArray(e)&&we(e[0])?Te(e,n):e}function He(e,r){let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){const o=new Date(e);if(!isNaN(o.getTime()))t=o;else return e}else return e;switch(r){case"timestamp":return t.getTime();case"locale":return t.toLocaleString();case"iso":default:return t.toISOString()}}function Te(e,r){return r==="skip"?null:Array.isArray(e)?e.map(t=>Be(t,r)):Be(e,r)}function Be(e,r){if(!we(e))return e;const t=e;return r==="metadata"?{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified}:{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified,_note:"Base64 encoding requires async implementation"}}function $r(e,r,t={}){try{const{strict:o=!1,validateTypes:n=!0,preserveUnknownFields:a=!0,dateFormat:l="auto"}=t;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let c;try{c=JSON.parse(e)}catch(p){return{success:!1,error:`Invalid JSON: ${p instanceof Error?p.message:"Unknown parsing error"}`}}if(!c||typeof c!="object")return{success:!1,error:"Parsed data must be an object"};const s=[],m=[],u={},f=(ir(r)||Z(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),g=new Map(f.map(p=>[p.name,p]));for(const p of f){const y=p.name,S=c[y];if(S===void 0){o&&p.required&&m.push(`Required field '${y}' is missing`);continue}try{u[y]=Fr(S,p,{validateTypes:n,dateFormat:l})}catch(x){const C=`Error deserializing field '${y}': ${String(x)}`;o?m.push(C):(s.push(C),u[y]=S)}}if(a)for(const[p,y]of Object.entries(c))!g.has(p)&&p!=="_metadata"&&(o&&s.push(`Unknown field '${p}' preserved`),u[p]=y);const b=m.length>0;return{success:!b,data:u,warnings:s.length>0?s:void 0,validationErrors:b?m:void 0}}catch(o){return{success:!1,error:`Deserialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Fr(e,r,t={}){const{validateTypes:o=!0,dateFormat:n="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Dr(e,n,o);case"int":case"integer":return Se(e,o);case"float":case"number":return Ce(e,o);case"boolean":return Or(e,o);case"int-array":return Ue(e,"integer",o);case"float-array":return Ue(e,"number",o);case"string":case"text":case"email":case"url":case"phone":return o?String(e):e;default:return e}}catch(a){if(o)throw new Error(`Type conversion failed: ${String(a)}`);return e}}function Vr(e,r={}){try{const{prettify:t=!0,includeMetadata:o=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const n={...e};return o&&(n._metadata={serializedAt:new Date().toISOString(),version:n.version||"1.0.0",propertyCount:(Array.isArray(n.properties)?n.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(n,null,2):JSON.stringify(n),metadata:{fieldCount:(Array.isArray(n.properties)?n.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Ar(e,r={}){try{const{strict:t=!1,validateTypes:o=!0}=r;let n;if(typeof e=="string")try{n=JSON.parse(e)}catch(u){return{success:!1,error:`Invalid JSON for definition: ${u instanceof Error?u.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")n={...e};else return{success:!1,error:"Input must be a string or object"};const a=[],l=[],c=["name","version","displayName"];for(const u of c)if(!n[u])if(t)l.push(`Required field '${u}' is missing`);else switch(a.push(`Missing field '${u}', using default`),u){case"name":n.name="unnamed-definition";break;case"version":n.version="1.0.0";break;case"displayName":n.displayName=n.name||"Unnamed Definition";break}const s=Array.isArray(n.properties)?n.properties:null;s?n.properties=s.map((u,d)=>{const f=Z(u)?u:{},g={...f};if(!f.name){const b=`Property at index ${d} missing 'name'`;t?l.push(b):(a.push(`${b}, using 'field_${d}'`),g.name=`field_${d}`)}return f.displayName||(g.displayName=f.name||`Field ${d}`),f.type||(t&&o?l.push(`Property '${f.name||d}' missing 'type'`):(a.push(`Property '${f.name||d}' missing 'type', using 'string'`),g.type="string")),f.defaultValue===void 0&&(g.defaultValue=null),f.required===void 0&&(g.required=!1),g}):t?l.push("Properties must be an array"):(a.push("Properties not found or invalid, using empty array"),n.properties=[]);const m=l.length>0;return{success:!m,data:n,warnings:a.length>0?a:void 0,validationErrors:m?l:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Dr(e,r,t){if(e instanceof Date)return e;if(typeof e=="number"){const o=new Date(e);if(t&&isNaN(o.getTime()))throw new Error(`Invalid timestamp: ${e}`);return o}if(typeof e=="string"){const o=new Date(e);if(t&&isNaN(o.getTime()))throw new Error(`Invalid date string: ${e}`);return o}if(t)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"&&Number.isInteger(e))return e;if(typeof e=="string"&&e.trim()!==""){const t=parseInt(e,10);if(r&&isNaN(t))throw new Error(`Cannot convert "${e}" to integer`);return t}if(r)throw new Error(`Cannot convert ${typeof e} to integer`);return e}function Ce(e,r){if(typeof e=="number")return e;if(typeof e=="string"&&e.trim()!==""){const t=parseFloat(e);if(r&&isNaN(t))throw new Error(`Cannot convert "${e}" to number`);return t}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Or(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;if(r)throw new Error(`Cannot convert "${e}" to boolean`)}if(typeof e=="number")return!!e;if(r)throw new Error(`Cannot convert ${typeof e} to boolean`);return e}function Ue(e,r,t){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(n=>n.trim()).filter(Boolean).map(n=>r==="integer"?Se(n,t):Ce(n,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((o,n)=>{try{return r==="integer"?Se(o,t):Ce(o,t)}catch(a){if(t)throw new Error(`Array element ${n}: ${a}`);return o}})}const zr=(e,r)=>{const t=new Map;let o=null,n=null,a=0;for(const l of e){const c=l.group;if(!c){o=null,n=null;continue}if(c===o)r[l.name].group=n??c;else{if(!t.has(c))t.set(c,1),n=null,r[l.name].group=c;else{const s=t.get(c),m=`${c}(${s})`;t.set(c,s+1),n=m,r[l.name].group=m,a++}o=c}}return a},Lr=(e,r={})=>{const{includeEmpty:t=!0}=r,o=[];let n=null,a=[],l=0;for(const s of e){const m=s.group||null;m!==n?((a.length>0||t)&&(a.length===0&&l++,o.push({name:n,fields:a})),n=m,a=[s]):a.push(s)}(a.length>0||t)&&(a.length===0&&l++,o.push({name:n,fields:a}));const c=Math.max(0,...o.map(s=>s.fields.length));return{groups:o,metadata:{totalGroups:o.length,emptyGroups:l,largestGroup:c}}},xe=new Map,ue=new Map,X=new Set,je=new Map,Pr=async e=>{try{let r;switch(e.toLowerCase()){case"fr":r=(await Promise.resolve().then(()=>require("./common-DLr0UoG9.js"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-Crb-me6O.js"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-DRIndE7S.js"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-BeJOG7Z0.js"))).default;break;case"en":r={};break;default:r={}}return{success:!0,translations:r,fromCache:!1}}catch(r){return{success:!1,translations:{},error:`Failed to load common translations for ${e}: ${r}`}}},qr=async e=>{if(!e)return{success:!1,translations:{},error:"Language is required"};const r=e.toLowerCase();if(r==="en")return{success:!0,translations:{},fromCache:!1};if(xe.has(r))return{success:!0,translations:xe.get(r)||{},fromCache:!0};const t=await Pr(r);return t.success&&(xe.set(r,t.translations),je.set(r,{loadedAt:new Date,size:Object.keys(t.translations).length,source:"common"})),t},Hr=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const t=`${e.toLowerCase()}/${r}`;if(X.has(t))return{success:!1,translations:{},error:"Previously failed to load",fromCache:!0};if(ue.has(t))return{success:!0,translations:ue.get(t)||{},fromCache:!0};try{let o=r;!r.includes("/")&&!r.includes(".")&&(o=`/locales/${e}/${r}.json`);const n=await fetch(o);if(!n.ok){const m=`HTTP ${n.status}: ${n.statusText}`;return n.status===404?(ue.set(t,{}),je.set(t,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(X.add(t),{success:!1,translations:{},error:m})}const a=n.headers.get("content-type")||"";!a.includes("application/json")&&!a.includes("text/json")&&cr()&&console.warn(`Translation file at ${o} has unexpected content-type: ${a}`);const l=await n.text();if(!l){const m="Empty translation file";return X.add(t),{success:!1,translations:{},error:m}}let c;try{c=JSON.parse(l)}catch(m){const u=`Invalid JSON in translation file: ${m instanceof Error?m.message:String(m)}`;return X.add(t),{success:!1,translations:{},error:u}}if(!c||typeof c!="object"){const m="Invalid translation file format";return X.add(t),{success:!1,translations:{},error:m}}const s=Object.fromEntries(Object.entries(c).map(([m,u])=>[m,typeof u=="string"?u:String(u)]));if(!s||typeof s!="object"){const m="Invalid translation file format";return X.add(t),{success:!1,translations:{},error:m}}return ue.set(t,s),je.set(t,{loadedAt:new Date,size:Object.keys(s).length,source:"user"}),{success:!0,translations:s,fromCache:!1}}catch(o){const n=`Failed to load user translations: ${o instanceof Error?o.message:"Unknown error"}`;return X.add(t),{success:!1,translations:{},error:n}}};function cr(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function Tr(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(t,o)=>{const n=parseInt(o,10)-1,a=r[n];if(a==null)return t;try{return String(a)}catch{return t}})}const Br=(e,r,t)=>(o,...n)=>{let a=o,l=!1;return!o||typeof o!="string"?String(o||""):(e.toLowerCase()==="en"?(a=o,l=!0):Object.prototype.hasOwnProperty.call(t,o)?(a=t[o],l=!0):Object.prototype.hasOwnProperty.call(r,o)?(a=r[o],l=!0):a=o,a=Tr(a,n),!l&&cr()&&console.debug(`Missing translation for "${o}" in language "${e}"`),a)},Me={length:["m","cm","mm","km","in","ft","yd","mi"],area:["m^2","cm^2","mm^2","in^2","ft^2","yd^2"],volume:["L","m^3","cm^3","mL","in^3","ft^3","yd^3"],weight:["kg","g","mg","t","lb","oz"],time:["min","s","h","ms","d"],temperature:["C","F","K"],angle:["deg","rad","rev"]},$e={length:{m:"Meter (m)",mm:"Millimeter (mm)",cm:"Centimeter (cm)",km:"Kilometer (km)",in:"Inch (in)",ft:"Foot (ft)",yd:"Yard (yd)",mi:"Mile (mi)"},area:{"m^2":"Square meter (m^2)","mm^2":"Square millimeter (mm^2)","cm^2":"Square centimeter (cm^2)","in^2":"Square inch (in^2)","ft^2":"Square foot (ft^2)","yd^2":"Square yard (yd^2)"},volume:{L:"Liter (L)","cm^3":"Cubic centimeter (cm^3)","m^3":"Cubic meter (m^3)",mL:"Milliliter (mL)","in^3":"Cubic inch (in^3)","ft^3":"Cubic foot (ft^3)","yd^3":"Cubic yard (yd^3)"},weight:{kg:"Kilogram (kg)",g:"Gram (g)",mg:"Milligram (mg)",t:"Tonne (t)",lb:"Pound (lb)",oz:"Ounce (oz)"},time:{s:"Second (s)",min:"Minute (min)",h:"Hour (h)",ms:"Millisecond (ms)",d:"Day (d)",wk:"Week (wk)"},temperature:{C:"Celsius (C)",F:"Fahrenheit (F)",K:"Kelvin (K)"},angle:{deg:"Degree (deg)",rad:"Radian (rad)",rev:"Revolution (rev)"}},Fe={length:{mm:1e3,cm:100,m:1,km:.001,in:100/2.54,ft:100/(2.54*12),yd:100/(2.54*36),mi:1/1609.344},area:{"m^2":1,"mm^2":1e6,"cm^2":1e4,"km^2":1/1e6,"in^2":(100/2.54)**2,"ft^2":(100/(2.54*12))**2,"yd^2":(100/(2.54*36))**2},volume:{"cm^3":1e6,"m^3":1,L:1,mL:1e6,"in^3":(100/2.54)**3,"ft^3":(100/(2.54*12))**3,"yd^3":(100/(2.54*36))**3},weight:{mg:1e6,g:1e3,kg:1,t:.001,lb:1/.45359237,oz:1/.028349523125},time:{ms:1e3,s:1,min:1/60,h:1/3600,d:1/86400,wk:1/604800},temperature:{C:1,F:33.8,K:274.15},angle:{deg:1,rad:Math.PI/180,rev:1/360}},Ve={},Ur=new Set([...Object.keys(Me),...Object.keys($e),...Object.keys(Fe)]);for(const e of Ur){const r={},t=Me[e]??[],o=$e[e]??{},n=Fe[e]??{};for(const a of t){const l=o[a];r[a]={name:typeof l=="string"?l:String(a),shortName:a,factor:Object.prototype.hasOwnProperty.call(n,a)?n[a]:void 0}}for(const[a,l]of Object.entries(o))if(!r[a]){const c=typeof l=="string"?l:String(a);r[a]={name:c,shortName:a,factor:Object.prototype.hasOwnProperty.call(n,a)?n[a]:void 0}}for(const[a,l]of Object.entries(n))r[a]||(r[a]={name:String(a),shortName:String(a),factor:l});Ve[e]=r}const Wr=Object.freeze(Object.defineProperty({__proto__:null,dimensionUnitDisplayMap:$e,dimensionUnitsMap:Me,dimensonUnitFactorsMap:Fe,unitsByDimension:Ve},Symbol.toStringTag,{value:"Module"})),_r=({field:e,value:r,onChange:t,onError:o})=>{const{definitionName:n,t:a}=F(),l=i.useRef(o);i.useEffect(()=>{l.current=o},[o]),i.useEffect(()=>{const d=z(n,e,r??!1,a);l.current?.(d??null)},[r,e,n,a]);const c=d=>{const f=d.target.checked;t?.(f,null)},s=d=>{(d.key===" "||d.key==="Spacebar"||d.key==="Space"||d.key==="Enter")&&(d.preventDefault(),t?.(!r,null))},m=e.name,u=z(n,e,r??!1,a);return h.jsx(q,{field:e,rightAlign:!1,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[h.jsx("label",{className:k.label,htmlFor:m,style:{textAlign:"left",justifyContent:"flex-start"},children:a(e.displayName)}),h.jsx("input",{id:m,"data-testid":"boolean-checkbox",type:"checkbox",checked:!!r,onChange:c,onKeyDown:s,"aria-checked":!!r,"aria-invalid":!!u,"aria-describedby":u?`${e.name}-error`:void 0,style:{cursor:"pointer",margin:"8px 0 8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",color:"#FFFFFF",accentColor:"#0000FF",opacity:void 0}})]})})},We=[{label:"Black",value:"#000000"},{label:"White",value:"#ffffff"},{label:"Red",value:"#ff0000"},{label:"Green",value:"#008000"},{label:"Blue",value:"#0000ff"},{label:"Yellow",value:"#ffff00"},{label:"Cyan",value:"#00ffff"},{label:"Magenta",value:"#ff00ff"},{label:"Orange",value:"#ffa500"},{label:"Purple",value:"#800080"},{label:"Brown",value:"#a52a2a"},{label:"Gray",value:"#808080"},{label:"Light Gray",value:"#d3d3d3"},{label:"Pink",value:"#ffc0cb"}];function lr(e){return/^#([0-9A-F]{3}){1,2}$/i.test(e)}function Kr(e){if(!lr(e))return null;const r=ur(e),t=parseInt(r.slice(1),16);return{r:t>>16&255,g:t>>8&255,b:t&255}}function ur(e){return e?(e=e.toLowerCase(),/^#([a-f0-9]){3}$/i.test(e)?"#"+e.slice(1).split("").map(r=>r+r).join(""):e):"#000000"}const Jr=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),[l,c]=i.useState("#000000"),s=i.useRef(null),m=i.useRef(null),u=i.useRef(o);i.useEffect(()=>{u.current=o},[o]),i.useEffect(()=>{const x=r&&lr(r)?r:"#000000",C=ur(x);c(C)},[r]),i.useEffect(()=>{const x=z(a,e,r??"#000000",n);u.current?.(x??null)},[r,e,a,n]);const d=z(a,e,r??"#000000",n),f=x=>{const C=x.target.value;c(C),t?.(C,null)},g=x=>{const C=x.target.value;c(C),t?.(C,null)},b=We.find(x=>x.value===l),{r:p,g:y,b:S}=Kr(l)||{r:0,g:0,b:0};return h.jsx(q,{field:e,error:d,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[h.jsxs("select",{ref:s,id:e.name,value:l,onChange:f,style:{minWidth:"120px",flex:1},className:T(k.input,k.inputSelect),"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0,children:[We.map(x=>h.jsx("option",{value:x.value,children:n(x.label)},x.value)),b?null:h.jsxs("option",{value:l,children:["(",p,", ",y,", ",S,")"]},l)]}),h.jsx("label",{style:{width:"2.5em",height:"1.8em",display:"inline-block",border:"1px solid #ccc",borderRadius:"4px",backgroundColor:l,cursor:"pointer",overflow:"hidden",flexShrink:0},children:h.jsx("input",{ref:m,id:`${e.name}-color`,type:"color",value:l,onChange:g,style:{opacity:0,width:"100%",height:"100%",border:"none",padding:0,cursor:"pointer"},"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0})})]})})},se=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},Gr=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return se(e)?e:"";const t=se(e);if(t){const o=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),a=String(t.getDate()).padStart(2,"0");return`${o}-${n}-${a}`}return""},Yr=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),{name:l,required:c}=e,s=i.useRef(null),m=i.useRef(o);i.useEffect(()=>{m.current=o},[o]);const u=i.useCallback(f=>{if(!f||f.trim()==="")return c?n("Value required"):null;if(f){const b=se(f);if(!b)return n("Invalid date format");if(e.minDate){const p=se(e.minDate);if(p&&b.getTime()<p.getTime())return n("Date must be on or after {{1}}",e.minDate)}if(e.maxDate){const p=se(e.maxDate);if(p&&b.getTime()>p.getTime())return n("Date must be on or before {{1}}",e.maxDate)}}return z(a,e,f,n)??null},[e,a,n,c]),d=f=>{const g=f.target.value,b=u(g);t?.(g,b)};return i.useEffect(()=>{const f=u(r);f!==s.current&&(s.current=f,m.current?.(f??null))},[r,u]),h.jsx(q,{field:e,error:u(r),children:h.jsx("input",{id:l,type:"date",value:Gr(r),onChange:d,className:T(k.input,k.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!u(r),"aria-describedby":u(r)?`${l}-error`:void 0})})},Xr=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useRef(o);i.useEffect(()=>{c.current=o},[o]);const s=i.useCallback(u=>u===""||u===null||u===void 0?n("Value required"):!e.options||e.options.length===0?null:e.options.some(f=>f.value===u)?z(a,e,u,n)??null:n("Invalid option selected"),[e,n,a]);i.useEffect(()=>{const u=r!=null?String(r):"",d=s(u);if(d&&e.options&&e.options.length>0){const f=String(e.options[0].value);l.current&&(l.current.value=f),t?.(f,null),c.current?.(null)}else l.current&&(l.current.value=u),c.current?.(d??null)},[r,s,t,e.options]);const m=u=>{const d=u.target.value,f=s(d);t?.(d,f)};return h.jsx(q,{field:e,error:s(String(r??"")),children:h.jsx("select",{id:e.name,"aria-invalid":!!s(String(r??"")),"aria-describedby":s(String(r??""))?`${e.name}-error`:void 0,defaultValue:String(r??""),ref:l,onChange:m,className:T(k.input,k.inputSelect),children:(e.options??[]).map(u=>h.jsx("option",{value:String(u.value),children:n(u.label)},String(u.value)))})})};function Zr(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const Qr=({field:e,value:r,onChange:t,onError:o})=>{const{definitionName:n,t:a}=F(),l=i.useRef(null),c=i.useCallback(d=>{const f=d.trim();return f===""?e.required?a("Value required"):null:Zr(f)?e.pattern&&!new RegExp(e.pattern).test(f)?e.patternErrorMessage?a(e.patternErrorMessage):a("Email does not match pattern: {{1}}",e.pattern):z(n,e,d,a)??null:a("Must be valid email format")},[e,n,a]),s=d=>{const f=d.target.value,g=c(f);t?.(f,g)},m=i.useRef(null),u=i.useRef(o);return i.useEffect(()=>{u.current=o},[o]),i.useEffect(()=>{const d=r??"",f=c(d);l.current&&l.current.value!==String(d)&&(l.current.value=String(d)),f!==m.current&&(m.current=f,u.current?.(f??null))},[r,c]),h.jsx(q,{field:e,error:c(String(r??"")),children:h.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:l,onChange:s,className:T(k.input,k.textInput),"aria-invalid":!!c(String(r??"")),"aria-describedby":c(String(r??""))?`${e.name}-error`:void 0})})},et=({field:e})=>{const{darkMode:r}=F(),{color:t=r?"#444444":"#CCCCCC",thickness:o=1,margin:n="8px 0"}=e;return h.jsx("div",{style:{width:"auto",height:"0",borderTop:`${o}px solid ${t}`,margin:n}})},rt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),[l,c]=i.useState(!1),s=i.useRef(null),m=i.useRef(o);i.useEffect(()=>{m.current=o},[o]);const u=i.useCallback(x=>e.required&&(!x||Array.isArray(x)&&x.length===0)?n("Value required"):z(a,e,x,n)??null,[e,a,n]),d=i.useMemo(()=>u(r),[r,u]);i.useEffect(()=>{const x=u(r);t?.(r,x),m.current?.(x??null)},[r,u]);const f=x=>{const C=x.target.files;let N=null;if(C&&C.length>0){const v=Array.from(C);e.multiple?N=[...Array.isArray(r)?r:[],...v]:N=v[0]}const w=u(N);t?.(N,w)},g=x=>{x.preventDefault(),x.stopPropagation(),c(!1);const C=x.dataTransfer.files;if(C&&C.length>0){const N=Array.from(C);let w=null;e.multiple?w=[...Array.isArray(r)?r:[],...N]:w=N[0];const v=u(w);t?.(w,v)}},b=x=>{x.preventDefault(),x.stopPropagation(),c(!0)},p=x=>{x.preventDefault(),x.stopPropagation(),c(!1)},y=x=>{if(Array.isArray(r)&&typeof x=="number"){const C=r.filter((v,j)=>j!==x),N=C.length>0?C:null,w=u(N);t?.(N,w)}else{const C=u(null);t?.(null,C)}},S=()=>{const x=Array.isArray(r)?r:r?[r]:[];return x.length===0?null:h.jsx("div",{style:{marginTop:"8px",display:"flex",flexDirection:"column",gap:"6px"},children:x.map((C,N)=>h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 10px",backgroundColor:"var(--reactaform-input-bg, #fff)",border:"1px solid var(--reactaform-border-color, #d1d5db)",borderRadius:"4px",fontSize:"0.875rem",gap:"8px"},children:[h.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.name}),h.jsx("button",{type:"button",onClick:()=>y(Array.isArray(r)?N:void 0),"aria-label":n("Remove file"),style:{background:"transparent",border:"none",color:"var(--reactaform-color-error, #ef4444)",cursor:"pointer",padding:"2px 6px",fontSize:"1.125rem",lineHeight:1,borderRadius:"4px",transition:"background-color 0.2s",flexShrink:0},onMouseEnter:w=>{w.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:w=>{w.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${C.name}-${N}`))})};return h.jsx(q,{field:e,error:d,children:h.jsxs("div",{style:{width:"100%"},children:[h.jsxs("div",{onDrop:g,onDragOver:b,onDragLeave:p,style:{position:"relative",border:`1px dashed ${l?"var(--reactaform-color-primary, #2563eb)":d?"var(--reactaform-color-error, #ef4444)":"var(--reactaform-border-color, #d1d5db)"}`,borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:l?"var(--reactaform-bg-hover, #f0f9ff)":"var(--reactaform-input-bg, #fff)",transition:"all 0.2s ease",cursor:"pointer",minHeight:"var(--reactaform-input-height, 34px)",width:"100%",maxWidth:"100%",alignSelf:"stretch",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},onClick:()=>s.current?.click(),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),s.current?.click())},role:"button","aria-label":e.multiple?n("Choose Files or Drag & Drop"):n("Choose File or Drag & Drop"),"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0,children:[h.jsx("input",{id:e.name,ref:s,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:f}),h.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),h.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:l?n("Drop files here"):e.multiple?n("Choose Files or Drag & Drop"):n("Choose File or Drag & Drop")}),e.accept&&h.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:l?0:1,transition:"opacity 0.15s ease",pointerEvents:l?"none":"auto"},children:e.accept})]}),S()]})})},tt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function nt(e){return e.split(",").map(r=>r.trim()).every(r=>tt.test(r))}const ot=e=>!e||e.trim()===""?[]:e.split(",").map(r=>r.trim()).filter(Boolean).map(Number),at=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),[l,c]=i.useState(Array.isArray(r)?r.join(", "):String(r??"")),s=i.useCallback(f=>{if(f.trim()==="")return e.required?n("Value required"):null;if(!nt(f))return n("Each value must be a valid float");const g=ot(f);if(e.minCount!==void 0&&g.length<e.minCount)return n("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&g.length>e.maxCount)return n("Maximum number of values: {{1}}",e.maxCount);for(const p of g){if(e.min!==void 0&&(e.minInclusive?p<e.min:p<=e.min))return n("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?p>e.max:p>=e.max))return n("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return z(a,e,g,n)??null},[a,e,n]),m=f=>{const g=f.target.value,b=s(g);c(g),t?.(g,b)},u=i.useRef(null),d=i.useRef(o);return i.useEffect(()=>{d.current=o},[o]),i.useEffect(()=>{const f=Array.isArray(r)?r.join(", "):String(r??""),g=s(f);g!==u.current&&(u.current=g,d.current?.(g??null))},[r,e.required,s,n]),h.jsx(q,{field:e,error:s(l),children:h.jsx("input",{id:e.name,type:"text",value:l,onChange:m,className:T(k.input,k.textInput),style:{flex:1},"aria-invalid":!!s(l),"aria-describedby":s(l)?`${e.name}-error`:void 0})})},st=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useCallback(f=>{if(f.trim()==="")return e.required?n("Value required"):null;const g=Number.parseFloat(f);return Number.isNaN(g)?n("Must be a valid float"):e.min!==void 0&&(e.minInclusive?g<e.min:g<=e.min)?n("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min):e.max!==void 0&&(e.maxInclusive?g>e.max:g>=e.max)?n("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max):z(a,e,g,n)??null},[e,a,n]),s=i.useRef(null),m=i.useRef(o);i.useEffect(()=>{m.current=o},[o]),i.useEffect(()=>{const f=String(r??""),g=c(f);g!==s.current&&(s.current=g,m.current?.(g??null)),l.current&&document.activeElement!==l.current&&(l.current.value=f)},[r,e,c,n]);const u=f=>{const g=f.target.value,b=c(g);t?.(g,b)},d=i.useMemo(()=>c(String(r??"")),[r,c]);return h.jsx(q,{field:e,error:d,children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:l,onChange:u,className:T(k.input,k.inputNumber),"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0})})};function it(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const ct=({field:e,value:r})=>{const{language:t,t:o}=F(),n=e.alignment||"center",a={left:"flex-start",center:"center",right:"flex-end"},l=typeof r=="string"?r:"";let c=l&&l.trim()!==""?l:typeof e.defaultValue=="string"?e.defaultValue:"";c&&!c.startsWith("/")&&(c=`${it()}${c}`);const s=e.localized?.split(";").map(y=>y.trim()),[m,u]=i.useState(c||""),d=i.useRef(c||null);if(i.useEffect(()=>{if(!c)return;const y=c.split("/"),S=y.pop(),x=S.lastIndexOf(".");if(x===-1)return;const C=S.substring(0,x),N=S.substring(x);let w=null;s?.includes(t)&&(w=`${C}_${t}${N}`);const v=new AbortController;if(w){const j=[...y,w].join("/");fetch(j,{method:"HEAD",signal:v.signal}).then($=>{const R=$.ok?j:c;R!==d.current&&(d.current=R,u(R))}).catch(()=>{c!==d.current&&(d.current=c,u(c))})}else{const j=c;j!==d.current&&(d.current=j,requestAnimationFrame(()=>u(j)))}return()=>{v.abort()}},[c,t,s]),!m)return null;const{width:f,height:g}=e,b={},p={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return f&&g?(b.width=f,b.height=g,p.width=`${f}px`,p.height=`${g}px`):f&&!g?(b.width=f,p.width=`${f}px`,p.height="auto"):!f&&g&&(b.height=g,p.width="auto",p.height=`${g}px`),h.jsx(q,{field:e,children:h.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:a[n]||"center",margin:"0 0"},children:h.jsx("img",{src:m,alt:o?.(e.displayName||"Image")||e.displayName||"Image",...b,style:p})})})};function lt(e){const r=/^-?\d+$/;return e.split(",").map(t=>t.trim()).every(t=>r.test(t))}const ut=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=",",[c,s]=i.useState(Array.isArray(r)?r.join(l+" "):String(r??"")),m=p=>!p||p.trim()===""?[]:p.split(l).map(y=>y.trim()).filter(Boolean).map(y=>Number(y)),u=i.useCallback(p=>{if(p.trim()==="")return e.required?n("Value required"):null;if(!lt(p))return n("Each value must be a valid integer");const y=m(p);if(e.minCount!==void 0&&y.length<e.minCount)return n("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&y.length>e.maxCount)return n("Maximum number of values: {{1}}",`${e.maxCount}`);for(const x of y){if(e.min!==void 0&&(e.minInclusive?x<e.min:x<=e.min))return n("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?x>e.max:x>=e.max))return n("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return z(a,e,y,n)??null},[a,e,n]),d=p=>{const y=p.target.value,S=u(y);s(y),t?.(y,S)},f=i.useRef(null),g=i.useRef(o);i.useEffect(()=>{g.current=o},[o]),i.useEffect(()=>{const p=Array.isArray(r)?r.join(l+" "):String(r??""),y=u(p);y!==f.current&&(f.current=y,g.current?.(y??null))},[r,e.required,u,n]);const b=u(c);return h.jsx(q,{field:e,error:b,children:h.jsx("input",{id:e.name,type:"text",value:c,onChange:d,className:T(k.input,k.textInput),style:{flex:1},"aria-invalid":!!b,"aria-describedby":b?`${e.name}-error`:void 0})})};function ft(e){return/^[-+]?\d*$/.test(e)}const mt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useCallback(f=>{if(f.trim()==="")return e.required?n("Value required"):null;if(!ft(f))return n("Must be a valid integer");const g=parseInt(f,10);if(Number.isNaN(g))return n("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?g<e.min:g<=e.min))return n("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?g>e.max:g>=e.max))return n("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const p=Number(e.step);if(!Number.isInteger(p))return n("Invalid step value");if(g%p!==0)return n("Must be a multiple of {{1}}",p)}return z(a,e,g,n)??null},[e,a,n]),s=i.useRef(null),m=i.useRef(o);i.useEffect(()=>{m.current=o},[o]),i.useEffect(()=>{const f=String(r??""),g=c(f);g!==s.current&&(s.current=g,m.current?.(g??null)),l.current&&document.activeElement!==l.current&&(l.current.value=f)},[r,e,c,n]);const u=f=>{const g=f.target.value,b=c(g);t?.(g,b)},d=i.useMemo(()=>c(String(r??"")),[r,c]);return h.jsx(q,{field:e,error:d,children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:l,onChange:u,className:T(k.input,k.inputNumber),"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0})})},dt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=e.minHeight??"80px",c=i.useRef(null),s=i.useRef(null),m=i.useRef(o);i.useEffect(()=>{m.current=o},[o]);const u=i.useCallback(b=>b.trim()===""?e.required?n("Value required"):null:e.minLength!==void 0&&b.length<e.minLength?n("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&b.length>e.maxLength?n("Must be at most {{1}} characters",e.maxLength):z(a,e,b,n),[e,a,n]),d=b=>{const p=b.target.value,y=u(p);t?.(p,y)};i.useEffect(()=>{const b=u(r);b!==s.current&&(s.current=b,m.current?.(b??null)),c.current&&c.current.value!==String(r??"")&&(c.current.value=String(r??""))},[r,u]);const f={id:e.name,defaultValue:String(r??""),ref:c,onChange:d,style:{resize:"vertical",minHeight:l,width:"100%",boxSizing:"border-box"},className:T(k.input,k.textInput)},g=u(r);return h.jsx(q,{field:e,error:g,children:h.jsx("textarea",{...f,"aria-invalid":!!g,"aria-describedby":g?`${e.name}-error`:void 0})})},pt=({field:e,value:r,onChange:t,onError:o})=>{const n=i.useRef(o);i.useEffect(()=>{n.current=o},[o]);const{t:a,darkMode:l,formStyle:c,fieldStyle:s,definitionName:m}=F(),u=(R,E,I)=>{if(!E)return{};const H=R?.[E];return(I&&H?H[I]:void 0)??{}},d=i.useRef(null),[f,g]=i.useState(!1),[b,p]=i.useState(null),y=i.useMemo(()=>e.options.map(R=>({value:R.value,label:a(R.label)})),[e.options,a]),S=i.useMemo(()=>{const R=Array.isArray(r)?r:[],E=new Set(y.map(I=>I.value));return R.filter(I=>E.has(I))},[r,y]),x=R=>{const E=Array.isArray(R)?R:[];return e.required&&E.length===0?a("Value required"):z(m,e,E,a)??null},C=()=>{if(!d.current)return;const R=d.current.getBoundingClientRect();p({x:R.left,y:R.bottom}),g(E=>!E)},N=R=>{const E=S.includes(R)?S.filter(D=>D!==R):[...S,R],I=x(E);n.current?.(I??null),t?.(E,I)},w=i.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",padding:"var(--reactaform-input-padding, 8px)",display:"flex",alignItems:"center",boxSizing:"border-box",cursor:"pointer",position:"relative",borderRadius:"var(--reactaform-border-radius, 4px)",border:"1px solid var(--reactaform-border-color, #ccc)",background:"var(--reactaform-secondary-bg, #fff)",color:"var(--reactaform-text-color, #000)",...u(c,"multiSelect","control"),...u(s,void 0,"control")}),[c,s]),v=i.useMemo(()=>({position:"absolute",right:"1.5em",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",padding:0,...u(c,"multiSelect","clearButton"),...u(s,void 0,"clearButton")}),[c,s]),j=i.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...u(c,"multiSelect","arrow"),...u(s,void 0,"arrow")}),[c,s]),$=x(Array.isArray(r)?r:[]);return h.jsxs("div",{children:[h.jsx(q,{field:e,error:null,children:h.jsx("div",{style:{width:"100%"},children:h.jsxs("div",{ref:d,className:"reactaform-multiselection-control",style:w,onClick:C,tabIndex:0,role:"button","aria-haspopup":"listbox","aria-expanded":f,"aria-invalid":!!$,"aria-describedby":$?`${e.name}-error`:void 0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),C())},children:[h.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[S.length," / ",y.length," selected"]}),S.length>0&&h.jsx("button",{type:"button","aria-label":"Clear selections",onClick:R=>{R.stopPropagation(),t?.([],null)},style:v,children:h.jsx("span",{style:v,"aria-hidden":!0,children:"✖"})}),h.jsx("span",{style:j,"aria-hidden":!0,children:"▼"})]})})}),f&&b&&h.jsx(gt,{position:b,options:y,selectedValues:S,onToggleOption:N,onClose:()=>g(!1),controlRef:d,darkMode:l})]})},gt=({position:e,options:r,selectedValues:t,onToggleOption:o,onClose:n,controlRef:a,darkMode:l})=>{const c=i.useRef(null),[s,m]=i.useState(-1),{formStyle:u,fieldStyle:d}=F(),f=(v,j,$)=>{if(!j)return{};const E=v?.[j];return($&&E?E[$]:void 0)??{}},g=i.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...f(u,"multiSelect","popup"),...f(d,void 0,"popup")}),[u,d]),b=i.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...f(u,"multiSelect","option"),...f(d,void 0,"option")}),[u,d]);i.useEffect(()=>{const v=j=>{const $=j.target;!c.current?.contains($)&&!a.current?.contains($)&&n()};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[n,a]),i.useEffect(()=>{c.current&&r.length>0&&requestAnimationFrame(()=>m(v=>v===-1?0:v))},[r.length]),i.useEffect(()=>{if(!c.current||s<0)return;const v=c.current.querySelector(`#multi-opt-${s}`);v&&requestAnimationFrame(()=>v.focus())},[s]);const p=250,y=200,[S,x]=i.useState(null),[C,N]=i.useState(null);if(i.useEffect(()=>{if(typeof window>"u")return;const v=()=>{let R=e.x,E=e.y,I=p;const D=a?.current;if(D){const H=D.getBoundingClientRect();R=H.left,E=H.bottom,I=Math.max(80,Math.round(H.width))}R=Math.min(R,window.innerWidth-I),E=Math.min(E,window.innerHeight-y),x({left:R,top:E}),N(I)};v(),window.addEventListener("scroll",v,!0),window.addEventListener("resize",v);let j=null;const $=a?.current;return typeof ResizeObserver<"u"&&$&&(j=new ResizeObserver(()=>v()),j.observe($)),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v),j&&$&&j.unobserve($)}},[a,e.x,e.y]),typeof window>"u")return null;let w=document.getElementById("popup-root");return w||(w=document.createElement("div"),w.id="popup-root",document.body.appendChild(w)),ke.createPortal(h.jsx("div",{ref:c,role:"listbox","aria-activedescendant":s>=0?`multi-opt-${s}`:void 0,style:{position:"absolute",top:S?S.top:e.y,left:S?S.left:e.x,width:C??p,...g},"data-reactaform-theme":l?"dark":"light",children:r.map((v,j)=>{const $=t.includes(v.value),R=l?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",E={...b,background:j===s?R:b.background};return h.jsxs("div",{id:`multi-opt-${j}`,onMouseDown:I=>{I.stopPropagation(),o(v.value)},onKeyDown:I=>{const D=r.length;switch(I.key){case"ArrowDown":I.preventDefault(),m(H=>(H+1)%D);break;case"ArrowUp":I.preventDefault(),m(H=>(H-1+D)%D);break;case"Home":I.preventDefault(),m(0);break;case"End":I.preventDefault(),m(D-1);break;case"Enter":case" ":I.preventDefault(),I.stopPropagation(),o(v.value);break;case"Escape":I.preventDefault(),n(),a?.current?.focus();break}},tabIndex:j===s?0:-1,role:"option","aria-selected":$,style:E,onMouseEnter:I=>{I.currentTarget.style.background=R,m(j)},onMouseLeave:I=>{I.currentTarget.style.background="transparent",m(D=>D===j?-1:D)},children:[h.jsx("input",{type:"checkbox",checked:$,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:l?"#10b981":"#22c55e",cursor:"pointer"}}),v.label]},v.value)})}),w)},ht=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=e.min??void 0,s=e.max??void 0,m=Math.max(1,Math.round(e.step??1)),u=i.useCallback(y=>isNaN(y)?n("Must be a valid integer"):Number.isInteger(y)?c!==void 0&&y<c?n("Must be ≥ {{1}}",c):s!==void 0&&y>s?n("Must be ≤ {{1}}",s):z(a,e,y,n)??null:n("Must be an integer"),[a,e,n,c,s]),d=i.useRef(null),f=i.useRef(o);i.useEffect(()=>{f.current=o},[o]),i.useEffect(()=>{if(document.activeElement===l.current)return;const S=String(r),x=u(r);l.current&&(l.current.value=S),x!==d.current&&(d.current=x,f.current?.(x??null))},[r,u]);const g=y=>{if(y.trim()==="")return e.required?n("Value required"):null;const x=Number(y);return u(x)},b=y=>{const S=y.target.value,x=y.target.valueAsNumber,C=g(S);t?.(x,C)},p=g(String(r??""));return h.jsx(q,{field:e,error:p,children:h.jsx("input",{ref:l,id:e.name,type:"number",defaultValue:String(r??""),min:c,max:s,step:m,onChange:b,style:{width:"100%",height:"100%"},className:k.input,"aria-invalid":!!p,"aria-describedby":p?`${e.name}-error`:void 0})})},bt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n}=F(),a=i.useRef(null),{definitionName:l}=F(),c=i.useCallback(d=>{const f=String(d??"").trim();if(f==="")return e.required?n("Value required"):null;if(e.pattern)try{if(!new RegExp(e.pattern).test(f))return e.patternErrorMessage?n(e.patternErrorMessage):n("Phone number does not match pattern: {{1}}",`${e.pattern}`)}catch{}return z(l,e,f,n)},[l,e,n]),s=i.useRef(null),m=i.useRef(o);i.useEffect(()=>{m.current=o},[o]),i.useEffect(()=>{const d=String(r??""),f=c(d);a.current&&a.current.value!==String(d)&&(a.current.value=String(d)),f!==s.current&&(s.current=f,m.current?.(f??null))},[r,c]);const u=d=>{const f=d.target.value,g=f.trim();let b=null;if(g===""){b=e.required?n("Value required"):null,t?.(f,b);return}b||(b=c(f)),t?.(f,b)};return h.jsx(q,{field:e,error:c(String(r??"")),children:h.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:a,onChange:u,className:T(k.input,k.textInput),"aria-invalid":!!c(String(r??"")),"aria-describedby":c(String(r??""))?`${e.name}-error`:void 0})})},yt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=e.layout?.toLowerCase()==="horizontal"?"row":"column",c=i.useRef(null),s=i.useRef(o);i.useEffect(()=>{s.current=o},[o]);const m=i.useCallback(d=>d===""||d===null||d===void 0?n("Value required"):!e.options||e.options.length===0?null:e.options.some(g=>g.value===d)?z(a,e,d,n)??null:n("Invalid option selected"),[e,n,a]);i.useEffect(()=>{const d=r!=null?String(r):"",f=m(d);if(s.current?.(f??null),c.current){const g=Array.from(c.current.querySelectorAll("input[type=radio]"));if(f&&e.options&&e.options.length>0){const b=String(e.options[0].value);g.forEach(p=>p.checked=p.value===b),t?.(b,null)}else g.forEach(b=>b.checked=b.value===d)}},[r,m,t,e.options]);const u=d=>{const f=d.target.value,g=m(f);s.current?.(g??null),t?.(f,g)};return h.jsx(q,{field:e,error:m(String(r??"")),children:h.jsx("div",{className:k.input,role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!m(String(r??"")),style:{display:"flex",flexDirection:l,flexWrap:l==="row"?"wrap":"nowrap",gap:l==="row"?"12px":"4px",alignItems:l==="row"?"center":"stretch",width:"100%",padding:l==="row"?"8px":void 0,boxSizing:"border-box"},ref:c,children:(e.options??[]).map(d=>h.jsxs("label",{className:T(k.label),style:{display:l==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:l==="column"?6:0,cursor:"pointer",width:l==="column"?"100%":void 0,justifyContent:"flex-start"},children:[h.jsx("input",{type:"radio",name:e.name,value:String(d.value),defaultChecked:String(r??"")===String(d.value),onChange:u,style:{width:"1.1em",height:"1.1em"}}),h.jsx("span",{style:{userSelect:"none",textAlign:l==="column"?"left":void 0,flex:l==="column"?1:void 0,fontWeight:400},children:n(d.label)})]},String(d.value)))})})},xt={display:"flex",gap:4},vt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},wt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),[l,c]=i.useState(null),s=i.useRef([]),m=e.max||5,u=i.useCallback(p=>e.required&&p===0?n("Value required"):z(a,e,p,n)??null,[e,n,a]),d=i.useRef(null),f=i.useRef(o);i.useEffect(()=>{f.current=o},[o]),i.useEffect(()=>{let p=r||0;r<0&&(p=0),r>m&&(p=m);const y=u(p);y!==d.current&&(d.current=y,f.current?.(y??null))},[r,u,m]);const g=p=>{const y=u(p);t?.(p,y)},b=(()=>{let p=r||0;return p<0&&(p=0),p>m&&(p=m),p})();return h.jsx(q,{field:e,error:u(b),children:h.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,style:xt,"aria-invalid":!!u(b),"aria-describedby":u(b)?`${e.name}-error`:void 0,children:(()=>{const p=e.icon,y=p&&String(p).trim()?String(p):"★";return[...Array(m)].map((S,x)=>{const C=x<b,w=l!==null&&x<=l||C?"gold":"lightgray";return h.jsx("span",{ref:v=>s.current[x]=v,role:"radio",tabIndex:b>0?x===b-1?0:-1:x===0?0:-1,"aria-checked":C,onClick:()=>g(x+1),onKeyDown:v=>{if(v.key==="Enter"||v.key===" ")v.preventDefault(),g(x+1);else if(v.key==="ArrowRight"||v.key==="ArrowUp"){v.preventDefault();const j=Math.min(m-1,x+1);s.current[j]?.focus()}else if(v.key==="ArrowLeft"||v.key==="ArrowDown"){v.preventDefault();const j=Math.max(0,x-1);s.current[j]?.focus()}},onMouseEnter:()=>c(x),onMouseLeave:()=>c(null),style:{...vt,color:w},"aria-label":`Rating ${x+1}`,title:n(`${e.displayName} ${x+1}`),children:y},x)})})()})})},St=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useRef(null),s=i.useRef(o);i.useEffect(()=>{s.current=o},[o]);const m=i.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),u=i.useCallback(p=>p===""?e.required?n("Value required"):null:e.minLength!==void 0&&p.length<e.minLength?n("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&p.length>e.maxLength?n("Must be at most {{1}} characters",e.maxLength):m&&!m.test(p)?e.patternErrorMessage?n(e.patternErrorMessage):n("Input does not match pattern: {{1}}",e.pattern):z(a,e,p,n),[e,a,n,m]),d=p=>{const y=p.target.value,S=u(y);t?.(y,S)};i.useEffect(()=>{const p=u(r??"");l.current&&l.current.value!==String(r??"")&&(l.current.value=String(r??"")),p!==c.current&&(c.current=p,s.current?.(p??null))},[r,u]);const[f,g]=i.useState(!1),b=()=>g(p=>!p);return h.jsx(q,{field:e,error:u(String(r??"")),children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[h.jsx("input",{id:e.name,type:f?"text":"password",defaultValue:String(r??""),ref:l,onChange:d,className:T(k.input,k.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!u(String(r??"")),"aria-describedby":u(String(r??""))?`${e.name}-error`:void 0}),h.jsx("button",{type:"button",onClick:b,"aria-label":n(f?"Hide password":"Show password"),style:{background:"transparent",border:"none",cursor:"pointer",fontSize:16,lineHeight:1,padding:"4px 6px",flexShrink:0},children:f?"🙈":"👁️"})]})})},Ct=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function jt(e){return Ct.test(e)}const Rt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useRef(null),s=i.useCallback(b=>{let p=null;if(b.trim()==="")return n("Value required");if(!jt(b))return n("Invalid number");const y=Number(b);return typeof e.min=="number"&&y<e.min?n("Value should be at least {{1}}",e.min):typeof e.max=="number"&&y>e.max?n("Value should be at most {{1}}",e.max):(p||(p=z(a,e,y,n)),p)},[a,e,n]),m=i.useRef(null),u=i.useRef(o);i.useEffect(()=>{u.current=o},[o]),i.useEffect(()=>{const b=String(r),p=s(b);c.current&&document.activeElement!==c.current&&(c.current.value=isNaN(Number(b))?String(e.min??0):String(Number(b))),l.current&&document.activeElement!==l.current&&(l.current.value=b),p!==m.current&&(m.current=p,u.current?.(p??null))},[r,s,e.min]);const d=e.min??0,f=e.max??100,g=b=>{const p=b.target.value,y=s(p);t?.(p,y)};return h.jsx(q,{field:e,error:s(String(r??"")),children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[h.jsx("input",{ref:c,id:`${e.name}-range`,type:"range",defaultValue:isNaN(Number(r))?String(d):String(Number(r)),onChange:g,min:d,max:f,style:{padding:0,flex:1},className:k.rangeInput,"aria-invalid":!!s(String(r??"")),"aria-describedby":s(String(r??""))?`${e.name}-error`:void 0}),h.jsx("input",{id:e.name,ref:l,type:"text",defaultValue:String(r??""),onChange:g,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:T(k.input,k.textInput),"aria-invalid":!!s(String(r??"")),"aria-describedby":s(String(r??""))?`${e.name}-error`:void 0})]})})},kt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,formStyle:a,fieldStyle:l,definitionName:c}=F(),s=a,m=l,u=(w,v,j)=>{if(!v)return{};const $=w?.[v];return(j&&$?$[j]:void 0)??{}},d=i.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...u(s,"switch","label"),...u(m,void 0,"label")}),[s,m]),f=i.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...u(s,"switch","hiddenInput"),...u(m,void 0,"hiddenInput")}),[s,m]),g=i.useMemo(()=>({position:"absolute",cursor:"pointer",top:0,left:0,right:0,bottom:0,backgroundColor:"var(--reactaform-switch-off-bg, #ccc)",transition:"0.3s",borderRadius:24,borderWidth:2,borderStyle:"solid",borderColor:"transparent",...u(s,"switch","slider"),...u(m,void 0,"slider")}),[s,m]),b=i.useMemo(()=>({position:"absolute",height:16,width:16,left:2,bottom:2,backgroundColor:"white",transition:"0.3s",borderRadius:"50%",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.3)",...u(s,"switch","knob"),...u(m,void 0,"knob")}),[s,m]),p=!!r,y=i.useRef(null),S=i.useRef(o),x=i.useCallback(w=>w?z(c,e,w,n)??null:e.required?n("Value required"):null,[e,n,c]),C=()=>{const w=!p,v=x(w);t?.(w,v)};i.useEffect(()=>{S.current=o},[o]),i.useEffect(()=>{const w=x(p);w!==y.current&&(y.current=w,S.current?.(w??null))},[p,e,x]);const N=e.name;return h.jsx(q,{field:e,error:x(p),rightAlign:!1,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[h.jsx("label",{className:k.label,htmlFor:N,style:{textAlign:"left",justifyContent:"flex-start"},children:n(e.displayName)}),h.jsxs("label",{style:d,children:[h.jsx("input",{id:e.name,type:"checkbox",checked:p,readOnly:!0,"aria-label":n(e.displayName),"aria-invalid":!!x(p),"aria-describedby":x(p)?`${e.name}-error`:void 0,style:f,tabIndex:-1}),h.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":p,"aria-invalid":!!x(p),"aria-describedby":x(p)?`${e.name}-error`:void 0,onClick:C,onKeyDown:w=>{(w.key===" "||w.key==="Spacebar"||w.key==="Space"||w.key==="Enter")&&(w.preventDefault(),C())},className:`reactaform-switch ${p?"active checked on":""} `,style:p?{...g,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:g,children:h.jsx("span",{style:{...b,transform:p?"translateX(20px)":void 0}})})]})]})})},_e=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useRef(null),s=i.useRef(o);i.useEffect(()=>{s.current=o},[o]);const m=i.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),u=i.useCallback(f=>f.trim()===""?e.required?n("Value required"):null:e.minLength!==void 0&&f.length<e.minLength?n("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&f.length>e.maxLength?n("Must be at most {{1}} characters",e.maxLength):m&&!m.test(f)?e.patternErrorMessage?n(e.patternErrorMessage):n("Input does not match pattern: {{1}}",e.pattern):z(a,e,f,n),[e,a,n,m]),d=f=>{const g=f.target.value,b=u(g);t?.(g,b)};return i.useEffect(()=>{const f=u(r);l.current&&l.current.value!==String(r??"")&&(l.current.value=String(r??"")),f!==c.current&&(c.current=f,s.current?.(f??null))},[r,u]),h.jsx(q,{field:e,error:u(String(r??"")),children:h.jsx("input",{id:e.name,"aria-invalid":!!u(String(r??"")),"aria-describedby":u(String(r??""))?`${e.name}-error`:void 0,type:"text",defaultValue:String(r??""),ref:l,onChange:d,className:T(k.input,k.textInput)})})},Et=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useRef(o),s=e.includeSeconds??!0;i.useEffect(()=>{c.current=o},[o]);const m=i.useCallback(d=>{if(!d||d.trim()==="")return e.required||e.min||e.max?n("Value required"):null;const f=p=>{const y=p.split(":").map(x=>parseInt(x,10));if(y.some(x=>Number.isNaN(x)))return NaN;let S=0;if(y.length===3)S=y[0]*3600+y[1]*60+y[2];else if(y.length===2)S=y[0]*3600+y[1]*60;else if(y.length===1)S=y[0]*3600;else return NaN;return S},g=f(d);if(Number.isNaN(g))return n("Invalid time format");if(e.min&&typeof e.min=="string"){const p=f(e.min);if(!Number.isNaN(p)&&g<p)return n("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const p=f(e.max);if(!Number.isNaN(p)&&g>p)return n("Time must be on or before {{1}}",e.max)}return z(a,e,d,n)??null},[e,a,n]),u=d=>{const f=d.target.value,g=m(f);t?.(f,g)};return i.useEffect(()=>{const d=m(r);d!==l.current&&(l.current=d,c.current?.(d??null))},[r,m]),h.jsx(q,{field:e,error:m(r),children:h.jsx("input",{id:e.name,type:"time",value:r,step:s?1:60,onChange:u,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:T(k.input,k.textInput),"aria-invalid":!!m(r),"aria-describedby":m(r)?`${e.name}-error`:void 0})})};function Nt({pos:e,options:r,onClose:t,onClickOption:o}){const n=i.useRef(null),a=i.useRef(!1),l=typeof window<"u"?document.getElementById("popup-root")||document.body:null;if(i.useEffect(()=>{function g(b){a.current||b.target.dataset?.popupMenu==="item"||n.current&&b.target instanceof Node&&!n.current.contains(b.target)&&t()}return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[t]),!l||r===void 0||r.length===0||!e||e.x==null||e.y==null)return null;const c=e.x,s=e.y,m=typeof window<"u"?window.innerWidth:1024,u=Math.max(0,m-160),d=Math.max(0,Math.min(c,u)),f=Math.max(0,s);return ke.createPortal(h.jsx("div",{ref:n,onMouseDown:g=>{g.stopPropagation()},style:{position:"fixed",top:f,left:d,backgroundColor:"var(--reactaform-primary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:"var(--reactaform-border-radius, 4px)",boxShadow:"var(--reactaform-shadow, 0 2px 10px rgba(0,0,0,0.2))",zIndex:9999,minWidth:"var(--reactaform-menu-min-width, 150px)",pointerEvents:"auto"},children:r.map((g,b)=>h.jsx("div",{"data-popup-menu":"item",onMouseDown:p=>{p.stopPropagation(),a.current=!0},onClick:p=>{p.stopPropagation(),p.preventDefault(),o(g),t(),setTimeout(()=>{a.current=!1},100)},style:{padding:"var(--reactaform-menu-item-padding, 8px 12px)",cursor:"pointer",fontSize:"var(--reactaform-menu-item-font-size, 0.8em)",borderBottom:b<r.length-1?"1px solid var(--reactaform-border-light, #eee)":void 0,transition:"background-color 0.15s ease"},onMouseEnter:p=>{p.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:p=>{p.currentTarget.style.backgroundColor="transparent"},children:g.label},g.label??b))}),l)}const ie={};function It(e,r){if(e in ie)return;const t=Ve[e]??{},o={},n={},a={};for(const[c,s]of Object.entries(t))typeof s.factor=="number"&&(o[c]=s.factor),n[c]=r(c),a[r(c)]=c;const l=Object.keys(t)[0]??"";ie[e]={default:l,factors:o,labels:n,reverseLabels:a}}function Mt(e,r,t){if(e==="C"){if(r==="F")return t*(9/5)+32;if(r==="K")return t+273.15}else if(e==="F"){if(r==="C")return(t-32)*5/9;if(r==="K")return(t-32)*5/9+273.15}else if(e==="K"){if(r==="C")return t-273.15;if(r==="F")return(t-273.15)*9/5+32}return t}function $t(e,r,t){if(!Number.isFinite(e))return[];if(t===ie.temperature)return Object.keys(t.labels).map(a=>{const l=Mt(r,a,e);return Number.isFinite(l)?{label:`${l.toFixed(6)} ${a}`,value:l.toString(),unit:a}:{label:`${String(l)} ${a}`,value:String(l),unit:a}});const n=t.factors[r];return n===void 0?[]:Object.entries(t.factors).map(([a,l])=>{const c=e/n*l;return Number.isFinite(c)?{label:`${c.toFixed(6)} ${a}`,value:c.toString(),unit:a}:{label:`${String(c)} ${a}`,value:String(c),unit:a}})}function fe(e,r){return e in r.labels?e:r.reverseLabels&&r.reverseLabels[e]?r.reverseLabels[e]:null}const Ft=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,Vt=({unitFactors:e,field:r,value:t,onChange:o,onError:n})=>{const{t:a,definitionName:l}=F(),c=i.useRef(null),s=i.useRef(null),m=i.useRef(null),[u,d]=i.useState(null),[f,g]=i.useState(null),[b,p]=i.useState(!1),[y,S]=i.useState(null),[x,C]=i.useState([]),N=i.useCallback((A,M)=>{if(!A||A.trim()==="")return r.required?a("Value required"):null;if(!Ft.test(A))return a("Must be a valid number");const O=z(l,r,[A,M],a);return O||null},[l,r,a]),w=e.reverseLabels!==void 0?e.reverseLabels:Object.fromEntries(Object.entries(e.labels).map(([A,M])=>[M,A]));i.useEffect(()=>{const A=String(t[0]);let M=t[1]??e.default;M=fe(M,e)||M;const O=document.activeElement;O===c.current||O===s.current||(c.current&&(c.current.value=A),s.current&&(s.current.value=M),m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),m.current=requestAnimationFrame(()=>{m.current=null,d(null),g(null)}))},[t,e]),i.useEffect(()=>()=>{m.current!==null&&(cancelAnimationFrame(m.current),m.current=null)},[]);const v=i.useRef(null),j=i.useRef(n);i.useEffect(()=>{j.current=n},[n]),i.useEffect(()=>{const A=String(t[0]);let M=t[1]??e.default;M=fe(M,e)||M;const O=N(A,M);O!==v.current&&(v.current=O,j.current?.(O??null))},[t,e,N]);const $=(A,M,O)=>{const W=w[M]||M;o?.([A,W],O)},R=A=>{const M=A.target.value,O=s.current?s.current.value:e.default,W=N(M,O);d(M),$(M,O,W)},E=A=>{const M=A.target.value,O=c.current?c.current.value:String(t[0]??""),W=N(O,M);g(M),s.current&&(s.current.value=M),$(O,M,W)},I=A=>{const M=c.current?c.current.value:String(t[0]??""),O=parseFloat(M),W=s.current?s.current.value:e.default;if(N(M,W)||!M.trim()||!Number.isFinite(O))return;const le=A.currentTarget.getBoundingClientRect(),ge=le.left,ee=le.bottom;S({x:ge,y:ee});const V=$t(O,W,e);if(V.length===0){C([]),p(!1);return}C(V),p(L=>!L)},D=A=>{const{value:M,unit:O}=A;p(!1),S(null),c.current&&(c.current.value=M),s.current&&(s.current.value=O),d(M),g(O);const W=N(M,O);$(M,O,W)},H=String(t[0]??""),te=fe(t[1]??e.default,e)||(t[1]??e.default),ne=u??H,Y=!!N(ne,f??te)||!ne.trim(),ce={width:"var(--reactaform-unit-btn-width, 2.5em)",height:"var(--reactaform-unit-btn-height, 2.5em)",padding:"var(--reactaform-unit-btn-padding, 0)",border:"none",borderRadius:"var(--reactaform-button-border-radius, var(--reactaform-border-radius, 0.25em))",backgroundColor:Y?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:Y?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",opacity:Y?+"var(--reactaform-button-disabled-opacity, 0.6)":1,display:"flex",alignItems:"center",justifyContent:"center"},G=N(H,te);return h.jsx(q,{field:r,error:G,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[h.jsx("input",{id:r.name,type:"text",ref:c,defaultValue:String(t[0]??""),onChange:R,style:{width:"var(--reactaform-unit-input-width, 100px)"},className:T(k.input,k.textInput),"aria-invalid":!!G,"aria-describedby":G?`${r.name}-error`:void 0}),h.jsx("select",{id:`${r.name}-unit`,ref:s,defaultValue:fe(t[1]??e.default,e)||(t[1]??e.default),onChange:E,className:T(k.input,k.inputSelect),"aria-invalid":!!G,"aria-describedby":G?`${r.name}-error`:void 0,children:Object.keys(e.labels).map(A=>h.jsx("option",{value:A,children:e.labels[A]??A},A))}),h.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[h.jsx("button",{onClick:I,"aria-disabled":Y,disabled:Y,style:ce,className:k.button,children:h.jsx("span",{style:{fontSize:"var(--reactaform-unit-btn-icon-size, 1em)",lineHeight:"1",transform:"translateY(-1px)",pointerEvents:"none"},children:"⟷"})}),b&&x&&h.jsx(Nt,{pos:y,options:x,onClose:()=>{S(null),p(!1)},onClickOption:D})]})]})})};function At({field:e,value:r,onChange:t}){const{t:o}=F(),n=e.dimension;if(!n)return null;ie[n]||It(n,o);const a=ie[n];return a?h.jsx(Vt,{unitFactors:a,field:e,value:r,onChange:t}):null}const Ke=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,Je=e=>{try{return new URL(e),!0}catch{return!1}},Dt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=F(),l=i.useRef(null),c=i.useCallback(d=>{const f=d.trim();if(f==="")return e.required?n("Value required"):null;if(!Ke.test(f)&&!Je(f)){const b=e.allowRelative===!0;let p=!1;if(Ke.test(f)||Je(f))p=!0;else if(b)try{new URL(f,"http://example.com"),p=!0}catch{p=!1}if(!p)return n("Must be a valid URL")}return z(a,e,f,n)??null},[a,e,n]),s=d=>{const f=d.target.value,g=c(f);t?.(f.trim(),g)},m=i.useRef(null),u=i.useRef(o);return i.useEffect(()=>{u.current=o},[o]),i.useEffect(()=>{const d=r??"",f=c(d);l.current&&l.current.value!==String(d)&&(l.current.value=String(d)),f!==m.current&&(m.current=f,u.current?.(f??null))},[r,c]),h.jsx(q,{field:e,error:c(String(r??"")),children:h.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:l,onChange:s,style:{alignItems:"left"},className:T(k.input,k.textInput),placeholder:"https://example.com","aria-invalid":!!c(String(r??"")),"aria-describedby":c(String(r??""))?`${e.name}-error`:void 0})})},Re=new de,Ot=new Set(["checkbox","switch","dropdown","radio","multi-selection","slider","stepper","color","rating"]),fr={checkbox:_r,color:Jr,date:Yr,dropdown:Xr,email:Qr,file:rt,float:st,"float-array":at,image:ct,int:mt,"int-array":ut,"multi-selection":pt,multiline:dt,password:St,phone:bt,radio:yt,rating:wt,separator:et,slider:Rt,string:_e,stepper:ht,switch:kt,text:_e,time:Et,unit:At,url:Dt};function mr(e,r,t){const o=r;if(!t&&e in fr){console.warn(`Can't Overwrite Base Component type "${e}".`);return}if(Ot.has(e)){Re.register(e,o);return}const n=a=>{const{callback:c,cancel:s}=Xe((...m)=>{const u=a.onChange;typeof u=="function"&&u(...m)},200);return i.useEffect(()=>()=>{s()},[s]),i.createElement(o,{...a,onChange:c})};Re.register(e,n)}function Ae(e,r){mr(e,r,!1)}function De(e){return Re.get(e)}let Ge=!1;function dr(){Ge||(Object.entries(fr).forEach(([e,r])=>{mr(e,r,!0)}),Ge=!0)}const Oe=new de;function ze(e,r){Oe.register(e,r)}function zt(e){return Oe.get(e)}function Lt(e){return Oe.get(e)}ze("Preset_AlertSubmitHandler",(e,r,t)=>{const o={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:t},n=JSON.stringify(o,null,2);alert(n)});const Q=new Map,U={components:new Map,fieldValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function pr(e,r,t){if(!e)return!0;if(t&&!t(e))return!1;switch(r){case"error":throw new Error(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}"`);case"warn":return console.warn(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}". Skipping.`),!1;case"override":return console.info(`Plugin "${e.newPlugin}" is overriding ${e.type} "${e.name}" previously registered by "${e.existingPlugin}"`),!0;case"skip":return!1}}function Pt(e){const r=[];if(e.components){for(const t of Object.keys(e.components))if(De(t)){const n=U.components.get(t);n&&n!==e.name&&r.push({type:"component",name:t,existingPlugin:n,newPlugin:e.name})}}if(e.fieldValidators)for(const[t,o]of Object.entries(e.fieldValidators))for(const n of Object.keys(o)){const l=U.fieldValidators.get(t)?.get(n);ar(t,n)&&l&&l!==e.name&&r.push({type:"fieldValidator",name:`${t}:${n}`,existingPlugin:l,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const o=sr(t),n=U.formValidators.get(t);o&&n&&n!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:n,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const o=Lt(t),n=U.submissionHandlers.get(t);o&&n&&n!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:n,newPlugin:e.name})}return r}function me(e,r,t,o,n,a,l,c){for(const s of Object.keys(e)){let m;if(c?m=n.find(u=>u.type==="fieldValidator"&&u.name===`${c}:${s}`):e===o.components?m=n.find(u=>u.type==="component"&&u.name===s):e===o.formValidators?m=n.find(u=>u.type==="formValidator"&&u.name===s):e===o.submissionHandlers&&(m=n.find(u=>u.type==="submissionHandler"&&u.name===s)),pr(m||null,a,l))if(c){const u=r.get(c)||new Map;u.set(s,o.name),r.set(c,u),t(s,e[s])}else r.set(s,o.name),t(s,e[s])}}function qt(e,r){const t=r?.conflictResolution||"error";if(Q.has(e.name)){const n={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!pr(n,t,r?.onConflict))return}const o=Pt(e);if(e.components&&me(e.components,U.components,Ae,e,o,t,r?.onConflict),e.fieldValidators)for(const[n,a]of Object.entries(e.fieldValidators))me(a,U.fieldValidators,(l,c)=>or(n,l,c),e,o,t,r?.onConflict,n);e.formValidators&&me(e.formValidators,U.formValidators,nr,e,o,t,r?.onConflict),e.submissionHandlers&&me(e.submissionHandlers,U.submissionHandlers,ze,e,o,t,r?.onConflict),e.setup&&e.setup(),Q.set(e.name,e)}function Ht(e,r=!1){const t=Q.get(e);if(!t)return!1;if(t.cleanup&&t.cleanup(),r){if(t.components)for(const o of Object.keys(t.components))U.components.delete(o);if(t.fieldValidators)for(const[o,n]of Object.entries(t.fieldValidators)){const a=U.fieldValidators.get(o);if(a){for(const l of Object.keys(n))a.delete(l);a.size===0&&U.fieldValidators.delete(o)}}if(t.formValidators)for(const o of Object.keys(t.formValidators))U.formValidators.delete(o);if(t.submissionHandlers)for(const o of Object.keys(t.submissionHandlers))U.submissionHandlers.delete(o)}return Q.delete(e),!0}function Tt(e){return Q.get(e)}function Bt(){return Array.from(Q.values())}function Ut(e){return Q.has(e)}function Wt(e){for(const[r,t]of Object.entries(e))Ae(r,t)}const gr=i.memo(({field:e,value:r,handleChange:t,handleError:o})=>{const n=De(e.type),a=i.useCallback((c,s)=>t(e.name,c,s),[t,e.name]),l=i.useCallback(c=>o?.(e.name,c),[o,e.name]);return n?h.jsx(n,{field:e,value:r,onChange:a,onError:l}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError);gr.displayName="FieldWrapper";const hr=(e,r,t,o)=>h.jsx(gr,{field:e,value:r[e.name],handleChange:t,handleError:o},e.name),br=i.memo(({groupName:e,isOpen:r,fields:t,valuesMap:o,handleChange:n,handleError:a,toggleGroup:l,t:c})=>{const s=i.useCallback(()=>l(e),[l,e]),{formStyle:m,fieldStyle:u}=F(),d=i.useMemo(()=>({border:"1px solid var(--reactaform-border-color, #bbb)",padding:"var(--reactaform-fieldset-padding, 0.5em)",borderRadius:"var(--reactaform-border-radius, 4px)",marginBottom:"var(--reactaform-space, 8px)",...m?.fieldset||{},...u?.fieldset||{}}),[m,u]),f=i.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...m?.legend||{},...u?.legend||{}}),[m,u]);return h.jsxs("fieldset",{style:d,children:[h.jsxs("legend",{onClick:s,style:f,children:[h.jsx("span",{children:c(e)}),h.jsx("span",{children:r?"▼":"▶"})]}),r&&t.map(g=>h.jsx("div",{children:hr(g,o,n,a)},g.name))]})});br.displayName="FieldGroup";const _t=(e,r,t,o,n,a,l,c,s)=>{const m=r.slice(0,c).filter(g=>l[g.name]),d=Lr(m).groups,f=[];return d.forEach(g=>{if(g.name){const b=e[g.name]??!0;f.push(h.jsx(br,{groupName:g.name,isOpen:b,fields:g.fields,valuesMap:t,handleChange:n,handleError:a,toggleGroup:s,t:o},g.name))}else g.fields.forEach(b=>f.push(h.jsx("div",{children:hr(b,t,n,a)},b.name)))}),f},Kt=e=>{const r={};return e.forEach(t=>{r[t.name]=!1}),r},Le=(e,r,t,o)=>{const n=r[e];if(!n?.children)return;const a=t[e],l=a!=null?String(a):"";(n.children[l]||[]).forEach(s=>{o[s]=!0,Le(s,r,t,o)})},yr=(e,r,t)=>{const o=r[e];o?.children&&Object.values(o.children).flat().forEach(n=>{t[n]=!1,yr(n,r,t)})},Jt=(e,r,t,o)=>{const n={...t};return e.forEach(a=>{(!a.parents||Object.keys(a.parents).length===0)&&(n[a.name]=!0,Le(a.name,o,r,n))}),n},Gt=(e,r,t,o,n)=>{const a={...e};if(yr(o,r,a),n!=null){const l=r[o];if(l?.children){const c=String(n);(l.children[c]||[]).forEach(m=>{a[m]=!0,Le(m,r,t,a)})}}return a};async function Yt(e,r,t,o,n){const a=Object.values(n).filter(Boolean);if(a.length>0)return{success:!1,message:o("Please fix validation errors before submitting."),errors:a};const l={...t},c=[];if(e&&Array.isArray(e.properties))for(const m of e.properties){const u=m.name,d=l[u];if(d==null)continue;const f=m.type;try{if(f==="int"||f==="number"||f==="float"){const g=Number(String(d).trim());isNaN(g)?c.push(o(`Invalid number format for field ${m.displayName||u}`)):l[u]=g}else if(f==="int-array"||f==="float-array"){const b=String(d).split(",").map(p=>p.trim()).filter(Boolean).map(p=>{const y=Number(p);return isNaN(y)?(c.push(o(`Invalid number "${p}" in array for field ${m.displayName||u}`)),0):y});c.length===0&&(l[u]=b)}}catch(g){c.push(o(`Error processing field ${m.displayName||u}: ${g}`))}}if(c.length>0)return{success:!1,message:o("Data transformation errors occurred."),errors:c};const s=await Nr(e,l,o);if(s&&s.length>0)return{success:!1,message:"Validation Fail",errors:s};if(e&&typeof e.submitHandlerName=="string"){const m=zt(e.submitHandlerName);if(m)try{const u=await m(e,r?.name??null,l,o);if(u&&u.length>0)return{success:!1,message:o("Submission failed."),errors:Array.isArray(u)?u:[u]}}catch(u){return{success:!1,message:o("Submission handler error occurred."),errors:[String(u)]}}}return{success:!0,message:o("Form submitted successfully."),data:l}}const xr=({definition:e,instance:r,chunkSize:t=50,chunkDelay:o=50})=>{const{properties:n,displayName:a}=e,l=F(),{t:c,formStyle:s,language:m}=l,u={...l,definitionName:e?.name??l.definitionName},[d,f]=i.useState("en"),[g,b]=i.useState([]),[p,y]=i.useState({}),[S,x]=i.useState({}),[C,N]=i.useState({}),[w,v]=i.useState({}),[j,$]=i.useState({}),[R,E]=i.useState(null),[I,D]=i.useState(null),[H,te]=i.useState(0),[ne,Pe]=i.useState(!1),[Y,ce]=i.useState(!1),[G,A]=i.useState(r.name||""),M=i.useRef(r),O=i.useRef(!1);i.useEffect(()=>{const V=Object.fromEntries(n.map(P=>[P.name,{...P,children:{}}]));n.forEach(P=>{P.parents&&Object.entries(P.parents).forEach(([oe,he])=>{const ae=V[oe];ae&&he.forEach(Cr=>{ae.children||(ae.children={});const qe=String(Cr);ae.children[qe]=[...ae.children[qe]||[],P.name]})})}),zr(n,V);const L=Object.values(V),B={};L.forEach(P=>{if(P.type==="unit"){const oe=typeof P.defaultValue=="number"?String(P.defaultValue):"",he=typeof P.defaultUnit=="string"?P.defaultUnit:String(P.defaultUnit??"m");B[P.name]=[oe,he]}else B[P.name]=P.defaultValue}),M.current=r,Object.keys(r.values).forEach(P=>{V[P]!==void 0&&(B[P]=r.values[P])});const K=Kt(L),J={};L.forEach(P=>{P.group&&!(P.group in J)&&(J[P.group]=!0)});const re=requestAnimationFrame(()=>{b(L),y(V),x(B),N(Jt(L,B,K,V)),v(J),Pe(!0),A(r.name)});return()=>cancelAnimationFrame(re)},[n,r,e]),i.useEffect(()=>{if(!ne||H>=g.length)return;const V=setTimeout(()=>{te(L=>Math.min(L+t,g.length))},o);return()=>clearTimeout(V)},[ne,H,g.length,t,o]);const W=i.useCallback((V,L,B)=>{E(null),D(null),x(K=>{const J={...K,[V]:L},re=p[V];return re&&["checkbox","dropdown","multi-select","radio","switch"].includes(re.type)&&N(oe=>Gt(oe,p,J,V,String(L))),J}),$(K=>B?{...K,[V]:B}:Object.fromEntries(Object.entries(K).filter(([re])=>re!==V)))},[p,E,D]);i.useEffect(()=>{let V=0;return V=requestAnimationFrame(()=>{m!==d&&(f(m||"en"),E(null),D(null))}),()=>cancelAnimationFrame(V)},[m,d]),i.useEffect(()=>{let V=0;return V=requestAnimationFrame(()=>{if(O.current){O.current=!1,M.current=r,A(r.name||"");return}M.current=r,E(null),D(null),A(r.name||"")}),()=>cancelAnimationFrame(V)},[r,r.name]);const pe=i.useCallback((V,L)=>{$(B=>L?{...B,[V]:String(L)}:Object.fromEntries(Object.entries(B).filter(([J])=>J!==V)))},[]),le=async()=>{O.current=!0;const V=M.current?.name;M.current.name=G;const L=await Yt(e,M.current,S,c,j),B=typeof L.message=="string"?L.message:String(L.message),K=Object.values(L.errors??{}).join(`
|
|
288
|
+
`);E(K?B+`
|
|
289
|
+
`+K:B),D(L.success),L.success||(M.current.name=V??M.current.name,A(V??""))},ge=V=>{v(L=>({...L,[V]:!L[V]}))},ee=i.useMemo(()=>Object.values(j).some(Boolean),[j]);return h.jsx(Ee.Provider,{value:u,children:h.jsxs("div",{style:s.container,children:[a&&h.jsx("h2",{style:s.titleStyle,children:c(a)}),R&&h.jsxs("div",{role:"status",style:{marginBottom:12,padding:12,borderRadius:6,backgroundColor:I?"rgba(76, 175, 80, 0.12)":"rgba(225, 29, 72, 0.06)",border:`1px solid ${I?"rgba(76,175,80,0.3)":"rgba(225,29,72,0.12)"}`,color:I?"var(--reactaform-success-color, #4CAF50)":"var(--reactaform-error-color, #e11d48)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[h.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:R}),h.jsx("button",{onClick:()=>{E(null),D(null)},"aria-label":c("Dismiss"),style:{marginLeft:12,background:"transparent",border:"none",cursor:"pointer",color:"inherit",fontSize:16,lineHeight:1},children:"×"})]}),r&&h.jsx(er,{name:G,onChange:V=>{A(V),E(null),D(null)}}),h.jsxs(h.Fragment,{children:[_t(w,g,S,c,W,pe,C,H,ge),H<g.length&&h.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"}})]}),h.jsx("button",{onClick:le,disabled:ee,onMouseEnter:()=>ce(!0),onMouseLeave:()=>ce(!1),style:{padding:"var(--reactaform-button-padding, var(--reactaform-space) 12px)",backgroundColor:ee?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",border:"none",borderRadius:"4px",cursor:ee?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",fontSize:"var(--reactaform-button-font-size, 14px)",fontWeight:"var(--reactaform-button-font-weight, 500)",boxShadow:"var(--reactaform-button-shadow, none)",marginTop:"var(--reactaform-button-margin-top, 0.5em)",transition:"opacity 0.2s ease",opacity:ee?"var(--reactaform-button-disabled-opacity, 0.6)":Y?"var(--reactaform-button-hover-opacity, 0.9)":"1"},children:c("Submit")})]})})};dr();const Xt=(e,r=!1)=>({container:{padding:"var(--reactaform-space-sm, 8px)",margin:"0 auto",backgroundColor:"transparent",borderRadius:0,color:"var(--reactaform-color-text)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, system-ui, -apple-system, sans-serif)",boxSizing:"border-box",minHeight:e?.minHeight??"0",...e?.width?{width:e.width,overflowX:"auto"}:{maxWidth:"100%"},...e?.height?{height:e.height,overflowY:"auto"}:{}},buttonStyle:{padding:"var(--reactaform-space-sm, 8px) var(--reactaform-space-md, 16px)",backgroundColor:"var(--reactaform-color-primary)",color:"var(--reactaform-color-background)",border:"1px solid var(--reactaform-color-primary)",borderRadius:"var(--reactaform-border-radius, 6px)",cursor:"pointer",fontSize:e?.fontSize||"1rem",fontWeight:"600",transition:"all 0.2s ease",boxShadow:"var(--reactaform-shadow-small, 0 1px 3px rgba(0, 0, 0, 0.12))"},titleStyle:{marginBottom:"var(--reactaform-space-lg, 24px)",color:"var(--reactaform-color-text)",fontSize:typeof e?.fontSize=="number"?`${e.fontSize*1.5}px`:"1.5rem",fontWeight:"700",lineHeight:"1.2",textAlign:"left"}}),Zt=(e,r=!1)=>{const t={color:"var(--reactaform-color-text)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)",transition:"all 0.2s ease",outline:"none",width:"100%",boxSizing:"border-box"};return{container:{fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)",fontSize:e?.fontSize||"var(--reactaform-font-size, 1rem)",width:"100%",maxWidth:e?.width||"100%",marginBottom:"var(--reactaform-space-md, 16px)"},label:{display:"block",marginBottom:"var(--reactaform-space-xs, 4px)",fontWeight:"500",color:"var(--reactaform-color-text)",fontSize:"var(--reactaform-font-size, 1rem)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)"},input:t,textInput:t,optionInput:t,select:{...t,cursor:"pointer",backgroundRepeat:"no-repeat",backgroundPosition:"right 8px center",backgroundSize:"16px",paddingRight:"32px",backgroundImage:`url("data:image/svg+xml;utf8,<svg
|
|
290
290
|
xmlns='http://www.w3.org/2000/svg'
|
|
291
291
|
viewBox='0 0 24 24'
|
|
292
292
|
fill='none'
|
|
@@ -295,4 +295,4 @@
|
|
|
295
295
|
stroke-linecap='round'
|
|
296
296
|
stroke-linejoin='round'>
|
|
297
297
|
<polyline points='6,9 12,15 18,9'/>
|
|
298
|
-
</svg>")`},textarea:{...
|
|
298
|
+
</svg>")`},textarea:{...t,minHeight:"80px",resize:"vertical",paddingTop:"var(--reactaform-space-sm, 8px)"},error:{color:"var(--reactaform-color-error)",fontSize:"0.875rem",marginTop:"var(--reactaform-space-xs, 4px)",display:"block"}}},vr=({children:e,definitionName:r="",defaultStyle:t,defaultLanguage:o="en",defaultDarkMode:n=!1,defaultLocalizeName:a="",className:l="reactaform-container"})=>{const c=r,s=a,m=n,u=o,d=i.useMemo(()=>t??{},[t]),[f,g]=i.useState({}),[b,p]=i.useState({}),[y,S]=i.useState({}),[x,C]=i.useState({});i.useEffect(()=>{let $=!0;return(async()=>{if(u==="en"){$&&(g({}),p({}));return}try{const E=await qr(u),I=E.success?E.translations:{};$&&g(I);const D=await Hr(u,s),H=D.success?D.translations:{};$&&p(H)}catch{$&&(g({}),p({}))}})(),()=>{$=!1}},[u,s]),i.useEffect(()=>{C(Xt(d,m)),S(Zt(d,m))},[d,m]);const N=i.useMemo(()=>Br(u,f,b),[u,f,b]),w=i.useCallback(($,...R)=>N($,...R),[N]),v=i.useMemo(()=>({definitionName:c,language:u,darkMode:m,formStyle:x,fieldStyle:y,t:w}),[c,u,m,y,x,w]),j=d?.height?{height:"100%"}:void 0;return h.jsx(Ee.Provider,{value:v,children:h.jsx("div",{"data-reactaform-theme":m?"dark":"light",className:l,style:j,children:e})})};function Qt(e){if(!e||typeof e!="object")return"Definition must be an object";const r=e;if(!r.name||typeof r.name!="string")return"Definition must include a 'name' string";if(!r.version||typeof r.version!="string")return"Definition must include a 'version' string";if(r.properties!==void 0&&!Array.isArray(r.properties))return"'properties' must be an array if provided";if(Array.isArray(r.properties))for(let t=0;t<r.properties.length;t++){const o=r.properties[t];if(!o||typeof o!="object")return`Property at index ${t} must be an object`;if(!o.name||typeof o.name!="string")return`Property at index ${t} must have a string 'name'`;if(!o.type||typeof o.type!="string")return`Property '${o.name}' must have a string 'type'`}return null}async function en(e,r={}){const{validateSchema:t=!0}=r;try{if(!e||typeof e!="string")return{success:!1,error:"jsonData must be a non-empty JSON string"};const o=e.trim();if(!o)return{success:!1,error:"jsonData is empty"};let n;try{n=JSON.parse(o)}catch(a){return{success:!1,error:`Invalid JSON format: ${a instanceof Error?a.message:"Unknown parsing error"}`}}if(t){const a=Qt(n);if(a)return{success:!1,error:`Schema validation failed: ${a}`}}return{success:!0,definition:n}}catch(o){return{success:!1,error:`Unexpected error loading definition: ${o instanceof Error?o.message:"Unknown error"}`}}}function wr(e,r){try{if(!e)return{success:!1,error:"Definition is required"};if(!r||typeof r!="string")return{success:!1,error:"Instance name is required"};const t={name:r,definition:e.name??"unknown",version:e.version??"1.0.0",values:{}},o=e.properties||[];return Array.isArray(o)&&o.forEach(n=>{const a=n;if(a.type==="unit"){const l=a.defaultUnit,c=Number(a.defaultValue)||void 0;t.values[a.name]=[c||0,l||"m"]}else a.defaultValue!==void 0&&(t.values[a.name]=a.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function rn(e){try{if(!e)return{success:!1,error:"Instance data is required"};let r;if(typeof e=="string")try{r=JSON.parse(e)}catch(t){return{success:!1,error:`Invalid JSON format: ${t instanceof Error?t.message:"Unknown parsing error"}`}}else r=e;return typeof r!="object"||r===null?{success:!1,error:"Instance must be a valid object"}:{success:!0,instance:r}}catch(r){return{success:!1,error:`Error loading instance: ${r instanceof Error?r.message:"Unknown error"}`}}}function tn(e,r,t){try{if(!e)return{success:!1,error:"Instance is required"};if(!r)return{success:!1,error:"Latest definition is required"};if(e.definition===r.name&&e.version===r.version)return{success:!0,instance:e};const o={name:e.name||r.name+"-instance",definition:r.name,version:r.version,values:{}},n=o.values,a={};(r.properties||[]).forEach(s=>{a[s.name]=s});const l=(s,m,u)=>{if(s==null)return s;const d=m.toLowerCase();try{if(d==="string")return String(s);if(d==="int"||d==="integer"||d==="number"||d==="float"){if(typeof s=="number")return s;if(typeof s=="boolean")return s?1:0;if(typeof s=="string"){const f=Number(s.trim());return Number.isNaN(f)?0:f}return 0}if(d==="boolean"||d==="bool")return typeof s=="boolean"?s:typeof s=="number"?s!==0:typeof s=="string"?["true","1","yes"].includes(s.toLowerCase()):!!s;if(d==="unit"){if(Array.isArray(s)&&s.length>=1)return s;if(typeof s=="number")return[s,u&&u.defaultUnit||""];if(typeof s=="string"){const f=Number(s);return Number.isNaN(f)?[0,u&&u.defaultUnit||""]:[f,u&&u.defaultUnit||""]}return s}if(d.endsWith("[]")||d==="array")return Array.isArray(s)?s:typeof s=="string"?s.split(",").map(f=>f.trim()).filter(Boolean):[s]}catch{}return s},c=e.values||{};Object.keys(c).forEach(s=>{const m=c[s],u=a[s];if(!u)return;const d=Array.isArray(m)?"array":m===null?"null":typeof m,f=(u.type||"").toLowerCase();d===f||f==="string"&&typeof m=="string"?n[s]=m:n[s]=l(m,f,u)}),(r.properties||[]).forEach(s=>{const m=s.name;m in n||(n[m]=s.defaultValue)});try{typeof t=="function"&&t?.(e,o,r)}catch(s){return{success:!1,error:`Upgrade callback error: ${s instanceof Error?s.message:String(s)}`}}return{success:!0,instance:o}}catch(o){return{success:!1,error:`Error upgrading instance: ${o instanceof Error?o.message:"Unknown error"}`}}}dr();function nn(e){const[r,t]=i.useState(null);return i.useEffect(()=>{const o=document.querySelector("[data-reactaform-theme]");if(!o)return;const n=o.closest("[data-reactaform-theme]");if(!n)return;const a=()=>t(n.getAttribute("data-reactaform-theme"));a();const l=new MutationObserver(c=>{for(const s of c)s.type==="attributes"&&s.attributeName==="data-reactaform-theme"&&a()});return l.observe(n,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>l.disconnect()},[e]),r}const on=({definitionData:e,instance:r,language:t,className:o,darkMode:n,style:a})=>{const l=i.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),c={fontSize:"inherit",fontFamily:"inherit",...a},s=nn(),m=n??s==="dark",u=t??"en";if(i.useEffect(()=>{let f=document.getElementById("popup-root");f||(f=document.createElement("div"),f.id="popup-root",document.body.appendChild(f))},[]),!l)return h.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."});let d=r;if(!d){const f=wr(l,l.name);if(!f.success||!f.instance)return h.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."});d=f.instance}return h.jsx(vr,{definitionName:l.name,defaultStyle:c,defaultLanguage:u,defaultDarkMode:m,defaultLocalizeName:l.localization||"",className:o,children:h.jsx(xr,{definition:l,instance:d})})};function Sr(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=Rr,document.head.appendChild(e)}catch{}}typeof document<"u"&&Sr();exports.CSS_CLASSES=k;exports.ReactaForm=on;exports.ReactaFormProvider=vr;exports.ReactaFormRenderer=xr;exports.StandardFieldLayout=q;exports.Units=Wr;exports.combineClasses=T;exports.createInstanceFromDefinition=wr;exports.deserializeDefinition=Ar;exports.deserializeInstance=$r;exports.getAllPlugins=Bt;exports.getComponent=De;exports.getPlugin=Tt;exports.hasPlugin=Ut;exports.injectReactaFormStyles=Sr;exports.loadInstance=rn;exports.loadJsonDefinition=en;exports.registerComponent=Ae;exports.registerComponents=Wt;exports.registerFieldValidationHandler=or;exports.registerFormValidationHandler=nr;exports.registerPlugin=qt;exports.registerSubmissionHandler=ze;exports.serializeDefinition=Vr;exports.serializeInstance=Ir;exports.unregisterPlugin=Ht;exports.upgradeInstanceToLatestDefinition=tn;exports.useDebouncedCallback=Xe;exports.useReactaFormContext=F;exports.validateFieldValue=z;
|