@opennsw/jsonforms-renderers 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- "use strict";var wt=Object.create;var je=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var At=(e,n,r)=>n in e?je(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var Ft=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let x of Rt(n))!St.call(e,x)&&x!==r&&je(e,x,{get:()=>n[x],enumerable:!(i=Ct(n,x))||i.enumerable});return e};var Re=(e,n,r)=>(r=e!=null?wt(Et(e)):{},Ft(n||!e||!e.__esModule?je(r,"default",{value:e,enumerable:!0}):r,e));var Ee=(e,n,r)=>At(e,typeof n!="symbol"?n+"":n,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),v=require("react"),y=require("@jsonforms/core"),B=require("@jsonforms/react"),o=require("@radix-ui/themes"),ee=require("@radix-ui/react-icons"),Ot=require("dayjs"),Se=require("@e965/xlsx"),Me=v.createContext(null);function It({children:e,onUpload:n,getDownloadUrl:r}){const i={onUpload:n,getDownloadUrl:r};return t.jsx(Me.Provider,{value:i,children:e})}function ze(){return v.useContext(Me)}const De=v.createContext(null);function Nt({children:e,services:n}){const r=v.useMemo(()=>n,[n]);return t.jsx(De.Provider,{value:r,children:e})}function Ue(e){const n=v.useContext(De);return!n||!e?null:n[e]??null}const se=(e,n,r,i=void 0)=>{v.useEffect(()=>{e===!1&&r(n,i)},[e,n,r,i])},le=(e,n)=>e?e.split(`
1
+ "use strict";var wt=Object.create;var je=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var At=(e,n,r)=>n in e?je(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var Ft=(e,n,r,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let x of Rt(n))!St.call(e,x)&&x!==r&&je(e,x,{get:()=>n[x],enumerable:!(l=Ct(n,x))||l.enumerable});return e};var Re=(e,n,r)=>(r=e!=null?wt(Et(e)):{},Ft(n||!e||!e.__esModule?je(r,"default",{value:e,enumerable:!0}):r,e));var Ee=(e,n,r)=>At(e,typeof n!="symbol"?n+"":n,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),b=require("react"),y=require("@jsonforms/core"),H=require("@jsonforms/react"),o=require("@radix-ui/themes"),ee=require("@radix-ui/react-icons"),Ot=require("dayjs"),Se=require("@e965/xlsx"),Me=b.createContext(null);function It({children:e,onUpload:n,getDownloadUrl:r}){const l={onUpload:n,getDownloadUrl:r};return t.jsx(Me.Provider,{value:l,children:e})}function ze(){return b.useContext(Me)}const De=b.createContext(null);function Nt({children:e,services:n}){const r=b.useMemo(()=>n,[n]);return t.jsx(De.Provider,{value:r,children:e})}function Ue(e){const n=b.useContext(De);return!n||!e?null:n[e]??null}const se=(e,n,r,l=void 0)=>{b.useEffect(()=>{e===!1&&r(n,l)},[e,n,r,l])},le=(e,n)=>e?e.split(`
2
2
  `).map(r=>r.trim()==="is a required property"?`${n||"This field"} is required`:r).join(`
3
- `):"",Be=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,uischema:l,schema:u,enabled:s,visible:a=!0})=>{var m;if(se(a,r,n),a===!1)return null;const d=c.length===0;return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[i," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsx(o.TextField.Root,{value:e||"",onChange:h=>n(r,h.target.value),disabled:!s,placeholder:(m=l.options)==null?void 0:m.placeholder,color:d?void 0:"red",id:r}),!d&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,i)}),u.description&&t.jsx(o.Text,{size:"1",color:"gray",children:u.description})]})})},Pe=y.rankWith(1,y.isStringControl),kt=B.withJsonFormsControlProps(Be),He=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,uischema:l,schema:u,enabled:s,visible:a=!0})=>{var h;if(se(a,r,n),a===!1)return null;const d=c.length===0,m=p=>{if(p===""){n(r,void 0);return}const g=Number(p);isNaN(g)||n(r,g)};return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[i," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsx(o.TextField.Root,{type:"number",value:e??"",onChange:p=>m(p.target.value),disabled:!s,placeholder:(h=l.options)==null?void 0:h.placeholder,color:d?void 0:"red",id:r}),!d&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,i)}),u.description&&t.jsx(o.Text,{size:"1",color:"gray",children:u.description})]})})},We=y.rankWith(2,y.or(y.isNumberControl,y.isIntegerControl)),Lt=B.withJsonFormsControlProps(He),$e=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,schema:l,enabled:u,visible:s=!0})=>{if(se(s,r,n),s===!1)return null;const a=c.length===0;return t.jsxs(o.Box,{mb:"4",children:[t.jsxs(o.Flex,{gap:"2",align:"center",children:[t.jsx(o.Checkbox,{checked:!!e,onCheckedChange:d=>n(r,d===!0),disabled:!u,id:r}),t.jsxs(o.Text,{as:"label",size:"2",htmlFor:r,children:[i," ",x&&"*"]})]}),!a&&t.jsx(o.Text,{color:"red",size:"1",className:"block mt-1",children:le(c,i)}),l.description&&t.jsx(o.Text,{size:"1",color:"gray",className:"block mt-1",children:l.description})]})},_e=y.rankWith(2,y.isBooleanControl),Mt=B.withJsonFormsControlProps($e),Ve=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,schema:l,enabled:u,visible:s=!0})=>{if(se(s,r,n),s===!1)return null;const a=c.length===0;let d=[];l.enum?d=l.enum.map(h=>({value:h,label:String(h)})):l.oneOf&&(d=l.oneOf.map(h=>({value:h.const,label:h.title||String(h.const)})));const m=e;return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"div",size:"2",weight:"bold",children:[i," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsx(o.RadioGroup.Root,{value:m!==void 0?String(m):"",onValueChange:h=>{const p=d.find(g=>String(g.value)===h);p&&n(r,p.value)},disabled:!u,children:t.jsx(o.Flex,{direction:"row",style:{flexWrap:"wrap",columnGap:"clamp(14px, 3vw, 36px)",rowGap:"clamp(8px, 1.6vw, 14px)"},children:d.map(h=>t.jsxs(o.Flex,{align:"center",gap:"2",style:{minWidth:"max-content"},children:[t.jsx(o.RadioGroup.Item,{value:String(h.value)}),t.jsx(o.Text,{size:"2",color:u?void 0:"gray",children:h.label})]},String(h.value)))})}),!a&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,i)}),l.description&&t.jsx(o.Text,{size:"1",color:"gray",children:l.description})]})})},Je=(e,n,r)=>{var x;return y.or(y.isEnumControl,y.isOneOfControl)(e,n,r)&&((x=e==null?void 0:e.options)==null?void 0:x.format)==="radio"?3:-1},zt=B.withJsonFormsControlProps(Ve),Ke=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,schema:l,uischema:u,enabled:s,visible:a=!0})=>{var p;if(se(a,r,n),a===!1)return null;const d=c.length===0;let m=[];l.enum?m=l.enum.map(g=>({value:String(g),label:String(g)})):l.oneOf&&(m=l.oneOf.map(g=>({value:String(g.const),label:g.title||String(g.const)})));const h=e!==void 0?String(e):"";return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[i," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsxs(o.Select.Root,{value:h,onValueChange:g=>n(r,g),disabled:!s,children:[t.jsx(o.Select.Trigger,{placeholder:((p=u.options)==null?void 0:p.placeholder)||"Select an option",color:d?void 0:"red",id:r}),t.jsx(o.Select.Content,{children:m.map(g=>t.jsx(o.Select.Item,{value:g.value,children:g.label},g.value))})]}),!d&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,i)}),l.description&&t.jsx(o.Text,{size:"1",color:"gray",children:l.description})]})})},Ge=y.rankWith(2,y.or(y.isEnumControl,y.isOneOfControl)),Dt=B.withJsonFormsControlProps(Ke),Ut={"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}},Bt=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,enabled:l,visible:u=!0,schema:s,uischema:a})=>{var pe;const d=(s==null?void 0:s["x-search"])??{service:""},m=d.service??"",h=d.mode??"large-paginated-list",p=Ut[h],g=(p==null?void 0:p.fetchOnOpen)??!1,S=d.params,R=Ue(m),b=s.type==="object",w=b?typeof e=="string"?{value:e}:e??void 0:void 0,N=b?w==null?void 0:w.value:e,U=w==null?void 0:w.label,A=m?R?p?null:`Invalid x-search.mode "${h}". Expected "small-list", "large-searchable-list", or "large-paginated-list".`:`Search service "${m}" is not registered.`:"Search not configured.",H=l!==!1,V=!c||c.length===0,[O,E]=v.useState(!1),[L,P]=v.useState(""),[re,Y]=v.useState([]),[ne,J]=v.useState(!1),[X,Z]=v.useState(!1),[ce,te]=v.useState(!1),[ie,T]=v.useState(null),[I,M]=v.useState(void 0),C=v.useRef(void 0),z=v.useRef(null),K=v.useRef(null),q=v.useRef(null),W=v.useRef(void 0);v.useEffect(()=>{var j,G;if(!N){M(void 0),W.current=void 0;return}if(((j=W.current)==null?void 0:j.value)===N&&((G=W.current)==null?void 0:G.label)===U)return;if(W.current={value:N,label:U},b&&U){M({id:N,name:U});return}if(M({id:N,name:U??N}),!(R!=null&&R.resolve))return;let f=!1;return R.resolve(N,S).then(Q=>{!f&&Q&&M(Q)}).catch(()=>{}),()=>{f=!0}},[N,U,b,R,S]);const xe=v.useCallback(async(f,j=!1)=>{var Q;if(!R){T("Search service not configured.");return}(Q=K.current)==null||Q.abort();const G=new AbortController;K.current=G,j?te(!0):(Z(!0),te(!1),T(null));try{const oe=await R.search({query:f,cursor:j?C.current:void 0,signal:G.signal,params:S}),k=oe.options??[];Y(j?jt=>[...jt,...k]:k),C.current=oe.nextCursor,J(((p==null?void 0:p.paginated)??!1)&&oe.nextCursor!=null)}catch{if(G.signal.aborted)return;T("Failed to load results. Please try again.")}finally{G.signal.aborted||(j?te(!1):Z(!1))}},[R,p==null?void 0:p.paginated,S]);if(v.useEffect(()=>{if(!O)return;const f=j=>{q.current&&!q.current.contains(j.target)&&E(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[O]),v.useEffect(()=>{var f;O||((f=K.current)==null||f.abort(),P(""),Y([]),J(!1),T(null),Z(!1),te(!1),C.current=void 0)},[O]),v.useEffect(()=>{if(!O)return;if(!L&&!g){Y([]),J(!1),T(null),C.current=void 0;return}z.current&&clearTimeout(z.current);const f=L?300:0;return z.current=setTimeout(()=>{Y([]),J(!1),C.current=void 0,xe(L)},f),()=>{z.current&&clearTimeout(z.current)}},[L,O,g,xe]),se(u,r,n,b?void 0:null),u===!1)return null;const he=()=>{P(""),Y([]),J(!1),T(null),C.current=void 0,E(!0)},be=f=>{n(r,b?{value:f.id,label:f.name}:f.id),M(f),W.current={value:f.id,label:b?f.name:void 0},E(!1)},ge=f=>{f.stopPropagation(),n(r,b?void 0:null),M(void 0)},ve=f=>{(f.key==="Enter"||f.key===" ")&&ge(f)},Te=((pe=a==null?void 0:a.options)==null?void 0:pe.placeholder)??"Select an option";return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[i," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsxs("div",{ref:q,style:{position:"relative"},children:[t.jsx(o.TextField.Root,{id:r,value:O?L:(I==null?void 0:I.name)??"",placeholder:O&&(p!=null&&p.searchable)?"Search...":Te,disabled:!H,readOnly:O&&!(p!=null&&p.searchable),style:V?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:f=>{p!=null&&p.searchable&&(P(f.target.value),O||he())},onFocus:()=>{H&&!O&&he()},onKeyDown:f=>{f.key==="Escape"&&E(!1)},children:t.jsx(o.TextField.Slot,{side:"right",children:t.jsxs(o.Flex,{align:"center",gap:"1",children:[N&&H&&t.jsx("span",{role:"button",tabIndex:0,onMouseDown:f=>f.preventDefault(),onClick:ge,onKeyDown:ve,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),t.jsx(ee.ChevronDownIcon,{style:{transform:O?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),O&&t.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:A?t.jsx(o.Box,{p:"3",children:t.jsx(o.Text,{size:"2",color:"gray",children:A})}):t.jsx(o.ScrollArea,{style:{maxHeight:240},children:t.jsxs(o.Box,{p:"1",children:[X&&t.jsx(o.Flex,{justify:"center",p:"4",children:t.jsx(o.Spinner,{})}),!X&&ie&&t.jsx(o.Box,{px:"3",py:"2",children:t.jsx(o.Text,{size:"2",color:"red",children:ie})}),!X&&!ie&&re.length===0&&t.jsx(o.Box,{px:"3",py:"2",children:t.jsx(o.Text,{size:"2",color:"gray",children:L||g?"No results found.":"Type to search…"})}),re.map(f=>t.jsx(o.Box,{px:"3",py:"2",onMouseDown:j=>j.preventDefault(),onClick:()=>be(f),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:f.id===N?"var(--accent-3)":void 0},className:"hover:bg-(--gray-3)",children:t.jsx(o.Text,{size:"2",children:f.name})},f.id)),(p==null?void 0:p.paginated)&&ne&&!ce&&t.jsx(o.Box,{px:"3",py:"2",children:t.jsx(o.Button,{variant:"ghost",size:"1",style:{width:"100%"},onMouseDown:f=>f.preventDefault(),onClick:()=>void xe(L,!0),children:"Load more"})}),ce&&t.jsx(o.Flex,{justify:"center",p:"2",children:t.jsx(o.Spinner,{})})]})})})]}),!V&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,i)}),s.description&&t.jsx(o.Text,{size:"1",color:"gray",children:s.description})]})})},Xe=B.withJsonFormsControlProps(Bt),qe=y.rankWith(3,y.schemaMatches(e=>{const n=e["x-search"];return(e.type==="string"||e.type==="object")&&typeof(n==null?void 0:n.service)=="string"&&n.service!==""})),Pt=(e,n)=>Ot(`${e}T${n}`).format(),Ht=({path:e,label:n,required:r,errors:i,description:x,children:c})=>{const l=i.length===0;return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:e,children:[n," ",r&&t.jsx(o.Text,{color:"red",children:"*"})]}),c,!l&&t.jsx(o.Text,{color:"red",size:"1",children:le(i,n)}),x&&t.jsx(o.Text,{size:"1",color:"gray",children:x})]})})},Ye=({data:e,handleChange:n,path:r,label:i,required:x,errors:c,schema:l,enabled:u,visible:s=!0})=>{if(v.useEffect(()=>{s===!1&&n(r,void 0)},[s,r,n]),s===!1)return null;const a=c.length===0,d=typeof e=="string"?e:"",m=b=>t.jsx(Ht,{path:r,label:i,required:x,errors:c,description:l.description,children:b});if(l.format==="time")return m(t.jsx(o.TextField.Root,{type:"time",value:d,onChange:b=>n(r,b.target.value),disabled:!u,color:a?void 0:"red",id:r}));const h=l.format==="date-time",[p="",g=""]=d.split("T"),S=g.slice(0,5),R=(b,w)=>{if(!b){n(r,void 0);return}n(r,h?Pt(b,w||"00:00"):b)};return m(t.jsxs(o.Flex,{gap:"2",align:"center",children:[t.jsx(o.TextField.Root,{type:"date",value:p,disabled:!u,color:a?void 0:"red",onChange:b=>R(b.target.value,S),id:r,style:{flex:1}}),h&&t.jsx(o.TextField.Root,{type:"time",value:S,disabled:!u||!p,color:a?void 0:"red",onChange:b=>R(p,b.target.value),style:{flex:1}})]}))},Ze=y.rankWith(2,y.or(y.isDateControl,y.isDateTimeControl,y.isTimeControl)),Wt=B.withJsonFormsControlProps(Ye),Qe=({uischema:e,schema:n,path:r,renderers:i,cells:x,enabled:c,visible:l=!0})=>{const s=e.elements;return l===!1?null:t.jsx(o.Flex,{direction:"column",gap:"4",children:s.map((a,d)=>t.jsx(B.JsonFormsDispatch,{uischema:a,schema:n,path:r,renderers:i,cells:x,enabled:c},`${r}-${d}`))})},et=y.rankWith(1,y.uiTypeIs("VerticalLayout")),tt=({uischema:e,schema:n,path:r,renderers:i,cells:x,enabled:c,visible:l=!0})=>{const s=e.elements;return l===!1?null:t.jsx(o.Flex,{direction:"row",gap:"4",children:s.map((a,d)=>t.jsx(o.Box,{style:{flex:1},children:t.jsx(B.JsonFormsDispatch,{uischema:a,schema:n,path:r,renderers:i,cells:x,enabled:c})},`${r}-${d}`))})},rt=y.rankWith(1,y.uiTypeIs("HorizontalLayout")),nt=({uischema:e,schema:n,path:r,renderers:i,cells:x,enabled:c,visible:l=!0})=>{const u=e,s=u.elements;return l===!1?null:t.jsxs(o.Box,{mb:"6",children:[u.label&&t.jsx(o.Heading,{size:"3",mb:"3",className:"text-gray-500 uppercase tracking-wide font-semibold",children:u.label}),t.jsx(o.Flex,{direction:"column",gap:"4",children:s.map((a,d)=>t.jsx(B.JsonFormsDispatch,{uischema:a,schema:n,path:r,renderers:i,cells:x,enabled:c},`${r}-${d}`))})]})},ot=y.rankWith(1,y.uiTypeIs("Group")),st=({uischema:e,schema:n,path:r,renderers:i,cells:x,enabled:c,visible:l=!0})=>{var h;const s=e.elements.filter(p=>p.type==="Category"),[a,d]=v.useState(((h=s[0])==null?void 0:h.label)||"");if(l===!1||!s.length)return null;const m=s.find(p=>p.label===a)?a:s[0].label;return t.jsxs(o.Tabs.Root,{value:m,onValueChange:d,children:[t.jsx(o.Tabs.List,{children:s.map((p,g)=>t.jsx(o.Tabs.Trigger,{value:p.label,children:p.label},`${r}-${g}`))}),t.jsx(o.Box,{pt:"3",children:s.map((p,g)=>t.jsx(o.Tabs.Content,{value:p.label,children:t.jsx(o.Flex,{direction:"column",gap:"4",children:p.elements.map((S,R)=>t.jsx(B.JsonFormsDispatch,{uischema:S,schema:n,path:r,renderers:i,cells:x,enabled:c},`${r}-${g}-${R}`))})},`${r}-${g}`))})]})},lt=y.rankWith(1,y.uiTypeIs("Categorization"));function ue(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}function de(e){return e.split(",").map(n=>{if(n=n.trim(),n.endsWith("/*"))return n.split("/")[0].toUpperCase()+"S";if(n.startsWith("."))return n.slice(1).toUpperCase();const r=n.split("/")[1];return r?r.toUpperCase():n}).join(", ")}function $t(e){return e?Array.isArray(e)?e:[e]:[]}const _t=({data:e,handleChange:n,path:r,label:i,required:x,uischema:c,schema:l,enabled:u,errors:s,visible:a=!0})=>{const d=ze();se(a,r,n,null);const m=!s||s.length===0,h=(l==null?void 0:l["x-file"])??{},p=(c==null?void 0:c.options)??{},g=h.maxFiles??p.maxFiles??1,S=h.maxSize??p.maxSize??5*1024*1024,R=h.accept??p.accept??"image/*,application/pdf",b=g>1,w=u!==!1,[N,U]=v.useState(!1),[A,H]=v.useState(null),[V,O]=v.useState({}),E=v.useRef(new Set),L=v.useRef(null),P=$t(e),re=P.length>=g;v.useEffect(()=>()=>{E.current.forEach(T=>URL.revokeObjectURL(T)),E.current.clear()},[]);const Y=v.useCallback(async T=>{if(H(null),P.length>=g){H(`Maximum ${g} file${g>1?"s":""} allowed.`);return}if(T.size>S){H(`File exceeds the ${ue(S)} limit.`);return}if(!R.split(",").map(C=>C.trim()).some(C=>C==="*"||C==="*/*"?!0:C.endsWith("/*")?T.type.startsWith(C.slice(0,-1)):C.startsWith(".")?T.name.toLowerCase().endsWith(C.toLowerCase()):T.type===C)){H(`Invalid type. Accepted: ${de(R)}`);return}if(!(d!=null&&d.onUpload)){H("Upload service not configured.");return}try{const C=await d.onUpload(T),z=URL.createObjectURL(T);E.current.add(z);const K={key:C.key,name:C.name??T.name,blobUrl:z};O(W=>({...W,[C.key]:K}));const q=[...P,C.key];n(r,b?q:q[0])}catch{H("Upload failed. Please try again."),L.current&&(L.current.value="")}},[P,g,S,R,d,r,n,b]);if(a===!1)return null;const ne=T=>{T.preventDefault(),T.stopPropagation(),!(!w||re)&&U(T.type==="dragenter"||T.type==="dragover")},J=T=>{var I;T.preventDefault(),T.stopPropagation(),U(!1),!(!w||re)&&(I=T.dataTransfer.files)!=null&&I[0]&&Y(T.dataTransfer.files[0])},X=T=>{var I;(I=T.target.files)!=null&&I[0]&&(Y(T.target.files[0]),T.target.value="")},Z=T=>{if(!w)return;O(M=>{var K;const C={...M},z=(K=C[T])==null?void 0:K.blobUrl;return z&&(URL.revokeObjectURL(z),E.current.delete(z)),delete C[T],C});const I=P.filter(M=>M!==T);n(r,b?I.length>0?I:null:I[0]??null)},ce=async(T,I)=>{var z,K,q;T.preventDefault();const M=(z=V[I])==null?void 0:z.blobUrl;if(M){(K=window.open(M,"_blank","noopener,noreferrer"))==null||K.focus();return}const C=window.open("","_blank");if(C)try{const W=await((q=d==null?void 0:d.getDownloadUrl)==null?void 0:q.call(d,I));W!=null&&W.url?C.location.href=W.url:C.close()}catch{C.close()}};if(!w&&P.length===0)return null;const te=g-P.length,ie=w&&!re;return t.jsxs(o.Box,{mb:"4",children:[t.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[i,x&&t.jsx(o.Text,{color:"red",children:" *"})]}),t.jsx(o.Text,{size:"1",color:"gray",children:b?`Up to ${g} files · ${ue(S)} each · ${de(R)}`:`${ue(S)} · ${de(R)}`})]}),P.map(T=>{var I;return t.jsx(o.Card,{size:"2",variant:"surface",mb:"2",children:t.jsxs(o.Flex,{align:"center",gap:"3",children:[t.jsx(o.Box,{style:{background:"var(--blue-3)",padding:8,borderRadius:6,color:"var(--blue-9)",flexShrink:0},children:t.jsx(ee.FileTextIcon,{width:"20",height:"20"})}),t.jsx(o.Box,{style:{flex:1,overflow:"hidden"},children:t.jsx(o.Text,{size:"2",weight:"bold",style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((I=V[T])==null?void 0:I.name)??"Uploaded File"})}),t.jsxs(o.Flex,{align:"center",gap:"2",style:{flexShrink:0},children:[t.jsx(o.Button,{variant:"soft",color:"blue",size:"1",onClick:M=>ce(M,T),children:"View"}),t.jsx(ee.CheckCircledIcon,{style:{color:"var(--green-9)",width:18,height:18}}),w&&t.jsx(o.IconButton,{variant:"ghost",color:"gray",onClick:()=>Z(T),children:t.jsx(ee.Cross2Icon,{})})]})]})},T)}),ie&&t.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{var T;return(T=L.current)==null?void 0:T.click()},onKeyDown:T=>{var I;(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),(I=L.current)==null||I.click())},onDragEnter:ne,onDragLeave:ne,onDragOver:ne,onDrop:J,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",N?"border-blue-500 bg-blue-50":A?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:[t.jsx("input",{ref:L,type:"file",style:{display:"none"},accept:R,onChange:X}),t.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:A?t.jsxs(t.Fragment,{children:[t.jsx(ee.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),t.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:A}),t.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):t.jsxs(t.Fragment,{children:[t.jsx(ee.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),t.jsx(o.Text,{size:"2",weight:"medium",children:P.length>0?`Add another file (${te} remaining)`:"Click to upload or drag and drop"}),t.jsxs(o.Text,{size:"1",color:"gray",children:[ue(S)," max · ",de(R)]})]})})]}),w&&re&&b&&t.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&&t.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(s,i)})]})},it=B.withJsonFormsControlProps(_t),ct=y.rankWith(10,y.and(y.schemaMatches(e=>{if(e.type==="string"&&e.format==="file")return!0;if(e.type==="array"){const n=e.items;return(n==null?void 0:n.type)==="string"&&(n==null?void 0:n.format)==="file"}return!1})));function Vt(e,n){return e!==!1&&n!==!0}class we extends Error{}function Jt(e,n){const r=Se.read(e,{type:"array",cellDates:!0});if(r.SheetNames.length===0)throw new we("This file has no sheets.");const i=n??r.SheetNames[0],x=r.Sheets[i];if(!x)throw new we(`This file doesn't have a sheet named "${i}".`);const c=Se.utils.sheet_to_json(x,{header:1,raw:!0,defval:null});return{sheetName:i,matrix:c,rowCount:c.length,colCount:Math.max(0,...c.map(l=>l.length))}}function Kt(e){let n=e+1,r="";for(;n>0;){const i=(n-1)%26;r=String.fromCharCode(65+i)+r,n=Math.floor((n-1)/26)}return r}class _ extends Error{constructor(r,i){super(i??r);Ee(this,"code");this.code=r,this.name="FormulaError"}}const Gt=["IFS","IFERROR","AND","OR","NOT","ROUND","ROUNDUP","ROUNDDOWN","INDEX","VLOOKUP","HLOOKUP","SUM","AVERAGE","COUNT","DATE","TODAY"],Xt=["MAX","MIN","MAXA","MINA","MEDIAN","LARGE","SMALL","PERMUT","PERMUTATIONA","MATCH","SWITCH","SUBSTITUTE","TEXTJOIN","COUNTA","UPPER"],qt=["YEAR","MONTH","DAY","WEEKDAY"],Yt=["IF"],Zt=["CONCATENATE","CONCAT","LEN","TRIM","LOWER","LEFT","RIGHT","MID","FIND","SEARCH"],Qt=new Set([...Gt,...Xt,...qt,...Zt,...Yt]),er=/"(?:[^"]|"")*"/g,Ae=new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(","g");function tr(e){const n=e.replace(er,i=>" ".repeat(i.length));Ae.lastIndex=0;let r;for(;(r=Ae.exec(n))!==null;){const i=r[1].toUpperCase();if(!Qt.has(i))throw new _("NAME",`Function ${i} is not allowed.`)}}function rr(e,n,r){let i=e;if(i==null)throw r.NA;if(typeof i=="object"&&!(i instanceof r)&&(i=n.retrieveRef(i)),i instanceof r)throw i;if(typeof i=="boolean")return i;if(typeof i=="number")return i!==0;throw r.VALUE}function at(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function ae(e){const n=at(e);return Array.isArray(n)?n.flat(1/0):[n]}function F(e){const n=at(e);return Array.isArray(n)?n.flat(1/0)[0]:n}function ye(e){return e===void 0?void 0:F(e)}function $(e){return e==null||e===""?"":typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof Date?e.toLocaleDateString():String(e)}function nr(e,n){return e instanceof n?e:new n(e.message||"#ERROR!")}function D(e){return e.find(n=>n instanceof Error)}function or(e,n){const r=c=>{throw nr(c,n)},i=(c,{checkArgsForErrors:l=!0}={})=>(...u)=>{const s=u.flatMap(ae);if(l){const d=D(s);d&&r(d)}const a=c(...s);return a instanceof Error?r(a):a},x=(c,{toText:l=!1}={})=>u=>{const s=F(u),a=D([s]);a&&r(a);const d=c(l?$(s):s);return d instanceof Error?r(d):d};return{IF:(c,l,u,s)=>{const a=rr(l,c,n);if(u==null)throw n.NA;return a?u:s??!1},MAX:i(e.MAX),MIN:i(e.MIN),MAXA:i(e.MAXA),MINA:i(e.MINA),MEDIAN:i(e.MEDIAN),COUNTA:i(e.COUNTA,{checkArgsForErrors:!1}),LARGE:(c,l)=>{const u=ae(c),s=F(l),a=D([...u,s]);a&&r(a);const d=e.LARGE(u,s);return d instanceof Error?r(d):d},SMALL:(c,l)=>{const u=ae(c),s=F(l),a=D([...u,s]);a&&r(a);const d=e.SMALL(u,s);return d instanceof Error?r(d):d},PERMUT:(c,l)=>{const u=[F(c),F(l)],s=D(u);s&&r(s);const a=e.PERMUT(u[0],u[1]);return a instanceof Error?r(a):a},PERMUTATIONA:(c,l)=>{const u=[F(c),F(l)],s=D(u);s&&r(s);const a=e.PERMUTATIONA(u[0],u[1]);return a instanceof Error?r(a):a},MATCH:(c,l)=>{const u=F(c),s=ae(l),a=D([u,...s]);a&&r(a);const d=e.MATCH(u,s,0);return d instanceof Error?r(d):d},SWITCH:(...c)=>{const l=c.map(F),u=D(l);u&&r(u);const s=e.SWITCH(...l);return s instanceof Error?r(s):s},SUBSTITUTE:(c,l,u,s)=>{const a=[$(F(c)),$(F(l)),$(F(u))];s!==void 0&&a.push(F(s));const d=D(a);d&&r(d);const m=e.SUBSTITUTE(...a);return m instanceof Error?r(m):m},TEXTJOIN:(c,l,...u)=>{const s=$(F(c)),a=F(l),d=u.flatMap(ae).map($),m=D([s,a]);m&&r(m);const h=e.TEXTJOIN(s,a,d);return h instanceof Error?r(h):h},UPPER:x(e.UPPER),YEAR:x(e.YEAR),MONTH:x(e.MONTH),DAY:x(e.DAY),WEEKDAY:(c,l)=>{const u=F(c),s=F(l),a=D([u]);a&&r(a);const d=e.WEEKDAY(u,s);return d instanceof Error?r(d):d},CONCATENATE:(...c)=>{const l=c.flatMap(ae),u=D(l);u&&r(u);const s=e.CONCATENATE(...l.map($));return s instanceof Error?r(s):s},CONCAT:(...c)=>{const l=c.flatMap(ae),u=D(l);u&&r(u);const s=e.CONCAT(...l.map($));return s instanceof Error?r(s):s},LEN:x(e.LEN,{toText:!0}),TRIM:x(e.TRIM,{toText:!0}),LOWER:x(e.LOWER,{toText:!0}),LEFT:(c,l)=>{const u=F(c),s=ye(l),a=D([u]);a&&r(a);const d=e.LEFT($(u),s);return d instanceof Error?r(d):d},RIGHT:(c,l)=>{const u=F(c),s=ye(l),a=D([u]);a&&r(a);const d=e.RIGHT($(u),s);return d instanceof Error?r(d):d},MID:(c,l,u)=>{const s=F(c),a=F(l),d=F(u),m=D([s,a,d]);m&&r(m);const h=e.MID($(s),a,d);return h instanceof Error?r(h):h},FIND:(c,l,u)=>{const s=F(c),a=F(l),d=ye(u),m=D([s,a]);m&&r(m);const h=e.FIND($(s),$(a),d);return h instanceof Error?r(h):h},SEARCH:(c,l,u)=>{const s=F(c),a=F(l),d=ye(u),m=D([s,a]);m&&r(m);const h=e.SEARCH($(s),$(a),d);return h instanceof Error?r(h):h}}}const sr={"#REF!":"REF","#VALUE!":"VALUE","#DIV/0!":"DIV0","#NAME?":"NAME","#N/A":"NA","#NUM!":"NUM","#NULL!":"NULL"};function Fe(e){return sr[e.error]??"ERROR"}function Oe(e,n){if(e instanceof _)return e;if(e instanceof n){const r=e.details;return r instanceof _?r:r instanceof n?new _(Fe(r),r.message):new _(Fe(e),e.message)}return new _("ERROR",e instanceof Error?e.message:void 0)}function lr(e){return Math.max(0,...e.map(n=>(n==null?void 0:n.length)??0))}function ir(e){return n=>{const r=e[n.row-1];if(n.row<1||n.col<1||r==null||n.col-1>=r.length)throw new _("REF");const i=r[n.col-1];return i==null||i===""?null:i}}function cr(e){return n=>{const r=Math.min(n.from.row,n.to.row),i=Math.min(n.from.col,n.to.col),x=Math.max(n.from.row,n.to.row),c=Math.max(n.from.col,n.to.col),l=lr(e);if(r>e.length||i>l)throw new _("REF");const u=Math.min(x,e.length),s=[];for(let a=r;a<=u;a++){const d=e[a-1],m=[];if(d!=null){const h=Math.min(c,d.length);for(let p=i;p<=h;p++){const g=d[p-1];m.push(g==null||g===""?null:g)}}s.push(m)}return s}}function ar(e){if(e==null||e==="")return null;if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date)return e;throw new _("VALUE")}async function ut(e,n){if(typeof e!="string")throw new _("ERROR");const r=e.trim();if(r==="")throw new _("ERROR");const i=r.startsWith("=")?r.slice(1):r;tr(i);const[x,c]=await Promise.all([import("fast-formula-parser"),import("@formulajs/formulajs")]),l=x.default??x,u=l.FormulaError,s=new l({...n,functions:or(c,u)});let a;try{a=s.parse(i,{row:1,col:1,sheet:"Sheet1"})}catch(d){throw Oe(d,u)}if(a instanceof u)throw Oe(a,u);return ar(a)}async function ur(e,n){return ut(n,{onCell:ir(e),onRange:cr(e)})}const Ie=-1;async function dr(e,n){const r=Object.keys(e);return ut(n,{onVariable:i=>{const x=r.indexOf(i);return x===-1?null:{row:Ie,col:x+1}},onCell:i=>{if(i.row===Ie)return e[r[i.col-1]]??null;throw new _("REF")},onRange:()=>{throw new _("REF")}})}const dt={REF:"#REF!",VALUE:"#VALUE!",DIV0:"#DIV/0!",NAME:"#NAME?",ERROR:"#ERROR!",NA:"#N/A",NUM:"#NUM!",NULL:"#NULL!"};function ft(e){const n=e instanceof _?e.code:"ERROR";return dt[n]}async function fr(e,n){return e.length===0?n.map(r=>({id:typeof(r==null?void 0:r.id)=="string"?r.id:"(unknown)",label:(r==null?void 0:r.label)??"(unknown)",value:null,error:dt.ERROR})):Promise.all(n.map(async r=>{try{if(!r||typeof r.label!="string"||typeof r.expression!="string"||typeof r.id!="string")throw new _("ERROR");return{id:r.id,label:r.label,value:await ur(e,r.expression)}}catch(i){return{id:typeof(r==null?void 0:r.id)=="string"?r.id:"(unknown)",label:(r==null?void 0:r.label)??"(unknown)",value:null,error:ft(i)}}}))}function xr(e,n={}){if(n.columnHeader&&n.rowHeader)throw new Error("x-spreadsheet: columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape.");return n.columnHeader?hr(e):n.rowHeader?pr(e):e}function xt(e){return e==null||e===""?null:e instanceof Date?e.toISOString():String(e)}function ht(e,n){const r=new Set;for(const i of e)if(i!=null){if(r.has(i))throw new Error(`x-spreadsheet: duplicate ${n} value "${i}" — every ${n==="columnHeader"?"column header":"column-A value"} must be unique to shape as records.`);r.add(i)}}function hr(e){const[n,...r]=e;if(!n)return[];const i=n.map(xt);return ht(i,"columnHeader"),r.map(x=>{const c=Object.create(null);return i.forEach((l,u)=>{l!=null&&(c[l]=x[u]??null)}),c})}function pr(e){const n=e.map(x=>xt(x[0]));ht(n,"rowHeader");const r=Math.max(0,...e.map(x=>x.length)),i=Math.max(0,r-1);return Array.from({length:i},(x,c)=>{const l=c+1,u=Object.create(null);return n.forEach((s,a)=>{s!=null&&(u[s]=e[a][l]??null)}),u})}function Ne(e){return!Array.isArray(e[0])}async function mr(e,n,r={}){const i=await fr(e,n),x=Object.create(null);for(const{id:c,label:l,value:u,error:s}of i)x[c]=s===void 0?{label:l,value:u}:{label:l,value:u,error:s};return r.persistSheet===!1?{derivations:x}:{sheet:xr(e,r),derivations:x}}const gr=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv",Tr=10*1024*1024,fe=200,ke=50,yr=[];function me(e){return e==null||e===""?"":e instanceof Date?e.toLocaleDateString():String(e)}const br=({data:e,handleChange:n,path:r,label:i,required:x,schema:c,enabled:l,readonly:u,errors:s,visible:a=!0})=>{se(a,r,n,null);const d=!s||s.length===0,m=Vt(l,u),h=(c==null?void 0:c["x-spreadsheet"])??{},p=(c==null?void 0:c["x-evaluate"])??yr,g=h.accept??gr,S=h.maxSize??Tr,R=h.persistSheet!==!1,b=h.columnHeader===!0,w=h.rowHeader===!0,N=h.showSheet!==!1,U=h.sheetName,A=e??null,[H,V]=v.useState(()=>A!=null&&A.sheet||Object.keys((A==null?void 0:A.derivations)??{}).length>0?"ready":"empty"),[O,E]=v.useState(null),[L,P]=v.useState(!1),[re,Y]=v.useState(null),ne=v.useRef(null),J=(A==null?void 0:A.sheet)??null,X=re??(J&&!Ne(J)?J:null),Z=re==null&&J&&Ne(J)?J:null,ce=(A==null?void 0:A.derivations)??{},te=X!=null||A!=null,ie=v.useCallback(async f=>{if(E(null),f.size>S){E(`File exceeds the ${ue(S)} limit.`);return}if(!g.split(",").map(k=>k.trim()).some(k=>k==="*"||k==="*/*"?!0:k.endsWith("/*")?f.type.startsWith(k.slice(0,-1)):k.startsWith(".")?f.name.toLowerCase().endsWith(k.toLowerCase()):f.type===k)){E(`Invalid type. Accepted: ${de(g)}`);return}V("parsing");let Q;try{const k=await f.arrayBuffer();Q=Jt(k,U).matrix}catch(k){V("error"),E(k instanceof we?k.message:"This doesn't look like a valid spreadsheet. Please check the file and try again.");return}Y(Q);let oe;try{oe=await mr(Q,p,{persistSheet:R,columnHeader:b,rowHeader:w})}catch(k){V("error"),E(k instanceof Error?k.message:"Failed to process the uploaded spreadsheet.");return}n(r,oe),V("ready")},[g,S,R,b,w,U,p,r,n]);if(a===!1)return null;if(b&&w)return t.jsxs(o.Box,{mb:"4",children:[t.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:i}),t.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&&!te)return null;const T=f=>{f.preventDefault(),f.stopPropagation(),m&&P(f.type==="dragenter"||f.type==="dragover")},I=f=>{var j;f.preventDefault(),f.stopPropagation(),P(!1),m&&(j=f.dataTransfer.files)!=null&&j[0]&&ie(f.dataTransfer.files[0])},M=f=>{var j;(j=f.target.files)!=null&&j[0]&&(ie(f.target.files[0]),f.target.value="")},C=()=>{m&&(Y(null),E(null),V("empty"),n(r,null))},z=b?1:0,K=w?1:0,q=X?X.slice(z):[],W=q.slice(0,fe),xe=Math.min(ke,Math.max(0,...W.map(f=>Math.max(0,f.length-K)))),he=Array.from({length:xe},(f,j)=>j+K),be=N&&X==null&&Z==null&&A!=null,ge="",ve=w&&!b,Te=Z?Z.slice(0,fe):[],pe=Array.from(new Set(Te.flatMap(f=>Object.keys(f)))).slice(0,ke);return t.jsxs(o.Box,{mb:"4",children:[t.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[t.jsxs(o.Flex,{align:"center",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[i,x&&t.jsx(o.Text,{color:"red",children:" *"})]}),te&&m&&t.jsxs(t.Fragment,{children:[t.jsx(o.Tooltip,{content:"Replace spreadsheet",children:t.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var f;return(f=ne.current)==null?void 0:f.click()},"aria-label":"Replace spreadsheet",children:t.jsx(ee.UploadIcon,{})})}),t.jsx(o.Tooltip,{content:"Remove spreadsheet",children:t.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:C,"aria-label":"Remove spreadsheet",children:t.jsx(ee.Cross2Icon,{})})})]})]}),t.jsxs(o.Text,{size:"1",color:"gray",children:[ue(S)," max · ",de(g)]})]}),te&&O&&t.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:O}),t.jsx("input",{ref:ne,type:"file",style:{display:"none"},accept:g,onChange:M}),m&&!te&&t.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var f;return(f=ne.current)==null?void 0:f.click()},onKeyDown:f=>{var j;(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),(j=ne.current)==null||j.click())},onDragEnter:T,onDragLeave:T,onDragOver:T,onDrop:I,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":O?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:t.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:H==="parsing"?t.jsxs(t.Fragment,{children:[t.jsx(o.Spinner,{size:"3"}),t.jsx(o.Text,{size:"2",color:"gray",children:"Parsing spreadsheet…"})]}):O?t.jsxs(t.Fragment,{children:[t.jsx(ee.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),t.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:O}),t.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):t.jsxs(t.Fragment,{children:[t.jsx(ee.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),t.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),t.jsxs(o.Text,{size:"1",color:"gray",children:[ue(S)," max · ",de(g)]})]})})}),X&&N&&t.jsxs(o.Box,{mt:"3",children:[t.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:t.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[!ve&&t.jsx(o.Table.Header,{children:t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.ColumnHeaderCell,{children:ge}),he.map(f=>{var j;return t.jsx(o.Table.ColumnHeaderCell,{children:b?me((j=X[0])==null?void 0:j[f]):Kt(f)},f)})]})}),t.jsx(o.Table.Body,{children:W.map((f,j)=>{var Q;const G=z+j;return t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.RowHeaderCell,{style:w?{fontWeight:700,background:"var(--gray-a3)"}:void 0,children:w?me((Q=X[G])==null?void 0:Q[0]):b?"":G+1}),he.map(oe=>t.jsx(o.Table.Cell,{children:me(f[oe])},oe))]},j)})})]})}),q.length>fe&&t.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",fe," of ",q.length," rows"]})]}),Z&&N&&t.jsxs(o.Box,{mt:"3",children:[t.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:t.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[t.jsx(o.Table.Header,{children:t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.ColumnHeaderCell,{}),pe.map(f=>t.jsx(o.Table.ColumnHeaderCell,{children:f},f))]})}),t.jsx(o.Table.Body,{children:Te.map((f,j)=>t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.RowHeaderCell,{children:j+1}),pe.map(G=>t.jsx(o.Table.Cell,{children:me(f[G])},G))]},j))})]})}),Z.length>fe&&t.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",fe," of ",Z.length," rows"]})]}),be&&t.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(ce).length>0&&t.jsxs(o.Box,{mt:"3",children:[t.jsx(o.Text,{size:"2",weight:"bold",as:"div",mb:"1",children:"Computed values"}),t.jsx(o.Flex,{direction:"column",gap:"1",children:Object.entries(ce).map(([f,j])=>t.jsxs(o.Flex,{justify:"between",children:[t.jsx(o.Text,{size:"2",children:j.label}),j.error?t.jsx(o.Text,{size:"2",color:"red",children:j.error}):t.jsx(o.Text,{size:"2",children:me(j.value)})]},f))})]}),!d&&t.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(s,i)})]})},pt=B.withJsonFormsControlProps(br),mt=y.rankWith(10,y.schemaMatches(e=>e.type==="object"&&typeof e["x-spreadsheet"]=="object"));function vr(e,n,r){const i={};for(const[x,c]of Object.entries(r)){const{path:l,default:u}=typeof c=="string"?{path:c,default:void 0}:c,s=n?`${n}.${l}`:l,a=y.Resolve.data(e,s);if(a==null){if(u===void 0)return;i[x]=u}else i[x]=a}return i}async function jr(e,n){try{return{status:"ok",value:await dr(e,n)}}catch(r){return{status:"error",error:ft(r)}}}function wr(e,n){return e==null?"":typeof e=="number"?e.toFixed(Cr(n)):e instanceof Date?e.toLocaleDateString():String(e)}function Cr(e){return Number.isFinite(e)?Math.min(100,Math.max(0,Math.trunc(e))):0}const Le="{value}",Rr=2,Er={},Sr=({data:e,handleChange:n,path:r,label:i,schema:x,visible:c=!0})=>{var H;se(c,r,n,null);const l=x==null?void 0:x["x-computed"],u=(l==null?void 0:l.inputs)??Er,s=(l==null?void 0:l.formula)??"",a=(l==null?void 0:l.format)??Le,d=(l==null?void 0:l.decimals)??Rr,m=B.useJsonForms(),h=r.split(".").slice(0,-1).join("."),p=vr((H=m.core)==null?void 0:H.data,h,u),g=p?JSON.stringify(p):null,S=m.readonly===!0,[R,b]=v.useState(()=>typeof e=="number"?"ok":"unavailable"),[w,N]=v.useState(()=>typeof e=="number"?e:null),[U,A]=v.useState(null);return v.useEffect(()=>{if(!c)return;let V=!1;const O=E=>{S||E!==(e??null)&&n(r,E)};if(p===void 0){b("unavailable"),A(null),N(null),O(null);return}return b(E=>E==="ok"?E:"loading"),jr(p,s).then(E=>{if(V)return;const L=E.status==="ok"&&typeof E.value=="number"&&Number.isFinite(E.value)?E.value:null;if(L===null){b("error"),A(E.status==="error"?E.error??"Unable to compute value.":"Computed value must be a number."),N(null),O(null);return}b("ok"),A(null),N(L),O(L)}),()=>{V=!0}},[g,s,c,S]),c===!1?null:t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:i}),R==="unavailable"?t.jsx(o.Text,{size:"2",color:"gray",children:"Not yet available."}):R==="loading"?t.jsxs(o.Flex,{align:"center",gap:"2",children:[t.jsx(o.Spinner,{size:"1"}),t.jsx(o.Text,{size:"2",color:"gray",children:"Computing…"})]}):R==="error"?t.jsx(o.Text,{size:"2",color:"red",children:U}):t.jsx(o.Text,{size:"2",children:a.split(Le).join(wr(w,d))}),x.description&&t.jsx(o.Text,{size:"1",color:"gray",children:x.description})]})})},gt=B.withJsonFormsControlProps(Sr),Tt=y.rankWith(5,y.schemaMatches(e=>{const n=e["x-computed"];return e.type==="number"&&typeof n=="object"&&n!==null})),Ar=({data:e,path:n,schema:r,uischema:i,enabled:x,visible:c,addItem:l,removeItems:u,rootSchema:s,arraySchema:a})=>{const d=a?r:r.items,m=a||r;if(c===!1||!d||typeof d!="object"||Array.isArray(d))return null;const h=d,p=Array.isArray(e)?e:[],g=m.title||"Array Items",S=()=>{const b=y.createDefaultValue(h,s);l&&l(n,b)()},R=b=>{if(u){const w=u(n,[b]);w&&w()}};return t.jsx(o.Box,{mb:"6",children:t.jsxs(o.Flex,{direction:"column",gap:"4",children:[t.jsx(o.Text,{as:"div",size:"4",weight:"bold",children:g}),p.length===0&&t.jsx(o.Box,{py:"4",px:"4",style:{backgroundColor:"var(--gray-3)",borderRadius:"var(--radius-3)"},children:t.jsx(o.Text,{size:"2",color:"gray",children:"No items have been added yet."})}),p.map((b,w)=>{var U;const N=`${n}.${w}`;return t.jsx(o.Card,{size:"3",variant:"surface",children:t.jsxs(o.Flex,{direction:"column",gap:"4",children:[t.jsxs(o.Flex,{justify:"between",align:"center",children:[t.jsxs(o.Text,{size:"3",weight:"bold",children:["Item ",w+1]}),x&&t.jsxs(o.Button,{type:"button",color:"red",variant:"soft",onClick:()=>R(w),title:"Remove item",children:[t.jsx(ee.TrashIcon,{}),"Remove"]})]}),t.jsx(o.Box,{children:t.jsx(B.JsonFormsDispatch,{schema:h,uischema:((U=i.options)==null?void 0:U.detail)||(h.type==="object"||h.properties?{type:"VerticalLayout",elements:Object.keys(h.properties||{}).map(A=>({type:"Control",scope:`#/properties/${A}`}))}:{type:"Control",scope:"#"}),path:N,enabled:x,renderers:void 0,cells:void 0})})]})},N)}),x&&t.jsx(o.Box,{mt:"2",children:t.jsxs(o.Button,{type:"button",variant:"surface",onClick:S,children:[t.jsx(ee.PlusIcon,{}),"Add Item"]})})]})})},Ce=B.withJsonFormsArrayControlProps(Ar),yt=y.rankWith(3,y.isObjectArrayControl),bt=({uischema:e,visible:n})=>{const r=e;return n===!1?null:t.jsx(o.Box,{mb:"4",children:t.jsx(o.Heading,{size:"4",children:r.text})})},vt=y.rankWith(1,y.uiTypeIs("Label")),Fr=y.rankWith(3,y.isPrimitiveArrayControl),Or=[{tester:Pe,renderer:kt},{tester:We,renderer:Lt},{tester:_e,renderer:Mt},{tester:Je,renderer:zt},{tester:qe,renderer:Xe},{tester:Ge,renderer:Dt},{tester:Ze,renderer:Wt},{tester:et,renderer:Qe},{tester:rt,renderer:tt},{tester:ot,renderer:nt},{tester:lt,renderer:st},{tester:ct,renderer:it},{tester:mt,renderer:pt},{tester:Tt,renderer:gt},{tester:yt,renderer:Ce},{tester:Fr,renderer:Ce},{tester:vt,renderer:bt}];exports.ArrayControl=Ce;exports.ArrayControlTester=yt;exports.BooleanControl=$e;exports.BooleanControlTester=_e;exports.CategorizationLayoutRenderer=st;exports.CategorizationLayoutTester=lt;exports.ComputedControl=gt;exports.ComputedControlTester=Tt;exports.DateControl=Ye;exports.DateControlTester=Ze;exports.FileControl=it;exports.FileControlTester=ct;exports.GroupLayoutRenderer=nt;exports.GroupLayoutTester=ot;exports.HorizontalLayoutRenderer=tt;exports.HorizontalLayoutTester=rt;exports.LabelRenderer=bt;exports.LabelTester=vt;exports.NumberControl=He;exports.NumberControlTester=We;exports.RadioControl=Ve;exports.RadioControlTester=Je;exports.SearchSelectControl=Xe;exports.SearchSelectControlTester=qe;exports.SearchServiceProvider=Nt;exports.SelectControl=Ke;exports.SelectControlTester=Ge;exports.SpreadsheetControl=pt;exports.SpreadsheetControlTester=mt;exports.TextControl=Be;exports.TextControlTester=Pe;exports.UploadProvider=It;exports.VerticalLayoutRenderer=Qe;exports.VerticalLayoutTester=et;exports.radixRenderers=Or;exports.useSearchService=Ue;exports.useUpload=ze;
3
+ `):"",Be=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,uischema:i,schema:u,enabled:s,visible:a=!0})=>{var m;if(se(a,r,n),a===!1)return null;const d=c.length===0;return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[l," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsx(o.TextField.Root,{value:e||"",onChange:h=>n(r,h.target.value),disabled:!s,placeholder:(m=i.options)==null?void 0:m.placeholder,color:d?void 0:"red",id:r}),!d&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,l)}),u.description&&t.jsx(o.Text,{size:"1",color:"gray",children:u.description})]})})},Pe=y.rankWith(1,y.isStringControl),kt=H.withJsonFormsControlProps(Be),He=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,uischema:i,schema:u,enabled:s,visible:a=!0})=>{var h;if(se(a,r,n),a===!1)return null;const d=c.length===0,m=p=>{if(p===""){n(r,void 0);return}const g=Number(p);isNaN(g)||n(r,g)};return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[l," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsx(o.TextField.Root,{type:"number",value:e??"",onChange:p=>m(p.target.value),disabled:!s,placeholder:(h=i.options)==null?void 0:h.placeholder,color:d?void 0:"red",id:r}),!d&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,l)}),u.description&&t.jsx(o.Text,{size:"1",color:"gray",children:u.description})]})})},We=y.rankWith(2,y.or(y.isNumberControl,y.isIntegerControl)),Lt=H.withJsonFormsControlProps(He),$e=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,schema:i,enabled:u,visible:s=!0})=>{if(se(s,r,n),s===!1)return null;const a=c.length===0;return t.jsxs(o.Box,{mb:"4",children:[t.jsxs(o.Flex,{gap:"2",align:"center",children:[t.jsx(o.Checkbox,{checked:!!e,onCheckedChange:d=>n(r,d===!0),disabled:!u,id:r}),t.jsxs(o.Text,{as:"label",size:"2",htmlFor:r,children:[l," ",x&&"*"]})]}),!a&&t.jsx(o.Text,{color:"red",size:"1",className:"block mt-1",children:le(c,l)}),i.description&&t.jsx(o.Text,{size:"1",color:"gray",className:"block mt-1",children:i.description})]})},_e=y.rankWith(2,y.isBooleanControl),Mt=H.withJsonFormsControlProps($e),Ve=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,schema:i,enabled:u,visible:s=!0})=>{if(se(s,r,n),s===!1)return null;const a=c.length===0;let d=[];i.enum?d=i.enum.map(h=>({value:h,label:String(h)})):i.oneOf&&(d=i.oneOf.map(h=>({value:h.const,label:h.title||String(h.const)})));const m=e;return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"div",size:"2",weight:"bold",children:[l," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsx(o.RadioGroup.Root,{value:m!==void 0?String(m):"",onValueChange:h=>{const p=d.find(g=>String(g.value)===h);p&&n(r,p.value)},disabled:!u,children:t.jsx(o.Flex,{direction:"row",style:{flexWrap:"wrap",columnGap:"clamp(14px, 3vw, 36px)",rowGap:"clamp(8px, 1.6vw, 14px)"},children:d.map(h=>t.jsxs(o.Flex,{align:"center",gap:"2",style:{minWidth:"max-content"},children:[t.jsx(o.RadioGroup.Item,{value:String(h.value)}),t.jsx(o.Text,{size:"2",color:u?void 0:"gray",children:h.label})]},String(h.value)))})}),!a&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,l)}),i.description&&t.jsx(o.Text,{size:"1",color:"gray",children:i.description})]})})},Je=(e,n,r)=>{var x;return y.or(y.isEnumControl,y.isOneOfControl)(e,n,r)&&((x=e==null?void 0:e.options)==null?void 0:x.format)==="radio"?3:-1},zt=H.withJsonFormsControlProps(Ve),Ke=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,schema:i,uischema:u,enabled:s,visible:a=!0})=>{var p;if(se(a,r,n),a===!1)return null;const d=c.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 h=e!==void 0?String(e):"";return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[l," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsxs(o.Select.Root,{value:h,onValueChange:g=>n(r,g),disabled:!s,children:[t.jsx(o.Select.Trigger,{placeholder:((p=u.options)==null?void 0:p.placeholder)||"Select an option",color:d?void 0:"red",id:r}),t.jsx(o.Select.Content,{children:m.map(g=>t.jsx(o.Select.Item,{value:g.value,children:g.label},g.value))})]}),!d&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,l)}),i.description&&t.jsx(o.Text,{size:"1",color:"gray",children:i.description})]})})},Ge=y.rankWith(2,y.or(y.isEnumControl,y.isOneOfControl)),Dt=H.withJsonFormsControlProps(Ke),Ut={"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}},Bt=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,enabled:i,visible:u=!0,schema:s,uischema:a})=>{var pe;const d=(s==null?void 0:s["x-search"])??{service:""},m=d.service??"",h=d.mode??"large-paginated-list",p=Ut[h],g=(p==null?void 0:p.fetchOnOpen)??!1,S=d.params,R=Ue(m),v=s.type==="object",A=v?typeof e=="string"?{value:e}:e??void 0:void 0,N=v?A==null?void 0:A.value:e,L=A==null?void 0:A.label,w=m?R?p?null:`Invalid x-search.mode "${h}". Expected "small-list", "large-searchable-list", or "large-paginated-list".`:`Search service "${m}" is not registered.`:"Search not configured.",z=i!==!1,P=!c||c.length===0,[F,E]=b.useState(!1),[M,W]=b.useState(""),[re,Y]=b.useState([]),[ne,J]=b.useState(!1),[X,Z]=b.useState(!1),[ce,te]=b.useState(!1),[ie,T]=b.useState(null),[I,D]=b.useState(void 0),C=b.useRef(void 0),U=b.useRef(null),K=b.useRef(null),q=b.useRef(null),$=b.useRef(void 0);b.useEffect(()=>{var j,G;if(!N){D(void 0),$.current=void 0;return}if(((j=$.current)==null?void 0:j.value)===N&&((G=$.current)==null?void 0:G.label)===L)return;if($.current={value:N,label:L},v&&L){D({id:N,name:L});return}if(D({id:N,name:L??N}),!(R!=null&&R.resolve))return;let f=!1;return R.resolve(N,S).then(Q=>{!f&&Q&&D(Q)}).catch(()=>{}),()=>{f=!0}},[N,L,v,R,S]);const xe=b.useCallback(async(f,j=!1)=>{var Q;if(!R){T("Search service not configured.");return}(Q=K.current)==null||Q.abort();const G=new AbortController;K.current=G,j?te(!0):(Z(!0),te(!1),T(null));try{const oe=await R.search({query:f,cursor:j?C.current:void 0,signal:G.signal,params:S}),k=oe.options??[];Y(j?jt=>[...jt,...k]:k),C.current=oe.nextCursor,J(((p==null?void 0:p.paginated)??!1)&&oe.nextCursor!=null)}catch{if(G.signal.aborted)return;T("Failed to load results. Please try again.")}finally{G.signal.aborted||(j?te(!1):Z(!1))}},[R,p==null?void 0:p.paginated,S]);if(b.useEffect(()=>{if(!F)return;const f=j=>{q.current&&!q.current.contains(j.target)&&E(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[F]),b.useEffect(()=>{var f;F||((f=K.current)==null||f.abort(),W(""),Y([]),J(!1),T(null),Z(!1),te(!1),C.current=void 0)},[F]),b.useEffect(()=>{if(!F)return;if(!M&&!g){Y([]),J(!1),T(null),C.current=void 0;return}U.current&&clearTimeout(U.current);const f=M?300:0;return U.current=setTimeout(()=>{Y([]),J(!1),C.current=void 0,xe(M)},f),()=>{U.current&&clearTimeout(U.current)}},[M,F,g,xe]),se(u,r,n,v?void 0:null),u===!1)return null;const he=()=>{W(""),Y([]),J(!1),T(null),C.current=void 0,E(!0)},be=f=>{n(r,v?{value:f.id,label:f.name}:f.id),D(f),$.current={value:f.id,label:v?f.name:void 0},E(!1)},ge=f=>{f.stopPropagation(),n(r,v?void 0:null),D(void 0)},ve=f=>{(f.key==="Enter"||f.key===" ")&&ge(f)},Te=((pe=a==null?void 0:a.options)==null?void 0:pe.placeholder)??"Select an option";return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:r,children:[l," ",x&&t.jsx(o.Text,{color:"red",children:"*"})]}),t.jsxs("div",{ref:q,style:{position:"relative"},children:[t.jsx(o.TextField.Root,{id:r,value:F?M:(I==null?void 0:I.name)??"",placeholder:F&&(p!=null&&p.searchable)?"Search...":Te,disabled:!z,readOnly:F&&!(p!=null&&p.searchable),style:P?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:f=>{p!=null&&p.searchable&&(W(f.target.value),F||he())},onFocus:()=>{z&&!F&&he()},onKeyDown:f=>{f.key==="Escape"&&E(!1)},children:t.jsx(o.TextField.Slot,{side:"right",children:t.jsxs(o.Flex,{align:"center",gap:"1",children:[N&&z&&t.jsx("span",{role:"button",tabIndex:0,onMouseDown:f=>f.preventDefault(),onClick:ge,onKeyDown:ve,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),t.jsx(ee.ChevronDownIcon,{style:{transform:F?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),F&&t.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:w?t.jsx(o.Box,{p:"3",children:t.jsx(o.Text,{size:"2",color:"gray",children:w})}):t.jsx(o.ScrollArea,{style:{maxHeight:240},children:t.jsxs(o.Box,{p:"1",children:[X&&t.jsx(o.Flex,{justify:"center",p:"4",children:t.jsx(o.Spinner,{})}),!X&&ie&&t.jsx(o.Box,{px:"3",py:"2",children:t.jsx(o.Text,{size:"2",color:"red",children:ie})}),!X&&!ie&&re.length===0&&t.jsx(o.Box,{px:"3",py:"2",children:t.jsx(o.Text,{size:"2",color:"gray",children:M||g?"No results found.":"Type to search…"})}),re.map(f=>t.jsx(o.Box,{px:"3",py:"2",onMouseDown:j=>j.preventDefault(),onClick:()=>be(f),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:f.id===N?"var(--accent-3)":void 0},className:"hover:bg-(--gray-3)",children:t.jsx(o.Text,{size:"2",children:f.name})},f.id)),(p==null?void 0:p.paginated)&&ne&&!ce&&t.jsx(o.Box,{px:"3",py:"2",children:t.jsx(o.Button,{variant:"ghost",size:"1",style:{width:"100%"},onMouseDown:f=>f.preventDefault(),onClick:()=>void xe(M,!0),children:"Load more"})}),ce&&t.jsx(o.Flex,{justify:"center",p:"2",children:t.jsx(o.Spinner,{})})]})})})]}),!P&&t.jsx(o.Text,{color:"red",size:"1",children:le(c,l)}),s.description&&t.jsx(o.Text,{size:"1",color:"gray",children:s.description})]})})},Xe=H.withJsonFormsControlProps(Bt),qe=y.rankWith(3,y.schemaMatches(e=>{const n=e["x-search"];return(e.type==="string"||e.type==="object")&&typeof(n==null?void 0:n.service)=="string"&&n.service!==""})),Pt=(e,n)=>Ot(`${e}T${n}`).format(),Ht=({path:e,label:n,required:r,errors:l,description:x,children:c})=>{const i=l.length===0;return t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:e,children:[n," ",r&&t.jsx(o.Text,{color:"red",children:"*"})]}),c,!i&&t.jsx(o.Text,{color:"red",size:"1",children:le(l,n)}),x&&t.jsx(o.Text,{size:"1",color:"gray",children:x})]})})},Ye=({data:e,handleChange:n,path:r,label:l,required:x,errors:c,schema:i,enabled:u,visible:s=!0})=>{if(b.useEffect(()=>{s===!1&&n(r,void 0)},[s,r,n]),s===!1)return null;const a=c.length===0,d=typeof e=="string"?e:"",m=v=>t.jsx(Ht,{path:r,label:l,required:x,errors:c,description:i.description,children:v});if(i.format==="time")return m(t.jsx(o.TextField.Root,{type:"time",value:d,onChange:v=>n(r,v.target.value),disabled:!u,color:a?void 0:"red",id:r}));const h=i.format==="date-time",[p="",g=""]=d.split("T"),S=g.slice(0,5),R=(v,A)=>{if(!v){n(r,void 0);return}n(r,h?Pt(v,A||"00:00"):v)};return m(t.jsxs(o.Flex,{gap:"2",align:"center",children:[t.jsx(o.TextField.Root,{type:"date",value:p,disabled:!u,color:a?void 0:"red",onChange:v=>R(v.target.value,S),id:r,style:{flex:1}}),h&&t.jsx(o.TextField.Root,{type:"time",value:S,disabled:!u||!p,color:a?void 0:"red",onChange:v=>R(p,v.target.value),style:{flex:1}})]}))},Ze=y.rankWith(2,y.or(y.isDateControl,y.isDateTimeControl,y.isTimeControl)),Wt=H.withJsonFormsControlProps(Ye),Qe=({uischema:e,schema:n,path:r,renderers:l,cells:x,enabled:c,visible:i=!0})=>{const s=e.elements;return i===!1?null:t.jsx(o.Flex,{direction:"column",gap:"4",children:s.map((a,d)=>t.jsx(H.JsonFormsDispatch,{uischema:a,schema:n,path:r,renderers:l,cells:x,enabled:c},`${r}-${d}`))})},et=y.rankWith(1,y.uiTypeIs("VerticalLayout")),tt=({uischema:e,schema:n,path:r,renderers:l,cells:x,enabled:c,visible:i=!0})=>{const s=e.elements;return i===!1?null:t.jsx(o.Flex,{direction:"row",gap:"4",children:s.map((a,d)=>t.jsx(o.Box,{style:{flex:1},children:t.jsx(H.JsonFormsDispatch,{uischema:a,schema:n,path:r,renderers:l,cells:x,enabled:c})},`${r}-${d}`))})},rt=y.rankWith(1,y.uiTypeIs("HorizontalLayout")),nt=({uischema:e,schema:n,path:r,renderers:l,cells:x,enabled:c,visible:i=!0})=>{const u=e,s=u.elements;return i===!1?null:t.jsxs(o.Box,{mb:"6",children:[u.label&&t.jsx(o.Heading,{size:"3",mb:"3",className:"text-gray-500 uppercase tracking-wide font-semibold",children:u.label}),t.jsx(o.Flex,{direction:"column",gap:"4",children:s.map((a,d)=>t.jsx(H.JsonFormsDispatch,{uischema:a,schema:n,path:r,renderers:l,cells:x,enabled:c},`${r}-${d}`))})]})},ot=y.rankWith(1,y.uiTypeIs("Group")),st=({uischema:e,schema:n,path:r,renderers:l,cells:x,enabled:c,visible:i=!0})=>{var h;const s=e.elements.filter(p=>p.type==="Category"),[a,d]=b.useState(((h=s[0])==null?void 0:h.label)||"");if(i===!1||!s.length)return null;const m=s.find(p=>p.label===a)?a:s[0].label;return t.jsxs(o.Tabs.Root,{value:m,onValueChange:d,children:[t.jsx(o.Tabs.List,{children:s.map((p,g)=>t.jsx(o.Tabs.Trigger,{value:p.label,children:p.label},`${r}-${g}`))}),t.jsx(o.Box,{pt:"3",children:s.map((p,g)=>t.jsx(o.Tabs.Content,{value:p.label,children:t.jsx(o.Flex,{direction:"column",gap:"4",children:p.elements.map((S,R)=>t.jsx(H.JsonFormsDispatch,{uischema:S,schema:n,path:r,renderers:l,cells:x,enabled:c},`${r}-${g}-${R}`))})},`${r}-${g}`))})]})},lt=y.rankWith(1,y.uiTypeIs("Categorization"));function ue(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}function de(e){return e.split(",").map(n=>{if(n=n.trim(),n.endsWith("/*"))return n.split("/")[0].toUpperCase()+"S";if(n.startsWith("."))return n.slice(1).toUpperCase();const r=n.split("/")[1];return r?r.toUpperCase():n}).join(", ")}function $t(e){return e?Array.isArray(e)?e:[e]:[]}const _t=({data:e,handleChange:n,path:r,label:l,required:x,uischema:c,schema:i,enabled:u,errors:s,visible:a=!0})=>{const d=ze();se(a,r,n,null);const m=!s||s.length===0,h=(i==null?void 0:i["x-file"])??{},p=(c==null?void 0:c.options)??{},g=h.maxFiles??p.maxFiles??1,S=h.maxSize??p.maxSize??5*1024*1024,R=h.accept??p.accept??"image/*,application/pdf",v=g>1,A=u!==!1,[N,L]=b.useState(!1),[w,z]=b.useState(null),[P,F]=b.useState({}),E=b.useRef(new Set),M=b.useRef(null),W=$t(e),re=W.length>=g;b.useEffect(()=>()=>{E.current.forEach(T=>URL.revokeObjectURL(T)),E.current.clear()},[]);const Y=b.useCallback(async T=>{if(z(null),W.length>=g){z(`Maximum ${g} file${g>1?"s":""} allowed.`);return}if(T.size>S){z(`File exceeds the ${ue(S)} limit.`);return}if(!R.split(",").map(C=>C.trim()).some(C=>C==="*"||C==="*/*"?!0:C.endsWith("/*")?T.type.startsWith(C.slice(0,-1)):C.startsWith(".")?T.name.toLowerCase().endsWith(C.toLowerCase()):T.type===C)){z(`Invalid type. Accepted: ${de(R)}`);return}if(!(d!=null&&d.onUpload)){z("Upload service not configured.");return}try{const C=await d.onUpload(T),U=URL.createObjectURL(T);E.current.add(U);const K={key:C.key,name:C.name??T.name,blobUrl:U};F($=>({...$,[C.key]:K}));const q=[...W,C.key];n(r,v?q:q[0])}catch{z("Upload failed. Please try again."),M.current&&(M.current.value="")}},[W,g,S,R,d,r,n,v]);if(a===!1)return null;const ne=T=>{T.preventDefault(),T.stopPropagation(),!(!A||re)&&L(T.type==="dragenter"||T.type==="dragover")},J=T=>{var I;T.preventDefault(),T.stopPropagation(),L(!1),!(!A||re)&&(I=T.dataTransfer.files)!=null&&I[0]&&Y(T.dataTransfer.files[0])},X=T=>{var I;(I=T.target.files)!=null&&I[0]&&(Y(T.target.files[0]),T.target.value="")},Z=T=>{if(!A)return;F(D=>{var K;const C={...D},U=(K=C[T])==null?void 0:K.blobUrl;return U&&(URL.revokeObjectURL(U),E.current.delete(U)),delete C[T],C});const I=W.filter(D=>D!==T);n(r,v?I.length>0?I:null:I[0]??null)},ce=async(T,I)=>{var U,K,q;T.preventDefault();const D=(U=P[I])==null?void 0:U.blobUrl;if(D){(K=window.open(D,"_blank","noopener,noreferrer"))==null||K.focus();return}const C=window.open("","_blank");if(C)try{const $=await((q=d==null?void 0:d.getDownloadUrl)==null?void 0:q.call(d,I));$!=null&&$.url?C.location.href=$.url:C.close()}catch{C.close()}};if(!A&&W.length===0)return null;const te=g-W.length,ie=A&&!re;return t.jsxs(o.Box,{mb:"4",children:[t.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[l,x&&t.jsx(o.Text,{color:"red",children:" *"})]}),t.jsx(o.Text,{size:"1",color:"gray",children:v?`Up to ${g} files · ${ue(S)} each · ${de(R)}`:`${ue(S)} · ${de(R)}`})]}),W.map(T=>{var I;return t.jsx(o.Card,{size:"2",variant:"surface",mb:"2",children:t.jsxs(o.Flex,{align:"center",gap:"3",children:[t.jsx(o.Box,{style:{background:"var(--blue-3)",padding:8,borderRadius:6,color:"var(--blue-9)",flexShrink:0},children:t.jsx(ee.FileTextIcon,{width:"20",height:"20"})}),t.jsx(o.Box,{style:{flex:1,overflow:"hidden"},children:t.jsx(o.Text,{size:"2",weight:"bold",style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((I=P[T])==null?void 0:I.name)??"Uploaded File"})}),t.jsxs(o.Flex,{align:"center",gap:"2",style:{flexShrink:0},children:[t.jsx(o.Button,{variant:"soft",color:"blue",size:"1",onClick:D=>ce(D,T),children:"View"}),t.jsx(ee.CheckCircledIcon,{style:{color:"var(--green-9)",width:18,height:18}}),A&&t.jsx(o.IconButton,{variant:"ghost",color:"gray",onClick:()=>Z(T),children:t.jsx(ee.Cross2Icon,{})})]})]})},T)}),ie&&t.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{var T;return(T=M.current)==null?void 0:T.click()},onKeyDown:T=>{var I;(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),(I=M.current)==null||I.click())},onDragEnter:ne,onDragLeave:ne,onDragOver:ne,onDrop:J,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",N?"border-blue-500 bg-blue-50":w?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:[t.jsx("input",{ref:M,type:"file",style:{display:"none"},accept:R,onChange:X}),t.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:w?t.jsxs(t.Fragment,{children:[t.jsx(ee.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),t.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:w}),t.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):t.jsxs(t.Fragment,{children:[t.jsx(ee.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),t.jsx(o.Text,{size:"2",weight:"medium",children:W.length>0?`Add another file (${te} remaining)`:"Click to upload or drag and drop"}),t.jsxs(o.Text,{size:"1",color:"gray",children:[ue(S)," max · ",de(R)]})]})})]}),A&&re&&v&&t.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&&t.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(s,l)})]})},it=H.withJsonFormsControlProps(_t),ct=y.rankWith(10,y.and(y.schemaMatches(e=>{if(e.type==="string"&&e.format==="file")return!0;if(e.type==="array"){const n=e.items;return(n==null?void 0:n.type)==="string"&&(n==null?void 0:n.format)==="file"}return!1})));function Vt(e,n){return e!==!1&&n!==!0}class we extends Error{}function Jt(e,n){const r=Se.read(e,{type:"array",cellDates:!0});if(r.SheetNames.length===0)throw new we("This file has no sheets.");const l=n??r.SheetNames[0],x=r.Sheets[l];if(!x)throw new we(`This file doesn't have a sheet named "${l}".`);const c=Se.utils.sheet_to_json(x,{header:1,raw:!0,defval:null});return{sheetName:l,matrix:c,rowCount:c.length,colCount:Math.max(0,...c.map(i=>i.length))}}function Kt(e){let n=e+1,r="";for(;n>0;){const l=(n-1)%26;r=String.fromCharCode(65+l)+r,n=Math.floor((n-1)/26)}return r}class V extends Error{constructor(r,l){super(l??r);Ee(this,"code");this.code=r,this.name="FormulaError"}}const Gt=["IFS","IFERROR","AND","OR","NOT","ROUND","ROUNDUP","ROUNDDOWN","INDEX","VLOOKUP","HLOOKUP","SUM","AVERAGE","COUNT","DATE","TODAY"],Xt=["MAX","MIN","MAXA","MINA","MEDIAN","LARGE","SMALL","PERMUT","PERMUTATIONA","MATCH","SWITCH","SUBSTITUTE","TEXTJOIN","COUNTA","UPPER"],qt=["YEAR","MONTH","DAY","WEEKDAY"],Yt=["IF"],Zt=["CONCATENATE","CONCAT","LEN","TRIM","LOWER","LEFT","RIGHT","MID","FIND","SEARCH"],Qt=new Set([...Gt,...Xt,...qt,...Zt,...Yt]),er=/"(?:[^"]|"")*"/g,Ae=new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(","g");function tr(e){const n=e.replace(er,l=>" ".repeat(l.length));Ae.lastIndex=0;let r;for(;(r=Ae.exec(n))!==null;){const l=r[1].toUpperCase();if(!Qt.has(l))throw new V("NAME",`Function ${l} is not allowed.`)}}function rr(e,n,r){let l=e;if(l==null)throw r.NA;if(typeof l=="object"&&!(l instanceof r)&&(l=n.retrieveRef(l)),l instanceof r)throw l;if(typeof l=="boolean")return l;if(typeof l=="number")return l!==0;throw r.VALUE}function at(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function ae(e){const n=at(e);return Array.isArray(n)?n.flat(1/0):[n]}function O(e){const n=at(e);return Array.isArray(n)?n.flat(1/0)[0]:n}function ye(e){return e===void 0?void 0:O(e)}function _(e){return e==null||e===""?"":typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof Date?e.toLocaleDateString():String(e)}function nr(e,n){return e instanceof n?e:new n(e.message||"#ERROR!")}function B(e){return e.find(n=>n instanceof Error)}function or(e,n){const r=c=>{throw nr(c,n)},l=(c,{checkArgsForErrors:i=!0}={})=>(...u)=>{const s=u.flatMap(ae);if(i){const d=B(s);d&&r(d)}const a=c(...s);return a instanceof Error?r(a):a},x=(c,{toText:i=!1}={})=>u=>{const s=O(u),a=B([s]);a&&r(a);const d=c(i?_(s):s);return d instanceof Error?r(d):d};return{IF:(c,i,u,s)=>{const a=rr(i,c,n);if(u==null)throw n.NA;return a?u:s??!1},MAX:l(e.MAX),MIN:l(e.MIN),MAXA:l(e.MAXA),MINA:l(e.MINA),MEDIAN:l(e.MEDIAN),COUNTA:l(e.COUNTA,{checkArgsForErrors:!1}),LARGE:(c,i)=>{const u=ae(c),s=O(i),a=B([...u,s]);a&&r(a);const d=e.LARGE(u,s);return d instanceof Error?r(d):d},SMALL:(c,i)=>{const u=ae(c),s=O(i),a=B([...u,s]);a&&r(a);const d=e.SMALL(u,s);return d instanceof Error?r(d):d},PERMUT:(c,i)=>{const u=[O(c),O(i)],s=B(u);s&&r(s);const a=e.PERMUT(u[0],u[1]);return a instanceof Error?r(a):a},PERMUTATIONA:(c,i)=>{const u=[O(c),O(i)],s=B(u);s&&r(s);const a=e.PERMUTATIONA(u[0],u[1]);return a instanceof Error?r(a):a},MATCH:(c,i)=>{const u=O(c),s=ae(i),a=B([u,...s]);a&&r(a);const d=e.MATCH(u,s,0);return d instanceof Error?r(d):d},SWITCH:(...c)=>{const i=c.map(O),u=B(i);u&&r(u);const s=e.SWITCH(...i);return s instanceof Error?r(s):s},SUBSTITUTE:(c,i,u,s)=>{const a=[_(O(c)),_(O(i)),_(O(u))];s!==void 0&&a.push(O(s));const d=B(a);d&&r(d);const m=e.SUBSTITUTE(...a);return m instanceof Error?r(m):m},TEXTJOIN:(c,i,...u)=>{const s=_(O(c)),a=O(i),d=u.flatMap(ae).map(_),m=B([s,a]);m&&r(m);const h=e.TEXTJOIN(s,a,d);return h instanceof Error?r(h):h},UPPER:x(e.UPPER),YEAR:x(e.YEAR),MONTH:x(e.MONTH),DAY:x(e.DAY),WEEKDAY:(c,i)=>{const u=O(c),s=O(i),a=B([u]);a&&r(a);const d=e.WEEKDAY(u,s);return d instanceof Error?r(d):d},CONCATENATE:(...c)=>{const i=c.flatMap(ae),u=B(i);u&&r(u);const s=e.CONCATENATE(...i.map(_));return s instanceof Error?r(s):s},CONCAT:(...c)=>{const i=c.flatMap(ae),u=B(i);u&&r(u);const s=e.CONCAT(...i.map(_));return s instanceof Error?r(s):s},LEN:x(e.LEN,{toText:!0}),TRIM:x(e.TRIM,{toText:!0}),LOWER:x(e.LOWER,{toText:!0}),LEFT:(c,i)=>{const u=O(c),s=ye(i),a=B([u]);a&&r(a);const d=e.LEFT(_(u),s);return d instanceof Error?r(d):d},RIGHT:(c,i)=>{const u=O(c),s=ye(i),a=B([u]);a&&r(a);const d=e.RIGHT(_(u),s);return d instanceof Error?r(d):d},MID:(c,i,u)=>{const s=O(c),a=O(i),d=O(u),m=B([s,a,d]);m&&r(m);const h=e.MID(_(s),a,d);return h instanceof Error?r(h):h},FIND:(c,i,u)=>{const s=O(c),a=O(i),d=ye(u),m=B([s,a]);m&&r(m);const h=e.FIND(_(s),_(a),d);return h instanceof Error?r(h):h},SEARCH:(c,i,u)=>{const s=O(c),a=O(i),d=ye(u),m=B([s,a]);m&&r(m);const h=e.SEARCH(_(s),_(a),d);return h instanceof Error?r(h):h}}}const sr={"#REF!":"REF","#VALUE!":"VALUE","#DIV/0!":"DIV0","#NAME?":"NAME","#N/A":"NA","#NUM!":"NUM","#NULL!":"NULL"};function Fe(e){return sr[e.error]??"ERROR"}function Oe(e,n){if(e instanceof V)return e;if(e instanceof n){const r=e.details;return r instanceof V?r:r instanceof n?new V(Fe(r),r.message):new V(Fe(e),e.message)}return new V("ERROR",e instanceof Error?e.message:void 0)}function lr(e){return Math.max(0,...e.map(n=>(n==null?void 0:n.length)??0))}function ir(e){return n=>{const r=e[n.row-1];if(n.row<1||n.col<1||r==null||n.col-1>=r.length)throw new V("REF");const l=r[n.col-1];return l==null||l===""?null:l}}function cr(e){return n=>{const r=Math.min(n.from.row,n.to.row),l=Math.min(n.from.col,n.to.col),x=Math.max(n.from.row,n.to.row),c=Math.max(n.from.col,n.to.col),i=lr(e);if(r>e.length||l>i)throw new V("REF");const u=Math.min(x,e.length),s=[];for(let a=r;a<=u;a++){const d=e[a-1],m=[];if(d!=null){const h=Math.min(c,d.length);for(let p=l;p<=h;p++){const g=d[p-1];m.push(g==null||g===""?null:g)}}s.push(m)}return s}}function ar(e){if(e==null||e==="")return null;if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date)return e;throw new V("VALUE")}async function ut(e,n){if(typeof e!="string")throw new V("ERROR");const r=e.trim();if(r==="")throw new V("ERROR");const l=r.startsWith("=")?r.slice(1):r;tr(l);const[x,c]=await Promise.all([import("fast-formula-parser"),import("@formulajs/formulajs")]),i=x.default??x,u=i.FormulaError,s=new i({...n,functions:or(c,u)});let a;try{a=s.parse(l,{row:1,col:1,sheet:"Sheet1"})}catch(d){throw Oe(d,u)}if(a instanceof u)throw Oe(a,u);return ar(a)}async function ur(e,n){return ut(n,{onCell:ir(e),onRange:cr(e)})}const Ie=-1;async function dr(e,n){const r=Object.keys(e);return ut(n,{onVariable:l=>{const x=r.indexOf(l);return x===-1?null:{row:Ie,col:x+1}},onCell:l=>{if(l.row===Ie)return e[r[l.col-1]]??null;throw new V("REF")},onRange:()=>{throw new V("REF")}})}const dt={REF:"#REF!",VALUE:"#VALUE!",DIV0:"#DIV/0!",NAME:"#NAME?",ERROR:"#ERROR!",NA:"#N/A",NUM:"#NUM!",NULL:"#NULL!"};function ft(e){const n=e instanceof V?e.code:"ERROR";return dt[n]}async function fr(e,n){return e.length===0?n.map(r=>({id:typeof(r==null?void 0:r.id)=="string"?r.id:"(unknown)",label:(r==null?void 0:r.label)??"(unknown)",value:null,error:dt.ERROR})):Promise.all(n.map(async r=>{try{if(!r||typeof r.label!="string"||typeof r.expression!="string"||typeof r.id!="string")throw new V("ERROR");return{id:r.id,label:r.label,value:await ur(e,r.expression)}}catch(l){return{id:typeof(r==null?void 0:r.id)=="string"?r.id:"(unknown)",label:(r==null?void 0:r.label)??"(unknown)",value:null,error:ft(l)}}}))}function xr(e,n={}){if(n.columnHeader&&n.rowHeader)throw new Error("x-spreadsheet: columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape.");return n.columnHeader?hr(e):n.rowHeader?pr(e):e}function xt(e){return e==null||e===""?null:e instanceof Date?e.toISOString():String(e)}function ht(e,n){const r=new Set;for(const l of e)if(l!=null){if(r.has(l))throw new Error(`x-spreadsheet: duplicate ${n} value "${l}" — every ${n==="columnHeader"?"column header":"column-A value"} must be unique to shape as records.`);r.add(l)}}function hr(e){const[n,...r]=e;if(!n)return[];const l=n.map(xt);return ht(l,"columnHeader"),r.map(x=>{const c=Object.create(null);return l.forEach((i,u)=>{i!=null&&(c[i]=x[u]??null)}),c})}function pr(e){const n=e.map(x=>xt(x[0]));ht(n,"rowHeader");const r=Math.max(0,...e.map(x=>x.length)),l=Math.max(0,r-1);return Array.from({length:l},(x,c)=>{const i=c+1,u=Object.create(null);return n.forEach((s,a)=>{s!=null&&(u[s]=e[a][i]??null)}),u})}function Ne(e){return!Array.isArray(e[0])}async function mr(e,n,r={}){const l=await fr(e,n),x=Object.create(null);for(const{id:c,label:i,value:u,error:s}of l)x[c]=s===void 0?{label:i,value:u}:{label:i,value:u,error:s};return r.persistSheet===!1?{derivations:x}:{sheet:xr(e,r),derivations:x}}const gr=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv",Tr=10*1024*1024,fe=200,ke=50,yr=[];function me(e){return e==null||e===""?"":e instanceof Date?e.toLocaleDateString():String(e)}const br=({data:e,handleChange:n,path:r,label:l,required:x,schema:c,enabled:i,readonly:u,errors:s,visible:a=!0})=>{se(a,r,n,null);const d=!s||s.length===0,m=Vt(i,u),h=(c==null?void 0:c["x-spreadsheet"])??{},p=(c==null?void 0:c["x-evaluate"])??yr,g=h.accept??gr,S=h.maxSize??Tr,R=h.persistSheet!==!1,v=h.columnHeader===!0,A=h.rowHeader===!0,N=h.showSheet!==!1,L=h.sheetName,w=e??null,[z,P]=b.useState(()=>w!=null&&w.sheet||Object.keys((w==null?void 0:w.derivations)??{}).length>0?"ready":"empty"),[F,E]=b.useState(null),[M,W]=b.useState(!1),[re,Y]=b.useState(null),ne=b.useRef(null),J=(w==null?void 0:w.sheet)??null,X=re??(J&&!Ne(J)?J:null),Z=re==null&&J&&Ne(J)?J:null,ce=(w==null?void 0:w.derivations)??{},te=X!=null||w!=null,ie=b.useCallback(async f=>{if(E(null),f.size>S){E(`File exceeds the ${ue(S)} limit.`);return}if(!g.split(",").map(k=>k.trim()).some(k=>k==="*"||k==="*/*"?!0:k.endsWith("/*")?f.type.startsWith(k.slice(0,-1)):k.startsWith(".")?f.name.toLowerCase().endsWith(k.toLowerCase()):f.type===k)){E(`Invalid type. Accepted: ${de(g)}`);return}P("parsing");let Q;try{const k=await f.arrayBuffer();Q=Jt(k,L).matrix}catch(k){P("error"),E(k instanceof we?k.message:"This doesn't look like a valid spreadsheet. Please check the file and try again.");return}Y(Q);let oe;try{oe=await mr(Q,p,{persistSheet:R,columnHeader:v,rowHeader:A})}catch(k){P("error"),E(k instanceof Error?k.message:"Failed to process the uploaded spreadsheet.");return}n(r,oe),P("ready")},[g,S,R,v,A,L,p,r,n]);if(a===!1)return null;if(v&&A)return t.jsxs(o.Box,{mb:"4",children:[t.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:l}),t.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&&!te)return null;const T=f=>{f.preventDefault(),f.stopPropagation(),m&&W(f.type==="dragenter"||f.type==="dragover")},I=f=>{var j;f.preventDefault(),f.stopPropagation(),W(!1),m&&(j=f.dataTransfer.files)!=null&&j[0]&&ie(f.dataTransfer.files[0])},D=f=>{var j;(j=f.target.files)!=null&&j[0]&&(ie(f.target.files[0]),f.target.value="")},C=()=>{m&&(Y(null),E(null),P("empty"),n(r,null))},U=v?1:0,K=A?1:0,q=X?X.slice(U):[],$=q.slice(0,fe),xe=Math.min(ke,Math.max(0,...$.map(f=>Math.max(0,f.length-K)))),he=Array.from({length:xe},(f,j)=>j+K),be=N&&X==null&&Z==null&&w!=null,ge="",ve=A&&!v,Te=Z?Z.slice(0,fe):[],pe=Array.from(new Set(Te.flatMap(f=>Object.keys(f)))).slice(0,ke);return t.jsxs(o.Box,{mb:"4",children:[t.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[t.jsxs(o.Flex,{align:"center",gap:"1",children:[t.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[l,x&&t.jsx(o.Text,{color:"red",children:" *"})]}),te&&m&&t.jsxs(t.Fragment,{children:[t.jsx(o.Tooltip,{content:"Replace spreadsheet",children:t.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var f;return(f=ne.current)==null?void 0:f.click()},"aria-label":"Replace spreadsheet",children:t.jsx(ee.UploadIcon,{})})}),t.jsx(o.Tooltip,{content:"Remove spreadsheet",children:t.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:C,"aria-label":"Remove spreadsheet",children:t.jsx(ee.Cross2Icon,{})})})]})]}),t.jsxs(o.Text,{size:"1",color:"gray",children:[ue(S)," max · ",de(g)]})]}),te&&F&&t.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:F}),t.jsx("input",{ref:ne,type:"file",style:{display:"none"},accept:g,onChange:D}),m&&!te&&t.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var f;return(f=ne.current)==null?void 0:f.click()},onKeyDown:f=>{var j;(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),(j=ne.current)==null||j.click())},onDragEnter:T,onDragLeave:T,onDragOver:T,onDrop:I,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",M?"border-blue-500 bg-blue-50":F?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:t.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:z==="parsing"?t.jsxs(t.Fragment,{children:[t.jsx(o.Spinner,{size:"3"}),t.jsx(o.Text,{size:"2",color:"gray",children:"Parsing spreadsheet…"})]}):F?t.jsxs(t.Fragment,{children:[t.jsx(ee.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),t.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:F}),t.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):t.jsxs(t.Fragment,{children:[t.jsx(ee.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),t.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),t.jsxs(o.Text,{size:"1",color:"gray",children:[ue(S)," max · ",de(g)]})]})})}),X&&N&&t.jsxs(o.Box,{mt:"3",children:[t.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:t.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[!ve&&t.jsx(o.Table.Header,{children:t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.ColumnHeaderCell,{children:ge}),he.map(f=>{var j;return t.jsx(o.Table.ColumnHeaderCell,{children:v?me((j=X[0])==null?void 0:j[f]):Kt(f)},f)})]})}),t.jsx(o.Table.Body,{children:$.map((f,j)=>{var Q;const G=U+j;return t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.RowHeaderCell,{style:A?{fontWeight:700,background:"var(--gray-a3)"}:void 0,children:A?me((Q=X[G])==null?void 0:Q[0]):v?"":G+1}),he.map(oe=>t.jsx(o.Table.Cell,{children:me(f[oe])},oe))]},j)})})]})}),q.length>fe&&t.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",fe," of ",q.length," rows"]})]}),Z&&N&&t.jsxs(o.Box,{mt:"3",children:[t.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:t.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[t.jsx(o.Table.Header,{children:t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.ColumnHeaderCell,{}),pe.map(f=>t.jsx(o.Table.ColumnHeaderCell,{children:f},f))]})}),t.jsx(o.Table.Body,{children:Te.map((f,j)=>t.jsxs(o.Table.Row,{children:[t.jsx(o.Table.RowHeaderCell,{children:j+1}),pe.map(G=>t.jsx(o.Table.Cell,{children:me(f[G])},G))]},j))})]})}),Z.length>fe&&t.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",fe," of ",Z.length," rows"]})]}),be&&t.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(ce).length>0&&t.jsxs(o.Box,{mt:"3",children:[t.jsx(o.Text,{size:"2",weight:"bold",as:"div",mb:"1",children:"Computed values"}),t.jsx(o.Flex,{direction:"column",gap:"1",children:Object.entries(ce).map(([f,j])=>t.jsxs(o.Flex,{justify:"between",children:[t.jsx(o.Text,{size:"2",children:j.label}),j.error?t.jsx(o.Text,{size:"2",color:"red",children:j.error}):t.jsx(o.Text,{size:"2",children:me(j.value)})]},f))})]}),!d&&t.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(s,l)})]})},pt=H.withJsonFormsControlProps(br),mt=y.rankWith(10,y.schemaMatches(e=>e.type==="object"&&typeof e["x-spreadsheet"]=="object"));function vr(e,n,r){const l={};for(const[x,c]of Object.entries(r)){const{path:i,default:u}=typeof c=="string"?{path:c,default:void 0}:c,s=n?`${n}.${i}`:i,a=y.Resolve.data(e,s);if(a==null){if(u===void 0)return;l[x]=u}else l[x]=a}return l}async function jr(e,n){try{return{status:"ok",value:await dr(e,n)}}catch(r){return{status:"error",error:ft(r)}}}function wr(e,n){return e==null?"":typeof e=="number"?e.toFixed(Cr(n)):e instanceof Date?e.toLocaleDateString():String(e)}function Cr(e){return Number.isFinite(e)?Math.min(100,Math.max(0,Math.trunc(e))):0}const Le="{value}",Rr=2,Er={},Sr=({data:e,handleChange:n,path:r,label:l,schema:x,visible:c=!0})=>{var z;se(c,r,n,null);const i=x==null?void 0:x["x-computed"],u=(i==null?void 0:i.inputs)??Er,s=(i==null?void 0:i.formula)??"",a=(i==null?void 0:i.format)??Le,d=(i==null?void 0:i.decimals)??Rr,m=H.useJsonForms(),h=r.split(".").slice(0,-1).join("."),p=vr((z=m.core)==null?void 0:z.data,h,u),g=p?JSON.stringify(p):null,S=m.readonly===!0,[R,v]=b.useState(()=>typeof e=="number"?"ok":"unavailable"),[A,N]=b.useState(()=>typeof e=="number"?e:null),[L,w]=b.useState(null);return b.useEffect(()=>{if(!c)return;let P=!1;const F=E=>{S||E!==(e??null)&&n(r,E)};if(p===void 0){v("unavailable"),w(null),N(null),F(null);return}return v(E=>E==="ok"?E:"loading"),jr(p,s).then(E=>{if(P)return;const M=E.status==="ok"&&typeof E.value=="number"&&Number.isFinite(E.value)?E.value:null;if(M===null){v("error"),w(E.status==="error"?E.error??"Unable to compute value.":"Computed value must be a number."),N(null),F(null);return}v("ok"),w(null),N(M),F(M)}),()=>{P=!0}},[g,s,c,S]),c===!1?null:t.jsx(o.Box,{mb:"4",children:t.jsxs(o.Flex,{direction:"column",gap:"1",children:[t.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:l}),R==="unavailable"?t.jsx(o.Text,{size:"2",color:"gray",children:"Not yet available."}):R==="loading"?t.jsxs(o.Flex,{align:"center",gap:"2",children:[t.jsx(o.Spinner,{size:"1"}),t.jsx(o.Text,{size:"2",color:"gray",children:"Computing…"})]}):R==="error"?t.jsx(o.Text,{size:"2",color:"red",children:L}):t.jsx(o.Text,{size:"2",children:a.split(Le).join(wr(A,d))}),x.description&&t.jsx(o.Text,{size:"1",color:"gray",children:x.description})]})})},gt=H.withJsonFormsControlProps(Sr),Tt=y.rankWith(5,y.schemaMatches(e=>{const n=e["x-computed"];return e.type==="number"&&typeof n=="object"&&n!==null})),Ar=({data:e,path:n,schema:r,uischema:l,enabled:x,visible:c,addItem:i,removeItems:u,rootSchema:s,arraySchema:a})=>{const d=a?r:r.items,m=a||r;if(c===!1||!d||typeof d!="object"||Array.isArray(d))return null;const h=d,p=Array.isArray(e)?e:[],g=m.title||"Array Items",S=l.options??{},R=x&&S.addable!==!1,v=x&&S.removable!==!1,A=()=>{const L=y.createDefaultValue(h,s);i&&i(n,L)()},N=L=>{if(u){const w=u(n,[L]);w&&w()}};return t.jsx(o.Box,{mb:"6",children:t.jsxs(o.Flex,{direction:"column",gap:"4",children:[t.jsx(o.Text,{as:"div",size:"4",weight:"bold",children:g}),p.length===0&&t.jsx(o.Box,{py:"4",px:"4",style:{backgroundColor:"var(--gray-3)",borderRadius:"var(--radius-3)"},children:t.jsx(o.Text,{size:"2",color:"gray",children:"No items have been added yet."})}),p.map((L,w)=>{var P;const z=`${n}.${w}`;return t.jsx(o.Card,{size:"3",variant:"surface",children:t.jsxs(o.Flex,{direction:"column",gap:"4",children:[t.jsxs(o.Flex,{justify:"between",align:"center",children:[t.jsxs(o.Text,{size:"3",weight:"bold",children:["Item ",w+1]}),v&&t.jsxs(o.Button,{type:"button",color:"red",variant:"soft",onClick:()=>N(w),title:"Remove item",children:[t.jsx(ee.TrashIcon,{}),"Remove"]})]}),t.jsx(o.Box,{children:t.jsx(H.JsonFormsDispatch,{schema:h,uischema:((P=l.options)==null?void 0:P.detail)||(h.type==="object"||h.properties?{type:"VerticalLayout",elements:Object.keys(h.properties||{}).map(F=>({type:"Control",scope:`#/properties/${F}`}))}:{type:"Control",scope:"#"}),path:z,enabled:x,renderers:void 0,cells:void 0})})]})},z)}),R&&t.jsx(o.Box,{mt:"2",children:t.jsxs(o.Button,{type:"button",variant:"surface",onClick:A,children:[t.jsx(ee.PlusIcon,{}),"Add Item"]})})]})})},Ce=H.withJsonFormsArrayControlProps(Ar),yt=y.rankWith(3,y.isObjectArrayControl),bt=({uischema:e,visible:n})=>{const r=e;return n===!1?null:t.jsx(o.Box,{mb:"4",children:t.jsx(o.Heading,{size:"4",children:r.text})})},vt=y.rankWith(1,y.uiTypeIs("Label")),Fr=y.rankWith(3,y.isPrimitiveArrayControl),Or=[{tester:Pe,renderer:kt},{tester:We,renderer:Lt},{tester:_e,renderer:Mt},{tester:Je,renderer:zt},{tester:qe,renderer:Xe},{tester:Ge,renderer:Dt},{tester:Ze,renderer:Wt},{tester:et,renderer:Qe},{tester:rt,renderer:tt},{tester:ot,renderer:nt},{tester:lt,renderer:st},{tester:ct,renderer:it},{tester:mt,renderer:pt},{tester:Tt,renderer:gt},{tester:yt,renderer:Ce},{tester:Fr,renderer:Ce},{tester:vt,renderer:bt}];exports.ArrayControl=Ce;exports.ArrayControlTester=yt;exports.BooleanControl=$e;exports.BooleanControlTester=_e;exports.CategorizationLayoutRenderer=st;exports.CategorizationLayoutTester=lt;exports.ComputedControl=gt;exports.ComputedControlTester=Tt;exports.DateControl=Ye;exports.DateControlTester=Ze;exports.FileControl=it;exports.FileControlTester=ct;exports.GroupLayoutRenderer=nt;exports.GroupLayoutTester=ot;exports.HorizontalLayoutRenderer=tt;exports.HorizontalLayoutTester=rt;exports.LabelRenderer=bt;exports.LabelTester=vt;exports.NumberControl=He;exports.NumberControlTester=We;exports.RadioControl=Ve;exports.RadioControlTester=Je;exports.SearchSelectControl=Xe;exports.SearchSelectControlTester=qe;exports.SearchServiceProvider=Nt;exports.SelectControl=Ke;exports.SelectControlTester=Ge;exports.SpreadsheetControl=pt;exports.SpreadsheetControlTester=mt;exports.TextControl=Be;exports.TextControlTester=Pe;exports.UploadProvider=It;exports.VerticalLayoutRenderer=Qe;exports.VerticalLayoutTester=et;exports.radixRenderers=Or;exports.useSearchService=Ue;exports.useUpload=ze;