@object-ui/console 3.1.2 → 3.1.3

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.
Files changed (63) hide show
  1. package/dist/assets/{AdvancedChartImpl-D711bBuO.js → AdvancedChartImpl-BvIFxlPf.js} +2 -2
  2. package/dist/assets/{AppManagementPage-CaWUYaXX.js → AppManagementPage-6bzxYNlP.js} +1 -1
  3. package/dist/assets/{AuditLogPage-CB1qkThp.js → AuditLogPage-qCzdxaNq.js} +1 -1
  4. package/dist/assets/{AuthPageLayout-9l5xWV_-.js → AuthPageLayout-DkrxSZOE.js} +1 -1
  5. package/dist/assets/{ChartImpl-B9B4Fnbe.js → ChartImpl-DYQ9eXJz.js} +1 -1
  6. package/dist/assets/CreateAppPage-DNKskVHK.js +1 -0
  7. package/dist/assets/{DashboardDesignPage-DGz-5xrK.js → DashboardDesignPage-T9tEAHAx.js} +1 -1
  8. package/dist/assets/{DashboardView-v834XbaQ.js → DashboardView-jCJCERzJ.js} +1 -1
  9. package/dist/assets/{EditAppPage-DocDqKMS.js → EditAppPage-UGT9V29B.js} +1 -1
  10. package/dist/assets/{ForgotPasswordPage-8ypvh4-X.js → ForgotPasswordPage-Ca0lLZwY.js} +1 -1
  11. package/dist/assets/{KanbanEnhanced-Cw4oddBv.js → KanbanEnhanced-CyIdmKhW.js} +1 -1
  12. package/dist/assets/{KanbanImpl-D6ggfmB0.js → KanbanImpl-PGPpv-gu.js} +1 -1
  13. package/dist/assets/{LoginPage-XakThPoT.js → LoginPage-BR2RpoGG.js} +1 -1
  14. package/dist/assets/{MarkdownImpl-C0wRapHT.js → MarkdownImpl-eDhoPCJp.js} +1 -1
  15. package/dist/assets/{OrgManagementPage-Df5167oO.js → OrgManagementPage-DjT2mZ2x.js} +1 -1
  16. package/dist/assets/{PageDesignPage-BzM4EsXt.js → PageDesignPage-DTEQcEuR.js} +1 -1
  17. package/dist/assets/{PageView-CpIQvLmr.js → PageView-CFJhE0CN.js} +2 -2
  18. package/dist/assets/{PermissionManagementPage-CZH3URJU.js → PermissionManagementPage-C_FPnvGW.js} +1 -1
  19. package/dist/assets/{ProfilePage-BvIbbebc.js → ProfilePage-CQkgvEEi.js} +1 -1
  20. package/dist/assets/RecordDetailView-ClpxNRz2.js +1 -0
  21. package/dist/assets/{RegisterPage-CIeFN9rY.js → RegisterPage-6IYU4bdp.js} +1 -1
  22. package/dist/assets/{ReportView-DYhXezmy.js → ReportView-DecAJ58u.js} +1 -1
  23. package/dist/assets/{RoleManagementPage-D0X7HlqJ.js → RoleManagementPage-v0ia3MGn.js} +1 -1
  24. package/dist/assets/{SearchResultsPage-CoMB32KW.js → SearchResultsPage-CaSb54ho.js} +1 -1
  25. package/dist/assets/{SystemHubPage-Cvl3VKcV.js → SystemHubPage-PNaxZEht.js} +1 -1
  26. package/dist/assets/{UserManagementPage-5k8BQxT1.js → UserManagementPage-KAZy5fgy.js} +1 -1
  27. package/dist/assets/data-adapter-DCM4pdG4.js +1 -0
  28. package/dist/assets/{framework-52FGgFF6.js → framework-jBjO8CT3.js} +2 -2
  29. package/dist/assets/{index-D5i0wk-G.js → index-BwkHrw9s.js} +1 -1
  30. package/dist/assets/index-DXak0mZe.css +1 -0
  31. package/dist/assets/{index-fjkakZm9.js → index-tta28Q_N.js} +3 -3
  32. package/dist/assets/infrastructure-CWeiQ12V.js +1 -0
  33. package/dist/assets/{maplibre-gl-DVmJFhI2.js → maplibre-gl-CENyyZ0G.js} +1 -1
  34. package/dist/assets/plugins-core-BV7ym-7D.js +8 -0
  35. package/dist/assets/plugins-views-gxDbTdkX.js +62 -0
  36. package/dist/assets/{ui-components-CxztIKgM.css → ui-components-BCiSmwiC.css} +1 -1
  37. package/dist/assets/ui-components-BRpbeVr1.js +36 -0
  38. package/dist/assets/ui-layout-VeUu0ZVf.js +1 -0
  39. package/dist/assets/vendor-charts-DthMRf4E.js +60 -0
  40. package/dist/assets/{vendor-dndkit-CX1oDZqy.js → vendor-dndkit-_-PfuStg.js} +1 -1
  41. package/dist/assets/vendor-i18n-B3GHNV0X.js +9 -0
  42. package/dist/assets/{vendor-icons-ndICq8DC.js → vendor-icons-CnLeuN7Z.js} +3419 -3414
  43. package/dist/assets/vendor-objectstack-BkRCrdfn.js +34 -0
  44. package/dist/assets/vendor-radix-BPVlBHPl.js +56 -0
  45. package/dist/assets/{vendor-react-9M-xu2bR.js → vendor-react-Dvo_9NuO.js} +6 -6
  46. package/dist/assets/{vendor-ui-utils-3tkeUVaX.js → vendor-ui-utils-CU11aiRA.js} +1 -1
  47. package/dist/assets/vendor-zod-CZmssJWz.js +39 -0
  48. package/dist/index.html +23 -23
  49. package/package.json +40 -40
  50. package/dist/assets/CreateAppPage-DLRU3TEg.js +0 -1
  51. package/dist/assets/RecordDetailView-BNnPf0DG.js +0 -1
  52. package/dist/assets/data-adapter-Bif-TtZA.js +0 -1
  53. package/dist/assets/index-h9Jznm67.css +0 -1
  54. package/dist/assets/infrastructure-Dn7jNPwf.js +0 -1
  55. package/dist/assets/plugins-core-CP8uPw4p.js +0 -8
  56. package/dist/assets/plugins-views-DZCu8Ex3.js +0 -62
  57. package/dist/assets/ui-components-BE4yvyhE.js +0 -36
  58. package/dist/assets/ui-layout-CYnH69Z2.js +0 -1
  59. package/dist/assets/vendor-charts-BLNOCZWl.js +0 -65
  60. package/dist/assets/vendor-i18n-E3-WitRV.js +0 -9
  61. package/dist/assets/vendor-objectstack-CatrkstC.js +0 -34
  62. package/dist/assets/vendor-radix-C6qchjxv.js +0 -56
  63. package/dist/assets/vendor-zod-C5j6C2CQ.js +0 -39
@@ -0,0 +1,62 @@
1
+ import{r as m,j as e,a as ts,e as rr,R as tt}from"./vendor-react-Dvo_9NuO.js";import{n as mn,l as pn,o as hn,i as Bs,g as nr,S as Ie,C as Se,c as Vs,d as Hs,p as xn,q as gn,s as lr}from"./framework-jBjO8CT3.js";import"./vendor-objectstack-BkRCrdfn.js";import{c as V,B,P as xt,J as gt,K as bt,aJ as bn,ad as yn,ab as qe,N as ir,C as Oe,v as Te,s as $e,u as Be,G as St,ay as or,az as cr,aA as dr,A as qs,ae as ur,af as mt,ag as pt,ah as ht,T as Ws,a as Gs,d as nt,e as lt,p as we,w as vn,x as jn,y as wn,z as Tt,aK as da,aL as Us,aM as Ys,aN as fr,aO as mr,t as Xs,aa as ce,ac as Nn}from"./ui-components-BRpbeVr1.js";import{ag as Cn,ae as Sn,ah as Ks,j as ps,af as kn,ai as Dn,aj as Rn,i as zs,m as Qe,am as pr,C as Dt,X as ss,J as Fn,ax as On,ay as hr,az as Tn,a2 as Pn,y as Vt,ad as Ms,aA as xr,S as Ls,x as ua,a as Mt,d as gr,_ as br,$ as En,z as ot,l as vt,b as yr,aB as kt,aC as vr,aq as fa,aD as An,aE as zn,A as ma,Q as Mn,aF as Ln,E as _n,aG as In,c as $n,aH as Bn,aI as Vn,aJ as Hn,a0 as qn,aK as jr,aL as wr,a9 as Wn,L as Gn,aM as Un,aN as Yn,aO as Js,q as Nr,G as pa,w as Cr,an as Sr,ao as kr,M as Dr,aa as Xn,n as Kn,aw as Cs,aP as Jn}from"./vendor-icons-CnLeuN7Z.js";import{r as Qn,c as Rr}from"./vendor-ui-utils-CU11aiRA.js";import{u as Fr,b as Zn,a as Qs}from"./infrastructure-CWeiQ12V.js";const el={grid:e.jsx(Rn,{className:"h-4 w-4"}),kanban:e.jsx(Dn,{className:"h-4 w-4"}),gallery:e.jsx(kn,{className:"h-4 w-4"}),calendar:e.jsx(ps,{className:"h-4 w-4"}),timeline:e.jsx(Ks,{className:"h-4 w-4"}),gantt:e.jsx(Sn,{className:"h-4 w-4"}),map:e.jsx(Cn,{className:"h-4 w-4"})},Ss={grid:"Grid",kanban:"Kanban",gallery:"Gallery",calendar:"Calendar",timeline:"Timeline",gantt:"Gantt",map:"Map"},tl=({currentView:t,availableViews:s=["grid","kanban"],onViewChange:a,className:r,animated:l=!0})=>{const d=m.useCallback(c=>{if(!l||c===t){a(c);return}typeof document<"u"&&"startViewTransition"in document?document.startViewTransition(()=>a(c)):a(c)},[l,t,a]);return e.jsx("div",{className:V("flex items-center gap-1 bg-transparent oui-view-switcher",r),children:s.map(c=>{const i=t===c;return e.jsxs("button",{type:"button",onClick:()=>d(c),"aria-label":Ss[c],title:Ss[c],"aria-pressed":i,"data-state":i?"on":"off",className:V("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50","hover:bg-muted hover:text-muted-foreground","gap-2 px-3 py-2","data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-sm border-transparent border data-[state=on]:border-border/50"),children:[el[c],e.jsx("span",{className:"hidden sm:inline-block text-xs font-medium",children:Ss[c]})]},c)})})};function sl(t){if(!t)return null;const s=t.split("-").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join("");return zs[s]??null}function al(t){return t.filter(s=>s.pinned||s.visible!=="false"&&s.visible!==!1).sort((s,a)=>(s.order??0)-(a.order??0))}const rl=({tabs:t,activeTab:s,onTabChange:a,className:r})=>{const l=m.useMemo(()=>al(t),[t]),d=m.useMemo(()=>l.find(n=>n.isDefault)?.name??l[0]?.name,[l]),[c,i]=m.useState(d),o=s??c,u=m.useCallback(h=>{i(h.name),a?.(h)},[a]);return l.length===0?null:e.jsx("div",{className:V("border-b px-2 sm:px-4 py-1 flex items-center gap-0.5 bg-background",r),"data-testid":"view-tabs",role:"tablist",children:l.map(h=>{const n=sl(h.icon),N=o===h.name;return e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-3 py-1.5 text-xs rounded-none transition-colors duration-150",N?"border-b-2 border-primary font-medium text-foreground":"text-muted-foreground hover:text-foreground"),"data-testid":`view-tab-${h.name}`,role:"tab","aria-selected":N,onClick:()=>u(h),children:[n&&e.jsx(n,{className:"h-3 w-3 mr-1.5"}),h.label]},h.name)})})};function nl({config:t,objectDef:s,data:a=[],onFilterChange:r,maxVisible:l,className:d}){switch(t.element){case"dropdown":return e.jsx(il,{fields:t.fields||[],objectDef:s,data:a,onFilterChange:r,maxVisible:l,className:d});case"tabs":return e.jsx(ol,{tabs:t.tabs||[],showAllRecords:t.showAllRecords!==!1,allowAddTab:t.allowAddTab,onFilterChange:r,className:d});case"toggle":return e.jsx(cl,{fields:t.fields||[],onFilterChange:r,className:d});default:return null}}function ll(t,s,a){return t.map(r=>{let l=r.options?[...r.options]:[];if(l.length===0&&s?.fields){const d=Array.isArray(s.fields)?s.fields.find(c=>c.name===r.field):s.fields[r.field];d?.options&&(Array.isArray(d.options)?l=d.options.map(c=>({label:c.label??String(c.value??c),value:c.value??c,color:c.color})):l=Object.entries(d.options).map(([c,i])=>({label:i?.label||c,value:c,color:i?.color})))}return r.showCount&&a.length>0&&(l=l.map(d=>({...d,count:a.filter(c=>c[r.field]===d.value).length}))),{...r,options:l}})}function il({fields:t,objectDef:s,data:a,onFilterChange:r,maxVisible:l,className:d}){const[c,i]=m.useState(()=>{const x={};return t.forEach(b=>{b.defaultValues&&b.defaultValues.length>0&&(x[b.field]=b.defaultValues)}),x}),o=m.useMemo(()=>ll(t,s,a),[t,s,a]),u=m.useCallback(x=>{const b=Object.entries(x).filter(([,f])=>f.length>0).map(([f,p])=>[f,"in",p]);r(b)},[r]),h=(x,b)=>{const f={...c,[x]:b};i(f),u(f)};m.useEffect(()=>{Object.values(c).some(b=>b.length>0)&&u(c)},[]);const n=l!==void 0&&l<o.length?o.slice(0,l):o,N=l!==void 0&&l<o.length?o.slice(l):[],j=x=>{const b=c[x.field]||[],f=b.length>0;return e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsxs("button",{"data-testid":`filter-badge-${x.field}`,className:V("inline-flex items-center gap-1 rounded-full border h-7 px-2.5 text-xs font-medium transition-colors shrink-0",f?"border-primary/30 bg-primary/5 text-primary":"border-border bg-background hover:bg-accent text-foreground"),children:[e.jsx("span",{className:"truncate max-w-[100px]",children:x.label||x.field}),f&&e.jsx("span",{className:"flex h-4 min-w-[16px] items-center justify-center rounded-full bg-primary/10 text-[10px]",children:b.length}),f?e.jsx(ss,{className:"h-3 w-3 opacity-60","data-testid":`filter-clear-${x.field}`,onClick:p=>{p.stopPropagation(),h(x.field,[])}}):e.jsx(Dt,{className:"h-3 w-3 opacity-60"})]})}),e.jsx(bt,{align:"start",className:"w-56 p-2",children:e.jsx("div",{className:"max-h-60 overflow-y-auto space-y-0.5","data-testid":`filter-options-${x.field}`,children:x.options.map(p=>e.jsxs("label",{className:V("flex items-center gap-2 text-sm py-1.5 px-2 rounded cursor-pointer",b.includes(p.value)?"bg-primary/5 text-primary":"hover:bg-muted"),children:[e.jsx("input",{type:"checkbox",checked:b.includes(p.value),onChange:()=>{const g=b.includes(p.value)?b.filter(C=>C!==p.value):[...b,p.value];h(x.field,g)},className:"rounded border-input"}),p.color&&e.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:p.color}}),e.jsx("span",{className:"truncate flex-1",children:p.label}),p.count!==void 0&&e.jsx("span",{className:"text-xs text-muted-foreground",children:p.count})]},String(p.value)))})})]},x.field)};return e.jsxs("div",{className:V("flex items-center gap-1 overflow-x-auto",d),"data-testid":"user-filters-dropdown",children:[e.jsx(pr,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),o.length===0?e.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"user-filters-empty",children:"No filter fields"}):e.jsxs(e.Fragment,{children:[n.map(j),N.length>0&&e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsxs("button",{"data-testid":"user-filters-more",className:"inline-flex items-center gap-1 rounded-full border border-border bg-background hover:bg-accent text-foreground h-7 px-2.5 text-xs font-medium transition-colors shrink-0",children:[e.jsx("span",{children:"More"}),e.jsx("span",{className:"flex h-4 min-w-[16px] items-center justify-center rounded-full bg-muted text-[10px] font-medium",children:N.length}),e.jsx(Dt,{className:"h-3 w-3 opacity-60"})]})}),e.jsx(bt,{align:"start",className:"w-64 p-2","data-testid":"user-filters-more-content",children:e.jsx("div",{className:"space-y-1",children:N.map(j)})})]})]})]})}function ol({tabs:t,showAllRecords:s,allowAddTab:a,onFilterChange:r,className:l}){const[d,c]=m.useState(()=>t.find(h=>h.default)?.id||(s?"__all__":t[0]?.id||"")),i=m.useCallback(u=>{if(c(u),u==="__all__")r([]);else{const h=t.find(n=>n.id===u);r(h?.filters||[])}},[t,r]),o=m.useMemo(()=>{const u=[...t];return s&&u.push({id:"__all__",label:"All records",filters:[]}),u},[t,s]);return m.useEffect(()=>{const u=t.find(h=>h.default);u&&r(u.filters||[])},[]),e.jsxs("div",{className:V("flex items-center gap-0.5 overflow-x-auto",l),"data-testid":"user-filters-tabs",children:[o.map(u=>e.jsx("button",{"data-testid":`filter-tab-${u.id}`,onClick:()=>i(u.id),className:V("inline-flex items-center h-7 px-3 text-xs font-medium rounded-md transition-colors shrink-0",d===u.id?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground hover:bg-muted"),children:u.label},u.id)),a&&e.jsx("button",{className:"inline-flex items-center justify-center h-7 w-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted shrink-0","data-testid":"filter-tab-add",title:"Add filter tab",children:e.jsx(Qe,{className:"h-3.5 w-3.5"})})]})}function cl({fields:t,onFilterChange:s,className:a}){const[r,l]=m.useState(()=>{const i=new Set;return t.forEach(o=>{o.defaultValues&&o.defaultValues.length>0&&i.add(o.field)}),i}),d=m.useCallback(i=>{const o=Array.from(i).map(u=>{const h=t.find(n=>n.field===u);return h?.defaultValues?[u,"in",h.defaultValues]:[u,"!=",null]});s(o)},[t,s]),c=i=>{l(o=>{const u=new Set(o);return u.has(i)?u.delete(i):u.add(i),d(u),u})};return m.useEffect(()=>{r.size>0&&d(r)},[]),e.jsx("div",{className:V("flex items-center gap-1 overflow-x-auto",a),"data-testid":"user-filters-toggle",children:t.map(i=>{const o=r.has(i.field);return e.jsx(B,{variant:o?"default":"outline",size:"sm",className:"h-7 px-3 text-xs shrink-0","data-testid":`filter-toggle-${i.field}`,onClick:()=>c(i.field),children:i.label||i.field},i.field)})})}const _s={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},Et=["xs","sm","md","lg","xl","2xl"];function dl(t){for(let s=Et.length-1;s>=0;s--){const a=Et[s];if(t>=_s[a])return a}return"xs"}function ul(){const[t,s]=m.useState(()=>typeof window<"u"?window.innerWidth:1024);m.useEffect(()=>{if(typeof window>"u")return;let l;const d=()=>{clearTimeout(l),l=setTimeout(()=>{s(window.innerWidth)},100)};return window.addEventListener("resize",d),()=>{clearTimeout(l),window.removeEventListener("resize",d)}},[]);const a=dl(t),r=Et.indexOf(a);return{breakpoint:a,width:t,isMobile:r<Et.indexOf("md"),isTablet:r>=Et.indexOf("md")&&r<Et.indexOf("lg"),isDesktop:r>=Et.indexOf("lg"),isAbove:l=>t>=_s[l],isBelow:l=>t<_s[l]}}function fl(t){const{onRefresh:s,threshold:a=80,enabled:r=!0}=t,l=m.useRef(null),[d,c]=m.useState(!1),[i,o]=m.useState(0),u=m.useRef(0),h=m.useCallback(j=>{if(!r||d)return;const x=l.current;x&&x.scrollTop===0&&(u.current=j.touches[0].clientY)},[r,d]),n=m.useCallback(j=>{if(!r||d||!u.current)return;const b=j.touches[0].clientY-u.current;b>0&&o(Math.min(b,a*1.5))},[r,d,a]),N=m.useCallback(async()=>{if(!r||d)return;const j=i;if(o(0),u.current=0,j>=a){c(!0);try{await s()}finally{c(!1)}}},[r,d,i,a,s]);return m.useEffect(()=>{const j=l.current;if(!(!j||!r))return j.addEventListener("touchstart",h,{passive:!0}),j.addEventListener("touchmove",n,{passive:!0}),j.addEventListener("touchend",N,{passive:!0}),()=>{j.removeEventListener("touchstart",h),j.removeEventListener("touchmove",n),j.removeEventListener("touchend",N)}},[h,n,N,r]),{ref:l,isRefreshing:d,pullDistance:i}}const Or=m.createContext(null);Or.displayName="MobileContext";function Lo({pwa:t,offline:s,children:a}){const r=ul(),l=m.useMemo(()=>({...r,pwa:t,offline:s}),[r,t,s]);return e.jsx(Or.Provider,{value:l,children:a})}function ml(t){switch(t){case"equals":case"eq":return"=";case"notEquals":case"ne":case"neq":return"!=";case"contains":return"contains";case"notContains":return"notcontains";case"greaterThan":case"gt":return">";case"greaterOrEqual":case"gte":return">=";case"lessThan":case"lt":return"<";case"lessOrEqual":case"lte":return"<=";case"in":return"in";case"notIn":return"not in";case"before":return"<";case"after":return">";default:return t}}function Tr(t){if(!Array.isArray(t)||t.length<3)return t;const[s,a,r]=t;return typeof s=="string"&&(s==="and"||s==="or")?[s,...t.slice(1).map(l=>Array.isArray(l)?Tr(l):l)]:a==="in"&&Array.isArray(r)?r.length===0?[]:r.length===1?[s,"=",r[0]]:["or",...r.map(l=>[s,"=",l])]:a==="not in"&&Array.isArray(r)?r.length===0?[]:r.length===1?[s,"!=",r[0]]:["and",...r.map(l=>[s,"!=",l])]:t}function pl(t){return t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase())}function Pr(t){return!Array.isArray(t)||t.length===0?[]:t.map(s=>Array.isArray(s)?Tr(s):s).filter(s=>Array.isArray(s)&&s.length>0)}function hl(t){if(!t||!t.conditions||t.conditions.length===0)return[];const s=t.conditions.map(r=>r.operator==="isEmpty"?[r.field,"=",null]:r.operator==="isNotEmpty"?[r.field,"!=",null]:[r.field,ml(r.operator),r.value]),a=Pr(s);return a.length===0?[]:a.length===1?a[0]:[t.logic,...a]}const ha={"list.recordCount":"{{count}} records","list.recordCountOne":"{{count}} record","list.noItems":"No items found","list.noItemsMessage":"There are no records to display. Try adjusting your filters or adding new data.","list.search":"Search","list.filter":"Filter","list.filterRecords":"Filter Records","list.sort":"Sort","list.sortRecords":"Sort Records","list.group":"Group","list.groupBy":"Group By","list.export":"Export","list.exportAs":"Export as {{format}}","list.color":"Color","list.rowColor":"Row Color","list.colorByField":"Color by field","list.clear":"Clear","list.none":"None","list.hideFields":"Hide fields","list.showAll":"Show all","list.pullToRefresh":"Pull to refresh","list.refreshing":"Refreshing…","list.dataLimitReached":"Showing first {{limit}} records. More data may be available.","list.addRecord":"Add record","list.tabs":"Tabs","list.allRecords":"All Records","list.share":"Share","list.print":"Print","list.hideFieldsTitle":"Hide Fields"};function xl(){try{const t=Fr();return t.t("list.recordCount")==="list.recordCount"?{t:(a,r)=>{let l=ha[a]||a;if(r)for(const[d,c]of Object.entries(r))l=l.replace(`{{${d}}}`,String(c));return l}}:{t:t.t}}catch{return{t:(t,s)=>{let a=ha[t]||t;if(s)for(const[r,l]of Object.entries(s))a=a.replace(`{{${r}}}`,String(l));return a}}}}function gl(){try{const{fieldLabel:t}=Zn();return{fieldLabel:t}}catch{return{fieldLabel:(t,s,a)=>a}}}const Er=({schema:t,className:s,onViewChange:a,onFilterChange:r,onSortChange:l,onSearchChange:d,onRowClick:c,showViewSwitcher:i=!1,...o})=>{const{t:u}=xl(),{fieldLabel:h}=gl(),n=m.useMemo(()=>({...t,viewType:t.viewType||"grid"}),[t]),N=m.useCallback((y,P)=>n.objectName?h(n.objectName,y,P):P,[n.objectName,h]),j=m.useMemo(()=>{const y=n.userActions,P=n.addRecord?.enabled===!0&&y?.addRecordForm!==!1;return{showSearch:y?.search!==void 0?y.search:n.showSearch!==!1,showSort:y?.sort!==void 0?y.sort:n.showSort!==!1,showFilters:y?.filter!==void 0?y.filter:n.showFilters!==!1,showDensity:y?.rowHeight!==void 0?y.rowHeight:n.showDensity===!0,showHideFields:n.showHideFields===!0,showGroup:n.showGroup!==!1,showColor:n.showColor===!0,showAddRecord:P,addRecordPosition:n.addRecord?.position==="bottom"?"bottom":"top"}},[n.userActions,n.showSearch,n.showSort,n.showFilters,n.showDensity,n.showHideFields,n.showGroup,n.showColor,n.addRecord,n.userActions?.addRecordForm]),[x,b]=m.useState(n.viewType),[f,p]=m.useState(""),[g,C]=m.useState(!1),[k,F]=m.useState(!1),[D,w]=m.useState(()=>n.sort&&n.sort.length>0?n.sort.map(y=>{if(typeof y=="string"){const P=y.trim().split(/\s+/);return{id:crypto.randomUUID(),field:P[0],order:P[1]?.toLowerCase()==="desc"?"desc":"asc"}}return{id:crypto.randomUUID(),field:y.field,order:y.order||"asc"}}):[]),[S,z]=m.useState(!1),[M,O]=m.useState({id:"root",logic:"and",conditions:[]}),[A,$]=m.useState(()=>!n.tabs||n.tabs.length===0?void 0:n.tabs.find(P=>P.isDefault)?.name??n.tabs[0]?.name),L=m.useCallback(y=>{if($(y.name),y.filter){const P={id:`tab-filter-${y.name}`,logic:y.filter.logic||"and",conditions:y.filter.conditions||[]};O(P),r?.(P)}else{const P={id:"root",logic:"and",conditions:[]};O(P),r?.(P)}},[r]),T=o.dataSource,[R,v]=m.useState([]),[E,I]=m.useState(!1),[W,le]=m.useState(null),[pe,de]=m.useState(!1),[Z,me]=m.useState(0),[Y,ee]=m.useState(!1),[ue,te]=m.useState(void 0),ae=ue??n.pagination?.pageSize??100,[G,H]=m.useState(n.grouping),[X,J]=m.useState(!1),[he,ge]=m.useState(n.rowColor),[Pe,Ue]=m.useState(!1),[be,xe]=m.useState([]),Re=m.useRef(0),[Ne,We]=m.useState(()=>{const y=new Set;return n.quickFilters?.forEach(P=>{const _=mn(P);_.defaultActive&&y.add(_.id)}),y}),[Ft,Ye]=m.useState([]),ct=m.useMemo(()=>{if(n.userFilters)return n.userFilters;if(!W?.fields)return;const y=new Set(["select","multi-select","boolean"]),P=[],_=Array.isArray(W.fields)?W.fields.map(q=>[q.name,q]):Object.entries(W.fields);for(const[q,U]of _)(y.has(U.type)||U.options&&!U.type)&&P.push({field:q,label:N(q,U.label||q),type:U.type==="boolean"?"boolean":U.type==="multi-select"?"multi-select":"select"});if(P.length!==0)return{element:"dropdown",fields:P}},[n.userFilters,W]),[Ae,Ve]=m.useState(()=>new Set(n.hiddenFields||[])),[jt,wt]=m.useState(!1),[st,Ge]=m.useState(!1),Xe=m.useMemo(()=>pn(n.quickFilters),[n.quickFilters]),Ke=m.useMemo(()=>{if(n.exportOptions)return Array.isArray(n.exportOptions)?{formats:n.exportOptions}:n.exportOptions},[n.exportOptions]),_t=m.useMemo(()=>n.densityMode?n.densityMode:n.rowHeight?{compact:"compact",short:"compact",medium:"comfortable",tall:"spacious",extra_tall:"spacious"}[n.rowHeight]||"comfortable":"compact",[n.densityMode,n.rowHeight]),dt=hn(_t),Le=m.useCallback(async()=>{me(y=>y+1)},[]),{ref:Gt,isRefreshing:It,pullDistance:Ze}=fl({onRefresh:Le,enabled:!!T&&!!n.objectName}),Ot=m.useMemo(()=>n.id?`listview-${n.objectName}-${n.id}-view`:`listview-${n.objectName}-view`,[n.objectName,n.id]);m.useEffect(()=>{let y=!0;return de(!1),le(null),(async()=>{if(!T||!n.objectName){de(!0);return}try{const _=await T.getObjectSchema(n.objectName);y&&le(_)}catch(_){console.warn("Failed to fetch object schema for ListView:",_)}finally{y&&de(!0)}})(),()=>{y=!1}},[n.objectName,T]);const re=m.useMemo(()=>Bs(W?.fields,n.fields),[W?.fields,n.fields]);m.useEffect(()=>{let y=!0;const P=++Re.current;if(n.data&&typeof n.data=="object"&&!Array.isArray(n.data)){const q=n.data;if(q.provider==="value"&&Array.isArray(q.items)){let U=q.items;if(f){const K=f.toLowerCase();U=U.filter(Q=>Object.values(Q).some(oe=>oe!=null&&String(oe).toLowerCase().includes(K)))}v(U),I(!1),ee(!1);return}}if(Array.isArray(n.data)){let q=n.data;if(f){const U=f.toLowerCase();q=q.filter(K=>Object.values(K).some(Q=>Q!=null&&String(Q).toLowerCase().includes(U)))}v(q),I(!1),ee(!1);return}return pe?((async()=>{if(!(!T||!n.objectName)){I(!0);try{let q=[];const U=n.filters||[],K=hl(M),Q=[];Xe&&Ne.size>0&&Xe.forEach(Fe=>{Ne.has(Fe.id)&&Fe.filters&&Fe.filters.length>0&&Q.push(Fe.filters)});const oe=Pr(Ft),se=[...U.length>0?[U]:[],...K.length>0?[K]:[],...Q,...oe].filter(Fe=>Array.isArray(Fe)&&Fe.length>0);se.length>1?q=["and",...se]:se.length===1&&(q=se[0]);const ke=D.length>0?D.filter(Fe=>Fe.field).map(Fe=>({field:Fe.field,order:Fe.order})):void 0,ze=await T.find(n.objectName,{$filter:q,$orderby:ke,$top:ae,...re.length>0?{$expand:re}:{},...f?{$search:f,...n.searchableFields&&n.searchableFields.length>0?{$searchFields:n.searchableFields}:{}}:{}});if(!y||P!==Re.current)return;let je=[];Array.isArray(ze)?je=ze:ze&&typeof ze=="object"&&(Array.isArray(ze.data)?je=ze.data:Array.isArray(ze.records)&&(je=ze.records)),v(je),ee(je.length>=ae)}catch(q){P===Re.current&&console.error("ListView data fetch error:",q)}finally{y&&P===Re.current&&I(!1)}}})(),()=>{y=!1}):void 0},[n.objectName,n.data,T,n.filters,ae,D,M,Ne,Xe,Ft,Z,f,n.searchableFields,re,pe]);const ie=m.useMemo(()=>{if(n.appearance?.allowedVisualizations&&n.appearance.allowedVisualizations.length>0)return n.appearance.allowedVisualizations.filter(P=>["grid","kanban","gallery","calendar","timeline","gantt","map"].includes(P));const y=["grid"];return(n.kanban?.groupField||n.options?.kanban?.groupField)&&y.push("kanban"),(n.gallery?.coverField||n.gallery?.imageField||n.options?.gallery?.imageField)&&y.push("gallery"),(n.calendar?.startDateField||n.options?.calendar?.startDateField)&&y.push("calendar"),(n.timeline?.startDateField||n.options?.timeline?.startDateField||n.options?.timeline?.dateField||n.options?.calendar?.startDateField)&&y.push("timeline"),(n.gantt?.startDateField||n.options?.gantt?.startDateField)&&y.push("gantt"),(n.options?.map?.locationField||n.options?.map?.latitudeField&&n.options?.map?.longitudeField)&&y.push("map"),n.viewType&&!y.includes(n.viewType)&&["grid","kanban","calendar","timeline","gantt","map","gallery"].includes(n.viewType)&&y.push(n.viewType),y},[n.options,n.viewType,n.kanban,n.calendar,n.gantt,n.gallery,n.timeline,n.appearance?.allowedVisualizations]);m.useEffect(()=>{n.viewType&&b(n.viewType)},[n.viewType]);const ye=m.useCallback(y=>{b(y);try{localStorage.setItem(Ot,y)}catch(P){console.warn("Failed to save view preference to localStorage:",P)}a?.(y)},[Ot,a]),fe=m.useCallback(y=>{p(y),d?.(y)},[d]),ve=nr({navigation:n.navigation,objectName:n.objectName,onNavigate:n.onNavigate,onRowClick:c}),Ce=m.useMemo(()=>{let y=n.fields||[];if(Array.isArray(y)||(y=[]),Ae.size>0&&(y=y.filter(P=>{const _=typeof P=="string"?P:P?.name||P?.fieldName||P?.field;return _!=null&&!Ae.has(_)})),n.fieldOrder&&n.fieldOrder.length>0){const P=new Map(n.fieldOrder.map((_,q)=>[_,q]));y=[...y].sort((_,q)=>{const U=typeof _=="string"?_:_?.name||_?.fieldName||_?.field,K=typeof q=="string"?q:q?.name||q?.fieldName||q?.field,Q=P.get(U)??1/0,oe=P.get(K)??1/0;return Q-oe})}return y},[n.fields,Ae,n.fieldOrder]),Me=m.useMemo(()=>{const y={objectName:n.objectName,fields:Ce,filters:n.filters,sort:D,className:"h-full w-full",showSearch:!1,onRowClick:ve.handleClick,...n.striped!=null?{striped:n.striped}:{},...n.bordered!=null?{bordered:n.bordered}:{}};switch(x){case"grid":return{type:"object-grid",...y,columns:Ce,...n.conditionalFormatting?{conditionalFormatting:n.conditionalFormatting}:{},...n.inlineEdit!=null?{editable:n.inlineEdit}:{},...n.wrapHeaders!=null?{wrapHeaders:n.wrapHeaders}:{},...n.virtualScroll!=null?{virtualScroll:n.virtualScroll}:{},...n.resizable!=null?{resizable:n.resizable}:{},...n.selection?{selection:n.selection}:{},...n.pagination?{pagination:n.pagination}:{},...G?{grouping:G}:{},...he?{rowColor:he}:{},...n.rowActions?{rowActions:n.rowActions}:{},...n.bulkActions?{batchActions:n.bulkActions}:{},...n.options?.grid||{}};case"kanban":return{type:"object-kanban",...y,groupBy:n.kanban?.groupField||n.options?.kanban?.groupField||"status",groupField:n.kanban?.groupField||n.options?.kanban?.groupField||"status",titleField:n.kanban?.titleField||n.options?.kanban?.titleField||"name",cardFields:n.kanban?.cardFields||Ce||[],...G?{grouping:G}:{},...n.options?.kanban||{},...n.kanban||{}};case"calendar":return{type:"object-calendar",...y,startDateField:n.calendar?.startDateField||n.options?.calendar?.startDateField||"start_date",endDateField:n.calendar?.endDateField||n.options?.calendar?.endDateField||"end_date",titleField:n.calendar?.titleField||n.options?.calendar?.titleField||"name",...n.calendar?.defaultView?{defaultView:n.calendar.defaultView}:{},...n.options?.calendar||{},...n.calendar||{}};case"gallery":{const P={...n.options?.gallery||{},...n.gallery||{}};return{type:"object-gallery",...y,gallery:Object.keys(P).length>0?P:void 0,imageField:n.gallery?.coverField||n.gallery?.imageField||n.options?.gallery?.imageField,titleField:n.gallery?.titleField||n.options?.gallery?.titleField||"name",subtitleField:n.gallery?.subtitleField||n.options?.gallery?.subtitleField,...G?{grouping:G}:{}}}case"timeline":{const P={...n.options?.timeline||{},...n.timeline||{}};return{type:"object-timeline",...y,timeline:Object.keys(P).length>0?P:void 0,startDateField:n.timeline?.startDateField||n.options?.timeline?.startDateField||n.options?.timeline?.dateField||"created_at",titleField:n.timeline?.titleField||n.options?.timeline?.titleField||"name",...n.timeline?.endDateField?{endDateField:n.timeline.endDateField}:{},...n.timeline?.groupByField?{groupByField:n.timeline.groupByField}:{},...n.timeline?.colorField?{colorField:n.timeline.colorField}:{},...n.timeline?.scale?{scale:n.timeline.scale}:{}}}case"gantt":return{type:"object-gantt",...y,startDateField:n.gantt?.startDateField||n.options?.gantt?.startDateField||"start_date",endDateField:n.gantt?.endDateField||n.options?.gantt?.endDateField||"end_date",progressField:n.gantt?.progressField||n.options?.gantt?.progressField||"progress",dependenciesField:n.gantt?.dependenciesField||n.options?.gantt?.dependenciesField||"dependencies",...n.gantt?.titleField?{titleField:n.gantt.titleField}:{},...n.options?.gantt||{},...n.gantt||{}};case"map":return{type:"object-map",...y,locationField:n.options?.map?.locationField||"location",...n.options?.map||{}};default:return y}},[x,n,D,Ce,G,he,ve.handleClick]),Ee=M.conditions&&M.conditions.length>0,_e=m.useMemo(()=>{let y;if(W?.fields?y=Object.entries(W.fields).map(([P,_])=>({value:P,label:N(P,_.label||P),type:_.type||"text",options:_.options})):y=(n.fields||[]).map(P=>{if(typeof P=="string")return{value:P,label:P,type:"text"};const _=P.name||P.fieldName;return{value:_,label:N(_,P.label||P.name),type:P.type||"text",options:P.options}}),n.filterableFields&&n.filterableFields.length>0){const P=new Set(n.filterableFields);y=y.filter(_=>P.has(_.value))}return y},[W,n.fields,n.filterableFields]),He=m.useCallback(y=>{We(P=>{const _=new Set(P);return _.has(y)?_.delete(y):_.add(y),_})},[]),at=m.useCallback(y=>{const P=Ke,_=P?.maxRecords||0,q=P?.includeHeaders!==!1,U=P?.fileNamePrefix||n.objectName||"export",K=_>0?R.slice(0,_):R;if(y==="csv"){const Q=Ce.map(je=>typeof je=="string"?je:je.name||je.fieldName||je.field),oe=[];q&&oe.push(Q.join(",")),K.forEach(je=>{oe.push(Q.map(Fe=>{const et=je[Fe];let ne;return et==null?ne="":Array.isArray(et)?ne=et.map(ut=>ut!=null&&typeof ut=="object"?JSON.stringify(ut):String(ut??"")).join("; "):typeof et=="object"?ne=JSON.stringify(et):ne=String(et),ne.includes(",")||ne.includes('"')||ne.includes(`
2
+ `)||ne.includes("\r")?`"${ne.replace(/"/g,'""')}"`:ne}).join(","))});const se=new Blob([oe.join(`
3
+ `)],{type:"text/csv;charset=utf-8;"}),ke=URL.createObjectURL(se),ze=document.createElement("a");ze.href=ke,ze.download=`${U}.csv`,ze.click(),URL.revokeObjectURL(ke)}else if(y==="json"){const Q=new Blob([JSON.stringify(K,null,2)],{type:"application/json"}),oe=URL.createObjectURL(Q),se=document.createElement("a");se.href=oe,se.download=`${U}.json`,se.click(),URL.revokeObjectURL(oe)}Ge(!1)},[R,Ce,Ke,n.objectName]),Je=m.useMemo(()=>(n.fields||[]).map(y=>{if(typeof y=="string")return{name:y,label:N(y,y)};const P=y.name||y.fieldName||y.field,_=y.label||y.name||y.field;return{name:P,label:N(P,_)}}),[n.fields,N]);return e.jsxs("div",{ref:Gt,className:V("flex flex-col h-full bg-background relative min-w-0 overflow-hidden",s),...n.aria?.label?{"aria-label":n.aria.label}:{},...n.aria?.describedBy?{"aria-describedby":n.aria.describedBy}:{},...n.aria?.live?{"aria-live":n.aria.live}:{},role:"region",children:[Ze>0&&e.jsx("div",{className:"flex items-center justify-center text-xs text-muted-foreground",style:{height:Ze},children:u(It?"list.refreshing":"list.pullToRefresh")}),i&&e.jsx("div",{className:"border-b px-4 py-1 flex items-center bg-background",children:e.jsx(tl,{currentView:x,availableViews:ie,onViewChange:ye})}),n.tabs&&n.tabs.length>0&&e.jsx(rl,{tabs:n.tabs,activeTab:A,onTabChange:L}),n.description&&n.appearance?.showDescription!==!1&&e.jsx("div",{className:"border-b px-4 py-1.5 text-xs text-muted-foreground bg-background","data-testid":"view-description",children:typeof n.description=="string"?n.description:""}),e.jsxs("div",{className:"border-b px-2 sm:px-4 py-1 flex items-center justify-between gap-1 sm:gap-2 bg-background",children:[e.jsx("div",{className:"flex items-center gap-0.5 overflow-x-auto min-w-0",children:ct&&e.jsx("div",{className:"shrink-0 min-w-0","data-testid":"user-filters",children:e.jsx(nl,{config:ct,objectDef:W,data:R,onFilterChange:Ye,maxVisible:3})})}),e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[j.showHideFields&&e.jsxs(xt,{open:jt,onOpenChange:wt,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",Ae.size>0&&"text-primary"),children:[e.jsx(Fn,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.hideFields")}),Ae.size>0&&e.jsx("span",{className:"ml-1 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-primary/10 text-[10px] font-medium text-primary",children:Ae.size})]})}),e.jsx(bt,{align:"start",className:"w-64 p-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:u("list.hideFieldsTitle")}),Ae.size>0&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>Ve(new Set),children:u("list.showAll")})]}),e.jsx("div",{className:"max-h-60 overflow-y-auto space-y-1",children:Je.map(y=>e.jsxs("label",{className:"flex items-center gap-2 text-sm py-1 px-1 rounded hover:bg-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!Ae.has(y.name),onChange:()=>{Ve(P=>{const _=new Set(P);return _.has(y.name)?_.delete(y.name):_.add(y.name),_})},className:"rounded border-input"}),e.jsx("span",{className:"truncate",children:y.label})]},y.name))})]})})]}),j.showHideFields&&(j.showFilters||j.showSort||j.showGroup)&&e.jsx("div",{className:"h-4 w-px bg-border/60 mx-0.5 shrink-0"}),j.showFilters&&e.jsxs(xt,{open:S,onOpenChange:z,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",Ee&&"bg-primary/10 border border-primary/20 text-primary"),children:[e.jsx(pr,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.filter")}),Ee&&e.jsx("span",{className:"ml-1 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-primary/10 text-[10px] font-medium text-primary",children:M.conditions?.length||0})]})}),e.jsx(bt,{align:"start",className:"w-[calc(100vw-2rem)] sm:w-[600px] max-w-[600px] p-3 sm:p-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between border-b pb-2",children:e.jsx("h4",{className:"font-medium text-sm",children:u("list.filterRecords")})}),e.jsx(bn,{fields:_e,value:M,onChange:y=>{O(y),r&&r(y)}})]})})]}),j.showGroup&&e.jsxs(xt,{open:X,onOpenChange:J,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",G&&"bg-primary/10 border border-primary/20 text-primary"),children:[e.jsx(On,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.group")}),G&&G.fields?.length>0&&e.jsx("span",{className:"ml-1 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-primary/10 text-[10px] font-medium text-primary",children:G.fields.length})]})}),e.jsx(bt,{align:"start",className:"w-64 p-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:u("list.groupBy")}),G&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>H(void 0),"data-testid":"clear-grouping",children:u("list.clear")})]}),e.jsx("div",{className:"max-h-60 overflow-y-auto space-y-1","data-testid":"group-field-list",children:Je.map(y=>{const P=G?.fields?.some(_=>_.field===y.name);return e.jsxs("label",{className:"flex items-center gap-2 text-sm py-1 px-1 rounded hover:bg-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!!P,onChange:()=>{if(P){const _=(G?.fields||[]).filter(q=>q.field!==y.name);H(_.length>0?{fields:_}:void 0)}else{const _=G?.fields||[];H({fields:[..._,{field:y.name,order:"asc",collapsed:!1}]})}},className:"rounded border-input"}),e.jsx("span",{className:"truncate",children:y.label})]},y.name)})})]})})]}),j.showSort&&e.jsxs(xt,{open:k,onOpenChange:F,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",D.length>0&&"bg-primary/10 border border-primary/20 text-primary"),children:[e.jsx(hr,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.sort")}),D.length>0&&e.jsx("span",{className:"ml-1 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-primary/10 text-[10px] font-medium text-primary",children:D.length})]})}),e.jsx(bt,{align:"start",className:"w-[calc(100vw-2rem)] sm:w-[600px] max-w-[600px] p-3 sm:p-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between border-b pb-2",children:e.jsx("h4",{className:"font-medium text-sm",children:u("list.sortRecords")})}),e.jsx(yn,{fields:_e,value:D,onChange:y=>{w(y),l&&l(y)}})]})})]}),(j.showFilters||j.showSort||j.showGroup)&&(j.showColor||j.showDensity)&&e.jsx("div",{className:"h-4 w-px bg-border/60 mx-0.5 shrink-0"}),j.showColor&&e.jsxs(xt,{open:Pe,onOpenChange:Ue,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",he&&"bg-primary/10 border border-primary/20 text-primary"),children:[e.jsx(Tn,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.color")})]})}),e.jsx(bt,{align:"start",className:"w-64 p-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:u("list.rowColor")}),he&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>ge(void 0),"data-testid":"clear-row-color",children:u("list.clear")})]}),e.jsxs("div",{className:"space-y-2","data-testid":"color-field-list",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:u("list.colorByField")}),e.jsxs("select",{className:"w-full h-8 rounded border border-input bg-background px-2 text-xs",value:he?.field||"",onChange:y=>{const P=y.target.value;ge(P?{field:P,colors:he?.colors||{}}:void 0)},"data-testid":"color-field-select",children:[e.jsx("option",{value:"",children:u("list.none")}),Je.map(y=>e.jsx("option",{value:y.name,children:y.label},y.name))]})]})]})})]}),j.showDensity&&e.jsxs(B,{variant:"ghost",size:"sm",className:V("h-7 px-2 text-muted-foreground hover:text-primary text-xs hidden lg:flex transition-colors duration-150",dt.mode!=="compact"&&"bg-primary/10 border border-primary/20 text-primary"),onClick:dt.cycle,title:`Density: ${dt.mode}`,children:[e.jsx(Pn,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline capitalize",children:dt.mode})]}),(j.showColor||j.showDensity)&&Ke&&n.allowExport!==!1&&e.jsx("div",{className:"h-4 w-px bg-border/60 mx-0.5 shrink-0"}),Ke&&n.allowExport!==!1&&e.jsxs(xt,{open:st,onOpenChange:Ge,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(B,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",children:[e.jsx(Vt,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.export")})]})}),e.jsx(bt,{align:"start",className:"w-48 p-2",children:e.jsx("div",{className:"space-y-1",children:(Ke.formats||["csv","json"]).map(y=>e.jsxs(B,{variant:"ghost",size:"sm",className:"w-full justify-start h-8 text-xs",onClick:()=>at(y),children:[e.jsx(Vt,{className:"h-3.5 w-3.5 mr-2"}),u("list.exportAs",{format:y.toUpperCase()})]},y))})})]}),(n.sharing?.enabled||n.sharing?.type)&&e.jsxs(B,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",title:`Sharing: ${n.sharing?.visibility||n.sharing?.type||"private"}`,"data-testid":"share-button",children:[e.jsx(Ms,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.share")})]}),n.allowPrinting&&e.jsxs(B,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",onClick:()=>window.print(),"data-testid":"print-button",children:[e.jsx(xr,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.print")})]}),(()=>{const y=n.allowPrinting||n.sharing?.enabled||n.sharing?.type||Ke&&n.allowExport!==!1;return j.showSearch&&y?e.jsx("div",{className:"h-4 w-px bg-border/60 mx-0.5 shrink-0"}):null})(),j.showSearch&&e.jsxs(xt,{open:g,onOpenChange:C,children:[e.jsx(gt,{asChild:!0,children:e.jsx(B,{variant:"ghost",size:"sm",className:V("h-7 w-7 p-0 text-muted-foreground hover:text-primary text-xs transition-colors duration-150",f&&"bg-primary/10 border border-primary/20 text-primary"),"data-testid":"search-icon-button",title:u("list.search"),children:e.jsx(Ls,{className:"h-3.5 w-3.5"})})}),e.jsx(bt,{align:"end",className:"w-[calc(100vw-2rem)] sm:w-64 p-2","data-testid":"search-popover",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ls,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(qe,{placeholder:u("list.search")+"...",value:f,onChange:y=>fe(y.target.value),className:"pl-7 h-8 text-xs",autoFocus:!0}),f&&e.jsx(B,{variant:"ghost",size:"sm",className:"absolute right-0.5 top-1/2 -translate-y-1/2 h-5 w-5 p-0 hover:bg-muted-foreground/20",onClick:()=>fe(""),children:e.jsx(ss,{className:"h-3 w-3"})})]})})]}),j.showAddRecord&&j.addRecordPosition==="top"&&e.jsxs(B,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150","data-testid":"add-record-button",onClick:()=>o.onAddRecord?.(),children:[e.jsx(Qe,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.addRecord")})]})]})]}),Xe&&Xe.length>0&&e.jsx("div",{className:"border-b px-2 sm:px-4 py-1 flex items-center gap-1 flex-wrap bg-background","data-testid":"quick-filters",children:Xe.map(y=>{const P=Ne.has(y.id),_=y.icon?zs[y.icon.split("-").map(q=>q.charAt(0).toUpperCase()+q.slice(1)).join("")]??null:null;return e.jsxs(B,{variant:P?"default":"outline",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>He(y.id),children:[_&&e.jsx(_,{className:"h-3 w-3 mr-1.5"}),y.label]},y.id)})}),e.jsx("div",{className:"flex-1 min-h-0 bg-background relative overflow-hidden animate-in fade-in-0 duration-200",children:!E&&R.length===0?(()=>{const y=n.emptyState?.icon,P=y?zs[y.split("-").map(_=>_.charAt(0).toUpperCase()+_.slice(1)).join("")]??ua:ua;return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[200px] text-center p-8","data-testid":"empty-state",children:[e.jsx(P,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-foreground mb-1",children:(typeof n.emptyState?.title=="string"?n.emptyState.title:void 0)??"No items found"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-md",children:(typeof n.emptyState?.message=="string"?n.emptyState.message:void 0)??"There are no records to display. Try adjusting your filters or adding new data."})]})})():e.jsx(Ie,{schema:Me,...o,data:R,loading:E,onRowSelect:xe})},x),j.showAddRecord&&j.addRecordPosition==="bottom"&&e.jsx("div",{className:"border-t px-2 sm:px-4 py-1 bg-background shrink-0",children:e.jsxs(B,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs transition-colors duration-150","data-testid":"add-record-button",onClick:()=>o.onAddRecord?.(),children:[e.jsx(Qe,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:u("list.addRecord")})]})}),n.bulkActions&&n.bulkActions.length>0&&be.length>0&&x!=="grid"&&e.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:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[be.length," selected"]}),e.jsx("div",{className:"flex items-center gap-1 ml-2",children:n.bulkActions.map(y=>e.jsx(B,{variant:"outline",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o.onBulkAction?.(y,be),"data-testid":`bulk-action-${y}`,children:pl(y)},y))}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs ml-auto",onClick:()=>xe([]),children:"Clear"})]}),!E&&R.length>0&&n.showRecordCount!==!1&&e.jsxs("div",{className:"border-t px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground bg-background shrink-0","data-testid":"record-count-bar",children:[e.jsx("span",{children:R.length===1?u("list.recordCountOne",{count:R.length}):u("list.recordCount",{count:R.length})}),Y&&e.jsx("span",{className:"text-amber-600","data-testid":"data-limit-warning",children:u("list.dataLimitReached",{limit:ae})}),n.pagination?.pageSizeOptions&&n.pagination.pageSizeOptions.length>0&&e.jsx("select",{className:"ml-auto h-6 rounded border border-input bg-background px-1 text-xs",value:ae,onChange:y=>{const P=Number(y.target.value);te(P),o.onPageSizeChange&&o.onPageSizeChange(P)},"data-testid":"page-size-selector",children:n.pagination.pageSizeOptions.map(y=>e.jsxs("option",{value:y,children:[y," / page"]},y))})]}),ve.isOverlay&&e.jsx(ir,{...ve,title:n.label?`${n.label} Detail`:n.objectName?`${n.objectName.charAt(0).toUpperCase()+n.objectName.slice(1)} Detail`:"Record Detail",children:y=>e.jsx("div",{className:"space-y-3",children:Object.entries(y).map(([P,_])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:P.replace(/_/g," ")}),e.jsx("span",{className:"text-sm",children:String(_??"—")})]},P))})})]})},bl={small:"grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6",medium:"grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4",large:"grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3"},yl={small:"aspect-square",medium:"aspect-[4/3]",large:"aspect-[16/10]"},vl=t=>{const{schema:s}=t,a=m.useContext(Vs),r=t.dataSource||a?.dataSource,l=Hs(s.bind),[d,c]=m.useState([]),[i,o]=m.useState(!1),[u,h]=m.useState(null),n=nr({navigation:s.navigation,objectName:s.objectName,onRowClick:t.onRowClick??t.onCardClick}),N=s.gallery,j=N?.coverField??s.imageField??"image",x=N?.coverFit??"cover",b=N?.cardSize??"medium",f=N?.titleField??s.titleField??"name",p=N?.visibleFields;m.useEffect(()=>{let A=!0;return(async()=>{if(!(!r||typeof r.getObjectSchema!="function"||!s.objectName))try{const L=await r.getObjectSchema(s.objectName);A&&h(L)}catch(L){console.warn("Failed to fetch object def for ObjectGallery",L)}})(),()=>{A=!1}},[s.objectName,r]),m.useEffect(()=>{let A=!0;if(t.data&&Array.isArray(t.data)){c(t.data);return}const $=async()=>{if(!(!r||typeof r.find!="function"||!s.objectName)){A&&o(!0);try{const L=Bs(u?.fields),T=await r.find(s.objectName,{$filter:s.filter,...L.length>0?{$expand:L}:{}});let R=[];if(Array.isArray(T))R=T;else if(T&&typeof T=="object"){const v=T;Array.isArray(v.records)?R=v.records:Array.isArray(v.data)&&(R=v.data)}A&&c(R)}catch(L){console.error("[ObjectGallery] Fetch error:",L)}finally{A&&o(!1)}}};return s.objectName&&!l&&!s.data&&!t.data&&$(),()=>{A=!1}},[s.objectName,r,l,s.data,s.filter,t.data,u]);const g=t.data||l||s.data||d||[],C=s.grouping?.fields,k=!!(C&&C.length>0),[F,D]=m.useState({}),w=m.useMemo(()=>C?C.some(A=>A.collapsed):!1,[C]),S=m.useCallback(A=>{D($=>({...$,[A]:$[A]!==void 0?!$[A]:!w}))},[w]),z=m.useMemo(()=>{if(!k||!C)return[];const A=new Map,$=[];for(const T of g){const R=C.map(v=>String(T[v.field]??"")).join(" / ");if(!A.has(R)){const v=C.map(E=>{const I=T[E.field];return I!=null&&I!==""?String(I):"(empty)"}).join(" / ");A.set(R,{label:v,items:[]}),$.push(R)}A.get(R).items.push(T)}const L=C[0]?.order??"asc";return $.sort((T,R)=>{const v=T.localeCompare(R,void 0,{numeric:!0,sensitivity:"base"});return L==="desc"?-v:v}),$.map(T=>{const R=A.get(T),v=T in F?F[T]:w;return{key:T,label:R.label,items:R.items,collapsed:v}})},[g,C,k,F,w]);if(i&&!g.length)return e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading Gallery..."});if(!g.length)return e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No items to display"});const M=(A,$)=>{const L=A.id??A._id??$,T=String(A[f]??"Untitled"),R=A[j];return e.jsxs(Oe,{role:"listitem",className:V("group overflow-hidden transition-all hover:shadow-md",(t.onCardClick||t.onRowClick||s.navigation)&&"cursor-pointer"),onClick:()=>n.handleClick(A),children:[e.jsx("div",{className:V("w-full overflow-hidden bg-muted relative",yl[b]),children:R?e.jsx("img",{src:R,alt:T,className:V("h-full w-full transition-transform group-hover:scale-105",x==="cover"&&"object-cover",x==="contain"&&"object-contain")}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary/50 text-muted-foreground",children:e.jsx("span",{className:"text-4xl font-light opacity-20",children:T[0]?.toUpperCase()})})}),e.jsxs(Te,{className:"p-3 border-t",children:[e.jsx("h3",{className:"font-medium truncate text-sm",title:T,children:T}),p&&p.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:p.map(v=>{const E=A[v];return E==null?null:e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:String(E)},v)})})]})]},L)},O=A=>e.jsx("div",{className:V("grid gap-4 p-4",bl[b],s.className),role:"list",children:A.map(($,L)=>M($,L))});return e.jsxs(e.Fragment,{children:[k?e.jsx("div",{className:"space-y-2",children:z.map(A=>e.jsxs("div",{className:"border rounded-md",children:[e.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:()=>S(A.key),children:[A.collapsed?e.jsx(Mt,{className:"h-4 w-4 shrink-0"}):e.jsx(Dt,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:A.label}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:A.items.length})]}),!A.collapsed&&O(A.items)]},A.key))}):O(g),n.isOverlay&&e.jsx(ir,{...n,title:"Gallery Item",children:A=>e.jsx("div",{className:"space-y-3",children:Object.entries(A).map(([$,L])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:$.replace(/_/g," ")}),e.jsx("span",{className:"text-sm",children:String(L??"—")})]},$))})})]})};Se.register("object-gallery",vl,{namespace:"plugin-list",label:"Gallery View",category:"view"});Se.register("list-view",Er,{namespace:"plugin-list",label:"List View",category:"Views",icon:"LayoutList",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"viewType",type:"enum",label:"Default View",enum:[{label:"Grid",value:"grid"},{label:"Kanban",value:"kanban"},{label:"Gallery",value:"gallery"},{label:"Calendar",value:"calendar"},{label:"Timeline",value:"timeline"},{label:"Gantt",value:"gantt"},{label:"Map",value:"map"}],defaultValue:"grid"},{name:"fields",type:"array",label:"Fields"},{name:"filters",type:"array",label:"Filters"},{name:"sort",type:"array",label:"Sort"},{name:"options",type:"object",label:"View Options"}],defaultProps:{objectName:"",viewType:"grid",fields:[],filters:[],sort:[],options:{}}});Se.register("list",Er,{namespace:"view",category:"view",label:"List",icon:"LayoutList",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"viewType",type:"enum",label:"Default View",enum:[{label:"Grid",value:"grid"},{label:"Kanban",value:"kanban"},{label:"Gallery",value:"gallery"},{label:"Calendar",value:"calendar"},{label:"Timeline",value:"timeline"},{label:"Gantt",value:"gantt"},{label:"Map",value:"map"}],defaultValue:"grid"},{name:"fields",type:"array",label:"Fields"},{name:"filters",type:"array",label:"Filters"},{name:"sort",type:"array",label:"Sort"},{name:"options",type:"object",label:"View Options"}]});const jl=new Set(["textarea","markdown","html","grid","rich-text","field:textarea","field:markdown","field:html","field:grid","field:rich-text"]);function wl(t){return jl.has(t)}function Nl(t,s){let a;return t<=3?a=1:t<=10?a=2:a=3,a}function xa(t,s){return s<=1?t:t.map(a=>a.span!==void 0?a:a.type&&wl(a.type)?{...a,span:s}:a)}function Cl(t,s,a){if(s!==void 0)return{fields:xa(t,s),columns:s};const r=Nl(t.length);return{fields:xa(t,r),columns:r}}function Sl(t,s){return function(){try{const r=Fr();return r.t(s)===s?{t:(d,c)=>{let i=t[d]||d;if(c)for(const[o,u]of Object.entries(c))i=i.replace(`{{${o}}}`,String(u));return i}}:{t:r.t}}catch{return{t:(r,l)=>{let d=t[r]||r;if(l)for(const[c,i]of Object.entries(l))d=d.replace(`{{${c}}}`,String(i));return d}}}}}const kl={"detail.back":"Back","detail.edit":"Edit","detail.editInline":"Edit inline","detail.save":"Save","detail.saveChanges":"Save changes","detail.editFieldsInline":"Edit fields inline","detail.share":"Share","detail.duplicate":"Duplicate","detail.export":"Export","detail.viewHistory":"View history","detail.delete":"Delete","detail.moreActions":"More actions","detail.addToFavorites":"Add to favorites","detail.removeFromFavorites":"Remove from favorites","detail.previousRecord":"Previous record","detail.nextRecord":"Next record","detail.recordOf":"{{current}} of {{total}}","detail.recordNotFound":"Record not found","detail.recordNotFoundDescription":"The record you are looking for does not exist or may have been deleted.","detail.goBack":"Go back","detail.details":"Details","detail.related":"Related","detail.relatedRecords":"{{count}} records","detail.relatedRecordOne":"{{count}} record","detail.noRelatedRecords":"No related records found","detail.loading":"Loading...","detail.copyToClipboard":"Copy to clipboard","detail.copied":"Copied!","detail.deleteConfirmation":"Are you sure you want to delete this record?","detail.editRecord":"Edit record","detail.viewAll":"View All","detail.new":"New","detail.emptyValue":"—","detail.activity":"Activity","detail.editRow":"Edit","detail.deleteRow":"Delete","detail.deleteRowConfirmation":"Are you sure you want to delete this record?","detail.actions":"Actions","detail.previousPage":"Previous","detail.nextPage":"Next","detail.pageOf":"Page {{current}} of {{total}}","detail.sortBy":"Sort by","detail.filterPlaceholder":"Filter...","detail.highlightFields":"Key Fields"},Zs=Sl(kl,"detail.back");function Dl(t,s){return!t||t<=1||s<=1?"":s===2?t>=2?"md:col-span-2":"":t===2?"md:col-span-2":t>=3?"md:col-span-2 lg:col-span-3":""}const $t=({section:t,data:s,className:a,objectSchema:r,objectName:l,isEditing:d=!1,onFieldChange:c,virtualScroll:i})=>{const[o,u]=m.useState(t.defaultCollapsed??!1),[h,n]=m.useState(null),[N,j]=m.useState(void 0),{t:x}=Zs(),{fieldLabel:b}=Qs(),f=m.useCallback((M,O)=>{const A=O!=null?String(O):"";navigator.clipboard.writeText(A).then(()=>{n(M),setTimeout(()=>n(null),2e3)})},[]),p=t.hideEmpty?t.fields.filter(M=>{const O=s?.[M.name]??M.value;return O!=null&&O!==""}):t.fields;if(p.length===0)return null;const{fields:g,columns:C}=Cl(p,t.columns),k=M=>{const O=s?.[M.name]??M.value;if(M.render)return e.jsx(Ie,{schema:M.render,data:{...s,value:O}});const A=Dl(M.span,C),$=(()=>{if(O==null)return e.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"});const R=r?.fields?.[M.name],v=M.type||R?.type,E={...M};if(R){!M.type&&R.type&&(E.type=R.type),R.options&&!E.options&&(E.options=R.options),R.currency&&!E.currency&&(E.currency=R.currency),R.precision!==void 0&&E.precision===void 0&&(E.precision=R.precision),R.format&&!E.format&&(E.format=R.format);const I=R.reference_to||R.reference;I&&!E.reference_to&&(E.reference_to=I),R.reference_field&&!E.reference_field&&(E.reference_field=R.reference_field)}if(v){const I=qs(v);if(I)return e.jsx(I,{value:O,field:E})}return String(O)})(),L=O!=null&&O!=="",T=h===M.name;return e.jsxs("div",{className:V("space-y-1.5 group",A),children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:b(l||"",M.name,M.label||M.name)}),d&&!M.readonly?e.jsx("div",{className:"min-h-[44px] sm:min-h-0",children:e.jsx("input",{type:M.type==="number"?"number":M.type==="date"?"date":"text",className:"w-full px-2 py-1.5 text-sm border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring",value:O!=null?String(O):"",onChange:R=>c?.(M.name,R.target.value)})}):e.jsxs("div",{className:V("flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md",L&&"cursor-pointer active:bg-muted/60 transition-colors"),onClick:L?()=>f(M.name,O):void 0,onKeyDown:L?R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),f(M.name,O))}:void 0,role:L?"button":void 0,tabIndex:L?0:void 0,children:[e.jsx("div",{className:"text-sm flex-1 break-words py-1",children:$}),L&&e.jsx(ur,{children:e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",onClick:R=>{R.stopPropagation(),f(M.name,O)},children:T?e.jsx(gr,{className:"h-3 w-3 text-green-600"}):e.jsx(br,{className:"h-3 w-3"})})}),e.jsx(ht,{children:x(T?"detail.copied":"detail.copyToClipboard")})]})})]})]},M.name)},F=i?.enabled===!0,D=i?.batchSize??20,w=100;m.useEffect(()=>{if(!F){j(void 0);return}if(g.length<=D){j(void 0);return}j(D);const M=setTimeout(()=>j(void 0),w);return()=>clearTimeout(M)},[F,g.length,D]);const S=N!==void 0?g.slice(0,N):g,z=e.jsx("div",{className:V("grid gap-3 sm:gap-4",C===1?"grid-cols-1":C===2?"grid-cols-1 md:grid-cols-2":"grid-cols-1 md:grid-cols-2 lg:grid-cols-3"),children:S.map(k)});return t.collapsible?e.jsx(or,{open:!o,onOpenChange:M=>u(!M),className:a,children:e.jsxs(Oe,{children:[e.jsx(cr,{asChild:!0,children:e.jsxs($e,{className:V("cursor-pointer hover:bg-muted/50 transition-colors",t.headerColor&&`bg-${t.headerColor}`),children:[e.jsxs(Be,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[t.icon&&e.jsx("span",{className:"text-muted-foreground",children:t.icon}),e.jsx("span",{children:t.title}),t.fields&&e.jsx(St,{variant:"secondary",className:"ml-2 text-xs",children:t.fields.length})]}),e.jsx("div",{className:"flex items-center gap-2",children:o?e.jsx(Mt,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground"})})]}),t.description&&!o&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1.5",children:t.description})]})}),e.jsx(dr,{children:e.jsx(Te,{className:"pt-4 sm:pt-6 px-3 sm:px-6",children:z})})]})}):e.jsxs(Oe,{className:V(t.showBorder===!1?"border-none shadow-none":"",a),children:[t.title&&e.jsxs($e,{className:V(t.headerColor&&`bg-${t.headerColor}`),children:[e.jsx(Be,{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[t.icon&&e.jsx("span",{className:"text-muted-foreground",children:t.icon}),e.jsx("span",{children:t.title}),t.fields&&e.jsx(St,{variant:"secondary",className:"ml-2 text-xs",children:t.fields.length})]})}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1.5",children:t.description})]}),e.jsx(Te,{className:"pt-4 sm:pt-6 px-3 sm:px-6",children:z})]})},Rl=({tabs:t,data:s,className:a})=>{const[r,l]=m.useState(t[0]?.key),d=t.filter(c=>typeof c.visible=="boolean"?c.visible:(typeof c.visible=="string",!0));return e.jsxs(Ws,{value:r,onValueChange:l,className:a,children:[e.jsx(Gs,{className:"w-full justify-start border-b rounded-none bg-transparent p-0",children:d.map(c=>e.jsx(nt,{value:c.key,className:"relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:e.jsxs("div",{className:"flex items-center gap-2",children:[c.icon&&e.jsx("span",{children:c.icon}),e.jsx("span",{children:c.label}),c.badge&&e.jsx(St,{variant:"secondary",className:"ml-1",children:c.badge})]})},c.key))}),d.map(c=>e.jsx(lt,{value:c.key,className:"mt-4",children:Array.isArray(c.content)?e.jsx("div",{className:"space-y-4",children:c.content.map((i,o)=>e.jsx(Ie,{schema:i,data:s},o))}):e.jsx(Ie,{schema:c.content,data:s})},c.key))]})},Is=({title:t,type:s,api:a,data:r=[],schema:l,columns:d,className:c,dataSource:i,objectName:o,onNew:u,onViewAll:h,onRowEdit:n,onRowDelete:N,pageSize:j,sortable:x=!1,filterable:b=!1,collapsible:f=!1,defaultCollapsed:p=!1})=>{const[g,C]=m.useState(r),[k,F]=m.useState(!1),[D,w]=m.useState(0),[S,z]=m.useState(null),[M,O]=m.useState("asc"),[A,$]=m.useState(""),[L,T]=m.useState(null),[R,v]=m.useState(p),{t:E}=Zs(),{fieldLabel:I}=Qs();m.useEffect(()=>{C(r)},[r]),m.useEffect(()=>{a&&i?.getObjectSchema&&!d?.length&&i.getObjectSchema(a).then(T).catch(H=>{console.warn(`[RelatedList] Failed to fetch schema for ${a}:`,H)})},[a,i,d]),m.useEffect(()=>{a&&!r.length&&(F(!0),i&&typeof i.find=="function"?i.find(a).then(H=>{const X=Array.isArray(H)?H:Array.isArray(H?.data)?H.data:[];C(X),F(!1)}).catch(H=>{console.error("Failed to fetch related data:",H),F(!1)}):fetch(a).then(H=>H.json()).then(H=>{const X=Array.isArray(H)?H:H?.data||[];C(X)}).catch(H=>{console.error("Failed to fetch related data:",H)}).finally(()=>F(!1)))},[a,r,i]);const W=m.useMemo(()=>{if(!A)return g;const H=A.toLowerCase();return g.filter(X=>Object.values(X).some(J=>J!=null&&String(J).toLowerCase().includes(H)))},[g,A]),le=m.useMemo(()=>S?[...W].sort((H,X)=>{const J=H[S],he=X[S];if(J==null&&he==null)return 0;if(J==null)return 1;if(he==null)return-1;const ge=String(J).localeCompare(String(he),void 0,{numeric:!0});return M==="asc"?ge:-ge}):W,[W,S,M]),pe=j&&j>0?j:0,de=pe?Math.max(1,Math.ceil(le.length/pe)):1,Z=pe?le.slice(D*pe,(D+1)*pe):le;m.useEffect(()=>{w(0)},[A,S,M]);const me=m.useCallback(H=>{S===H?O(X=>X==="asc"?"desc":"asc"):(z(H),O("asc"))},[S]),Y=m.useCallback(H=>{window.confirm(E("detail.deleteRowConfirmation"))&&N?.(H)},[N,E]),ee=m.useMemo(()=>{if(d&&d.length>0)return d;if(!L?.fields)return[];const H=o||a||"";return Object.entries(L.fields).filter(([X])=>!X.startsWith("_")&&X!=="id").map(([X,J])=>{const he={accessorKey:X,header:I(H,X,J.label||X)};if(J.type){const ge=qs(J.type);if(ge){const Pe={name:X,label:J.label||X,type:J.type,...J.options&&{options:J.options},...J.currency&&{currency:J.currency},...J.precision!==void 0&&{precision:J.precision},...J.format&&{format:J.format},...(J.reference_to||J.reference)&&{reference_to:J.reference_to||J.reference},...J.reference_field&&{reference_field:J.reference_field}};he.cell=Ue=>Ue==null?m.createElement("span",{className:"text-muted-foreground/50 text-xs italic"},"—"):m.createElement(ge,{value:Ue,field:Pe})}}return he})},[d,L,o,a,I]),ue=m.useMemo(()=>{if(l)return l;switch(s){case"grid":case"table":return{type:"data-table",data:Z,columns:ee,pagination:!1,pageSize:pe||10};case"list":return{type:"data-list",data:Z};default:return{type:"div",children:"No view configured"}}},[s,Z,ee,l,pe]),te=!!n||!!N,ae=f?"cursor-pointer select-none":void 0,G=f?()=>v(H=>!H):void 0;return e.jsxs(Oe,{className:c,children:[e.jsx($e,{className:ae,onClick:G,children:e.jsxs(Be,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[f&&(R?e.jsx(Mt,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground"})),e.jsx("span",{children:t}),e.jsx(St,{variant:"secondary",className:"text-xs font-normal","aria-label":`${g.length} records`,children:g.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[u&&e.jsxs(B,{variant:"ghost",size:"sm",onClick:H=>{H.stopPropagation(),u()},className:"gap-1 h-7 text-xs",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"}),E("detail.new")]}),h&&e.jsxs(B,{variant:"ghost",size:"sm",onClick:H=>{H.stopPropagation(),h()},className:"gap-1 h-7 text-xs",children:[E("detail.viewAll"),e.jsx(En,{className:"h-3 w-3"})]})]})]})}),!R&&e.jsxs(Te,{children:[b&&g.length>0&&e.jsx("div",{className:"mb-3",children:e.jsx(qe,{placeholder:E("detail.filterPlaceholder"),value:A,onChange:H=>$(H.target.value),className:"h-8 text-sm"})}),x&&ee&&ee.length>0&&g.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:ee.map(H=>{const X=H.accessorKey||H.field||H.name;if(!X)return null;const J=H.header||H.label||X,he=S===X;return e.jsxs(B,{variant:he?"secondary":"ghost",size:"sm",className:"gap-1 h-7 text-xs",onClick:()=>me(X),children:[e.jsx(hr,{className:"h-3 w-3"}),J,he&&(M==="asc"?" ↑":" ↓")]},X)})}),k?e.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground",children:E("detail.loading")}):g.length===0?e.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-sm",children:E("detail.noRelatedRecords")}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{schema:ue}),te&&Z.length>0&&e.jsx("div",{className:"mt-2 space-y-1","data-testid":"row-actions",children:Z.map((H,X)=>e.jsxs("div",{className:"flex items-center justify-between px-2 py-1 text-xs border-b last:border-b-0",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:H.name||H.title||H.id||`Row ${X+1}`}),e.jsxs("div",{className:"flex items-center gap-1",children:[n&&e.jsxs(B,{variant:"ghost",size:"sm",className:"h-6 text-xs gap-1 px-2",onClick:()=>n(H),children:[e.jsx(ot,{className:"h-3 w-3"}),E("detail.editRow")]}),N&&e.jsxs(B,{variant:"ghost",size:"sm",className:"h-6 text-xs gap-1 px-2 text-destructive hover:text-destructive",onClick:()=>Y(H),children:[e.jsx(vt,{className:"h-3 w-3"}),E("detail.deleteRow")]})]})]},H.id||X))})]}),pe>0&&le.length>pe&&e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t",children:[e.jsxs(B,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",disabled:D===0,onClick:()=>w(H=>Math.max(0,H-1)),children:[e.jsx(yr,{className:"h-3 w-3"}),E("detail.previousPage")]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:E("detail.pageOf",{current:D+1,total:de})}),e.jsxs(B,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",disabled:D>=de-1,onClick:()=>w(H=>Math.min(de-1,H+1)),children:[E("detail.nextPage"),e.jsx(Mt,{className:"h-3 w-3"})]})]})]})]})},ga=({group:t,data:s,className:a,objectSchema:r,objectName:l,isEditing:d=!1,onFieldChange:c})=>{const i=t.collapsible??!0,[o,u]=m.useState(t.defaultCollapsed??!1),h=e.jsx("div",{className:"space-y-3 sm:space-y-4",children:t.sections.map((n,N)=>e.jsx($t,{section:n,data:s,objectSchema:r,objectName:l,isEditing:d,onFieldChange:c},N))});return i?e.jsxs(or,{open:!o,onOpenChange:n=>u(!n),className:a,children:[e.jsx(cr,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b cursor-pointer hover:bg-muted/50 transition-colors rounded-t-md px-2 py-1.5",children:[o?e.jsx(Mt,{className:"h-4 w-4 text-muted-foreground shrink-0"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground shrink-0"}),t.icon&&e.jsx("span",{className:"text-muted-foreground",children:t.icon}),e.jsx("h3",{className:"text-lg font-semibold",children:t.title})]})}),t.description&&!o&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.description}),e.jsx(dr,{children:e.jsx("div",{className:"mt-3",children:h})})]}):e.jsxs("div",{className:V("space-y-3",a),children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[t.icon&&e.jsx("span",{className:"text-muted-foreground",children:t.icon}),e.jsx("h3",{className:"text-lg font-semibold",children:t.title})]}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.description}),h]})},Fl=({fields:t,data:s,className:a,objectName:r,objectSchema:l})=>{const{fieldLabel:d}=Qs();if(!t.length||!s)return null;const c=t.filter(i=>{const o=s?.[i.name];return o!=null&&o!==""});return c.length===0?null:e.jsx(Oe,{className:V("bg-muted/30 border-dashed",a),children:e.jsx(Te,{className:"py-3 px-4",children:e.jsx("div",{className:V("grid gap-4",c.length===1?"grid-cols-1":c.length===2?"grid-cols-2":c.length===3?"grid-cols-3":"grid-cols-2 md:grid-cols-4"),children:c.map(i=>{const o=s[i.name],u=l?.fields?.[i.name],h=i.type||u?.type,n={name:i.name,label:i.label,type:h||"text",...u?.options&&{options:u.options},...u?.currency&&{currency:u.currency},...u?.precision!==void 0&&{precision:u.precision},...u?.format&&{format:u.format}},N=qs(h||"text");return e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:[i.icon&&e.jsx("span",{className:"mr-1",children:i.icon}),d(r||"",i.name,i.label)]}),e.jsx("span",{className:"text-sm font-semibold truncate",children:e.jsx(N,{value:o,field:n})})]},i.name)})})})})};function Ol(t){try{const s=new Date(t),r=new Date().getTime()-s.getTime(),l=Math.floor(r/6e4);if(l<1)return"just now";if(l<60)return`${l}m ago`;const d=Math.floor(l/60);if(d<24)return`${d}h ago`;const c=Math.floor(d/24);return c<7?`${c}d ago`:s.toLocaleDateString()}catch{return t}}const ba=({comments:t,onAddComment:s,onTogglePin:a,searchable:r=!1,className:l})=>{const[d,c]=m.useState(""),[i,o]=m.useState(!1),[u,h]=m.useState(""),n=m.useCallback(async()=>{const x=d.trim();if(!(!x||!s)){o(!0);try{await s(x),c("")}finally{o(!1)}}},[d,s]),N=m.useCallback(x=>{x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&(x.preventDefault(),n())},[n]),j=m.useMemo(()=>[...u.trim()?t.filter(b=>{const f=u.trim().toLowerCase();return b.text.toLowerCase().includes(f)||b.author.toLowerCase().includes(f)}):t].sort((b,f)=>b.pinned&&!f.pinned?-1:!b.pinned&&f.pinned?1:0),[t,u]);return e.jsxs(Oe,{className:V("",l),children:[e.jsx($e,{children:e.jsxs(Be,{className:"flex items-center gap-2 text-base",children:[e.jsx(kt,{className:"h-4 w-4"}),"Comments",e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.length,")"]})]})}),e.jsxs(Te,{className:"space-y-4",children:[r&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ls,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx("input",{className:"w-full rounded-md border border-input bg-background pl-8 pr-8 py-1.5 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",placeholder:"Search comments…",value:u,onChange:x=>h(x.target.value),"aria-label":"Search comments"}),u&&e.jsx("button",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>h(""),"aria-label":"Clear search",type:"button",children:e.jsx(ss,{className:"h-3.5 w-3.5"})})]})}),s&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{className:"flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none",placeholder:"Add a comment… (Ctrl+Enter to submit)",value:d,onChange:x=>c(x.target.value),onKeyDown:N,disabled:i}),e.jsx(B,{size:"icon",variant:"default",onClick:n,disabled:!d.trim()||i,className:"shrink-0 self-end",children:e.jsx(vr,{className:"h-4 w-4"})})]}),j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:u.trim()?"No matching comments":"No comments yet"}):e.jsx("div",{className:"space-y-3",children:j.map(x=>e.jsxs("div",{className:V("flex gap-3",x.pinned&&"bg-muted/40 rounded-md p-2 -mx-2"),children:[e.jsx("div",{className:"shrink-0",children:x.avatarUrl?e.jsx("img",{src:x.avatarUrl,alt:x.author,className:"h-8 w-8 rounded-full object-cover"}):e.jsx("div",{className:"h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground",children:x.author.charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:x.author}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Ol(x.createdAt)}),x.pinned&&e.jsxs("span",{className:"text-xs text-amber-600 flex items-center gap-0.5",children:[e.jsx(fa,{className:"h-3 w-3"}),"Pinned"]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:x.text}),a&&e.jsxs("button",{type:"button",className:"mt-1 text-xs text-muted-foreground hover:text-foreground flex items-center gap-1",onClick:()=>a(x.id),"aria-label":x.pinned?"Unpin comment":"Pin comment",children:[e.jsx(fa,{className:"h-3 w-3"}),x.pinned?"Unpin":"Pin"]})]})]},x.id))})]})]})},ya={field_change:ot,create:zn,delete:vt,comment:kt,status_change:An},Tl={field_change:"bg-blue-100 text-blue-600",create:"bg-green-100 text-green-600",delete:"bg-red-100 text-red-600",comment:"bg-purple-100 text-purple-600",status_change:"bg-amber-100 text-amber-600"};function Pl(t){try{const s=new Date(t),r=new Date().getTime()-s.getTime(),l=Math.floor(r/6e4);if(l<1)return"just now";if(l<60)return`${l}m ago`;const d=Math.floor(l/60);if(d<24)return`${d}h ago`;const c=Math.floor(d/24);return c<7?`${c}d ago`:s.toLocaleDateString()}catch{return t}}function El(t){if(t.description)return t.description;if(t.type==="field_change"&&t.field){const s=t.field.charAt(0).toUpperCase()+t.field.slice(1).replace(/_/g," "),a=t.oldValue!=null?String(t.oldValue):"(empty)",r=t.newValue!=null?String(t.newValue):"(empty)";return`Changed ${s} from "${a}" to "${r}"`}return t.type==="create"?"Created this record":t.type==="delete"?"Deleted this record":t.type==="status_change"&&t.field?`Changed status to "${t.newValue!=null?String(t.newValue):"(empty)"}"`:"Updated record"}const va={all:"All",field_change:"Field Changes",create:"Creates",delete:"Deletes",comment:"Comments",status_change:"Status Changes"},ja=({activities:t,filterable:s=!1,defaultFilter:a="all",className:r})=>{const[l,d]=m.useState(a),c=m.useMemo(()=>l==="all"?t:t.filter(i=>i.type===l),[t,l]);return e.jsxs(Oe,{className:V("",r),children:[e.jsx($e,{children:e.jsxs(Be,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ks,{className:"h-4 w-4"}),"Activity",e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",c.length,")"]})]})}),e.jsxs(Te,{children:[s&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",role:"group","aria-label":"Activity type filter",children:Object.keys(va).map(i=>e.jsxs("button",{type:"button",className:V("inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors",l===i?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"),onClick:()=>d(i),"aria-pressed":l===i,children:[i!=="all"&&m.createElement(ya[i]||ot,{className:"h-3 w-3"}),va[i]]},i))}),c.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No activity recorded"}):e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-4 top-2 bottom-2 w-px bg-border"}),e.jsx("div",{className:"space-y-4",children:c.map(i=>{const o=ya[i.type]||ot,u=Tl[i.type]||"bg-gray-100 text-gray-600";return e.jsxs("div",{className:"flex gap-3 relative",children:[e.jsx("div",{className:V("shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10",u),children:e.jsx(o,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0 pt-1",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:i.user})," ",e.jsx("span",{className:"text-muted-foreground",children:El(i)})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:Pl(i.timestamp)})]})]},i.id)})})]})]})]})},wa=5,Ar=({schema:t,dataSource:s,className:a,onEdit:r,onDelete:l,onBack:d,inlineEdit:c=!1,onFieldSave:i})=>{const[o,u]=m.useState(t.data),[h,n]=m.useState(!t.data&&!!(t.api&&t.resourceId||s&&t.objectName&&t.resourceId)),[N,j]=m.useState(!1),[x,b]=m.useState(!1),[f,p]=m.useState({}),[g,C]=m.useState(null),{t:k}=Zs();m.useEffect(()=>{let v=!0;if(t.data){u(t.data),n(!1);return}if(s&&t.objectName&&t.resourceId){n(!0),C(null),u(null);const E=t.objectName,I=t.resourceId,W=`${E}-`,le=[...t.sections?.flatMap(de=>de.fields)||[],...t.fields||[]];(s.getObjectSchema?s.getObjectSchema(E).catch(()=>null):Promise.resolve(null)).then(de=>{if(!v)return;C(de);const Z=Bs(de?.fields,le),me=Z.length>0?{$expand:Z}:void 0,Y=me?s.findOne(E,I,me):s.findOne(E,I),ee=()=>{const ue=String(I),te=ue.startsWith(W)?ue.slice(W.length):`${W}${ue}`;return(me?s.findOne(E,te,me):s.findOne(E,te)).then(ae=>{v&&(u(ae),n(!1))}).catch(()=>{v&&(u(null),n(!1))})};return Y.catch(()=>null).then(ue=>{if(v){if(ue){u(ue),n(!1);return}return ee()}})}).catch(de=>{v&&(console.error("Failed to fetch detail data:",de),n(!1))})}else t.api&&t.resourceId&&(n(!0),fetch(`${t.api}/${t.resourceId}`).then(E=>E.json()).then(E=>{v&&u(E?.data||E)}).catch(E=>{console.error("Failed to fetch detail data:",E)}).finally(()=>{v&&n(!1)}));return()=>{v=!1}},[t.api,t.resourceId,t.objectName,s,t.sections,t.fields]);const F=m.useCallback(()=>{if(d)d();else if(t.onNavigate){const v=t.backUrl||(t.objectName?`/${t.objectName}`:"/");t.onNavigate(v,{replace:!0})}else t.backUrl?window.location.href=t.backUrl:window.history.back()},[d,t]),D=m.useCallback(()=>{r?r():t.onNavigate&&t.editUrl?t.onNavigate(t.editUrl):t.onNavigate&&t.objectName&&t.resourceId?t.onNavigate(`/${t.objectName}/${t.resourceId}/edit`):t.editUrl&&(window.location.href=t.editUrl)},[r,t]),w=m.useCallback(()=>{const v=t.deleteConfirmation||k("detail.deleteConfirmation");window.confirm(v)&&(l?.(),t.onNavigate&&t.objectName&&t.onNavigate(`/${t.objectName}`,{replace:!0}))},[l,t]),S=m.useCallback(()=>{navigator.share&&t.objectName&&t.resourceId?navigator.share({title:t.title||k("detail.details"),text:`${t.objectName} #${t.resourceId}`,url:window.location.href}).catch(v=>console.log("Share failed:",v)):navigator.clipboard.writeText(window.location.href).then(()=>{console.log("Link copied to clipboard")})},[t]),z=m.useCallback(()=>{console.log("Duplicate record:",o)},[o]),M=m.useCallback(()=>{console.log("Export record:",o)},[o]),O=m.useCallback(()=>{console.log("View history for record:",t.resourceId)},[t]),A=m.useCallback(()=>{j(!N)},[N]),$=m.useCallback(()=>{if(x){const v=Object.entries(f);if(v.length>0){const E={...o,...f};u(E),v.forEach(([I,W])=>{i?.(I,W,E)})}p({})}b(!x)},[x,f,o,i]),L=m.useCallback((v,E)=>{p(I=>({...I,[v]:E}))},[]);m.useEffect(()=>{if(!t.recordNavigation)return;const v=t.recordNavigation,E=I=>{const W=I.target?.tagName;W==="INPUT"||W==="TEXTAREA"||I.target?.isContentEditable||(I.key==="ArrowLeft"&&v.currentIndex>0?(I.preventDefault(),v.onNavigate(v.recordIds[v.currentIndex-1])):I.key==="ArrowRight"&&v.currentIndex<v.recordIds.length-1&&(I.preventDefault(),v.onNavigate(v.recordIds[v.currentIndex+1])))};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[t.recordNavigation]);const T=m.useMemo(()=>{if(!t.autoDiscoverRelated||!g?.fields)return[];if(t.related&&t.related.length>0)return[];const v=[],E=g.fields;for(const[I,W]of Object.entries(E)){const le=W?.reference_to||W?.reference;W&&(W.type==="lookup"||W.type==="master_detail")&&le&&v.push({title:W.label||I.charAt(0).toUpperCase()+I.slice(1),type:"table",objectName:le,referenceField:I})}return v},[t.autoDiscoverRelated,t.related,g]),R=m.useMemo(()=>t.related&&t.related.length>0?t.related:T.map(v=>({title:v.title,type:v.type,api:v.objectName,data:[]})),[t.related,T]);return h||t.loading?e.jsxs("div",{className:V("space-y-4",a),children:[e.jsx(we,{className:"h-10 w-full"}),e.jsx(we,{className:"h-64 w-full"}),e.jsx(we,{className:"h-48 w-full"})]}):!o&&!t.data?e.jsxs("div",{className:V("flex flex-col items-center justify-center py-16 text-center",a),children:[e.jsx("p",{className:"text-lg font-semibold",children:k("detail.recordNotFound")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:k("detail.recordNotFoundDescription")}),(t.showBack??!0)&&e.jsxs(B,{variant:"outline",size:"sm",onClick:F,className:"mt-4 gap-2",children:[e.jsx(ma,{className:"h-4 w-4"}),k("detail.goBack")]})]}):e.jsx(ur,{children:e.jsxs("div",{className:V("space-y-6",a),children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b",children:[e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3 flex-1 min-w-0",children:[(t.showBack??!0)&&e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:"ghost",size:"icon",onClick:F,className:"shrink-0 mt-1",children:e.jsx(ma,{className:"h-4 w-4"})})}),e.jsx(ht,{children:k("detail.back")})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold truncate",children:t.primaryField&&o?.[t.primaryField]||t.title||k("detail.details")}),t.summaryFields?.map(v=>{const E=o?.[v];return E==null||E===""?null:e.jsx(St,{variant:"secondary",className:"text-xs","aria-label":`${v}: ${E}`,children:String(E)},v)}),e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0",onClick:A,children:N?e.jsx(Mn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}):e.jsx(Ln,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(ht,{children:k(N?"detail.removeFromFavorites":"detail.addToFavorites")})]})]}),t.objectName&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium",children:t.objectName}),e.jsx("span",{className:"text-muted-foreground/60",children:"•"}),e.jsxs("span",{children:["#",t.resourceId]})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto",children:[t.recordNavigation&&e.jsxs("div",{className:"flex items-center gap-1 mr-2",children:[e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:"outline",size:"icon",className:"h-8 w-8",disabled:t.recordNavigation.currentIndex<=0,onClick:()=>{const v=t.recordNavigation;v.currentIndex>0&&v.onNavigate(v.recordIds[v.currentIndex-1])},children:e.jsx(yr,{className:"h-4 w-4"})})}),e.jsx(ht,{children:k("detail.previousRecord")})]}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap px-1",children:k("detail.recordOf",{current:t.recordNavigation.currentIndex+1,total:t.recordNavigation.recordIds.length})}),e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:"outline",size:"icon",className:"h-8 w-8",disabled:t.recordNavigation.currentIndex>=t.recordNavigation.recordIds.length-1,onClick:()=>{const v=t.recordNavigation;v.currentIndex<v.recordIds.length-1&&v.onNavigate(v.recordIds[v.currentIndex+1])},children:e.jsx(Mt,{className:"h-4 w-4"})})}),e.jsx(ht,{children:k("detail.nextRecord")})]})]}),t.actions?.map((v,E)=>e.jsx(Ie,{schema:v,data:o},E)),c&&e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:x?"default":"outline",size:"sm",onClick:$,className:"gap-2 hidden sm:inline-flex",children:x?e.jsxs(e.Fragment,{children:[e.jsx(gr,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:k("detail.save")})]}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:k("detail.editInline")})]})})}),e.jsx(ht,{children:k(x?"detail.saveChanges":"detail.editFieldsInline")})]}),e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(B,{variant:"outline",size:"icon",onClick:S,className:"hidden sm:inline-flex",children:e.jsx(Ms,{className:"h-4 w-4"})})}),e.jsx(ht,{children:k("detail.share")})]}),t.showEdit&&e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsxs(B,{variant:"default",onClick:D,className:"gap-2 hidden sm:inline-flex",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:k("detail.edit")})]})}),e.jsx(ht,{children:k("detail.editRecord")})]}),e.jsxs(vn,{children:[e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(jn,{asChild:!0,children:e.jsx(B,{variant:"ghost",size:"icon",children:e.jsx(_n,{className:"h-4 w-4"})})})}),e.jsx(ht,{children:k("detail.moreActions")})]}),e.jsxs(wn,{align:"end",className:"w-[calc(100vw-2rem)] sm:w-48 max-h-[60vh] overflow-y-auto",children:[e.jsxs(Tt,{onClick:S,className:"sm:hidden",children:[e.jsx(Ms,{className:"h-4 w-4 mr-2"}),k("detail.share")]}),t.showEdit&&e.jsxs(Tt,{onClick:D,className:"sm:hidden",children:[e.jsx(ot,{className:"h-4 w-4 mr-2"}),k("detail.edit")]}),c&&e.jsxs(Tt,{onClick:$,className:"sm:hidden",children:[e.jsx(ot,{className:"h-4 w-4 mr-2"}),k(x?"detail.save":"detail.editInline")]}),e.jsx(da,{className:"sm:hidden"}),e.jsxs(Tt,{onClick:z,children:[e.jsx(br,{className:"h-4 w-4 mr-2"}),k("detail.duplicate")]}),e.jsxs(Tt,{onClick:M,children:[e.jsx(Vt,{className:"h-4 w-4 mr-2"}),k("detail.export")]}),e.jsxs(Tt,{onClick:O,children:[e.jsx(In,{className:"h-4 w-4 mr-2"}),k("detail.viewHistory")]}),t.showDelete&&e.jsxs(e.Fragment,{children:[e.jsx(da,{}),e.jsxs(Tt,{onClick:w,className:"text-destructive focus:text-destructive",children:[e.jsx(vt,{className:"h-4 w-4 mr-2"}),k("detail.delete")]})]})]})]})]})]}),t.header&&e.jsx("div",{children:e.jsx(Ie,{schema:t.header,data:o})}),t.highlightFields&&t.highlightFields.length>0&&e.jsx(Fl,{fields:t.highlightFields,data:o,objectName:t.objectName,objectSchema:g}),t.autoTabs&&!t.tabs?.length?e.jsxs(Ws,{defaultValue:"details",className:"w-full",children:[e.jsxs(Gs,{className:"w-full justify-start border-b rounded-none bg-transparent p-0",children:[e.jsx(nt,{value:"details",className:"relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:k("detail.details")}),R.length>0&&e.jsx(nt,{value:"related",className:"relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[k("detail.related"),e.jsx(St,{variant:"secondary",className:"text-xs",children:R.length})]})}),t.activities&&t.activities.length>0&&e.jsx(nt,{value:"activity",className:"relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[k("detail.activity"),e.jsx(St,{variant:"secondary",className:"text-xs",children:t.activities.length})]})})]}),e.jsx(lt,{value:"details",className:"mt-4",children:e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[t.sectionGroups&&t.sectionGroups.length>0&&t.sectionGroups.map((v,E)=>e.jsx(ga,{group:v,data:{...o,...f},objectSchema:g,objectName:t.objectName,isEditing:x,onFieldChange:L},E)),t.sections&&t.sections.length>0&&t.sections.map((v,E)=>e.jsx($t,{section:v,data:{...o,...f},objectSchema:g,objectName:t.objectName,isEditing:x,onFieldChange:L},E)),t.fields&&t.fields.length>0&&!t.sections?.length&&e.jsx($t,{section:{fields:t.fields,columns:t.columns},data:{...o,...f},objectSchema:g,objectName:t.objectName,isEditing:x,onFieldChange:L}),t.comments&&e.jsx(ba,{comments:t.comments,onAddComment:t.onAddComment})]})}),R.length>0&&e.jsx(lt,{value:"related",className:"mt-4",children:e.jsx("div",{className:"space-y-4",children:R.map((v,E)=>e.jsx(Is,{title:v.title,type:v.type,api:v.api,data:v.data,columns:v.columns,dataSource:s,objectName:v.api,collapsible:!0,pageSize:wa},E))})}),t.activities&&t.activities.length>0&&e.jsx(lt,{value:"activity",className:"mt-4",children:e.jsx(ja,{activities:t.activities})})]}):e.jsxs(e.Fragment,{children:[t.sectionGroups&&t.sectionGroups.length>0&&e.jsx("div",{className:"space-y-3 sm:space-y-4",children:t.sectionGroups.map((v,E)=>e.jsx(ga,{group:v,data:{...o,...f},objectSchema:g,objectName:t.objectName,isEditing:x,onFieldChange:L},E))}),t.sections&&t.sections.length>0&&e.jsx("div",{className:"space-y-3 sm:space-y-4",children:t.sections.map((v,E)=>e.jsx($t,{section:v,data:{...o,...f},objectSchema:g,objectName:t.objectName,isEditing:x,onFieldChange:L},E))}),t.fields&&t.fields.length>0&&!t.sections?.length&&e.jsx($t,{section:{fields:t.fields,columns:t.columns},data:{...o,...f},objectSchema:g,objectName:t.objectName,isEditing:x,onFieldChange:L}),t.tabs&&t.tabs.length>0&&e.jsx(Rl,{tabs:t.tabs,data:o}),R.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-semibold",children:k("detail.related")}),R.map((v,E)=>e.jsx(Is,{title:v.title,type:v.type,api:v.api,data:v.data,columns:v.columns,dataSource:s,objectName:v.api,collapsible:!0,pageSize:wa},E))]}),t.comments&&e.jsx(ba,{comments:t.comments,onAddComment:t.onAddComment}),t.activities&&t.activities.length>0&&e.jsx(ja,{activities:t.activities})]}),t.footer&&e.jsx("div",{children:e.jsx(Ie,{schema:t.footer,data:o})})]})})},Al=({change:t,className:s})=>{const a=t.fieldLabel??t.field.charAt(0).toUpperCase()+t.field.slice(1).replace(/_/g," "),r=t.oldDisplayValue??(t.oldValue!=null?String(t.oldValue):"(empty)"),l=t.newDisplayValue??(t.newValue!=null?String(t.newValue):"(empty)");return e.jsxs("div",{className:V("flex items-center gap-1.5 text-sm flex-wrap",s),children:[e.jsx("span",{className:"font-medium text-foreground",children:a}),e.jsx("span",{className:"text-muted-foreground line-through",children:r}),e.jsx($n,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-foreground",children:l})]})},zl=["👍","❤️","🎉","😂","😮","😢"],Na=({reactions:t,onToggleReaction:s,emojiOptions:a=zl,className:r})=>{const[l,d]=m.useState(!1),c=m.useCallback(i=>{s?.(i),d(!1)},[s]);return e.jsxs("div",{className:V("flex items-center gap-1 flex-wrap",r),children:[t.map(i=>e.jsxs("button",{type:"button",className:V("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs border transition-colors",i.reacted?"bg-primary/10 border-primary/30 text-primary":"bg-muted border-border text-muted-foreground hover:bg-muted/80"),onClick:()=>c(i.emoji),disabled:!s,"aria-label":`${i.emoji} ${i.count} reaction${i.count!==1?"s":""}`,children:[e.jsx("span",{children:i.emoji}),e.jsx("span",{children:i.count})]},i.emoji)),s&&e.jsxs("div",{className:"relative",children:[e.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>d(!l),"aria-label":"Add reaction",children:e.jsx(Bn,{className:"h-3.5 w-3.5"})}),l&&e.jsx("div",{className:"absolute bottom-full mb-1 left-0 bg-popover border rounded-md shadow-md z-50 p-1.5 flex gap-1",role:"listbox","aria-label":"Emoji picker",children:a.map(i=>e.jsx("button",{type:"button",className:"hover:bg-accent rounded p-1 text-base transition-colors",onClick:()=>c(i),role:"option","aria-selected":t.some(o=>o.emoji===i&&o.reacted),children:i},i))})]})]})};function Ml(t){try{const s=new Date(t),r=new Date().getTime()-s.getTime(),l=Math.floor(r/6e4);if(l<1)return"just now";if(l<60)return`${l}m ago`;const d=Math.floor(l/60);if(d<24)return`${d}h ago`;const c=Math.floor(d/24);return c<7?`${c}d ago`:s.toLocaleDateString()}catch{return t}}const Ll=({parentItem:t,replies:s,onAddReply:a,showReplyInput:r=!0,className:l})=>{const[d,c]=m.useState(!1),[i,o]=m.useState(""),[u,h]=m.useState(!1),n=m.useCallback(async()=>{const j=i.trim();if(!(!j||!a)){h(!0);try{await a(t.id,j),o("")}finally{h(!1)}}},[i,a,t.id]),N=m.useCallback(j=>{j.key==="Enter"&&(j.ctrlKey||j.metaKey)&&(j.preventDefault(),n())},[n]);return s.length===0&&!r?null:e.jsxs("div",{className:V("ml-10 mt-1",l),children:[s.length>0&&e.jsxs("button",{type:"button",className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1",onClick:()=>c(!d),"aria-expanded":d,children:[d?e.jsx(Dt,{className:"h-3 w-3"}):e.jsx(Mt,{className:"h-3 w-3"}),e.jsx(kt,{className:"h-3 w-3"}),e.jsxs("span",{children:[s.length," ",s.length===1?"reply":"replies"]})]}),d&&e.jsx("div",{className:"space-y-2 border-l-2 border-border pl-3",children:s.map(j=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"shrink-0",children:j.actorAvatarUrl?e.jsx("img",{src:j.actorAvatarUrl,alt:j.actor,className:"h-6 w-6 rounded-full object-cover"}):e.jsx("div",{className:"h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground",children:j.actor.charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-medium",children:j.actor}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Ml(j.createdAt)})]}),e.jsx("p",{className:"text-xs whitespace-pre-wrap break-words",children:j.body})]})]},j.id))}),r&&a&&e.jsxs("div",{className:"flex gap-1.5 mt-1.5",children:[e.jsx("input",{className:"flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",placeholder:"Reply…",value:i,onChange:j=>o(j.target.value),onKeyDown:N,disabled:u}),e.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0",onClick:n,disabled:!i.trim()||u,"aria-label":"Send reply",children:e.jsx(vr,{className:"h-3 w-3"})})]})]})},_l=({subscription:t,onToggle:s,className:a})=>{const[r,l]=m.useState(!1),d=m.useCallback(async()=>{if(s){l(!0);try{await s(!t.subscribed)}finally{l(!1)}}},[s,t.subscribed]);return e.jsx(B,{variant:"ghost",size:"icon",className:V("h-8 w-8",a),onClick:d,disabled:r||!s,"aria-label":t.subscribed?"Unsubscribe from notifications":"Subscribe to notifications",title:t.subscribed?"Subscribed — click to unsubscribe":"Subscribe to notifications",children:t.subscribed?e.jsx(Vn,{className:"h-4 w-4 text-primary"}):e.jsx(Hn,{className:"h-4 w-4 text-muted-foreground"})})},Il={comment:kt,field_change:ot,task:Wn,event:ps,system:wr,email:jr,call:qn},$l={comment:"bg-purple-100 text-purple-600",field_change:"bg-blue-100 text-blue-600",task:"bg-green-100 text-green-600",event:"bg-amber-100 text-amber-600",system:"bg-gray-100 text-gray-600",email:"bg-indigo-100 text-indigo-600",call:"bg-teal-100 text-teal-600"},Bl=[{value:"all",label:"All Activity"},{value:"comments_only",label:"Comments Only"},{value:"changes_only",label:"Field Changes"},{value:"tasks_only",label:"Tasks Only"}];function Vl(t){try{const s=new Date(t),r=new Date().getTime()-s.getTime(),l=Math.floor(r/6e4);if(l<1)return"just now";if(l<60)return`${l}m ago`;const d=Math.floor(l/60);if(d<24)return`${d}h ago`;const c=Math.floor(d/24);return c<7?`${c}d ago`:s.toLocaleDateString()}catch{return t}}function Hl(t,s){switch(s){case"comments_only":return t.filter(a=>a.type==="comment");case"changes_only":return t.filter(a=>a.type==="field_change");case"tasks_only":return t.filter(a=>a.type==="task");default:return t}}const Ca=({items:t,config:s,filterMode:a,onFilterChange:r,hasMore:l=!1,onLoadMore:d,loading:c=!1,onAddComment:i,onAddReply:o,onToggleReaction:u,subscription:h,onToggleSubscription:n,collapseWhenEmpty:N=!1,className:j})=>{const[x,b]=m.useState("all"),[f,p]=m.useState(""),[g,C]=m.useState(!1),[k,F]=m.useState(!1),D=a??x,w=s?.showFilterToggle!==!1,S=s?.showCommentInput!==!1&&!!i,z=s?.enableReactions??!1,M=s?.enableThreading??!1,O=s?.showSubscriptionToggle??!1,A=m.useMemo(()=>Hl(t,D),[t,D]),$=m.useMemo(()=>M?A.filter(I=>!I.parentId):A,[A,M]),L=m.useMemo(()=>{if(!M)return new Map;const I=new Map;for(const W of A)if(W.parentId){const le=I.get(W.parentId)??[];le.push(W),I.set(W.parentId,le)}return I},[A,M]),T=m.useCallback(I=>{r?r(I):b(I)},[r]),R=m.useCallback(async()=>{const I=f.trim();if(!(!I||!i)){C(!0);try{await i(I),p("")}finally{C(!1)}}},[f,i]),v=m.useCallback(I=>{I.key==="Enter"&&(I.ctrlKey||I.metaKey)&&(I.preventDefault(),R())},[R]),E=m.useCallback(async()=>{if(d){F(!0);try{await d()}finally{F(!1)}}},[d]);return e.jsxs(Oe,{className:V("",j),children:[e.jsx($e,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Be,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ks,{className:"h-4 w-4"}),"Activity",e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",A.length,")"]})]}),e.jsx("div",{className:"flex items-center gap-1",children:O&&h&&e.jsx(_l,{subscription:h,onToggle:n})})]})}),e.jsxs(Te,{className:"space-y-4",children:[w&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("select",{className:"rounded-md border border-input bg-background px-2.5 py-1.5 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",value:D,onChange:I=>T(I.target.value),"aria-label":"Filter activity",children:Bl.map(I=>e.jsx("option",{value:I.value,children:I.label},I.value))})}),S&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{className:"flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none",placeholder:"Leave a comment… (Ctrl+Enter to submit)",value:f,onChange:I=>p(I.target.value),onKeyDown:v,disabled:g}),e.jsx(B,{size:"icon",variant:"default",onClick:R,disabled:!f.trim()||g,className:"shrink-0 self-end","aria-label":"Submit comment",children:e.jsx(kt,{className:"h-4 w-4"})})]}),A.length===0?N?null:e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No activity recorded"}):e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-4 top-2 bottom-2 w-px bg-border"}),e.jsx("div",{className:"space-y-4",children:$.map(I=>{const W=Il[I.type]||wr,le=$l[I.type]||"bg-gray-100 text-gray-600",pe=L.get(I.id)??[];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex gap-3 relative",children:[e.jsx("div",{className:V("shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10",le),children:I.actorAvatarUrl?e.jsx("img",{src:I.actorAvatarUrl,alt:I.actor,className:"h-8 w-8 rounded-full object-cover"}):e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0 pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-sm font-medium",children:I.actor}),I.source&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["via ",I.source]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Vl(I.createdAt)}),I.edited&&e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"(edited)"}),I.pinned&&e.jsx("span",{className:"text-xs text-amber-600",children:"📌 Pinned"})]}),I.body&&e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words text-muted-foreground",children:I.body}),I.type==="field_change"&&I.fieldChanges&&e.jsx("div",{className:"space-y-1 mt-1",children:I.fieldChanges.map((de,Z)=>e.jsx(Al,{change:de},Z))}),z&&I.reactions&&I.reactions.length>0&&e.jsx("div",{className:"mt-1.5",children:e.jsx(Na,{reactions:I.reactions,onToggleReaction:u?de=>u(I.id,de):void 0})}),z&&(!I.reactions||I.reactions.length===0)&&u&&e.jsx("div",{className:"mt-1.5",children:e.jsx(Na,{reactions:[],onToggleReaction:de=>u(I.id,de)})})]})]}),M&&(I.replyCount??0)>0&&e.jsx(Ll,{parentItem:I,replies:pe,onAddReply:o,showReplyInput:!!o})]},I.id)})})]}),l&&e.jsx("div",{className:"text-center pt-2",children:e.jsxs(B,{variant:"ghost",size:"sm",onClick:E,disabled:k,"aria-label":"Load more activity",children:[k?e.jsx(Gn,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(Dt,{className:"h-4 w-4 mr-1"}),"Load more"]})})]})]})},_o=({config:t,items:s,hasMore:a,onLoadMore:r,loading:l,onAddComment:d,onAddReply:c,onToggleReaction:i,subscription:o,onToggleSubscription:u,filterMode:h,onFilterChange:n,collapseWhenEmpty:N=!1,className:j})=>{const x=t?.position??"right",b=t?.width??"360px",f=t?.collapsible??!0,p=N&&s.length===0||(t?.defaultCollapsed??!1),[g,C]=m.useState(p);return x==="right"||x==="left"?g&&f?e.jsx("div",{className:V("flex items-start pt-4",x==="right"?"border-l":"border-r",j),children:e.jsx(B,{variant:"ghost",size:"icon",className:"h-8 w-8 mx-1",onClick:()=>C(!1),"aria-label":"Open discussion panel",children:e.jsx(Un,{className:"h-4 w-4"})})}):e.jsxs("div",{className:V("flex flex-col overflow-hidden",x==="right"?"border-l":"border-r",j),style:{width:b,minWidth:b},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(kt,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Discussion"})]}),f&&e.jsx(B,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>C(!0),"aria-label":"Close discussion panel",children:e.jsx(ss,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(Ca,{items:s,config:t?.feed,hasMore:a,onLoadMore:r,loading:l,onAddComment:d,onAddReply:c,onToggleReaction:i,subscription:o,onToggleSubscription:u,filterMode:h,onFilterChange:n,collapseWhenEmpty:N,className:"border-0 shadow-none"})})]}):e.jsx("div",{className:V("",j),children:f&&g?e.jsxs(B,{variant:"ghost",className:"w-full justify-start gap-2 text-muted-foreground",onClick:()=>C(!1),"aria-label":"Show discussion",children:[e.jsx(kt,{className:"h-4 w-4"}),e.jsxs("span",{children:["Show Discussion (",s.length,")"]})]}):e.jsxs("div",{children:[f&&e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(kt,{className:"h-4 w-4"}),"Discussion"]}),e.jsx(B,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>C(!0),"aria-label":"Hide discussion",children:e.jsx(Yn,{className:"h-3.5 w-3.5"})})]}),e.jsx(Ca,{items:s,config:t?.feed,hasMore:a,onLoadMore:r,loading:l,onAddComment:d,onAddReply:c,onToggleReaction:i,subscription:o,onToggleSubscription:u,filterMode:h,onFilterChange:n,collapseWhenEmpty:N})]})})};Se.register("detail-view",Ar,{namespace:"plugin-detail",label:"Detail View",category:"Views",icon:"FileText",inputs:[{name:"title",type:"string",label:"Title"},{name:"objectName",type:"string",label:"Object Name"},{name:"resourceId",type:"string",label:"Resource ID"},{name:"api",type:"string",label:"API Endpoint"},{name:"data",type:"object",label:"Data"},{name:"layout",type:"enum",label:"Layout Mode",enum:["vertical","horizontal","grid"]},{name:"columns",type:"number",label:"Grid Columns"},{name:"sections",type:"array",label:"Sections"},{name:"fields",type:"array",label:"Fields"},{name:"tabs",type:"array",label:"Tabs"},{name:"related",type:"array",label:"Related Lists"},{name:"actions",type:"array",label:"Actions"},{name:"showBack",type:"boolean",label:"Show Back Button",defaultValue:!0},{name:"backUrl",type:"string",label:"Back URL"},{name:"showEdit",type:"boolean",label:"Show Edit Button",defaultValue:!1},{name:"editUrl",type:"string",label:"Edit URL"},{name:"showDelete",type:"boolean",label:"Show Delete Button",defaultValue:!1},{name:"deleteConfirmation",type:"string",label:"Delete Confirmation Message"},{name:"loading",type:"boolean",label:"Show Loading State"},{name:"header",type:"object",label:"Custom Header"},{name:"footer",type:"object",label:"Custom Footer"}],defaultProps:{title:"Detail View",showBack:!0,showEdit:!1,showDelete:!1,sections:[],fields:[],tabs:[],related:[]}});Se.register("detail-section",$t,{namespace:"plugin-detail",label:"Detail Section",category:"Detail Components",inputs:[{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"fields",type:"array",label:"Fields",required:!0},{name:"collapsible",type:"boolean",label:"Collapsible",defaultValue:!1},{name:"defaultCollapsed",type:"boolean",label:"Default Collapsed",defaultValue:!1},{name:"columns",type:"number",label:"Columns",defaultValue:2},{name:"showBorder",type:"boolean",label:"Show Border",defaultValue:!0},{name:"headerColor",type:"string",label:"Header Color"}]});Se.register("related-list",Is,{namespace:"plugin-detail",label:"Related List",category:"Detail Components",inputs:[{name:"title",type:"string",label:"Title",required:!0},{name:"type",type:"enum",label:"Type",enum:[{label:"List",value:"list"},{label:"Grid",value:"grid"},{label:"Table",value:"table"}],defaultValue:"table"},{name:"api",type:"string",label:"API Endpoint"},{name:"data",type:"array",label:"Data"},{name:"columns",type:"array",label:"Columns"}]});Se.register("detail",Ar,{namespace:"view",category:"view",label:"Detail",icon:"FileText",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"recordId",type:"string",label:"Record ID"},{name:"fields",type:"array",label:"Fields"}]});function Ht(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)&&t.provider==="object"}function ns(t){if(t!=null)return typeof t=="string"?t:t.defaultValue||t.key}const ks=["hsl(var(--chart-1))","hsl(var(--chart-2))","hsl(var(--chart-3))","hsl(var(--chart-4))","hsl(var(--chart-5))"],ql=m.forwardRef(({schema:t,className:s,dataSource:a,onRefresh:r,recordCount:l,userActions:d,designMode:c,selectedWidgetId:i,onWidgetClick:o,...u},h)=>{const n=t.columns||4,N=t.gap||4,[j,x]=m.useState(!1),[b,f]=m.useState(!1),p=m.useRef(null);m.useEffect(()=>{const O=()=>f(window.innerWidth<768);return O(),window.addEventListener("resize",O),()=>window.removeEventListener("resize",O)},[]);const g=m.useCallback(()=>{r&&(x(!0),r(),setTimeout(()=>x(!1),600))},[r]);m.useEffect(()=>{if(!(!t.refreshInterval||t.refreshInterval<=0||!r))return p.current=setInterval(g,t.refreshInterval*1e3),()=>{p.current&&clearInterval(p.current)}},[t.refreshInterval,r,g]);const C=m.useCallback((O,A)=>{!c||!o||!A||(O.stopPropagation(),o(A))},[c,o]),k=m.useCallback((O,A,$)=>{if(!c||!o)return;const L=t.widgets||[];if(O.key==="Enter"||O.key===" ")O.preventDefault(),o(A??null);else if(O.key==="ArrowRight"||O.key==="ArrowDown"){O.preventDefault();const T=$+1<L.length?L[$+1]:null;T?.id&&o(T.id)}else if(O.key==="ArrowLeft"||O.key==="ArrowUp"){O.preventDefault();const T=$-1>=0?L[$-1]:null;T?.id&&o(T.id)}else O.key==="Escape"&&(O.preventDefault(),o(null))},[c,o,t.widgets]),F=m.useCallback(O=>{!c||!o||O.target===O.currentTarget&&o(null)},[c,o]),D=(O,A,$)=>{const L=O.layout?{...O.layout,w:Math.min(O.layout.w,n)}:void 0,R=(()=>{if(O.component)return O.component;const Z=O.type,me=O.options||{};if(Z==="bar"||Z==="line"||Z==="area"||Z==="pie"||Z==="donut"||Z==="scatter"){const Y=O.data||me.data,ee=O.categoryField||me.xField||"name",ue=O.valueField||me.yField||"value";if(Ht(Y)){const ae=Y.aggregate,G=ae?{field:O.valueField||ae.field,function:O.aggregate||ae.function,groupBy:O.categoryField||ae.groupBy}:void 0,H=G?.field||ue;return{type:"object-chart",chartType:Z,objectName:O.object||Y.object,aggregate:G,xAxisKey:ee,series:[{dataKey:H}],colors:ks,className:"h-[200px] sm:h-[250px] md:h-[300px]"}}if(!Y&&O.object){const ae=O.aggregate?{field:O.valueField||"value",function:O.aggregate,groupBy:O.categoryField||"name"}:void 0;return{type:"object-chart",chartType:Z,objectName:O.object,aggregate:ae,xAxisKey:ee,series:[{dataKey:O.valueField||"value"}],colors:ks,className:"h-[200px] sm:h-[250px] md:h-[300px]"}}const te=Array.isArray(Y)?Y:Y?.items||[];return{type:"chart",chartType:Z,data:te,xAxisKey:ee,series:[{dataKey:ue}],colors:ks,className:"h-[200px] sm:h-[250px] md:h-[300px]"}}if(Z==="table"){const Y=O.data||me.data;if(Ht(Y)){const{data:ee,...ue}=me;return{type:"object-data-table",...ue,objectName:O.object||Y.object,dataProvider:Y,filter:Y.filter||O.filter,searchable:O.searchable??!1,pagination:O.pagination??!1,className:"border-0"}}return!Y&&O.object?{type:"object-data-table",...me,objectName:O.object,filter:O.filter,searchable:O.searchable??!1,pagination:O.pagination??!1,className:"border-0"}:{type:"data-table",...me,data:Y?.items||[],searchable:!1,pagination:!1,className:"border-0"}}if(Z==="pivot"){const Y=O.data||me.data;if(Ht(Y)){const{data:ee,...ue}=me;return{type:"object-pivot",...ue,objectName:O.object||Y.object,dataProvider:Y,filter:Y.filter||O.filter}}return!Y&&O.object?{type:"object-pivot",...me,objectName:O.object,filter:O.filter}:{type:"pivot",...me,data:Array.isArray(Y)?Y:Y?.items||[]}}return{...O,...me}})(),v=O.type==="metric",E=ns(O.title),I=ns(O.description),W=O.id||E||`widget-${A}`,le=c&&i===O.id,pe=c?{"data-testid":`dashboard-preview-widget-${O.id}`,"data-widget-id":O.id,role:"button",tabIndex:0,"aria-selected":le,"aria-label":`Widget: ${E||`Widget ${A+1}`}`,onClick:Z=>C(Z,O.id),onKeyDown:Z=>k(Z,O.id,A)}:{},de=c?V("cursor-pointer rounded-lg transition-all outline-none","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",le?"ring-2 ring-primary shadow-md bg-primary/5 dark:bg-primary/10":"hover:ring-2 hover:ring-primary/40 hover:shadow-sm"):void 0;return v?e.jsxs("div",{className:V("h-full w-full",c&&"relative",de),style:!b&&L?{gridColumn:`span ${L.w}`,gridRow:`span ${L.h}`}:void 0,...pe,children:[e.jsx(Ie,{schema:R,className:V("h-full w-full",c&&"pointer-events-none")}),c&&e.jsx("div",{className:"absolute inset-0 z-10","aria-hidden":"true","data-testid":"widget-click-overlay"})]},W):e.jsxs(Oe,{className:V("overflow-hidden border-border/50 shadow-sm transition-all hover:shadow-md","bg-card/50 backdrop-blur-sm",$&&"w-full",c&&"relative",de),style:!b&&L?{gridColumn:`span ${L.w}`,gridRow:`span ${L.h}`}:void 0,...pe,children:[E&&e.jsxs($e,{className:"pb-2 border-b border-border/40 bg-muted/20 px-3 sm:px-6",children:[e.jsx(Be,{className:"text-sm sm:text-base font-medium tracking-tight truncate",title:E,children:E}),I&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:I})]}),e.jsx(Te,{className:"p-0",children:e.jsx("div",{className:V("h-full w-full","p-3 sm:p-4 md:p-6",c&&"pointer-events-none"),children:e.jsx(Ie,{schema:R})})}),c&&e.jsx("div",{className:"absolute inset-0 z-10","aria-hidden":"true","data-testid":"widget-click-overlay"})]},W)},w=t.header&&e.jsxs("div",{className:"col-span-full mb-4",children:[t.header.showTitle!==!1&&t.title&&e.jsx("h2",{className:"text-lg font-semibold tracking-tight",children:ns(t.title)}),t.header.showDescription!==!1&&t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:ns(t.description)}),t.header.actions&&t.header.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-3",children:t.header.actions.map((O,A)=>e.jsx(B,{variant:"outline",size:"sm",children:O.label},A))})]}),S=l!==void 0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[l.toLocaleString()," records"]}),z=d?JSON.stringify(d):void 0,M=r&&e.jsxs("div",{className:V("flex items-center justify-end gap-3 mb-2",!b&&"col-span-full"),children:[S,e.jsxs(B,{variant:"outline",size:"sm",onClick:g,disabled:j,"aria-label":"Refresh dashboard",children:[e.jsx(Js,{className:V("h-4 w-4 mr-2",j&&"animate-spin")}),j?"Refreshing…":"Refresh All"]})]});if(b){const O=t.widgets?.filter($=>$.type==="metric")||[],A=t.widgets?.filter($=>$.type!=="metric")||[];return e.jsxs("div",{ref:h,className:V("flex flex-col gap-4 px-4",s),"data-user-actions":z,onClick:F,...u,children:[w,M,O.length>0&&e.jsx("div",{className:"grid grid-cols-2 gap-3",onClick:F,children:O.map(($,L)=>D($,L))}),A.length>0&&e.jsx("div",{className:"flex flex-col gap-4",onClick:F,children:A.map(($,L)=>D($,L,!0))})]})}return e.jsxs("div",{ref:h,className:V("grid auto-rows-min","grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",s),style:{...n>4&&{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},gap:`${N*.25}rem`},"data-user-actions":z,onClick:F,...u,children:[w,M,t.widgets?.map((O,A)=>D(O,A))]})});function Wt(t){const{margin:s,containerPadding:a,containerWidth:r,cols:l}=t;return(r-s[0]*(l-1)-a[0]*2)/l}function qt(t,s,a){return Number.isFinite(t)?Math.round(s*t+Math.max(0,t-1)*a):t}function Ut(t,s,a,r,l,d,c){const{margin:i,containerPadding:o,rowHeight:u}=t,h=Wt(t);let n,N,j,x;if(c?(n=Math.round(c.width),N=Math.round(c.height)):(n=qt(r,h,i[0]),N=qt(l,u,i[1])),d?(j=Math.round(d.top),x=Math.round(d.left)):c?(j=Math.round(c.top),x=Math.round(c.left)):(j=Math.round((u+i[1])*a+o[1]),x=Math.round((h+i[0])*s+o[0])),!d&&!c){if(Number.isFinite(r)){const f=Math.round((h+i[0])*(s+r)+o[0])-x-n;f!==i[0]&&(n+=f-i[0])}if(Number.isFinite(l)){const f=Math.round((u+i[1])*(a+l)+o[1])-j-N;f!==i[1]&&(N+=f-i[1])}}return{top:j,left:x,width:n,height:N}}function Wl(t,s,a,r,l){const{margin:d,containerPadding:c,cols:i,rowHeight:o,maxRows:u}=t,h=Wt(t);let n=Math.round((a-c[0])/(h+d[0])),N=Math.round((s-c[1])/(o+d[1]));return n=fs(n,0,i-r),N=fs(N,0,u-l),{x:n,y:N}}function ls(t,s,a){const{margin:r,containerPadding:l,rowHeight:d}=t,c=Wt(t),i=Math.round((a-l[0])/(c+r[0])),o=Math.round((s-l[1])/(d+r[1]));return{x:i,y:o}}function Gl(t,s,a){const{margin:r,rowHeight:l}=t,d=Wt(t),c=Math.max(1,Math.round((s+r[0])/(d+r[0]))),i=Math.max(1,Math.round((a+r[1])/(l+r[1])));return{w:c,h:i}}function fs(t,s,a){return Math.max(Math.min(t,a),s)}function ea(t,s){return!(t.i===s.i||t.x+t.w<=s.x||t.x>=s.x+s.w||t.y+t.h<=s.y||t.y>=s.y+s.h)}function zt(t,s){for(let a=0;a<t.length;a++){const r=t[a];if(r!==void 0&&ea(r,s))return r}}function zr(t,s){return t.filter(a=>ea(a,s))}function Ul(t,s){return s==="horizontal"?Mr(t):s==="vertical"||s==="wrap"?$s(t):[...t]}function $s(t){return[...t].sort((s,a)=>s.y!==a.y?s.y-a.y:s.x-a.x)}function Mr(t){return[...t].sort((s,a)=>s.x!==a.x?s.x-a.x:s.y-a.y)}function hs(t){let s=0;for(let a=0;a<t.length;a++){const r=t[a];if(r!==void 0){const l=r.y+r.h;l>s&&(s=l)}}return s}function Pt(t,s){for(let a=0;a<t.length;a++){const r=t[a];if(r!==void 0&&r.i===s)return r}}function xs(t){return t.filter(s=>s.static===!0)}function Lt(t){return{i:t.i,x:t.x,y:t.y,w:t.w,h:t.h,minW:t.minW,maxW:t.maxW,minH:t.minH,maxH:t.maxH,moved:!!t.moved,static:!!t.static,isDraggable:t.isDraggable,isResizable:t.isResizable,resizeHandles:t.resizeHandles,constraints:t.constraints,isBounded:t.isBounded}}function Rt(t){const s=new Array(t.length);for(let a=0;a<t.length;a++){const r=t[a];r!==void 0&&(s[a]=Lt(r))}return s}function Yl(t,s){const a=new Array(t.length);for(let r=0;r<t.length;r++){const l=t[r];l!==void 0&&(s.i===l.i?a[r]=s:a[r]=l)}return a}function Xl(t,s,a){let r=Pt(t,s);return r?(r=a(Lt(r)),[Yl(t,r),r]):[[...t],null]}function ta(t,s){const a=xs(t);for(let r=0;r<t.length;r++){const l=t[r];if(l!==void 0)if(l.x+l.w>s.cols&&(l.x=s.cols-l.w),l.x<0&&(l.x=0,l.w=s.cols),!l.static)a.push(l);else for(;zt(a,l);)l.y++}return t}function At(t,s,a,r,l,d,c,i,o){if(s.static&&s.isDraggable!==!0)return[...t];if(s.y===r&&s.x===a)return[...t];const u=s.x,h=s.y;typeof a=="number"&&(s.x=a),typeof r=="number"&&(s.y=r),s.moved=!0;let n=Ul(t,c);(c==="vertical"&&typeof r=="number"?h>=r:c==="horizontal"&&typeof a=="number"?u>=a:!1)&&(n=n.reverse());const j=zr(n,s),x=j.length>0;if(x&&o)return Rt(t);if(x&&d)return s.x=u,s.y=h,s.moved=!1,t;let b=[...t];for(let f=0;f<j.length;f++){const p=j[f];p!==void 0&&(p.moved||(p.static?b=Sa(b,p,s,l,c):b=Sa(b,s,p,l,c)))}return b}function Sa(t,s,a,r,l,d){const c=l==="horizontal",i=l==="vertical",o=s.static;if(r){r=!1;const n={x:c?Math.max(s.x-a.w,0):a.x,y:i?Math.max(s.y-a.h,0):a.y,w:a.w,h:a.h,i:"-1"},N=zt(t,n),j=N!==void 0&&N.y+N.h>s.y,x=N!==void 0&&s.x+s.w>N.x;if(!N)return At(t,a,c?n.x:void 0,i?n.y:void 0,r,o,l);if(j&&i)return At(t,a,void 0,a.y+1,r,o,l);if(j&&l===null)return s.y=a.y,a.y=a.y+a.h,[...t];if(x&&c)return At(t,s,a.x,void 0,r,o,l)}const u=c?a.x+1:void 0,h=i?a.y+1:void 0;return u===void 0&&h===void 0?[...t]:At(t,a,u,h,r,o,l)}function Bt(t,s,a){return Math.max(s,Math.min(a,t))}var Kl={name:"gridBounds",constrainPosition(t,s,a,{cols:r,maxRows:l}){return{x:Bt(s,0,Math.max(0,r-t.w)),y:Bt(a,0,Math.max(0,l-t.h))}},constrainSize(t,s,a,r,{cols:l,maxRows:d}){const c=r==="w"||r==="nw"||r==="sw"?t.x+t.w:l-t.x,i=r==="n"||r==="nw"||r==="ne"?t.y+t.h:d-t.y;return{w:Bt(s,1,Math.max(1,c)),h:Bt(a,1,Math.max(1,i))}}},Jl={name:"minMaxSize",constrainSize(t,s,a){return{w:Bt(s,t.minW??1,t.maxW??1/0),h:Bt(a,t.minH??1,t.maxH??1/0)}}},Lr=[Kl,Jl];function is(t,s,a,r,l){let d={x:a,y:r};for(const c of t)c.constrainPosition&&(d=c.constrainPosition(s,d.x,d.y,l));if(s.constraints)for(const c of s.constraints)c.constrainPosition&&(d=c.constrainPosition(s,d.x,d.y,l));return d}function Ql(t,s,a,r,l,d){let c={w:a,h:r};for(const i of t)i.constrainSize&&(c=i.constrainSize(s,c.w,c.h,l,d));if(s.constraints)for(const i of s.constraints)i.constrainSize&&(c=i.constrainSize(s,c.w,c.h,l,d));return c}function _r({top:t,left:s,width:a,height:r}){const l=`translate(${s}px,${t}px)`;return{transform:l,WebkitTransform:l,MozTransform:l,msTransform:l,OTransform:l,width:`${a}px`,height:`${r}px`,position:"absolute"}}function Zl({top:t,left:s,width:a,height:r}){return{top:`${t}px`,left:`${s}px`,width:`${a}px`,height:`${r}px`,position:"absolute"}}function ka(t){return t*100+"%"}function ei(t,s,a,r){return t+a>r?s:a}function Ir(t,s,a){return t<0?s:a}function ti(t){return Math.max(0,t)}function ms(t){return Math.max(0,t)}var sa=(t,s,a)=>{const{left:r,height:l,width:d}=s,c=t.top-(l-t.height);return{left:r,width:d,height:Ir(c,t.height,l),top:ms(c)}},aa=(t,s,a)=>{const{top:r,left:l,height:d,width:c}=s;return{top:r,height:d,width:ei(t.left,t.width,c,a),left:ti(l)}},ra=(t,s,a)=>{const{top:r,height:l,width:d}=s,c=t.left+t.width-d;return c<0?{height:l,width:t.left+t.width,top:ms(r),left:0}:{height:l,width:d,top:ms(r),left:c}},na=(t,s,a)=>{const{top:r,left:l,height:d,width:c}=s;return{width:c,left:l,height:Ir(r,t.height,d),top:ms(r)}},si=(t,s,a)=>sa(t,aa(t,s,a)),ai=(t,s,a)=>sa(t,ra(t,s)),ri=(t,s,a)=>na(t,aa(t,s,a)),ni=(t,s,a)=>na(t,ra(t,s)),li={n:sa,ne:si,e:aa,se:ri,s:na,sw:ni,w:ra,nw:ai};function ii(t,s,a,r){const l=li[t];return l?l(s,{...s,...a},r):a}var oi={type:"transform",scale:1,calcStyle(t){return _r(t)}},ci=oi,di={cols:12,rowHeight:150,margin:[10,10],containerPadding:null,maxRows:1/0},ui={enabled:!0,bounded:!1,threshold:3},fi={enabled:!0,handles:["se"]},mi={enabled:!1,defaultItem:{w:1,h:1}};function la(t,s,a,r,l){const d=r==="x"?"w":"h";s[r]+=1;const c=t.findIndex(o=>o.i===s.i),i=l??xs(t).length>0;for(let o=c+1;o<t.length;o++){const u=t[o];if(u!==void 0&&!u.static){if(!i&&u.y>s.y+s.h)break;ea(s,u)&&la(t,u,a+s[d],r,i)}}s[r]=a}function pi(t,s,a,r){for(s.x=Math.max(s.x,0),s.y=Math.max(s.y,0),s.y=Math.min(r,s.y);s.y>0&&!zt(t,s);)s.y--;let l;for(;(l=zt(t,s))!==void 0;)la(a,s,l.y+l.h,"y");return s.y=Math.max(s.y,0),s}function hi(t,s,a,r){for(s.x=Math.max(s.x,0),s.y=Math.max(s.y,0);s.x>0&&!zt(t,s);)s.x--;let l;for(;(l=zt(t,s))!==void 0;)if(la(r,s,l.x+l.w,"x"),s.x+s.w>a)for(s.x=a-s.w,s.y++;s.x>0&&!zt(t,s);)s.x--;return s.x=Math.max(s.x,0),s}var $r={type:"vertical",allowOverlap:!1,compact(t,s){const a=xs(t);let r=hs(a);const l=$s(t),d=new Array(t.length);for(let c=0;c<l.length;c++){const i=l[c];if(i===void 0)continue;let o=Lt(i);o.static||(o=pi(a,o,l,r),r=Math.max(r,o.y+o.h),a.push(o));const u=t.indexOf(i);d[u]=o,o.moved=!1}return d}},Br={type:"horizontal",allowOverlap:!1,compact(t,s){const a=xs(t),r=Mr(t),l=new Array(t.length);for(let d=0;d<r.length;d++){const c=r[d];if(c===void 0)continue;let i=Lt(c);i.static||(i=hi(a,i,s,r),a.push(i));const o=t.indexOf(c);l[o]=i,i.moved=!1}return l}},Vr={type:null,allowOverlap:!1,compact(t,s){return Rt(t)}},xi={...$r,allowOverlap:!0,compact(t,s){return Rt(t)}},gi={...Br,allowOverlap:!0,compact(t,s){return Rt(t)}},bi={...Vr,allowOverlap:!0};function ia(t,s=!1,a=!1){let r;return s?t==="vertical"?r=xi:t==="horizontal"?r=gi:r=bi:t==="vertical"?r=$r:t==="horizontal"?r=Br:r=Vr,a?{...r,preventCollision:a}:r}function Hr(t){return Object.keys(t).sort((a,r)=>t[a]-t[r])}function Da(t,s){const a=Hr(t);let r=a[0];if(r===void 0)throw new Error("No breakpoints defined");for(let l=1;l<a.length;l++){const d=a[l];if(d===void 0)continue;const c=t[d];s>c&&(r=d)}return r}function Ra(t,s){const a=s[t];if(a===void 0)throw new Error(`ResponsiveReactGridLayout: \`cols\` entry for breakpoint ${String(t)} is missing!`);return a}function Ds(t,s,a,r,l,d){const c=t[a];if(c)return Rt(c);let i=t[r];const o=Hr(s),u=o.slice(o.indexOf(a));for(let j=0;j<u.length;j++){const x=u[j];if(x===void 0)continue;const b=t[x];if(b){i=b;break}}const h=Rt(i||[]),n=ta(h,{cols:l});return(typeof d=="object"&&d!==null?d:ia(d)).compact(n,l)}function os(t,s){if(Array.isArray(t))return t;const a=t,r=a[s];if(r!==void 0)return r;const l=Object.keys(a);for(const d of l){const c=a[d];if(c!==void 0)return c}return[10,10]}function qr(t){return function(a,r,l,d,c,i,o){return t(a,r,o)}}function gs(t){return function(a,r,l,d){if(!a||!r||typeof a!="object"||typeof r!="object")return t(a,r,l,d);var c=d.get(a),i=d.get(r);if(c&&i)return c===r&&i===a;d.set(a,r),d.set(r,a);var o=t(a,r,l,d);return d.delete(a),d.delete(r),o}}function Wr(t,s){var a={};for(var r in t)a[r]=t[r];for(var r in s)a[r]=s[r];return a}function Fa(t){return t.constructor===Object||t.constructor==null}function Oa(t){return typeof t.then=="function"}function bs(t,s){return t===s||t!==t&&s!==s}var yi="[object Arguments]",vi="[object Boolean]",ji="[object Date]",wi="[object RegExp]",Ni="[object Map]",Ci="[object Number]",Si="[object Object]",ki="[object Set]",Di="[object String]",Ta=Object.prototype.toString;function ys(t){var s=t.areArraysEqual,a=t.areDatesEqual,r=t.areMapsEqual,l=t.areObjectsEqual,d=t.areRegExpsEqual,c=t.areSetsEqual,i=t.createIsNestedEqual,o=i(u);function u(h,n,N){if(h===n)return!0;if(!h||!n||typeof h!="object"||typeof n!="object")return h!==h&&n!==n;if(Fa(h)&&Fa(n))return l(h,n,o,N);var j=Array.isArray(h),x=Array.isArray(n);if(j||x)return j===x&&s(h,n,o,N);var b=Ta.call(h);return b!==Ta.call(n)?!1:b===ji?a(h,n,o,N):b===wi?d(h,n,o,N):b===Ni?r(h,n,o,N):b===ki?c(h,n,o,N):b===Si||b===yi?Oa(h)||Oa(n)?!1:l(h,n,o,N):b===vi||b===Ci||b===Di?bs(h.valueOf(),n.valueOf()):!1}return u}function Gr(t,s,a,r){var l=t.length;if(s.length!==l)return!1;for(;l-- >0;)if(!a(t[l],s[l],l,l,t,s,r))return!1;return!0}var Ri=gs(Gr);function Ur(t,s){return bs(t.valueOf(),s.valueOf())}function Yr(t,s,a,r){var l=t.size===s.size;if(!l)return!1;if(!t.size)return!0;var d={},c=0;return t.forEach(function(i,o){if(l){var u=!1,h=0;s.forEach(function(n,N){!u&&!d[h]&&(u=a(o,N,c,h,t,s,r)&&a(i,n,o,N,t,s,r))&&(d[h]=!0),h++}),c++,l=u}}),l}var Fi=gs(Yr),Oi="_owner",Ti=Object.prototype.hasOwnProperty;function Xr(t,s,a,r){var l=Object.keys(t),d=l.length;if(Object.keys(s).length!==d)return!1;for(var c;d-- >0;){if(c=l[d],c===Oi){var i=!!t.$$typeof,o=!!s.$$typeof;if((i||o)&&i!==o)return!1}if(!Ti.call(s,c)||!a(t[c],s[c],c,c,t,s,r))return!1}return!0}var Pi=gs(Xr);function Kr(t,s){return t.source===s.source&&t.flags===s.flags}function Jr(t,s,a,r){var l=t.size===s.size;if(!l)return!1;if(!t.size)return!0;var d={};return t.forEach(function(c,i){if(l){var o=!1,u=0;s.forEach(function(h,n){!o&&!d[u]&&(o=a(c,h,i,n,t,s,r))&&(d[u]=!0),u++}),l=o}}),l}var Ei=gs(Jr),Qr=Object.freeze({areArraysEqual:Gr,areDatesEqual:Ur,areMapsEqual:Yr,areObjectsEqual:Xr,areRegExpsEqual:Kr,areSetsEqual:Jr,createIsNestedEqual:qr}),Zr=Object.freeze({areArraysEqual:Ri,areDatesEqual:Ur,areMapsEqual:Fi,areObjectsEqual:Pi,areRegExpsEqual:Kr,areSetsEqual:Ei,createIsNestedEqual:qr}),Ai=ys(Qr);function yt(t,s){return Ai(t,s,void 0)}ys(Wr(Qr,{createIsNestedEqual:function(){return bs}}));ys(Zr);ys(Wr(Zr,{createIsNestedEqual:function(){return bs}}));function zi(t={}){const{measureBeforeMount:s=!1,initialWidth:a=1280}=t,[r,l]=m.useState(a),[d,c]=m.useState(!s),i=m.useRef(null),o=m.useRef(null),u=m.useCallback(()=>{const h=i.current;if(h){const n=h.offsetWidth;l(n),d||c(!0)}},[d]);return m.useEffect(()=>{const h=i.current;if(h)return u(),typeof ResizeObserver<"u"&&(o.current=new ResizeObserver(n=>{const N=n[0];if(N){const j=N.contentRect.width;l(j)}}),o.current.observe(h)),()=>{o.current&&(o.current.disconnect(),o.current=null)}},[u]),{width:r,mounted:d,containerRef:i,measureWidth:u}}var Yt={exports:{}},Rs={},Fs={exports:{}},Os,Pa;function Mi(){if(Pa)return Os;Pa=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Os=t,Os}var Ts,Ea;function Li(){if(Ea)return Ts;Ea=1;var t=Mi();function s(){}function a(){}return a.resetWarningCache=s,Ts=function(){function r(c,i,o,u,h,n){if(n!==t){var N=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw N.name="Invariant Violation",N}}r.isRequired=r;function l(){return r}var d={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:l,element:r,elementType:r,instanceOf:l,node:r,objectOf:l,oneOf:l,oneOfType:l,shape:l,exact:l,checkPropTypes:a,resetWarningCache:s};return d.PropTypes=d,d},Ts}var Aa;function vs(){return Aa||(Aa=1,Fs.exports=Li()()),Fs.exports}var De={},Nt={},za;function js(){if(za)return Nt;za=1,Object.defineProperty(Nt,"__esModule",{value:!0}),Nt.dontSetMe=l,Nt.findInArray=t,Nt.int=r,Nt.isFunction=s,Nt.isNum=a;function t(d,c){for(let i=0,o=d.length;i<o;i++)if(c.apply(c,[d[i],i,d]))return d[i]}function s(d){return typeof d=="function"||Object.prototype.toString.call(d)==="[object Function]"}function a(d){return typeof d=="number"&&!isNaN(d)}function r(d){return parseInt(d,10)}function l(d,c,i){if(d[c])return new Error(`Invalid prop ${c} passed to ${i} - do not set this, set it on the child.`)}return Nt}var Ct={},Ma;function _i(){if(Ma)return Ct;Ma=1,Object.defineProperty(Ct,"__esModule",{value:!0}),Ct.browserPrefixToKey=a,Ct.browserPrefixToStyle=r,Ct.default=void 0,Ct.getPrefix=s;const t=["Moz","Webkit","O","ms"];function s(){let d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u")return"";const c=window.document?.documentElement?.style;if(!c||d in c)return"";for(let i=0;i<t.length;i++)if(a(d,t[i])in c)return t[i];return""}function a(d,c){return c?`${c}${l(d)}`:d}function r(d,c){return c?`-${c.toLowerCase()}-${d}`:d}function l(d){let c="",i=!0;for(let o=0;o<d.length;o++)i?(c+=d[o].toUpperCase(),i=!1):d[o]==="-"?i=!0:c+=d[o];return c}return Ct.default=s(),Ct}var La;function oa(){if(La)return De;La=1,Object.defineProperty(De,"__esModule",{value:!0}),De.addClassName=F,De.addEvent=c,De.addUserSelectStyles=g,De.createCSSTransform=j,De.createSVGTransform=x,De.getTouch=f,De.getTouchIdentifier=p,De.getTranslation=b,De.innerHeight=h,De.innerWidth=n,De.matchesSelector=l,De.matchesSelectorAndParentsTo=d,De.offsetXYFromParent=N,De.outerHeight=o,De.outerWidth=u,De.removeClassName=D,De.removeEvent=i,De.scheduleRemoveUserSelectStyles=C;var t=js(),s=a(_i());function a(w,S){if(typeof WeakMap=="function")var z=new WeakMap,M=new WeakMap;return(a=function(O,A){if(!A&&O&&O.__esModule)return O;var $,L,T={__proto__:null,default:O};if(O===null||typeof O!="object"&&typeof O!="function")return T;if($=A?M:z){if($.has(O))return $.get(O);$.set(O,T)}for(const R in O)R!=="default"&&{}.hasOwnProperty.call(O,R)&&((L=($=Object.defineProperty)&&Object.getOwnPropertyDescriptor(O,R))&&(L.get||L.set)?$(T,R,L):T[R]=O[R]);return T})(w,S)}let r="";function l(w,S){return r||(r=(0,t.findInArray)(["matches","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","oMatchesSelector"],function(z){return(0,t.isFunction)(w[z])})),(0,t.isFunction)(w[r])?w[r](S):!1}function d(w,S,z){let M=w;do{if(l(M,S))return!0;if(M===z)return!1;M=M.parentNode}while(M);return!1}function c(w,S,z,M){if(!w)return;const O={capture:!0,...M};w.addEventListener?w.addEventListener(S,z,O):w.attachEvent?w.attachEvent("on"+S,z):w["on"+S]=z}function i(w,S,z,M){if(!w)return;const O={capture:!0,...M};w.removeEventListener?w.removeEventListener(S,z,O):w.detachEvent?w.detachEvent("on"+S,z):w["on"+S]=null}function o(w){let S=w.clientHeight;const z=w.ownerDocument.defaultView.getComputedStyle(w);return S+=(0,t.int)(z.borderTopWidth),S+=(0,t.int)(z.borderBottomWidth),S}function u(w){let S=w.clientWidth;const z=w.ownerDocument.defaultView.getComputedStyle(w);return S+=(0,t.int)(z.borderLeftWidth),S+=(0,t.int)(z.borderRightWidth),S}function h(w){let S=w.clientHeight;const z=w.ownerDocument.defaultView.getComputedStyle(w);return S-=(0,t.int)(z.paddingTop),S-=(0,t.int)(z.paddingBottom),S}function n(w){let S=w.clientWidth;const z=w.ownerDocument.defaultView.getComputedStyle(w);return S-=(0,t.int)(z.paddingLeft),S-=(0,t.int)(z.paddingRight),S}function N(w,S,z){const O=S===S.ownerDocument.body?{left:0,top:0}:S.getBoundingClientRect(),A=(w.clientX+S.scrollLeft-O.left)/z,$=(w.clientY+S.scrollTop-O.top)/z;return{x:A,y:$}}function j(w,S){const z=b(w,S,"px");return{[(0,s.browserPrefixToKey)("transform",s.default)]:z}}function x(w,S){return b(w,S,"")}function b(w,S,z){let{x:M,y:O}=w,A=`translate(${M}${z},${O}${z})`;if(S){const $=`${typeof S.x=="string"?S.x:S.x+z}`,L=`${typeof S.y=="string"?S.y:S.y+z}`;A=`translate(${$}, ${L})`+A}return A}function f(w,S){return w.targetTouches&&(0,t.findInArray)(w.targetTouches,z=>S===z.identifier)||w.changedTouches&&(0,t.findInArray)(w.changedTouches,z=>S===z.identifier)}function p(w){if(w.targetTouches&&w.targetTouches[0])return w.targetTouches[0].identifier;if(w.changedTouches&&w.changedTouches[0])return w.changedTouches[0].identifier}function g(w){if(!w)return;let S=w.getElementById("react-draggable-style-el");S||(S=w.createElement("style"),S.type="text/css",S.id="react-draggable-style-el",S.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
4
+ `,S.innerHTML+=`.react-draggable-transparent-selection *::selection {all: inherit;}
5
+ `,w.getElementsByTagName("head")[0].appendChild(S)),w.body&&F(w.body,"react-draggable-transparent-selection")}function C(w){window.requestAnimationFrame?window.requestAnimationFrame(()=>{k(w)}):k(w)}function k(w){if(w)try{if(w.body&&D(w.body,"react-draggable-transparent-selection"),w.selection)w.selection.empty();else{const S=(w.defaultView||window).getSelection();S&&S.type!=="Caret"&&S.removeAllRanges()}}catch{}}function F(w,S){w.classList?w.classList.add(S):w.className.match(new RegExp(`(?:^|\\s)${S}(?!\\S)`))||(w.className+=` ${S}`)}function D(w,S){w.classList?w.classList.remove(S):w.className=w.className.replace(new RegExp(`(?:^|\\s)${S}(?!\\S)`,"g"),"")}return De}var rt={},_a;function en(){if(_a)return rt;_a=1,Object.defineProperty(rt,"__esModule",{value:!0}),rt.canDragX=l,rt.canDragY=d,rt.createCoreData=i,rt.createDraggableData=o,rt.getBoundPosition=a,rt.getControlPosition=c,rt.snapToGrid=r;var t=js(),s=oa();function a(n,N,j){if(!n.props.bounds)return[N,j];let{bounds:x}=n.props;x=typeof x=="string"?x:u(x);const b=h(n);if(typeof x=="string"){const{ownerDocument:f}=b,p=f.defaultView;let g;if(x==="parent"?g=b.parentNode:g=b.getRootNode().querySelector(x),!(g instanceof p.HTMLElement))throw new Error('Bounds selector "'+x+'" could not find an element.');const C=g,k=p.getComputedStyle(b),F=p.getComputedStyle(C);x={left:-b.offsetLeft+(0,t.int)(F.paddingLeft)+(0,t.int)(k.marginLeft),top:-b.offsetTop+(0,t.int)(F.paddingTop)+(0,t.int)(k.marginTop),right:(0,s.innerWidth)(C)-(0,s.outerWidth)(b)-b.offsetLeft+(0,t.int)(F.paddingRight)-(0,t.int)(k.marginRight),bottom:(0,s.innerHeight)(C)-(0,s.outerHeight)(b)-b.offsetTop+(0,t.int)(F.paddingBottom)-(0,t.int)(k.marginBottom)}}return(0,t.isNum)(x.right)&&(N=Math.min(N,x.right)),(0,t.isNum)(x.bottom)&&(j=Math.min(j,x.bottom)),(0,t.isNum)(x.left)&&(N=Math.max(N,x.left)),(0,t.isNum)(x.top)&&(j=Math.max(j,x.top)),[N,j]}function r(n,N,j){const x=Math.round(N/n[0])*n[0],b=Math.round(j/n[1])*n[1];return[x,b]}function l(n){return n.props.axis==="both"||n.props.axis==="x"}function d(n){return n.props.axis==="both"||n.props.axis==="y"}function c(n,N,j){const x=typeof N=="number"?(0,s.getTouch)(n,N):null;if(typeof N=="number"&&!x)return null;const b=h(j),f=j.props.offsetParent||b.offsetParent||b.ownerDocument.body;return(0,s.offsetXYFromParent)(x||n,f,j.props.scale)}function i(n,N,j){const x=!(0,t.isNum)(n.lastX),b=h(n);return x?{node:b,deltaX:0,deltaY:0,lastX:N,lastY:j,x:N,y:j}:{node:b,deltaX:N-n.lastX,deltaY:j-n.lastY,lastX:n.lastX,lastY:n.lastY,x:N,y:j}}function o(n,N){const j=n.props.scale;return{node:N.node,x:n.state.x+N.deltaX/j,y:n.state.y+N.deltaY/j,deltaX:N.deltaX/j,deltaY:N.deltaY/j,lastX:n.state.x,lastY:n.state.y}}function u(n){return{left:n.left,top:n.top,right:n.right,bottom:n.bottom}}function h(n){const N=n.findDOMNode();if(!N)throw new Error("<DraggableCore>: Unmounted during event!");return N}return rt}var Xt={},cs={},Ia;function tn(){if(Ia)return cs;Ia=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.default=t;function t(){}return cs}var $a;function Ii(){if($a)return Xt;$a=1,Object.defineProperty(Xt,"__esModule",{value:!0}),Xt.default=void 0;var t=o(ts()),s=i(vs()),a=i(rr()),r=oa(),l=en(),d=js(),c=i(tn());function i(b){return b&&b.__esModule?b:{default:b}}function o(b,f){if(typeof WeakMap=="function")var p=new WeakMap,g=new WeakMap;return(o=function(C,k){if(!k&&C&&C.__esModule)return C;var F,D,w={__proto__:null,default:C};if(C===null||typeof C!="object"&&typeof C!="function")return w;if(F=k?g:p){if(F.has(C))return F.get(C);F.set(C,w)}for(const S in C)S!=="default"&&{}.hasOwnProperty.call(C,S)&&((D=(F=Object.defineProperty)&&Object.getOwnPropertyDescriptor(C,S))&&(D.get||D.set)?F(w,S,D):w[S]=C[S]);return w})(b,f)}function u(b,f,p){return(f=h(f))in b?Object.defineProperty(b,f,{value:p,enumerable:!0,configurable:!0,writable:!0}):b[f]=p,b}function h(b){var f=n(b,"string");return typeof f=="symbol"?f:f+""}function n(b,f){if(typeof b!="object"||!b)return b;var p=b[Symbol.toPrimitive];if(p!==void 0){var g=p.call(b,f);if(typeof g!="object")return g;throw new TypeError("@@toPrimitive must return a primitive value.")}return(f==="string"?String:Number)(b)}const N={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}};let j=N.mouse,x=class extends t.Component{constructor(){super(...arguments),u(this,"dragging",!1),u(this,"lastX",NaN),u(this,"lastY",NaN),u(this,"touchIdentifier",null),u(this,"mounted",!1),u(this,"handleDragStart",f=>{if(this.props.onMouseDown(f),!this.props.allowAnyClick&&typeof f.button=="number"&&f.button!==0)return!1;const p=this.findDOMNode();if(!p||!p.ownerDocument||!p.ownerDocument.body)throw new Error("<DraggableCore> not mounted on DragStart!");const{ownerDocument:g}=p;if(this.props.disabled||!(f.target instanceof g.defaultView.Node)||this.props.handle&&!(0,r.matchesSelectorAndParentsTo)(f.target,this.props.handle,p)||this.props.cancel&&(0,r.matchesSelectorAndParentsTo)(f.target,this.props.cancel,p))return;f.type==="touchstart"&&!this.props.allowMobileScroll&&f.preventDefault();const C=(0,r.getTouchIdentifier)(f);this.touchIdentifier=C;const k=(0,l.getControlPosition)(f,C,this);if(k==null)return;const{x:F,y:D}=k,w=(0,l.createCoreData)(this,F,D);(0,c.default)("DraggableCore: handleDragStart: %j",w),(0,c.default)("calling",this.props.onStart),!(this.props.onStart(f,w)===!1||this.mounted===!1)&&(this.props.enableUserSelectHack&&(0,r.addUserSelectStyles)(g),this.dragging=!0,this.lastX=F,this.lastY=D,(0,r.addEvent)(g,j.move,this.handleDrag),(0,r.addEvent)(g,j.stop,this.handleDragStop))}),u(this,"handleDrag",f=>{const p=(0,l.getControlPosition)(f,this.touchIdentifier,this);if(p==null)return;let{x:g,y:C}=p;if(Array.isArray(this.props.grid)){let D=g-this.lastX,w=C-this.lastY;if([D,w]=(0,l.snapToGrid)(this.props.grid,D,w),!D&&!w)return;g=this.lastX+D,C=this.lastY+w}const k=(0,l.createCoreData)(this,g,C);if((0,c.default)("DraggableCore: handleDrag: %j",k),this.props.onDrag(f,k)===!1||this.mounted===!1){try{this.handleDragStop(new MouseEvent("mouseup"))}catch{const w=document.createEvent("MouseEvents");w.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),this.handleDragStop(w)}return}this.lastX=g,this.lastY=C}),u(this,"handleDragStop",f=>{if(!this.dragging)return;const p=(0,l.getControlPosition)(f,this.touchIdentifier,this);if(p==null)return;let{x:g,y:C}=p;if(Array.isArray(this.props.grid)){let w=g-this.lastX||0,S=C-this.lastY||0;[w,S]=(0,l.snapToGrid)(this.props.grid,w,S),g=this.lastX+w,C=this.lastY+S}const k=(0,l.createCoreData)(this,g,C);if(this.props.onStop(f,k)===!1||this.mounted===!1)return!1;const D=this.findDOMNode();D&&this.props.enableUserSelectHack&&(0,r.scheduleRemoveUserSelectStyles)(D.ownerDocument),(0,c.default)("DraggableCore: handleDragStop: %j",k),this.dragging=!1,this.lastX=NaN,this.lastY=NaN,D&&((0,c.default)("DraggableCore: Removing handlers"),(0,r.removeEvent)(D.ownerDocument,j.move,this.handleDrag),(0,r.removeEvent)(D.ownerDocument,j.stop,this.handleDragStop))}),u(this,"onMouseDown",f=>(j=N.mouse,this.handleDragStart(f))),u(this,"onMouseUp",f=>(j=N.mouse,this.handleDragStop(f))),u(this,"onTouchStart",f=>(j=N.touch,this.handleDragStart(f))),u(this,"onTouchEnd",f=>(j=N.touch,this.handleDragStop(f)))}componentDidMount(){this.mounted=!0;const f=this.findDOMNode();f&&(0,r.addEvent)(f,N.touch.start,this.onTouchStart,{passive:!1})}componentWillUnmount(){this.mounted=!1;const f=this.findDOMNode();if(f){const{ownerDocument:p}=f;(0,r.removeEvent)(p,N.mouse.move,this.handleDrag),(0,r.removeEvent)(p,N.touch.move,this.handleDrag),(0,r.removeEvent)(p,N.mouse.stop,this.handleDragStop),(0,r.removeEvent)(p,N.touch.stop,this.handleDragStop),(0,r.removeEvent)(f,N.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&(0,r.scheduleRemoveUserSelectStyles)(p)}}findDOMNode(){return this.props?.nodeRef?this.props?.nodeRef?.current:a.default.findDOMNode(this)}render(){return t.cloneElement(t.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}};return Xt.default=x,u(x,"displayName","DraggableCore"),u(x,"propTypes",{allowAnyClick:s.default.bool,allowMobileScroll:s.default.bool,children:s.default.node.isRequired,disabled:s.default.bool,enableUserSelectHack:s.default.bool,offsetParent:function(b,f){if(b[f]&&b[f].nodeType!==1)throw new Error("Draggable's offsetParent must be a DOM Node.")},grid:s.default.arrayOf(s.default.number),handle:s.default.string,cancel:s.default.string,nodeRef:s.default.object,onStart:s.default.func,onDrag:s.default.func,onStop:s.default.func,onMouseDown:s.default.func,scale:s.default.number,className:d.dontSetMe,style:d.dontSetMe,transform:d.dontSetMe}),u(x,"defaultProps",{allowAnyClick:!1,allowMobileScroll:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1}),Xt}var Ba;function $i(){return Ba||(Ba=1,(function(t){Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"DraggableCore",{enumerable:!0,get:function(){return o.default}}),t.default=void 0;var s=n(ts()),a=h(vs()),r=h(rr()),l=Qn(),d=oa(),c=en(),i=js(),o=h(Ii()),u=h(tn());function h(p){return p&&p.__esModule?p:{default:p}}function n(p,g){if(typeof WeakMap=="function")var C=new WeakMap,k=new WeakMap;return(n=function(F,D){if(!D&&F&&F.__esModule)return F;var w,S,z={__proto__:null,default:F};if(F===null||typeof F!="object"&&typeof F!="function")return z;if(w=D?k:C){if(w.has(F))return w.get(F);w.set(F,z)}for(const M in F)M!=="default"&&{}.hasOwnProperty.call(F,M)&&((S=(w=Object.defineProperty)&&Object.getOwnPropertyDescriptor(F,M))&&(S.get||S.set)?w(z,M,S):z[M]=F[M]);return z})(p,g)}function N(){return N=Object.assign?Object.assign.bind():function(p){for(var g=1;g<arguments.length;g++){var C=arguments[g];for(var k in C)({}).hasOwnProperty.call(C,k)&&(p[k]=C[k])}return p},N.apply(null,arguments)}function j(p,g,C){return(g=x(g))in p?Object.defineProperty(p,g,{value:C,enumerable:!0,configurable:!0,writable:!0}):p[g]=C,p}function x(p){var g=b(p,"string");return typeof g=="symbol"?g:g+""}function b(p,g){if(typeof p!="object"||!p)return p;var C=p[Symbol.toPrimitive];if(C!==void 0){var k=C.call(p,g);if(typeof k!="object")return k;throw new TypeError("@@toPrimitive must return a primitive value.")}return(g==="string"?String:Number)(p)}class f extends s.Component{static getDerivedStateFromProps(g,C){let{position:k}=g,{prevPropsPosition:F}=C;return k&&(!F||k.x!==F.x||k.y!==F.y)?((0,u.default)("Draggable: getDerivedStateFromProps %j",{position:k,prevPropsPosition:F}),{x:k.x,y:k.y,prevPropsPosition:{...k}}):null}constructor(g){super(g),j(this,"onDragStart",(C,k)=>{if((0,u.default)("Draggable: onDragStart: %j",k),this.props.onStart(C,(0,c.createDraggableData)(this,k))===!1)return!1;this.setState({dragging:!0,dragged:!0})}),j(this,"onDrag",(C,k)=>{if(!this.state.dragging)return!1;(0,u.default)("Draggable: onDrag: %j",k);const F=(0,c.createDraggableData)(this,k),D={x:F.x,y:F.y,slackX:0,slackY:0};if(this.props.bounds){const{x:S,y:z}=D;D.x+=this.state.slackX,D.y+=this.state.slackY;const[M,O]=(0,c.getBoundPosition)(this,D.x,D.y);D.x=M,D.y=O,D.slackX=this.state.slackX+(S-D.x),D.slackY=this.state.slackY+(z-D.y),F.x=D.x,F.y=D.y,F.deltaX=D.x-this.state.x,F.deltaY=D.y-this.state.y}if(this.props.onDrag(C,F)===!1)return!1;this.setState(D)}),j(this,"onDragStop",(C,k)=>{if(!this.state.dragging||this.props.onStop(C,(0,c.createDraggableData)(this,k))===!1)return!1;(0,u.default)("Draggable: onDragStop: %j",k);const D={dragging:!1,slackX:0,slackY:0};if(!!this.props.position){const{x:S,y:z}=this.props.position;D.x=S,D.y=z}this.setState(D)}),this.state={dragging:!1,dragged:!1,x:g.position?g.position.x:g.defaultPosition.x,y:g.position?g.position.y:g.defaultPosition.y,prevPropsPosition:{...g.position},slackX:0,slackY:0,isElementSVG:!1},g.position&&!(g.onDrag||g.onStop)&&console.warn("A `position` was applied to this <Draggable>, without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element.")}componentDidMount(){typeof window.SVGElement<"u"&&this.findDOMNode()instanceof window.SVGElement&&this.setState({isElementSVG:!0})}componentWillUnmount(){this.state.dragging&&this.setState({dragging:!1})}findDOMNode(){return this.props?.nodeRef?.current??r.default.findDOMNode(this)}render(){const{axis:g,bounds:C,children:k,defaultPosition:F,defaultClassName:D,defaultClassNameDragging:w,defaultClassNameDragged:S,position:z,positionOffset:M,scale:O,...A}=this.props;let $={},L=null;const R=!!!z||this.state.dragging,v=z||F,E={x:(0,c.canDragX)(this)&&R?this.state.x:v.x,y:(0,c.canDragY)(this)&&R?this.state.y:v.y};this.state.isElementSVG?L=(0,d.createSVGTransform)(E,M):$=(0,d.createCSSTransform)(E,M);const I=(0,l.clsx)(k.props.className||"",D,{[w]:this.state.dragging,[S]:this.state.dragged});return s.createElement(o.default,N({},A,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),s.cloneElement(s.Children.only(k),{className:I,style:{...k.props.style,...$},transform:L}))}}t.default=f,j(f,"displayName","Draggable"),j(f,"propTypes",{...o.default.propTypes,axis:a.default.oneOf(["both","x","y","none"]),bounds:a.default.oneOfType([a.default.shape({left:a.default.number,right:a.default.number,top:a.default.number,bottom:a.default.number}),a.default.string,a.default.oneOf([!1])]),defaultClassName:a.default.string,defaultClassNameDragging:a.default.string,defaultClassNameDragged:a.default.string,defaultPosition:a.default.shape({x:a.default.number,y:a.default.number}),positionOffset:a.default.shape({x:a.default.oneOfType([a.default.number,a.default.string]),y:a.default.oneOfType([a.default.number,a.default.string])}),position:a.default.shape({x:a.default.number,y:a.default.number}),className:i.dontSetMe,style:i.dontSetMe,transform:i.dontSetMe}),j(f,"defaultProps",{...o.default.defaultProps,axis:"both",bounds:!1,defaultClassName:"react-draggable",defaultClassNameDragging:"react-draggable-dragging",defaultClassNameDragged:"react-draggable-dragged",defaultPosition:{x:0,y:0},scale:1})})(Rs)),Rs}var Va;function ca(){if(Va)return Yt.exports;Va=1;const{default:t,DraggableCore:s}=$i();return Yt.exports=t,Yt.exports.default=t,Yt.exports.DraggableCore=s,Yt.exports}var Bi=ca(),Kt={exports:{}},Jt={},ds={},Ha;function Vi(){if(Ha)return ds;Ha=1,ds.__esModule=!0,ds.cloneElement=i;var t=s(ts());function s(o){return o&&o.__esModule?o:{default:o}}function a(o,u){var h=Object.keys(o);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(o);u&&(n=n.filter(function(N){return Object.getOwnPropertyDescriptor(o,N).enumerable})),h.push.apply(h,n)}return h}function r(o){for(var u=1;u<arguments.length;u++){var h=arguments[u]!=null?arguments[u]:{};u%2?a(Object(h),!0).forEach(function(n){l(o,n,h[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(h)):a(Object(h)).forEach(function(n){Object.defineProperty(o,n,Object.getOwnPropertyDescriptor(h,n))})}return o}function l(o,u,h){return(u=d(u))in o?Object.defineProperty(o,u,{value:h,enumerable:!0,configurable:!0,writable:!0}):o[u]=h,o}function d(o){var u=c(o,"string");return typeof u=="symbol"?u:u+""}function c(o,u){if(typeof o!="object"||!o)return o;var h=o[Symbol.toPrimitive];if(h!==void 0){var n=h.call(o,u);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(u==="string"?String:Number)(o)}function i(o,u){return u.style&&o.props.style&&(u.style=r(r({},o.props.style),u.style)),u.className&&o.props.className&&(u.className=`${o.props.className} ${u.className}`),t.default.cloneElement(o,u)}return ds}var Qt={},qa;function sn(){if(qa)return Qt;qa=1,Qt.__esModule=!0,Qt.resizableProps=void 0;var t=s(vs());ca();function s(a){return a&&a.__esModule?a:{default:a}}return Qt.resizableProps={axis:t.default.oneOf(["both","x","y","none"]),className:t.default.string,children:t.default.element.isRequired,draggableOpts:t.default.shape({allowAnyClick:t.default.bool,cancel:t.default.string,children:t.default.node,disabled:t.default.bool,enableUserSelectHack:t.default.bool,offsetParent:typeof Element<"u"?t.default.instanceOf(Element):t.default.any,grid:t.default.arrayOf(t.default.number),handle:t.default.string,nodeRef:t.default.object,onStart:t.default.func,onDrag:t.default.func,onStop:t.default.func,onMouseDown:t.default.func,scale:t.default.number}),height:function(){for(var a=arguments.length,r=new Array(a),l=0;l<a;l++)r[l]=arguments[l];const[d]=r;return d.axis==="both"||d.axis==="y"?t.default.number.isRequired(...r):t.default.number(...r)},handle:t.default.oneOfType([t.default.node,t.default.func]),handleSize:t.default.arrayOf(t.default.number),lockAspectRatio:t.default.bool,maxConstraints:t.default.arrayOf(t.default.number),minConstraints:t.default.arrayOf(t.default.number),onResizeStop:t.default.func,onResizeStart:t.default.func,onResize:t.default.func,resizeHandles:t.default.arrayOf(t.default.oneOf(["s","w","e","n","sw","nw","se","ne"])),transformScale:t.default.number,width:function(){for(var a=arguments.length,r=new Array(a),l=0;l<a;l++)r[l]=arguments[l];const[d]=r;return d.axis==="both"||d.axis==="x"?t.default.number.isRequired(...r):t.default.number(...r)}},Qt}var Wa;function an(){if(Wa)return Jt;Wa=1,Jt.__esModule=!0,Jt.default=void 0;var t=d(ts()),s=ca(),a=Vi(),r=sn();const l=["children","className","draggableOpts","width","height","handle","handleSize","lockAspectRatio","axis","minConstraints","maxConstraints","onResize","onResizeStop","onResizeStart","resizeHandles","transformScale"];function d(b,f){if(typeof WeakMap=="function")var p=new WeakMap,g=new WeakMap;return(d=function(C,k){if(!k&&C&&C.__esModule)return C;var F,D,w={__proto__:null,default:C};if(C===null||typeof C!="object"&&typeof C!="function")return w;if(F=k?g:p){if(F.has(C))return F.get(C);F.set(C,w)}for(const S in C)S!=="default"&&{}.hasOwnProperty.call(C,S)&&((D=(F=Object.defineProperty)&&Object.getOwnPropertyDescriptor(C,S))&&(D.get||D.set)?F(w,S,D):w[S]=C[S]);return w})(b,f)}function c(){return c=Object.assign?Object.assign.bind():function(b){for(var f=1;f<arguments.length;f++){var p=arguments[f];for(var g in p)({}).hasOwnProperty.call(p,g)&&(b[g]=p[g])}return b},c.apply(null,arguments)}function i(b,f){if(b==null)return{};var p,g,C=o(b,f);if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(b);for(g=0;g<k.length;g++)p=k[g],f.indexOf(p)===-1&&{}.propertyIsEnumerable.call(b,p)&&(C[p]=b[p])}return C}function o(b,f){if(b==null)return{};var p={};for(var g in b)if({}.hasOwnProperty.call(b,g)){if(f.indexOf(g)!==-1)continue;p[g]=b[g]}return p}function u(b,f){var p=Object.keys(b);if(Object.getOwnPropertySymbols){var g=Object.getOwnPropertySymbols(b);f&&(g=g.filter(function(C){return Object.getOwnPropertyDescriptor(b,C).enumerable})),p.push.apply(p,g)}return p}function h(b){for(var f=1;f<arguments.length;f++){var p=arguments[f]!=null?arguments[f]:{};f%2?u(Object(p),!0).forEach(function(g){n(b,g,p[g])}):Object.getOwnPropertyDescriptors?Object.defineProperties(b,Object.getOwnPropertyDescriptors(p)):u(Object(p)).forEach(function(g){Object.defineProperty(b,g,Object.getOwnPropertyDescriptor(p,g))})}return b}function n(b,f,p){return(f=N(f))in b?Object.defineProperty(b,f,{value:p,enumerable:!0,configurable:!0,writable:!0}):b[f]=p,b}function N(b){var f=j(b,"string");return typeof f=="symbol"?f:f+""}function j(b,f){if(typeof b!="object"||!b)return b;var p=b[Symbol.toPrimitive];if(p!==void 0){var g=p.call(b,f);if(typeof g!="object")return g;throw new TypeError("@@toPrimitive must return a primitive value.")}return(f==="string"?String:Number)(b)}let x=class extends t.Component{constructor(){super(...arguments),this.handleRefs={},this.lastHandleRect=null,this.slack=null,this.lastSize=null}componentWillUnmount(){this.resetData()}resetData(){this.lastHandleRect=this.slack=this.lastSize=null}runConstraints(f,p){const{minConstraints:g,maxConstraints:C,lockAspectRatio:k}=this.props;if(!g&&!C&&!k)return[f,p];if(k){const z=this.props.width/this.props.height,M=f-this.props.width,O=p-this.props.height;Math.abs(M)>Math.abs(O*z)?p=f/z:f=p*z}const[F,D]=[f,p];let[w,S]=this.slack||[0,0];return f+=w,p+=S,g&&(f=Math.max(g[0],f),p=Math.max(g[1],p)),C&&(f=Math.min(C[0],f),p=Math.min(C[1],p)),this.slack=[w+(F-f),S+(D-p)],[f,p]}resizeHandler(f,p){return(g,C)=>{let{node:k,deltaX:F,deltaY:D}=C;f==="onResizeStart"&&this.resetData();const w=(this.props.axis==="both"||this.props.axis==="x")&&p!=="n"&&p!=="s",S=(this.props.axis==="both"||this.props.axis==="y")&&p!=="e"&&p!=="w";if(!w&&!S)return;const z=p[0],M=p[p.length-1],O=k.getBoundingClientRect();if(this.lastHandleRect!=null){if(M==="w"){const v=O.left-this.lastHandleRect.left;F+=v}if(z==="n"){const v=O.top-this.lastHandleRect.top;D+=v}}this.lastHandleRect=O,M==="w"&&(F=-F),z==="n"&&(D=-D);let A=this.props.width+(w?F/this.props.transformScale:0),$=this.props.height+(S?D/this.props.transformScale:0);[A,$]=this.runConstraints(A,$),f==="onResizeStop"&&this.lastSize&&({width:A,height:$}=this.lastSize);const L=A!==this.props.width||$!==this.props.height;f!=="onResizeStop"&&(this.lastSize={width:A,height:$});const T=typeof this.props[f]=="function"?this.props[f]:null;T&&!(f==="onResize"&&!L)&&(g.persist?.(),T(g,{node:k,size:{width:A,height:$},handle:p})),f==="onResizeStop"&&this.resetData()}}renderResizeHandle(f,p){const{handle:g}=this.props;if(!g)return t.createElement("span",{className:`react-resizable-handle react-resizable-handle-${f}`,ref:p});if(typeof g=="function")return g(f,p);const C=typeof g.type=="string",k=h({ref:p},C?{}:{handleAxis:f});return t.cloneElement(g,k)}render(){const f=this.props,{children:p,className:g,draggableOpts:C,width:k,height:F,handle:D,handleSize:w,lockAspectRatio:S,axis:z,minConstraints:M,maxConstraints:O,onResize:A,onResizeStop:$,onResizeStart:L,resizeHandles:T,transformScale:R}=f,v=i(f,l);return(0,a.cloneElement)(p,h(h({},v),{},{className:`${g?`${g} `:""}react-resizable`,children:[...t.Children.toArray(p.props.children),...T.map(E=>{const I=this.handleRefs[E]??(this.handleRefs[E]=t.createRef());return t.createElement(s.DraggableCore,c({},C,{nodeRef:I,key:`resizableHandle-${E}`,onStop:this.resizeHandler("onResizeStop",E),onStart:this.resizeHandler("onResizeStart",E),onDrag:this.resizeHandler("onResize",E)}),this.renderResizeHandle(E,I))})]}))}};return Jt.default=x,x.propTypes=r.resizableProps,x.defaultProps={axis:"both",handleSize:[20,20],lockAspectRatio:!1,minConstraints:[20,20],maxConstraints:[1/0,1/0],resizeHandles:["se"],transformScale:1},Jt}var Zt={},Ga;function Hi(){if(Ga)return Zt;Ga=1,Zt.__esModule=!0,Zt.default=void 0;var t=c(ts()),s=d(vs()),a=d(an()),r=sn();const l=["handle","handleSize","onResize","onResizeStart","onResizeStop","draggableOpts","minConstraints","maxConstraints","lockAspectRatio","axis","width","height","resizeHandles","style","transformScale"];function d(f){return f&&f.__esModule?f:{default:f}}function c(f,p){if(typeof WeakMap=="function")var g=new WeakMap,C=new WeakMap;return(c=function(k,F){if(!F&&k&&k.__esModule)return k;var D,w,S={__proto__:null,default:k};if(k===null||typeof k!="object"&&typeof k!="function")return S;if(D=F?C:g){if(D.has(k))return D.get(k);D.set(k,S)}for(const z in k)z!=="default"&&{}.hasOwnProperty.call(k,z)&&((w=(D=Object.defineProperty)&&Object.getOwnPropertyDescriptor(k,z))&&(w.get||w.set)?D(S,z,w):S[z]=k[z]);return S})(f,p)}function i(){return i=Object.assign?Object.assign.bind():function(f){for(var p=1;p<arguments.length;p++){var g=arguments[p];for(var C in g)({}).hasOwnProperty.call(g,C)&&(f[C]=g[C])}return f},i.apply(null,arguments)}function o(f,p){var g=Object.keys(f);if(Object.getOwnPropertySymbols){var C=Object.getOwnPropertySymbols(f);p&&(C=C.filter(function(k){return Object.getOwnPropertyDescriptor(f,k).enumerable})),g.push.apply(g,C)}return g}function u(f){for(var p=1;p<arguments.length;p++){var g=arguments[p]!=null?arguments[p]:{};p%2?o(Object(g),!0).forEach(function(C){h(f,C,g[C])}):Object.getOwnPropertyDescriptors?Object.defineProperties(f,Object.getOwnPropertyDescriptors(g)):o(Object(g)).forEach(function(C){Object.defineProperty(f,C,Object.getOwnPropertyDescriptor(g,C))})}return f}function h(f,p,g){return(p=n(p))in f?Object.defineProperty(f,p,{value:g,enumerable:!0,configurable:!0,writable:!0}):f[p]=g,f}function n(f){var p=N(f,"string");return typeof p=="symbol"?p:p+""}function N(f,p){if(typeof f!="object"||!f)return f;var g=f[Symbol.toPrimitive];if(g!==void 0){var C=g.call(f,p);if(typeof C!="object")return C;throw new TypeError("@@toPrimitive must return a primitive value.")}return(p==="string"?String:Number)(f)}function j(f,p){if(f==null)return{};var g,C,k=x(f,p);if(Object.getOwnPropertySymbols){var F=Object.getOwnPropertySymbols(f);for(C=0;C<F.length;C++)g=F[C],p.indexOf(g)===-1&&{}.propertyIsEnumerable.call(f,g)&&(k[g]=f[g])}return k}function x(f,p){if(f==null)return{};var g={};for(var C in f)if({}.hasOwnProperty.call(f,C)){if(p.indexOf(C)!==-1)continue;g[C]=f[C]}return g}let b=class extends t.Component{constructor(){super(...arguments),this.state={width:this.props.width,height:this.props.height,propsWidth:this.props.width,propsHeight:this.props.height},this.onResize=(p,g)=>{const{size:C}=g;this.props.onResize?(p.persist?.(),this.setState(C,()=>this.props.onResize&&this.props.onResize(p,g))):this.setState(C)}}static getDerivedStateFromProps(p,g){return g.propsWidth!==p.width||g.propsHeight!==p.height?{width:p.width,height:p.height,propsWidth:p.width,propsHeight:p.height}:null}render(){const p=this.props,{handle:g,handleSize:C,onResize:k,onResizeStart:F,onResizeStop:D,draggableOpts:w,minConstraints:S,maxConstraints:z,lockAspectRatio:M,axis:O,width:A,height:$,resizeHandles:L,style:T,transformScale:R}=p,v=j(p,l);return t.createElement(a.default,{axis:O,draggableOpts:w,handle:g,handleSize:C,height:this.state.height,lockAspectRatio:M,maxConstraints:z,minConstraints:S,onResizeStart:F,onResize:this.onResize,onResizeStop:D,resizeHandles:L,transformScale:R,width:this.state.width},t.createElement("div",i({},v,{style:u(u({},T),{},{width:this.state.width+"px",height:this.state.height+"px"})})))}};return Zt.default=b,b.propTypes=u(u({},r.resizableProps),{},{children:s.default.element}),Zt}var Ua;function qi(){return Ua||(Ua=1,Kt.exports=function(){throw new Error("Don't instantiate Resizable directly! Use require('react-resizable').Resizable")},Kt.exports.Resizable=an().default,Kt.exports.ResizableBox=Hi().default),Kt.exports}var Wi=qi();function Ya(t){const{children:s,cols:a,containerWidth:r,margin:l,containerPadding:d,rowHeight:c,maxRows:i,isDraggable:o,isResizable:u,isBounded:h,static:n,useCSSTransforms:N=!0,usePercentages:j=!1,transformScale:x=1,positionStrategy:b,dragThreshold:f=0,droppingPosition:p,className:g="",style:C,handle:k="",cancel:F="",x:D,y:w,w:S,h:z,minW:M=1,maxW:O=1/0,minH:A=1,maxH:$=1/0,i:L,resizeHandles:T,resizeHandle:R,constraints:v=Lr,layoutItem:E,layout:I=[],onDragStart:W,onDrag:le,onDragStop:pe,onResizeStart:de,onResize:Z,onResizeStop:me}=t,[Y,ee]=m.useState(!1),[ue,te]=m.useState(!1),ae=m.useRef(null),G=m.useRef({left:0,top:0}),H=m.useRef({top:0,left:0,width:0,height:0}),X=m.useRef(void 0),J=m.useRef(I);J.current=I;const he=m.useRef(null),ge=m.useRef(null),Pe=m.useRef(!1),Ue=m.useRef({x:0,y:0}),be=m.useRef(!1),xe=m.useMemo(()=>({cols:a,containerPadding:d,containerWidth:r,margin:l,maxRows:i,rowHeight:c}),[a,d,r,l,i,c]),Re=m.useMemo(()=>({cols:a,maxRows:i,containerWidth:r,containerHeight:0,rowHeight:c,margin:l,layout:[]}),[a,i,r,c,l]),Ne=m.useCallback(()=>({...Re,layout:J.current}),[Re]),We=m.useMemo(()=>E??{i:L,x:D,y:w,w:S,h:z,minW:M,maxW:O,minH:A,maxH:$},[E,L,D,w,S,z,M,O,A,$]),Ft=m.useCallback(re=>{if(b?.calcStyle)return b.calcStyle(re);if(N)return _r(re);const ie=Zl(re);return j?{...ie,left:ka(re.left/r),width:ka(re.width/r)}:ie},[b,N,j,r]),Ye=m.useCallback((re,{node:ie})=>{if(!W)return;const{offsetParent:ye}=ie;if(!ye)return;const fe=ye.getBoundingClientRect(),ve=ie.getBoundingClientRect(),Ce=ve.left/x,Me=fe.left/x,Ee=ve.top/x,_e=fe.top/x;let He;if(b?.calcDragPosition){const P=re;He=b.calcDragPosition(P.clientX,P.clientY,P.clientX-ve.left,P.clientY-ve.top)}else He={left:Ce-Me+ye.scrollLeft,top:Ee-_e+ye.scrollTop};if(G.current=He,f>0){const P=re;Ue.current={x:P.clientX,y:P.clientY},Pe.current=!0,be.current=!1,ee(!0);return}ee(!0);const at=ls(xe,He.top,He.left),{x:Je,y}=is(v,We,at.x,at.y,Ne());W(L,Je,y,{e:re,node:ie,newPosition:He})},[W,x,xe,b,f,v,We,Ne,L]),ct=m.useCallback((re,{node:ie,deltaX:ye,deltaY:fe})=>{if(!le||!Y)return;const ve=re;if(Pe.current&&!be.current){const Je=ve.clientX-Ue.current.x,y=ve.clientY-Ue.current.y;if(Math.hypot(Je,y)<f)return;if(be.current=!0,Pe.current=!1,W){const _=ls(xe,G.current.top,G.current.left),{x:q,y:U}=is(v,We,_.x,_.y,Ne());W(L,q,U,{e:re,node:ie,newPosition:G.current})}}let Ce=G.current.top+fe,Me=G.current.left+ye;if(h){const{offsetParent:Je}=ie;if(Je){const y=Je.clientHeight-qt(z,c,l[1]);Ce=fs(Ce,0,y);const P=Wt(xe),_=r-qt(S,P,l[0]);Me=fs(Me,0,_)}}const Ee={top:Ce,left:Me};G.current=Ee;const _e=ls(xe,Ce,Me),{x:He,y:at}=is(v,We,_e.x,_e.y,Ne());le(L,He,at,{e:re,node:ie,newPosition:Ee})},[le,W,Y,f,h,z,c,l,xe,r,S,L,v,We,Ne]),Ae=m.useCallback((re,{node:ie})=>{if(!pe||!Y)return;const ye=Pe.current;if(Pe.current=!1,be.current=!1,Ue.current={x:0,y:0},ye){ee(!1),G.current={left:0,top:0};return}const{left:fe,top:ve}=G.current,Ce={top:ve,left:fe};ee(!1),G.current={left:0,top:0};const Me=ls(xe,ve,fe),{x:Ee,y:_e}=is(v,We,Me.x,Me.y,Ne());pe(L,Ee,_e,{e:re,node:ie,newPosition:Ce})},[pe,Y,xe,v,We,Ne,L]);he.current=Ye,ge.current=ct;const Ve=m.useCallback((re,{node:ie,size:ye,handle:fe},ve,Ce)=>{const Me=Ce==="onResizeStart"?de:Ce==="onResize"?Z:me;if(!Me)return;let Ee;ie?Ee=ii(fe,ve,ye,r):Ee={...ye,top:ve.top,left:ve.left},H.current=Ee;const _e=Gl(xe,Ee.width,Ee.height),{w:He,h:at}=Ql(v,We,_e.w,_e.h,fe,Ne());Me(L,He,at,{e:re.nativeEvent,node:ie,size:Ee,handle:fe})},[de,Z,me,r,xe,L,v,We,Ne]),jt=m.useCallback((re,ie)=>{te(!0);const ye=Ut(xe,D,w,S,z),fe={...ie,handle:ie.handle};Ve(re,fe,ye,"onResizeStart")},[Ve,xe,D,w,S,z]),wt=m.useCallback((re,ie)=>{const ye=Ut(xe,D,w,S,z),fe={...ie,handle:ie.handle};Ve(re,fe,ye,"onResize")},[Ve,xe,D,w,S,z]),st=m.useCallback((re,ie)=>{te(!1),H.current={top:0,left:0,width:0,height:0};const ye=Ut(xe,D,w,S,z),fe={...ie,handle:ie.handle};Ve(re,fe,ye,"onResizeStop")},[Ve,xe,D,w,S,z]);m.useEffect(()=>{if(!p)return;const re=ae.current;if(!re)return;const ie=X.current||{left:0,top:0},ye=Y&&(p.left!==ie.left||p.top!==ie.top);if(Y){if(ye){const fe=p.left-G.current.left,ve=p.top-G.current.top,Ce={node:re,deltaX:fe,deltaY:ve,lastX:G.current.left,lastY:G.current.top,x:p.left,y:p.top};ge.current?.(p.e,Ce)}}else{const fe={node:re,deltaX:p.left,deltaY:p.top,lastX:0,lastY:0,x:p.left,y:p.top};he.current?.(p.e,fe)}X.current=p},[p,Y,L]);const Ge=Ut(xe,D,w,S,z,Y?G.current:null,ue?H.current:null),Xe=tt.Children.only(s),Ke=Ut(xe,0,0,1,1),_t=[Ke.width,Ke.height],dt=[1/0,1/0],Le=Xe.props,Gt=Le.className,It=Le.style;let Ze=tt.cloneElement(Xe,{ref:ae,className:Rr("react-grid-item",Gt,g,{static:n,resizing:ue,"react-draggable":o,"react-draggable-dragging":Y,dropping:!!p,cssTransforms:N}),style:{...C,...It,...Ft(Ge)}});const Ot=R;return Ze=e.jsx(Wi.Resizable,{draggableOpts:{disabled:!u},className:u?void 0:"react-resizable-hide",width:Ge.width,height:Ge.height,minConstraints:_t,maxConstraints:dt,onResizeStart:jt,onResize:wt,onResizeStop:st,transformScale:x,resizeHandles:T,handle:Ot,children:Ze}),Ze=e.jsx(Bi.DraggableCore,{disabled:!o,onStart:Ye,onDrag:ct,onStop:Ae,handle:k,cancel:".react-resizable-handle"+(F?","+F:""),scale:x,nodeRef:ae,children:Ze}),Ze}var ft=()=>{},Xa="react-grid-layout",rn=!1;try{rn=/firefox/i.test(navigator.userAgent)}catch{}function Gi(t,s){const a=tt.Children.toArray(t),r=tt.Children.toArray(s);if(a.length!==r.length)return!1;for(let l=0;l<a.length;l++){const d=a[l],c=r[l];if(d?.key!==c?.key)return!1}return!0}function Ka(t,s,a,r){const l=[],d=new Set;tt.Children.forEach(s,i=>{if(!tt.isValidElement(i)||i.key===null)return;const o=String(i.key);d.add(o);const u=t.find(h=>h.i===o);if(u)l.push(Lt(u));else{const n=i.props["data-grid"];n?l.push({i:o,x:n.x??0,y:n.y??0,w:n.w??1,h:n.h??1,minW:n.minW,maxW:n.maxW,minH:n.minH,maxH:n.maxH,static:n.static,isDraggable:n.isDraggable,isResizable:n.isResizable,resizeHandles:n.resizeHandles,isBounded:n.isBounded}):l.push({i:o,x:0,y:hs(l),w:1,h:1})}});const c=ta(l,{cols:a});return r.compact(c,a)}function Ui(t){const{children:s,width:a,gridConfig:r,dragConfig:l,resizeConfig:d,dropConfig:c,positionStrategy:i=ci,compactor:o,constraints:u=Lr,layout:h=[],droppingItem:n,autoSize:N=!0,className:j="",style:x={},innerRef:b,onLayoutChange:f=ft,onDragStart:p=ft,onDrag:g=ft,onDragStop:C=ft,onResizeStart:k=ft,onResize:F=ft,onResizeStop:D=ft,onDrop:w=ft,onDropDragOver:S=ft}=t,z=m.useMemo(()=>({...di,...r}),[r]),M=m.useMemo(()=>({...ui,...l}),[l]),O=m.useMemo(()=>({...fi,...d}),[d]),A=m.useMemo(()=>({...mi,...c}),[c]),{cols:$,rowHeight:L,maxRows:T,margin:R,containerPadding:v}=z,{enabled:E,bounded:I,handle:W,cancel:le,threshold:pe}=M,{enabled:de,handles:Z,handleComponent:me}=O,{enabled:Y,defaultItem:ee,onDragOver:ue}=A,te=o??ia("vertical"),ae=te.type,G=te.allowOverlap,H=te.preventCollision??!1,X=m.useMemo(()=>n??{i:"__dropping-elem__",...ee},[n,ee]),J=i.type==="transform",he=i.scale,ge=v??R,[Pe,Ue]=m.useState(!1),[be,xe]=m.useState(()=>Ka(h,s,$,te)),[Re,Ne]=m.useState(null),[We,Ft]=m.useState(!1),[Ye,ct]=m.useState(null),[Ae,Ve]=m.useState(),jt=m.useRef(null),wt=m.useRef(null),st=m.useRef(null),Ge=m.useRef(0),Xe=m.useRef(be),Ke=m.useRef(h),_t=m.useRef(s),dt=m.useRef(ae),Le=m.useRef(be);Le.current=be,m.useEffect(()=>{Ue(!0),yt(be,h)||f(be)},[]),m.useEffect(()=>{if(Re||Ye)return;const y=!yt(h,Ke.current),P=!Gi(s,_t.current),_=ae!==dt.current;if(y||P||_){const U=Ka(y?h:be,s,$,te);yt(U,be)||xe(U)}Ke.current=h,_t.current=s,dt.current=ae},[h,s,$,ae,te,Re,Ye,be]),m.useEffect(()=>{if(!Re&&!yt(be,Xe.current)){Xe.current=be;const y=be.filter(P=>P.i!==X.i);f(y)}},[be,Re,f,X.i]);const Gt=m.useMemo(()=>{if(!N)return;const y=hs(be),P=ge[1];return y*L+(y-1)*R[1]+P*2+"px"},[N,be,L,R,ge]),It=m.useCallback((y,P,_,q)=>{const U=Le.current,K=Pt(U,y);if(!K)return;const Q={w:K.w,h:K.h,x:K.x,y:K.y,i:y};jt.current=Lt(K),st.current=U,Ne(Q),p(U,K,K,null,q.e,q.node)},[p]),Ze=m.useCallback((y,P,_,q)=>{const U=Le.current,K=jt.current,Q=Pt(U,y);if(!Q)return;const oe={w:Q.w,h:Q.h,x:Q.x,y:Q.y,i:y},se=At(U,Q,P,_,!0,H,ae,$,G);g(se,K,Q,oe,q.e,q.node),xe(te.compact(se,$)),Ne(oe)},[H,ae,$,G,te,g]),Ot=m.useCallback((y,P,_,q)=>{if(!Re)return;const U=Le.current,K=jt.current,Q=Pt(U,y);if(!Q)return;const oe=At(U,Q,P,_,!0,H,ae,$,G),se=te.compact(oe,$);C(se,K,Q,null,q.e,q.node);const ke=st.current;jt.current=null,st.current=null,Ne(null),xe(se),ke&&!yt(ke,se)&&f(se)},[Re,H,ae,$,G,te,C,f]),re=m.useCallback((y,P,_,q)=>{const U=Le.current,K=Pt(U,y);K&&(wt.current=Lt(K),st.current=U,Ft(!0),k(U,K,K,null,q.e,q.node))},[k]),ie=m.useCallback((y,P,_,q)=>{const U=Le.current,K=wt.current,{handle:Q}=q;let oe=!1,se,ke;const[ze,je]=Xl(U,y,ne=>(se=ne.x,ke=ne.y,["sw","w","nw","n","ne"].includes(Q)&&(["sw","nw","w"].includes(Q)&&(se=ne.x+(ne.w-P),P=ne.x!==se&&se<0?ne.w:P,se=se<0?0:se),["ne","n","nw"].includes(Q)&&(ke=ne.y+(ne.h-_),_=ne.y!==ke&&ke<0?ne.h:_,ke=ke<0?0:ke),oe=!0),H&&!G&&zr(U,{...ne,w:P,h:_,x:se??ne.x,y:ke??ne.y}).filter(ut=>ut.i!==ne.i).length>0&&(ke=ne.y,_=ne.h,se=ne.x,P=ne.w,oe=!1),ne.w=P,ne.h=_,ne));if(!je)return;let Fe=ze;oe&&se!==void 0&&ke!==void 0&&(Fe=At(ze,je,se,ke,!0,H,ae,$,G));const et={w:je.w,h:je.h,x:je.x,y:je.y,i:y,static:!0};F(Fe,K,je,et,q.e,q.node),xe(te.compact(Fe,$)),Ne(et)},[H,ae,$,G,te,F]),ye=m.useCallback((y,P,_,q)=>{const U=Le.current,K=wt.current,Q=Pt(U,y),oe=te.compact(U,$);D(oe,K,Q??null,null,q.e,q.node);const se=st.current;wt.current=null,st.current=null,Ne(null),Ft(!1),xe(oe),se&&!yt(se,oe)&&f(oe)},[$,te,D,f]),fe=m.useCallback(()=>{const y=Le.current;if(!y.some(q=>q.i===X.i)){ct(null),Ne(null),Ve(void 0);return}const _=te.compact(y.filter(q=>q.i!==X.i),$);xe(_),ct(null),Ne(null),Ve(void 0)},[X.i,$,te]),ve=m.useCallback(y=>{if(y.preventDefault(),y.stopPropagation(),rn&&!y.nativeEvent.target?.classList.contains(Xa))return!1;const P=ue?ue(y.nativeEvent):S(y);if(P===!1)return Ye&&fe(),!1;const{dragOffsetX:_=0,dragOffsetY:q=0,...U}=P??{},K={...X,...U},Q=y.currentTarget.getBoundingClientRect(),oe={cols:$,margin:R,maxRows:T,rowHeight:L,containerWidth:a,containerPadding:ge},se=Wt(oe),ke=qt(K.w,se,R[0]),ze=qt(K.h,L,R[1]),je=ke/2,Fe=ze/2,et=y.clientX-Q.left+_-je,ne=y.clientY-Q.top+q-Fe,as=Math.max(0,et),ut=Math.max(0,ne),rs={left:as/he,top:ut/he,e:y.nativeEvent};if(Ye)Ae&&(Ae.left!==rs.left||Ae.top!==rs.top)&&Ve(rs);else{const Ns=Wl(oe,ut,as,K.w,K.h);ct(e.jsx("div",{},K.i)),Ve(rs),xe([...Le.current,{...K,x:Ns.x,y:Ns.y,static:!1,isDraggable:!0}])}},[Ye,Ae,X,ue,S,fe,he,$,R,T,L,a,ge]),Ce=m.useCallback(y=>{y.preventDefault(),y.stopPropagation(),Ge.current--,Ge.current<0&&(Ge.current=0),Ge.current===0&&fe()},[fe]),Me=m.useCallback(y=>{y.preventDefault(),y.stopPropagation(),Ge.current++},[]),Ee=m.useCallback(y=>{y.preventDefault(),y.stopPropagation();const P=Le.current,_=P.find(q=>q.i===X.i);Ge.current=0,fe(),w(P,_,y.nativeEvent)},[X.i,fe,w]),_e=m.useCallback((y,P)=>{if(!y||!y.key)return null;const _=Pt(be,String(y.key));if(!_)return null;const q=typeof _.isDraggable=="boolean"?_.isDraggable:!_.static&&E,U=typeof _.isResizable=="boolean"?_.isResizable:!_.static&&de,K=_.resizeHandles||[...Z],Q=q&&I&&_.isBounded!==!1,oe=me;return e.jsx(Ya,{containerWidth:a,cols:$,margin:R,containerPadding:ge,maxRows:T,rowHeight:L,cancel:le,handle:W,onDragStart:It,onDrag:Ze,onDragStop:Ot,onResizeStart:re,onResize:ie,onResizeStop:ye,isDraggable:q,isResizable:U,isBounded:Q,useCSSTransforms:J&&Pe,usePercentages:!Pe,transformScale:he,positionStrategy:i,dragThreshold:pe,w:_.w,h:_.h,x:_.x,y:_.y,i:_.i,minH:_.minH,minW:_.minW,maxH:_.maxH,maxW:_.maxW,static:_.static,droppingPosition:P?Ae:void 0,resizeHandles:K,resizeHandle:oe,constraints:u,layoutItem:_,layout:be,children:y},_.i)},[be,a,$,R,ge,T,L,le,W,It,Ze,Ot,re,ie,ye,E,de,I,J,Pe,he,i,pe,Ae,Z,me,u]),He=()=>Re?e.jsx(Ya,{w:Re.w,h:Re.h,x:Re.x,y:Re.y,i:Re.i,className:`react-grid-placeholder ${We?"placeholder-resizing":""}`,containerWidth:a,cols:$,margin:R,containerPadding:ge,maxRows:T,rowHeight:L,isDraggable:!1,isResizable:!1,isBounded:!1,useCSSTransforms:J,transformScale:he,constraints:u,layout:be,children:e.jsx("div",{})}):null,at=Rr(Xa,j),Je={height:Gt,...x};return e.jsxs("div",{ref:b,className:at,style:Je,onDrop:Y?Ee:void 0,onDragLeave:Y?Ce:void 0,onDragEnter:Y?Me:void 0,onDragOver:Y?ve:void 0,children:[tt.Children.map(s,y=>tt.isValidElement(y)?_e(y):null),Y&&Ye&&_e(Ye,!0),He()]})}var Yi={lg:1200,md:996,sm:768,xs:480,xxs:0},Xi={lg:12,md:10,sm:6,xs:4,xxs:2},Ps=()=>{};function Ki(t,s,a,r){const l=[];tt.Children.forEach(s,c=>{if(!tt.isValidElement(c)||c.key===null)return;const i=String(c.key),o=t.find(u=>u.i===i);if(o)l.push({...o,i});else{const h=c.props["data-grid"];h?l.push({i,x:h.x??0,y:h.y??0,w:h.w??1,h:h.h??1,minW:h.minW,maxW:h.maxW,minH:h.minH,maxH:h.maxH,static:h.static,isDraggable:h.isDraggable,isResizable:h.isResizable,resizeHandles:h.resizeHandles,isBounded:h.isBounded}):l.push({i,x:0,y:hs(l),w:1,h:1})}});const d=ta(l,{cols:a});return r.compact(d,a)}function Ji(t){const{children:s,width:a,breakpoint:r,breakpoints:l=Yi,cols:d=Xi,layouts:c={},rowHeight:i=150,maxRows:o=1/0,margin:u=[10,10],containerPadding:h=null,compactor:n,onBreakpointChange:N=Ps,onLayoutChange:j=Ps,onWidthChange:x=Ps,...b}=t,f=n??ia("vertical"),p=f.type,g=f.allowOverlap,C=m.useMemo(()=>r??Da(l,a),[]),k=m.useMemo(()=>Ra(C,d),[C,d]),F=m.useMemo(()=>Ds(c,l,C,C,k,p),[]),[D,w]=m.useState(C),[S,z]=m.useState(k),[M,O]=m.useState(F),[A,$]=m.useState(c),L=m.useRef(a),T=m.useRef(r),R=m.useRef(l),v=m.useRef(d),E=m.useRef(c),I=m.useRef(p),W=m.useRef(A);m.useEffect(()=>{W.current=A},[A]);const le=m.useMemo(()=>yt(c,E.current)?null:Ds(c,l,D,D,S,f),[c,l,D,S,f]),pe=le??M;m.useEffect(()=>{le!==null&&(O(le),$(c),W.current=c,E.current=c)},[le,c]),m.useEffect(()=>{if(p!==I.current){const ee=f.compact(Rt(pe),S),ue={...W.current,[D]:ee};O(ee),$(ue),W.current=ue,j(ee,ue),I.current=p}},[p,f,pe,S,g,D,j]),m.useEffect(()=>{const ee=a!==L.current,ue=r!==T.current,te=!yt(l,R.current),ae=!yt(d,v.current);if(ee||ue||te||ae){const G=r??Da(l,a),H=Ra(G,d),X=D;if(X!==G||te||ae){const ge={...W.current};ge[X]||(ge[X]=Rt(M));let Pe=Ds(ge,l,G,X,H,f);Pe=Ki(Pe,s,H,f),ge[G]=Pe,w(G),z(H),O(Pe),$(ge),W.current=ge,N(G,H),j(Pe,ge)}const J=os(u,G),he=h?os(h,G):null;x(a,J,H,he),L.current=a,T.current=r,R.current=l,v.current=d}},[a,r,l,d,D,S,M,s,f,p,g,u,h,N,j,x]);const de=m.useCallback(ee=>{const te={...W.current,[D]:ee};O(ee),$(te),W.current=te,j(ee,te)},[D,j]),Z=m.useMemo(()=>os(u,D),[u,D]),me=m.useMemo(()=>h===null?null:os(h,D),[h,D]),Y=m.useMemo(()=>({cols:S,rowHeight:i,maxRows:o,margin:Z,containerPadding:me}),[S,i,o,Z,me]);return e.jsx(Ui,{...b,width:a,gridConfig:Y,compactor:f,onLayoutChange:de,layout:pe,children:s})}function Qi({editMode:t}){const s=gn();return m.useEffect(()=>{if(t)return s.startDrag({id:"dashboard-layout",type:"dashboard-widget",data:{}}),()=>{s.endDrag()};s.endDrag("dashboard")},[t,s]),null}const Es=["hsl(var(--chart-1))","hsl(var(--chart-2))","hsl(var(--chart-3))","hsl(var(--chart-4))","hsl(var(--chart-5))"],Zi=({schema:t,className:s,onLayoutChange:a,persistLayoutKey:r="dashboard-layout",onRefresh:l})=>{const{width:d,containerRef:c,mounted:i}=zi(),[o,u]=m.useState(!1),[h,n]=m.useState(!1),N=xn(),j=m.useRef(null),x=m.useCallback(()=>{l&&(n(!0),l(),setTimeout(()=>n(!1),600))},[l]);m.useEffect(()=>{if(!(!t.refreshInterval||t.refreshInterval<=0||!l))return j.current=setInterval(x,t.refreshInterval*1e3),()=>{j.current&&clearInterval(j.current)}},[t.refreshInterval,l,x]);const[b,f]=m.useState(()=>{if(typeof window<"u"&&r){const F=localStorage.getItem(r);if(F)try{return JSON.parse(F)}catch(D){console.error("Failed to parse saved layout:",D)}}return{lg:t.widgets?.map((F,D)=>({i:F.id||`widget-${D}`,x:F.layout?.x||D%4*3,y:F.layout?.y||Math.floor(D/4)*4,w:F.layout?.w||3,h:F.layout?.h||4}))||[]}}),p=m.useCallback((F,D)=>{f(D),a?.(F)},[a]),g=m.useCallback(()=>{typeof window<"u"&&r&&localStorage.setItem(r,JSON.stringify(b)),u(!1)},[b,r]),C=m.useCallback(()=>{const F={lg:t.widgets?.map((D,w)=>({i:D.id||`widget-${w}`,x:D.layout?.x||w%4*3,y:D.layout?.y||Math.floor(w/4)*4,w:D.layout?.w||3,h:D.layout?.h||4}))||[]};f(F),typeof window<"u"&&r&&localStorage.removeItem(r)},[t.widgets,r]),k=m.useCallback(F=>{if(F.component)return F.component;const D=F.type,w=F.options||{};if(D==="bar"||D==="line"||D==="area"||D==="pie"||D==="donut"||D==="scatter"){const S=F.data||w.data,z=F.categoryField||w.xField||"name",M=F.valueField||w.yField||"value";if(Ht(S)){const A=S.aggregate,$=A?{field:F.valueField||A.field,function:F.aggregate||A.function,groupBy:F.categoryField||A.groupBy}:void 0,L=$?.field||M;return{type:"object-chart",chartType:D,objectName:F.object||S.object,aggregate:$,xAxisKey:z,series:[{dataKey:L}],colors:Es,className:"h-full"}}if(!S&&F.object){const A=F.aggregate?{field:F.valueField||"value",function:F.aggregate,groupBy:F.categoryField||"name"}:void 0;return{type:"object-chart",chartType:D,objectName:F.object,aggregate:A,xAxisKey:z,series:[{dataKey:F.valueField||"value"}],colors:Es,className:"h-full"}}const O=Array.isArray(S)?S:S?.items||[];return{type:"chart",chartType:D,data:O,xAxisKey:z,series:[{dataKey:M}],colors:Es,className:"h-full"}}if(D==="table"){const S=F.data||w.data;if(Ht(S)){const{data:z,...M}=w;return{type:"data-table",...M,objectName:F.object||S.object,dataProvider:S,data:[],searchable:!1,pagination:!1,className:"border-0"}}return!S&&F.object?{type:"data-table",...w,objectName:F.object,data:[],searchable:!1,pagination:!1,className:"border-0"}:{type:"data-table",...w,data:S?.items||[],searchable:!1,pagination:!1,className:"border-0"}}if(D==="pivot"){const S=F.data||w.data;if(Ht(S)){const{data:z,...M}=w;return{type:"pivot",...M,objectName:F.object||S.object,dataProvider:S,data:[]}}return{type:"pivot",...w,data:Array.isArray(S)?S:S?.items||[]}}return{...F,...w}},[]);return e.jsxs("div",{ref:c,className:V("w-full",s),"data-testid":"grid-layout",children:[N&&e.jsx(Qi,{editMode:o}),e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-2xl font-bold",children:t.title||"Dashboard"}),e.jsx("div",{className:"flex gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsxs(B,{onClick:g,size:"sm",variant:"default",children:[e.jsx(Nr,{className:"h-4 w-4 mr-2"}),"Save Layout"]}),e.jsxs(B,{onClick:C,size:"sm",variant:"outline",children:[e.jsx(ss,{className:"h-4 w-4 mr-2"}),"Reset"]}),e.jsx(B,{onClick:()=>u(!1),size:"sm",variant:"ghost",children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[l&&e.jsxs(B,{onClick:x,size:"sm",variant:"outline",disabled:h,"aria-label":"Refresh dashboard",children:[e.jsx(Js,{className:V("h-4 w-4 mr-2",h&&"animate-spin")}),h?"Refreshing…":"Refresh All"]}),e.jsxs(B,{onClick:()=>u(!0),size:"sm",variant:"outline",children:[e.jsx(ot,{className:"h-4 w-4 mr-2"}),"Edit Layout"]})]})})]}),i&&e.jsx(Ji,{className:"layout",width:d,layouts:b,breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:12,md:10,sm:6,xs:4,xxs:2},rowHeight:60,dragConfig:{enabled:o,handle:".drag-handle"},resizeConfig:{enabled:o},onLayoutChange:p,children:t.widgets?.map((F,D)=>{const w=F.id||`widget-${D}`,S=k(F),z=F.type==="metric";return e.jsx("div",{className:"h-full",children:z?e.jsxs("div",{className:"h-full w-full relative",children:[o&&e.jsx("div",{className:"drag-handle absolute top-2 right-2 z-10 cursor-move p-1 bg-background/80 rounded border border-border",children:e.jsx(pa,{className:"h-4 w-4"})}),e.jsx(Ie,{schema:S,className:"h-full w-full"})]}):e.jsxs(Oe,{className:V("h-full overflow-hidden border-border/50 shadow-sm transition-all","bg-card/50 backdrop-blur-sm",o&&"ring-2 ring-primary/20"),children:[F.title&&e.jsxs($e,{className:"pb-2 border-b border-border/40 bg-muted/20 flex flex-row items-center justify-between",children:[e.jsx(Be,{className:"text-base font-medium tracking-tight truncate",title:F.title,children:F.title}),o&&e.jsx("div",{className:"drag-handle cursor-move p-1 hover:bg-muted/40 rounded",children:e.jsx(pa,{className:"h-4 w-4"})})]}),e.jsx(Te,{className:"p-0 h-full",children:e.jsx("div",{className:V("h-full w-full overflow-auto p-4"),children:e.jsx(Ie,{schema:S})})})]})},w)})})]})};function As(t){if(t!=null)return typeof t=="string"?t:t.defaultValue||t.key}const eo=({label:t,value:s,trend:a,icon:r,className:l,description:d,...c})=>{const i=m.useMemo(()=>{if(typeof r=="string"){const o=Cr[r];return o?e.jsx(o,{className:"h-4 w-4 text-muted-foreground"}):null}return r},[r]);return e.jsxs(Oe,{className:V("h-full overflow-hidden",l),...c,children:[e.jsxs($e,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Be,{className:"text-sm font-medium truncate",children:As(t)}),i&&e.jsx("div",{className:"h-4 w-4 text-muted-foreground shrink-0",children:i})]}),e.jsxs(Te,{children:[e.jsx("div",{className:"text-2xl font-bold truncate",children:s}),(a||d)&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center mt-1 truncate",children:[a&&e.jsxs("span",{className:V("flex items-center mr-2 shrink-0",a.direction==="up"&&"text-green-500",a.direction==="down"&&"text-red-500",a.direction==="neutral"&&"text-yellow-500"),children:[a.direction==="up"&&e.jsx(Sr,{className:"h-3 w-3 mr-1"}),a.direction==="down"&&e.jsx(kr,{className:"h-3 w-3 mr-1"}),a.direction==="neutral"&&e.jsx(Dr,{className:"h-3 w-3 mr-1"}),a.value,"%"]}),e.jsx("span",{className:"truncate",children:As(d)||As(a?.label)})]})]})]})};function Ja(t){if(t!=null)return typeof t=="string"?t:t.defaultValue||t.key}const to=({title:t,value:s,icon:a,trend:r,trendValue:l,description:d,className:c,...i})=>{const o=a&&Cr[a];return e.jsxs(Oe,{className:V("h-full",c),...i,children:[e.jsxs($e,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:Ja(t)}),o&&e.jsx(o,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Te,{children:[e.jsx("div",{className:"text-2xl font-bold",children:s}),(r||l||d)&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center mt-1",children:[r&&l&&e.jsxs("span",{className:V("flex items-center mr-2",r==="up"&&"text-green-500",r==="down"&&"text-red-500",r==="neutral"&&"text-yellow-500"),children:[r==="up"&&e.jsx(Sr,{className:"h-3 w-3 mr-1"}),r==="down"&&e.jsx(kr,{className:"h-3 w-3 mr-1"}),r==="neutral"&&e.jsx(Dr,{className:"h-3 w-3 mr-1"}),l]}),Ja(d)]})]})]})};function so(t,s){if(!s)return String(t);let a="",r="",l=!1,d,c=s;const i=c.match(/^([^0-9.,#]*)/);if(i&&i[1]){const h=i[1];a=h.replace(",",""),h.includes(",")&&(l=!0),c=c.slice(i[1].length)}c.includes(",")&&(l=!0,c=c.replace(/,/g,""));const o=c.match(/\.(\d+)f?/);o&&(d=Number(o[1]),c=c.slice(o[0].length)),r=c.replace(/[0-9#.f]/g,"");const u=d!==void 0?t.toFixed(d):String(t);if(l){const[h,n]=u.split("."),N=h.replace(/\B(?=(\d{3})+(?!\d))/g,",");return a+(n!==void 0?`${N}.${n}`:N)+r}return a+u+r}function us(t,s){if(t.length===0)return 0;switch(s){case"sum":return t.reduce((a,r)=>a+r,0);case"count":return t.length;case"avg":return t.reduce((a,r)=>a+r,0)/t.length;case"min":return Math.min(...t);case"max":return Math.max(...t);default:return t.reduce((a,r)=>a+r,0)}}const nn=({schema:t,className:s})=>{const{title:a,rowField:r,columnField:l,valueField:d,aggregation:c="sum",data:i=[],showRowTotals:o=!1,showColumnTotals:u=!1,format:h,columnColors:n}=t,N=Array.isArray(i)?i:[],{rowKeys:j,colKeys:x,matrix:b,rowTotals:f,colTotals:p,grandTotal:g}=m.useMemo(()=>{const k=new Map,F=new Map,D={};for(const L of N){const T=String(L[r]??""),R=String(L[l]??""),v=Number(L[d])||0;k.set(T,!0),F.set(R,!0),D[T]||(D[T]={}),D[T][R]||(D[T][R]=[]),D[T][R].push(v)}const w=Array.from(k.keys()),S=Array.from(F.keys()),z={},M={},O={};for(const L of w){z[L]={};const T=[];for(const R of S){const v=D[L]?.[R]??[],E=us(v,c);z[L][R]=E,T.push(...v),!O[R]&&O[R]}M[L]=us(T,c)}for(const L of S){const T=[];for(const R of w){const v=D[R]?.[L]??[];T.push(...v)}O[L]=us(T,c)}const A=[];for(const L of N)A.push(Number(L[d])||0);const $=us(A,c);return{rowKeys:w,colKeys:S,matrix:z,rowTotals:M,colTotals:O,grandTotal:$}},[N,r,l,d,c]),C=k=>so(k,h);return N.length===0?e.jsxs("div",{className:V("overflow-auto",s),children:[a&&e.jsx("h3",{className:"text-sm font-semibold mb-2",children:a}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground","data-testid":"pivot-empty-state",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 mb-2 opacity-40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"})]}),e.jsx("p",{className:"text-xs",children:"No data available"})]})]}):e.jsxs("div",{className:V("overflow-auto",s),children:[a&&e.jsx("h3",{className:"text-sm font-semibold mb-2",children:a}),e.jsxs("table",{className:"w-full text-sm border-collapse",role:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"text-left p-2 font-medium text-muted-foreground",children:r}),x.map(k=>e.jsx("th",{className:V("text-right p-2 font-medium",n?.[k]??"text-muted-foreground"),children:k},k)),o&&e.jsx("th",{className:"text-right p-2 font-semibold text-muted-foreground bg-muted/20",children:"Total"})]})}),e.jsx("tbody",{children:j.map(k=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/30",children:[e.jsx("td",{className:"p-2 font-medium",children:k}),x.map(F=>e.jsx("td",{className:V("text-right p-2 tabular-nums",n?.[F]),children:C(b[k]?.[F]??0)},F)),o&&e.jsx("td",{className:"text-right p-2 font-semibold tabular-nums bg-muted/20",children:C(f[k]??0)})]},k))}),u&&e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t-2 border-border font-semibold bg-muted/40",children:[e.jsx("td",{className:"p-2",children:"Total"}),x.map(k=>e.jsx("td",{className:"text-right p-2 tabular-nums",children:C(p[k]??0)},k)),o&&e.jsx("td",{className:"text-right p-2 tabular-nums font-bold",children:C(g)})]})})]})]})},ao=({schema:t,dataSource:s,className:a})=>{const r=m.useContext(Vs),l=s||r?.dataSource,d=Hs(t.bind),[c,i]=m.useState([]),[o,u]=m.useState(!1),[h,n]=m.useState(null);m.useEffect(()=>{let b=!0;const f=async()=>{if(!(!l||!t.objectName)){b&&(u(!0),n(null));try{let p;if(typeof l.find=="function"){const g=await l.find(t.objectName,{$filter:t.filter});p=lr(g)}else return;b&&i(p)}catch(p){console.error("[ObjectPivotTable] Fetch error:",p),b&&n(p instanceof Error?p.message:"Failed to load data")}finally{b&&u(!1)}}};return t.objectName&&!d&&(!t.data||t.data.length===0)&&f(),()=>{b=!1}},[t.objectName,l,d,t.data,t.filter]);const N=d||t.data||c,j=Array.isArray(N)?N:[];if(o&&j.length===0)return e.jsxs("div",{className:V("overflow-auto",a),"data-testid":"pivot-loading",children:[t.title&&e.jsx("h3",{className:"text-sm font-semibold mb-2",children:t.title}),e.jsxs("div",{className:"space-y-2 p-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(we,{className:"h-6 w-24"}),e.jsx(we,{className:"h-6 w-20"}),e.jsx(we,{className:"h-6 w-20"}),e.jsx(we,{className:"h-6 w-20"})]}),[1,2,3].map(b=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(we,{className:"h-5 w-24"}),e.jsx(we,{className:"h-5 w-20"}),e.jsx(we,{className:"h-5 w-20"}),e.jsx(we,{className:"h-5 w-20"})]},b))]})]});if(h)return e.jsxs("div",{className:V("overflow-auto",a),"data-testid":"pivot-error",children:[t.title&&e.jsx("h3",{className:"text-sm font-semibold mb-2",children:t.title}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-destructive","data-testid":"pivot-error-message",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 mb-2 opacity-60",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsx("p",{className:"text-xs",children:h})]})]});if(!l&&t.objectName&&j.length===0)return e.jsxs("div",{className:V("overflow-auto",a),children:[t.title&&e.jsx("h3",{className:"text-sm font-semibold mb-2",children:t.title}),e.jsx("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:e.jsxs("p",{className:"text-xs",children:["No data source available for “",t.objectName,"”"]})})]});const x={...t,data:j};return e.jsx(nn,{schema:x,className:a})},ro=({schema:t,dataSource:s,className:a})=>{const r=m.useContext(Vs),l=s||r?.dataSource,d=Hs(t.bind),[c,i]=m.useState([]),[o,u]=m.useState(!1),[h,n]=m.useState(null);m.useEffect(()=>{let f=!0;const p=async()=>{if(!(!l||!t.objectName)){f&&(u(!0),n(null));try{let g;if(typeof l.find=="function"){const C=await l.find(t.objectName,{$filter:t.filter});g=lr(C)}else return;f&&i(g)}catch(g){console.error("[ObjectDataTable] Fetch error:",g),f&&n(g instanceof Error?g.message:"Failed to load data")}finally{f&&u(!1)}}};return t.objectName&&!d&&(!t.data||t.data.length===0)&&p(),()=>{f=!1}},[t.objectName,l,d,t.data,t.filter]);const N=d||t.data||c,j=Array.isArray(N)?N:[],x=m.useMemo(()=>t.columns&&t.columns.length>0?t.columns:j.length===0?[]:Object.keys(j[0]).filter(p=>!p.startsWith("_")).map(p=>({header:p.charAt(0).toUpperCase()+p.slice(1).replace(/([A-Z])/g," $1"),accessorKey:p})),[t.columns,j]);if(o&&j.length===0)return e.jsx("div",{className:V("overflow-auto",a),"data-testid":"table-loading",children:e.jsxs("div",{className:"space-y-2 p-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(we,{className:"h-6 w-1/4"}),e.jsx(we,{className:"h-6 w-1/4"}),e.jsx(we,{className:"h-6 w-1/4"}),e.jsx(we,{className:"h-6 w-1/4"})]}),[1,2,3,4].map(f=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(we,{className:"h-5 w-1/4"}),e.jsx(we,{className:"h-5 w-1/4"}),e.jsx(we,{className:"h-5 w-1/4"}),e.jsx(we,{className:"h-5 w-1/4"})]},f))]})});if(h)return e.jsx("div",{className:V("overflow-auto",a),"data-testid":"table-error",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-destructive","data-testid":"table-error-message",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 mb-2 opacity-60",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsx("p",{className:"text-xs",children:h})]})});if(!l&&t.objectName&&j.length===0)return e.jsx("div",{className:V("overflow-auto",a),children:e.jsx("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:e.jsxs("p",{className:"text-xs",children:["No data source available for “",t.objectName,"”"]})})});if(j.length===0)return e.jsx("div",{className:V("overflow-auto",a),"data-testid":"table-empty-state",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 mb-2 opacity-40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"3",y1:"9",x2:"21",y2:"9"}),e.jsx("line",{x1:"9",y1:"21",x2:"9",y2:"9"})]}),e.jsx("p",{className:"text-xs",children:"No data available"})]})});const b={...t,type:"data-table",data:j,columns:x};return e.jsx(Ie,{schema:b,className:a})},no={breadcrumb:["Dashboard","Configuration"],sections:[{key:"layout",title:"Layout",fields:[{key:"columns",label:"Columns",type:"slider",defaultValue:3,min:1,max:12,step:1},{key:"gap",label:"Gap",type:"slider",defaultValue:4,min:0,max:16,step:1},{key:"rowHeight",label:"Row height",type:"input",defaultValue:"120",placeholder:"e.g. 120"}]},{key:"data",title:"Data",collapsible:!0,fields:[{key:"refreshInterval",label:"Refresh interval",type:"select",defaultValue:"0",options:[{value:"0",label:"Manual"},{value:"30",label:"30s"},{value:"60",label:"1 min"},{value:"300",label:"5 min"}]}]},{key:"appearance",title:"Appearance",collapsible:!0,defaultCollapsed:!0,fields:[{key:"title",label:"Title",type:"input",placeholder:"Dashboard title"},{key:"showDescription",label:"Show description",type:"switch",defaultValue:!0},{key:"theme",label:"Theme",type:"select",defaultValue:"auto",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"auto",label:"Auto"}]}]}]};function Vo({open:t,onClose:s,config:a,onSave:r,onFieldChange:l}){const{draft:d,isDirty:c,updateField:i,discard:o}=Us(a,{onUpdate:l});return e.jsx(Ys,{open:t,onClose:s,schema:no,draft:d,isDirty:c,onFieldChange:i,onSave:()=>r(d),onDiscard:o})}const lo=[{value:"metric",label:"Metric"},{value:"bar",label:"Bar Chart"},{value:"line",label:"Line Chart"},{value:"pie",label:"Pie Chart"},{value:"donut",label:"Donut Chart"},{value:"area",label:"Area Chart"},{value:"scatter",label:"Scatter Plot"},{value:"table",label:"Table"},{value:"pivot",label:"Pivot Table"},{value:"list",label:"List"},{value:"custom",label:"Custom"}],io=[{value:"default",label:"Default"},{value:"blue",label:"Blue"},{value:"teal",label:"Teal"},{value:"orange",label:"Orange"},{value:"purple",label:"Purple"},{value:"success",label:"Success"},{value:"warning",label:"Warning"},{value:"danger",label:"Danger"}],Qa=[{value:"count",label:"Count"},{value:"sum",label:"Sum"},{value:"avg",label:"Average"},{value:"min",label:"Min"},{value:"max",label:"Max"}],oo=["bar","line","area","pie","donut","scatter"];function Za(t){return!!t&&oo.includes(t)}const er=[{value:"group",label:"Group"},{value:"value",label:"Value"}],tr=[{value:"asc",label:"↑"},{value:"desc",label:"↓"}];function es(t,s,a,r){return{key:t,label:s,type:"custom",render:(l,d,c)=>e.jsx(fr,{label:s,children:e.jsx("div",{"data-testid":`config-field-${t}`,children:e.jsx(mr,{options:r??[],value:l??"",onValueChange:d,placeholder:a,searchPlaceholder:"Search fields…",emptyText:"No fields found.",className:"h-7 w-32 text-xs",disabled:!c.object})})})}}function co(t,s,a){const r=t&&t.length>0,l=r?{key:"object",label:"Data source",type:"custom",render:(N,j)=>e.jsx(fr,{label:"Data source",children:e.jsx("div",{"data-testid":"config-field-object",children:e.jsx(mr,{options:t,value:N??"",onValueChange:j,placeholder:"Select object…",searchPlaceholder:"Search objects…",emptyText:"No objects found.",className:"h-7 w-32 text-xs"})})})}:{key:"object",label:"Data source",type:"input",placeholder:"Object name"},d=r?es("categoryField","Category field","Select field…",s):{key:"categoryField",label:"Category field",type:"input",placeholder:"e.g. status"},c=r?es("valueField","Value field","Select field…",s):{key:"valueField",label:"Value field",type:"input",placeholder:"e.g. amount"},i=r?es("rowField","Field","Select row field…",s):{key:"rowField",label:"Field",type:"input",placeholder:"e.g. owner"},o=r?es("columnField","Field","Select column field…",s):{key:"columnField",label:"Field",type:"input",placeholder:"e.g. stage"},u=r?es("pivotValueField","Field","Select value field…",s):{key:"pivotValueField",label:"Field",type:"input",placeholder:"e.g. amount"};return{breadcrumb:["Dashboard",{pivot:"Pivot table",table:"Table"}[a??""]??(Za(a)?"Chart":"Widget")],sections:[{key:"general",title:"General",fields:[{key:"title",label:"Title",type:"input",placeholder:"Widget title"},{key:"description",label:"Description",type:"input",placeholder:"Widget description"},{key:"type",label:"Widget type",type:"select",options:lo,defaultValue:"metric"}]},{key:"data",title:"Data Binding",collapsible:!0,visibleWhen:N=>N.type!=="pivot",fields:[l,d,c,{key:"aggregate",label:"Aggregation",type:"select",options:Qa,defaultValue:"count"}]},{key:"pivot-data",title:"Data",collapsible:!0,visibleWhen:N=>N.type==="pivot",fields:[l]},{key:"pivot-rows",title:"Rows",collapsible:!0,visibleWhen:N=>N.type==="pivot",fields:[i,{key:"rowSortBy",label:"Sort by",type:"icon-group",options:er,defaultValue:"group"},{key:"rowSortOrder",label:"Sort order",type:"icon-group",options:tr,defaultValue:"asc"},{key:"showRowLabels",label:"Show label",type:"switch",defaultValue:!0},{key:"showRowTotals",label:"Show totals",type:"switch",defaultValue:!1}]},{key:"pivot-columns",title:"Columns",collapsible:!0,visibleWhen:N=>N.type==="pivot",fields:[o,{key:"columnSortBy",label:"Sort by",type:"icon-group",options:er,defaultValue:"group"},{key:"columnSortOrder",label:"Sort order",type:"icon-group",options:tr,defaultValue:"asc"},{key:"showColumnLabels",label:"Show label",type:"switch",defaultValue:!0},{key:"showColumnTotals",label:"Show totals",type:"switch",defaultValue:!1}]},{key:"pivot-values",title:"Values",collapsible:!0,visibleWhen:N=>N.type==="pivot",fields:[u,{key:"aggregation",label:"Aggregation",type:"select",options:Qa,defaultValue:"sum"},{key:"format",label:"Number format",type:"input",placeholder:"e.g. $,.2f"}]},{key:"chart-axis",title:"Axis & Series",collapsible:!0,visibleWhen:N=>Za(N.type),fields:[{key:"xAxisLabel",label:"X-axis label",type:"input",placeholder:"e.g. Month"},{key:"yAxisLabel",label:"Y-axis label",type:"input",placeholder:"e.g. Revenue"},{key:"showLegend",label:"Show legend",type:"switch",defaultValue:!0}]},{key:"table-columns",title:"Columns",collapsible:!0,visibleWhen:N=>N.type==="table",fields:[{key:"searchable",label:"Searchable",type:"switch",defaultValue:!1},{key:"pagination",label:"Pagination",type:"switch",defaultValue:!1}]},{key:"layout",title:"Layout",collapsible:!0,fields:[{key:"layoutW",label:"Width (columns)",type:"slider",min:1,max:12,step:1,defaultValue:1},{key:"layoutH",label:"Height (rows)",type:"slider",min:1,max:6,step:1,defaultValue:1}]},{key:"appearance",title:"Appearance",collapsible:!0,defaultCollapsed:!0,fields:[{key:"colorVariant",label:"Color variant",type:"select",options:io,defaultValue:"default"},{key:"actionUrl",label:"Action URL",type:"input",placeholder:"https://..."}]}]}}function sr(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="object"){const s=t;return s.defaultValue||s.key||""}return String(t)}function Ho({open:t,onClose:s,config:a,onSave:r,onFieldChange:l,headerExtra:d,availableObjects:c,availableFields:i}){const o=m.useMemo(()=>({...a,title:typeof a.title=="object"?sr(a.title):a.title,description:typeof a.description=="object"?sr(a.description):a.description}),[a]),{draft:u,isDirty:h,updateField:n,discard:N}=Us(o,{onUpdate:l}),j=m.useMemo(()=>co(c,i,u.type),[c,i,u.type]);return e.jsx(Ys,{open:t,onClose:s,schema:j,draft:u,isDirty:h,onFieldChange:n,onSave:()=>r(u),onDiscard:N,headerExtra:d})}Se.register("dashboard",ql,{namespace:"view",label:"Dashboard",category:"Complex",icon:"layout-dashboard",inputs:[{name:"columns",type:"number",label:"Columns",defaultValue:3},{name:"gap",type:"number",label:"Gap",defaultValue:4},{name:"className",type:"string",label:"CSS Class"}],defaultProps:{columns:3,widgets:[]}});Se.register("metric",eo,{namespace:"plugin-dashboard",label:"Metric Widget",category:"Dashboard",inputs:[{name:"label",type:"string",label:"Label"},{name:"value",type:"string",label:"Value"}]});Se.register("metric-card",to,{namespace:"plugin-dashboard",label:"Metric Card",category:"Dashboard",inputs:[{name:"title",type:"string",label:"Title"},{name:"value",type:"string",label:"Value",required:!0},{name:"icon",type:"string",label:"Icon (Lucide name)"},{name:"trend",type:"enum",label:"Trend",enum:[{label:"Up",value:"up"},{label:"Down",value:"down"},{label:"Neutral",value:"neutral"}]},{name:"trendValue",type:"string",label:"Trend Value (e.g., +12%)"},{name:"description",type:"string",label:"Description"}],defaultProps:{title:"Metric",value:"0"}});Se.register("pivot",nn,{namespace:"plugin-dashboard",label:"Pivot Table",category:"Dashboard",icon:"table-2",inputs:[{name:"title",type:"string",label:"Title"},{name:"rowField",type:"string",label:"Row Field",required:!0},{name:"columnField",type:"string",label:"Column Field",required:!0},{name:"valueField",type:"string",label:"Value Field",required:!0},{name:"aggregation",type:"enum",label:"Aggregation",enum:[{label:"Sum",value:"sum"},{label:"Count",value:"count"},{label:"Average",value:"avg"},{label:"Min",value:"min"},{label:"Max",value:"max"}]},{name:"showRowTotals",type:"boolean",label:"Show Row Totals"},{name:"showColumnTotals",type:"boolean",label:"Show Column Totals"},{name:"format",type:"string",label:"Number Format"}],defaultProps:{rowField:"",columnField:"",valueField:"",aggregation:"sum",data:[]}});Se.register("object-pivot",ao,{namespace:"plugin-dashboard",label:"Object Pivot Table",category:"Dashboard",icon:"table-2",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"title",type:"string",label:"Title"},{name:"rowField",type:"string",label:"Row Field",required:!0},{name:"columnField",type:"string",label:"Column Field",required:!0},{name:"valueField",type:"string",label:"Value Field",required:!0},{name:"aggregation",type:"enum",label:"Aggregation",enum:[{label:"Sum",value:"sum"},{label:"Count",value:"count"},{label:"Average",value:"avg"},{label:"Min",value:"min"},{label:"Max",value:"max"}]},{name:"showRowTotals",type:"boolean",label:"Show Row Totals"},{name:"showColumnTotals",type:"boolean",label:"Show Column Totals"},{name:"filter",type:"array",label:"Filter"},{name:"format",type:"string",label:"Number Format"}],defaultProps:{rowField:"",columnField:"",valueField:"",aggregation:"sum"}});Se.register("dashboard-grid",Zi,{namespace:"plugin-dashboard",label:"Dashboard Grid (Editable)",category:"Complex",icon:"layout-grid",inputs:[{name:"title",type:"string",label:"Title"},{name:"persistLayoutKey",type:"string",label:"Layout Storage Key",defaultValue:"dashboard-layout"},{name:"className",type:"string",label:"CSS Class"}],defaultProps:{title:"Dashboard",widgets:[],persistLayoutKey:"dashboard-layout"}});Se.register("object-data-table",ro,{namespace:"plugin-dashboard",label:"Object Data Table",category:"Dashboard",icon:"table",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filter",type:"array",label:"Filter"},{name:"searchable",type:"boolean",label:"Searchable"},{name:"pagination",type:"boolean",label:"Pagination"}],defaultProps:{searchable:!1,pagination:!1}});const uo=({schema:t})=>{const{title:s,description:a,data:r,columns:l}=t;t.chart?.type;const d=!!t.chart;return e.jsxs(Oe,{className:`h-full flex flex-col ${t.className||""}`,children:[e.jsxs($e,{children:[s&&e.jsx(Be,{children:s}),a&&e.jsx(Xs,{children:a})]}),e.jsxs(Te,{className:"flex-1 overflow-auto space-y-4",children:[d&&(()=>{const c=t.chart?.type;let i=c?Se.get(c):null;return i||(i=Se.get("chart")),i?e.jsx("div",{className:"min-h-[300px] border rounded-lg p-4 bg-background/50",children:e.jsx(i,{schema:{...t.chart,data:t.chart.data||r}})}):e.jsxs("div",{className:"min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center",children:["Unknown component type: ",c||"chart"]})})(),r&&r.length>0&&e.jsx("div",{className:"border rounded-lg",children:(()=>{const c=Se.get("aggrid")||Se.get("table");return c?e.jsx(c,{schema:{type:"aggrid",rowData:r,columnDefs:l,domLayout:"autoHeight"}}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"text-xs uppercase bg-muted",children:e.jsx("tr",{children:l?.map(i=>e.jsx("th",{className:"px-6 py-3",children:i.headerName||i.label||i.field},i.field))})}),e.jsx("tbody",{children:r.map((i,o)=>e.jsx("tr",{className:"bg-background border-b",children:l?.map(u=>e.jsx("td",{className:"px-6 py-4",children:i[u.field]},u.field))},o))})]})})})()})]})]})};function fo(t,s,a){const r=t.fields||[],l=r.map(i=>i.label||i.name),d=s.map(i=>r.map(o=>{let u=i[o.name];return u=on(u),typeof u=="string"&&(u.includes(",")||u.includes('"')||u.includes(`
6
+ `))?`"${u.replace(/"/g,'""')}"`:u??""})),c=[...a?.includeHeaders!==!1?[l.join(",")]:[],...d.map(i=>i.join(","))].join(`
7
+ `);ws(c,a?.filename||`${t.title||"report"}.csv`,"text/csv")}function mo(t,s,a){const r={title:t.title,description:t.description,generatedAt:new Date().toISOString(),data:s},l=JSON.stringify(r,null,2);ws(l,a?.filename||`${t.title||"report"}.json`,"application/json")}function ln(t,s,a){const r=t.fields||[],l=dn(a?.orientation),d=cn(a?.pageSize),c=`<!DOCTYPE html>
8
+ <html>
9
+ <head>
10
+ <meta charset="utf-8">
11
+ <title>${it(t.title||"Report")}</title>
12
+ <style>
13
+ @page { size: ${d} ${l}; margin: 20mm; }
14
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
15
+ h1 { font-size: 24px; margin-bottom: 8px; }
16
+ .description { color: #666; margin-bottom: 24px; }
17
+ .meta { color: #999; font-size: 12px; margin-bottom: 16px; }
18
+ table { width: 100%; border-collapse: collapse; margin-top: 16px; }
19
+ th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
20
+ td { padding: 8px 12px; border: 1px solid #ddd; }
21
+ tr:nth-child(even) { background: #fafafa; }
22
+ </style>
23
+ </head>
24
+ <body>
25
+ <h1>${it(t.title||"Report")}</h1>
26
+ ${t.description?`<p class="description">${it(t.description)}</p>`:""}
27
+ <p class="meta">Generated: ${new Date().toLocaleString()}</p>
28
+ <table>
29
+ <thead><tr>${r.map(i=>`<th>${it(i.label||i.name)}</th>`).join("")}</tr></thead>
30
+ <tbody>${s.map(i=>`<tr>${r.map(o=>`<td>${it(String(i[o.name]??""))}</td>`).join("")}</tr>`).join("")}</tbody>
31
+ </table>
32
+ </body>
33
+ </html>`;ws(c,a?.filename||`${t.title||"report"}.html`,"text/html")}function po(t,s,a){const r=t.fields||[],l=dn(a?.orientation),d=cn(a?.pageSize),c=window.open("","_blank");if(!c){const i={...a,filename:a?.filename?.replace(/\.pdf$/,".html")||`${t.title||"report"}.html`};ln(t,s,i);return}c.document.write(`<!DOCTYPE html>
34
+ <html>
35
+ <head>
36
+ <meta charset="utf-8">
37
+ <title>${it(t.title||"Report")}</title>
38
+ <style>
39
+ @page { size: ${d} ${l}; margin: 20mm; }
40
+ @media print { .no-print { display: none; } }
41
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
42
+ h1 { font-size: 24px; margin-bottom: 8px; }
43
+ .description { color: #666; margin-bottom: 24px; }
44
+ .meta { color: #999; font-size: 12px; margin-bottom: 16px; }
45
+ table { width: 100%; border-collapse: collapse; margin-top: 16px; }
46
+ th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
47
+ td { padding: 8px 12px; border: 1px solid #ddd; }
48
+ tr:nth-child(even) { background: #fafafa; }
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <h1>${it(t.title||"Report")}</h1>
53
+ ${t.description?`<p class="description">${it(t.description)}</p>`:""}
54
+ <p class="meta">Generated: ${new Date().toLocaleString()}</p>
55
+ <table>
56
+ <thead><tr>${r.map(i=>`<th>${it(i.label||i.name)}</th>`).join("")}</tr></thead>
57
+ <tbody>${s.map(i=>`<tr>${r.map(o=>`<td>${it(String(i[o.name]??""))}</td>`).join("")}</tr>`).join("")}</tbody>
58
+ </table>
59
+ </body>
60
+ </html>`),c.document.close(),c.onload=()=>{c.print()}}function ho(t,s,a){const r=t.fields||[],l=r.map(i=>i.label||i.name),d=s.map(i=>r.map(o=>{let u=i[o.name];return u=on(u),typeof u=="string"&&(u.includes(",")||u.includes('"')||u.includes(`
61
+ `)||u.includes(" "))?`"${u.replace(/"/g,'""')}"`:u??""})),c="\uFEFF"+[...a?.includeHeaders!==!1?[l.join(" ")]:[],...d.map(i=>i.join(" "))].join(`
62
+ `);ws(c,a?.filename||`${t.title||"report"}.tsv`,"text/tab-separated-values")}function xo(t,s,a,r){switch(t){case"csv":fo(s,a,r);break;case"json":mo(s,a,r);break;case"html":ln(s,a,r);break;case"pdf":po(s,a,r);break;case"excel":ho(s,a,r);break;default:console.warn(`Unsupported export format: ${t}`)}}function it(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function on(t){if(typeof t=="string"&&t.length>0){const s=t.charAt(0);if(s==="="||s==="+"||s==="-"||s==="@"||s==="|")return` ${t}`}return t}function cn(t){return["A4","A3","Letter","Legal"].includes(t||"")?t:"A4"}function dn(t){return t==="landscape"?"landscape":"portrait"}function ws(t,s,a){const r=new Blob([t],{type:`${a};charset=utf-8`}),l=URL.createObjectURL(r),d=document.createElement("a");d.href=l,d.download=s,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(l)}function ar(t,s){if(t==null||t==="")return"";const a=s?.type,r=s?.format;if(a==="date"||r==="date"||go(t))return bo(t);if(a==="number"||typeof t=="number"){const l=typeof t=="number"?t:Number(t);return isNaN(l)?String(t):r==="currency"||r==="currency_cny"?`¥${l.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0})}`:r==="currency_usd"?`$${l.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0})}`:r==="percent"?`${l.toLocaleString("en-US",{minimumFractionDigits:1,maximumFractionDigits:1})}%`:l.toLocaleString("en-US")}return String(t)}function go(t){return typeof t!="string"?!1:/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(t)}function bo(t){try{const s=new Date(t);if(isNaN(s.getTime()))return String(t);const a=s.getFullYear(),r=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0");return`${a}-${r}-${l}`}catch{return String(t)}}function yo(t,s){if(!s||s.length===0||!t||t.length===0)return null;const a=s[0],r=a.field,l=new Map;for(const i of t){const o=String(i[r]??"(empty)");l.has(o)||l.set(o,[]),l.get(o).push(i)}const d=[];for(const[i,o]of l)d.push({key:i,label:`${a.label||r}: ${i}`,rows:o});const c=a.sort==="desc"?-1:1;return d.sort((i,o)=>i.key.localeCompare(o.key)*c),d}const un=({schema:t,onRefresh:s})=>{const{report:a,data:r,showToolbar:l=!0,allowExport:d=!0,allowPrint:c=!0,loading:i=!1}=t,o=x=>{if(!a){console.warn("ReportViewer: Cannot export, no report defined");return}xo(x,a,r||[],a.exportConfigs?.[x])},u=()=>{window.print()},h=()=>{s?.()},n=(x,b)=>{if(!r)return 0;const f=r.map(p=>Number(p[x])||0);switch(b){case"count":return r.length;case"sum":return f.reduce((p,g)=>p+g,0);case"avg":return f.length>0?(f.reduce((p,g)=>p+g,0)/f.length).toFixed(2):0;case"min":return f.length>0?Math.min(...f):0;case"max":return f.length>0?Math.max(...f):0;default:return""}},N=(x,b)=>{const f=a?.conditionalFormatting;if(!(!f||!Array.isArray(f)))for(const p of f){if(p.field!==x)continue;const g=String(b??""),C=String(p.value??"");let k=!1;switch(p.operator){case"equals":k=g===C;break;case"not_equals":k=g!==C;break;case"contains":k=g.includes(C);break;case"greater_than":k=Number(b)>Number(p.value);break;case"less_than":k=Number(b)<Number(p.value);break}if(k){const F={};return p.backgroundColor&&(F.backgroundColor=p.backgroundColor),p.textColor&&(F.color=p.textColor),F}}},j=(x,b)=>{if(x==null||x==="")return"";if(b.renderAs==="badge"){const f=b.colorMap?.[String(x)]||"";return e.jsx(St,{className:f,children:String(x)})}return ar(x,b)};return a?e.jsxs("div",{className:"space-y-4",children:[l&&e.jsxs("div",{className:"flex items-center justify-between gap-2 p-4 bg-card rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a.title}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.refreshInterval&&e.jsxs(B,{variant:"outline",size:"sm",onClick:h,children:[e.jsx(Js,{className:"h-4 w-4 mr-2"}),"Refresh"]}),c&&e.jsxs(B,{variant:"outline",size:"sm",onClick:u,children:[e.jsx(xr,{className:"h-4 w-4 mr-2"}),"Print"]}),d&&a.showExportButtons&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>o("pdf"),children:[e.jsx(Vt,{className:"h-4 w-4 mr-2"}),"PDF"]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>o("excel"),children:[e.jsx(Vt,{className:"h-4 w-4 mr-2"}),"Excel"]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>o("csv"),children:[e.jsx(Vt,{className:"h-4 w-4 mr-2"}),"CSV"]})]})]})]}),e.jsxs(Oe,{children:[e.jsxs($e,{children:[!l&&a.title&&e.jsx(Be,{children:a.title}),!l&&a.description&&e.jsx(Xs,{children:a.description})]}),e.jsxs(Te,{className:"space-y-6",children:[i&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[1,2,3].map(x=>e.jsx(Oe,{children:e.jsxs(Te,{className:"p-4 space-y-2",children:[e.jsx(we,{className:"h-4 w-20"}),e.jsx(we,{className:"h-8 w-28"})]})},x))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:"h-10 w-full"}),[1,2,3,4,5].map(x=>e.jsx(we,{className:"h-8 w-full"},x))]})]}),!i&&a.sections?.map((x,b)=>x.visible===!1?null:e.jsxs("div",{className:"space-y-2",children:[x.title&&x.type!=="header"&&e.jsx("h3",{className:"text-lg font-semibold border-b pb-2",children:x.title}),x.type==="header"&&x.title&&e.jsx("div",{className:"text-2xl font-bold py-4",children:x.title}),x.type==="summary"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:a.fields?.filter(f=>f.showInSummary).map((f,p)=>e.jsx(Oe,{children:e.jsxs(Te,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:f.label||f.name}),e.jsx("div",{className:"text-2xl font-bold",children:ar(n(f.name,f.aggregation),f)})]})},p))}),x.type==="chart"&&x.chart&&e.jsx("div",{className:"min-h-[300px]",children:(()=>{let f=x.chart.type;const p=!!x.chart.chartType;!f&&p&&(f="chart"),f&&!!Se.get(f)||(f="chart");const k=f==="chart"?{xAxisKey:x.chart.xAxisKey||x.chart.xAxisField||"name",series:x.chart.series||(x.chart.yAxisFields?x.chart.yAxisFields.map(D=>({dataKey:D})):[]),chartType:x.chart.chartType||"bar"}:{},F={...x.chart,type:f,...k,data:r||x.chart.data,className:x.chart.className||"w-full h-[350px]"};return e.jsx(Ie,{schema:F})})()}),x.type==="table"&&e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[600px]",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:x.columns?.map((f,p)=>e.jsx("th",{className:`px-4 py-2 font-medium ${f.type==="number"?"text-right":"text-left"}`,children:f.label||f.name},p))})}),e.jsx("tbody",{children:(()=>{const f=yo(r||[],a.groupBy||[]);return f?f.map(p=>e.jsxs(tt.Fragment,{children:[e.jsx("tr",{className:"bg-muted/60",children:e.jsxs("td",{colSpan:x.columns?.length||1,className:"px-4 py-2 font-semibold text-sm",children:[p.label," (",p.rows.length,")"]})}),p.rows.map((g,C)=>e.jsx("tr",{className:"border-t hover:bg-muted/50 even:bg-muted/20",children:x.columns?.map((k,F)=>e.jsx("td",{className:`px-4 py-2 ${k.type==="number"?"text-right tabular-nums":""}`,style:N(k.name,g[k.name]),children:j(g[k.name],k)},F))},C))]},p.key)):r?.map((p,g)=>e.jsx("tr",{className:"border-t hover:bg-muted/50 even:bg-muted/20",children:x.columns?.map((C,k)=>e.jsx("td",{className:`px-4 py-2 ${C.type==="number"?"text-right tabular-nums":""}`,style:N(C.name,p[C.name]),children:j(p[C.name],C)},k))},g))})()})]})}),x.type==="text"&&x.text&&e.jsx("div",{className:"prose max-w-none",children:e.jsx("p",{children:x.text})}),x.type==="page-break"&&e.jsx("div",{className:"border-t-2 border-dashed my-8 print:page-break-after-always"}),x.content&&e.jsx(Ie,{schema:x.content})]},b)),!a.sections&&r&&r.length>0&&e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[600px]",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:a.fields?.map((x,b)=>e.jsx("th",{className:`px-4 py-2 font-medium ${x.type==="number"?"text-right":"text-left"}`,children:x.label||x.name},b))})}),e.jsx("tbody",{children:r.map((x,b)=>e.jsx("tr",{className:"border-t hover:bg-muted/50 even:bg-muted/20",children:a.fields?.map((f,p)=>e.jsx("td",{className:`px-4 py-2 ${f.type==="number"?"text-right tabular-nums":""}`,style:N(f.name,x[f.name]),children:j(x[f.name],f)},p))},b))})]})})]})]})]}):e.jsx(Oe,{children:e.jsx(Te,{className:"p-8 text-center text-muted-foreground",children:"No report to display"})})},fn=({schedule:t,onChange:s})=>{const[a,r]=m.useState(t||{enabled:!1,frequency:"weekly",time:"09:00",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:["pdf"]}),l=o=>{const u={...a,...o};r(u),s?.(u)},d=[{value:"once",label:"Once"},{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"monthly",label:"Monthly"},{value:"quarterly",label:"Quarterly"},{value:"yearly",label:"Yearly"}],c=[{value:"pdf",label:"PDF"},{value:"excel",label:"Excel"},{value:"csv",label:"CSV"},{value:"html",label:"HTML"}],i=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"}];return e.jsxs(Oe,{children:[e.jsx($e,{children:e.jsxs(Be,{className:"flex items-center gap-2",children:[e.jsx(ps,{className:"h-5 w-5"}),"Schedule Configuration"]})}),e.jsxs(Te,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"schedule-enabled",checked:a.enabled||!1,onChange:o=>l({enabled:o.target.checked}),className:"rounded"}),e.jsx(ce,{htmlFor:"schedule-enabled",children:"Enable Scheduled Report"})]}),a.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Frequency"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:a.frequency||"weekly",onChange:o=>l({frequency:o.target.value}),children:d.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))})]}),a.frequency==="weekly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Day of Week"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:a.dayOfWeek??1,onChange:o=>l({dayOfWeek:Number(o.target.value)}),children:i.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))})]}),a.frequency==="monthly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Day of Month"}),e.jsx(qe,{type:"number",min:1,max:31,value:a.dayOfMonth??1,onChange:o=>l({dayOfMonth:Number(o.target.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ce,{className:"flex items-center gap-2",children:[e.jsx(Xn,{className:"h-4 w-4"}),"Time"]}),e.jsx(qe,{type:"time",value:a.time||"09:00",onChange:o=>l({time:o.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Timezone"}),e.jsx(qe,{value:a.timezone||"",onChange:o=>l({timezone:o.target.value}),placeholder:"e.g. America/New_York"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Export Formats"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.map(o=>e.jsxs("label",{className:"flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50",children:[e.jsx("input",{type:"checkbox",checked:a.formats?.includes(o.value)||!1,onChange:u=>{const h=a.formats||[];l({formats:u.target.checked?[...h,o.value]:h.filter(n=>n!==o.value)})},className:"rounded"}),e.jsx("span",{className:"text-sm",children:o.label})]},o.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ce,{className:"flex items-center gap-2",children:[e.jsx(jr,{className:"h-4 w-4"}),"Email Recipients"]}),e.jsx(qe,{placeholder:"email1@example.com, email2@example.com",value:a.recipients?.join(", ")||"",onChange:o=>l({recipients:o.target.value.split(",").map(u=>u.trim()).filter(Boolean)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Email Subject"}),e.jsx(qe,{value:a.subject||"",onChange:o=>l({subject:o.target.value}),placeholder:"Scheduled Report: {report_title}"})]})]})]})]})},vo=({schema:t})=>{const{report:s,dataSources:a=[],availableFields:r=[],showPreview:l=!0,onSave:d,onCancel:c}=t,[i,o]=m.useState(s||{type:"report",title:"New Report",fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[u,h]=m.useState(i.fields||[]),[n,N]=m.useState(i.filters||[]),[j,x]=m.useState(i.groupBy||[]),[b,f]=m.useState(i.sections||[]),p=()=>{if(r.length>0&&u.length<r.length){const T=r.find(R=>!u.some(v=>v.name===R.name));if(T){const R=[...u,T];h(R),o({...i,fields:R})}}},g=T=>{const R=u.filter((v,E)=>E!==T);h(R),o({...i,fields:R})},C=(T,R)=>{const v=[...u];v[T]=R,h(v),o({...i,fields:v})},k=()=>{const T={field:r[0]?.name||"",operator:"equals",value:""},R=[...n,T];N(R),o({...i,filters:R})},F=T=>{const R=n.filter((v,E)=>E!==T);N(R),o({...i,filters:R})},D=(T,R)=>{const v=[...n];v[T]=R,N(v),o({...i,filters:v})},w=()=>{const T={field:r[0]?.name||"",sort:"asc"},R=[...j,T];x(R),o({...i,groupBy:R})},S=T=>{const R=j.filter((v,E)=>E!==T);x(R),o({...i,groupBy:R})},z=(T,R)=>{const v=[...j];v[T]=R,x(v),o({...i,groupBy:v})},M=T=>{const R={type:T,title:`New ${T} Section`},v=[...b,R];f(v),o({...i,sections:v})},O=T=>{const R=b.filter((v,E)=>E!==T);f(R),o({...i,sections:R})},A=(T,R)=>{const v=[...b];v[T]=R,f(v),o({...i,sections:v})},$=()=>{console.log("Saving report:",i),d&&alert("Report saved! (Handler: "+d+")")},L=()=>{c&&console.log("Report cancelled:",c)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Oe,{children:[e.jsxs($e,{children:[e.jsx(Be,{children:"Report Builder"}),e.jsx(Xs,{children:"Configure your report settings, fields, filters, and sections"})]}),e.jsxs(Te,{children:[e.jsxs(Ws,{defaultValue:"basic",className:"w-full",children:[e.jsxs(Gs,{className:"grid w-full grid-cols-6",children:[e.jsxs(nt,{value:"basic",children:[e.jsx(Kn,{className:"h-4 w-4 mr-2"}),"Basic"]}),e.jsxs(nt,{value:"fields",children:[e.jsx(Cs,{className:"h-4 w-4 mr-2"}),"Fields"]}),e.jsxs(nt,{value:"filters",children:[e.jsx(Jn,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsxs(nt,{value:"grouping",children:[e.jsx(Cs,{className:"h-4 w-4 mr-2"}),"Group By"]}),e.jsxs(nt,{value:"sections",children:[e.jsx(Cs,{className:"h-4 w-4 mr-2"}),"Sections"]}),e.jsxs(nt,{value:"schedule",children:[e.jsx(ps,{className:"h-4 w-4 mr-2"}),"Schedule"]})]}),e.jsx(lt,{value:"basic",className:"space-y-4 mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{htmlFor:"report-title",children:"Report Title"}),e.jsx(qe,{id:"report-title",value:i.title||"",onChange:T=>o({...i,title:T.target.value}),placeholder:"Enter report title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{htmlFor:"report-description",children:"Description"}),e.jsx(qe,{id:"report-description",value:i.description||"",onChange:T=>o({...i,description:T.target.value}),placeholder:"Enter report description"})]}),a.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Data Source"}),e.jsxs("select",{className:"w-full border rounded-md p-2",children:[e.jsx("option",{value:"",children:"Select a data source"}),a.map((T,R)=>e.jsxs("option",{value:R,children:["Data Source ",R+1]},R))]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{children:"Export Options"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.showExportButtons||!1,onChange:T=>o({...i,showExportButtons:T.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Export Buttons"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.showPrintButton||!1,onChange:T=>o({...i,showPrintButton:T.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Print Button"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{htmlFor:"export-format",children:"Default Export Format"}),e.jsxs("select",{id:"export-format",className:"w-full border rounded-md p-2",value:i.defaultExportFormat||"pdf",onChange:T=>o({...i,defaultExportFormat:T.target.value}),children:[e.jsx("option",{value:"pdf",children:"PDF"}),e.jsx("option",{value:"excel",children:"Excel"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"html",children:"HTML"})]})]})]})}),e.jsxs(lt,{value:"fields",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ce,{children:"Report Fields"}),e.jsxs(B,{size:"sm",variant:"outline",onClick:p,disabled:u.length>=r.length,children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Add Field"]})]}),e.jsxs("div",{className:"space-y-2",children:[u.map((T,R)=>e.jsx("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:e.jsxs("div",{className:"flex-1 grid grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Field Name"}),e.jsx("div",{className:"text-sm font-medium",children:T.name})]}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Label"}),e.jsx(qe,{className:"h-8 text-sm",value:T.label||T.name,onChange:v=>C(R,{...T,label:v.target.value})})]}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Aggregation"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:T.aggregation||"",onChange:v=>C(R,{...T,aggregation:v.target.value}),children:[e.jsx("option",{value:"",children:"None"}),e.jsx("option",{value:"sum",children:"Sum"}),e.jsx("option",{value:"count",children:"Count"}),e.jsx("option",{value:"avg",children:"Average"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"})]})]}),e.jsx("div",{className:"flex items-end justify-end",children:e.jsx(B,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>g(R),children:e.jsx(vt,{className:"h-4 w-4"})})})]})},R)),u.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:'No fields selected. Click "Add Field" to begin.'})]})]}),e.jsxs(lt,{value:"filters",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ce,{children:"Report Filters"}),e.jsxs(B,{size:"sm",variant:"outline",onClick:k,children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Add Filter"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map((T,R)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:T.field,onChange:v=>D(R,{...T,field:v.target.value}),children:r.map((v,E)=>e.jsx("option",{value:v.name,children:v.label||v.name},E))})]}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Operator"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:T.operator,onChange:v=>D(R,{...T,operator:v.target.value}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"gt",children:"Greater Than"}),e.jsx("option",{value:"lt",children:"Less Than"}),e.jsx("option",{value:"between",children:"Between"})]})]}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Value"}),e.jsx(qe,{className:"h-8 text-sm",value:String(T.value),onChange:v=>D(R,{...T,value:v.target.value})})]})]}),e.jsx(B,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>F(R),children:e.jsx(vt,{className:"h-4 w-4"})})]},R)),n.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No filters defined."})]})]}),e.jsxs(lt,{value:"grouping",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ce,{children:"Grouping Rules"}),e.jsxs(B,{size:"sm",variant:"outline",onClick:w,children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Add Group"]})]}),e.jsxs("div",{className:"space-y-2",children:[j.map((T,R)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:T.field,onChange:v=>z(R,{...T,field:v.target.value}),children:r.map((v,E)=>e.jsx("option",{value:v.name,children:v.label||v.name},E))})]}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Sort Order"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:T.sort||"asc",onChange:v=>z(R,{...T,sort:v.target.value}),children:[e.jsx("option",{value:"asc",children:"Ascending"}),e.jsx("option",{value:"desc",children:"Descending"})]})]})]}),e.jsx(B,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>S(R),children:e.jsx(vt,{className:"h-4 w-4"})})]},R)),j.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No grouping rules applied."})]})]}),e.jsxs(lt,{value:"sections",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ce,{children:"Report Sections"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(B,{size:"sm",variant:"outline",onClick:()=>M("header"),children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Header"]}),e.jsxs(B,{size:"sm",variant:"outline",onClick:()=>M("chart"),children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Chart"]}),e.jsxs(B,{size:"sm",variant:"outline",onClick:()=>M("table"),children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Table"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[b.map((T,R)=>e.jsxs("div",{className:"p-3 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx("div",{className:"text-xs bg-muted px-2 py-0.5 rounded uppercase",children:T.type}),T.title]}),e.jsx(B,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>O(R),children:e.jsx(vt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Title"}),e.jsx(qe,{className:"h-8 text-sm",value:T.title||"",onChange:v=>A(R,{...T,title:v.target.value})})]}),T.type==="text"&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(ce,{className:"text-xs",children:"Content"}),e.jsx(qe,{className:"h-8 text-sm",value:T.text||"",onChange:v=>A(R,{...T,text:v.target.value})})]}),T.type==="chart"&&e.jsxs("div",{className:"col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(ce,{className:"text-xs font-semibold",children:"Chart Configuration"})}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"Chart Type"}),e.jsxs("select",{className:"flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",value:T.chart?.chartType||"bar",onChange:v=>A(R,{...T,chart:{...T.chart,type:"chart",chartType:v.target.value}}),children:[e.jsx("option",{value:"bar",children:"Bar"}),e.jsx("option",{value:"line",children:"Line"}),e.jsx("option",{value:"area",children:"Area"}),e.jsx("option",{value:"pie",children:"Pie"})]})]}),e.jsxs("div",{children:[e.jsx(ce,{className:"text-xs",children:"X-Axis Field"}),e.jsxs("select",{className:"flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",value:T.chart?.xAxisField||"",onChange:v=>A(R,{...T,chart:{...T.chart,type:"chart",xAxisField:v.target.value}}),children:[e.jsx("option",{value:"",children:"Select Field..."}),r.map(v=>e.jsx("option",{value:v.name,children:v.label||v.name},v.name)),r.length===0&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"name",children:"Name"}),e.jsx("option",{value:"month",children:"Month"})]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(ce,{className:"text-xs",children:"Y-Axis Fields (comma separated)"}),e.jsx(qe,{className:"h-8 text-sm",placeholder:"e.g. value, count",value:T.chart?.yAxisFields?.join(", ")||"",onChange:v=>A(R,{...T,chart:{...T.chart,type:"chart",yAxisFields:v.target.value.split(",").map(E=>E.trim()).filter(Boolean)}})})]})]})]})]},R)),b.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No customized sections. The default report layout will be used."})]})]}),e.jsx(lt,{value:"schedule",className:"space-y-4 mt-4",children:e.jsx(fn,{schedule:i.schedule,onChange:T=>o({...i,schedule:T})})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-6 pt-4 border-t",children:[e.jsx(B,{variant:"outline",onClick:L,children:"Cancel"}),e.jsxs(B,{onClick:$,children:[e.jsx(Nr,{className:"h-4 w-4 mr-2"}),"Save Report"]})]})]})]}),l&&e.jsxs(Oe,{className:"mt-8 border-2 border-blue-100",children:[e.jsx($e,{className:"bg-blue-50/50",children:e.jsx(Be,{className:"text-blue-900 text-sm uppercase tracking-wide",children:"Live Preview"})}),e.jsx(Te,{className:"pt-6",children:e.jsx(un,{schema:{type:"report-viewer",report:{...i,fields:u,filters:n,groupBy:j,sections:b},data:[{id:1,name:"Sample Item A",value:100,status:"New"},{id:2,name:"Sample Item B",value:250,status:"Active"},{id:3,name:"Sample Item C",value:75,status:"Closed"}]}})})]})]})},jo=[{value:"",label:"None"},{value:"sum",label:"Sum"},{value:"count",label:"Count"},{value:"avg",label:"Average"},{value:"min",label:"Min"},{value:"max",label:"Max"}];function wo({availableFields:t,value:s,onChange:a}){const r=Array.isArray(s)?s.map(i=>typeof i=="string"?{name:i,label:i,type:"string"}:{name:i.name||i.field||i.value,label:i.label||i.name||"",type:i.type||"string",aggregation:i.aggregation}):[],l=r.map(i=>i.name),d=i=>{const o=l.includes(i);let u;if(o)u=r.filter(h=>h.name!==i);else{const h=t.find(n=>n.value===i);u=[...r,{name:i,label:h?.label||i,type:h?.type||"string"}]}a(u)},c=(i,o)=>{const u=r.map(h=>h.name===i?{...h,aggregation:o||void 0,showInSummary:!!o}:h);a(u)};return t.length===0?e.jsx("div",{className:"text-xs text-muted-foreground py-2","data-testid":"field-picker-empty",children:"No fields available"}):e.jsx("div",{className:"space-y-1 py-1","data-testid":"field-picker",children:t.map(i=>{const o=l.includes(i.value),u=r.find(h=>h.name===i.value);return e.jsxs("div",{className:"flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 flex-1 cursor-pointer",children:[e.jsx(Nn,{checked:o,onCheckedChange:()=>d(i.value),"data-testid":`field-picker-${i.value}`}),e.jsx("span",{className:"flex-1",children:i.label}),i.type&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:i.type})]}),o&&e.jsx("select",{className:"h-5 text-[10px] border rounded px-1 bg-background",value:u?.aggregation||"",onChange:h=>c(i.value,h.target.value),"data-testid":`field-agg-${i.value}`,children:jo.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]},i.value)})})}const No=[{value:"",label:"None"},{value:"bar",label:"Bar Chart"},{value:"line",label:"Line Chart"},{value:"pie",label:"Pie Chart"},{value:"area",label:"Area Chart"},{value:"donut",label:"Donut Chart"},{value:"scatter",label:"Scatter Plot"}];function Co({availableFields:t,value:s,onChange:a}){const r=s||{},l=d=>a({...r,...d});return e.jsxs("div",{className:"space-y-2 py-1","data-testid":"chart-config",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"Chart type"}),e.jsx("select",{className:"w-full h-7 text-xs border rounded px-2 bg-background",value:r.chartType||"",onChange:d=>l({chartType:d.target.value||void 0}),"data-testid":"chart-type-select",children:No.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))})]}),r.chartType&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"X-axis field"}),e.jsxs("select",{className:"w-full h-7 text-xs border rounded px-2 bg-background",value:r.xAxisField||"",onChange:d=>l({xAxisField:d.target.value||void 0}),"data-testid":"chart-x-field",children:[e.jsx("option",{value:"",children:"Select field…"}),t.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"Y-axis field"}),e.jsxs("select",{className:"w-full h-7 text-xs border rounded px-2 bg-background",value:r.yAxisFields?.[0]||"",onChange:d=>l({yAxisFields:d.target.value?[d.target.value]:[]}),"data-testid":"chart-y-field",children:[e.jsx("option",{value:"",children:"Select field…"}),t.filter(d=>d.type==="number").map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))]})]})]})]})}const So=[{value:"equals",label:"="},{value:"not_equals",label:"≠"},{value:"greater_than",label:">"},{value:"less_than",label:"<"},{value:"contains",label:"Contains"}];function ko({availableFields:t,value:s,onChange:a}){const r=Array.isArray(s)?s:[],l=()=>{a([...r,{field:t[0]?.value||"",operator:"equals",value:"",backgroundColor:"#fef9c3",textColor:""}])},d=i=>{a(r.filter((o,u)=>u!==i))},c=(i,o)=>{a(r.map((u,h)=>h===i?{...u,...o}:u))};return e.jsxs("div",{className:"space-y-2 py-1","data-testid":"conditional-format-rules",children:[r.map((i,o)=>e.jsxs("div",{className:"flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20",children:[e.jsx("select",{className:"h-5 text-[10px] border rounded px-1 bg-background flex-1",value:i.field,onChange:u=>c(o,{field:u.target.value}),"data-testid":`cf-rule-field-${o}`,children:t.map(u=>e.jsx("option",{value:u.value,children:u.label},u.value))}),e.jsx("select",{className:"h-5 text-[10px] border rounded px-1 bg-background w-12",value:i.operator,onChange:u=>c(o,{operator:u.target.value}),children:So.map(u=>e.jsx("option",{value:u.value,children:u.label},u.value))}),e.jsx("input",{className:"h-5 text-[10px] border rounded px-1 bg-background w-16",value:i.value,placeholder:"value",onChange:u=>c(o,{value:u.target.value}),"data-testid":`cf-rule-value-${o}`}),e.jsx("input",{type:"color",className:"h-5 w-5 rounded border cursor-pointer",value:i.backgroundColor||"#fef9c3",onChange:u=>c(o,{backgroundColor:u.target.value}),title:"Background color"}),e.jsx(B,{type:"button",size:"sm",variant:"ghost",className:"h-5 w-5 p-0",onClick:()=>d(o),"data-testid":`cf-rule-remove-${o}`,children:e.jsx(vt,{className:"h-3 w-3"})})]},o)),e.jsxs(B,{type:"button",size:"sm",variant:"outline",className:"h-6 text-[10px] w-full",onClick:l,"data-testid":"cf-add-rule",children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"}),"Add Rule"]})]})}const Do=[{value:"header",label:"Header"},{value:"summary",label:"Summary"},{value:"table",label:"Table"},{value:"chart",label:"Chart"},{value:"text",label:"Text"}];function Ro({value:t,onChange:s}){const a=Array.isArray(t)?t:[],r=i=>{s([...a,{type:i,title:`New ${i}`,visible:!0}])},l=i=>{s(a.filter((o,u)=>u!==i))},d=(i,o)=>{s(a.map((u,h)=>h===i?{...u,...o}:u))},c=(i,o)=>{const u=i+o;if(u<0||u>=a.length)return;const h=[...a];[h[i],h[u]]=[h[u],h[i]],s(h)};return e.jsxs("div",{className:"space-y-2 py-1","data-testid":"section-manager",children:[a.map((i,o)=>e.jsxs("div",{className:"flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 mr-1",children:[e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground disabled:opacity-30",disabled:o===0,onClick:()=>c(o,-1),"data-testid":`section-up-${o}`,children:"▲"}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground disabled:opacity-30",disabled:o===a.length-1,onClick:()=>c(o,1),"data-testid":`section-down-${o}`,children:"▼"})]}),e.jsx("span",{className:"text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0",children:i.type}),e.jsx("input",{className:"h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0",value:i.title||"",placeholder:"Section title",onChange:u=>d(o,{title:u.target.value}),"data-testid":`section-title-${o}`}),e.jsx(B,{type:"button",size:"sm",variant:"ghost",className:"h-5 w-5 p-0 shrink-0",onClick:()=>l(o),"data-testid":`section-remove-${o}`,children:e.jsx(vt,{className:"h-3 w-3"})})]},o)),e.jsx("div",{className:"flex gap-1 flex-wrap",children:Do.map(i=>e.jsxs(B,{type:"button",size:"sm",variant:"outline",className:"h-6 text-[10px]",onClick:()=>r(i.value),"data-testid":`section-add-${i.value}`,children:[e.jsx(Qe,{className:"h-3 w-3 mr-0.5"}),i.label]},i.value))})]})}function Fo(t=[]){return{breadcrumb:["Report","Configuration"],sections:[{key:"basic",title:"Basic",fields:[{key:"title",label:"Title",type:"input",placeholder:"Report title"},{key:"description",label:"Description",type:"input",placeholder:"Report description"},{key:"reportType",label:"Report type",type:"select",defaultValue:"tabular",options:[{value:"tabular",label:"Tabular"},{value:"summary",label:"Summary"},{value:"matrix",label:"Matrix"}],helpText:"Tabular: flat table. Summary: grouped with subtotals. Matrix: pivot table (planned)."}]},{key:"data",title:"Data",collapsible:!0,fields:[{key:"objectName",label:"Data source",type:"input",placeholder:"e.g. opportunity",helpText:"Object name to query data from"},{key:"limit",label:"Row limit",type:"input",defaultValue:"100",placeholder:"e.g. 100"}]},{key:"columns",title:"Columns",collapsible:!0,hint:"Select fields to display as report columns. Set aggregation per column for summary reports.",fields:[{key:"fields",label:"Report columns",type:"custom",render:(s,a)=>e.jsx(wo,{availableFields:t,value:s,onChange:a})}]},{key:"filters",title:"Filters",collapsible:!0,hint:"Define filter conditions for the report data",fields:[{key:"filters",label:"Conditions",type:"filter",fields:t}]},{key:"groupBy",title:"Group By",collapsible:!0,hint:"Group report data and compute aggregations",fields:[{key:"groupBy",label:"Grouping",type:"sort",fields:t}]},{key:"chart",title:"Chart",collapsible:!0,hint:"Add a chart visualization to the report",fields:[{key:"chartConfig",label:"Chart",type:"custom",render:(s,a)=>e.jsx(Co,{availableFields:t,value:s,onChange:a})}]},{key:"conditionalFormatting",title:"Conditional Format",collapsible:!0,defaultCollapsed:!0,hint:"Highlight cells based on field value conditions",fields:[{key:"conditionalFormatting",label:"Rules",type:"custom",render:(s,a)=>e.jsx(ko,{availableFields:t,value:s,onChange:a})}]},{key:"sections",title:"Sections",collapsible:!0,defaultCollapsed:!0,hint:"Manage report layout blocks (header, table, chart, summary)",fields:[{key:"sections",label:"Report sections",type:"custom",render:(s,a)=>e.jsx(Ro,{value:s,onChange:a})}]},{key:"export",title:"Export",collapsible:!0,defaultCollapsed:!0,fields:[{key:"showExportButtons",label:"Show export buttons",type:"switch",defaultValue:!0},{key:"showPrintButton",label:"Show print button",type:"switch",defaultValue:!0},{key:"defaultExportFormat",label:"Default export format",type:"select",defaultValue:"pdf",options:[{value:"pdf",label:"PDF"},{value:"excel",label:"Excel"},{value:"csv",label:"CSV"},{value:"json",label:"JSON"},{value:"html",label:"HTML"}]}]},{key:"schedule",title:"Schedule",collapsible:!0,defaultCollapsed:!0,fields:[{key:"schedule",label:"Schedule",type:"custom",render:(s,a)=>e.jsx(fn,{schedule:s,onChange:a})}]},{key:"appearance",title:"Appearance",collapsible:!0,defaultCollapsed:!0,fields:[{key:"showToolbar",label:"Show toolbar",type:"switch",defaultValue:!0},{key:"refreshInterval",label:"Refresh interval",type:"select",defaultValue:"0",options:[{value:"0",label:"Manual"},{value:"30",label:"30s"},{value:"60",label:"1 min"},{value:"300",label:"5 min"}]}]}]}}function qo({open:t,onClose:s,config:a,onSave:r,onFieldChange:l,availableFields:d}){const{draft:c,isDirty:i,updateField:o,discard:u,undo:h,redo:n,canUndo:N,canRedo:j}=Us(a,{onUpdate:l}),x=m.useMemo(()=>Fo(d),[d]);return e.jsx(Ys,{open:t,onClose:s,schema:x,draft:c,isDirty:i,onFieldChange:o,onSave:()=>r(c),onDiscard:u,onUndo:h,onRedo:n,canUndo:N,canRedo:j})}Se.register("report",uo,{namespace:"report",label:"Report",category:"Report",inputs:[{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"chart",type:"code",label:"Chart Configuration"}]});Se.register("report-viewer",un,{namespace:"report",label:"Report Viewer",category:"Report",inputs:[{name:"report",type:"code",label:"Report Definition"},{name:"showToolbar",type:"boolean",label:"Show Toolbar"}]});Se.register("report-builder",vo,{namespace:"report",label:"Report Builder",category:"Report",inputs:[{name:"report",type:"code",label:"Initial Report"}]});export{Ar as D,Er as L,Lo as M,_o as R,Ho as W,ql as a,Vo as b,un as c,qo as d,fl as u};