@object-ui/plugin-grid 3.1.3 → 3.1.5

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,15 +1,15 @@
1
- (function(L,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/fields"),require("@object-ui/components"),require("lucide-react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","@object-ui/core","@object-ui/react","@object-ui/fields","@object-ui/components","lucide-react","react-dom"],u):(L=typeof globalThis<"u"?globalThis:L||self,u(L.ObjectUIPluginGrid={},L.React,L.core,L.react,L.fields,L.components,L.lucideReact,L.ReactDOM))})(this,(function(L,u,_e,pe,Z,v,I,_t){"use strict";function Tt(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,s.get?s:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const Fe=Tt(u);var ze={exports:{}},Te={};var Ye;function At(){if(Ye)return Te;Ye=1;var e=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function t(s,n,i){var a=null;if(i!==void 0&&(a=""+i),n.key!==void 0&&(a=""+n.key),"key"in n){i={};for(var l in n)l!=="key"&&(i[l]=n[l])}else i=n;return n=i.ref,{$$typeof:e,type:s,key:a,ref:n!==void 0?n:null,props:i}}return Te.Fragment=o,Te.jsx=t,Te.jsxs=t,Te}var Ae={};var Je;function Mt(){return Je||(Je=1,process.env.NODE_ENV!=="production"&&(function(){function e(d){if(d==null)return null;if(typeof d=="function")return d.$$typeof===de?null:d.displayName||d.name||null;if(typeof d=="string")return d;switch(d){case T:return"Fragment";case z:return"Profiler";case D:return"StrictMode";case J:return"Suspense";case oe:return"SuspenseList";case Ee:return"Activity"}if(typeof d=="object")switch(typeof d.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),d.$$typeof){case C:return"Portal";case Y:return d.displayName||"Context";case P:return(d._context.displayName||"Context")+".Consumer";case q:var A=d.render;return d=d.displayName,d||(d=A.displayName||A.name||"",d=d!==""?"ForwardRef("+d+")":"ForwardRef"),d;case Me:return A=d.displayName||null,A!==null?A:e(d.type)||"Memo";case ve:A=d._payload,d=d._init;try{return e(d(A))}catch{}}return null}function o(d){return""+d}function t(d){try{o(d);var A=!1}catch{A=!0}if(A){A=console;var K=A.error,H=typeof Symbol=="function"&&Symbol.toStringTag&&d[Symbol.toStringTag]||d.constructor.name||"Object";return K.call(A,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",H),o(d)}}function s(d){if(d===T)return"<>";if(typeof d=="object"&&d!==null&&d.$$typeof===ve)return"<...>";try{var A=e(d);return A?"<"+A+">":"<...>"}catch{return"<...>"}}function n(){var d=ge.A;return d===null?null:d.getOwner()}function i(){return Error("react-stack-top-frame")}function a(d){if(V.call(d,"key")){var A=Object.getOwnPropertyDescriptor(d,"key").get;if(A&&A.isReactWarning)return!1}return d.key!==void 0}function l(d,A){function K(){ae||(ae=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",A))}K.isReactWarning=!0,Object.defineProperty(d,"key",{get:K,configurable:!0})}function m(){var d=e(this.type);return je[d]||(je[d]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),d=this.props.ref,d!==void 0?d:null}function p(d,A,K,H,we,ee){var R=K.ref;return d={$$typeof:w,type:d,key:A,props:K,_owner:H},(R!==void 0?R:null)!==null?Object.defineProperty(d,"ref",{enumerable:!1,get:m}):Object.defineProperty(d,"ref",{enumerable:!1,value:null}),d._store={},Object.defineProperty(d._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(d,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(d,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:we}),Object.defineProperty(d,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ee}),Object.freeze&&(Object.freeze(d.props),Object.freeze(d)),d}function f(d,A,K,H,we,ee){var R=A.children;if(R!==void 0)if(H)if(Q(R)){for(H=0;H<R.length;H++)h(R[H]);Object.freeze&&Object.freeze(R)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else h(R);if(V.call(A,"key")){R=e(d);var X=Object.keys(A).filter(function(me){return me!=="key"});H=0<X.length?"{key: someKey, "+X.join(": ..., ")+": ...}":"{key: someKey}",xe[R+H]||(X=0<X.length?"{"+X.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@object-ui/core`),require(`@object-ui/react`),require(`@object-ui/fields`),require(`@object-ui/components`),require(`lucide-react`),require(`react-dom`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`lucide-react`,`react-dom`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginGrid={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e.lucide_react,e.ReactDOM))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:c(f(e)),h(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(t);function g(e){let{onRefresh:n,threshold:r=80,enabled:i=!0}=e,a=(0,t.useRef)(null),[o,s]=(0,t.useState)(!1),[c,l]=(0,t.useState)(0),u=(0,t.useRef)(0),d=(0,t.useCallback)(e=>{if(!i||o)return;let t=a.current;t&&t.scrollTop===0&&(u.current=e.touches[0].clientY)},[i,o]),f=(0,t.useCallback)(e=>{if(!i||o||!u.current)return;let t=e.touches[0].clientY-u.current;t>0&&l(Math.min(t,r*1.5))},[i,o,r]),p=(0,t.useCallback)(async()=>{if(!i||o)return;let e=c;if(l(0),u.current=0,e>=r){s(!0);try{await n()}finally{s(!1)}}},[i,o,c,r,n]);return(0,t.useEffect)(()=>{let e=a.current;if(!(!e||!i))return e.addEventListener(`touchstart`,d,{passive:!0}),e.addEventListener(`touchmove`,f,{passive:!0}),e.addEventListener(`touchend`,p,{passive:!0}),()=>{e.removeEventListener(`touchstart`,d),e.removeEventListener(`touchmove`,f),e.removeEventListener(`touchend`,p)}},[d,f,p,i]),{ref:a,isRefreshing:o,pullDistance:c}}var _=m((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),v=m((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ee?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=O.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(k.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){M||(M=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return N[e]||(N[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(A(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(k.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,I[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,H,R,X,R),xe[R+H]=!0)}if(R=null,K!==void 0&&(t(K),R=""+K),a(A)&&(t(A.key),R=""+A.key),"key"in A){K={};for(var ue in A)ue!=="key"&&(K[ue]=A[ue])}else K=A;return R&&l(K,typeof d=="function"?d.displayName||d.name||"Unknown":d),p(d,R,K,n(),we,ee)}function h(d){g(d)?d._store&&(d._store.validated=1):typeof d=="object"&&d!==null&&d.$$typeof===ve&&(d._payload.status==="fulfilled"?g(d._payload.value)&&d._payload.value._store&&(d._payload.value._store.validated=1):d._store&&(d._store.validated=1))}function g(d){return typeof d=="object"&&d!==null&&d.$$typeof===w}var b=u,w=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),T=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),z=Symbol.for("react.profiler"),P=Symbol.for("react.consumer"),Y=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),J=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),Me=Symbol.for("react.memo"),ve=Symbol.for("react.lazy"),Ee=Symbol.for("react.activity"),de=Symbol.for("react.client.reference"),ge=b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,V=Object.prototype.hasOwnProperty,Q=Array.isArray,he=console.createTask?console.createTask:function(){return null};b={react_stack_bottom_frame:function(d){return d()}};var ae,je={},re=b.react_stack_bottom_frame.bind(b,i)(),be=he(s(i)),xe={};Ae.Fragment=T,Ae.jsx=function(d,A,K){var H=1e4>ge.recentlyCreatedOwnerStacks++;return f(d,A,K,!1,H?Error("react-stack-top-frame"):re,H?he(s(d)):be)},Ae.jsxs=function(d,A,K){var H=1e4>ge.recentlyCreatedOwnerStacks++;return f(d,A,K,!0,H?Error("react-stack-top-frame"):re,H?he(s(d)):be)}})()),Ae}var Xe;function Dt(){return Xe||(Xe=1,process.env.NODE_ENV==="production"?ze.exports=At():ze.exports=Mt()),ze.exports}var r=Dt();function It(e){const{onRefresh:o,threshold:t=80,enabled:s=!0}=e,n=u.useRef(null),[i,a]=u.useState(!1),[l,m]=u.useState(0),p=u.useRef(0),f=u.useCallback(b=>{if(!s||i)return;const w=n.current;w&&w.scrollTop===0&&(p.current=b.touches[0].clientY)},[s,i]),h=u.useCallback(b=>{if(!s||i||!p.current)return;const C=b.touches[0].clientY-p.current;C>0&&m(Math.min(C,t*1.5))},[s,i,t]),g=u.useCallback(async()=>{if(!s||i)return;const b=l;if(m(0),p.current=0,b>=t){a(!0);try{await o()}finally{a(!1)}}},[s,i,l,t,o]);return u.useEffect(()=>{const b=n.current;if(!(!b||!s))return b.addEventListener("touchstart",f,{passive:!0}),b.addEventListener("touchmove",h,{passive:!0}),b.addEventListener("touchend",g,{passive:!0}),()=>{b.removeEventListener("touchstart",f),b.removeEventListener("touchmove",h),b.removeEventListener("touchend",g)}},[f,h,g,s]),{ref:n,isRefreshing:i,pullDistance:l}}const Ft=u.createContext(null);Ft.displayName="MobileContext";const zt={red:"bg-red-100",green:"bg-green-100",blue:"bg-blue-100",yellow:"bg-yellow-100",orange:"bg-orange-100",purple:"bg-purple-100",pink:"bg-pink-100",gray:"bg-gray-100",grey:"bg-gray-100",indigo:"bg-indigo-100",teal:"bg-teal-100",cyan:"bg-cyan-100",amber:"bg-amber-100",lime:"bg-lime-100",emerald:"bg-emerald-100",rose:"bg-rose-100",sky:"bg-sky-100",violet:"bg-violet-100",fuchsia:"bg-fuchsia-100",slate:"bg-slate-100",zinc:"bg-zinc-100",stone:"bg-stone-100",neutral:"bg-neutral-100"};function Lt(e){if(e.startsWith("bg-"))return e;const o=e.toLowerCase().trim();return zt[o]}function Qe(e){return u.useCallback(o=>{if(!e?.field||!e.colors)return;const t=String(o[e.field]??""),s=e.colors[t];if(s)return Lt(s)},[e?.field,e?.colors])}function Pt(e,o){return o.map(t=>String(e[t.field]??"")).join(" / ")}function Rt(e,o){return o.map(t=>{const s=e[t.field];return s!=null&&s!==""?String(s):"(empty)"}).join(" / ")}function $t(e,o){return o.map(({field:t,type:s})=>{const n=e.map(a=>Number(a[t])).filter(a=>Number.isFinite(a));let i;switch(s){case"count":i=n.length;break;case"sum":i=n.reduce((a,l)=>a+l,0);break;case"avg":i=n.length>0?n.reduce((a,l)=>a+l,0)/n.length:0;break;case"min":i=n.length>0?Math.min(...n):0;break;case"max":i=n.length>0?Math.max(...n):0;break;default:i=0}return{field:t,type:s,value:i}})}function Vt(e,o,t){const s=e.localeCompare(o,void 0,{numeric:!0,sensitivity:"base"});return t==="desc"?-s:s}function Ze(e,o,t){const s=e?.fields,n=!!(s&&s.length>0),[i,a]=u.useState({}),l=u.useMemo(()=>s?s.some(f=>f.collapsed):!1,[s]),m=u.useMemo(()=>{if(!n||!s)return[];const f=new Map,h=[];for(const b of o){const w=Pt(b,s);f.has(w)||(f.set(w,{label:Rt(b,s),rows:[]}),h.push(w)),f.get(w).rows.push(b)}const g=s[0]?.order??"asc";return h.sort((b,w)=>Vt(b,w,g)),h.map(b=>{const w=f.get(b),C=b in i?i[b]:l,T=t&&t.length>0?$t(w.rows,t):[];return{key:b,label:w.label,rows:w.rows,collapsed:C,aggregations:T}})},[o,s,n,i,l,t]),p=u.useCallback(f=>{a(h=>({...h,[f]:h[f]!==void 0?!h[f]:!l}))},[l]);return{groups:m,isGrouped:n,toggleGroup:p}}const et=({groupKey:e,label:o,count:t,collapsed:s,aggregations:n,onToggle:i,children:a})=>r.jsxs("div",{className:"border rounded-md","data-testid":`group-row-${e}`,children:[r.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors",onClick:()=>i(e),"aria-expanded":!s,children:[s?r.jsx(I.ChevronRight,{className:"h-4 w-4 shrink-0"}):r.jsx(I.ChevronDown,{className:"h-4 w-4 shrink-0"}),r.jsx("span",{className:"group-label",children:o}),n&&n.length>0&&r.jsx("span",{className:"ml-2 text-xs text-muted-foreground group-aggregations",children:n.map(l=>r.jsxs("span",{className:"mr-2",children:[l.type,": ",Number.isInteger(l.value)?l.value:l.value.toFixed(2)]},`${l.field}-${l.type}`))}),r.jsxs("span",{className:"ml-auto text-xs text-muted-foreground group-count",children:["(",t,")"]})]}),!s&&a]});function Kt(e){return typeof e=="string"?{type:e}:e}function Bt(e,o){if(o.length===0)return null;switch(e){case"count":return o.length;case"sum":return o.reduce((t,s)=>t+s,0);case"avg":return o.reduce((t,s)=>t+s,0)/o.length;case"min":return Math.min(...o);case"max":return Math.max(...o);default:return null}}function Wt(e,o){if(o===null)return"";const s={count:"Count",sum:"Sum",avg:"Avg",min:"Min",max:"Max"}[e]||e,n=e==="avg"?o.toLocaleString(void 0,{maximumFractionDigits:2}):o.toLocaleString();return`${s}: ${n}`}function tt(e,o){return u.useMemo(()=>{const t=new Map;if(!e||e.length===0||o.length===0)return{summaries:t,hasSummary:!1};for(const s of e){if(!s.summary)continue;const n=Kt(s.summary),i=n.field||s.field,a=[];for(const m of o){const p=m[i];if(p!=null&&typeof p=="number"&&!isNaN(p))a.push(p);else if(p!=null&&typeof p=="string"){const f=parseFloat(p);isNaN(f)||a.push(f)}}let l;if(n.type==="count"){const m=o.filter(p=>p[i]!=null&&p[i]!=="").length;l=m>0?m:null}else l=Bt(n.type,a);t.set(s.field,{field:s.field,value:l,label:Wt(n.type,l)})}return{summaries:t,hasSummary:t.size>0}},[e,o])}function Le(e){return e.replace(/_/g," ").replace(/\b\w/g,o=>o.toUpperCase())}const st=({row:e,rowActions:o,canEdit:t,canDelete:s,onEdit:n,onDelete:i,onAction:a})=>r.jsxs(v.DropdownMenu,{children:[r.jsx(v.DropdownMenuTrigger,{asChild:!0,children:r.jsxs(v.Button,{variant:"ghost",size:"icon",className:"h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0","data-testid":"row-action-trigger",children:[r.jsx(I.MoreVertical,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"Open menu"})]})}),r.jsxs(v.DropdownMenuContent,{align:"end",children:[t&&n&&r.jsxs(v.DropdownMenuItem,{onClick:()=>n(e),children:[r.jsx(I.Edit,{className:"mr-2 h-4 w-4"}),"Edit"]}),s&&i&&r.jsxs(v.DropdownMenuItem,{onClick:()=>i(e),children:[r.jsx(I.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]}),o?.map(l=>r.jsx(v.DropdownMenuItem,{onClick:()=>a?.(l,e),"data-testid":`row-action-${l}`,children:Le(l)},l))]})]}),We=({selectedRows:e,actions:o,onAction:t,onClearSelection:s})=>!o||o.length===0||e.length===0?null:r.jsxs("div",{className:"border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0","data-testid":"bulk-actions-bar",children:[r.jsxs("span",{className:"text-muted-foreground font-medium",children:[e.length," selected"]}),r.jsx("div",{className:"flex items-center gap-1 ml-2",children:o.map(n=>r.jsx(v.Button,{variant:"outline",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>t?.(n,e),"data-testid":`bulk-action-${n}`,children:Le(n)},n))}),r.jsx(v.Button,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs ml-auto",onClick:s,children:"Clear"})]}),rt={"grid.actions":"Actions","grid.edit":"Edit","grid.delete":"Delete","grid.export":"Export","grid.exportAs":"Export as {{format}}","grid.loading":"Loading grid...","grid.errorLoading":"Error loading grid","grid.pullToRefresh":"Pull to refresh","grid.refreshing":"Refreshing…","grid.openRecord":"Open record"};function qt(){try{const e=pe.useObjectTranslation();return e.t("grid.actions")==="grid.actions"?{t:(t,s)=>{let n=rt[t]||t;if(s)for(const[i,a]of Object.entries(s))n=n.replace(`{{${i}}}`,String(a));return n}}:{t:e.t}}catch{return{t:(e,o)=>{let t=rt[e]||e;if(o)for(const[s,n]of Object.entries(o))t=t.replace(`{{${s}}}`,String(n));return t}}}}function Gt(e){if(e!=null)return typeof e=="string"?e:e.defaultValue||e.key}function Ht(e){return e.data?Array.isArray(e.data)?{provider:"value",items:e.data}:e.data:e.staticData?{provider:"value",items:e.staticData}:e.objectName?{provider:"object",object:e.objectName}:null}function qe(e){if(!(!e||e.length===0))return typeof e[0]=="object"&&e[0]!==null,e}const nt=({schema:e,dataSource:o,onEdit:t,onDelete:s,onRowSelect:n,onRowClick:i,onCellChange:a,onRowSave:l,onBatchSave:m,onAddRecord:p,...f})=>{const[h,g]=u.useState([]),[b,w]=u.useState(!0),[C,T]=u.useState(null),{t:D}=qt(),{fieldLabel:z}=pe.useSafeFieldLabel(),[P,Y]=u.useState(null),[q,J]=u.useState(!1),[oe,Me]=u.useState(0),[ve,Ee]=u.useState(!1),[de,ge]=u.useState(e.rowHeight??"compact"),[V,Q]=u.useState([]),he=u.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[ae,je]=u.useState(()=>{try{const c=localStorage.getItem(he);return c?JSON.parse(c):{}}catch{return{}}}),re=u.useCallback(c=>{je(c);try{localStorage.setItem(he,JSON.stringify(c))}catch(M){console.warn("Failed to persist column state:",M)}},[he]),be=u.useCallback(async()=>{Me(c=>c+1)},[]),{ref:xe,isRefreshing:d,pullDistance:A}=It({onRefresh:be,enabled:!!o&&!!e.objectName});u.useEffect(()=>{const c=()=>J(window.innerWidth<480);return c(),window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[]);const K=f.data,H=pe.useDataScope(e.bind),we=Ht(e),ee=u.useMemo(()=>K&&Array.isArray(K)?{provider:"value",items:K}:H&&Array.isArray(H)?{provider:"value",items:H}:we,[JSON.stringify(we),H,K]),R=ee?.provider==="value",X=ee?.provider==="object"&&ee&&"object"in ee?ee.object:e.objectName,ue=e.fields,me=e.columns,Pe=e.filter,ke=e.sort,pt=e.pagination,gt=e.pageSize;u.useEffect(()=>{R&&ee?.provider==="value"&&(g(c=>{const M=ee.items;return JSON.stringify(c)!==JSON.stringify(M)?M:c}),w(!1))},[R,ee]),u.useEffect(()=>{if(!R||!X||!o)return;let c=!1;return(async()=>{try{const k=await o.getObjectSchema(X);c||Y(k)}catch(k){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${X}):`,k)}})(),()=>{c=!0}},[R,X,o]),u.useEffect(()=>{if(R)return;let c=!1;return(async()=>{w(!0),T(null);try{let k=null;const U=qe(me)||ue;if(X&&o){const te=await o.getObjectSchema(X);if(c)return;k=te}else if(U&&X)k={name:X,fields:{}};else throw X?new Error("DataSource required"):new Error("Object name required for data fetching");if(c||Y(k),o&&X){const j={$select:(()=>{if(ue)return ue;if(me&&Array.isArray(me))return me.map(S=>typeof S=="string"?S:S.field)})(),$top:pt?.pageSize||gt||50};Pe&&Array.isArray(Pe)?j.$filter=Pe:e.defaultFilters&&(j.$filter=e.defaultFilters),ke?typeof ke=="string"?j.$orderby=ke:Array.isArray(ke)&&(j.$orderby=ke.map(S=>`${S.field} ${S.order}`).join(", ")):e.defaultSort&&(j.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);const x=_e.buildExpandFields(k?.fields,me??ue);x.length>0&&(j.$expand=x);const N=await o.find(X,j);if(c)return;g(N.data||[])}}catch(k){c||T(k)}finally{c||w(!1)}})(),()=>{c=!0}},[X,ue,me,Pe,ke,pt,gt,o,R,ee,oe]);const ne=pe.useNavigationOverlay({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:i}),{execute:De}=pe.useAction(),Ss=Qe(e.rowColor),Ns=u.useCallback(c=>{const M=e.conditionalFormatting;if(!(!M||M.length===0))for(const k of M){let U=!1;const te=("condition"in k?k.condition:void 0)||("expression"in k?k.expression:void 0)||void 0;if(te)U=_e.evaluatePlainCondition(te,c);else if("field"in k&&"operator"in k&&k.field&&k.operator){const j=k,x=c[j.field];switch(j.operator){case"equals":U=x===j.value;break;case"not_equals":U=x!==j.value;break;case"contains":U=typeof x=="string"&&typeof j.value=="string"&&x.includes(j.value);break;case"greater_than":U=typeof x=="number"&&typeof j.value=="number"&&x>j.value;break;case"less_than":U=typeof x=="number"&&typeof j.value=="number"&&x<j.value;break;case"in":U=Array.isArray(j.value)&&j.value.includes(x);break}}if(U){const j={};return"style"in k&&k.style&&Object.assign(j,k.style),"backgroundColor"in k&&k.backgroundColor&&(j.backgroundColor=k.backgroundColor),"textColor"in k&&k.textColor&&(j.color=k.textColor),"borderColor"in k&&k.borderColor&&(j.borderColor=k.borderColor),j}}},[e.conditionalFormatting]),{groups:Es,isGrouped:xt,toggleGroup:ks}=Ze(e.grouping,h),Os=u.useMemo(()=>{const c=qe(e.columns);if(c&&c.length>0&&typeof c[0]=="object")return c},[e.columns]),{summaries:bt,hasSummary:_s}=tt(Os,h),Re=u.useCallback(()=>{const c=j=>j?{text:r.jsx(I.Type,{className:"h-3.5 w-3.5"}),number:r.jsx(I.Hash,{className:"h-3.5 w-3.5"}),currency:r.jsx(I.Hash,{className:"h-3.5 w-3.5"}),percent:r.jsx(I.Hash,{className:"h-3.5 w-3.5"}),date:r.jsx(I.Calendar,{className:"h-3.5 w-3.5"}),datetime:r.jsx(I.Clock,{className:"h-3.5 w-3.5"}),boolean:r.jsx(I.CheckSquare,{className:"h-3.5 w-3.5"}),user:r.jsx(I.User,{className:"h-3.5 w-3.5"}),select:r.jsx(I.Tag,{className:"h-3.5 w-3.5"})}[j]||r.jsx(I.Type,{className:"h-3.5 w-3.5"}):r.jsx(I.Type,{className:"h-3.5 w-3.5"}),M=j=>{if(j.type)return j.type;const x=j.field.toLowerCase();if(["completed","is_completed","done","active","enabled","archived"].some(O=>x===O||x===`is_${O}`))return"boolean";if(["created_time","modified_time","updated_time","created_at","updated_at","modified_at","last_login","logged_at"].some(O=>x===O||x.endsWith(`_${O}`)))return"datetime";if(["date","due","created","updated","deadline","start","end","expires"].some(O=>x.includes(O))){if(h.length>0){const O=h.find($=>$[j.field]!=null)?.[j.field];if(typeof O=="string"&&!isNaN(Date.parse(O)))return"date"}return"date"}if(["probability","percent","percentage","completion","progress","rate"].some(O=>x.includes(O))&&h.length>0&&typeof h.find($=>$[j.field]!=null)?.[j.field]=="number")return"percent";if(["status","priority","category","stage","type","severity","level"].some(O=>x.includes(O))&&h.length>0){const O=new Set(h.map($=>$[j.field]).filter(Boolean));if(O.size>0&&O.size<=10)return"select"}if(["assignee","owner","author","reporter","creator","user"].some(O=>x.includes(O)))return"user";if(["amount","price","total","revenue","cost","budget","salary"].some(O=>x.includes(O))&&h.length>0&&typeof h.find($=>$[j.field]!=null)?.[j.field]=="number")return"currency";if(h.length>0){const O=h.find($=>$[j.field]!=null)?.[j.field];if(typeof O=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(O))return"datetime"}return null},k=qe(me);if(k){if(k.length>0&&typeof k[0]=="object"&&k[0]!==null){const j=k[0];if("accessorKey"in j)return k.map(x=>{if(x.cell)return x;const N={field:x.accessorKey,label:x.header,type:x.type},S=M(N);if(!S)return x;const F=Z.getCellRenderer(S),E={name:x.accessorKey,type:S};if(S==="select"){const y=Array.from(new Set(h.map(_=>_[x.accessorKey]).filter(Boolean)));E.options=y.map(_=>({value:_,label:Z.humanizeLabel(String(_))}))}return{...x,headerIcon:c(S),cell:y=>r.jsx(F,{value:y,field:E})}});if("field"in j)return k.filter(x=>x?.field&&typeof x.field=="string"&&!x.hidden).map((x,N)=>{const S=Gt(x.label)||x.field.charAt(0).toUpperCase()+x.field.slice(1).replace(/_/g," "),F=e.objectName?z(e.objectName,x.field,S):S;let E;const y=P?.fields?.[x.field],_=x.type||y?.type||M({field:x.field})||null,B=_?Z.getCellRenderer(_):null,O={name:x.field,type:_||"text"};if(y&&(y.label&&(O.label=y.label),y.currency&&(O.currency=y.currency),y.precision!==void 0&&(O.precision=y.precision),y.format&&(O.format=y.format),y.options&&(O.options=y.options)),_==="select"&&!O.options){const G=Array.from(new Set(h.map(ce=>ce[x.field]).filter(Boolean)));O.options=G.map(ce=>({value:ce,label:Z.humanizeLabel(String(ce))}))}x.options&&(O.options=x.options);const $=N===0&&!x.link&&!x.action,se=x.link||$;x.link&&x.action||$&&x.action?E=(G,ce)=>{const Se=B?r.jsx(B,{value:G,field:O}):G!=null&&G!==""?String(G):r.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"});return r.jsx("button",{type:"button",className:"text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit","data-testid":$?"primary-field-link":"link-cell",onClick:Oe=>{Oe.stopPropagation(),ne.handleClick(ce)},children:Se})}:se?E=(G,ce)=>{const Se=B?r.jsx(B,{value:G,field:O}):G!=null&&G!==""?String(G):r.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"});return r.jsx("button",{type:"button",className:"text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit","data-testid":$?"primary-field-link":"link-cell",onClick:Oe=>{Oe.stopPropagation(),ne.handleClick(ce)},children:Se})}:x.action?E=(G,ce)=>r.jsx(v.Button,{variant:"outline",size:"sm",className:"h-7 text-xs","data-testid":"action-cell",onClick:Se=>{Se.stopPropagation(),De({type:x.action,params:{record:ce,field:x.field,value:G}})},children:Le(x.action)}):B?E=G=>r.jsx(B,{value:G,field:O}):E=G=>G!=null&&G!==""?r.jsx("span",{children:String(G)}):r.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"});const fe=x.prefix;if(fe?.field){const G=E,ce=fe.type==="badge"?Z.getCellRenderer("select"):null;E=(Se,Oe)=>{const Be=Oe[fe.field],Ks=Be!=null&&Be!==""?ce?r.jsx(ce,{value:Be,field:{name:fe.field,type:"select"}}):r.jsx("span",{className:"text-muted-foreground text-xs mr-1.5",children:String(Be)}):null;return r.jsxs("span",{className:"flex items-center gap-1.5",children:[Ks,G(Se,Oe)]})}}const ie=["number","currency","percent"],le=_||x.type,ye=x.align||(le&&ie.includes(le)?"right":void 0),W=N===0||x.essential===!0;return{header:F,accessorKey:x.field,headerIcon:c(_),...!W&&{className:"hidden sm:table-cell"},...x.width&&{width:x.width},...ye&&{align:ye},sortable:x.sortable!==!1,...x.resizable!==void 0&&{resizable:x.resizable},...x.wrap!==void 0&&{wrap:x.wrap},...E&&{cell:E},...x.pinned&&{pinned:x.pinned}}})}return k.filter(j=>typeof j=="string"&&j.trim().length>0).map((j,x)=>{const N=P?.fields?.[j],F=N?.label||j.charAt(0).toUpperCase()+j.slice(1).replace(/_/g," "),E=e.objectName?z(e.objectName,j,F):F,y=N?.type||M({field:j})||null,_=y?Z.getCellRenderer(y):null,B={name:j,type:y||"text"};if(N&&(N.label&&(B.label=N.label),N.currency&&(B.currency=N.currency),N.precision!==void 0&&(B.precision=N.precision),N.format&&(B.format=N.format),N.options&&(B.options=N.options)),y==="select"&&!B.options){const ie=Array.from(new Set(h.map(le=>le[j]).filter(Boolean)));B.options=ie.map(le=>({value:le,label:Z.humanizeLabel(String(le))}))}const $=y&&["number","currency","percent"].includes(y)?"right":void 0,se=x===0;let fe;return se&&_?fe=(ie,le)=>{const ye=r.jsx(_,{value:ie,field:B});return r.jsx("button",{type:"button",className:"text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit","data-testid":"primary-field-link",onClick:W=>{W.stopPropagation(),ne.handleClick(le)},children:ye})}:se?fe=(ie,le)=>r.jsx("button",{type:"button",className:"text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit","data-testid":"primary-field-link",onClick:ye=>{ye.stopPropagation(),ne.handleClick(le)},children:ie!=null&&ie!==""?String(ie):r.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"})}):_&&(fe=ie=>r.jsx(_,{value:ie,field:B})),{header:E,accessorKey:j,...y&&{headerIcon:c(y)},...$&&{align:$},...fe&&{cell:fe},sortable:N?.sortable!==!1}})}if(R){const j=ee?.provider==="value"?ee.items:[];if(j.length>0)return(ue||Object.keys(j[0])).map(N=>{const S=P?.fields?.[N],F=S?.type||M({field:N})||null,E=F?Z.getCellRenderer(F):null,y=S?.label||N.charAt(0).toUpperCase()+N.slice(1).replace(/_/g," "),_={name:N,type:F||"text"};if(S&&(S.label&&(_.label=S.label),S.currency&&(_.currency=S.currency),S.precision!==void 0&&(_.precision=S.precision),S.format&&(_.format=S.format),S.options&&(_.options=S.options)),F==="select"&&!_.options){const $=Array.from(new Set(h.map(se=>se[N]).filter(Boolean)));_.options=$.map(se=>({value:se,label:Z.humanizeLabel(String(se))}))}const O=F&&["number","currency","percent"].includes(F)?"right":void 0;return{header:y,accessorKey:N,...F&&{headerIcon:c(F)},...O&&{align:O},...E&&{cell:$=>r.jsx(E,{value:$,field:_})},sortable:S?.sortable!==!1}})}if(!P)return[];const U=[];return(ue||Object.keys(P.fields||{})).forEach(j=>{const x=P.fields?.[j];if(!x||x.permissions&&x.permissions.read===!1)return;const N=Z.getCellRenderer(x.type),S=["number","currency","percent"];U.push({header:e.objectName?z(e.objectName,j,x.label||j):x.label||j,accessorKey:j,...S.includes(x.type)&&{align:"right"},cell:F=>r.jsx(N,{value:F,field:x}),sortable:x.sortable!==!1})}),U},[P,ue,me,ee,R,ne.handleClick,De,h,z,e.objectName]),Ts=u.useCallback(c=>{const M=e.exportOptions,k=M?.maxRecords||0,U=M?.includeHeaders!==!1,te=M?.fileNamePrefix||e.objectName||"export",j=k>0?h.slice(0,k):h,x=(S,F)=>{const E=URL.createObjectURL(S),y=document.createElement("a");y.href=E,y.download=F,y.click(),URL.revokeObjectURL(E)},N=S=>{const F=S==null?"":String(S);return F.includes(",")||F.includes('"')||F.includes(`
7
- `)||F.includes("\r")?`"${F.replace(/"/g,'""')}"`:F};if(c==="csv"){const S=Re().filter(_=>_.accessorKey!=="_actions"),F=S.map(_=>_.accessorKey),E=S.map(_=>_.header),y=[];U&&y.push(E.join(",")),j.forEach(_=>{y.push(F.map(B=>N(_[B])).join(","))}),x(new Blob([y.join(`
8
- `)],{type:"text/csv;charset=utf-8;"}),`${te}.csv`)}else c==="json"&&x(new Blob([JSON.stringify(j,null,2)],{type:"application/json"}),`${te}.json`);Ee(!1)},[h,e.exportOptions,e.objectName,Re]);if(C)return r.jsxs("div",{className:"p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",children:[r.jsx("h3",{className:"text-red-800 font-semibold",children:D("grid.errorLoading")}),r.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(b&&h.length===0)return q?r.jsx("div",{className:"space-y-2 p-2",children:[1,2,3].map(c=>r.jsxs("div",{className:"border rounded-lg p-3 bg-card animate-pulse",children:[r.jsx("div",{className:"h-5 bg-muted rounded w-3/4 mb-3"}),r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("div",{className:"h-4 bg-muted rounded w-1/4"}),r.jsx("div",{className:"h-5 bg-muted rounded-full w-20"})]}),r.jsx("div",{className:"h-3 bg-muted rounded w-1/3"})]},c))}):r.jsxs("div",{className:"p-4 sm:p-8 text-center",children:[r.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-foreground"}),r.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:D("grid.loading")})]});let Ie=[...Re()];if(ae.widths&&(Ie=Ie.map(c=>{const M=ae.widths?.[c.accessorKey];return M?{...c,size:M}:c})),ae.order&&ae.order.length>0){const c=new Map(ae.order.map((M,k)=>[M,k]));Ie.sort((M,k)=>{const U=c.get(M.accessorKey)??1/0,te=c.get(k.accessorKey)??1/0;return U-te})}const Ce="operations"in e?e.operations:void 0,yt=Ce&&(Ce.update||Ce.delete),As=e.rowActions&&e.rowActions.length>0,$e=yt||As?[...Ie,{header:D("grid.actions"),accessorKey:"_actions",cell:(c,M)=>r.jsx(st,{row:M,rowActions:e.rowActions,canEdit:!!(Ce?.update&&t),canDelete:!!(Ce?.delete&&s),onEdit:t,onDelete:s,onAction:(k,U)=>De({type:k,params:{record:U}})}),sortable:!1}]:Ie,He=$e.filter(c=>c.pinned==="left"),vt=$e.filter(c=>c.pinned==="right"),Ms=$e.filter(c=>!c.pinned),jt=He.length>0||vt.length>0,wt="sticky right-0 z-10 bg-background border-l border-border",Ct=jt?[...He,...Ms,...vt.map(c=>({...c,className:[c.className,wt].filter(Boolean).join(" "),cellClassName:[c.cellClassName,wt].filter(Boolean).join(" ")}))]:$e,Ds=jt?He.length:e.frozenColumns??1,Ve=e.batchActions??e.bulkActions,Is=Ve&&Ve.length>0;let Ke=!1;e.selection?.type?Ke=e.selection.type==="none"?!1:e.selection.type:e.selectable!==void 0?Ke=e.selectable:Is&&(Ke="multiple");const Fs=e.pagination!==void 0?!0:e.showPagination!==void 0?e.showPagination:!0,zs=e.pagination?.pageSize||e.pageSize||10,Ls=e.searchableFields!==void 0?e.searchableFields.length>0:e.showSearch!==void 0?e.showSearch:!0,St={type:"data-table",caption:e.label||e.title,columns:Ct,data:h,pagination:Fs,pageSize:zs,searchable:Ls,selectable:Ke,sortable:!0,exportable:Ce?.export,rowActions:yt,resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,singleClickEdit:e.singleClickEdit??!0,className:e.className,cellClassName:de==="compact"?"px-3 py-1 text-[13px] leading-tight":de==="short"?"px-3 py-1 text-[13px] leading-normal":de==="tall"?"px-3 py-2.5 text-sm":de==="extra_tall"?"px-3 py-3.5 text-sm leading-relaxed":"px-3 py-1.5 text-[13px] leading-normal",showRowNumbers:!0,showAddRow:!!Ce?.create,onAddRecord:p,rowClassName:e.rowColor?(c,M)=>Ss(c):void 0,rowStyle:e.conditionalFormatting?.length?(c,M)=>Ns(c):void 0,frozenColumns:Ds,onSelectionChange:c=>{Q(c),n?.(c)},onRowClick:ne.handleClick,onCellChange:a,onRowSave:l,onBatchSave:m,onColumnResize:(c,M)=>{re({...ae,widths:{...ae.widths,[c]:M}})},onColumnReorder:c=>{re({...ae,order:c})}},Ps=c=>({...St,caption:void 0,data:c,pagination:!1,searchable:!1}),Ue=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:"Record Detail";if(q&&h.length>0&&!xt){const c=Re().filter(E=>E.accessorKey!=="_actions"),M=new Map;c.forEach(E=>M.set(E.accessorKey,E));const k=c[0],U=["amount","price","total","revenue","cost","value","budget","salary"],te=["stage","status","priority","category","severity","level"],j=["date","due","created","updated","deadline","start","end","expires"],x=["probability","percent","rate","ratio","confidence","score"],N=E=>{const y=(E||"").toLowerCase();return y.includes("won")||y.includes("completed")||y.includes("done")||y.includes("active")?"bg-green-100 text-green-800 border-green-300":y.includes("lost")||y.includes("cancelled")||y.includes("rejected")||y.includes("closed lost")?"bg-red-100 text-red-800 border-red-300":y.includes("negotiation")||y.includes("review")||y.includes("in progress")?"bg-yellow-100 text-yellow-800 border-yellow-300":y.includes("proposal")||y.includes("pending")?"bg-blue-100 text-blue-800 border-blue-300":y.includes("qualification")||y.includes("qualified")?"bg-indigo-100 text-indigo-800 border-indigo-300":y.includes("prospecting")||y.includes("new")||y.includes("open")?"bg-purple-100 text-purple-800 border-purple-300":"bg-muted text-muted-foreground border-border"},S=E=>{const y=(E||"").toLowerCase();return y.includes("won")||y.includes("completed")||y.includes("done")||y.includes("active")?"border-l-green-500":y.includes("lost")||y.includes("cancelled")||y.includes("rejected")?"border-l-red-500":y.includes("negotiation")||y.includes("review")||y.includes("in progress")?"border-l-yellow-500":y.includes("proposal")||y.includes("pending")?"border-l-blue-500":y.includes("qualification")||y.includes("qualified")?"border-l-indigo-500":y.includes("prospecting")||y.includes("new")||y.includes("open")?"border-l-purple-500":"border-l-gray-300"},F=E=>{const y=E.toLowerCase();return U.some(_=>y.includes(_))?"amount":te.some(_=>y.includes(_))?"stage":j.some(_=>y.includes(_))?"date":x.some(_=>y.includes(_))?"percent":"other"};return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"space-y-2 p-2",children:h.map((E,y)=>{const _=c.slice(1,5),B=_.find(W=>F(W.accessorKey)==="amount"),O=_.find(W=>F(W.accessorKey)==="stage"),$=_.filter(W=>F(W.accessorKey)==="date"),se=_.filter(W=>F(W.accessorKey)==="percent"),fe=_.filter(W=>W!==B&&W!==O&&!$.includes(W)&&!se.includes(W)),ie=O?String(E[O.accessorKey]??""):"",le=ie?S(ie):"",ye=["border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation",le?`border-l-[3px] ${le}`:""].filter(Boolean).join(" ");return r.jsxs("div",{className:ye,onClick:()=>ne.handleClick(E),children:[k&&r.jsx("div",{className:"font-semibold text-sm truncate mb-1",children:E[k.accessorKey]??"—"}),(B||O)&&r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[B&&r.jsx("span",{className:"text-sm tabular-nums font-medium",children:typeof E[B.accessorKey]=="number"?Z.formatCompactCurrency(E[B.accessorKey]):E[B.accessorKey]??"—"}),O&&E[O.accessorKey]&&r.jsx(v.Badge,{variant:"outline",className:`text-xs shrink-0 max-w-[140px] truncate ${N(String(E[O.accessorKey]))}`,children:E[O.accessorKey]})]}),($.length>0||se.length>0)&&r.jsxs("div",{className:"flex items-center justify-between py-0.5 text-xs text-muted-foreground",children:[$[0]&&r.jsx("span",{className:"tabular-nums",children:E[$[0].accessorKey]?Z.formatDate(E[$[0].accessorKey],"short"):"—"}),se[0]&&E[se[0].accessorKey]!=null&&r.jsx("span",{className:"tabular-nums",children:Z.formatPercent(Number(E[se[0].accessorKey]))})]}),$.slice(1).map(W=>r.jsxs("div",{className:"flex justify-between items-center py-0.5",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:W.header}),r.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:E[W.accessorKey]?Z.formatDate(E[W.accessorKey],"short"):"—"})]},W.accessorKey)),fe.map(W=>{const G=E[W.accessorKey];return G==null||G===""?null:r.jsxs("div",{className:"flex justify-between items-center py-0.5",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:W.header}),r.jsx("span",{className:"text-xs font-medium truncate ml-2 text-right",children:W.cell?W.cell(G,E):String(G)})]},W.accessorKey)})]},E.id||E._id||y)})}),ne.isOverlay&&r.jsx(v.NavigationOverlay,{...ne,title:Ue,children:E=>r.jsx("div",{className:"space-y-3",children:Object.entries(E).map(([y,_])=>r.jsxs("div",{className:"flex flex-col",children:[r.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:y.replace(/_/g," ")}),r.jsx("span",{className:"text-sm",children:String(_??"—")})]},y))})})]})}const Rs=()=>{ge(c=>c==="compact"?"short":c==="short"?"medium":c==="medium"?"tall":c==="tall"?"extra_tall":"compact")},$s={compact:I.Rows4,short:I.Rows3,medium:I.Rows2,tall:I.AlignJustify,extra_tall:I.AlignJustify}[de],Nt=e.rowHeight!==void 0,Et=e.exportOptions||Nt?r.jsxs("div",{className:"flex items-center justify-end gap-1 px-2 py-1",children:[Nt&&r.jsxs(v.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs",onClick:Rs,title:`Row height: ${de}`,children:[r.jsx($s,{className:"h-3.5 w-3.5 mr-1.5"}),r.jsx("span",{className:"hidden sm:inline capitalize",children:de})]}),e.exportOptions&&r.jsxs(v.Popover,{open:ve,onOpenChange:Ee,children:[r.jsx(v.PopoverTrigger,{asChild:!0,children:r.jsxs(v.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs",children:[r.jsx(I.Download,{className:"h-3.5 w-3.5 mr-1.5"}),r.jsx("span",{className:"hidden sm:inline",children:D("grid.export")})]})}),r.jsx(v.PopoverContent,{align:"end",className:"w-48 p-2",children:r.jsx("div",{className:"space-y-1",children:(e.exportOptions.formats||["csv","json"]).map(c=>r.jsxs(v.Button,{variant:"ghost",size:"sm",className:"w-full justify-start h-8 text-xs",onClick:()=>Ts(c),children:[r.jsx(I.Download,{className:"h-3.5 w-3.5 mr-2"}),D("grid.exportAs",{format:c.toUpperCase()})]},c))})})]})]}):null,kt=c=>{const M=["_id","id","created_at","updated_at","created_by","updated_by"],k=Object.entries(c),U=k.filter(([N])=>!M.includes(N)),te=k.filter(([N])=>M.includes(N)&&N!=="_id"&&N!=="id"),j=N=>N.charAt(0).toUpperCase()+N.slice(1).replace(/_/g," "),x=(N,S)=>{if(S==null||S==="")return r.jsx("span",{className:"text-muted-foreground/50 text-sm italic",children:"Empty"});const F=P?.fields?.[N];if(F?.type){const y=Z.getCellRenderer(F.type);if(y)return r.jsx(y,{value:S,field:F})}return typeof S=="boolean"?r.jsx(v.Badge,{variant:S?"default":"outline",children:S?"Yes":"No"}):typeof S=="string"&&!isNaN(Date.parse(S))&&(N.includes("date")||N.includes("_at")||N.includes("time"))?r.jsx("span",{className:"text-sm tabular-nums",children:Z.formatDate(S)}):typeof S=="number"&&["amount","price","total","revenue","cost","value","budget","salary"].some(y=>N.toLowerCase().includes(y))?r.jsx("span",{className:"text-sm tabular-nums font-medium",children:Z.formatCurrency(S)}):r.jsx("span",{className:"text-sm break-words",children:String(S)})};return r.jsxs("div",{className:"space-y-4","data-testid":"record-detail-panel",children:[r.jsx("div",{className:"rounded-lg border bg-card",children:r.jsx("div",{className:"divide-y",children:U.map(([N,S])=>r.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-4 px-4 py-3",children:[r.jsx("span",{className:"text-xs font-medium text-muted-foreground sm:w-1/3 sm:text-right sm:pt-0.5 uppercase tracking-wide shrink-0",children:j(N)}),r.jsx("div",{className:"flex-1 min-w-0",children:x(N,S)})]},N))})}),te.length>0&&r.jsxs("div",{className:"rounded-lg border bg-muted/30",children:[r.jsx("div",{className:"px-4 py-2 border-b",children:r.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"System"})}),r.jsx("div",{className:"divide-y divide-border/50",children:te.map(([N,S])=>r.jsxs("div",{className:"flex items-center gap-4 px-4 py-2",children:[r.jsx("span",{className:"text-xs text-muted-foreground w-1/3 text-right shrink-0",children:j(N)}),r.jsx("span",{className:"text-xs text-muted-foreground flex-1 min-w-0 break-words",children:String(S??"")})]},N))})]})]})},Vs=_s?r.jsx("div",{className:"border-t bg-muted/30 px-2 py-1.5","data-testid":"column-summary-footer",children:r.jsx("div",{className:"flex gap-4 text-xs text-muted-foreground font-medium",children:Ct.filter(c=>bt.has(c.accessorKey)).map(c=>{const M=bt.get(c.accessorKey);return r.jsxs("span",{"data-testid":`summary-${c.accessorKey}`,children:[c.header,": ",M.label]},c.accessorKey)})})}):null,Ot=xt?r.jsx("div",{className:"space-y-2",children:Es.map(c=>r.jsx(et,{groupKey:c.key,label:c.label,count:c.rows.length,collapsed:c.collapsed,aggregations:c.aggregations,onToggle:ks,children:r.jsx(pe.SchemaRenderer,{schema:Ps(c.rows)})},c.key))}):r.jsxs(r.Fragment,{children:[r.jsx(pe.SchemaRenderer,{schema:St}),Vs]});return ne.isOverlay&&ne.mode==="split"?r.jsx(v.NavigationOverlay,{...ne,title:Ue,mainContent:r.jsxs(r.Fragment,{children:[Et,Ot,r.jsx(We,{selectedRows:V,actions:Ve??[],onAction:(c,M)=>De({type:c,params:{records:M}}),onClearSelection:()=>Q([])})]}),children:c=>kt(c)}):r.jsxs("div",{ref:xe,className:"relative h-full",children:[A>0&&r.jsx("div",{className:"flex items-center justify-center text-xs text-muted-foreground",style:{height:A},children:D(d?"grid.refreshing":"grid.pullToRefresh")}),Et,Ot,r.jsx(We,{selectedRows:V,actions:Ve??[],onAction:(c,M)=>De({type:c,params:{records:M}}),onClearSelection:()=>Q([])}),ne.isOverlay&&r.jsx(v.NavigationOverlay,{...ne,title:Ue,children:c=>kt(c)})]})};function Ne(e,o,t){let s=t.initialDeps??[],n,i=!0;function a(){var l,m,p;let f;t.key&&((l=t.debug)!=null&&l.call(t))&&(f=Date.now());const h=e();if(!(h.length!==s.length||h.some((w,C)=>s[C]!==w)))return n;s=h;let b;if(t.key&&((m=t.debug)!=null&&m.call(t))&&(b=Date.now()),n=o(...h),t.key&&((p=t.debug)!=null&&p.call(t))){const w=Math.round((Date.now()-f)*100)/100,C=Math.round((Date.now()-b)*100)/100,T=C/16,D=(z,P)=>{for(z=String(z);z.length<P;)z=" "+z;return z};console.info(`%c⏱ ${D(C,5)} /${D(w,5)} ms`,`
6
+ <%s key={someKey} {...props} />`,o,p,m,p),I[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),ee=Symbol.for(`react.client.reference`),O=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,k=Object.prototype.hasOwnProperty,A=Array.isArray,j=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var M,N={},P=m.react_stack_bottom_frame.bind(m,o)(),F=j(i(o)),I={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>O.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):P,r?j(i(e)):F)},e.jsxs=function(e,t,n){var r=1e4>O.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):P,r?j(i(e)):F)}})()})),y=m(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=_():t.exports=v()}))(),b=(0,t.createContext)(null);b.displayName=`MobileContext`;var x={red:`bg-red-100`,green:`bg-green-100`,blue:`bg-blue-100`,yellow:`bg-yellow-100`,orange:`bg-orange-100`,purple:`bg-purple-100`,pink:`bg-pink-100`,gray:`bg-gray-100`,grey:`bg-gray-100`,indigo:`bg-indigo-100`,teal:`bg-teal-100`,cyan:`bg-cyan-100`,amber:`bg-amber-100`,lime:`bg-lime-100`,emerald:`bg-emerald-100`,rose:`bg-rose-100`,sky:`bg-sky-100`,violet:`bg-violet-100`,fuchsia:`bg-fuchsia-100`,slate:`bg-slate-100`,zinc:`bg-zinc-100`,stone:`bg-stone-100`,neutral:`bg-neutral-100`};function S(e){return e.startsWith(`bg-`)?e:x[e.toLowerCase().trim()]}function C(e){return(0,t.useCallback)(t=>{if(!e?.field||!e.colors)return;let n=String(t[e.field]??``),r=e.colors[n];if(r)return S(r)},[e?.field,e?.colors])}function w(e,t){return t.map(t=>String(e[t.field]??``)).join(` / `)}function T(e,t){return t.map(t=>{let n=e[t.field];return n!=null&&n!==``?String(n):`(empty)`}).join(` / `)}function E(e,t){return t.map(({field:t,type:n})=>{let r=e.map(e=>Number(e[t])).filter(e=>Number.isFinite(e)),i;switch(n){case`count`:i=r.length;break;case`sum`:i=r.reduce((e,t)=>e+t,0);break;case`avg`:i=r.length>0?r.reduce((e,t)=>e+t,0)/r.length:0;break;case`min`:i=r.length>0?Math.min(...r):0;break;case`max`:i=r.length>0?Math.max(...r):0;break;default:i=0}return{field:t,type:n,value:i}})}function D(e,t,n){let r=e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`});return n===`desc`?-r:r}function ee(e,n,r){let i=e?.fields,a=!!(i&&i.length>0),[o,s]=(0,t.useState)({}),c=(0,t.useMemo)(()=>i?i.some(e=>e.collapsed):!1,[i]);return{groups:(0,t.useMemo)(()=>{if(!a||!i)return[];let e=new Map,t=[];for(let r of n){let n=w(r,i);e.has(n)||(e.set(n,{label:T(r,i),rows:[]}),t.push(n)),e.get(n).rows.push(r)}let s=i[0]?.order??`asc`;return t.sort((e,t)=>D(e,t,s)),t.map(t=>{let n=e.get(t),i=t in o?o[t]:c,a=r&&r.length>0?E(n.rows,r):[];return{key:t,label:n.label,rows:n.rows,collapsed:i,aggregations:a}})},[n,i,a,o,c,r]),isGrouped:a,toggleGroup:(0,t.useCallback)(e=>{s(t=>({...t,[e]:t[e]===void 0?!c:!t[e]}))},[c])}}var O=({groupKey:e,label:t,count:n,collapsed:r,aggregations:i,onToggle:a,children:s})=>(0,y.jsxs)(`div`,{className:`border rounded-md`,"data-testid":`group-row-${e}`,children:[(0,y.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors`,onClick:()=>a(e),"aria-expanded":!r,children:[r?(0,y.jsx)(o.ChevronRight,{className:`h-4 w-4 shrink-0`}):(0,y.jsx)(o.ChevronDown,{className:`h-4 w-4 shrink-0`}),(0,y.jsx)(`span`,{className:`group-label`,children:t}),i&&i.length>0&&(0,y.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground group-aggregations`,children:i.map(e=>(0,y.jsxs)(`span`,{className:`mr-2`,children:[e.type,`: `,Number.isInteger(e.value)?e.value:e.value.toFixed(2)]},`${e.field}-${e.type}`))}),(0,y.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground group-count`,children:[`(`,n,`)`]})]}),!r&&s]});function k(e){return typeof e==`string`?{type:e}:e}function A(e,t){if(t.length===0)return null;switch(e){case`count`:return t.length;case`sum`:return t.reduce((e,t)=>e+t,0);case`avg`:return t.reduce((e,t)=>e+t,0)/t.length;case`min`:return Math.min(...t);case`max`:return Math.max(...t);default:return null}}function j(e,t){return t===null?``:`${{count:`Count`,sum:`Sum`,avg:`Avg`,min:`Min`,max:`Max`}[e]||e}: ${e===`avg`?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString()}`}function M(e,n){return(0,t.useMemo)(()=>{let t=new Map;if(!e||e.length===0||n.length===0)return{summaries:t,hasSummary:!1};for(let r of e){if(!r.summary)continue;let e=k(r.summary),i=e.field||r.field,a=[];for(let e of n){let t=e[i];if(t!=null&&typeof t==`number`&&!isNaN(t))a.push(t);else if(t!=null&&typeof t==`string`){let e=parseFloat(t);isNaN(e)||a.push(e)}}let o;if(e.type===`count`){let e=n.filter(e=>e[i]!=null&&e[i]!==``).length;o=e>0?e:null}else o=A(e.type,a);t.set(r.field,{field:r.field,value:o,label:j(e.type,o)})}return{summaries:t,hasSummary:t.size>0}},[e,n])}function N(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var P=({row:e,rowActions:t,canEdit:n,canDelete:r,onEdit:i,onDelete:s,onAction:c})=>(0,y.jsxs)(a.DropdownMenu,{children:[(0,y.jsx)(a.DropdownMenuTrigger,{asChild:!0,children:(0,y.jsxs)(a.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0`,"data-testid":`row-action-trigger`,children:[(0,y.jsx)(o.MoreVertical,{className:`h-4 w-4`}),(0,y.jsx)(`span`,{className:`sr-only`,children:`Open menu`})]})}),(0,y.jsxs)(a.DropdownMenuContent,{align:`end`,children:[n&&i&&(0,y.jsxs)(a.DropdownMenuItem,{onClick:()=>i(e),children:[(0,y.jsx)(o.Edit,{className:`mr-2 h-4 w-4`}),`Edit`]}),r&&s&&(0,y.jsxs)(a.DropdownMenuItem,{onClick:()=>s(e),children:[(0,y.jsx)(o.Trash2,{className:`mr-2 h-4 w-4`}),`Delete`]}),t?.map(t=>(0,y.jsx)(a.DropdownMenuItem,{onClick:()=>c?.(t,e),"data-testid":`row-action-${t}`,children:N(t)},t))]})]}),F=({selectedRows:e,actions:t,onAction:n,onClearSelection:r})=>!t||t.length===0||e.length===0?null:(0,y.jsxs)(`div`,{className:`border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0`,"data-testid":`bulk-actions-bar`,children:[(0,y.jsxs)(`span`,{className:`text-muted-foreground font-medium`,children:[e.length,` selected`]}),(0,y.jsx)(`div`,{className:`flex items-center gap-1 ml-2`,children:t.map(t=>(0,y.jsx)(a.Button,{variant:`outline`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>n?.(t,e),"data-testid":`bulk-action-${t}`,children:N(t)},t))}),(0,y.jsx)(a.Button,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs ml-auto`,onClick:r,children:`Clear`})]}),I={"grid.actions":`Actions`,"grid.edit":`Edit`,"grid.delete":`Delete`,"grid.export":`Export`,"grid.exportAs":`Export as {{format}}`,"grid.loading":`Loading grid...`,"grid.errorLoading":`Error loading grid`,"grid.pullToRefresh":`Pull to refresh`,"grid.refreshing":`Refreshing…`,"grid.openRecord":`Open record`};function te(){try{let e=(0,r.useObjectTranslation)();return e.t(`grid.actions`)===`grid.actions`?{t:(e,t)=>{let n=I[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}:{t:e.t}}catch{return{t:(e,t)=>{let n=I[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}}}function ne(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}function re(e){return e.data?Array.isArray(e.data)?{provider:`value`,items:e.data}:e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function ie(e){if(!(!e||e.length===0))return typeof e[0]==`object`&&e[0],e}var ae=({schema:e,dataSource:s,onEdit:c,onDelete:l,onRowSelect:u,onRowClick:d,onCellChange:f,onRowSave:p,onBatchSave:m,onAddRecord:h,..._})=>{let[v,b]=(0,t.useState)([]),[x,S]=(0,t.useState)(!0),[w,T]=(0,t.useState)(null),{t:E}=te(),{fieldLabel:D}=(0,r.useSafeFieldLabel)(),[k,A]=(0,t.useState)(null),[j,I]=(0,t.useState)(!1),[ae,L]=(0,t.useState)(0),[oe,se]=(0,t.useState)(!1),[R,ce]=(0,t.useState)(e.rowHeight??`compact`),[le,ue]=(0,t.useState)([]),de=t.default.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[z,fe]=(0,t.useState)(()=>{try{let e=localStorage.getItem(de);return e?JSON.parse(e):{}}catch{return{}}}),pe=(0,t.useCallback)(e=>{fe(e);try{localStorage.setItem(de,JSON.stringify(e))}catch(e){console.warn(`Failed to persist column state:`,e)}},[de]),{ref:me,isRefreshing:he,pullDistance:ge}=g({onRefresh:(0,t.useCallback)(async()=>{L(e=>e+1)},[]),enabled:!!s&&!!e.objectName});(0,t.useEffect)(()=>{let e=()=>I(window.innerWidth<480);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let B=_.data,V=(0,r.useDataScope)(e.bind),_e=re(e),H=t.default.useMemo(()=>B&&Array.isArray(B)?{provider:`value`,items:B}:V&&Array.isArray(V)?{provider:`value`,items:V}:_e,[JSON.stringify(_e),V,B]),U=H?.provider===`value`,W=H?.provider===`object`&&H&&`object`in H?H.object:e.objectName,G=e.fields,K=e.columns,q=e.filter,J=e.sort,ve=e.pagination,ye=e.pageSize;(0,t.useEffect)(()=>{U&&H?.provider===`value`&&(b(e=>{let t=H.items;return JSON.stringify(e)===JSON.stringify(t)?e:t}),S(!1))},[U,H]),(0,t.useEffect)(()=>{if(!U||!W||!s)return;let e=!1;return(async()=>{try{let t=await s.getObjectSchema(W);e||A(t)}catch(e){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${W}):`,e)}})(),()=>{e=!0}},[U,W,s]),(0,t.useEffect)(()=>{if(U)return;let t=!1;return(async()=>{S(!0),T(null);try{let r=null,i=ie(K)||G;if(W&&s){let e=await s.getObjectSchema(W);if(t)return;r=e}else if(i&&W)r={name:W,fields:{}};else if(W)throw Error(`DataSource required`);else throw Error(`Object name required for data fetching`);if(t||A(r),s&&W){let i={$select:(()=>{if(G)return G;if(K&&Array.isArray(K))return K.map(e=>typeof e==`string`?e:e.field)})(),$top:ve?.pageSize||ye||50};q&&Array.isArray(q)?i.$filter=q:e.defaultFilters&&(i.$filter=e.defaultFilters),J?typeof J==`string`?i.$orderby=J:Array.isArray(J)&&(i.$orderby=J.map(e=>`${e.field} ${e.order}`).join(`, `)):e.defaultSort&&(i.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);let a=(0,n.buildExpandFields)(r?.fields,K??G);a.length>0&&(i.$expand=a);let o=await s.find(W,i);if(t)return;b(o.data||[])}}catch(e){t||T(e)}finally{t||S(!1)}})(),()=>{t=!0}},[W,G,K,q,J,ve,ye,s,U,H,ae]);let Y=(0,r.useNavigationOverlay)({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:d}),{execute:X}=(0,r.useAction)(),be=C(e.rowColor),xe=(0,t.useCallback)(t=>{let r=e.conditionalFormatting;if(!(!r||r.length===0))for(let e of r){let r=!1,i=(`condition`in e?e.condition:void 0)||(`expression`in e?e.expression:void 0)||void 0;if(i)r=(0,n.evaluatePlainCondition)(i,t);else if(`field`in e&&`operator`in e&&e.field&&e.operator){let n=e,i=t[n.field];switch(n.operator){case`equals`:r=i===n.value;break;case`not_equals`:r=i!==n.value;break;case`contains`:r=typeof i==`string`&&typeof n.value==`string`&&i.includes(n.value);break;case`greater_than`:r=typeof i==`number`&&typeof n.value==`number`&&i>n.value;break;case`less_than`:r=typeof i==`number`&&typeof n.value==`number`&&i<n.value;break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}}if(r){let t={};return`style`in e&&e.style&&Object.assign(t,e.style),`backgroundColor`in e&&e.backgroundColor&&(t.backgroundColor=e.backgroundColor),`textColor`in e&&e.textColor&&(t.color=e.textColor),`borderColor`in e&&e.borderColor&&(t.borderColor=e.borderColor),t}}},[e.conditionalFormatting]),{groups:Se,isGrouped:Ce,toggleGroup:we}=ee(e.grouping,v),{summaries:Te,hasSummary:Ee}=M(t.default.useMemo(()=>{let t=ie(e.columns);if(t&&t.length>0&&typeof t[0]==`object`)return t},[e.columns]),v),Z=(0,t.useCallback)(()=>{let t=e=>e&&{text:(0,y.jsx)(o.Type,{className:`h-3.5 w-3.5`}),number:(0,y.jsx)(o.Hash,{className:`h-3.5 w-3.5`}),currency:(0,y.jsx)(o.Hash,{className:`h-3.5 w-3.5`}),percent:(0,y.jsx)(o.Hash,{className:`h-3.5 w-3.5`}),date:(0,y.jsx)(o.Calendar,{className:`h-3.5 w-3.5`}),datetime:(0,y.jsx)(o.Clock,{className:`h-3.5 w-3.5`}),boolean:(0,y.jsx)(o.CheckSquare,{className:`h-3.5 w-3.5`}),user:(0,y.jsx)(o.User,{className:`h-3.5 w-3.5`}),select:(0,y.jsx)(o.Tag,{className:`h-3.5 w-3.5`})}[e]||(0,y.jsx)(o.Type,{className:`h-3.5 w-3.5`}),n=e=>{if(e.type)return e.type;let t=e.field.toLowerCase();if([`completed`,`is_completed`,`done`,`active`,`enabled`,`archived`].some(e=>t===e||t===`is_${e}`))return`boolean`;if([`created_time`,`modified_time`,`updated_time`,`created_at`,`updated_at`,`modified_at`,`last_login`,`logged_at`].some(e=>t===e||t.endsWith(`_${e}`)))return`datetime`;if([`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`].some(e=>t.includes(e))){if(v.length>0){let t=v.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&!isNaN(Date.parse(t)))return`date`}return`date`}if([`probability`,`percent`,`percentage`,`completion`,`progress`,`rate`].some(e=>t.includes(e))&&v.length>0&&typeof v.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`percent`;if([`status`,`priority`,`category`,`stage`,`type`,`severity`,`level`].some(e=>t.includes(e))&&v.length>0){let t=new Set(v.map(t=>t[e.field]).filter(Boolean));if(t.size>0&&t.size<=10)return`select`}if([`assignee`,`owner`,`author`,`reporter`,`creator`,`user`].some(e=>t.includes(e)))return`user`;if([`amount`,`price`,`total`,`revenue`,`cost`,`budget`,`salary`].some(e=>t.includes(e))&&v.length>0&&typeof v.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`currency`;if(v.length>0){let t=v.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return`datetime`}return null},r=ie(K);if(r){if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let o=r[0];if(`accessorKey`in o)return r.map(e=>{if(e.cell)return e;let r=n({field:e.accessorKey,label:e.header,type:e.type});if(!r)return e;let a=(0,i.getCellRenderer)(r),o={name:e.accessorKey,type:r};return r===`select`&&(o.options=Array.from(new Set(v.map(t=>t[e.accessorKey]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))}))),{...e,headerIcon:t(r),cell:e=>(0,y.jsx)(a,{value:e,field:o})}});if(`field`in o)return r.filter(e=>e?.field&&typeof e.field==`string`&&!e.hidden).map((r,o)=>{let s=ne(r.label)||r.field.charAt(0).toUpperCase()+r.field.slice(1).replace(/_/g,` `),c=e.objectName?D(e.objectName,r.field,s):s,l,u=k?.fields?.[r.field],d=r.type||u?.type||n({field:r.field})||null,f=d?(0,i.getCellRenderer)(d):null,p={name:r.field,type:d||`text`};u&&(u.label&&(p.label=u.label),u.currency&&(p.currency=u.currency),u.precision!==void 0&&(p.precision=u.precision),u.format&&(p.format=u.format),u.options&&(p.options=u.options)),d===`select`&&!p.options&&(p.options=Array.from(new Set(v.map(e=>e[r.field]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))}))),r.options&&(p.options=r.options);let m=o===0&&!r.link&&!r.action,h=r.link||m;l=r.link&&r.action||m&&r.action||h?(e,t)=>{let n=f?(0,y.jsx)(f,{value:e,field:p}):e!=null&&e!==``?String(e):(0,y.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`});return(0,y.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":m?`primary-field-link`:`link-cell`,onClick:e=>{e.stopPropagation(),Y.handleClick(t)},children:n})}:r.action?(e,t)=>(0,y.jsx)(a.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,"data-testid":`action-cell`,onClick:n=>{n.stopPropagation(),X({type:r.action,params:{record:t,field:r.field,value:e}})},children:N(r.action)}):f?e=>(0,y.jsx)(f,{value:e,field:p}):e=>e!=null&&e!==``?(0,y.jsx)(`span`,{children:String(e)}):(0,y.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`});let g=r.prefix;if(g?.field){let e=l,t=g.type===`badge`?(0,i.getCellRenderer)(`select`):null;l=(n,r)=>{let i=r[g.field];return(0,y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[i!=null&&i!==``?t?(0,y.jsx)(t,{value:i,field:{name:g.field,type:`select`}}):(0,y.jsx)(`span`,{className:`text-muted-foreground text-xs mr-1.5`,children:String(i)}):null,e(n,r)]})}}let _=[`number`,`currency`,`percent`],b=d||r.type,x=r.align||(b&&_.includes(b)?`right`:void 0),S=o===0||r.essential===!0;return{header:c,accessorKey:r.field,headerIcon:t(d),...!S&&{className:`hidden sm:table-cell`},...r.width&&{width:r.width},...x&&{align:x},sortable:r.sortable!==!1,...r.resizable!==void 0&&{resizable:r.resizable},...r.wrap!==void 0&&{wrap:r.wrap},...l&&{cell:l},...r.pinned&&{pinned:r.pinned}}})}return r.filter(e=>typeof e==`string`&&e.trim().length>0).map((r,a)=>{let o=k?.fields?.[r],s=o?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),c=e.objectName?D(e.objectName,r,s):s,l=o?.type||n({field:r})||null,u=l?(0,i.getCellRenderer)(l):null,d={name:r,type:l||`text`};o&&(o.label&&(d.label=o.label),o.currency&&(d.currency=o.currency),o.precision!==void 0&&(d.precision=o.precision),o.format&&(d.format=o.format),o.options&&(d.options=o.options)),l===`select`&&!d.options&&(d.options=Array.from(new Set(v.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))})));let f=l&&[`number`,`currency`,`percent`].includes(l)?`right`:void 0,p=a===0,m;return p&&u?m=(e,t)=>{let n=(0,y.jsx)(u,{value:e,field:d});return(0,y.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),Y.handleClick(t)},children:n})}:p?m=(e,t)=>(0,y.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),Y.handleClick(t)},children:e!=null&&e!==``?String(e):(0,y.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):u&&(m=e=>(0,y.jsx)(u,{value:e,field:d})),{header:c,accessorKey:r,...l&&{headerIcon:t(l)},...f&&{align:f},...m&&{cell:m},sortable:o?.sortable!==!1}})}if(U){let e=H?.provider===`value`?H.items:[];if(e.length>0)return(G||Object.keys(e[0])).map(e=>{let r=k?.fields?.[e],a=r?.type||n({field:e})||null,o=a?(0,i.getCellRenderer)(a):null,s=r?.label||e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `),c={name:e,type:a||`text`};r&&(r.label&&(c.label=r.label),r.currency&&(c.currency=r.currency),r.precision!==void 0&&(c.precision=r.precision),r.format&&(c.format=r.format),r.options&&(c.options=r.options)),a===`select`&&!c.options&&(c.options=Array.from(new Set(v.map(t=>t[e]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))})));let l=a&&[`number`,`currency`,`percent`].includes(a)?`right`:void 0;return{header:s,accessorKey:e,...a&&{headerIcon:t(a)},...l&&{align:l},...o&&{cell:e=>(0,y.jsx)(o,{value:e,field:c})},sortable:r?.sortable!==!1}})}if(!k)return[];let s=[];return(G||Object.keys(k.fields||{})).forEach(t=>{let n=k.fields?.[t];if(!n||n.permissions&&n.permissions.read===!1)return;let r=(0,i.getCellRenderer)(n.type);s.push({header:e.objectName?D(e.objectName,t,n.label||t):n.label||t,accessorKey:t,...[`number`,`currency`,`percent`].includes(n.type)&&{align:`right`},cell:e=>(0,y.jsx)(r,{value:e,field:n}),sortable:n.sortable!==!1})}),s},[k,G,K,H,U,Y.handleClick,X,v,D,e.objectName]),De=(0,t.useCallback)(t=>{let n=e.exportOptions,r=n?.maxRecords||0,i=n?.includeHeaders!==!1,a=n?.fileNamePrefix||e.objectName||`export`,o=r>0?v.slice(0,r):v,s=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)},c=e=>{let t=e==null?``:String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
7
+ `)||t.includes(`\r`)?`"${t.replace(/"/g,`""`)}"`:t};if(t===`csv`){let e=Z().filter(e=>e.accessorKey!==`_actions`),t=e.map(e=>e.accessorKey),n=e.map(e=>e.header),r=[];i&&r.push(n.join(`,`)),o.forEach(e=>{r.push(t.map(t=>c(e[t])).join(`,`))}),s(new Blob([r.join(`
8
+ `)],{type:`text/csv;charset=utf-8;`}),`${a}.csv`)}else t===`json`&&s(new Blob([JSON.stringify(o,null,2)],{type:`application/json`}),`${a}.json`);se(!1)},[v,e.exportOptions,e.objectName,Z]);if(w)return(0,y.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,y.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:E(`grid.errorLoading`)}),(0,y.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:w.message})]});if(x&&v.length===0)return j?(0,y.jsx)(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>(0,y.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card animate-pulse`,children:[(0,y.jsx)(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-3`}),(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,y.jsx)(`div`,{className:`h-4 bg-muted rounded w-1/4`}),(0,y.jsx)(`div`,{className:`h-5 bg-muted rounded-full w-20`})]}),(0,y.jsx)(`div`,{className:`h-3 bg-muted rounded w-1/3`})]},e))}):(0,y.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,y.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-foreground`}),(0,y.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:E(`grid.loading`)})]});let Q=[...Z()];if(z.widths&&(Q=Q.map(e=>{let t=z.widths?.[e.accessorKey];return t?{...e,size:t}:e})),z.order&&z.order.length>0){let e=new Map(z.order.map((e,t)=>[e,t]));Q.sort((t,n)=>(e.get(t.accessorKey)??1/0)-(e.get(n.accessorKey)??1/0))}let $=`operations`in e?e.operations:void 0,Oe=$&&($.update||$.delete),ke=e.rowActions&&e.rowActions.length>0,Ae=Oe||ke?[...Q,{header:E(`grid.actions`),accessorKey:`_actions`,cell:(t,n)=>(0,y.jsx)(P,{row:n,rowActions:e.rowActions,canEdit:!!($?.update&&c),canDelete:!!($?.delete&&l),onEdit:c,onDelete:l,onAction:(e,t)=>X({type:e,params:{record:t}})}),sortable:!1}]:Q,je=Ae.filter(e=>e.pinned===`left`),Me=Ae.filter(e=>e.pinned===`right`),Ne=Ae.filter(e=>!e.pinned),Pe=je.length>0||Me.length>0,Fe=`sticky right-0 z-10 bg-background border-l border-border`,Ie=Pe?[...je,...Ne,...Me.map(e=>({...e,className:[e.className,Fe].filter(Boolean).join(` `),cellClassName:[e.cellClassName,Fe].filter(Boolean).join(` `)}))]:Ae,Le=Pe?je.length:e.frozenColumns??1,Re=e.batchActions??e.bulkActions,ze=Re&&Re.length>0,Be=!1;e.selection?.type?Be=e.selection.type===`none`?!1:e.selection.type:e.selectable===void 0?ze&&(Be=`multiple`):Be=e.selectable;let Ve=e.pagination===void 0?e.showPagination===void 0?!0:e.showPagination:!0,He=e.pagination?.pageSize||e.pageSize||10,Ue=e.searchableFields===void 0?e.showSearch===void 0?!0:e.showSearch:e.searchableFields.length>0,We={type:`data-table`,caption:e.label||e.title,columns:Ie,data:v,pagination:Ve,pageSize:He,searchable:Ue,selectable:Be,sortable:!0,exportable:$?.export,rowActions:Oe,resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,singleClickEdit:e.singleClickEdit??!0,className:e.className,cellClassName:R===`compact`?`px-3 py-1 text-[13px] leading-tight`:R===`short`?`px-3 py-1 text-[13px] leading-normal`:R===`tall`?`px-3 py-2.5 text-sm`:R===`extra_tall`?`px-3 py-3.5 text-sm leading-relaxed`:`px-3 py-1.5 text-[13px] leading-normal`,showRowNumbers:!0,showAddRow:!!$?.create,onAddRecord:h,rowClassName:e.rowColor?(e,t)=>be(e):void 0,rowStyle:e.conditionalFormatting?.length?(e,t)=>xe(e):void 0,frozenColumns:Le,onSelectionChange:e=>{ue(e),u?.(e)},onRowClick:Y.handleClick,onCellChange:f,onRowSave:p,onBatchSave:m,onColumnResize:(e,t)=>{pe({...z,widths:{...z.widths,[e]:t}})},onColumnReorder:e=>{pe({...z,order:e})}},Ge=e=>({...We,caption:void 0,data:e,pagination:!1,searchable:!1}),Ke=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:`Record Detail`;if(j&&v.length>0&&!Ce){let e=Z().filter(e=>e.accessorKey!==`_actions`),t=new Map;e.forEach(e=>t.set(e.accessorKey,e));let n=e[0],r=[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`],o=[`stage`,`status`,`priority`,`category`,`severity`,`level`],s=[`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`],c=[`probability`,`percent`,`rate`,`ratio`,`confidence`,`score`],l=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)?`bg-green-100 text-green-800 border-green-300`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t.includes(`closed lost`)?`bg-red-100 text-red-800 border-red-300`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)?`bg-yellow-100 text-yellow-800 border-yellow-300`:t.includes(`proposal`)||t.includes(`pending`)?`bg-blue-100 text-blue-800 border-blue-300`:t.includes(`qualification`)||t.includes(`qualified`)?`bg-indigo-100 text-indigo-800 border-indigo-300`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`bg-purple-100 text-purple-800 border-purple-300`:`bg-muted text-muted-foreground border-border`},u=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)?`border-l-green-500`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)?`border-l-red-500`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)?`border-l-yellow-500`:t.includes(`proposal`)||t.includes(`pending`)?`border-l-blue-500`:t.includes(`qualification`)||t.includes(`qualified`)?`border-l-indigo-500`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`border-l-purple-500`:`border-l-gray-300`},d=e=>{let t=e.toLowerCase();return r.some(e=>t.includes(e))?`amount`:o.some(e=>t.includes(e))?`stage`:s.some(e=>t.includes(e))?`date`:c.some(e=>t.includes(e))?`percent`:`other`};return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`space-y-2 p-2`,children:v.map((t,r)=>{let o=e.slice(1,5),s=o.find(e=>d(e.accessorKey)===`amount`),c=o.find(e=>d(e.accessorKey)===`stage`),f=o.filter(e=>d(e.accessorKey)===`date`),p=o.filter(e=>d(e.accessorKey)===`percent`),m=o.filter(e=>e!==s&&e!==c&&!f.includes(e)&&!p.includes(e)),h=c?String(t[c.accessorKey]??``):``,g=h?u(h):``;return(0,y.jsxs)(`div`,{className:[`border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation`,g?`border-l-[3px] ${g}`:``].filter(Boolean).join(` `),onClick:()=>Y.handleClick(t),children:[n&&(0,y.jsx)(`div`,{className:`font-semibold text-sm truncate mb-1`,children:t[n.accessorKey]??`—`}),(s||c)&&(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[s&&(0,y.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:typeof t[s.accessorKey]==`number`?(0,i.formatCompactCurrency)(t[s.accessorKey]):t[s.accessorKey]??`—`}),c&&t[c.accessorKey]&&(0,y.jsx)(a.Badge,{variant:`outline`,className:`text-xs shrink-0 max-w-[140px] truncate ${l(String(t[c.accessorKey]))}`,children:t[c.accessorKey]})]}),(f.length>0||p.length>0)&&(0,y.jsxs)(`div`,{className:`flex items-center justify-between py-0.5 text-xs text-muted-foreground`,children:[f[0]&&(0,y.jsx)(`span`,{className:`tabular-nums`,children:t[f[0].accessorKey]?(0,i.formatDate)(t[f[0].accessorKey],`short`):`—`}),p[0]&&t[p[0].accessorKey]!=null&&(0,y.jsx)(`span`,{className:`tabular-nums`,children:(0,i.formatPercent)(Number(t[p[0].accessorKey]))})]}),f.slice(1).map(e=>(0,y.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.header}),(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:t[e.accessorKey]?(0,i.formatDate)(t[e.accessorKey],`short`):`—`})]},e.accessorKey)),m.map(e=>{let n=t[e.accessorKey];return n==null||n===``?null:(0,y.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.header}),(0,y.jsx)(`span`,{className:`text-xs font-medium truncate ml-2 text-right`,children:e.cell?e.cell(n,t):String(n)})]},e.accessorKey)})]},t.id||t._id||r)})}),Y.isOverlay&&(0,y.jsx)(a.NavigationOverlay,{...Y,title:Ke,children:e=>(0,y.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,y.jsxs)(`div`,{className:`flex flex-col`,children:[(0,y.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,y.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})}let qe=()=>{ce(e=>e===`compact`?`short`:e===`short`?`medium`:e===`medium`?`tall`:e===`tall`?`extra_tall`:`compact`)},Je={compact:o.Rows4,short:o.Rows3,medium:o.Rows2,tall:o.AlignJustify,extra_tall:o.AlignJustify}[R],Ye=e.rowHeight!==void 0,Xe=e.exportOptions||Ye?(0,y.jsxs)(`div`,{className:`flex items-center justify-end gap-1 px-2 py-1`,children:[Ye&&(0,y.jsxs)(a.Button,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,onClick:qe,title:`Row height: ${R}`,children:[(0,y.jsx)(Je,{className:`h-3.5 w-3.5 mr-1.5`}),(0,y.jsx)(`span`,{className:`hidden sm:inline capitalize`,children:R})]}),e.exportOptions&&(0,y.jsxs)(a.Popover,{open:oe,onOpenChange:se,children:[(0,y.jsx)(a.PopoverTrigger,{asChild:!0,children:(0,y.jsxs)(a.Button,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,children:[(0,y.jsx)(o.Download,{className:`h-3.5 w-3.5 mr-1.5`}),(0,y.jsx)(`span`,{className:`hidden sm:inline`,children:E(`grid.export`)})]})}),(0,y.jsx)(a.PopoverContent,{align:`end`,className:`w-48 p-2`,children:(0,y.jsx)(`div`,{className:`space-y-1`,children:(e.exportOptions.formats||[`csv`,`json`]).map(e=>(0,y.jsxs)(a.Button,{variant:`ghost`,size:`sm`,className:`w-full justify-start h-8 text-xs`,onClick:()=>De(e),children:[(0,y.jsx)(o.Download,{className:`h-3.5 w-3.5 mr-2`}),E(`grid.exportAs`,{format:e.toUpperCase()})]},e))})})]})]}):null,Ze=e=>{let t=[`_id`,`id`,`created_at`,`updated_at`,`created_by`,`updated_by`],n=Object.entries(e),r=n.filter(([e])=>!t.includes(e)),o=n.filter(([e])=>t.includes(e)&&e!==`_id`&&e!==`id`),s=e=>e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `),c=(e,t)=>{if(t==null||t===``)return(0,y.jsx)(`span`,{className:`text-muted-foreground/50 text-sm italic`,children:`Empty`});let n=k?.fields?.[e];if(n?.type){let e=(0,i.getCellRenderer)(n.type);if(e)return(0,y.jsx)(e,{value:t,field:n})}return typeof t==`boolean`?(0,y.jsx)(a.Badge,{variant:t?`default`:`outline`,children:t?`Yes`:`No`}):typeof t==`string`&&!isNaN(Date.parse(t))&&(e.includes(`date`)||e.includes(`_at`)||e.includes(`time`))?(0,y.jsx)(`span`,{className:`text-sm tabular-nums`,children:(0,i.formatDate)(t)}):typeof t==`number`&&[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`].some(t=>e.toLowerCase().includes(t))?(0,y.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:(0,i.formatCurrency)(t)}):(0,y.jsx)(`span`,{className:`text-sm break-words`,children:String(t)})};return(0,y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`record-detail-panel`,children:[(0,y.jsx)(`div`,{className:`rounded-lg border bg-card`,children:(0,y.jsx)(`div`,{className:`divide-y`,children:r.map(([e,t])=>(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-4 px-4 py-3`,children:[(0,y.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground sm:w-1/3 sm:text-right sm:pt-0.5 uppercase tracking-wide shrink-0`,children:s(e)}),(0,y.jsx)(`div`,{className:`flex-1 min-w-0`,children:c(e,t)})]},e))})}),o.length>0&&(0,y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30`,children:[(0,y.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,y.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`System`})}),(0,y.jsx)(`div`,{className:`divide-y divide-border/50`,children:o.map(([e,t])=>(0,y.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2`,children:[(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground w-1/3 text-right shrink-0`,children:s(e)}),(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1 min-w-0 break-words`,children:String(t??``)})]},e))})]})]})},Qe=Ee?(0,y.jsx)(`div`,{className:`border-t bg-muted/30 px-2 py-1.5`,"data-testid":`column-summary-footer`,children:(0,y.jsx)(`div`,{className:`flex gap-4 text-xs text-muted-foreground font-medium`,children:Ie.filter(e=>Te.has(e.accessorKey)).map(e=>{let t=Te.get(e.accessorKey);return(0,y.jsxs)(`span`,{"data-testid":`summary-${e.accessorKey}`,children:[e.header,`: `,t.label]},e.accessorKey)})})}):null,$e=Ce?(0,y.jsx)(`div`,{className:`space-y-2`,children:Se.map(e=>(0,y.jsx)(O,{groupKey:e.key,label:e.label,count:e.rows.length,collapsed:e.collapsed,aggregations:e.aggregations,onToggle:we,children:(0,y.jsx)(r.SchemaRenderer,{schema:Ge(e.rows)})},e.key))}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(r.SchemaRenderer,{schema:We}),Qe]});return Y.isOverlay&&Y.mode===`split`?(0,y.jsx)(a.NavigationOverlay,{...Y,title:Ke,mainContent:(0,y.jsxs)(y.Fragment,{children:[Xe,$e,(0,y.jsx)(F,{selectedRows:le,actions:Re??[],onAction:(e,t)=>X({type:e,params:{records:t}}),onClearSelection:()=>ue([])})]}),children:e=>Ze(e)}):(0,y.jsxs)(`div`,{ref:me,className:`relative h-full`,children:[ge>0&&(0,y.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:ge},children:E(he?`grid.refreshing`:`grid.pullToRefresh`)}),Xe,$e,(0,y.jsx)(F,{selectedRows:le,actions:Re??[],onAction:(e,t)=>X({type:e,params:{records:t}}),onClearSelection:()=>ue([])}),Y.isOverlay&&(0,y.jsx)(a.NavigationOverlay,{...Y,title:Ke,children:e=>Ze(e)})]})};function L(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o;n.key&&n.debug?.call(n)&&(o=Date.now());let s=e();if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug?.call(n)&&(c=Date.now()),i=t(...s),n.key&&n.debug?.call(n)){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%c⏱ ${i(t,5)} /${i(e,5)} ms`,`
9
9
  font-size: .6rem;
10
10
  font-weight: bold;
11
- color: hsl(${Math.max(0,Math.min(120-120*T,120))}deg 100% 31%);`,t?.key)}return t?.onChange&&!(i&&t.skipInitialOnChange)&&t.onChange(n),i=!1,n}return a.updateDeps=l=>{s=l},a}function it(e,o){if(e===void 0)throw new Error("Unexpected undefined");return e}const Ut=(e,o)=>Math.abs(e-o)<1.01,Yt=(e,o,t)=>{let s;return function(...n){e.clearTimeout(s),s=e.setTimeout(()=>o.apply(this,n),t)}},lt=e=>{const{offsetWidth:o,offsetHeight:t}=e;return{width:o,height:t}},Jt=e=>e,Xt=e=>{const o=Math.max(e.startIndex-e.overscan,0),t=Math.min(e.endIndex+e.overscan,e.count-1),s=[];for(let n=o;n<=t;n++)s.push(n);return s},Qt=(e,o)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;const n=a=>{const{width:l,height:m}=a;o({width:Math.round(l),height:Math.round(m)})};if(n(lt(t)),!s.ResizeObserver)return()=>{};const i=new s.ResizeObserver(a=>{const l=()=>{const m=a[0];if(m?.borderBoxSize){const p=m.borderBoxSize[0];if(p){n({width:p.inlineSize,height:p.blockSize});return}}n(lt(t))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return i.observe(t,{box:"border-box"}),()=>{i.unobserve(t)}},ot={passive:!0},at=typeof window>"u"?!0:"onscrollend"in window,Zt=(e,o)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;let n=0;const i=e.options.useScrollendEvent&&at?()=>{}:Yt(s,()=>{o(n,!1)},e.options.isScrollingResetDelay),a=f=>()=>{const{horizontal:h,isRtl:g}=e.options;n=h?t.scrollLeft*(g&&-1||1):t.scrollTop,i(),o(n,f)},l=a(!0),m=a(!1);t.addEventListener("scroll",l,ot);const p=e.options.useScrollendEvent&&at;return p&&t.addEventListener("scrollend",m,ot),()=>{t.removeEventListener("scroll",l),p&&t.removeEventListener("scrollend",m)}},es=(e,o,t)=>{if(o?.borderBoxSize){const s=o.borderBoxSize[0];if(s)return Math.round(s[t.options.horizontal?"inlineSize":"blockSize"])}return e[t.options.horizontal?"offsetWidth":"offsetHeight"]},ts=(e,{adjustments:o=0,behavior:t},s)=>{var n,i;const a=e+o;(i=(n=s.scrollElement)==null?void 0:n.scrollTo)==null||i.call(n,{[s.options.horizontal?"left":"top"]:a,behavior:t})};class ss{constructor(o){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var t,s,n;return((n=(s=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:s.now)==null?void 0:n.call(s))??Date.now()},this.observer=(()=>{let t=null;const s=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(n=>{n.forEach(i=>{const a=()=>{this._measureElement(i.target,i)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var n;(n=s())==null||n.disconnect(),t=null},observe:n=>{var i;return(i=s())==null?void 0:i.observe(n,{box:"border-box"})},unobserve:n=>{var i;return(i=s())==null?void 0:i.unobserve(n)}}})(),this.range=null,this.setOptions=t=>{Object.entries(t).forEach(([s,n])=>{typeof n>"u"&&delete t[s]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Jt,rangeExtractor:Xt,onChange:()=>{},measureElement:es,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...t}},this.notify=t=>{var s,n;(n=(s=this.options).onChange)==null||n.call(s,this,t)},this.maybeNotify=Ne(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:process.env.NODE_ENV!=="production"&&"maybeNotify",debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(n=>{this.observer.observe(n)}),this.unsubs.push(this.options.observeElementRect(this,n=>{this.scrollRect=n,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(n,i)=>{this.scrollAdjustments=0,this.scrollDirection=i?this.getScrollOffset()<n?"forward":"backward":null,this.scrollOffset=n,this.isScrolling=i,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(t,s)=>{const n=new Map,i=new Map;for(let a=s-1;a>=0;a--){const l=t[a];if(n.has(l.lane))continue;const m=i.get(l.lane);if(m==null||l.end>m.end?i.set(l.lane,l):l.end<m.end&&n.set(l.lane,!0),n.size===this.options.lanes)break}return i.size===this.options.lanes?Array.from(i.values()).sort((a,l)=>a.end===l.end?a.index-l.index:a.end-l.end)[0]:void 0},this.getMeasurementOptions=Ne(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(t,s,n,i,a,l)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMeasuredCacheIndexes=[],{count:t,paddingStart:s,scrollMargin:n,getItemKey:i,enabled:a,lanes:l}),{key:!1}),this.getMeasurements=Ne(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:t,paddingStart:s,scrollMargin:n,getItemKey:i,enabled:a,lanes:l},m)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const g of this.laneAssignments.keys())g>=t&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const p=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1);const f=this.measurementsCache.slice(0,p),h=new Array(l).fill(void 0);for(let g=0;g<p;g++){const b=f[g];b&&(h[b.lane]=g)}for(let g=p;g<t;g++){const b=i(g),w=this.laneAssignments.get(g);let C,T;if(w!==void 0&&this.options.lanes>1){C=w;const Y=h[C],q=Y!==void 0?f[Y]:void 0;T=q?q.end+this.options.gap:s+n}else{const Y=this.options.lanes===1?f[g-1]:this.getFurthestMeasurement(f,g);T=Y?Y.end+this.options.gap:s+n,C=Y?Y.lane:g%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(g,C)}const D=m.get(b),z=typeof D=="number"?D:this.options.estimateSize(g),P=T+z;f[g]={index:g,start:T,size:z,end:P,key:b,lane:C},h[C]=g}return this.measurementsCache=f,f},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=Ne(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,s,n,i)=>this.range=t.length>0&&s>0?rs({measurements:t,outerSize:s,scrollOffset:n,lanes:i}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=Ne(()=>{let t=null,s=null;const n=this.calculateRange();return n&&(t=n.startIndex,s=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,s]},(t,s,n,i,a)=>i===null||a===null?[]:t({startIndex:i,endIndex:a,overscan:s,count:n}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=t=>{const s=this.options.indexAttribute,n=t.getAttribute(s);return n?parseInt(n,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const n=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(n!==void 0&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),a=Math.max(0,n-i),l=Math.min(this.options.count-1,n+i);return t>=a&&t<=l}return!0},this._measureElement=(t,s)=>{if(!t.isConnected){this.observer.unobserve(t);return}const n=this.indexFromElement(t),i=this.measurementsCache[n];if(!i)return;const a=i.key,l=this.elementsCache.get(a);l!==t&&(l&&this.observer.unobserve(l),this.observer.observe(t),this.elementsCache.set(a,t)),this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,s,this))},this.resizeItem=(t,s)=>{var n;const i=this.measurementsCache[t];if(!i)return;const a=this.itemSizeCache.get(i.key)??i.size,l=s-a;l!==0&&(((n=this.scrollState)==null?void 0:n.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(i,l,this):i.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",l),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=l,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(i.index),this.itemSizeCache=new Map(this.itemSizeCache.set(i.key,s)),this.notify(!1))},this.measureElement=t=>{if(!t){this.elementsCache.forEach((s,n)=>{s.isConnected||(this.observer.unobserve(s),this.elementsCache.delete(n))});return}this._measureElement(t,void 0)},this.getVirtualItems=Ne(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,s)=>{const n=[];for(let i=0,a=t.length;i<a;i++){const l=t[i],m=s[l];n.push(m)}return n},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const s=this.getMeasurements();if(s.length!==0)return it(s[ct(0,s.length-1,n=>it(s[n]).start,t)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(t,s,n=0)=>{if(!this.scrollElement)return 0;const i=this.getSize(),a=this.getScrollOffset();s==="auto"&&(s=t>=a+i?"end":"start"),s==="center"?t+=(n-i)/2:s==="end"&&(t-=i);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,t),0)},this.getOffsetForIndex=(t,s="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const n=this.getSize(),i=this.getScrollOffset(),a=this.measurementsCache[t];if(!a)return;if(s==="auto")if(a.end>=i+n-this.options.scrollPaddingEnd)s="end";else if(a.start<=i+this.options.scrollPaddingStart)s="start";else return[i,s];if(s==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),s];const l=s==="end"?a.end+this.options.scrollPaddingEnd:a.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,s,a.size),s]},this.scrollToOffset=(t,{align:s="start",behavior:n="auto"}={})=>{const i=this.getOffsetForAlignment(t,s),a=this.now();this.scrollState={index:null,align:s,behavior:n,startedAt:a,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:s="auto",behavior:n="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const i=this.getOffsetForIndex(t,s);if(!i)return;const[a,l]=i,m=this.now();this.scrollState={index:t,align:l,behavior:n,startedAt:m,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:s="auto"}={})=>{const n=this.getScrollOffset()+t,i=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:i,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var t;const s=this.getMeasurements();let n;if(s.length===0)n=this.options.paddingStart;else if(this.options.lanes===1)n=((t=s[s.length-1])==null?void 0:t.end)??0;else{const i=Array(this.options.lanes).fill(null);let a=s.length-1;for(;a>=0&&i.some(l=>l===null);){const l=s[a];i[l.lane]===null&&(i[l.lane]=l.end),a--}n=Math.max(...i.filter(l=>l!==null))}return Math.max(n-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(t,{adjustments:s,behavior:n})=>{this.options.scrollToFn(t,{behavior:n,adjustments:s},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(o)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,n=s?s[0]:this.scrollState.lastTargetOffset,i=1,a=n!==this.scrollState.lastTargetOffset;if(!a&&Ut(n,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=i){this.scrollState=null;return}}else this.scrollState.stableFrames=0,a&&(this.scrollState.lastTargetOffset=n,this.scrollState.behavior="auto",this._scrollToOffset(n,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const ct=(e,o,t,s)=>{for(;e<=o;){const n=(e+o)/2|0,i=t(n);if(i<s)e=n+1;else if(i>s)o=n-1;else return n}return e>0?e-1:0};function rs({measurements:e,outerSize:o,scrollOffset:t,lanes:s}){const n=e.length-1,i=m=>e[m].start;if(e.length<=s)return{startIndex:0,endIndex:n};let a=ct(0,n,i,t),l=a;if(s===1)for(;l<n&&e[l].end<t+o;)l++;else if(s>1){const m=Array(s).fill(0);for(;l<n&&m.some(f=>f<t+o);){const f=e[l];m[f.lane]=f.end,l++}const p=Array(s).fill(t+o);for(;a>=0&&p.some(f=>f>=t);){const f=e[a];p[f.lane]=f.start,a--}a=Math.max(0,a-a%s),l=Math.min(n,l+(s-1-l%s))}return{startIndex:a,endIndex:l}}const dt=typeof document<"u"?Fe.useLayoutEffect:Fe.useEffect;function ns({useFlushSync:e=!0,...o}){const t=Fe.useReducer(()=>({}),{})[1],s={...o,onChange:(i,a)=>{var l;e&&a?_t.flushSync(t):t(),(l=o.onChange)==null||l.call(o,i,a)}},[n]=Fe.useState(()=>new ss(s));return n.setOptions(s),dt(()=>n._didMount(),[]),dt(()=>n._willUpdate()),n}function is(e){return ns({observeElementRect:Qt,observeElementOffset:Zt,scrollToFn:ts,...e})}const ls=({data:e,columns:o,rowHeight:t=40,height:s=600,className:n="",headerClassName:i="",rowClassName:a,onRowClick:l,overscan:m=5})=>{const p=u.useRef(null),f=is({count:e.length,getScrollElement:()=>p.current,estimateSize:()=>t,overscan:m}),h=f.getVirtualItems();return r.jsxs("div",{className:n,children:[r.jsx("div",{className:`grid border-b sticky top-0 bg-muted/30 z-10 ${i}`,style:{gridTemplateColumns:o.map(g=>g.width||"1fr").join(" ")},children:o.map((g,b)=>r.jsx("div",{className:`px-4 py-2 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/70 ${g.align==="center"?"text-center":g.align==="right"?"text-right":"text-left"}`,children:g.header},b))}),r.jsx("div",{ref:p,className:"overflow-auto",style:{height:typeof s=="number"?`${s}px`:s,contain:"strict"},children:r.jsx("div",{style:{height:`${f.getTotalSize()}px`,width:"100%",position:"relative"},children:h.map(g=>{const b=e[g.index],w=typeof a=="function"?a(b,g.index):a||"";return r.jsx("div",{className:`grid border-b hover:bg-muted/50 cursor-pointer ${w}`,style:{position:"absolute",top:0,left:0,width:"100%",height:`${g.size}px`,transform:`translateY(${g.start}px)`,gridTemplateColumns:o.map(C=>C.width||"1fr").join(" ")},onClick:()=>l?.(b,g.index),children:o.map((C,T)=>{const D=b[C.accessorKey],z=C.cell?C.cell(D,b):D;return r.jsx("div",{className:`px-4 py-2 text-sm flex items-center ${C.align==="center"?"text-center justify-center":C.align==="right"?"text-right justify-end":"text-left justify-start"}`,children:z},T)})},g.key)})})}),r.jsxs("div",{className:"px-4 py-2 text-xs text-muted-foreground border-t",children:["Showing ",h.length," of ",e.length," rows (virtual scrolling enabled)"]})]})},os=10;function as(e){const o=[];let t=[],s="",n=!1;for(let i=0;i<e.length;i++){const a=e[i],l=e[i+1];n?a==='"'&&l==='"'?(s+='"',i++):a==='"'?n=!1:s+=a:a==='"'?n=!0:a===","?(t.push(s.trim()),s=""):a===`
12
- `||a==="\r"&&l===`
13
- `?(t.push(s.trim()),t.some(m=>m!=="")&&o.push(t),t=[],s="",a==="\r"&&i++):s+=a}return t.push(s.trim()),t.some(i=>i!=="")&&o.push(t),o}function ut(e,o){if(!e)return!0;switch(o){case"number":case"currency":case"percent":return!isNaN(Number(e));case"boolean":return["true","false","1","0","yes","no"].includes(e.toLowerCase());case"date":case"datetime":return!isNaN(Date.parse(e));default:return!0}}function cs(e,o){const t={};return e.forEach((s,n)=>{const i=s.toLowerCase().replace(/[_\s-]/g,""),a=o.find(l=>{const m=l.name.toLowerCase().replace(/[_\s-]/g,""),p=l.label.toLowerCase().replace(/[_\s-]/g,"");return m===i||p===i});a&&(t[n]=a.name)}),t}function ds(e,o,t){const s=[],n={};for(const i of o){const a=e[i.csvIdx]??"";if(i.field.required&&!a){s.push({row:t,field:i.field.name,message:"Required field is empty"});continue}if(a&&!ut(a,i.field.type)){s.push({row:t,field:i.field.name,message:`Invalid ${i.field.type} value: "${a}"`});continue}n[i.field.name]=a}return{record:n,errors:s}}const us=({onFileLoaded:e})=>{const[o,t]=u.useState(!1),[s,n]=u.useState(null),i=u.useCallback(a=>{if(n(null),!a.name.endsWith(".csv")){n("Only CSV files are supported.");return}const l=new FileReader;l.onload=m=>{const p=as(m.target?.result);if(p.length<2){n("File must contain a header row and at least one data row.");return}e(p[0],p.slice(1))},l.readAsText(a)},[e]);return r.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[r.jsxs("div",{className:v.cn("flex w-full flex-col items-center justify-center gap-3 rounded-lg border-2 border-dashed p-10 transition-colors",o?"border-primary bg-primary/5":"border-muted-foreground/25"),onDragOver:a=>{a.preventDefault(),t(!0)},onDragLeave:()=>t(!1),onDrop:a=>{a.preventDefault(),t(!1);const l=a.dataTransfer.files[0];l&&i(l)},children:[r.jsx(I.Upload,{className:"h-10 w-10 text-muted-foreground"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Drag & drop a CSV file here, or click to browse"}),r.jsxs("label",{children:[r.jsx("input",{type:"file",accept:".csv",className:"hidden",onChange:a=>{const l=a.target.files?.[0];l&&i(l)}}),r.jsx(v.Button,{variant:"outline",size:"sm",asChild:!0,children:r.jsx("span",{children:"Browse Files"})})]})]}),s&&r.jsxs("p",{className:"flex items-center gap-1 text-sm text-destructive",children:[r.jsx(I.AlertCircle,{className:"h-4 w-4"})," ",s]})]})},fs=({headers:e,fields:o,mapping:t,onMappingChange:s})=>{const n=u.useMemo(()=>new Set(Object.values(t)),[t]),i=u.useCallback((a,l)=>{const m={...t};l==="__skip__"?delete m[a]:m[a]=l,s(m)},[t,s]);return r.jsx("div",{className:"max-h-[360px] overflow-auto",children:r.jsxs(v.Table,{children:[r.jsx(v.TableHeader,{children:r.jsxs(v.TableRow,{children:[r.jsx(v.TableHead,{children:"CSV Column"}),r.jsx(v.TableHead,{children:"Maps To"}),r.jsx(v.TableHead,{className:"w-24 text-center",children:"Status"})]})}),r.jsx(v.TableBody,{children:e.map((a,l)=>r.jsxs(v.TableRow,{children:[r.jsx(v.TableCell,{className:"font-medium",children:a}),r.jsx(v.TableCell,{children:r.jsxs(v.Select,{value:t[l]??"__skip__",onValueChange:m=>i(l,m),children:[r.jsx(v.SelectTrigger,{className:"h-8 w-56",children:r.jsx(v.SelectValue,{placeholder:"Skip column"})}),r.jsxs(v.SelectContent,{children:[r.jsx(v.SelectItem,{value:"__skip__",children:"— Skip —"}),o.map(m=>r.jsxs(v.SelectItem,{value:m.name,disabled:n.has(m.name)&&t[l]!==m.name,children:[m.label,m.required?" *":""]},m.name))]})]})}),r.jsx(v.TableCell,{className:"text-center",children:t[l]?r.jsx(v.Badge,{variant:"default",className:"text-xs",children:"Mapped"}):r.jsx(v.Badge,{variant:"secondary",className:"text-xs",children:"Skipped"})})]},l))})]})})},hs=({headers:e,rows:o,mapping:t,fields:s})=>{const n=u.useMemo(()=>Object.entries(t).map(([m,p])=>({csvIdx:Number(m),header:e[Number(m)],field:s.find(f=>f.name===p)})),[t,e,s]),i=o.slice(0,os),a=u.useMemo(()=>i.map((m,p)=>{const f={};for(const h of n){const g=m[h.csvIdx]??"";h.field.required&&!g?f[h.csvIdx]="Required":g&&!ut(g,h.field.type)&&(f[h.csvIdx]=`Invalid ${h.field.type}`)}return f}),[i,n]),l=a.filter(m=>Object.keys(m).length>0).length;return r.jsxs("div",{className:"max-h-[360px] overflow-auto",children:[l>0&&r.jsxs("p",{className:"mb-2 flex items-center gap-1 text-xs text-destructive",children:[r.jsx(I.AlertCircle,{className:"h-3.5 w-3.5"})," ",l," row(s) with errors in preview"]}),r.jsxs(v.Table,{children:[r.jsx(v.TableHeader,{children:r.jsxs(v.TableRow,{children:[r.jsx(v.TableHead,{className:"w-12",children:"#"}),n.map(m=>r.jsx(v.TableHead,{children:m.field.label},m.csvIdx))]})}),r.jsx(v.TableBody,{children:i.map((m,p)=>{const f=a[p],h=Object.keys(f).length>0;return r.jsxs(v.TableRow,{className:v.cn(h&&"bg-destructive/5"),children:[r.jsx(v.TableCell,{className:"text-xs text-muted-foreground",children:p+1}),n.map(g=>{const b=m[g.csvIdx]??"",w=f[g.csvIdx];return r.jsx(v.TableCell,{className:v.cn(w&&"text-destructive"),title:w,children:b||r.jsx("span",{className:"text-muted-foreground/50",children:"—"})},g.csvIdx)})]},p)})})]}),r.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Showing ",i.length," of ",o.length," rows"]})]})},ft=({objectName:e,objectLabel:o,fields:t,dataSource:s,onComplete:n,onCancel:i,open:a,onOpenChange:l,onErrorMode:m="skip"})=>{const[p,f]=u.useState("upload"),[h,g]=u.useState([]),[b,w]=u.useState([]),[C,T]=u.useState({}),[D,z]=u.useState(!1),[P,Y]=u.useState(0),[q,J]=u.useState(null),oe=o??e,Me=u.useMemo(()=>{const V=new Set(Object.values(C));return t.filter(Q=>Q.required&&!V.has(Q.name))},[t,C]),ve=u.useCallback((V,Q)=>{g(V),w(Q),T(cs(V,t)),f("mapping")},[t]),Ee=u.useCallback(async()=>{z(!0),Y(0);const V=[];let Q=0,he=0;const ae=Object.entries(C).map(([re,be])=>({csvIdx:Number(re),field:t.find(xe=>xe.name===be)}));for(let re=0;re<b.length;re++){const{record:be,errors:xe}=ds(b[re],ae,re+1);if(xe.length>0){if(he++,V.push(...xe),m==="stop")break}else try{s?.create&&await s.create(e,be),Q++}catch(d){he++;const A=d instanceof Error?d.message:"Failed to create record";if(V.push({row:re+1,field:"",message:A}),m==="stop")break}Y(Math.round((re+1)/b.length*100))}const je={totalRows:b.length,importedRows:Q,skippedRows:he,errors:V};J(je),z(!1),n?.(je)},[b,C,t,s,e,n,m]),de=u.useCallback(()=>{f("upload"),g([]),w([]),T({}),Y(0),J(null)},[]),ge=u.useCallback(()=>{de(),l?.(!1),i?.()},[de,l,i]);return r.jsx(v.Dialog,{open:a,onOpenChange:V=>{V?l?.(V):ge()},children:r.jsxs(v.DialogContent,{className:"sm:max-w-2xl",children:[r.jsxs(v.DialogHeader,{children:[r.jsxs(v.DialogTitle,{className:"flex items-center gap-2",children:[r.jsx(I.FileSpreadsheet,{className:"h-5 w-5"})," Import ",oe]}),r.jsxs(v.DialogDescription,{children:[p==="upload"&&"Upload a CSV file to get started.",p==="mapping"&&"Map CSV columns to object fields.",p==="preview"&&"Review data before importing."]})]}),r.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:["upload","mapping","preview"].map((V,Q)=>r.jsxs(u.Fragment,{children:[Q>0&&r.jsx(I.ArrowRight,{className:"h-3 w-3"}),r.jsxs("span",{className:v.cn("rounded-full px-3 py-1",p===V?"bg-primary text-primary-foreground":"bg-muted"),children:[Q+1,". ",V==="upload"?"Upload":V==="mapping"?"Mapping":"Preview"]})]},V))}),q?r.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[r.jsx(I.CheckCircle2,{className:"h-10 w-10 text-green-500"}),r.jsx("p",{className:"text-lg font-semibold",children:"Import Complete"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsxs(v.Badge,{variant:"default",children:[q.importedRows," imported"]}),q.skippedRows>0&&r.jsxs(v.Badge,{variant:"destructive",children:[q.skippedRows," skipped"]})]}),q.errors.length>0&&r.jsxs("div",{className:"max-h-32 w-full overflow-auto rounded border p-2 text-xs",children:[q.errors.slice(0,10).map((V,Q)=>r.jsxs("p",{className:"text-destructive",children:["Row ",V.row,V.field?` (${V.field})`:"",": ",V.message]},Q)),q.errors.length>10&&r.jsxs("p",{className:"text-muted-foreground",children:["…and ",q.errors.length-10," more errors"]})]})]}):r.jsxs(r.Fragment,{children:[p==="upload"&&r.jsx(us,{onFileLoaded:ve}),p==="mapping"&&r.jsx(fs,{headers:h,fields:t,mapping:C,onMappingChange:T}),p==="preview"&&r.jsx(hs,{headers:h,rows:b,mapping:C,fields:t}),D&&r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx(v.Progress,{value:P,className:"h-2"}),r.jsxs("p",{className:"text-center text-xs text-muted-foreground",children:["Importing… ",P,"%"]})]})]}),r.jsx(v.DialogFooter,{className:"gap-2 sm:gap-0",children:q?r.jsx(v.Button,{onClick:ge,children:"Close"}):r.jsxs(r.Fragment,{children:[r.jsxs(v.Button,{variant:"ghost",onClick:ge,disabled:D,children:[r.jsx(I.X,{className:"mr-1 h-4 w-4"})," Cancel"]}),(p==="mapping"||p==="preview")&&r.jsxs(v.Button,{variant:"outline",onClick:()=>f(p==="mapping"?"upload":"mapping"),disabled:D,children:[r.jsx(I.ArrowLeft,{className:"mr-1 h-4 w-4"})," Back"]}),p==="mapping"&&r.jsxs(v.Button,{onClick:()=>f("preview"),disabled:Object.keys(C).length===0||Me.length>0,children:["Next ",r.jsx(I.ArrowRight,{className:"ml-1 h-4 w-4"})]}),p==="preview"&&r.jsx(v.Button,{onClick:Ee,disabled:D,children:D?"Importing…":`Import ${b.length} Rows`})]})})]})})};function ms({value:e,onSave:o,onCancel:t,validate:s,type:n="text",placeholder:i,editing:a=!1,className:l,disabled:m=!1}){const[p,f]=u.useState(a),[h,g]=u.useState(String(e??"")),[b,w]=u.useState(),[C,T]=u.useState(!1),D=u.useRef(null);u.useEffect(()=>{p||g(String(e??""))},[e,p]),u.useEffect(()=>{p&&D.current&&(D.current.focus(),D.current.select())},[p]);const z=u.useCallback(()=>{m||(f(!0),g(String(e??"")),w(void 0))},[m,e]),P=u.useCallback(()=>{f(!1),g(String(e??"")),w(void 0),t?.()},[e,t]),Y=u.useCallback(async()=>{if(s){const oe=s(h);if(oe){w(oe);return}}const J=n==="number"?Number(h):h;T(!0);try{const oe=await o(J);if(typeof oe=="string"){w(oe),T(!1);return}f(!1),w(void 0)}catch(oe){w(oe?.message||"Save failed")}finally{T(!1)}},[h,s,n,o]),q=u.useCallback(J=>{J.key==="Enter"?(J.preventDefault(),Y()):J.key==="Escape"&&(J.preventDefault(),P())},[Y,P]);return p?r.jsxs("div",{"data-slot":"inline-editing",className:v.cn("relative flex items-center gap-1",l),children:[r.jsxs("div",{className:"flex-1 relative",children:[r.jsx("input",{ref:D,"data-slot":"inline-editing-input",type:n,value:h,onChange:J=>{g(J.target.value),b&&w(void 0)},onKeyDown:q,placeholder:i,disabled:C,"aria-invalid":!!b,"aria-describedby":b?"inline-editing-error":void 0,className:v.cn("w-full rounded border px-2 py-1 text-sm outline-none transition-colors","focus:ring-2 focus:ring-ring focus:border-input",b?"border-destructive focus:ring-destructive/30":"border-input",C&&"opacity-50")}),b&&r.jsx("p",{id:"inline-editing-error","data-slot":"inline-editing-error",className:"absolute left-0 top-full mt-0.5 text-xs text-destructive",role:"alert",children:b})]}),r.jsx("button",{"data-slot":"inline-editing-save",type:"button",onClick:Y,disabled:C,"aria-label":"Save",className:v.cn("inline-flex h-6 w-6 items-center justify-center rounded text-primary hover:bg-primary/10 transition-colors",C&&"opacity-50 cursor-not-allowed"),children:r.jsx(I.Check,{className:"h-3.5 w-3.5"})}),r.jsx("button",{"data-slot":"inline-editing-cancel",type:"button",onClick:P,disabled:C,"aria-label":"Cancel",className:"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors",children:r.jsx(I.X,{className:"h-3.5 w-3.5"})})]}):r.jsx("div",{"data-slot":"inline-editing",className:v.cn("group relative cursor-pointer rounded px-2 py-1 hover:bg-muted/50 transition-colors min-h-[1.75rem] flex items-center",m&&"cursor-default opacity-60",l),onClick:z,role:"button",tabIndex:m?-1:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),z())},"aria-label":`Edit value: ${String(e??"")}`,children:r.jsx("span",{"data-slot":"inline-editing-display",className:"truncate text-sm",children:e!=null&&String(e)!==""?String(e):r.jsx("span",{className:"text-muted-foreground italic",children:i||"Click to edit"})})})}function ht(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function ps({data:e,columns:o,onPaste:t,enabled:s=!0}){const[n,i]=u.useState(null),a=u.useCallback(()=>{if(!s||!n)return;const{startRow:p,startCol:f,endRow:h,endCol:g}=ht(n),b=[];for(let C=p;C<=h;C++){const T=e[C];if(!T)continue;const D=[];for(let z=f;z<=g;z++){const P=o[z];D.push(P?String(T[P]??""):"")}b.push(D.join(" "))}const w=b.join(`
14
- `);navigator.clipboard.writeText(w)},[s,n,e,o]),l=u.useCallback(()=>{if(!s||!n||!t)return;const{startRow:p,startCol:f}=ht(n);navigator.clipboard.readText().then(h=>{const g=[],b=h.split(`
15
- `);for(let w=0;w<b.length;w++){const C=b[w].split(" ");for(let T=0;T<C.length;T++){const D=p+w,z=f+T,P=o[z];P&&D<e.length&&g.push({rowIndex:D,field:P,value:C[T]})}}g.length>0&&t(g)})},[s,n,o,e.length,t]),m=u.useCallback(p=>{if(!s)return;const f=p.metaKey||p.ctrlKey;f&&p.key==="c"?(p.preventDefault(),a()):f&&p.key==="v"&&(p.preventDefault(),l())},[s,a,l]);return u.useEffect(()=>{s||i(null)},[s]),{selectedRange:n,setSelectedRange:i,onCopy:a,onPaste:l,onKeyDown:m}}const gs=[{position:0,className:"bg-green-100"},{position:.5,className:"bg-yellow-100"},{position:1,className:"bg-red-100"}];function xs(e,o){let t=1/0,s=-1/0;for(const n of e){const i=Number(n[o]);Number.isFinite(i)&&(i<t&&(t=i),i>s&&(s=i))}return Number.isFinite(t)?[t,s]:[0,0]}function bs(e,o){if(o.length===0)return"";if(o.length===1)return o[0].className;let t=o[0],s=Math.abs(e-t.position);for(let n=1;n<o.length;n++){const i=Math.abs(e-o[n].position);i<s&&(t=o[n],s=i)}return t.className}function ys(e){const{field:o,data:t,min:s,max:n,stops:i=gs}=e,[a,l]=u.useMemo(()=>xs(t,o),[t,o]),m=s??a,p=n??l;return u.useCallback(f=>{const h=Number(f[o]);if(!Number.isFinite(h))return;if(p===m)return i.length>0?i[0].className:void 0;const g=Math.max(0,Math.min(1,(h-m)/(p-m)));return bs(g,i)},[o,m,p,i])}const mt="text/x-group-key";function vs({groupKeys:e}){const[o,t]=u.useState(e),[s,n]=u.useState(null);u.useEffect(()=>{t(f=>{const h=new Set(f),g=new Set(e);if(f.length===e.length&&f.every((C,T)=>C===e[T]))return f;const b=f.filter(C=>g.has(C)),w=e.filter(C=>!h.has(C));return[...b,...w]})},[e]);const i=u.useCallback((f,h)=>{t(g=>{if(f<0||f>=g.length||h<0||h>=g.length||f===h)return g;const b=[...g],[w]=b.splice(f,1);return b.splice(h,0,w),b})},[]),a=u.useCallback((f,h)=>{f.dataTransfer.effectAllowed="move",f.dataTransfer.setData(mt,h),n(h)},[]),l=u.useCallback(f=>{f.preventDefault(),f.dataTransfer.dropEffect="move"},[]),m=u.useCallback((f,h)=>{f.preventDefault();const g=f.dataTransfer.getData(mt);!g||g===h||t(b=>{const w=b.indexOf(g),C=b.indexOf(h);if(w===-1||C===-1)return b;const T=[...b],[D]=T.splice(w,1);return T.splice(C,0,D),T})},[]),p=u.useCallback(()=>{n(null)},[]);return{groupOrder:o,moveGroup:i,onDragStart:a,onDragOver:l,onDrop:m,onDragEnd:p,draggingKey:s}}function js({value:e,onChange:o,onConfirm:t,onCancel:s,activeCell:n,disabled:i=!1,className:a}){const[l,m]=u.useState(!1),[p,f]=u.useState(e),h=u.useRef(null);u.useEffect(()=>{l||f(e)},[e,l]),u.useEffect(()=>{l&&h.current&&(h.current.focus(),h.current.select())},[l]);const g=u.useCallback(()=>{i||(m(!0),f(e))},[i,e]),b=u.useCallback(()=>{m(!1),o?.(p),t?.(p)},[p,o,t]),w=u.useCallback(()=>{m(!1),f(e),s?.()},[e,s]),C=u.useCallback(T=>{T.key==="Enter"?(T.preventDefault(),b()):T.key==="Escape"&&(T.preventDefault(),w())},[b,w]);return r.jsxs("div",{className:v.cn("flex items-center gap-2 border-b border-border bg-muted/30 px-3 py-1.5",a),children:[r.jsx(I.FunctionSquare,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),n&&r.jsx("span",{className:"min-w-[4rem] shrink-0 rounded bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground",children:n}),r.jsx("input",{ref:h,type:"text",value:l?p:e,readOnly:!l,disabled:i,onClick:g,onChange:T=>f(T.target.value),onKeyDown:C,className:v.cn("flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground",l&&"rounded ring-1 ring-ring px-1",i&&"cursor-not-allowed opacity-50")}),l&&r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:b,className:"rounded p-0.5 text-green-600 hover:bg-green-100","aria-label":"Confirm",children:r.jsx(I.Check,{className:"h-4 w-4"})}),r.jsx("button",{type:"button",onClick:w,className:"rounded p-0.5 text-red-600 hover:bg-red-100","aria-label":"Cancel",children:r.jsx(I.X,{className:"h-4 w-4"})})]})]})}function ws({frozenWidth:e,onResize:o,minFrozenWidth:t=100,minScrollableWidth:s=200,left:n,right:i,className:a}){const l=u.useRef(null),[m,p]=u.useState(e),f=u.useRef(!1),h=u.useRef(0),g=u.useRef(0),b=o?e:m,w=u.useCallback(C=>{C.preventDefault(),f.current=!0,h.current=C.clientX,g.current=b;const T=z=>{if(!f.current||!l.current)return;const P=l.current.offsetWidth,Y=z.clientX-h.current;let q=g.current+Y;q=Math.max(q,t),q=Math.min(q,P-s),o?o(q):p(q)},D=()=>{f.current=!1,document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",D)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",D)},[b,t,s,o]);return r.jsxs("div",{ref:l,className:v.cn("flex h-full w-full overflow-hidden",a),children:[r.jsx("div",{className:"shrink-0 overflow-auto",style:{width:b},children:n}),r.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:w,className:v.cn("flex w-2 cursor-col-resize items-center justify-center","border-x border-border bg-muted/50 hover:bg-muted","transition-colors"),children:r.jsx(I.GripVertical,{className:"h-4 w-4 text-muted-foreground"})}),r.jsx("div",{className:"min-w-0 flex-1 overflow-auto",children:i})]})}const Ge=({schema:e,...o})=>{const{dataSource:t}=pe.useSchemaContext()||{};return r.jsx(nt,{schema:e,dataSource:t,...o})};_e.ComponentRegistry.register("object-grid",Ge,{namespace:"plugin-grid",label:"Object Grid",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filters",type:"array",label:"Filters"}]}),_e.ComponentRegistry.register("grid",Ge,{namespace:"view",label:"Data Grid",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filters",type:"array",label:"Filters"}]});const Cs=({schema:e,...o})=>{const{dataSource:t}=pe.useSchemaContext()||{};return r.jsx(ft,{objectName:e.objectName,objectLabel:e.objectLabel,fields:e.fields??[],dataSource:t,...o})};_e.ComponentRegistry.register("import-wizard",Cs,{namespace:"plugin-grid",label:"Import Wizard",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields",required:!0}]}),L.BulkActionBar=We,L.FormulaBar=js,L.GroupRow=et,L.ImportWizard=ft,L.InlineEditing=ms,L.ObjectGrid=nt,L.ObjectGridRenderer=Ge,L.RowActionMenu=st,L.SplitPaneGrid=ws,L.VirtualGrid=ls,L.formatActionLabel=Le,L.useCellClipboard=ps,L.useColumnSummary=tt,L.useGradientColor=ys,L.useGroupReorder=vs,L.useGroupedData=Ze,L.useRowColor=Qe,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
11
+ color: hsl(${Math.max(0,Math.min(120-120*r,120))}deg 100% 31%);`,n?.key)}return n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i}return o.updateDeps=e=>{r=e},o}function oe(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var se=(e,t)=>Math.abs(e-t)<1.01,R=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},ce=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},le=e=>e,ue=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),r=[];for(let e=t;e<=n;e++)r.push(e);return r},de=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(ce(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(ce(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},z={passive:!0},fe=typeof window>`u`?!0:`onscrollend`in window,pe=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=0,a=e.options.useScrollendEvent&&fe?()=>void 0:R(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=r=>()=>{let{horizontal:o,isRtl:s}=e.options;i=o?n.scrollLeft*(s&&-1||1):n.scrollTop,a(),t(i,r)},s=o(!0),c=o(!1);n.addEventListener(`scroll`,s,z);let l=e.options.useScrollendEvent&&fe;return l&&n.addEventListener(`scrollend`,c,z),()=>{n.removeEventListener(`scroll`,s),l&&n.removeEventListener(`scrollend`,c)}},me=(e,t,n)=>{if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},he=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;let o=e+t;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:o,behavior:n})},ge=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,n])=>{n===void 0&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:le,rangeExtractor:ue,onChange:()=>{},measureElement:me,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...e}},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=L(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:process.env.NODE_ENV!==`production`&&`maybeNotify`,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=L(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(e,t,n,r,i,a)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a}),{key:!1}),this.getMeasurements=L(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a},o)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let s=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1);let c=this.measurementsCache.slice(0,s),l=Array(a).fill(void 0);for(let e=0;e<s;e++){let t=c[e];t&&(l[t.lane]=e)}for(let i=s;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,u;if(a!==void 0&&this.options.lanes>1){s=a;let e=l[s],r=e===void 0?void 0:c[e];u=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?c[i-1]:this.getFurthestMeasurement(c,i);u=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(i,s)}let d=o.get(e),f=typeof d==`number`?d:this.options.estimateSize(i),p=u+f;c[i]={index:i,start:u,size:f,end:p,key:e,lane:s},l[s]=i}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!==`production`&&`getMeasurements`,debug:()=>this.options.debug}),this.calculateRange=L(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?V({measurements:e,outerSize:t,scrollOffset:n,lanes:r}):null,{key:process.env.NODE_ENV!==`production`&&`calculateRange`,debug:()=>this.options.debug}),this.getVirtualIndexes=L(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:process.env.NODE_ENV!==`production`&&`getVirtualIndexes`,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{let n=this.measurementsCache[e];if(!n)return;let r=t-(this.itemSizeCache.get(n.key)??n.size);r!==0&&(this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?n.start<this.getScrollOffset()+this.scrollAdjustments:this.shouldAdjustScrollPositionOnItemSizeChange(n,r,this))&&(process.env.NODE_ENV!==`production`&&this.options.debug&&console.info(`correction`,r),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=r,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,t)),this.notify(!1))},this.getVirtualItems=L(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:process.env.NODE_ENV!==`production`&&`getVirtualItems`,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length!==0)return oe(t[B(0,t.length-1,e=>oe(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t);this.scrollState={index:null,align:t,behavior:n,startedAt:this.now(),lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e;this.scrollState={index:null,align:`start`,behavior:t,startedAt:this.now(),lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1)t=e[e.length-1]?.end??0;else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&se(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.scrollState=null;return}}else this.scrollState.stableFrames=0,n&&(this.scrollState.lastTargetOffset=t,this.scrollState.behavior=`auto`,this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}));this.scheduleScrollReconcile()}},B=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function V({measurements:e,outerSize:t,scrollOffset:n,lanes:r}){let i=e.length-1,a=t=>e[t].start;if(e.length<=r)return{startIndex:0,endIndex:i};let o=B(0,i,a,n),s=o;if(r===1)for(;s<i&&e[s].end<n+t;)s++;else if(r>1){let a=Array(r).fill(0);for(;s<i&&a.some(e=>e<n+t);){let t=e[s];a[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(i,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var _e=typeof document<`u`?t.useLayoutEffect:t.useEffect;function H({useFlushSync:e=!0,...n}){let r=t.useReducer(()=>({}),{})[1],i={...n,onChange:(t,i)=>{var a;e&&i?(0,s.flushSync)(r):r(),(a=n.onChange)==null||a.call(n,t,i)}},[a]=t.useState(()=>new ge(i));return a.setOptions(i),_e(()=>a._didMount(),[]),_e(()=>a._willUpdate()),a}function U(e){return H({observeElementRect:de,observeElementOffset:pe,scrollToFn:he,...e})}var W=({data:e,columns:n,rowHeight:r=40,height:i=600,className:a=``,headerClassName:o=``,rowClassName:s,onRowClick:c,overscan:l=5})=>{let u=(0,t.useRef)(null),d=U({count:e.length,getScrollElement:()=>u.current,estimateSize:()=>r,overscan:l}),f=d.getVirtualItems();return(0,y.jsxs)(`div`,{className:a,children:[(0,y.jsx)(`div`,{className:`grid border-b sticky top-0 bg-muted/30 z-10 ${o}`,style:{gridTemplateColumns:n.map(e=>e.width||`1fr`).join(` `)},children:n.map((e,t)=>(0,y.jsx)(`div`,{className:`px-4 py-2 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/70 ${e.align===`center`?`text-center`:e.align===`right`?`text-right`:`text-left`}`,children:e.header},t))}),(0,y.jsx)(`div`,{ref:u,className:`overflow-auto`,style:{height:typeof i==`number`?`${i}px`:i,contain:`strict`},children:(0,y.jsx)(`div`,{style:{height:`${d.getTotalSize()}px`,width:`100%`,position:`relative`},children:f.map(t=>{let r=e[t.index];return(0,y.jsx)(`div`,{className:`grid border-b hover:bg-muted/50 cursor-pointer ${typeof s==`function`?s(r,t.index):s||``}`,style:{position:`absolute`,top:0,left:0,width:`100%`,height:`${t.size}px`,transform:`translateY(${t.start}px)`,gridTemplateColumns:n.map(e=>e.width||`1fr`).join(` `)},onClick:()=>c?.(r,t.index),children:n.map((e,t)=>{let n=r[e.accessorKey],i=e.cell?e.cell(n,r):n;return(0,y.jsx)(`div`,{className:`px-4 py-2 text-sm flex items-center ${e.align===`center`?`text-center justify-center`:e.align===`right`?`text-right justify-end`:`text-left justify-start`}`,children:i},t)})},t.key)})})}),(0,y.jsxs)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground border-t`,children:[`Showing `,f.length,` of `,e.length,` rows (virtual scrolling enabled)`]})]})},G=10;function K(e){let t=[],n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a],s=e[a+1];i?o===`"`&&s===`"`?(r+=`"`,a++):o===`"`?i=!1:r+=o:o===`"`?i=!0:o===`,`?(n.push(r.trim()),r=``):o===`
12
+ `||o===`\r`&&s===`
13
+ `?(n.push(r.trim()),n.some(e=>e!==``)&&t.push(n),n=[],r=``,o===`\r`&&a++):r+=o}return n.push(r.trim()),n.some(e=>e!==``)&&t.push(n),t}function q(e,t){if(!e)return!0;switch(t){case`number`:case`currency`:case`percent`:return!isNaN(Number(e));case`boolean`:return[`true`,`false`,`1`,`0`,`yes`,`no`].includes(e.toLowerCase());case`date`:case`datetime`:return!isNaN(Date.parse(e));default:return!0}}function J(e,t){let n={};return e.forEach((e,r)=>{let i=e.toLowerCase().replace(/[_\s-]/g,``),a=t.find(e=>{let t=e.name.toLowerCase().replace(/[_\s-]/g,``),n=e.label.toLowerCase().replace(/[_\s-]/g,``);return t===i||n===i});a&&(n[r]=a.name)}),n}function ve(e,t,n){let r=[],i={};for(let a of t){let t=e[a.csvIdx]??``;if(a.field.required&&!t){r.push({row:n,field:a.field.name,message:`Required field is empty`});continue}if(t&&!q(t,a.field.type)){r.push({row:n,field:a.field.name,message:`Invalid ${a.field.type} value: "${t}"`});continue}i[a.field.name]=t}return{record:i,errors:r}}var ye=({onFileLoaded:e})=>{let[n,r]=(0,t.useState)(!1),[i,s]=(0,t.useState)(null),c=(0,t.useCallback)(t=>{if(s(null),!t.name.endsWith(`.csv`)){s(`Only CSV files are supported.`);return}let n=new FileReader;n.onload=t=>{let n=K(t.target?.result);if(n.length<2){s(`File must contain a header row and at least one data row.`);return}e(n[0],n.slice(1))},n.readAsText(t)},[e]);return(0,y.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-6`,children:[(0,y.jsxs)(`div`,{className:(0,a.cn)(`flex w-full flex-col items-center justify-center gap-3 rounded-lg border-2 border-dashed p-10 transition-colors`,n?`border-primary bg-primary/5`:`border-muted-foreground/25`),onDragOver:e=>{e.preventDefault(),r(!0)},onDragLeave:()=>r(!1),onDrop:e=>{e.preventDefault(),r(!1);let t=e.dataTransfer.files[0];t&&c(t)},children:[(0,y.jsx)(o.Upload,{className:`h-10 w-10 text-muted-foreground`}),(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Drag & drop a CSV file here, or click to browse`}),(0,y.jsxs)(`label`,{children:[(0,y.jsx)(`input`,{type:`file`,accept:`.csv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&c(t)}}),(0,y.jsx)(a.Button,{variant:`outline`,size:`sm`,asChild:!0,children:(0,y.jsx)(`span`,{children:`Browse Files`})})]})]}),i&&(0,y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-destructive`,children:[(0,y.jsx)(o.AlertCircle,{className:`h-4 w-4`}),` `,i]})]})},Y=({headers:e,fields:n,mapping:r,onMappingChange:i})=>{let o=(0,t.useMemo)(()=>new Set(Object.values(r)),[r]),s=(0,t.useCallback)((e,t)=>{let n={...r};t===`__skip__`?delete n[e]:n[e]=t,i(n)},[r,i]);return(0,y.jsx)(`div`,{className:`max-h-[360px] overflow-auto`,children:(0,y.jsxs)(a.Table,{children:[(0,y.jsx)(a.TableHeader,{children:(0,y.jsxs)(a.TableRow,{children:[(0,y.jsx)(a.TableHead,{children:`CSV Column`}),(0,y.jsx)(a.TableHead,{children:`Maps To`}),(0,y.jsx)(a.TableHead,{className:`w-24 text-center`,children:`Status`})]})}),(0,y.jsx)(a.TableBody,{children:e.map((e,t)=>(0,y.jsxs)(a.TableRow,{children:[(0,y.jsx)(a.TableCell,{className:`font-medium`,children:e}),(0,y.jsx)(a.TableCell,{children:(0,y.jsxs)(a.Select,{value:r[t]??`__skip__`,onValueChange:e=>s(t,e),children:[(0,y.jsx)(a.SelectTrigger,{className:`h-8 w-56`,children:(0,y.jsx)(a.SelectValue,{placeholder:`Skip column`})}),(0,y.jsxs)(a.SelectContent,{children:[(0,y.jsx)(a.SelectItem,{value:`__skip__`,children:`— Skip —`}),n.map(e=>(0,y.jsxs)(a.SelectItem,{value:e.name,disabled:o.has(e.name)&&r[t]!==e.name,children:[e.label,e.required?` *`:``]},e.name))]})]})}),(0,y.jsx)(a.TableCell,{className:`text-center`,children:r[t]?(0,y.jsx)(a.Badge,{variant:`default`,className:`text-xs`,children:`Mapped`}):(0,y.jsx)(a.Badge,{variant:`secondary`,className:`text-xs`,children:`Skipped`})})]},t))})]})})},X=({headers:e,rows:n,mapping:r,fields:i})=>{let s=(0,t.useMemo)(()=>Object.entries(r).map(([t,n])=>({csvIdx:Number(t),header:e[Number(t)],field:i.find(e=>e.name===n)})),[r,e,i]),c=n.slice(0,G),l=(0,t.useMemo)(()=>c.map((e,t)=>{let n={};for(let t of s){let r=e[t.csvIdx]??``;t.field.required&&!r?n[t.csvIdx]=`Required`:r&&!q(r,t.field.type)&&(n[t.csvIdx]=`Invalid ${t.field.type}`)}return n}),[c,s]),u=l.filter(e=>Object.keys(e).length>0).length;return(0,y.jsxs)(`div`,{className:`max-h-[360px] overflow-auto`,children:[u>0&&(0,y.jsxs)(`p`,{className:`mb-2 flex items-center gap-1 text-xs text-destructive`,children:[(0,y.jsx)(o.AlertCircle,{className:`h-3.5 w-3.5`}),` `,u,` row(s) with errors in preview`]}),(0,y.jsxs)(a.Table,{children:[(0,y.jsx)(a.TableHeader,{children:(0,y.jsxs)(a.TableRow,{children:[(0,y.jsx)(a.TableHead,{className:`w-12`,children:`#`}),s.map(e=>(0,y.jsx)(a.TableHead,{children:e.field.label},e.csvIdx))]})}),(0,y.jsx)(a.TableBody,{children:c.map((e,t)=>{let n=l[t];return(0,y.jsxs)(a.TableRow,{className:(0,a.cn)(Object.keys(n).length>0&&`bg-destructive/5`),children:[(0,y.jsx)(a.TableCell,{className:`text-xs text-muted-foreground`,children:t+1}),s.map(t=>{let r=e[t.csvIdx]??``,i=n[t.csvIdx];return(0,y.jsx)(a.TableCell,{className:(0,a.cn)(i&&`text-destructive`),title:i,children:r||(0,y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`—`})},t.csvIdx)})]},t)})})]}),(0,y.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Showing `,c.length,` of `,n.length,` rows`]})]})},be=({objectName:e,objectLabel:n,fields:r,dataSource:i,onComplete:s,onCancel:c,open:l,onOpenChange:u,onErrorMode:d=`skip`})=>{let[f,p]=(0,t.useState)(`upload`),[m,h]=(0,t.useState)([]),[g,_]=(0,t.useState)([]),[v,b]=(0,t.useState)({}),[x,S]=(0,t.useState)(!1),[C,w]=(0,t.useState)(0),[T,E]=(0,t.useState)(null),D=n??e,ee=(0,t.useMemo)(()=>{let e=new Set(Object.values(v));return r.filter(t=>t.required&&!e.has(t.name))},[r,v]),O=(0,t.useCallback)((e,t)=>{h(e),_(t),b(J(e,r)),p(`mapping`)},[r]),k=(0,t.useCallback)(async()=>{S(!0),w(0);let t=[],n=0,a=0,o=Object.entries(v).map(([e,t])=>({csvIdx:Number(e),field:r.find(e=>e.name===t)}));for(let r=0;r<g.length;r++){let{record:s,errors:c}=ve(g[r],o,r+1);if(c.length>0){if(a++,t.push(...c),d===`stop`)break}else try{i?.create&&await i.create(e,s),n++}catch(e){a++;let n=e instanceof Error?e.message:`Failed to create record`;if(t.push({row:r+1,field:``,message:n}),d===`stop`)break}w(Math.round((r+1)/g.length*100))}let c={totalRows:g.length,importedRows:n,skippedRows:a,errors:t};E(c),S(!1),s?.(c)},[g,v,r,i,e,s,d]),A=(0,t.useCallback)(()=>{p(`upload`),h([]),_([]),b({}),w(0),E(null)},[]),j=(0,t.useCallback)(()=>{A(),u?.(!1),c?.()},[A,u,c]);return(0,y.jsx)(a.Dialog,{open:l,onOpenChange:e=>{e?u?.(e):j()},children:(0,y.jsxs)(a.DialogContent,{className:`sm:max-w-2xl`,children:[(0,y.jsxs)(a.DialogHeader,{children:[(0,y.jsxs)(a.DialogTitle,{className:`flex items-center gap-2`,children:[(0,y.jsx)(o.FileSpreadsheet,{className:`h-5 w-5`}),` Import `,D]}),(0,y.jsxs)(a.DialogDescription,{children:[f===`upload`&&`Upload a CSV file to get started.`,f===`mapping`&&`Map CSV columns to object fields.`,f===`preview`&&`Review data before importing.`]})]}),(0,y.jsx)(`div`,{className:`flex items-center justify-center gap-2 text-xs text-muted-foreground`,children:[`upload`,`mapping`,`preview`].map((e,n)=>(0,y.jsxs)(t.default.Fragment,{children:[n>0&&(0,y.jsx)(o.ArrowRight,{className:`h-3 w-3`}),(0,y.jsxs)(`span`,{className:(0,a.cn)(`rounded-full px-3 py-1`,f===e?`bg-primary text-primary-foreground`:`bg-muted`),children:[n+1,`. `,e===`upload`?`Upload`:e===`mapping`?`Mapping`:`Preview`]})]},e))}),T?(0,y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-4`,children:[(0,y.jsx)(o.CheckCircle2,{className:`h-10 w-10 text-green-500`}),(0,y.jsx)(`p`,{className:`text-lg font-semibold`,children:`Import Complete`}),(0,y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,y.jsxs)(a.Badge,{variant:`default`,children:[T.importedRows,` imported`]}),T.skippedRows>0&&(0,y.jsxs)(a.Badge,{variant:`destructive`,children:[T.skippedRows,` skipped`]})]}),T.errors.length>0&&(0,y.jsxs)(`div`,{className:`max-h-32 w-full overflow-auto rounded border p-2 text-xs`,children:[T.errors.slice(0,10).map((e,t)=>(0,y.jsxs)(`p`,{className:`text-destructive`,children:[`Row `,e.row,e.field?` (${e.field})`:``,`: `,e.message]},t)),T.errors.length>10&&(0,y.jsxs)(`p`,{className:`text-muted-foreground`,children:[`…and `,T.errors.length-10,` more errors`]})]})]}):(0,y.jsxs)(y.Fragment,{children:[f===`upload`&&(0,y.jsx)(ye,{onFileLoaded:O}),f===`mapping`&&(0,y.jsx)(Y,{headers:m,fields:r,mapping:v,onMappingChange:b}),f===`preview`&&(0,y.jsx)(X,{headers:m,rows:g,mapping:v,fields:r}),x&&(0,y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,y.jsx)(a.Progress,{value:C,className:`h-2`}),(0,y.jsxs)(`p`,{className:`text-center text-xs text-muted-foreground`,children:[`Importing… `,C,`%`]})]})]}),(0,y.jsx)(a.DialogFooter,{className:`gap-2 sm:gap-0`,children:T?(0,y.jsx)(a.Button,{onClick:j,children:`Close`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(a.Button,{variant:`ghost`,onClick:j,disabled:x,children:[(0,y.jsx)(o.X,{className:`mr-1 h-4 w-4`}),` Cancel`]}),(f===`mapping`||f===`preview`)&&(0,y.jsxs)(a.Button,{variant:`outline`,onClick:()=>p(f===`mapping`?`upload`:`mapping`),disabled:x,children:[(0,y.jsx)(o.ArrowLeft,{className:`mr-1 h-4 w-4`}),` Back`]}),f===`mapping`&&(0,y.jsxs)(a.Button,{onClick:()=>p(`preview`),disabled:Object.keys(v).length===0||ee.length>0,children:[`Next `,(0,y.jsx)(o.ArrowRight,{className:`ml-1 h-4 w-4`})]}),f===`preview`&&(0,y.jsx)(a.Button,{onClick:k,disabled:x,children:x?`Importing…`:`Import ${g.length} Rows`})]})})]})})};function xe({value:e,onSave:n,onCancel:r,validate:i,type:s=`text`,placeholder:c,editing:l=!1,className:u,disabled:d=!1}){let[f,p]=(0,t.useState)(l),[m,h]=(0,t.useState)(String(e??``)),[g,_]=(0,t.useState)(),[v,b]=(0,t.useState)(!1),x=(0,t.useRef)(null);(0,t.useEffect)(()=>{f||h(String(e??``))},[e,f]),(0,t.useEffect)(()=>{f&&x.current&&(x.current.focus(),x.current.select())},[f]);let S=(0,t.useCallback)(()=>{d||(p(!0),h(String(e??``)),_(void 0))},[d,e]),C=(0,t.useCallback)(()=>{p(!1),h(String(e??``)),_(void 0),r?.()},[e,r]),w=(0,t.useCallback)(async()=>{if(i){let e=i(m);if(e){_(e);return}}let e=s===`number`?Number(m):m;b(!0);try{let t=await n(e);if(typeof t==`string`){_(t),b(!1);return}p(!1),_(void 0)}catch(e){_(e?.message||`Save failed`)}finally{b(!1)}},[m,i,s,n]),T=(0,t.useCallback)(e=>{e.key===`Enter`?(e.preventDefault(),w()):e.key===`Escape`&&(e.preventDefault(),C())},[w,C]);return f?(0,y.jsxs)(`div`,{"data-slot":`inline-editing`,className:(0,a.cn)(`relative flex items-center gap-1`,u),children:[(0,y.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,y.jsx)(`input`,{ref:x,"data-slot":`inline-editing-input`,type:s,value:m,onChange:e=>{h(e.target.value),g&&_(void 0)},onKeyDown:T,placeholder:c,disabled:v,"aria-invalid":!!g,"aria-describedby":g?`inline-editing-error`:void 0,className:(0,a.cn)(`w-full rounded border px-2 py-1 text-sm outline-none transition-colors`,`focus:ring-2 focus:ring-ring focus:border-input`,g?`border-destructive focus:ring-destructive/30`:`border-input`,v&&`opacity-50`)}),g&&(0,y.jsx)(`p`,{id:`inline-editing-error`,"data-slot":`inline-editing-error`,className:`absolute left-0 top-full mt-0.5 text-xs text-destructive`,role:`alert`,children:g})]}),(0,y.jsx)(`button`,{"data-slot":`inline-editing-save`,type:`button`,onClick:w,disabled:v,"aria-label":`Save`,className:(0,a.cn)(`inline-flex h-6 w-6 items-center justify-center rounded text-primary hover:bg-primary/10 transition-colors`,v&&`opacity-50 cursor-not-allowed`),children:(0,y.jsx)(o.Check,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(`button`,{"data-slot":`inline-editing-cancel`,type:`button`,onClick:C,disabled:v,"aria-label":`Cancel`,className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors`,children:(0,y.jsx)(o.X,{className:`h-3.5 w-3.5`})})]}):(0,y.jsx)(`div`,{"data-slot":`inline-editing`,className:(0,a.cn)(`group relative cursor-pointer rounded px-2 py-1 hover:bg-muted/50 transition-colors min-h-[1.75rem] flex items-center`,d&&`cursor-default opacity-60`,u),onClick:S,role:`button`,tabIndex:d?-1:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),S())},"aria-label":`Edit value: ${String(e??``)}`,children:(0,y.jsx)(`span`,{"data-slot":`inline-editing-display`,className:`truncate text-sm`,children:e!=null&&String(e)!==``?String(e):(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:c||`Click to edit`})})})}function Se(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function Ce({data:e,columns:n,onPaste:r,enabled:i=!0}){let[a,o]=(0,t.useState)(null),s=(0,t.useCallback)(()=>{if(!i||!a)return;let{startRow:t,startCol:r,endRow:o,endCol:s}=Se(a),c=[];for(let i=t;i<=o;i++){let t=e[i];if(!t)continue;let a=[];for(let e=r;e<=s;e++){let r=n[e];a.push(r?String(t[r]??``):``)}c.push(a.join(` `))}let l=c.join(`
14
+ `);navigator.clipboard.writeText(l)},[i,a,e,n]),c=(0,t.useCallback)(()=>{if(!i||!a||!r)return;let{startRow:t,startCol:o}=Se(a);navigator.clipboard.readText().then(i=>{let a=[],s=i.split(`
15
+ `);for(let r=0;r<s.length;r++){let i=s[r].split(` `);for(let s=0;s<i.length;s++){let c=t+r,l=n[o+s];l&&c<e.length&&a.push({rowIndex:c,field:l,value:i[s]})}}a.length>0&&r(a)})},[i,a,n,e.length,r]),l=(0,t.useCallback)(e=>{if(!i)return;let t=e.metaKey||e.ctrlKey;t&&e.key===`c`?(e.preventDefault(),s()):t&&e.key===`v`&&(e.preventDefault(),c())},[i,s,c]);return(0,t.useEffect)(()=>{i||o(null)},[i]),{selectedRange:a,setSelectedRange:o,onCopy:s,onPaste:c,onKeyDown:l}}var we=[{position:0,className:`bg-green-100`},{position:.5,className:`bg-yellow-100`},{position:1,className:`bg-red-100`}];function Te(e,t){let n=1/0,r=-1/0;for(let i of e){let e=Number(i[t]);Number.isFinite(e)&&(e<n&&(n=e),e>r&&(r=e))}return Number.isFinite(n)?[n,r]:[0,0]}function Ee(e,t){if(t.length===0)return``;if(t.length===1)return t[0].className;let n=t[0],r=Math.abs(e-n.position);for(let i=1;i<t.length;i++){let a=Math.abs(e-t[i].position);a<r&&(n=t[i],r=a)}return n.className}function Z(e){let{field:n,data:r,min:i,max:a,stops:o=we}=e,[s,c]=(0,t.useMemo)(()=>Te(r,n),[r,n]),l=i??s,u=a??c;return(0,t.useCallback)(e=>{let t=Number(e[n]);if(Number.isFinite(t))return u===l?o.length>0?o[0].className:void 0:Ee(Math.max(0,Math.min(1,(t-l)/(u-l))),o)},[n,l,u,o])}var De=`text/x-group-key`;function Q({groupKeys:e}){let[n,r]=(0,t.useState)(e),[i,a]=(0,t.useState)(null);return(0,t.useEffect)(()=>{r(t=>{let n=new Set(t),r=new Set(e);if(t.length===e.length&&t.every((t,n)=>t===e[n]))return t;let i=t.filter(e=>r.has(e)),a=e.filter(e=>!n.has(e));return[...i,...a]})},[e]),{groupOrder:n,moveGroup:(0,t.useCallback)((e,t)=>{r(n=>{if(e<0||e>=n.length||t<0||t>=n.length||e===t)return n;let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},[]),onDragStart:(0,t.useCallback)((e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(De,t),a(t)},[]),onDragOver:(0,t.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),onDrop:(0,t.useCallback)((e,t)=>{e.preventDefault();let n=e.dataTransfer.getData(De);!n||n===t||r(e=>{let r=e.indexOf(n),i=e.indexOf(t);if(r===-1||i===-1)return e;let a=[...e],[o]=a.splice(r,1);return a.splice(i,0,o),a})},[]),onDragEnd:(0,t.useCallback)(()=>{a(null)},[]),draggingKey:i}}function $({value:e,onChange:n,onConfirm:r,onCancel:i,activeCell:s,disabled:c=!1,className:l}){let[u,d]=(0,t.useState)(!1),[f,p]=(0,t.useState)(e),m=(0,t.useRef)(null);(0,t.useEffect)(()=>{u||p(e)},[e,u]),(0,t.useEffect)(()=>{u&&m.current&&(m.current.focus(),m.current.select())},[u]);let h=(0,t.useCallback)(()=>{c||(d(!0),p(e))},[c,e]),g=(0,t.useCallback)(()=>{d(!1),n?.(f),r?.(f)},[f,n,r]),_=(0,t.useCallback)(()=>{d(!1),p(e),i?.()},[e,i]),v=(0,t.useCallback)(e=>{e.key===`Enter`?(e.preventDefault(),g()):e.key===`Escape`&&(e.preventDefault(),_())},[g,_]);return(0,y.jsxs)(`div`,{className:(0,a.cn)(`flex items-center gap-2 border-b border-border bg-muted/30 px-3 py-1.5`,l),children:[(0,y.jsx)(o.FunctionSquare,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),s&&(0,y.jsx)(`span`,{className:`min-w-[4rem] shrink-0 rounded bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground`,children:s}),(0,y.jsx)(`input`,{ref:m,type:`text`,value:u?f:e,readOnly:!u,disabled:c,onClick:h,onChange:e=>p(e.target.value),onKeyDown:v,className:(0,a.cn)(`flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`,u&&`rounded ring-1 ring-ring px-1`,c&&`cursor-not-allowed opacity-50`)}),u&&(0,y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,y.jsx)(`button`,{type:`button`,onClick:g,className:`rounded p-0.5 text-green-600 hover:bg-green-100`,"aria-label":`Confirm`,children:(0,y.jsx)(o.Check,{className:`h-4 w-4`})}),(0,y.jsx)(`button`,{type:`button`,onClick:_,className:`rounded p-0.5 text-red-600 hover:bg-red-100`,"aria-label":`Cancel`,children:(0,y.jsx)(o.X,{className:`h-4 w-4`})})]})]})}function Oe({frozenWidth:e,onResize:n,minFrozenWidth:r=100,minScrollableWidth:i=200,left:s,right:c,className:l}){let u=(0,t.useRef)(null),[d,f]=(0,t.useState)(e),p=(0,t.useRef)(!1),m=(0,t.useRef)(0),h=(0,t.useRef)(0),g=n?e:d,_=(0,t.useCallback)(e=>{e.preventDefault(),p.current=!0,m.current=e.clientX,h.current=g;let t=e=>{if(!p.current||!u.current)return;let t=u.current.offsetWidth,a=e.clientX-m.current,o=h.current+a;o=Math.max(o,r),o=Math.min(o,t-i),n?n(o):f(o)},a=()=>{p.current=!1,document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,a)};document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,a)},[g,r,i,n]);return(0,y.jsxs)(`div`,{ref:u,className:(0,a.cn)(`flex h-full w-full overflow-hidden`,l),children:[(0,y.jsx)(`div`,{className:`shrink-0 overflow-auto`,style:{width:g},children:s}),(0,y.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:_,className:(0,a.cn)(`flex w-2 cursor-col-resize items-center justify-center`,`border-x border-border bg-muted/50 hover:bg-muted`,`transition-colors`),children:(0,y.jsx)(o.GripVertical,{className:`h-4 w-4 text-muted-foreground`})}),(0,y.jsx)(`div`,{className:`min-w-0 flex-1 overflow-auto`,children:c})]})}var ke=({schema:e,...t})=>{let{dataSource:n}=(0,r.useSchemaContext)()||{};return(0,y.jsx)(ae,{schema:e,dataSource:n,...t})};n.ComponentRegistry.register(`object-grid`,ke,{namespace:`plugin-grid`,label:`Object Grid`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`},{name:`filters`,type:`array`,label:`Filters`}]}),n.ComponentRegistry.register(`grid`,ke,{namespace:`view`,label:`Data Grid`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`},{name:`filters`,type:`array`,label:`Filters`}]}),n.ComponentRegistry.register(`import-wizard`,({schema:e,...t})=>{let{dataSource:n}=(0,r.useSchemaContext)()||{};return(0,y.jsx)(be,{objectName:e.objectName,objectLabel:e.objectLabel,fields:e.fields??[],dataSource:n,...t})},{namespace:`plugin-grid`,label:`Import Wizard`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`,required:!0}]}),e.BulkActionBar=F,e.FormulaBar=$,e.GroupRow=O,e.ImportWizard=be,e.InlineEditing=xe,e.ObjectGrid=ae,e.ObjectGridRenderer=ke,e.RowActionMenu=P,e.SplitPaneGrid=Oe,e.VirtualGrid=W,e.formatActionLabel=N,e.useCellClipboard=Ce,e.useColumnSummary=M,e.useGradientColor=Z,e.useGroupReorder=Q,e.useGroupedData=ee,e.useRowColor=C});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-grid",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Grid plugin for Object UI",
@@ -15,26 +15,26 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@tanstack/react-virtual": "^3.13.21",
18
+ "@tanstack/react-virtual": "^3.13.23",
19
19
  "lucide-react": "^0.577.0",
20
- "@object-ui/components": "3.1.3",
21
- "@object-ui/core": "3.1.3",
22
- "@object-ui/fields": "3.1.3",
23
- "@object-ui/mobile": "3.1.3",
24
- "@object-ui/react": "3.1.3",
25
- "@object-ui/types": "3.1.3"
20
+ "@object-ui/components": "3.1.5",
21
+ "@object-ui/core": "3.1.5",
22
+ "@object-ui/fields": "3.1.5",
23
+ "@object-ui/mobile": "3.1.5",
24
+ "@object-ui/react": "3.1.5",
25
+ "@object-ui/types": "3.1.5"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^18.0.0 || ^19.0.0",
29
29
  "react-dom": "^18.0.0 || ^19.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@vitejs/plugin-react": "^5.1.4",
33
- "msw": "^2.12.10",
32
+ "@vitejs/plugin-react": "^6.0.1",
33
+ "msw": "^2.12.14",
34
34
  "typescript": "^5.9.3",
35
- "vite": "^7.3.1",
35
+ "vite": "^8.0.1",
36
36
  "vite-plugin-dts": "^4.5.4",
37
- "@object-ui/data-objectstack": "3.1.3"
37
+ "@object-ui/data-objectstack": "3.1.5"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "vite build",