@opennsw/jsonforms-renderers 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -112,6 +112,10 @@ export declare const SpreadsheetControl: ComponentType<OwnPropsOfControl>;
112
112
 
113
113
  export declare const SpreadsheetControlTester: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
114
114
 
115
+ export declare const SpreadsheetExportControl: ComponentType<OwnPropsOfControl>;
116
+
117
+ export declare const SpreadsheetExportControlTester: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
118
+
115
119
  export declare const TextControl: ({ data, handleChange, path, label, required, errors, uischema, schema, enabled, visible, }: ControlProps) => JSX.Element | null;
116
120
 
117
121
  export declare const TextControlTester: RankedTester;
@@ -150,4 +154,8 @@ export declare const XmlControl: ComponentType<OwnPropsOfControl>;
150
154
 
151
155
  export declare const XmlControlTester: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
152
156
 
157
+ export declare const XmlExportControl: ComponentType<OwnPropsOfControl>;
158
+
159
+ export declare const XmlExportControlTester: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
160
+
153
161
  export { }
@@ -1,3 +1,3 @@
1
- "use strict";var kt=Object.create;var Re=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var Dt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Mt=(e,r,t)=>r in e?Re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var zt=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let c of Nt(r))!Lt.call(e,c)&&c!==t&&Re(e,c,{get:()=>r[c],enumerable:!(s=It(r,c))||s.enumerable});return e};var we=(e,r,t)=>(t=e!=null?kt(Dt(e)):{},zt(r||!e||!e.__esModule?Re(t,"default",{value:e,enumerable:!0}):t,e));var Ie=(e,r,t)=>Mt(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),y=require("react"),b=require("@jsonforms/core"),J=require("@jsonforms/react"),o=require("@radix-ui/themes"),Y=require("@radix-ui/react-icons"),Ut=require("dayjs"),Ne=require("@e965/xlsx"),$e=y.createContext(null);function Pt({children:e,onUpload:r,getDownloadUrl:t}){const s={onUpload:r,getDownloadUrl:t};return n.jsx($e.Provider,{value:s,children:e})}function _e(){return y.useContext($e)}const We=y.createContext(null);function Bt({children:e,services:r}){const t=y.useMemo(()=>r,[r]);return n.jsx(We.Provider,{value:t,children:e})}function Ve(e){const r=y.useContext(We);return!r||!e?null:r[e]??null}const pe=(e,r,t,s=void 0)=>{y.useEffect(()=>{e===!1&&t(r,s)},[e,r,t,s])},xe=(e,r)=>e?e.split(`
1
+ "use strict";var nr=Object.create;var Ie=Object.defineProperty;var or=Object.getOwnPropertyDescriptor;var sr=Object.getOwnPropertyNames;var ir=Object.getPrototypeOf,lr=Object.prototype.hasOwnProperty;var ar=(e,r,t)=>r in e?Ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var cr=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of sr(r))!lr.call(e,a)&&a!==t&&Ie(e,a,{get:()=>r[a],enumerable:!(o=or(r,a))||o.enumerable});return e};var je=(e,r,t)=>(t=e!=null?nr(ir(e)):{},cr(r||!e||!e.__esModule?Ie(t,"default",{value:e,enumerable:!0}):t,e));var Ve=(e,r,t)=>ar(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("react"),v=require("@jsonforms/core"),H=require("@jsonforms/react"),s=require("@radix-ui/themes"),Z=require("@radix-ui/react-icons"),rt=require("dayjs"),nt=g.createContext(null);function ur({children:e,onUpload:r,getDownloadUrl:t}){const o={onUpload:r,getDownloadUrl:t};return n.jsx(nt.Provider,{value:o,children:e})}function ot(){return g.useContext(nt)}const st=g.createContext(null);function dr({children:e,services:r}){const t=g.useMemo(()=>r,[r]);return n.jsx(st.Provider,{value:t,children:e})}function it(e){const r=g.useContext(st);return!r||!e?null:r[e]??null}const me=(e,r,t,o=void 0)=>{g.useEffect(()=>{e===!1&&t(r,o)},[e,r,t,o])},fe=(e,r)=>e?e.split(`
2
2
  `).map(t=>t.trim()==="is a required property"?`${r||"This field"} is required`:t).join(`
3
- `):"",He=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,uischema:i,schema:d,enabled:a,visible:u=!0})=>{var m;if(pe(u,t,r),u===!1)return null;const f=l.length===0;return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsx(o.TextField.Root,{value:e||"",onChange:p=>r(t,p.target.value),disabled:!a,placeholder:(m=i.options)==null?void 0:m.placeholder,color:f?void 0:"red",id:t}),!f&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),d.description&&n.jsx(o.Text,{size:"1",color:"gray",children:d.description})]})})},Xe=b.rankWith(1,b.isStringControl),$t=J.withJsonFormsControlProps(He),Je=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,uischema:i,schema:d,enabled:a,visible:u=!0})=>{var p;if(pe(u,t,r),u===!1)return null;const f=l.length===0,m=x=>{if(x===""){r(t,void 0);return}const g=Number(x);isNaN(g)||r(t,g)};return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsx(o.TextField.Root,{type:"number",value:e??"",onChange:x=>m(x.target.value),disabled:!a,placeholder:(p=i.options)==null?void 0:p.placeholder,color:f?void 0:"red",id:t}),!f&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),d.description&&n.jsx(o.Text,{size:"1",color:"gray",children:d.description})]})})},Ke=b.rankWith(2,b.or(b.isNumberControl,b.isIntegerControl)),_t=J.withJsonFormsControlProps(Je),Ge=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,enabled:d,visible:a=!0})=>{if(pe(a,t,r),a===!1)return null;const u=l.length===0;return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(o.Checkbox,{checked:!!e,onCheckedChange:f=>r(t,f===!0),disabled:!d,id:t}),n.jsxs(o.Text,{as:"label",size:"2",htmlFor:t,children:[s," ",c&&"*"]})]}),!u&&n.jsx(o.Text,{color:"red",size:"1",className:"block mt-1",children:xe(l,s)}),i.description&&n.jsx(o.Text,{size:"1",color:"gray",className:"block mt-1",children:i.description})]})},Ye=b.rankWith(2,b.isBooleanControl),Wt=J.withJsonFormsControlProps(Ge),qe=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,enabled:d,visible:a=!0})=>{if(pe(a,t,r),a===!1)return null;const u=l.length===0;let f=[];i.enum?f=i.enum.map(p=>({value:p,label:String(p)})):i.oneOf&&(f=i.oneOf.map(p=>({value:p.const,label:p.title||String(p.const)})));const m=e;return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"div",size:"2",weight:"bold",children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsx(o.RadioGroup.Root,{value:m!==void 0?String(m):"",onValueChange:p=>{const x=f.find(g=>String(g.value)===p);x&&r(t,x.value)},disabled:!d,children:n.jsx(o.Flex,{direction:"row",style:{flexWrap:"wrap",columnGap:"clamp(14px, 3vw, 36px)",rowGap:"clamp(8px, 1.6vw, 14px)"},children:f.map(p=>n.jsxs(o.Flex,{align:"center",gap:"2",style:{minWidth:"max-content"},children:[n.jsx(o.RadioGroup.Item,{value:String(p.value)}),n.jsx(o.Text,{size:"2",color:d?void 0:"gray",children:p.label})]},String(p.value)))})}),!u&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),i.description&&n.jsx(o.Text,{size:"1",color:"gray",children:i.description})]})})},Ze=(e,r,t)=>{var c;return b.or(b.isEnumControl,b.isOneOfControl)(e,r,t)&&((c=e==null?void 0:e.options)==null?void 0:c.format)==="radio"?3:-1},Vt=J.withJsonFormsControlProps(qe),Qe=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,uischema:d,enabled:a,visible:u=!0})=>{var x;if(pe(u,t,r),u===!1)return null;const f=l.length===0;let m=[];i.enum?m=i.enum.map(g=>({value:String(g),label:String(g)})):i.oneOf&&(m=i.oneOf.map(g=>({value:String(g.const),label:g.title||String(g.const)})));const p=e!==void 0?String(e):"";return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsxs(o.Select.Root,{value:p,onValueChange:g=>r(t,g),disabled:!a,children:[n.jsx(o.Select.Trigger,{placeholder:((x=d.options)==null?void 0:x.placeholder)||"Select an option",color:f?void 0:"red",id:t}),n.jsx(o.Select.Content,{children:m.map(g=>n.jsx(o.Select.Item,{value:g.value,children:g.label},g.value))})]}),!f&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),i.description&&n.jsx(o.Text,{size:"1",color:"gray",children:i.description})]})})},et=b.rankWith(2,b.or(b.isEnumControl,b.isOneOfControl)),Ht=J.withJsonFormsControlProps(Qe),Xt={"small-list":{fetchOnOpen:!0,searchable:!1,paginated:!1},"large-searchable-list":{fetchOnOpen:!0,searchable:!0,paginated:!1},"large-paginated-list":{fetchOnOpen:!1,searchable:!0,paginated:!0}},Jt=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,enabled:i,visible:d=!0,schema:a,uischema:u})=>{var me;const f=(a==null?void 0:a["x-search"])??{service:""},m=f.service??"",p=f.mode??"large-paginated-list",x=Xt[p],g=(x==null?void 0:x.fetchOnOpen)??!1,F=f.params,E=Ve(m),T=a.type==="object",O=T?typeof e=="string"?{value:e}:e??void 0:void 0,L=T?O==null?void 0:O.value:e,N=O==null?void 0:O.label,v=m?E?x?null:`Invalid x-search.mode "${p}". Expected "small-list", "large-searchable-list", or "large-paginated-list".`:`Search service "${m}" is not registered.`:"Search not configured.",U=i!==!1,P=!l||l.length===0,[S,R]=y.useState(!1),[B,W]=y.useState(""),[$,V]=y.useState([]),[Q,ee]=y.useState(!1),[se,ne]=y.useState(!1),[le,ue]=y.useState(!1),[H,h]=y.useState(null),[C,X]=y.useState(void 0),A=y.useRef(void 0),M=y.useRef(null),q=y.useRef(null),oe=y.useRef(null),G=y.useRef(void 0);y.useEffect(()=>{var ie,Z;if(!L){X(void 0),G.current=void 0;return}if(((ie=G.current)==null?void 0:ie.value)===L&&((Z=G.current)==null?void 0:Z.label)===N)return;if(G.current={value:L,label:N},T&&N){X({id:L,name:N});return}if(X({id:L,name:N??L}),!(E!=null&&E.resolve))return;let w=!1;return E.resolve(L,F).then(ae=>{!w&&ae&&X(ae)}).catch(()=>{}),()=>{w=!0}},[L,N,T,E,F]);const k=y.useCallback(async(w,ie=!1)=>{var ae;if(!E){h("Search service not configured.");return}(ae=q.current)==null||ae.abort();const Z=new AbortController;q.current=Z,ie?ue(!0):(ne(!0),ue(!1),h(null));try{const ye=await E.search({query:w,cursor:ie?A.current:void 0,signal:Z.signal,params:F}),ve=ye.options??[];V(ie?je=>[...je,...ve]:ve),A.current=ye.nextCursor,ee(((x==null?void 0:x.paginated)??!1)&&ye.nextCursor!=null)}catch{if(Z.signal.aborted)return;h("Failed to load results. Please try again.")}finally{Z.signal.aborted||(ie?ue(!1):ne(!1))}},[E,x==null?void 0:x.paginated,F]);if(y.useEffect(()=>{if(!S)return;const w=ie=>{oe.current&&!oe.current.contains(ie.target)&&R(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[S]),y.useEffect(()=>{var w;S||((w=q.current)==null||w.abort(),W(""),V([]),ee(!1),h(null),ne(!1),ue(!1),A.current=void 0)},[S]),y.useEffect(()=>{if(!S)return;if(!B&&!g){V([]),ee(!1),h(null),A.current=void 0;return}M.current&&clearTimeout(M.current);const w=B?300:0;return M.current=setTimeout(()=>{V([]),ee(!1),A.current=void 0,k(B)},w),()=>{M.current&&clearTimeout(M.current)}},[B,S,g,k]),pe(d,t,r,T?void 0:null),d===!1)return null;const j=()=>{W(""),V([]),ee(!1),h(null),A.current=void 0,R(!0)},D=w=>{r(t,T?{value:w.id,label:w.name}:w.id),X(w),G.current={value:w.id,label:T?w.name:void 0},R(!1)},ce=w=>{w.stopPropagation(),r(t,T?void 0:null),X(void 0)},_=w=>{(w.key==="Enter"||w.key===" ")&&ce(w)},z=((me=u==null?void 0:u.options)==null?void 0:me.placeholder)??"Select an option";return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsxs("div",{ref:oe,style:{position:"relative"},children:[n.jsx(o.TextField.Root,{id:t,value:S?B:(C==null?void 0:C.name)??"",placeholder:S&&(x!=null&&x.searchable)?"Search...":z,disabled:!U,readOnly:S&&!(x!=null&&x.searchable),style:P?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:w=>{x!=null&&x.searchable&&(W(w.target.value),S||j())},onFocus:()=>{U&&!S&&j()},onKeyDown:w=>{w.key==="Escape"&&R(!1)},children:n.jsx(o.TextField.Slot,{side:"right",children:n.jsxs(o.Flex,{align:"center",gap:"1",children:[L&&U&&n.jsx("span",{role:"button",tabIndex:0,onMouseDown:w=>w.preventDefault(),onClick:ce,onKeyDown:_,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),n.jsx(Y.ChevronDownIcon,{style:{transform:S?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),S&&n.jsx(o.Box,{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:50,background:"var(--color-panel-solid)",borderRadius:"var(--radius-3)",boxShadow:"var(--shadow-5)",border:"1px solid var(--gray-a6)",overflow:"hidden"},children:v?n.jsx(o.Box,{p:"3",children:n.jsx(o.Text,{size:"2",color:"gray",children:v})}):n.jsx(o.ScrollArea,{style:{maxHeight:240},children:n.jsxs(o.Box,{p:"1",children:[se&&n.jsx(o.Flex,{justify:"center",p:"4",children:n.jsx(o.Spinner,{})}),!se&&H&&n.jsx(o.Box,{px:"3",py:"2",children:n.jsx(o.Text,{size:"2",color:"red",children:H})}),!se&&!H&&$.length===0&&n.jsx(o.Box,{px:"3",py:"2",children:n.jsx(o.Text,{size:"2",color:"gray",children:B||g?"No results found.":"Type to search…"})}),$.map(w=>n.jsx(o.Box,{px:"3",py:"2",onMouseDown:ie=>ie.preventDefault(),onClick:()=>D(w),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:w.id===L?"var(--accent-3)":void 0},className:"hover:bg-(--gray-3)",children:n.jsx(o.Text,{size:"2",children:w.name})},w.id)),(x==null?void 0:x.paginated)&&Q&&!le&&n.jsx(o.Box,{px:"3",py:"2",children:n.jsx(o.Button,{variant:"ghost",size:"1",style:{width:"100%"},onMouseDown:w=>w.preventDefault(),onClick:()=>void k(B,!0),children:"Load more"})}),le&&n.jsx(o.Flex,{justify:"center",p:"2",children:n.jsx(o.Spinner,{})})]})})})]}),!P&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),a.description&&n.jsx(o.Text,{size:"1",color:"gray",children:a.description})]})})},tt=J.withJsonFormsControlProps(Jt),rt=b.rankWith(3,b.schemaMatches(e=>{const r=e["x-search"];return(e.type==="string"||e.type==="object")&&typeof(r==null?void 0:r.service)=="string"&&r.service!==""})),Kt=(e,r)=>Ut(`${e}T${r}`).format(),Gt=({path:e,label:r,required:t,errors:s,description:c,children:l})=>{const i=s.length===0;return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:e,children:[r," ",t&&n.jsx(o.Text,{color:"red",children:"*"})]}),l,!i&&n.jsx(o.Text,{color:"red",size:"1",children:xe(s,r)}),c&&n.jsx(o.Text,{size:"1",color:"gray",children:c})]})})},nt=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,enabled:d,visible:a=!0})=>{if(y.useEffect(()=>{a===!1&&r(t,void 0)},[a,t,r]),a===!1)return null;const u=l.length===0,f=typeof e=="string"?e:"",m=T=>n.jsx(Gt,{path:t,label:s,required:c,errors:l,description:i.description,children:T});if(i.format==="time")return m(n.jsx(o.TextField.Root,{type:"time",value:f,onChange:T=>r(t,T.target.value),disabled:!d,color:u?void 0:"red",id:t}));const p=i.format==="date-time",[x="",g=""]=f.split("T"),F=g.slice(0,5),E=(T,O)=>{if(!T){r(t,void 0);return}r(t,p?Kt(T,O||"00:00"):T)};return m(n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(o.TextField.Root,{type:"date",value:x,disabled:!d,color:u?void 0:"red",onChange:T=>E(T.target.value,F),id:t,style:{flex:1}}),p&&n.jsx(o.TextField.Root,{type:"time",value:F,disabled:!d||!x,color:u?void 0:"red",onChange:T=>E(x,T.target.value),style:{flex:1}})]}))},ot=b.rankWith(2,b.or(b.isDateControl,b.isDateTimeControl,b.isTimeControl)),Yt=J.withJsonFormsControlProps(nt),st=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{const a=e.elements;return i===!1?null:n.jsx(o.Flex,{direction:"column",gap:"4",children:a.map((u,f)=>n.jsx(J.JsonFormsDispatch,{uischema:u,schema:r,path:t,renderers:s,cells:c,enabled:l},`${t}-${f}`))})},lt=b.rankWith(1,b.uiTypeIs("VerticalLayout")),it=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{const a=e.elements;return i===!1?null:n.jsx(o.Flex,{direction:"row",gap:"4",children:a.map((u,f)=>n.jsx(o.Box,{style:{flex:1},children:n.jsx(J.JsonFormsDispatch,{uischema:u,schema:r,path:t,renderers:s,cells:c,enabled:l})},`${t}-${f}`))})},at=b.rankWith(1,b.uiTypeIs("HorizontalLayout")),ct=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{const d=e,a=d.elements;return i===!1?null:n.jsxs(o.Box,{mb:"6",children:[d.label&&n.jsx(o.Heading,{size:"3",mb:"3",className:"text-gray-500 uppercase tracking-wide font-semibold",children:d.label}),n.jsx(o.Flex,{direction:"column",gap:"4",children:a.map((u,f)=>n.jsx(J.JsonFormsDispatch,{uischema:u,schema:r,path:t,renderers:s,cells:c,enabled:l},`${t}-${f}`))})]})},ut=b.rankWith(1,b.uiTypeIs("Group")),dt=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{var p;const a=e.elements.filter(x=>x.type==="Category"),[u,f]=y.useState(((p=a[0])==null?void 0:p.label)||"");if(i===!1||!a.length)return null;const m=a.find(x=>x.label===u)?u:a[0].label;return n.jsxs(o.Tabs.Root,{value:m,onValueChange:f,children:[n.jsx(o.Tabs.List,{children:a.map((x,g)=>n.jsx(o.Tabs.Trigger,{value:x.label,children:x.label},`${t}-${g}`))}),n.jsx(o.Box,{pt:"3",children:a.map((x,g)=>n.jsx(o.Tabs.Content,{value:x.label,children:n.jsx(o.Flex,{direction:"column",gap:"4",children:x.elements.map((F,E)=>n.jsx(J.JsonFormsDispatch,{uischema:F,schema:r,path:t,renderers:s,cells:c,enabled:l},`${t}-${g}-${E}`))})},`${t}-${g}`))})]})},ft=b.rankWith(1,b.uiTypeIs("Categorization"));function fe(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}function he(e){return e.split(",").map(r=>{if(r=r.trim(),r.endsWith("/*"))return r.split("/")[0].toUpperCase()+"S";if(r.startsWith("."))return r.slice(1).toUpperCase();const t=r.split("/")[1];return t?t.toUpperCase():r}).join(", ")}function qt(e){return e?Array.isArray(e)?e:[e]:[]}const Zt=({data:e,handleChange:r,path:t,label:s,required:c,uischema:l,schema:i,enabled:d,errors:a,visible:u=!0})=>{const f=_e();pe(u,t,r,null);const m=!a||a.length===0,p=(i==null?void 0:i["x-file"])??{},x=(l==null?void 0:l.options)??{},g=p.maxFiles??x.maxFiles??1,F=p.maxSize??x.maxSize??5*1024*1024,E=p.accept??x.accept??"image/*,application/pdf",T=g>1,O=d!==!1,[L,N]=y.useState(!1),[v,U]=y.useState(null),[P,S]=y.useState({}),R=y.useRef(new Set),B=y.useRef(null),W=qt(e),$=W.length>=g;y.useEffect(()=>()=>{R.current.forEach(h=>URL.revokeObjectURL(h)),R.current.clear()},[]);const V=y.useCallback(async h=>{if(U(null),W.length>=g){U(`Maximum ${g} file${g>1?"s":""} allowed.`);return}if(h.size>F){U(`File exceeds the ${fe(F)} limit.`);return}if(!E.split(",").map(A=>A.trim()).some(A=>A==="*"||A==="*/*"?!0:A.endsWith("/*")?h.type.startsWith(A.slice(0,-1)):A.startsWith(".")?h.name.toLowerCase().endsWith(A.toLowerCase()):h.type===A)){U(`Invalid type. Accepted: ${he(E)}`);return}if(!(f!=null&&f.onUpload)){U("Upload service not configured.");return}try{const A=await f.onUpload(h),M=URL.createObjectURL(h);R.current.add(M);const q={key:A.key,name:A.name??h.name,blobUrl:M};S(G=>({...G,[A.key]:q}));const oe=[...W,A.key];r(t,T?oe:oe[0])}catch{U("Upload failed. Please try again."),B.current&&(B.current.value="")}},[W,g,F,E,f,t,r,T]);if(u===!1)return null;const Q=h=>{h.preventDefault(),h.stopPropagation(),!(!O||$)&&N(h.type==="dragenter"||h.type==="dragover")},ee=h=>{var C;h.preventDefault(),h.stopPropagation(),N(!1),!(!O||$)&&(C=h.dataTransfer.files)!=null&&C[0]&&V(h.dataTransfer.files[0])},se=h=>{var C;(C=h.target.files)!=null&&C[0]&&(V(h.target.files[0]),h.target.value="")},ne=h=>{if(!O)return;S(X=>{var q;const A={...X},M=(q=A[h])==null?void 0:q.blobUrl;return M&&(URL.revokeObjectURL(M),R.current.delete(M)),delete A[h],A});const C=W.filter(X=>X!==h);r(t,T?C.length>0?C:null:C[0]??null)},le=async(h,C)=>{var M,q,oe;h.preventDefault();const X=(M=P[C])==null?void 0:M.blobUrl;if(X){(q=window.open(X,"_blank","noopener,noreferrer"))==null||q.focus();return}const A=window.open("","_blank");if(A)try{const G=await((oe=f==null?void 0:f.getDownloadUrl)==null?void 0:oe.call(f,C));G!=null&&G.url?A.location.href=G.url:A.close()}catch{A.close()}};if(!O&&W.length===0)return null;const ue=g-W.length,H=O&&!$;return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&n.jsx(o.Text,{color:"red",children:" *"})]}),n.jsx(o.Text,{size:"1",color:"gray",children:T?`Up to ${g} files · ${fe(F)} each · ${he(E)}`:`${fe(F)} · ${he(E)}`})]}),W.map(h=>{var C;return n.jsx(o.Card,{size:"2",variant:"surface",mb:"2",children:n.jsxs(o.Flex,{align:"center",gap:"3",children:[n.jsx(o.Box,{style:{background:"var(--blue-3)",padding:8,borderRadius:6,color:"var(--blue-9)",flexShrink:0},children:n.jsx(Y.FileTextIcon,{width:"20",height:"20"})}),n.jsx(o.Box,{style:{flex:1,overflow:"hidden"},children:n.jsx(o.Text,{size:"2",weight:"bold",style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((C=P[h])==null?void 0:C.name)??"Uploaded File"})}),n.jsxs(o.Flex,{align:"center",gap:"2",style:{flexShrink:0},children:[n.jsx(o.Button,{variant:"soft",color:"blue",size:"1",onClick:X=>le(X,h),children:"View"}),n.jsx(Y.CheckCircledIcon,{style:{color:"var(--green-9)",width:18,height:18}}),O&&n.jsx(o.IconButton,{variant:"ghost",color:"gray",onClick:()=>ne(h),children:n.jsx(Y.Cross2Icon,{})})]})]})},h)}),H&&n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{var h;return(h=B.current)==null?void 0:h.click()},onKeyDown:h=>{var C;(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),(C=B.current)==null||C.click())},onDragEnter:Q,onDragLeave:Q,onDragOver:Q,onDrop:ee,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",L?"border-blue-500 bg-blue-50":v?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:[n.jsx("input",{ref:B,type:"file",style:{display:"none"},accept:E,onChange:se}),n.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:v?n.jsxs(n.Fragment,{children:[n.jsx(Y.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:v}),n.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Y.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(o.Text,{size:"2",weight:"medium",children:W.length>0?`Add another file (${ue} remaining)`:"Click to upload or drag and drop"}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(F)," max · ",he(E)]})]})})]}),O&&$&&T&&n.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block",textAlign:"center"},children:["Maximum ",g," files uploaded. Remove one to replace it."]}),!m&&n.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:xe(a,s)})]})},ht=J.withJsonFormsControlProps(Zt),pt=b.rankWith(10,b.and(b.schemaMatches(e=>{if(e.type==="string"&&e.format==="file")return!0;if(e.type==="array"){const r=e.items;return(r==null?void 0:r.type)==="string"&&(r==null?void 0:r.format)==="file"}return!1})));function xt(e,r){return e!==!1&&r!==!0}class Ae extends Error{}function Qt(e,r){const t=Ne.read(e,{type:"array",cellDates:!0});if(t.SheetNames.length===0)throw new Ae("This file has no sheets.");const s=r??t.SheetNames[0],c=t.Sheets[s];if(!c)throw new Ae(`This file doesn't have a sheet named "${s}".`);const l=Ne.utils.sheet_to_json(c,{header:1,raw:!0,defval:null});return{sheetName:s,matrix:l,rowCount:l.length,colCount:Math.max(0,...l.map(i=>i.length))}}function er(e){let r=e+1,t="";for(;r>0;){const s=(r-1)%26;t=String.fromCharCode(65+s)+t,r=Math.floor((r-1)/26)}return t}class re extends Error{constructor(t,s){super(s??t);Ie(this,"code");this.code=t,this.name="FormulaError"}}const tr=["IFS","IFERROR","AND","OR","NOT","ROUND","ROUNDUP","ROUNDDOWN","INDEX","VLOOKUP","HLOOKUP","SUM","AVERAGE","COUNT","DATE","TODAY"],rr=["MAX","MIN","MAXA","MINA","MEDIAN","LARGE","SMALL","PERMUT","PERMUTATIONA","MATCH","SWITCH","SUBSTITUTE","TEXTJOIN","COUNTA","UPPER"],nr=["YEAR","MONTH","DAY","WEEKDAY"],or=["IF"],sr=["CONCATENATE","CONCAT","LEN","TRIM","LOWER","LEFT","RIGHT","MID","FIND","SEARCH"],lr=new Set([...tr,...rr,...nr,...sr,...or]),ir=/"(?:[^"]|"")*"/g,De=new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(","g");function ar(e){const r=e.replace(ir,s=>" ".repeat(s.length));De.lastIndex=0;let t;for(;(t=De.exec(r))!==null;){const s=t[1].toUpperCase();if(!lr.has(s))throw new re("NAME",`Function ${s} is not allowed.`)}}function cr(e,r,t){let s=e;if(s==null)throw t.NA;if(typeof s=="object"&&!(s instanceof t)&&(s=r.retrieveRef(s)),s instanceof t)throw s;if(typeof s=="boolean")return s;if(typeof s=="number")return s!==0;throw t.VALUE}function mt(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function Te(e){const r=mt(e);return Array.isArray(r)?r.flat(1/0):[r]}function I(e){const r=mt(e);return Array.isArray(r)?r.flat(1/0)[0]:r}function Ce(e){return e===void 0?void 0:I(e)}function te(e){return e==null||e===""?"":typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof Date?e.toLocaleDateString():String(e)}function ur(e,r){return e instanceof r?e:new r(e.message||"#ERROR!")}function K(e){return e.find(r=>r instanceof Error)}function dr(e,r){const t=l=>{throw ur(l,r)},s=(l,{checkArgsForErrors:i=!0}={})=>(...d)=>{const a=d.flatMap(Te);if(i){const f=K(a);f&&t(f)}const u=l(...a);return u instanceof Error?t(u):u},c=(l,{toText:i=!1}={})=>d=>{const a=I(d),u=K([a]);u&&t(u);const f=l(i?te(a):a);return f instanceof Error?t(f):f};return{IF:(l,i,d,a)=>{const u=cr(i,l,r);if(d==null)throw r.NA;return u?d:a??!1},MAX:s(e.MAX),MIN:s(e.MIN),MAXA:s(e.MAXA),MINA:s(e.MINA),MEDIAN:s(e.MEDIAN),COUNTA:s(e.COUNTA,{checkArgsForErrors:!1}),LARGE:(l,i)=>{const d=Te(l),a=I(i),u=K([...d,a]);u&&t(u);const f=e.LARGE(d,a);return f instanceof Error?t(f):f},SMALL:(l,i)=>{const d=Te(l),a=I(i),u=K([...d,a]);u&&t(u);const f=e.SMALL(d,a);return f instanceof Error?t(f):f},PERMUT:(l,i)=>{const d=[I(l),I(i)],a=K(d);a&&t(a);const u=e.PERMUT(d[0],d[1]);return u instanceof Error?t(u):u},PERMUTATIONA:(l,i)=>{const d=[I(l),I(i)],a=K(d);a&&t(a);const u=e.PERMUTATIONA(d[0],d[1]);return u instanceof Error?t(u):u},MATCH:(l,i)=>{const d=I(l),a=Te(i),u=K([d,...a]);u&&t(u);const f=e.MATCH(d,a,0);return f instanceof Error?t(f):f},SWITCH:(...l)=>{const i=l.map(I),d=K(i);d&&t(d);const a=e.SWITCH(...i);return a instanceof Error?t(a):a},SUBSTITUTE:(l,i,d,a)=>{const u=[te(I(l)),te(I(i)),te(I(d))];a!==void 0&&u.push(I(a));const f=K(u);f&&t(f);const m=e.SUBSTITUTE(...u);return m instanceof Error?t(m):m},TEXTJOIN:(l,i,...d)=>{const a=te(I(l)),u=I(i),f=d.flatMap(Te).map(te),m=K([a,u]);m&&t(m);const p=e.TEXTJOIN(a,u,f);return p instanceof Error?t(p):p},UPPER:c(e.UPPER),YEAR:c(e.YEAR),MONTH:c(e.MONTH),DAY:c(e.DAY),WEEKDAY:(l,i)=>{const d=I(l),a=I(i),u=K([d]);u&&t(u);const f=e.WEEKDAY(d,a);return f instanceof Error?t(f):f},CONCATENATE:(...l)=>{const i=l.flatMap(Te),d=K(i);d&&t(d);const a=e.CONCATENATE(...i.map(te));return a instanceof Error?t(a):a},CONCAT:(...l)=>{const i=l.flatMap(Te),d=K(i);d&&t(d);const a=e.CONCAT(...i.map(te));return a instanceof Error?t(a):a},LEN:c(e.LEN,{toText:!0}),TRIM:c(e.TRIM,{toText:!0}),LOWER:c(e.LOWER,{toText:!0}),LEFT:(l,i)=>{const d=I(l),a=Ce(i),u=K([d]);u&&t(u);const f=e.LEFT(te(d),a);return f instanceof Error?t(f):f},RIGHT:(l,i)=>{const d=I(l),a=Ce(i),u=K([d]);u&&t(u);const f=e.RIGHT(te(d),a);return f instanceof Error?t(f):f},MID:(l,i,d)=>{const a=I(l),u=I(i),f=I(d),m=K([a,u,f]);m&&t(m);const p=e.MID(te(a),u,f);return p instanceof Error?t(p):p},FIND:(l,i,d)=>{const a=I(l),u=I(i),f=Ce(d),m=K([a,u]);m&&t(m);const p=e.FIND(te(a),te(u),f);return p instanceof Error?t(p):p},SEARCH:(l,i,d)=>{const a=I(l),u=I(i),f=Ce(d),m=K([a,u]);m&&t(m);const p=e.SEARCH(te(a),te(u),f);return p instanceof Error?t(p):p}}}const fr={"#REF!":"REF","#VALUE!":"VALUE","#DIV/0!":"DIV0","#NAME?":"NAME","#N/A":"NA","#NUM!":"NUM","#NULL!":"NULL"};function Le(e){return fr[e.error]??"ERROR"}function Me(e,r){if(e instanceof re)return e;if(e instanceof r){const t=e.details;return t instanceof re?t:t instanceof r?new re(Le(t),t.message):new re(Le(e),e.message)}return new re("ERROR",e instanceof Error?e.message:void 0)}function hr(e){return Math.max(0,...e.map(r=>(r==null?void 0:r.length)??0))}function pr(e){return r=>{const t=e[r.row-1];if(r.row<1||r.col<1||t==null||r.col-1>=t.length)throw new re("REF");const s=t[r.col-1];return s==null||s===""?null:s}}function xr(e){return r=>{const t=Math.min(r.from.row,r.to.row),s=Math.min(r.from.col,r.to.col),c=Math.max(r.from.row,r.to.row),l=Math.max(r.from.col,r.to.col),i=hr(e);if(t>e.length||s>i)throw new re("REF");const d=Math.min(c,e.length),a=[];for(let u=t;u<=d;u++){const f=e[u-1],m=[];if(f!=null){const p=Math.min(l,f.length);for(let x=s;x<=p;x++){const g=f[x-1];m.push(g==null||g===""?null:g)}}a.push(m)}return a}}function mr(e){if(e==null||e==="")return null;if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date)return e;throw new re("VALUE")}async function gt(e,r){if(typeof e!="string")throw new re("ERROR");const t=e.trim();if(t==="")throw new re("ERROR");const s=t.startsWith("=")?t.slice(1):t;ar(s);const[c,l]=await Promise.all([import("fast-formula-parser"),import("@formulajs/formulajs")]),i=c.default??c,d=i.FormulaError,a=new i({...r,functions:dr(l,d)});let u;try{u=a.parse(s,{row:1,col:1,sheet:"Sheet1"})}catch(f){throw Me(f,d)}if(u instanceof d)throw Me(u,d);return mr(u)}async function gr(e,r){return gt(r,{onCell:pr(e),onRange:xr(e)})}const ze=-1;async function yt(e,r){const t=Object.keys(e);return gt(r,{onVariable:s=>{const c=t.indexOf(s);return c===-1?null:{row:ze,col:c+1}},onCell:s=>{if(s.row===ze)return e[t[s.col-1]]??null;throw new re("REF")},onRange:()=>{throw new re("REF")}})}const Tt={REF:"#REF!",VALUE:"#VALUE!",DIV0:"#DIV/0!",NAME:"#NAME?",ERROR:"#ERROR!",NA:"#N/A",NUM:"#NUM!",NULL:"#NULL!"};function ke(e){const r=e instanceof re?e.code:"ERROR";return Tt[r]}async function yr(e,r){return e.length===0?r.map(t=>({id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:Tt.ERROR})):Promise.all(r.map(async t=>{try{if(!t||typeof t.label!="string"||typeof t.expression!="string"||typeof t.id!="string")throw new re("ERROR");return{id:t.id,label:t.label,value:await gr(e,t.expression)}}catch(s){return{id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:ke(s)}}}))}function Tr(e,r={}){if(r.columnHeader&&r.rowHeader)throw new Error("x-spreadsheet: columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape.");return r.columnHeader?br(e):r.rowHeader?vr(e):e}function bt(e){return e==null||e===""?null:e instanceof Date?e.toISOString():String(e)}function vt(e,r){const t=new Set;for(const s of e)if(s!=null){if(t.has(s))throw new Error(`x-spreadsheet: duplicate ${r} value "${s}" — every ${r==="columnHeader"?"column header":"column-A value"} must be unique to shape as records.`);t.add(s)}}function br(e){const[r,...t]=e;if(!r)return[];const s=r.map(bt);return vt(s,"columnHeader"),t.map(c=>{const l=Object.create(null);return s.forEach((i,d)=>{i!=null&&(l[i]=c[d]??null)}),l})}function vr(e){const r=e.map(c=>bt(c[0]));vt(r,"rowHeader");const t=Math.max(0,...e.map(c=>c.length)),s=Math.max(0,t-1);return Array.from({length:s},(c,l)=>{const i=l+1,d=Object.create(null);return r.forEach((a,u)=>{a!=null&&(d[a]=e[u][i]??null)}),d})}function jr(e){return!Array.isArray(e[0])}function wr(e){const r=Object.create(null);for(const{id:t,label:s,value:c,error:l}of e)r[t]=l===void 0?{label:s,value:c}:{label:s,value:c,error:l};return r}function Fe(e,r){const t=s=>s instanceof Date?s.toISOString():s??null;return t(e)===t(r)}function Cr(e,r){const t=e??{},s=r??{},c=Object.keys(t);return c.length!==Object.keys(s).length?!1:c.every(l=>{if(!Object.prototype.hasOwnProperty.call(s,l))return!1;const i=t[l],d=s[l];return i.label===d.label&&i.error===d.error&&Fe(i.value,d.value)})}function Er(e,r){if(e==null||r==null)return e===r;const t=Array.isArray(e);if(t!==Array.isArray(r))return!1;if(t){const i=e,d=r;return i.length===d.length&&i.every((a,u)=>Fe(a,d[u]))}const s=e,c=r,l=Object.keys(s);return l.length!==Object.keys(c).length?!1:l.every(i=>Object.prototype.hasOwnProperty.call(c,i)&&Fe(s[i],c[i]))}function Rr(e,r){if(e===r)return!0;if(e==null||r==null)return!1;const t=e,s=r;return t.length!==s.length?!1:t.every((c,l)=>Er(c,s[l]))}function Sr(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e instanceof Date}function Ar(e){if(e.length===0)return[];const r=[],t=new Set;for(const c of e)for(const l of Object.keys(c))t.has(l)||(t.add(l),r.push(l));if(r.length===0)return[];const s=e.map(c=>r.map(l=>{if(!Object.prototype.hasOwnProperty.call(c,l))return null;const i=c[l];return Sr(i)?i:null}));return[r,...s]}function Fr(e){const r=Math.max(0,...e.map(t=>t.length));return Array.from({length:r},(t,s)=>e.map(c=>c[s]??null))}const Or=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv",kr=10*1024*1024,Se=200,Ir=50,Nr=[];function Ee(e){return e==null||e===""?"":e instanceof Date?e.toLocaleDateString():String(e)}const Dr=({data:e,handleChange:r,path:t,label:s,required:c,schema:l,enabled:i,readonly:d,errors:a,visible:u=!0})=>{pe(u,t,r,null);const f=!a||a.length===0,m=xt(i,d),p=(l==null?void 0:l["x-spreadsheet"])??{},x=(l==null?void 0:l["x-evaluate"])??Nr,g=p.accept??Or,F=p.maxSize??kr,E=p.columnHeader===!0,T=p.rowHeader===!0,O=p.showSheet!==!1,L=p.sheetName,N=p.persistSheet!==!1,v=e??null,[U,P]=y.useState(()=>v!=null&&v.sheet||Object.keys((v==null?void 0:v.derivations)??{}).length>0?"ready":"empty"),[S,R]=y.useState(null),[B,W]=y.useState(!1),[$,V]=y.useState(null),[Q,ee]=y.useState(null),se=y.useRef(null),ne=y.useRef(null),le=(v==null?void 0:v.sheet)??null,ue=y.useCallback(j=>{if(!jr(j))return j;const D=Ar(j);return T?Fr(D):D},[T]),H=y.useMemo(()=>$??(le?ue(le):null),[$,le,ue]),h=((Q==null?void 0:Q.matrix)===H?Q.derivations:null)??(v==null?void 0:v.derivations)??{},C=H!=null||v!=null,X=y.useMemo(()=>{const j=E?1:0,D=T?1:0,ce=H?H.slice(j):[],_=ce.slice(0,Se),z=Math.min(Ir,Math.max(0,..._.map(Z=>Math.max(0,Z.length-D)))),me=Array.from({length:z},(Z,ae)=>ae+D),w="",ie=T&&!E;return n.jsx(n.Fragment,{children:H&&O&&n.jsxs(o.Box,{mt:"3",children:[n.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:n.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[!ie&&n.jsx(o.Table.Header,{children:n.jsxs(o.Table.Row,{children:[n.jsx(o.Table.ColumnHeaderCell,{children:w}),me.map(Z=>{var ae;return n.jsx(o.Table.ColumnHeaderCell,{children:E?Ee((ae=H[0])==null?void 0:ae[Z]):er(Z)},Z)})]})}),n.jsx(o.Table.Body,{children:_.map((Z,ae)=>{var ve;const ye=j+ae;return n.jsxs(o.Table.Row,{children:[n.jsx(o.Table.RowHeaderCell,{style:T?{fontWeight:700,background:"var(--gray-a3)"}:void 0,children:T?Ee((ve=H[ye])==null?void 0:ve[0]):E?"":ye+1}),me.map(je=>n.jsx(o.Table.Cell,{children:Ee(Z[je])},je))]},ae)})})]})}),ce.length>Se&&n.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",Se," of ",ce.length," rows"]})]})})},[H,O,E,T]),A=y.useCallback(async j=>{if(R(null),j.size>F){R(`File exceeds the ${fe(F)} limit.`);return}if(!g.split(",").map(z=>z.trim()).some(z=>z==="*"||z==="*/*"?!0:z.endsWith("/*")?j.type.startsWith(z.slice(0,-1)):z.startsWith(".")?j.name.toLowerCase().endsWith(z.toLowerCase()):j.type===z)){R(`Invalid type. Accepted: ${he(g)}`);return}P("parsing");let _;try{const z=await j.arrayBuffer();_=Qt(z,L).matrix}catch(z){P("error"),R(z instanceof Ae?z.message:"This doesn't look like a valid spreadsheet. Please check the file and try again.");return}ne.current=(e==null?void 0:e.sheet)??null,V(_),P("ready")},[g,F,L,e]);if(y.useEffect(()=>{$!=null&&le!=null&&le!==ne.current&&V(null)},[$,le]),y.useEffect(()=>{if(x.length===0&&!N)return;let j=!1;const D=_=>{m&&(Cr(v==null?void 0:v.derivations,_==null?void 0:_.derivations)&&Rr(v==null?void 0:v.sheet,_==null?void 0:_.sheet)||(ne.current=(_==null?void 0:_.sheet)??null,r(t,_)))},ce=H??[];if(ce.length===0){v!=null&&D(void 0);return}return yr(ce,x).then(_=>{if(j)return;let z;if($!=null){if(N)try{z=Tr(ce,{columnHeader:E,rowHeader:T})}catch(w){R(w instanceof Error?w.message:"Failed to process this sheet.");return}}else z=v==null?void 0:v.sheet;R(null);const me=wr(_);ee({matrix:ce,derivations:me}),D(z===void 0?{derivations:me}:{sheet:z,derivations:me})}),()=>{j=!0}},[H,$,x,m,N,E,T]),u===!1)return null;if(E&&T)return n.jsxs(o.Box,{mb:"4",children:[n.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:s}),n.jsx(o.Text,{size:"2",color:"red",style:{display:"block"},children:"Invalid x-spreadsheet config: columnHeader and rowHeader cannot both be true — pick one orientation."})]});if(!m&&!C)return null;const M=j=>{j.preventDefault(),j.stopPropagation(),m&&W(j.type==="dragenter"||j.type==="dragover")},q=j=>{var D;j.preventDefault(),j.stopPropagation(),W(!1),m&&(D=j.dataTransfer.files)!=null&&D[0]&&A(j.dataTransfer.files[0])},oe=j=>{var D;(D=j.target.files)!=null&&D[0]&&(A(j.target.files[0]),j.target.value="")},G=()=>{m&&(V(null),ee(null),ne.current=null,R(null),P("empty"),r(t,null))},k=O&&H==null&&v!=null;return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(o.Flex,{align:"center",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&n.jsx(o.Text,{color:"red",children:" *"})]}),C&&m&&n.jsxs(n.Fragment,{children:[n.jsx(o.Tooltip,{content:"Replace spreadsheet",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var j;return(j=se.current)==null?void 0:j.click()},"aria-label":"Replace spreadsheet",children:n.jsx(Y.UploadIcon,{})})}),n.jsx(o.Tooltip,{content:"Remove spreadsheet",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:G,"aria-label":"Remove spreadsheet",children:n.jsx(Y.Cross2Icon,{})})})]})]}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(F)," max · ",he(g)]})]}),C&&S&&n.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:S}),n.jsx("input",{ref:se,type:"file",style:{display:"none"},accept:g,onChange:oe}),m&&!C&&n.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var j;return(j=se.current)==null?void 0:j.click()},onKeyDown:j=>{var D;(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),(D=se.current)==null||D.click())},onDragEnter:M,onDragLeave:M,onDragOver:M,onDrop:q,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",B?"border-blue-500 bg-blue-50":S?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:n.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:U==="parsing"?n.jsxs(n.Fragment,{children:[n.jsx(o.Spinner,{size:"3"}),n.jsx(o.Text,{size:"2",color:"gray",children:"Parsing spreadsheet…"})]}):S?n.jsxs(n.Fragment,{children:[n.jsx(Y.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:S}),n.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Y.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(F)," max · ",he(g)]})]})})}),X,k&&n.jsx(o.Text,{size:"2",color:"gray",mt:"3",style:{display:"block"},children:"Sheet preview not stored for this field — re-upload to view contents."}),Object.keys(h).length>0&&n.jsxs(o.Box,{mt:"3",children:[n.jsx(o.Text,{size:"2",weight:"bold",as:"div",mb:"1",children:"Computed values"}),n.jsx(o.Flex,{direction:"column",gap:"1",children:Object.entries(h).map(([j,D])=>n.jsxs(o.Flex,{justify:"between",children:[n.jsx(o.Text,{size:"2",children:D.label}),D.error?n.jsx(o.Text,{size:"2",color:"red",children:D.error}):n.jsx(o.Text,{size:"2",children:Ee(D.value)})]},j))})]}),!f&&n.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:xe(a,s)})]})},jt=J.withJsonFormsControlProps(Dr),wt=b.rankWith(10,b.schemaMatches(e=>e.type==="object"&&typeof e["x-spreadsheet"]=="object"));class ge extends Error{}const Ue=5e6,Lr=1024,Mr=/^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["']/i,zr={ignoreAttributes:!1,attributeNamePrefix:"@_",textNodeName:"#text",parseTagValue:!0,parseAttributeValue:!0,numberParseOptions:{hex:!1,leadingZeros:!1,eNotation:!0},trimValues:!0,cdataPropName:!1,commentPropName:!1,processEntities:!0,htmlEntities:!0,ignoreDeclaration:!0,ignorePiTags:!0,alwaysCreateTextNode:!1,preserveOrder:!1,removeNSPrefix:!1,maxNestedTags:100,strictReservedNames:!0};function Ur(e){const r=new Set(e);return r.size===0?()=>!1:(t,s)=>r.has(typeof s=="string"?s:s.toString())||r.has(t)}function Pr(e){const r=e instanceof Error?e.message:"";return r.startsWith("[SECURITY] Invalid name:")?"This document uses a reserved JavaScript name (__proto__, constructor or prototype) as an element or attribute name, which cannot be represented safely.":r==="External entities are not supported"||r==="Parameter entities are not supported"?`${r}. Please remove the DOCTYPE entity declarations and try again.`:r.startsWith("Maximum nested tags exceeded")?"This document is nested too deeply to parse.":r.startsWith("Entity count")||r.includes("exceeds maximum allowed")?"This document declares too many or too large entity definitions to expand safely.":"This doesn't look like a valid XML document. Please check the file and try again."}async function Br(e,r={}){var u;if(typeof e!="string")throw new ge("This file could not be read as text.");const t=e.charCodeAt(0)===65279?e.slice(1):e;if(t.trim()==="")throw new ge("This file is empty.");if(t.length>Ue)throw new ge(`This document is too large to parse (over ${Ue/1e6} million characters).`);const s=(u=Mr.exec(t.slice(0,Lr)))==null?void 0:u[1];if(s&&!/^utf-?8$/i.test(s))throw new ge(`This document declares the unsupported encoding "${s}". Only UTF-8 is supported.`);const{XMLParser:c,XMLValidator:l}=await import("fast-xml-parser"),i=l.validate(t,{allowBooleanAttributes:!1});if(i!==!0){const{msg:f,line:m,col:p}=i.err;throw new ge(`Invalid XML at line ${m}, column ${p}: ${f}`)}const d=new c({...zr,removeNSPrefix:r.removeNamespaces===!0,isArray:Ur(r.arrayPaths??[])});let a;try{a=d.parse(t)}catch(f){throw new ge(Pr(f))}if(a==null||typeof a!="object"||Array.isArray(a))throw new ge("This document has no root element.");return a}const be={found:!1},de=e=>({found:!0,value:e});function Pe(e){return e==null||e===""?be:Array.isArray(e)||e instanceof Date?de(e):typeof e=="object"?be:typeof e=="string"||typeof e=="number"||typeof e=="boolean"?de(e):be}const $r=new Set(["true","1","yes","y"]),_r=new Set(["false","0","no","n"]);async function Wr(e,r){switch(r.as){case void 0:return de(e);case"string":return de(e instanceof Date?e.toISOString():String(e));case"number":{const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?de(t):be}case"boolean":{const t=String(e).trim().toLowerCase();return $r.has(t)?de(!0):_r.has(t)?de(!1):be}case"date":{const{default:t}=await import("dayjs"),{default:s}=await Promise.resolve().then(()=>require("./customParseFormat-CLvZwox5.cjs")).then(i=>i.customParseFormat);t.extend(s);const c=e instanceof Date?e.toISOString():String(e),l=r.format?t(c,r.format,!0):t(c);return l.isValid()?de(l.format("YYYY-MM-DD")):be}}}async function Vr(e,r){if(r.formula!==void 0){const t={};for(const[s,c]of Object.entries(r.inputs??{})){const l=Pe(b.Resolve.data(e,c));if(!l.found||Array.isArray(l.value))return be;t[s]=l.value}try{return de(await yt(t,r.formula))}catch(s){throw new Error(`x-xml.writeTo "${r.to}": ${ke(s)}`)}}if(r.from===void 0)throw new Error(`x-xml.writeTo "${r.to}" needs either "from" or "formula".`);return Pe(b.Resolve.data(e,r.from))}async function Hr(e,r){const t=[];for(const s of r){let c=await Vr(e,s);const l=c.found&&Array.isArray(c.value);if(c.found&&!l&&s.map){const i=c.value instanceof Date?c.value.toISOString():String(c.value);Object.prototype.hasOwnProperty.call(s.map,i)&&(c=de(s.map[i]))}if(c.found&&!l&&(c=await Wr(c.value,s)),!c.found){if(s.default===void 0)continue;t.push({to:s.to,value:s.default});continue}t.push({to:s.to,value:c.value})}return t}const Xr=".xml,text/xml,application/xml",Jr=5*1024*1024,Kr=({data:e,handleChange:r,path:t,label:s,required:c,schema:l,enabled:i,readonly:d,errors:a,visible:u=!0})=>{pe(u,t,r);const f=!a||a.length===0,m=xt(i,d),p=(l==null?void 0:l["x-xml"])??{},x=p.accept??Xr,g=p.maxSize??Jr,F=p.arrayPaths,E=p.removeNamespaces===!0,T=p.writeTo,O=p.writeBase??"root",L=p.persistDocument!==!1,N=J.useJsonForms(),v=e??null,[U,P]=y.useState(()=>v?"ready":"empty"),[S,R]=y.useState(null),[B,W]=y.useState(!1),$=y.useRef(null),V=y.useRef(0),Q=v!=null,ee=T!==void 0&&T.length>0,se=y.useCallback(async h=>{var G;const C=++V.current;if(R(null),h.size>g){R(`File exceeds the ${fe(g)} limit.`);return}if(!x.split(",").map(k=>k.trim()).some(k=>k==="*"||k==="*/*"?!0:k.endsWith("/*")?h.type.startsWith(k.slice(0,-1)):k.startsWith(".")?h.name.toLowerCase().endsWith(k.toLowerCase()):h.type===k)){R(`Invalid type. Accepted: ${he(x)}`);return}P("parsing");let M;try{const k=await h.text();M=await Br(k,{arrayPaths:F,removeNamespaces:E})}catch(k){if(C!==V.current)return;P("error"),R(k instanceof ge?k.message:"This doesn't look like a valid XML document. Please check the file and try again.");return}let q=[];if(T&&T.length>0)try{q=await Hr(M,T)}catch(k){if(C!==V.current)return;P("error"),R(k instanceof Error?k.message:"This document could not be mapped onto the form.");return}if(C!==V.current)return;L&&r(t,M);const oe=O==="parent"?t.split(".").slice(0,-1).join("."):"";for(const k of q)(G=N.dispatch)==null||G.call(N,b.update(oe?`${oe}.${k.to}`:k.to,()=>k.value));P("ready")},[x,g,F,E,T,O,L,t,r,N]);if(u===!1||!m&&!Q)return null;const ne=h=>{h.preventDefault(),h.stopPropagation(),m&&W(h.type==="dragenter"||h.type==="dragover")},le=h=>{var C;h.preventDefault(),h.stopPropagation(),W(!1),m&&(C=h.dataTransfer.files)!=null&&C[0]&&se(h.dataTransfer.files[0])},ue=h=>{var C;(C=h.target.files)!=null&&C[0]&&(se(h.target.files[0]),h.target.value="")},H=()=>{m&&(++V.current,R(null),P("empty"),r(t,void 0))};return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(o.Flex,{align:"center",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&n.jsx(o.Text,{color:"red",children:" *"})]}),!ee&&Q&&m&&n.jsxs(n.Fragment,{children:[n.jsx(o.Tooltip,{content:"Replace document",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var h;return(h=$.current)==null?void 0:h.click()},"aria-label":"Replace document",children:n.jsx(Y.UploadIcon,{})})}),n.jsx(o.Tooltip,{content:"Remove document",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:H,"aria-label":"Remove document",children:n.jsx(Y.Cross2Icon,{})})})]})]}),n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(g)," max · ",he(x)]}),ee&&m&&n.jsxs(o.Button,{size:"1",variant:"soft",onClick:()=>{var h;return(h=$.current)==null?void 0:h.click()},disabled:U==="parsing",children:[U==="parsing"?n.jsx(o.Spinner,{size:"1"}):n.jsx(Y.UploadIcon,{}),"Upload"]})]})]}),(ee||Q)&&S&&n.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:S}),n.jsx("input",{ref:$,type:"file",style:{display:"none"},accept:x,onChange:ue}),!ee&&m&&!Q&&n.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var h;return(h=$.current)==null?void 0:h.click()},onKeyDown:h=>{var C;(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),(C=$.current)==null||C.click())},onDragEnter:ne,onDragLeave:ne,onDragOver:ne,onDrop:le,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",B?"border-blue-500 bg-blue-50":S?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:n.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:U==="parsing"?n.jsxs(n.Fragment,{children:[n.jsx(o.Spinner,{size:"3"}),n.jsx(o.Text,{size:"2",color:"gray",children:"Parsing document…"})]}):S?n.jsxs(n.Fragment,{children:[n.jsx(Y.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:S}),n.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Y.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(g)," max · ",he(x)]})]})})}),!f&&n.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:xe(a,s)})]})},Ct=J.withJsonFormsControlProps(Kr),Et=b.rankWith(10,b.schemaMatches(e=>{const r=e["x-xml"];return e.type==="object"&&typeof r=="object"&&r!==null}));function Gr(e,r,t){const s={};for(const[c,l]of Object.entries(t)){const{path:i,default:d}=typeof l=="string"?{path:l,default:void 0}:l,a=r?`${r}.${i}`:i,u=b.Resolve.data(e,a);if(u==null){if(d===void 0)return;s[c]=d}else s[c]=u}return s}async function Yr(e,r){try{return{status:"ok",value:await yt(e,r)}}catch(t){return{status:"error",error:ke(t)}}}function qr(e,r){return e==null?"":typeof e=="number"?e.toFixed(Zr(r)):e instanceof Date?e.toLocaleDateString():String(e)}function Zr(e){return Number.isFinite(e)?Math.min(100,Math.max(0,Math.trunc(e))):0}const Be="{value}",Qr=2,en={},tn=({data:e,handleChange:r,path:t,label:s,schema:c,visible:l=!0})=>{var U;pe(l,t,r,null);const i=c==null?void 0:c["x-computed"],d=(i==null?void 0:i.inputs)??en,a=(i==null?void 0:i.formula)??"",u=(i==null?void 0:i.format)??Be,f=(i==null?void 0:i.decimals)??Qr,m=J.useJsonForms(),p=t.split(".").slice(0,-1).join("."),x=Gr((U=m.core)==null?void 0:U.data,p,d),g=x?JSON.stringify(x):null,F=m.readonly===!0,[E,T]=y.useState(()=>typeof e=="number"?"ok":"unavailable"),[O,L]=y.useState(()=>typeof e=="number"?e:null),[N,v]=y.useState(null);return y.useEffect(()=>{if(!l)return;let P=!1;const S=R=>{F||R!==(e??null)&&r(t,R)};if(x===void 0){T("unavailable"),v(null),L(null),S(null);return}return T(R=>R==="ok"?R:"loading"),Yr(x,a).then(R=>{if(P)return;const B=R.status==="ok"&&typeof R.value=="number"&&Number.isFinite(R.value)?R.value:null;if(B===null){T("error"),v(R.status==="error"?R.error??"Unable to compute value.":"Computed value must be a number."),L(null),S(null);return}T("ok"),v(null),L(B),S(B)}),()=>{P=!0}},[g,a,l,F]),l===!1?null:n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:s}),E==="unavailable"?n.jsx(o.Text,{size:"2",color:"gray",children:"Not yet available."}):E==="loading"?n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsx(o.Spinner,{size:"1"}),n.jsx(o.Text,{size:"2",color:"gray",children:"Computing…"})]}):E==="error"?n.jsx(o.Text,{size:"2",color:"red",children:N}):n.jsx(o.Text,{size:"2",children:u.split(Be).join(qr(O,f))}),c.description&&n.jsx(o.Text,{size:"1",color:"gray",children:c.description})]})})},Rt=J.withJsonFormsControlProps(tn),St=b.rankWith(5,b.schemaMatches(e=>{const r=e["x-computed"];return e.type==="number"&&typeof r=="object"&&r!==null})),rn=({data:e,path:r,schema:t,uischema:s,enabled:c,visible:l,addItem:i,removeItems:d,rootSchema:a,arraySchema:u})=>{const f=u?t:t.items,m=u||t;if(l===!1||!f||typeof f!="object"||Array.isArray(f))return null;const p=f,x=Array.isArray(e)?e:[],g=m.title||"Array Items",F=s.options??{},E=c&&F.addable!==!1,T=c&&F.removable!==!1,O=()=>{const N=b.createDefaultValue(p,a);i&&i(r,N)()},L=N=>{if(d){const v=d(r,[N]);v&&v()}};return n.jsx(o.Box,{mb:"6",children:n.jsxs(o.Flex,{direction:"column",gap:"4",children:[n.jsx(o.Text,{as:"div",size:"4",weight:"bold",children:g}),x.length===0&&n.jsx(o.Box,{py:"4",px:"4",style:{backgroundColor:"var(--gray-3)",borderRadius:"var(--radius-3)"},children:n.jsx(o.Text,{size:"2",color:"gray",children:"No items have been added yet."})}),x.map((N,v)=>{var P;const U=`${r}.${v}`;return n.jsx(o.Card,{size:"3",variant:"surface",children:n.jsxs(o.Flex,{direction:"column",gap:"4",children:[n.jsxs(o.Flex,{justify:"between",align:"center",children:[n.jsxs(o.Text,{size:"3",weight:"bold",children:["Item ",v+1]}),T&&n.jsxs(o.Button,{type:"button",color:"red",variant:"soft",onClick:()=>L(v),title:"Remove item",children:[n.jsx(Y.TrashIcon,{}),"Remove"]})]}),n.jsx(o.Box,{children:n.jsx(J.JsonFormsDispatch,{schema:p,uischema:((P=s.options)==null?void 0:P.detail)||(p.type==="object"||p.properties?{type:"VerticalLayout",elements:Object.keys(p.properties||{}).map(S=>({type:"Control",scope:`#/properties/${S}`}))}:{type:"Control",scope:"#"}),path:U,enabled:c,renderers:void 0,cells:void 0})})]})},U)}),E&&n.jsx(o.Box,{mt:"2",children:n.jsxs(o.Button,{type:"button",variant:"surface",onClick:O,children:[n.jsx(Y.PlusIcon,{}),"Add Item"]})})]})})},Oe=J.withJsonFormsArrayControlProps(rn),At=b.rankWith(3,b.isObjectArrayControl),Ft=({uischema:e,visible:r})=>{const t=e;return r===!1?null:n.jsx(o.Box,{mb:"4",children:n.jsx(o.Heading,{size:"4",children:t.text})})},Ot=b.rankWith(1,b.uiTypeIs("Label")),nn=b.rankWith(3,b.isPrimitiveArrayControl),on=[{tester:Xe,renderer:$t},{tester:Ke,renderer:_t},{tester:Ye,renderer:Wt},{tester:Ze,renderer:Vt},{tester:rt,renderer:tt},{tester:et,renderer:Ht},{tester:ot,renderer:Yt},{tester:lt,renderer:st},{tester:at,renderer:it},{tester:ut,renderer:ct},{tester:ft,renderer:dt},{tester:pt,renderer:ht},{tester:wt,renderer:jt},{tester:Et,renderer:Ct},{tester:St,renderer:Rt},{tester:At,renderer:Oe},{tester:nn,renderer:Oe},{tester:Ot,renderer:Ft}];exports.ArrayControl=Oe;exports.ArrayControlTester=At;exports.BooleanControl=Ge;exports.BooleanControlTester=Ye;exports.CategorizationLayoutRenderer=dt;exports.CategorizationLayoutTester=ft;exports.ComputedControl=Rt;exports.ComputedControlTester=St;exports.DateControl=nt;exports.DateControlTester=ot;exports.FileControl=ht;exports.FileControlTester=pt;exports.GroupLayoutRenderer=ct;exports.GroupLayoutTester=ut;exports.HorizontalLayoutRenderer=it;exports.HorizontalLayoutTester=at;exports.LabelRenderer=Ft;exports.LabelTester=Ot;exports.NumberControl=Je;exports.NumberControlTester=Ke;exports.RadioControl=qe;exports.RadioControlTester=Ze;exports.SearchSelectControl=tt;exports.SearchSelectControlTester=rt;exports.SearchServiceProvider=Bt;exports.SelectControl=Qe;exports.SelectControlTester=et;exports.SpreadsheetControl=jt;exports.SpreadsheetControlTester=wt;exports.TextControl=He;exports.TextControlTester=Xe;exports.UploadProvider=Pt;exports.VerticalLayoutRenderer=st;exports.VerticalLayoutTester=lt;exports.XmlControl=Ct;exports.XmlControlTester=Et;exports.radixRenderers=on;exports.useSearchService=Ve;exports.useUpload=_e;
3
+ `):"",lt=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,uischema:l,schema:c,enabled:u,visible:f=!0})=>{var h;if(me(f,t,r),f===!1)return null;const d=i.length===0;return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[o," ",a&&n.jsx(s.Text,{color:"red",children:"*"})]}),n.jsx(s.TextField.Root,{value:e||"",onChange:p=>r(t,p.target.value),disabled:!u,placeholder:(h=l.options)==null?void 0:h.placeholder,color:d?void 0:"red",id:t}),!d&&n.jsx(s.Text,{color:"red",size:"1",children:fe(i,o)}),c.description&&n.jsx(s.Text,{size:"1",color:"gray",children:c.description})]})})},at=v.rankWith(1,v.isStringControl),fr=H.withJsonFormsControlProps(lt),ct=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,uischema:l,schema:c,enabled:u,visible:f=!0})=>{var p;if(me(f,t,r),f===!1)return null;const d=i.length===0,h=m=>{if(m===""){r(t,void 0);return}const y=Number(m);isNaN(y)||r(t,y)};return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[o," ",a&&n.jsx(s.Text,{color:"red",children:"*"})]}),n.jsx(s.TextField.Root,{type:"number",value:e??"",onChange:m=>h(m.target.value),disabled:!u,placeholder:(p=l.options)==null?void 0:p.placeholder,color:d?void 0:"red",id:t}),!d&&n.jsx(s.Text,{color:"red",size:"1",children:fe(i,o)}),c.description&&n.jsx(s.Text,{size:"1",color:"gray",children:c.description})]})})},ut=v.rankWith(2,v.or(v.isNumberControl,v.isIntegerControl)),pr=H.withJsonFormsControlProps(ct),dt=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,schema:l,enabled:c,visible:u=!0})=>{if(me(u,t,r),u===!1)return null;const f=i.length===0;return n.jsxs(s.Box,{mb:"4",children:[n.jsxs(s.Flex,{gap:"2",align:"center",children:[n.jsx(s.Checkbox,{checked:!!e,onCheckedChange:d=>r(t,d===!0),disabled:!c,id:t}),n.jsxs(s.Text,{as:"label",size:"2",htmlFor:t,children:[o," ",a&&"*"]})]}),!f&&n.jsx(s.Text,{color:"red",size:"1",className:"block mt-1",children:fe(i,o)}),l.description&&n.jsx(s.Text,{size:"1",color:"gray",className:"block mt-1",children:l.description})]})},ft=v.rankWith(2,v.isBooleanControl),hr=H.withJsonFormsControlProps(dt),pt=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,schema:l,enabled:c,visible:u=!0})=>{if(me(u,t,r),u===!1)return null;const f=i.length===0;let d=[];l.enum?d=l.enum.map(p=>({value:p,label:String(p)})):l.oneOf&&(d=l.oneOf.map(p=>({value:p.const,label:p.title||String(p.const)})));const h=e;return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"div",size:"2",weight:"bold",children:[o," ",a&&n.jsx(s.Text,{color:"red",children:"*"})]}),n.jsx(s.RadioGroup.Root,{value:h!==void 0?String(h):"",onValueChange:p=>{const m=d.find(y=>String(y.value)===p);m&&r(t,m.value)},disabled:!c,children:n.jsx(s.Flex,{direction:"row",style:{flexWrap:"wrap",columnGap:"clamp(14px, 3vw, 36px)",rowGap:"clamp(8px, 1.6vw, 14px)"},children:d.map(p=>n.jsxs(s.Flex,{align:"center",gap:"2",style:{minWidth:"max-content"},children:[n.jsx(s.RadioGroup.Item,{value:String(p.value)}),n.jsx(s.Text,{size:"2",color:c?void 0:"gray",children:p.label})]},String(p.value)))})}),!f&&n.jsx(s.Text,{color:"red",size:"1",children:fe(i,o)}),l.description&&n.jsx(s.Text,{size:"1",color:"gray",children:l.description})]})})},ht=(e,r,t)=>{var a;return v.or(v.isEnumControl,v.isOneOfControl)(e,r,t)&&((a=e==null?void 0:e.options)==null?void 0:a.format)==="radio"?3:-1},xr=H.withJsonFormsControlProps(pt),xt=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,schema:l,uischema:c,enabled:u,visible:f=!0})=>{var F,M,D;me(f,t,r);const d=((F=c.options)==null?void 0:F.autocomplete)===!0,[h,p]=g.useState(!1),[m,y]=g.useState(""),[k,A]=g.useState(0),w=g.useRef(null);if(g.useEffect(()=>{if(!d||!h)return;const b=j=>{w.current&&!w.current.contains(j.target)&&p(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[d,h]),f===!1)return null;const E=i.length===0;let O=[];l.enum?O=l.enum.map(b=>({value:String(b),label:String(b)})):l.oneOf&&(O=l.oneOf.map(b=>({value:String(b.const),label:b.title||String(b.const)})));const N=e!==void 0?String(e):"",I=((M=c.options)==null?void 0:M.placeholder)||"Select an option";if(d){const b=((D=O.find(S=>S.value===N))==null?void 0:D.label)??"",j=h?O.filter(S=>S.label.toLowerCase().includes(m.toLowerCase())):O,V=Math.min(k,j.length-1),X=S=>{r(t,S.value),p(!1)},G=S=>{S.stopPropagation(),r(t,void 0),y("")},L=S=>{(S.key==="Enter"||S.key===" ")&&G(S)};return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[o," ",a&&n.jsx(s.Text,{color:"red",children:"*"})]}),n.jsxs("div",{ref:w,style:{position:"relative"},children:[n.jsx(s.TextField.Root,{id:t,value:h?m:b,placeholder:I,disabled:!u,style:E?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:S=>{y(S.target.value),A(0),h||p(!0)},onFocus:()=>{u&&!h&&(y(""),A(0),p(!0))},onKeyDown:S=>{S.key==="Escape"?p(!1):S.key==="ArrowDown"?(S.preventDefault(),h?A(J=>Math.min(J+1,j.length-1)):(y(""),p(!0))):S.key==="ArrowUp"?(S.preventDefault(),h&&A(J=>Math.max(J-1,0))):S.key==="Enter"&&h&&j[V]&&(S.preventDefault(),X(j[V]))},children:n.jsx(s.TextField.Slot,{side:"right",children:n.jsxs(s.Flex,{align:"center",gap:"1",children:[N&&u&&n.jsx("span",{role:"button",tabIndex:0,onMouseDown:S=>S.preventDefault(),onClick:G,onKeyDown:L,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),n.jsx(Z.ChevronDownIcon,{style:{transform:h?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),h&&n.jsx(s.Box,{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:50,background:"var(--color-panel-solid)",borderRadius:"var(--radius-3)",boxShadow:"var(--shadow-5)",border:"1px solid var(--gray-a6)",overflow:"hidden"},children:n.jsx(s.ScrollArea,{style:{maxHeight:240},children:n.jsxs(s.Box,{p:"1",children:[j.length===0&&n.jsx(s.Box,{px:"3",py:"2",children:n.jsx(s.Text,{size:"2",color:"gray",children:"No results found."})}),j.map((S,J)=>n.jsx(s.Box,{px:"3",py:"2",onMouseDown:Q=>Q.preventDefault(),onClick:()=>X(S),onMouseEnter:()=>A(J),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:J===V?"var(--accent-4)":S.value===N?"var(--accent-3)":void 0},children:n.jsx(s.Text,{size:"2",children:S.label})},S.value))]})})})]}),!E&&n.jsx(s.Text,{color:"red",size:"1",children:fe(i,o)}),l.description&&n.jsx(s.Text,{size:"1",color:"gray",children:l.description})]})})}return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[o," ",a&&n.jsx(s.Text,{color:"red",children:"*"})]}),n.jsxs(s.Select.Root,{value:N,onValueChange:b=>r(t,b),disabled:!u,children:[n.jsx(s.Select.Trigger,{placeholder:I,color:E?void 0:"red",id:t}),n.jsx(s.Select.Content,{children:O.map(b=>n.jsx(s.Select.Item,{value:b.value,children:b.label},b.value))})]}),!E&&n.jsx(s.Text,{color:"red",size:"1",children:fe(i,o)}),l.description&&n.jsx(s.Text,{size:"1",color:"gray",children:l.description})]})})},mt=v.rankWith(2,v.or(v.isEnumControl,v.isOneOfControl)),mr=H.withJsonFormsControlProps(xt),gt=/\{([A-Za-z0-9_]+)(?:\(([^(){}]*)\))?\}/g,gr={today:e=>rt().format(e||"YYYY-MM-DD")},yr=e=>typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="bigint",We=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);function ze(e,r,t={}){const o={...gr,...t};return e.replace(gt,(a,i,l)=>{let c;if(l===void 0){if(!We(r,i))return a;c=r[i]}else{if(!We(o,i))return a;try{c=o[i](l)}catch{return a}}return c==null?"":yr(c)?String(c):a})}function Pe(e){const r=[];let t=0;for(const o of e.matchAll(gt))o.index>t&&r.push(e.slice(t,o.index)),r.push(o[2]===void 0?{name:o[1]}:{name:o[1],arg:o[2]}),t=o.index+o[0].length;return t<e.length&&r.push(e.slice(t)),r}function br(e){if(typeof e=="string"&&e.length>0)return e;if(e&&typeof e=="object"&&typeof e.value=="string"){const r=e.value;return r.length>0?r:void 0}}function vr(e){if(typeof e=="string")return e.length>0?{parent:e}:void 0;if(!e||typeof e!="object")return;const r=Object.entries(e);if(r.length===0)return;const t={},o=[];for(const[a,i]of r)typeof i=="string"&&i.length>0?t[a]=i:o.push(a);return o.length>0&&console.warn(`x-search.dependsOn: ignoring invalid entries [${o.join(", ")}]`),Object.keys(t).length===0?(console.warn("x-search.dependsOn: map has no valid entries; search will not fetch until fixed"),{}):t}function Tr(e,r,t){const o={};for(const[a,i]of Object.entries(e))o[a]=br(v.Resolve.data(r,t?`${t}.${i}`:i));return o}function He(e,r){return r?{...e,name:ze(r,e)}:e}const jr={"small-list":{fetchOnOpen:!0,searchable:!1,paginated:!1},"large-searchable-list":{fetchOnOpen:!0,searchable:!0,paginated:!1},"large-paginated-list":{fetchOnOpen:!1,searchable:!0,paginated:!0}},wr=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,enabled:l,visible:c=!0,schema:u,uischema:f})=>{var Fe,ce;const d=(u==null?void 0:u["x-search"])??{service:"",displayTemplate:""},h=d.service??"",p=d.mode??"large-paginated-list",m=jr[p],y=(m==null?void 0:m.fetchOnOpen)??!1,k=typeof d.displayTemplate=="string"?d.displayTemplate:"",A=H.useJsonForms(),w=t.split(".").slice(0,-1).join("."),{parentValues:E,parentValuesKey:O,missingParent:N}=g.useMemo(()=>{var ue;const T=vr(d.dependsOn);if(!T)return{parentValues:void 0,parentValuesKey:"",missingParent:!1};const Y=Tr(T,(ue=A.core)==null?void 0:ue.data,w),re=Object.keys(Y).length===0||Object.values(Y).some(Se=>!Se);return{parentValues:Y,parentValuesKey:JSON.stringify(Y),missingParent:re}},[d.dependsOn,(Fe=A.core)==null?void 0:Fe.data,w]),I=g.useMemo(()=>E?{...d.params,...E}:d.params,[E,O,d.params]),F=it(h),M=u.type==="object",D=M?typeof e=="string"?{value:e}:e??void 0:void 0,b=M?D==null?void 0:D.value:e,j=D==null?void 0:D.label,V=h?F?m?k?null:"x-search.displayTemplate is required.":`Invalid x-search.mode "${p}". Expected "small-list", "large-searchable-list", or "large-paginated-list".`:`Search service "${h}" is not registered.`:"Search not configured.",X=l!==!1,G=!i||i.length===0,[L,S]=g.useState(!1),[J,Q]=g.useState(""),[pe,ne]=g.useState([]),[ge,x]=g.useState(!1),[R,K]=g.useState(!1),[z,U]=g.useState(!1),[te,q]=g.useState(null),[oe,P]=g.useState(void 0),ae=g.useRef(void 0),Te=g.useRef(null),Re=g.useRef(null),Ae=g.useRef(null),ye=g.useRef(void 0),C=g.useRef(void 0);g.useEffect(()=>{if(!E)return;const T=C.current;if(C.current=E,!T||!b)return;Object.keys(E).some(re=>T[re]!==void 0&&T[re]!==E[re])&&r(t,M?void 0:null)},[O,b,r,t,M]),g.useEffect(()=>{var Y,re;if(V){P(void 0),ye.current=void 0;return}if(!b){P(void 0),ye.current=void 0;return}if(((Y=ye.current)==null?void 0:Y.value)===b&&((re=ye.current)==null?void 0:re.label)===j)return;if(ye.current={value:b,label:j},M&&j){P({id:b,name:j});return}if(P({id:b,name:j??b}),!(F!=null&&F.resolve))return;let T=!1;return F.resolve(b,I).then(ue=>{!T&&ue&&P(He(ue,k))}).catch(()=>{}),()=>{T=!0}},[V,b,j,M,F,I,k]);const B=g.useCallback(async(T,Y=!1)=>{var ue;if(V)return;if(!F){q("Search service not configured.");return}(ue=Re.current)==null||ue.abort();const re=new AbortController;Re.current=re,Y?U(!0):(K(!0),U(!1),q(null));try{const Se=await F.search({query:T,cursor:Y?ae.current:void 0,signal:re.signal,params:I});if(re.signal.aborted)return;const _e=(Se.options??[]).map(ke=>He(ke,k));ne(Y?ke=>[...ke,..._e]:_e),ae.current=Se.nextCursor,x(((m==null?void 0:m.paginated)??!1)&&Se.nextCursor!=null)}catch{if(re.signal.aborted)return;q("Failed to load results. Please try again.")}finally{re.signal.aborted||(Y?U(!1):K(!1))}},[V,F,m==null?void 0:m.paginated,I,k]);if(g.useEffect(()=>{if(!L)return;const T=Y=>{Ae.current&&!Ae.current.contains(Y.target)&&S(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[L]),g.useEffect(()=>{var T;L||((T=Re.current)==null||T.abort(),Q(""),ne([]),x(!1),q(null),K(!1),U(!1),ae.current=void 0)},[L]),g.useEffect(()=>{if(!L)return;if(N){ne([]),x(!1),q(null),ae.current=void 0;return}if(!J&&!y){ne([]),x(!1),q(null),ae.current=void 0;return}Te.current&&clearTimeout(Te.current);const T=J?300:0;return Te.current=setTimeout(()=>{ne([]),x(!1),ae.current=void 0,B(J)},T),()=>{Te.current&&clearTimeout(Te.current)}},[J,L,y,B,N,O]),me(c,t,r),c===!1)return null;const se=()=>{Q(""),ne([]),x(!1),q(null),ae.current=void 0,S(!0)},W=T=>{r(t,M?{value:T.id,label:T.name}:T.id),P(T),ye.current={value:T.id,label:M?T.name:void 0},S(!1)},$=T=>{T.stopPropagation(),r(t,void 0),P(void 0)},be=T=>{(T.key==="Enter"||T.key===" ")&&$(T)},Ce=((ce=f==null?void 0:f.options)==null?void 0:ce.placeholder)??"Select an option";return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[o," ",a&&n.jsx(s.Text,{color:"red",children:"*"})]}),n.jsxs("div",{ref:Ae,style:{position:"relative"},children:[n.jsx(s.TextField.Root,{id:t,value:L?J:(oe==null?void 0:oe.name)??"",placeholder:L&&(m!=null&&m.searchable)?"Search...":Ce,disabled:!X,readOnly:L&&!(m!=null&&m.searchable),style:G?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:T=>{m!=null&&m.searchable&&(Q(T.target.value),L||se())},onFocus:()=>{X&&!L&&se()},onKeyDown:T=>{T.key==="Escape"&&S(!1)},children:n.jsx(s.TextField.Slot,{side:"right",children:n.jsxs(s.Flex,{align:"center",gap:"1",children:[b&&X&&n.jsx("span",{role:"button",tabIndex:0,onMouseDown:T=>T.preventDefault(),onClick:$,onKeyDown:be,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),n.jsx(Z.ChevronDownIcon,{style:{transform:L?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),L&&n.jsx(s.Box,{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:50,background:"var(--color-panel-solid)",borderRadius:"var(--radius-3)",boxShadow:"var(--shadow-5)",border:"1px solid var(--gray-a6)",overflow:"hidden"},children:V?n.jsx(s.Box,{p:"3",children:n.jsx(s.Text,{size:"2",color:"gray",children:V})}):n.jsx(s.ScrollArea,{style:{maxHeight:240},children:n.jsxs(s.Box,{p:"1",children:[R&&n.jsx(s.Flex,{justify:"center",p:"4",children:n.jsx(s.Spinner,{})}),!R&&te&&n.jsx(s.Box,{px:"3",py:"2",children:n.jsx(s.Text,{size:"2",color:"red",children:te})}),!R&&!te&&pe.length===0&&n.jsx(s.Box,{px:"3",py:"2",children:n.jsx(s.Text,{size:"2",color:"gray",children:N?"Select the related field first.":J||y?"No results found.":"Type to search…"})}),pe.map(T=>n.jsx(s.Box,{px:"3",py:"2",onMouseDown:Y=>Y.preventDefault(),onClick:()=>W(T),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:T.id===b?"var(--accent-3)":void 0},className:"hover:bg-(--gray-3)",children:n.jsx(s.Text,{size:"2",children:T.name})},T.id)),(m==null?void 0:m.paginated)&&ge&&!z&&n.jsx(s.Box,{px:"3",py:"2",children:n.jsx(s.Button,{variant:"ghost",size:"1",style:{width:"100%"},onMouseDown:T=>T.preventDefault(),onClick:()=>void B(J,!0),children:"Load more"})}),z&&n.jsx(s.Flex,{justify:"center",p:"2",children:n.jsx(s.Spinner,{})})]})})})]}),!G&&n.jsx(s.Text,{color:"red",size:"1",children:fe(i,o)}),u.description&&n.jsx(s.Text,{size:"1",color:"gray",children:u.description})]})})},yt=H.withJsonFormsControlProps(wr),bt=v.rankWith(3,v.schemaMatches(e=>{const r=e["x-search"];return(e.type==="string"||e.type==="object")&&typeof(r==null?void 0:r.service)=="string"&&r.service!==""})),Er=(e,r)=>rt(`${e}T${r}`).format(),Cr=({path:e,label:r,required:t,errors:o,description:a,children:i})=>{const l=o.length===0;return n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",htmlFor:e,children:[r," ",t&&n.jsx(s.Text,{color:"red",children:"*"})]}),i,!l&&n.jsx(s.Text,{color:"red",size:"1",children:fe(o,r)}),a&&n.jsx(s.Text,{size:"1",color:"gray",children:a})]})})},vt=({data:e,handleChange:r,path:t,label:o,required:a,errors:i,schema:l,enabled:c,visible:u=!0})=>{if(g.useEffect(()=>{u===!1&&r(t,void 0)},[u,t,r]),u===!1)return null;const f=i.length===0,d=typeof e=="string"?e:"",h=w=>n.jsx(Cr,{path:t,label:o,required:a,errors:i,description:l.description,children:w});if(l.format==="time")return h(n.jsx(s.TextField.Root,{type:"time",value:d,onChange:w=>r(t,w.target.value),disabled:!c,color:f?void 0:"red",id:t}));const p=l.format==="date-time",[m="",y=""]=d.split("T"),k=y.slice(0,5),A=(w,E)=>{if(!w){r(t,void 0);return}r(t,p?Er(w,E||"00:00"):w)};return h(n.jsxs(s.Flex,{gap:"2",align:"center",children:[n.jsx(s.TextField.Root,{type:"date",value:m,disabled:!c,color:f?void 0:"red",onChange:w=>A(w.target.value,k),id:t,style:{flex:1}}),p&&n.jsx(s.TextField.Root,{type:"time",value:k,disabled:!c||!m,color:f?void 0:"red",onChange:w=>A(m,w.target.value),style:{flex:1}})]}))},Tt=v.rankWith(2,v.or(v.isDateControl,v.isDateTimeControl,v.isTimeControl)),Sr=H.withJsonFormsControlProps(vt),jt=({uischema:e,schema:r,path:t,renderers:o,cells:a,enabled:i,visible:l=!0})=>{const u=e.elements;return l===!1?null:n.jsx(s.Flex,{direction:"column",gap:"4",children:u.map((f,d)=>n.jsx(H.JsonFormsDispatch,{uischema:f,schema:r,path:t,renderers:o,cells:a,enabled:i},`${t}-${d}`))})},wt=v.rankWith(1,v.uiTypeIs("VerticalLayout")),Et=({uischema:e,schema:r,path:t,renderers:o,cells:a,enabled:i,visible:l=!0})=>{const u=e.elements;return l===!1?null:n.jsx(s.Flex,{direction:"row",gap:"4",children:u.map((f,d)=>n.jsx(s.Box,{style:{flex:1},children:n.jsx(H.JsonFormsDispatch,{uischema:f,schema:r,path:t,renderers:o,cells:a,enabled:i})},`${t}-${d}`))})},Ct=v.rankWith(1,v.uiTypeIs("HorizontalLayout")),St=({uischema:e,schema:r,path:t,renderers:o,cells:a,enabled:i,visible:l=!0})=>{const c=e,u=c.elements;return l===!1?null:n.jsxs(s.Box,{mb:"6",children:[c.label&&n.jsx(s.Heading,{size:"3",mb:"3",className:"text-gray-500 uppercase tracking-wide font-semibold",children:c.label}),n.jsx(s.Flex,{direction:"column",gap:"4",children:u.map((f,d)=>n.jsx(H.JsonFormsDispatch,{uischema:f,schema:r,path:t,renderers:o,cells:a,enabled:i},`${t}-${d}`))})]})},Rt=v.rankWith(1,v.uiTypeIs("Group")),At=({uischema:e,schema:r,path:t,renderers:o,cells:a,enabled:i,visible:l=!0})=>{var p;const u=e.elements.filter(m=>m.type==="Category"),[f,d]=g.useState(((p=u[0])==null?void 0:p.label)||"");if(l===!1||!u.length)return null;const h=u.find(m=>m.label===f)?f:u[0].label;return n.jsxs(s.Tabs.Root,{value:h,onValueChange:d,children:[n.jsx(s.Tabs.List,{children:u.map((m,y)=>n.jsx(s.Tabs.Trigger,{value:m.label,children:m.label},`${t}-${y}`))}),n.jsx(s.Box,{pt:"3",children:u.map((m,y)=>n.jsx(s.Tabs.Content,{value:m.label,children:n.jsx(s.Flex,{direction:"column",gap:"4",children:m.elements.map((k,A)=>n.jsx(H.JsonFormsDispatch,{uischema:k,schema:r,path:t,renderers:o,cells:a,enabled:i},`${t}-${y}-${A}`))})},`${t}-${y}`))})]})},Ft=v.rankWith(1,v.uiTypeIs("Categorization"));function he(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}function xe(e){const r=e.split(",").map(i=>i.trim()).filter(Boolean),t=r.filter(i=>i.startsWith(".")),a=(t.length>0?t:r).map(i=>{if(i.endsWith("/*"))return i.split("/")[0].toUpperCase()+"S";if(i.startsWith("."))return i.slice(1).toUpperCase();const l=i.split("/")[1];return l?l.toUpperCase():i});return[...new Set(a)].join(", ")}function Rr(e){return e?Array.isArray(e)?e:[e]:[]}const Ar=({data:e,handleChange:r,path:t,label:o,required:a,uischema:i,schema:l,enabled:c,errors:u,visible:f=!0})=>{const d=ot();me(f,t,r);const h=!u||u.length===0,p=(l==null?void 0:l["x-file"])??{},m=(i==null?void 0:i.options)??{},y=p.maxFiles??m.maxFiles??1,k=p.maxSize??m.maxSize??5*1024*1024,A=p.accept??m.accept??"image/*,application/pdf",w=y>1,E=c!==!1,[O,N]=g.useState(!1),[I,F]=g.useState(null),[M,D]=g.useState({}),b=g.useRef(new Set),j=g.useRef(null),V=Rr(e),X=V.length>=y;g.useEffect(()=>()=>{b.current.forEach(x=>URL.revokeObjectURL(x)),b.current.clear()},[]);const G=g.useCallback(async x=>{if(F(null),V.length>=y){F(`Maximum ${y} file${y>1?"s":""} allowed.`);return}if(x.size>k){F(`File exceeds the ${he(k)} limit.`);return}if(!A.split(",").map(z=>z.trim()).some(z=>z==="*"||z==="*/*"?!0:z.endsWith("/*")?x.type.startsWith(z.slice(0,-1)):z.startsWith(".")?x.name.toLowerCase().endsWith(z.toLowerCase()):x.type===z)){F(`Invalid type. Accepted: ${xe(A)}`);return}if(!(d!=null&&d.onUpload)){F("Upload service not configured.");return}try{const z=await d.onUpload(x),U=URL.createObjectURL(x);b.current.add(U);const te={key:z.key,name:z.name??x.name,blobUrl:U};D(oe=>({...oe,[z.key]:te}));const q=[...V,z.key];r(t,w?q:q[0])}catch{F("Upload failed. Please try again."),j.current&&(j.current.value="")}},[V,y,k,A,d,t,r,w]);if(f===!1)return null;const L=x=>{x.preventDefault(),x.stopPropagation(),!(!E||X)&&N(x.type==="dragenter"||x.type==="dragover")},S=x=>{var R;x.preventDefault(),x.stopPropagation(),N(!1),!(!E||X)&&(R=x.dataTransfer.files)!=null&&R[0]&&G(x.dataTransfer.files[0])},J=x=>{var R;(R=x.target.files)!=null&&R[0]&&(G(x.target.files[0]),x.target.value="")},Q=x=>{if(!E)return;D(K=>{var te;const z={...K},U=(te=z[x])==null?void 0:te.blobUrl;return U&&(URL.revokeObjectURL(U),b.current.delete(U)),delete z[x],z});const R=V.filter(K=>K!==x);r(t,w?R.length>0?R:void 0:R[0])},pe=async(x,R)=>{var U,te,q;x.preventDefault();const K=(U=M[R])==null?void 0:U.blobUrl;if(K){(te=window.open(K,"_blank","noopener,noreferrer"))==null||te.focus();return}const z=window.open("","_blank");if(z)try{const oe=await((q=d==null?void 0:d.getDownloadUrl)==null?void 0:q.call(d,R));oe!=null&&oe.url?z.location.href=oe.url:z.close()}catch{z.close()}};if(!E&&V.length===0)return null;const ne=y-V.length,ge=E&&!X;return n.jsxs(s.Box,{mb:"4",children:[n.jsxs(s.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",children:[o,a&&n.jsx(s.Text,{color:"red",children:" *"})]}),n.jsx(s.Text,{size:"1",color:"gray",children:w?`Up to ${y} files · ${he(k)} each · ${xe(A)}`:`${he(k)} · ${xe(A)}`})]}),V.map(x=>{var R;return n.jsx(s.Card,{size:"2",variant:"surface",mb:"2",children:n.jsxs(s.Flex,{align:"center",gap:"3",children:[n.jsx(s.Box,{style:{background:"var(--blue-3)",padding:8,borderRadius:6,color:"var(--blue-9)",flexShrink:0},children:n.jsx(Z.FileTextIcon,{width:"20",height:"20"})}),n.jsx(s.Box,{style:{flex:1,overflow:"hidden"},children:n.jsx(s.Text,{size:"2",weight:"bold",style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((R=M[x])==null?void 0:R.name)??"Uploaded File"})}),n.jsxs(s.Flex,{align:"center",gap:"2",style:{flexShrink:0},children:[n.jsx(s.Button,{variant:"soft",color:"blue",size:"1",onClick:K=>pe(K,x),children:"View"}),n.jsx(Z.CheckCircledIcon,{style:{color:"var(--green-9)",width:18,height:18}}),E&&n.jsx(s.IconButton,{variant:"ghost",color:"gray",onClick:()=>Q(x),children:n.jsx(Z.Cross2Icon,{})})]})]})},x)}),ge&&n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{var x;return(x=j.current)==null?void 0:x.click()},onKeyDown:x=>{var R;(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),(R=j.current)==null||R.click())},onDragEnter:L,onDragLeave:L,onDragOver:L,onDrop:S,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",O?"border-blue-500 bg-blue-50":I?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:[n.jsx("input",{ref:j,type:"file",style:{display:"none"},accept:A,onChange:J}),n.jsx(s.Flex,{direction:"column",align:"center",gap:"2",children:I?n.jsxs(n.Fragment,{children:[n.jsx(Z.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(s.Text,{size:"2",color:"red",weight:"medium",children:I}),n.jsx(s.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Z.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(s.Text,{size:"2",weight:"medium",children:V.length>0?`Add another file (${ne} remaining)`:"Click to upload or drag and drop"}),n.jsxs(s.Text,{size:"1",color:"gray",children:[he(k)," max · ",xe(A)]})]})})]}),E&&X&&w&&n.jsxs(s.Text,{size:"1",color:"gray",mt:"1",style:{display:"block",textAlign:"center"},children:["Maximum ",y," files uploaded. Remove one to replace it."]}),!h&&n.jsx(s.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:fe(u,o)})]})},Ot=H.withJsonFormsControlProps(Ar),kt=v.rankWith(10,v.and(v.schemaMatches(e=>{if(e.type==="string"&&e.format==="file")return!0;if(e.type==="array"){const r=e.items;return(r==null?void 0:r.type)==="string"&&(r==null?void 0:r.format)==="file"}return!1})));function It(e,r){return e!==!1&&r!==!0}class De extends Error{}async function Fr(e,r){const{read:t,utils:o}=await import("@e965/xlsx"),a=t(e,{type:"array",cellDates:!0});if(a.SheetNames.length===0)throw new De("This file has no sheets.");const i=r??a.SheetNames[0],l=a.Sheets[i];if(!l)throw new De(`This file doesn't have a sheet named "${i}".`);const c=o.sheet_to_json(l,{header:1,raw:!0,defval:null});return{sheetName:i,matrix:c,rowCount:c.length,colCount:Math.max(0,...c.map(u=>u.length))}}function Or(e){let r=e+1,t="";for(;r>0;){const o=(r-1)%26;t=String.fromCharCode(65+o)+t,r=Math.floor((r-1)/26)}return t}class le extends Error{constructor(t,o){super(o??t);Ve(this,"code");this.code=t,this.name="FormulaError"}}const kr=["IFS","IFERROR","AND","OR","NOT","ROUND","ROUNDUP","ROUNDDOWN","INDEX","VLOOKUP","HLOOKUP","SUM","AVERAGE","COUNT","DATE","TODAY"],Ir=["MAX","MIN","MAXA","MINA","MEDIAN","LARGE","SMALL","PERMUT","PERMUTATIONA","MATCH","SWITCH","SUBSTITUTE","TEXTJOIN","COUNTA","UPPER"],Nr=["YEAR","MONTH","DAY","WEEKDAY"],Dr=["IF"],Lr=["CONCATENATE","CONCAT","LEN","TRIM","LOWER","LEFT","RIGHT","MID","FIND","SEARCH"],Mr=new Set([...kr,...Ir,...Nr,...Lr,...Dr]),zr=/"(?:[^"]|"")*"/g,Xe=new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(","g");function Pr(e){const r=e.replace(zr,o=>" ".repeat(o.length));Xe.lastIndex=0;let t;for(;(t=Xe.exec(r))!==null;){const o=t[1].toUpperCase();if(!Mr.has(o))throw new le("NAME",`Function ${o} is not allowed.`)}}function Ur(e,r,t){let o=e;if(o==null)throw t.NA;if(typeof o=="object"&&!(o instanceof t)&&(o=r.retrieveRef(o)),o instanceof t)throw o;if(typeof o=="boolean")return o;if(typeof o=="number")return o!==0;throw t.VALUE}function Nt(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function we(e){const r=Nt(e);return Array.isArray(r)?r.flat(1/0):[r]}function _(e){const r=Nt(e);return Array.isArray(r)?r.flat(1/0)[0]:r}function Oe(e){return e===void 0?void 0:_(e)}function ie(e){return e==null||e===""?"":typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof Date?e.toLocaleDateString():String(e)}function Br(e,r){return e instanceof r?e:new r(e.message||"#ERROR!")}function ee(e){return e.find(r=>r instanceof Error)}function $r(e,r){const t=i=>{throw Br(i,r)},o=(i,{checkArgsForErrors:l=!0}={})=>(...c)=>{const u=c.flatMap(we);if(l){const d=ee(u);d&&t(d)}const f=i(...u);return f instanceof Error?t(f):f},a=(i,{toText:l=!1}={})=>c=>{const u=_(c),f=ee([u]);f&&t(f);const d=i(l?ie(u):u);return d instanceof Error?t(d):d};return{IF:(i,l,c,u)=>{const f=Ur(l,i,r);if(c==null)throw r.NA;return f?c:u??!1},MAX:o(e.MAX),MIN:o(e.MIN),MAXA:o(e.MAXA),MINA:o(e.MINA),MEDIAN:o(e.MEDIAN),COUNTA:o(e.COUNTA,{checkArgsForErrors:!1}),LARGE:(i,l)=>{const c=we(i),u=_(l),f=ee([...c,u]);f&&t(f);const d=e.LARGE(c,u);return d instanceof Error?t(d):d},SMALL:(i,l)=>{const c=we(i),u=_(l),f=ee([...c,u]);f&&t(f);const d=e.SMALL(c,u);return d instanceof Error?t(d):d},PERMUT:(i,l)=>{const c=[_(i),_(l)],u=ee(c);u&&t(u);const f=e.PERMUT(c[0],c[1]);return f instanceof Error?t(f):f},PERMUTATIONA:(i,l)=>{const c=[_(i),_(l)],u=ee(c);u&&t(u);const f=e.PERMUTATIONA(c[0],c[1]);return f instanceof Error?t(f):f},MATCH:(i,l)=>{const c=_(i),u=we(l),f=ee([c,...u]);f&&t(f);const d=e.MATCH(c,u,0);return d instanceof Error?t(d):d},SWITCH:(...i)=>{const l=i.map(_),c=ee(l);c&&t(c);const u=e.SWITCH(...l);return u instanceof Error?t(u):u},SUBSTITUTE:(i,l,c,u)=>{const f=[ie(_(i)),ie(_(l)),ie(_(c))];u!==void 0&&f.push(_(u));const d=ee(f);d&&t(d);const h=e.SUBSTITUTE(...f);return h instanceof Error?t(h):h},TEXTJOIN:(i,l,...c)=>{const u=ie(_(i)),f=_(l),d=c.flatMap(we).map(ie),h=ee([u,f]);h&&t(h);const p=e.TEXTJOIN(u,f,d);return p instanceof Error?t(p):p},UPPER:a(e.UPPER),YEAR:a(e.YEAR),MONTH:a(e.MONTH),DAY:a(e.DAY),WEEKDAY:(i,l)=>{const c=_(i),u=_(l),f=ee([c]);f&&t(f);const d=e.WEEKDAY(c,u);return d instanceof Error?t(d):d},CONCATENATE:(...i)=>{const l=i.flatMap(we),c=ee(l);c&&t(c);const u=e.CONCATENATE(...l.map(ie));return u instanceof Error?t(u):u},CONCAT:(...i)=>{const l=i.flatMap(we),c=ee(l);c&&t(c);const u=e.CONCAT(...l.map(ie));return u instanceof Error?t(u):u},LEN:a(e.LEN,{toText:!0}),TRIM:a(e.TRIM,{toText:!0}),LOWER:a(e.LOWER,{toText:!0}),LEFT:(i,l)=>{const c=_(i),u=Oe(l),f=ee([c]);f&&t(f);const d=e.LEFT(ie(c),u);return d instanceof Error?t(d):d},RIGHT:(i,l)=>{const c=_(i),u=Oe(l),f=ee([c]);f&&t(f);const d=e.RIGHT(ie(c),u);return d instanceof Error?t(d):d},MID:(i,l,c)=>{const u=_(i),f=_(l),d=_(c),h=ee([u,f,d]);h&&t(h);const p=e.MID(ie(u),f,d);return p instanceof Error?t(p):p},FIND:(i,l,c)=>{const u=_(i),f=_(l),d=Oe(c),h=ee([u,f]);h&&t(h);const p=e.FIND(ie(u),ie(f),d);return p instanceof Error?t(p):p},SEARCH:(i,l,c)=>{const u=_(i),f=_(l),d=Oe(c),h=ee([u,f]);h&&t(h);const p=e.SEARCH(ie(u),ie(f),d);return p instanceof Error?t(p):p}}}const _r={"#REF!":"REF","#VALUE!":"VALUE","#DIV/0!":"DIV0","#NAME?":"NAME","#N/A":"NA","#NUM!":"NUM","#NULL!":"NULL"};function Je(e){return _r[e.error]??"ERROR"}function Ke(e,r){if(e instanceof le)return e;if(e instanceof r){const t=e.details;return t instanceof le?t:t instanceof r?new le(Je(t),t.message):new le(Je(e),e.message)}return new le("ERROR",e instanceof Error?e.message:void 0)}function Vr(e){return Math.max(0,...e.map(r=>(r==null?void 0:r.length)??0))}function Wr(e){return r=>{const t=e[r.row-1];if(r.row<1||r.col<1||t==null||r.col-1>=t.length)throw new le("REF");const o=t[r.col-1];return o==null||o===""?null:o}}function Hr(e){return r=>{const t=Math.min(r.from.row,r.to.row),o=Math.min(r.from.col,r.to.col),a=Math.max(r.from.row,r.to.row),i=Math.max(r.from.col,r.to.col),l=Vr(e);if(t>e.length||o>l)throw new le("REF");const c=Math.min(a,e.length),u=[];for(let f=t;f<=c;f++){const d=e[f-1],h=[];if(d!=null){const p=Math.min(i,d.length);for(let m=o;m<=p;m++){const y=d[m-1];h.push(y==null||y===""?null:y)}}u.push(h)}return u}}function Xr(e){if(e==null||e==="")return null;if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date)return e;throw new le("VALUE")}async function Dt(e,r){if(typeof e!="string")throw new le("ERROR");const t=e.trim();if(t==="")throw new le("ERROR");const o=t.startsWith("=")?t.slice(1):t;Pr(o);const[a,i]=await Promise.all([import("fast-formula-parser"),import("@formulajs/formulajs")]),l=a.default??a,c=l.FormulaError,u=new l({...r,functions:$r(i,c)});let f;try{f=u.parse(o,{row:1,col:1,sheet:"Sheet1"})}catch(d){throw Ke(d,c)}if(f instanceof c)throw Ke(f,c);return Xr(f)}async function Jr(e,r){return Dt(r,{onCell:Wr(e),onRange:Hr(e)})}const qe=-1;async function Lt(e,r){const t=Object.keys(e);return Dt(r,{onVariable:o=>{const a=t.indexOf(o);return a===-1?null:{row:qe,col:a+1}},onCell:o=>{if(o.row===qe)return e[t[o.col-1]]??null;throw new le("REF")},onRange:()=>{throw new le("REF")}})}const Mt={REF:"#REF!",VALUE:"#VALUE!",DIV0:"#DIV/0!",NAME:"#NAME?",ERROR:"#ERROR!",NA:"#N/A",NUM:"#NUM!",NULL:"#NULL!"};function Ue(e){const r=e instanceof le?e.code:"ERROR";return Mt[r]}async function Kr(e,r){return e.length===0?r.map(t=>({id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:Mt.ERROR})):Promise.all(r.map(async t=>{try{if(!t||typeof t.label!="string"||typeof t.expression!="string"||typeof t.id!="string")throw new le("ERROR");return{id:t.id,label:t.label,value:await Jr(e,t.expression)}}catch(o){return{id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:Ue(o)}}}))}function Ge(e){const r=new Set;for(const{id:t}of e){if(r.has(t))return t;r.add(t)}return null}function zt(e){const{columnHeader:r,rowHeader:t,columns:o,rows:a}=e;if(o!==void 0&&!Array.isArray(o))return"columns must be an array of { id, label } objects.";if(a!==void 0&&!Array.isArray(a))return"rows must be an array of { id, label } objects.";if(o!==void 0&&o.length===0)return"columns is declared but empty — declare at least one field, or omit it entirely for raw matrix mode.";if(a!==void 0&&a.length===0)return"rows is declared but empty — declare at least one field, or omit it entirely for raw matrix mode.";const i=d=>!!d&&typeof d.id=="string"&&d.id!==""&&typeof d.label=="string"&&d.label!=="",l=o==null?void 0:o.findIndex(d=>!i(d));if(l!=null&&l!==-1)return`columns[${l}] must be a { id, label } object with non-empty string fields.`;const c=a==null?void 0:a.findIndex(d=>!i(d));if(c!=null&&c!==-1)return`rows[${c}] must be a { id, label } object with non-empty string fields.`;const u=!!o&&o.length>0,f=!!a&&a.length>0;if(u){const d=Ge(o);if(d)return`duplicate column id "${d}" — every declared column id must be unique.`}if(f){const d=Ge(a);if(d)return`duplicate row id "${d}" — every declared row id must be unique.`}return r&&t?"columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape.":u&&f?"columns and rows cannot both be declared — pick one orientation for the persisted sheet shape.":r&&!u?"columnHeader is true but columns is missing or empty — declare the column list columnHeader positions map to.":t&&!f?"rowHeader is true but rows is missing or empty — declare the row list rowHeader positions map to.":null}function Ye(e,r={}){const t=zt(r);if(t)throw new Error(`x-spreadsheet: ${t}`);const{columnHeader:o,rowHeader:a,columns:i,rows:l}=r;return i&&i.length>0?qr(e,i,o===!0):l&&l.length>0?Gr(e,l,a===!0):e}function qr(e,r,t){return(t?e.slice(1):e).map(a=>{const i=Object.create(null);return r.forEach((l,c)=>{i[l.id]=a[c]??null}),i})}function Gr(e,r,t){const o=t?1:0,a=Math.max(0,...e.map(l=>l.length)),i=Math.max(0,a-o);return Array.from({length:i},(l,c)=>{const u=o+c,f=Object.create(null);return r.forEach((d,h)=>{var p;f[d.id]=((p=e[h])==null?void 0:p[u])??null}),f})}function Pt(e){return!Array.isArray(e[0])}function Yr(e){const r=Object.create(null);for(const{id:t,label:o,value:a,error:i}of e)r[t]=i===void 0?{label:o,value:a}:{label:o,value:a,error:i};return r}function Le(e,r){const t=o=>o instanceof Date?o.toISOString():o??null;return t(e)===t(r)}function Zr(e,r){const t=e??{},o=r??{},a=Object.keys(t);return a.length!==Object.keys(o).length?!1:a.every(i=>{if(!Object.prototype.hasOwnProperty.call(o,i))return!1;const l=t[i],c=o[i];return l.label===c.label&&l.error===c.error&&Le(l.value,c.value)})}function Qr(e,r){if(e==null||r==null)return e===r;const t=Array.isArray(e);if(t!==Array.isArray(r))return!1;if(t){const l=e,c=r;return l.length===c.length&&l.every((u,f)=>Le(u,c[f]))}const o=e,a=r,i=Object.keys(o);return i.length!==Object.keys(a).length?!1:i.every(l=>Object.prototype.hasOwnProperty.call(a,l)&&Le(o[l],a[l]))}function en(e,r){if(e===r)return!0;if(e==null||r==null)return!1;const t=e,o=r;return t.length!==o.length?!1:t.every((a,i)=>Qr(a,o[i]))}function tn(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e instanceof Date}function Ut(e,r){if(e.length===0)return[];const t=[],o=new Set;for(const i of r??[])o.has(i)||(o.add(i),t.push(i));for(const i of e)for(const l of Object.keys(i))o.has(l)||(o.add(l),t.push(l));if(t.length===0)return[];const a=e.map(i=>t.map(l=>{if(!Object.prototype.hasOwnProperty.call(i,l))return null;const c=i[l];return tn(c)?c:null}));return[t,...a]}function rn(e){const r=Math.max(0,...e.map(t=>t.length));return Array.from({length:r},(t,o)=>e.map(a=>a[o]??null))}const nn=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv",on=10*1024*1024,Ne=200,sn=50,ln=[];function Ze(e){return e==null||e===""?"":e instanceof Date?e.toLocaleDateString():String(e)}const an=({data:e,handleChange:r,path:t,label:o,required:a,schema:i,enabled:l,readonly:c,errors:u,visible:f=!0})=>{me(f,t,r);const d=!u||u.length===0,h=It(l,c),p=(i==null?void 0:i["x-spreadsheet"])??{},m=(i==null?void 0:i["x-evaluate"])??ln,y=p.accept??nn,k=p.maxSize??on,A=p.columnHeader===!0,w=p.rowHeader===!0,E=p.columns,O=p.rows,N=Array.isArray(E)&&E.length>0,I=Array.isArray(O)&&O.length>0,F=zt({columnHeader:A,rowHeader:w,columns:E,rows:O}),M=p.showSheet!==!1,D=p.sheetName,b=p.persistSheet!==!1,j=e??null,[V,X]=g.useState(()=>j!=null&&j.sheet||Object.keys((j==null?void 0:j.derivations)??{}).length>0?"ready":"empty"),[G,L]=g.useState(null),[S,J]=g.useState(!1),[Q,pe]=g.useState(null),[ne,ge]=g.useState(null),x=g.useRef(null),R=g.useRef(null),K=(j==null?void 0:j.sheet)??null,z=g.useCallback(C=>{if(!Pt(C))return C;const B=I?O:N?E:void 0,se=Ut(C,B==null?void 0:B.map(W=>W.id));return I?rn(se):se},[N,I,E,O]),U=g.useMemo(()=>Q??(K?z(K):null),[Q,K,z]),te=((ne==null?void 0:ne.matrix)===U?ne.derivations:null)??(j==null?void 0:j.derivations)??{},q=U!=null||j!=null,oe=g.useMemo(()=>{const C=N?1:0,B=I?1:0,se=U?U.slice(C):[],W=se.slice(0,Ne),$=Math.min(sn,Math.max(0,...W.map(ce=>Math.max(0,ce.length-B)))),be=Array.from({length:$},(ce,T)=>T+B),Ce="",Fe=I&&!N;return n.jsx(n.Fragment,{children:U&&M&&n.jsxs(s.Box,{mt:"3",children:[n.jsx(s.Box,{style:{overflow:"auto",maxHeight:420},children:n.jsxs(s.Table.Root,{variant:"surface",size:"1",children:[!Fe&&n.jsx(s.Table.Header,{children:n.jsxs(s.Table.Row,{children:[n.jsx(s.Table.ColumnHeaderCell,{children:Ce}),be.map(ce=>{var T;return n.jsx(s.Table.ColumnHeaderCell,{children:N?((T=E==null?void 0:E[ce])==null?void 0:T.label)??"":Or(ce)},ce)})]})}),n.jsx(s.Table.Body,{children:W.map((ce,T)=>{var re;const Y=C+T;return n.jsxs(s.Table.Row,{children:[n.jsx(s.Table.RowHeaderCell,{style:I?{fontWeight:700,background:"var(--gray-a3)"}:void 0,children:I?((re=O==null?void 0:O[Y])==null?void 0:re.label)??"":N?"":Y+1}),be.map(ue=>n.jsx(s.Table.Cell,{children:Ze(ce[ue])},ue))]},T)})})]})}),se.length>Ne&&n.jsxs(s.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",Ne," of ",se.length," rows"]})]})})},[U,M,N,I,E,O]),P=g.useCallback(async C=>{if(L(null),C.size>k){L(`File exceeds the ${he(k)} limit.`);return}if(!y.split(",").map($=>$.trim()).some($=>$==="*"||$==="*/*"?!0:$.endsWith("/*")?C.type.startsWith($.slice(0,-1)):$.startsWith(".")?C.name.toLowerCase().endsWith($.toLowerCase()):C.type===$)){L(`Invalid type. Accepted: ${xe(y)}`);return}X("parsing");let W;try{const $=await C.arrayBuffer();W=(await Fr($,D)).matrix}catch($){X("error"),L($ instanceof De?$.message:"This doesn't look like a valid spreadsheet. Please check the file and try again.");return}if(N||I)try{W=z(Ye(W,{columnHeader:A,rowHeader:w,columns:E,rows:O}))}catch($){X("error"),L($ instanceof Error?$.message:"Failed to process this sheet.");return}R.current=(e==null?void 0:e.sheet)??null,pe(W),X("ready")},[y,k,D,e,A,w,E,O,N,I,z]);if(g.useEffect(()=>{Q!=null&&K!=null&&K!==R.current&&pe(null)},[Q,K]),g.useEffect(()=>{if(F||m.length===0&&!b)return;let C=!1;const B=W=>{h&&(Zr(j==null?void 0:j.derivations,W==null?void 0:W.derivations)&&en(j==null?void 0:j.sheet,W==null?void 0:W.sheet)||(R.current=(W==null?void 0:W.sheet)??null,r(t,W)))},se=U??[];if(se.length===0){j!=null&&B(void 0);return}return Kr(se,m).then(W=>{if(C)return;let $;if(Q!=null){if(b)try{$=Ye(se,{columnHeader:N,rowHeader:I,columns:E,rows:O})}catch(Ce){L(Ce instanceof Error?Ce.message:"Failed to process this sheet.");return}}else $=j==null?void 0:j.sheet;L(null);const be=Yr(W);ge({matrix:se,derivations:be}),B($===void 0?{derivations:be}:{sheet:$,derivations:be})}),()=>{C=!0}},[U,Q,m,h,b,N,I,E,O,F]),f===!1)return null;if(F)return n.jsxs(s.Box,{mb:"4",children:[n.jsx(s.Text,{as:"label",size:"2",weight:"bold",children:o}),n.jsxs(s.Text,{size:"2",color:"red",style:{display:"block"},children:["Invalid x-spreadsheet config: ",F]})]});if(!h&&!q)return null;const ae=C=>{C.preventDefault(),C.stopPropagation(),h&&J(C.type==="dragenter"||C.type==="dragover")},Te=C=>{var B;C.preventDefault(),C.stopPropagation(),J(!1),h&&(B=C.dataTransfer.files)!=null&&B[0]&&P(C.dataTransfer.files[0])},Re=C=>{var B;(B=C.target.files)!=null&&B[0]&&(P(C.target.files[0]),C.target.value="")},Ae=()=>{h&&(pe(null),ge(null),R.current=null,L(null),X("empty"),r(t,void 0))},ye=M&&U==null&&j!=null;return n.jsxs(s.Box,{mb:"4",children:[n.jsxs(s.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(s.Flex,{align:"center",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",children:[o,a&&n.jsx(s.Text,{color:"red",children:" *"})]}),q&&h&&n.jsxs(n.Fragment,{children:[n.jsx(s.Tooltip,{content:"Replace spreadsheet",children:n.jsx(s.IconButton,{variant:"ghost",size:"1",onClick:()=>{var C;return(C=x.current)==null?void 0:C.click()},"aria-label":"Replace spreadsheet",children:n.jsx(Z.UploadIcon,{})})}),n.jsx(s.Tooltip,{content:"Remove spreadsheet",children:n.jsx(s.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:Ae,"aria-label":"Remove spreadsheet",children:n.jsx(Z.Cross2Icon,{})})})]})]}),n.jsxs(s.Text,{size:"1",color:"gray",children:[he(k)," max · ",xe(y)]})]}),q&&G&&n.jsx(s.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:G}),n.jsx("input",{ref:x,type:"file",style:{display:"none"},accept:y,onChange:Re}),h&&!q&&n.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var C;return(C=x.current)==null?void 0:C.click()},onKeyDown:C=>{var B;(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),(B=x.current)==null||B.click())},onDragEnter:ae,onDragLeave:ae,onDragOver:ae,onDrop:Te,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",S?"border-blue-500 bg-blue-50":G?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:n.jsx(s.Flex,{direction:"column",align:"center",gap:"2",children:V==="parsing"?n.jsxs(n.Fragment,{children:[n.jsx(s.Spinner,{size:"3"}),n.jsx(s.Text,{size:"2",color:"gray",children:"Parsing spreadsheet…"})]}):G?n.jsxs(n.Fragment,{children:[n.jsx(Z.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(s.Text,{size:"2",color:"red",weight:"medium",children:G}),n.jsx(s.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Z.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(s.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),n.jsxs(s.Text,{size:"1",color:"gray",children:[he(k)," max · ",xe(y)]})]})})}),oe,ye&&n.jsx(s.Text,{size:"2",color:"gray",mt:"3",style:{display:"block"},children:"Sheet preview not stored for this field — re-upload to view contents."}),Object.keys(te).length>0&&n.jsxs(s.Box,{mt:"3",children:[n.jsx(s.Text,{size:"2",weight:"bold",as:"div",mb:"1",children:"Computed values"}),n.jsx(s.Flex,{direction:"column",gap:"1",children:Object.entries(te).map(([C,B])=>n.jsxs(s.Flex,{justify:"between",children:[n.jsx(s.Text,{size:"2",children:B.label}),B.error?n.jsx(s.Text,{size:"2",color:"red",children:B.error}):n.jsx(s.Text,{size:"2",children:Ze(B.value)})]},C))})]}),!d&&n.jsx(s.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:fe(u,o)})]})},Bt=H.withJsonFormsControlProps(an),$t=v.rankWith(10,v.schemaMatches(e=>e.type==="object"&&typeof e["x-spreadsheet"]=="object")),cn="Sheet1",un="xlsx";function dn(e){if(e===void 0)return null;if(!Array.isArray(e))return"columns must be an array of { id, label } objects.";if(e.length===0)return"columns is declared but empty — declare at least one field, or omit it entirely.";const r=e.findIndex(t=>!t||typeof t!="object"||typeof t.id!="string"||t.id===""||typeof t.label!="string"||t.label==="");return r!==-1?`columns[${r}] must be a { id, label } object with non-empty string fields.`:null}function fn(e,r){if(!Pt(e))return e;const t=Ut(e,r==null?void 0:r.map(l=>l.id));if(!r||t.length===0)return t;const o=new Map(r.map(l=>[l.id,l.label])),[a,...i]=t;return[a.map(l=>o.get(String(l))??l),...i]}const pn=({data:e,label:r,schema:t,visible:o=!0})=>{const[a,i]=g.useState(null);if(o===!1)return null;const l=(t==null?void 0:t["x-spreadsheet-export"])??{},c=l.columns,u=l.sheetName??cn,f=l.fileType??un,d=l.fileName??`export.${f}`,h=dn(c);if(h)return n.jsxs(s.Box,{mb:"4",children:[n.jsx(s.Text,{as:"label",size:"2",weight:"bold",children:r}),n.jsxs(s.Text,{size:"2",color:"red",style:{display:"block"},children:["Invalid x-spreadsheet-export config: ",h]})]});const p=Array.isArray(e)&&e.length>0,m=async()=>{if(p){i(null);try{const y=await import("@e965/xlsx"),k=fn(e,c),A=y.utils.aoa_to_sheet(k),w=y.utils.book_new();y.utils.book_append_sheet(w,A,u),y.writeFile(w,d,{bookType:f})}catch(y){i(y instanceof Error?y.message:"Failed to build the workbook.")}}};return n.jsxs(s.Box,{mb:"4",children:[n.jsx(s.Text,{as:"label",size:"2",weight:"bold",style:{display:"block",marginBottom:"var(--space-2)"},children:r}),n.jsxs(s.Button,{type:"button",variant:"soft",disabled:!p,onClick:()=>void m(),children:[n.jsx(Z.DownloadIcon,{})," Download Spreadsheet"]}),a&&n.jsx(s.Text,{size:"2",color:"red",style:{display:"block",marginTop:"var(--space-2)"},children:a})]})},_t=H.withJsonFormsControlProps(pn),Vt=v.rankWith(10,v.and(v.schemaMatches(e=>{const r=e["x-spreadsheet-export"];return e.type==="array"&&typeof r=="object"&&r!==null}),v.not(v.optionIs("editable",!0))));class ve extends Error{}const Qe=5e6,hn=1024,xn=/^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["']/i,mn={ignoreAttributes:!1,attributeNamePrefix:"@_",textNodeName:"#text",parseTagValue:!0,parseAttributeValue:!0,numberParseOptions:{hex:!1,leadingZeros:!1,eNotation:!0},trimValues:!0,cdataPropName:!1,commentPropName:!1,processEntities:!0,htmlEntities:!0,ignoreDeclaration:!0,ignorePiTags:!0,alwaysCreateTextNode:!1,preserveOrder:!1,removeNSPrefix:!1,maxNestedTags:100,strictReservedNames:!0};function gn(e){const r=new Set(e);return r.size===0?()=>!1:(t,o)=>r.has(typeof o=="string"?o:o.toString())||r.has(t)}function yn(e){const r=e instanceof Error?e.message:"";return r.startsWith("[SECURITY] Invalid name:")?"This document uses a reserved JavaScript name (__proto__, constructor or prototype) as an element or attribute name, which cannot be represented safely.":r==="External entities are not supported"||r==="Parameter entities are not supported"?`${r}. Please remove the DOCTYPE entity declarations and try again.`:r.startsWith("Maximum nested tags exceeded")?"This document is nested too deeply to parse.":r.startsWith("Entity count")||r.includes("exceeds maximum allowed")?"This document declares too many or too large entity definitions to expand safely.":"This doesn't look like a valid XML document. Please check the file and try again."}async function bn(e,r={}){var f;if(typeof e!="string")throw new ve("This file could not be read as text.");const t=e.charCodeAt(0)===65279?e.slice(1):e;if(t.trim()==="")throw new ve("This file is empty.");if(t.length>Qe)throw new ve(`This document is too large to parse (over ${Qe/1e6} million characters).`);const o=(f=xn.exec(t.slice(0,hn)))==null?void 0:f[1];if(o&&!/^utf-?8$/i.test(o))throw new ve(`This document declares the unsupported encoding "${o}". Only UTF-8 is supported.`);const{XMLParser:a,XMLValidator:i}=await import("fast-xml-parser"),l=i.validate(t,{allowBooleanAttributes:!1});if(l!==!0){const{msg:d,line:h,col:p}=l.err;throw new ve(`Invalid XML at line ${h}, column ${p}: ${d}`)}const c=new a({...mn,removeNSPrefix:r.removeNamespaces===!0,isArray:gn(r.arrayPaths??[])});let u;try{u=c.parse(t)}catch(d){throw new ve(yn(d))}if(u==null||typeof u!="object"||Array.isArray(u))throw new ve("This document has no root element.");return u}const Ee={found:!1},de=e=>({found:!0,value:e});function et(e){return e==null||e===""?Ee:Array.isArray(e)||e instanceof Date?de(e):typeof e=="object"?Ee:typeof e=="string"||typeof e=="number"||typeof e=="boolean"?de(e):Ee}const vn=new Set(["true","1","yes","y"]),Tn=new Set(["false","0","no","n"]);async function jn(e,r){switch(r.as){case void 0:return de(e);case"string":return de(e instanceof Date?e.toISOString():String(e));case"number":{const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?de(t):Ee}case"boolean":{const t=String(e).trim().toLowerCase();return vn.has(t)?de(!0):Tn.has(t)?de(!1):Ee}case"date":{const{default:t}=await import("dayjs"),{default:o}=await Promise.resolve().then(()=>require("./customParseFormat-CLvZwox5.cjs")).then(l=>l.customParseFormat);t.extend(o);const a=e instanceof Date?e.toISOString():String(e),i=r.format?t(a,r.format,!0):t(a);return i.isValid()?de(i.format("YYYY-MM-DD")):Ee}}}async function wn(e,r){if(r.formula!==void 0){const t={};for(const[o,a]of Object.entries(r.inputs??{})){const i=et(v.Resolve.data(e,a));if(!i.found||Array.isArray(i.value))return Ee;t[o]=i.value}try{return de(await Lt(t,r.formula))}catch(o){throw new Error(`writeTo "${r.to}": ${Ue(o)}`)}}if(r.from===void 0)throw new Error(`writeTo "${r.to}" needs either "from" or "formula".`);return et(v.Resolve.data(e,r.from))}function Wt(e){const r={};for(const{to:t,value:o}of e){const a=t.split(".").filter(Boolean);if(a.length===0)continue;let i=r;for(const l of a.slice(0,-1)){const c=i[l];if(c&&typeof c=="object"&&!Array.isArray(c))i=c;else{const u={};i[l]=u,i=u}}i[a[a.length-1]]=o}return r}async function Be(e,r){const t=[];for(const o of r){let a=await wn(e,o);const i=a.found&&Array.isArray(a.value);if(a.found&&i&&o.writeTo){const l=await Promise.all(a.value.map(async c=>Wt(await Be(c,o.writeTo))));t.push({to:o.to,value:l});continue}if(a.found&&!i&&o.writeTo)throw new Error(`writeTo "${o.to}": "writeTo" is set, but "from" did not resolve to a repeating element.`);if(a.found&&!i&&o.map){const l=a.value instanceof Date?a.value.toISOString():String(a.value);Object.prototype.hasOwnProperty.call(o.map,l)&&(a=de(o.map[l]))}if(a.found&&!i&&(a=await jn(a.value,o)),!a.found){if(o.default===void 0)continue;t.push({to:o.to,value:o.default});continue}t.push({to:o.to,value:a.value})}return t}const En=".xml,text/xml,application/xml",Cn=5*1024*1024,Sn=({data:e,handleChange:r,path:t,label:o,required:a,schema:i,enabled:l,readonly:c,errors:u,visible:f=!0})=>{me(f,t,r);const d=!u||u.length===0,h=It(l,c),p=(i==null?void 0:i["x-xml"])??{},m=p.accept??En,y=p.maxSize??Cn,k=p.arrayPaths,A=p.removeNamespaces===!0,w=p.writeTo,E=p.writeBase??"root",O=p.persistDocument!==!1,N=H.useJsonForms(),I=e??null,[F,M]=g.useState(()=>I?"ready":"empty"),[D,b]=g.useState(null),[j,V]=g.useState(!1),X=g.useRef(null),G=g.useRef(0),L=I!=null,S=w!==void 0&&w.length>0,J=g.useCallback(async x=>{var oe;const R=++G.current;if(b(null),x.size>y){b(`File exceeds the ${he(y)} limit.`);return}if(!m.split(",").map(P=>P.trim()).some(P=>P==="*"||P==="*/*"?!0:P.endsWith("/*")?x.type.startsWith(P.slice(0,-1)):P.startsWith(".")?x.name.toLowerCase().endsWith(P.toLowerCase()):x.type===P)){b(`Invalid type. Accepted: ${xe(m)}`);return}M("parsing");let U;try{const P=await x.text();U=await bn(P,{arrayPaths:k,removeNamespaces:A})}catch(P){if(R!==G.current)return;M("error"),b(P instanceof ve?P.message:"This doesn't look like a valid XML document. Please check the file and try again.");return}let te=[];if(w&&w.length>0)try{te=await Be(U,w)}catch(P){if(R!==G.current)return;M("error"),b(P instanceof Error?P.message:"This document could not be mapped onto the form.");return}if(R!==G.current)return;O&&r(t,U);const q=E==="parent"?t.split(".").slice(0,-1).join("."):"";for(const P of te)(oe=N.dispatch)==null||oe.call(N,v.update(q?`${q}.${P.to}`:P.to,()=>P.value));M("ready")},[m,y,k,A,w,E,O,t,r,N]);if(f===!1||!h&&!L)return null;const Q=x=>{x.preventDefault(),x.stopPropagation(),h&&V(x.type==="dragenter"||x.type==="dragover")},pe=x=>{var R;x.preventDefault(),x.stopPropagation(),V(!1),h&&(R=x.dataTransfer.files)!=null&&R[0]&&J(x.dataTransfer.files[0])},ne=x=>{var R;(R=x.target.files)!=null&&R[0]&&(J(x.target.files[0]),x.target.value="")},ge=()=>{h&&(++G.current,b(null),M("empty"),r(t,void 0))};return n.jsxs(s.Box,{mb:"4",children:[n.jsxs(s.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(s.Flex,{align:"center",gap:"1",children:[n.jsxs(s.Text,{as:"label",size:"2",weight:"bold",children:[o,a&&n.jsx(s.Text,{color:"red",children:" *"})]}),!S&&L&&h&&n.jsxs(n.Fragment,{children:[n.jsx(s.Tooltip,{content:"Replace document",children:n.jsx(s.IconButton,{variant:"ghost",size:"1",onClick:()=>{var x;return(x=X.current)==null?void 0:x.click()},"aria-label":"Replace document",children:n.jsx(Z.UploadIcon,{})})}),n.jsx(s.Tooltip,{content:"Remove document",children:n.jsx(s.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:ge,"aria-label":"Remove document",children:n.jsx(Z.Cross2Icon,{})})})]})]}),n.jsxs(s.Flex,{align:"center",gap:"2",children:[n.jsxs(s.Text,{size:"1",color:"gray",children:[he(y)," max · ",xe(m)]}),S&&h&&n.jsxs(s.Button,{size:"1",variant:"soft",onClick:()=>{var x;return(x=X.current)==null?void 0:x.click()},disabled:F==="parsing",children:[F==="parsing"?n.jsx(s.Spinner,{size:"1"}):n.jsx(Z.UploadIcon,{}),"Upload"]})]})]}),(S||L)&&D&&n.jsx(s.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:D}),n.jsx("input",{ref:X,type:"file",style:{display:"none"},accept:m,onChange:ne}),!S&&h&&!L&&n.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var x;return(x=X.current)==null?void 0:x.click()},onKeyDown:x=>{var R;(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),(R=X.current)==null||R.click())},onDragEnter:Q,onDragLeave:Q,onDragOver:Q,onDrop:pe,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",j?"border-blue-500 bg-blue-50":D?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:n.jsx(s.Flex,{direction:"column",align:"center",gap:"2",children:F==="parsing"?n.jsxs(n.Fragment,{children:[n.jsx(s.Spinner,{size:"3"}),n.jsx(s.Text,{size:"2",color:"gray",children:"Parsing document…"})]}):D?n.jsxs(n.Fragment,{children:[n.jsx(Z.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(s.Text,{size:"2",color:"red",weight:"medium",children:D}),n.jsx(s.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Z.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(s.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),n.jsxs(s.Text,{size:"1",color:"gray",children:[he(y)," max · ",xe(m)]})]})})}),!d&&n.jsx(s.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:fe(u,o)})]})},Ht=H.withJsonFormsControlProps(Sn),Xt=v.rankWith(10,v.schemaMatches(e=>{const r=e["x-xml"];return e.type==="object"&&typeof r=="object"&&r!==null}));function Rn(e,r,t){const o=new Blob([e],{type:t}),a=URL.createObjectURL(o),i=document.createElement("a");i.href=a,i.download=r,i.click(),URL.revokeObjectURL(a)}const An="root",Fn="export.xml";function On(e){return e===void 0?"writeTo is required — see docs/xml-export-control.md.":Array.isArray(e)?e.length===0?"writeTo is declared but empty — declare at least one entry.":null:"writeTo must be an array of { from | formula, to } entries."}function kn(e){return e==null?!0:Array.isArray(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:!1}const In=({path:e,label:r,schema:t,visible:o=!0})=>{var w,E;const a=(t==null?void 0:t["x-xml-export"])??{},i=a.rootElement??An,l=a.fileName??Fn,c=a.writeTo,u=a.writeBase??"root",f=On(c),d=H.useJsonForms(),h=u==="parent"?e.split(".").slice(0,-1).join("."):"",p=h?v.Resolve.data((w=d.core)==null?void 0:w.data,h):(E=d.core)==null?void 0:E.data,[m,y]=g.useState(null),k=kn(p),A=g.useCallback(async()=>{if(!c)return;y(null);let O;try{const D=await Be(p,c);O=Wt(D)}catch(D){y(D instanceof Error?D.message:"This mapping could not be resolved.");return}const{XMLBuilder:N}=await import("fast-xml-parser"),I={[i]:O},M=new N({format:!0,indentBy:" ",ignoreAttributes:!0}).build(I);Rn(M,l,"application/xml")},[c,p,i,l]);return o===!1?null:f?n.jsxs(s.Box,{mb:"4",children:[n.jsx(s.Text,{as:"label",size:"2",weight:"bold",children:r}),n.jsxs(s.Text,{size:"2",color:"red",style:{display:"block"},children:["Invalid x-xml-export config: ",f]})]}):n.jsxs(s.Box,{mb:"4",children:[n.jsx(s.Text,{as:"label",size:"2",weight:"bold",style:{display:"block",marginBottom:"var(--space-2)"},children:r}),n.jsxs(s.Button,{size:"1",variant:"soft",disabled:k,onClick:()=>void A(),children:[n.jsx(Z.DownloadIcon,{}),"Download XML"]}),m&&n.jsx(s.Text,{size:"2",color:"red",style:{display:"block",marginTop:"var(--space-2)"},children:m})]})},Jt=H.withJsonFormsControlProps(In),Kt=v.rankWith(10,v.schemaMatches(e=>{const r=e["x-xml-export"];return e.type==="object"&&typeof r=="object"&&r!==null}));function qt(e,r,t){const{path:o,default:a}=typeof t=="string"?{path:t,default:void 0}:t,i=v.Resolve.data(e,r?`${r}.${o}`:o);return i??a}function Nn(e,r,t){const o={};for(const[a,i]of Object.entries(t)){const l=qt(e,r,i);if(l===void 0)return;o[a]=l}return o}async function Dn(e,r){try{return{status:"ok",value:await Lt(e,r)}}catch(t){return{status:"error",error:Ue(t)}}}function Ln(e,r){return e==null?"":typeof e=="number"?e.toFixed(Mn(r)):e instanceof Date?e.toLocaleDateString():String(e)}function Mn(e){return Number.isFinite(e)?Math.min(100,Math.max(0,Math.trunc(e))):0}const zn="{value}",Pn=2,Un={},Bn=({data:e,handleChange:r,path:t,label:o,schema:a,visible:i=!0})=>{var F;me(i,t,r);const l=a==null?void 0:a["x-computed"],c=(l==null?void 0:l.inputs)??Un,u=(l==null?void 0:l.formula)??"",f=(l==null?void 0:l.format)??zn,d=(l==null?void 0:l.decimals)??Pn,h=H.useJsonForms(),p=t.split(".").slice(0,-1).join("."),m=Nn((F=h.core)==null?void 0:F.data,p,c),y=m?JSON.stringify(m):null,k=h.readonly===!0,[A,w]=g.useState(()=>typeof e=="number"?"ok":"unavailable"),[E,O]=g.useState(()=>typeof e=="number"?e:null),[N,I]=g.useState(null);return g.useEffect(()=>{if(!i)return;let M=!1;const D=b=>{k||b!==e&&r(t,b)};if(m===void 0){w("unavailable"),I(null),O(null),D(void 0);return}return w(b=>b==="ok"?b:"loading"),Dn(m,u).then(b=>{if(M)return;const j=b.status==="ok"&&typeof b.value=="number"&&Number.isFinite(b.value)?b.value:null;if(j===null){w("error"),I(b.status==="error"?b.error??"Unable to compute value.":"Computed value must be a number."),O(null),D(void 0);return}w("ok"),I(null),O(j),D(j)}),()=>{M=!0}},[y,u,i,k]),i===!1?null:n.jsx(s.Box,{mb:"4",children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsx(s.Text,{as:"label",size:"2",weight:"bold",children:o}),A==="unavailable"?n.jsx(s.Text,{size:"2",color:"gray",children:"Not yet available."}):A==="loading"?n.jsxs(s.Flex,{align:"center",gap:"2",children:[n.jsx(s.Spinner,{size:"1"}),n.jsx(s.Text,{size:"2",color:"gray",children:"Computing…"})]}):A==="error"?n.jsx(s.Text,{size:"2",color:"red",children:N}):n.jsx(s.Text,{size:"2",children:ze(f,{value:Ln(E,d)})}),a.description&&n.jsx(s.Text,{size:"1",color:"gray",children:a.description})]})})},Gt=H.withJsonFormsControlProps(Bn),Yt=v.rankWith(5,v.schemaMatches(e=>{const r=e["x-computed"];return e.type==="number"&&typeof r=="object"&&r!==null})),Zt="seq",tt=2,$n=e=>e==null||e==="",Qt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0,_n=e=>{const r=e==null?void 0:e["x-template"];if(typeof r!="object"||r===null)return;const{template:t,inputs:o}=r;if(!(typeof t!="string"||t===""))return{template:t,inputs:o}},$e=e=>typeof e=="object"&&e.name===Zt&&e.arg!==void 0,Vn=e=>e.every((r,t)=>!$e(r)||typeof e[t-1]!="object"&&typeof e[t+1]!="object"),Wn=e=>{const r=new Set;for(const t of Pe(e))typeof t=="object"&&t.arg===void 0&&r.add(t.name);return[...r]},Hn=e=>{const r=[];for(const[t,o]of Object.entries((e==null?void 0:e.properties)??{})){const a=_n(o);a&&r.push([t,a])}return r},Xn=(e,r,t)=>{var a;const o={};for(const i of Wn(t.template)){const l=qt(e,r,((a=t.inputs)==null?void 0:a[i])??i);o[i]=typeof l=="string"||typeof l=="number"||typeof l=="boolean"?String(l):""}return o},Jn=e=>r=>{const t=r.trim()===""?tt:Number(r);return`${e}`.padStart(Number.isInteger(t)&&t>=0?t:tt,"0")},Kn=e=>{const r=o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");let t="";for(const o of Pe(e))typeof o=="string"?t+=r(o):t+=$e(o)?"(\\d+)":".*?";return new RegExp(`^${t}$`)},qn=(e,r,t)=>{var i,l;const o=Kn(t.template);let a=0;for(const c of e){const u=(i=Qt(c))==null?void 0:i[r];if(typeof u!="string")continue;const f=Number((l=o.exec(u))==null?void 0:l[1]);Number.isFinite(f)&&f>a&&(a=f)}return a},Gn=(e,r,t,o,a,i)=>{const l=Hn(e);if(l.length===0)return r;const c=Qt(r);if(!c)return r;const u={...c};for(const[f,d]of l){if(!$n(u[f]))continue;const h=Pe(d.template),p={};if(h.some($e)){if(!Vn(h)){console.warn(`x-template: {seq(…)} needs literal text between it and other placeholders; not numbering "${d.template}"`);continue}const m=Math.max(i[f]??0,qn(t,f,d))+1;i[f]=m,p[Zt]=Jn(m)}u[f]=ze(d.template,Xn(o,a,d),p)}return u},Yn=({path:e,items:r,itemsSchema:t,rootSchema:o,addItem:a,sequences:i})=>{const l=H.useJsonForms(),c=()=>{var f;const u=Gn(t,v.createDefaultValue(t,o),r,(f=l.core)==null?void 0:f.data,e.split(".").slice(0,-1).join("."),i.current);a&&a(e,u)()};return n.jsx(s.Box,{mt:"2",children:n.jsxs(s.Button,{type:"button",variant:"surface",onClick:c,children:[n.jsx(Z.PlusIcon,{}),"Add Item"]})})},Zn=({data:e,path:r,schema:t,uischema:o,enabled:a,visible:i,addItem:l,removeItems:c,rootSchema:u,arraySchema:f})=>{const d=g.useRef({}),h=f?t:t.items,p=f||t;if(i===!1||!h||typeof h!="object"||Array.isArray(h))return null;const m=h,y=Array.isArray(e)?e:[],k=p.title||"Array Items",A=o.options??{},w=a&&A.addable!==!1,E=a&&A.removable!==!1,O=A.itemLabel||"Item",N=I=>{if(c){const F=c(r,[I]);F&&F()}};return n.jsx(s.Box,{mb:"6",children:n.jsxs(s.Flex,{direction:"column",gap:"4",children:[n.jsx(s.Text,{as:"div",size:"4",weight:"bold",children:k}),y.length===0&&n.jsx(s.Box,{py:"4",px:"4",style:{backgroundColor:"var(--gray-3)",borderRadius:"var(--radius-3)"},children:n.jsx(s.Text,{size:"2",color:"gray",children:"No items have been added yet."})}),y.map((I,F)=>{var D;const M=`${r}.${F}`;return n.jsx(s.Card,{size:"3",variant:"surface",children:n.jsxs(s.Flex,{direction:"column",gap:"4",children:[n.jsxs(s.Flex,{justify:"between",align:"center",children:[n.jsxs(s.Text,{size:"3",weight:"bold",children:[O," ",F+1]}),E&&n.jsxs(s.Button,{type:"button",color:"red",variant:"soft",onClick:()=>N(F),title:"Remove item",children:[n.jsx(Z.TrashIcon,{}),"Remove"]})]}),n.jsx(s.Box,{children:n.jsx(H.JsonFormsDispatch,{schema:m,uischema:((D=o.options)==null?void 0:D.detail)||(m.type==="object"||m.properties?{type:"VerticalLayout",elements:Object.keys(m.properties||{}).map(b=>({type:"Control",scope:`#/properties/${b}`}))}:{type:"Control",scope:"#"}),path:M,enabled:a,renderers:void 0,cells:void 0})})]})},M)}),w&&n.jsx(Yn,{path:r,items:y,itemsSchema:m,rootSchema:u,addItem:l,sequences:d})]})})},Me=H.withJsonFormsArrayControlProps(Zn),er=v.rankWith(3,v.isObjectArrayControl),tr=({uischema:e,visible:r})=>{const t=e;return r===!1?null:n.jsx(s.Box,{mb:"4",children:n.jsx(s.Heading,{size:"4",children:t.text})})},rr=v.rankWith(1,v.uiTypeIs("Label")),Qn=v.rankWith(3,v.isPrimitiveArrayControl),eo=[{tester:at,renderer:fr},{tester:ut,renderer:pr},{tester:ft,renderer:hr},{tester:ht,renderer:xr},{tester:bt,renderer:yt},{tester:mt,renderer:mr},{tester:Tt,renderer:Sr},{tester:wt,renderer:jt},{tester:Ct,renderer:Et},{tester:Rt,renderer:St},{tester:Ft,renderer:At},{tester:kt,renderer:Ot},{tester:$t,renderer:Bt},{tester:Vt,renderer:_t},{tester:Xt,renderer:Ht},{tester:Kt,renderer:Jt},{tester:Yt,renderer:Gt},{tester:er,renderer:Me},{tester:Qn,renderer:Me},{tester:rr,renderer:tr}];exports.ArrayControl=Me;exports.ArrayControlTester=er;exports.BooleanControl=dt;exports.BooleanControlTester=ft;exports.CategorizationLayoutRenderer=At;exports.CategorizationLayoutTester=Ft;exports.ComputedControl=Gt;exports.ComputedControlTester=Yt;exports.DateControl=vt;exports.DateControlTester=Tt;exports.FileControl=Ot;exports.FileControlTester=kt;exports.GroupLayoutRenderer=St;exports.GroupLayoutTester=Rt;exports.HorizontalLayoutRenderer=Et;exports.HorizontalLayoutTester=Ct;exports.LabelRenderer=tr;exports.LabelTester=rr;exports.NumberControl=ct;exports.NumberControlTester=ut;exports.RadioControl=pt;exports.RadioControlTester=ht;exports.SearchSelectControl=yt;exports.SearchSelectControlTester=bt;exports.SearchServiceProvider=dr;exports.SelectControl=xt;exports.SelectControlTester=mt;exports.SpreadsheetControl=Bt;exports.SpreadsheetControlTester=$t;exports.SpreadsheetExportControl=_t;exports.SpreadsheetExportControlTester=Vt;exports.TextControl=lt;exports.TextControlTester=at;exports.UploadProvider=ur;exports.VerticalLayoutRenderer=jt;exports.VerticalLayoutTester=wt;exports.XmlControl=Ht;exports.XmlControlTester=Xt;exports.XmlExportControl=Jt;exports.XmlExportControlTester=Kt;exports.radixRenderers=eo;exports.useSearchService=it;exports.useUpload=ot;