@objectstack/console 11.0.0 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AdapterProvider-BieqtbDy.js → AdapterProvider-BTAMdG2T.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-_rod9OeO.js → AiPendingActionsPage-BtiQFQw8.js} +1 -1
- package/dist/assets/ApiConsolePage-CQJbzAsw.js +1 -0
- package/dist/assets/{AppDocsIndex-0yBeTLFW.js → AppDocsIndex-CbHC6KGX.js} +1 -1
- package/dist/assets/{AppManagementPage-jXBjId07.js → AppManagementPage-DOoQrTPO.js} +1 -1
- package/dist/assets/ApprovalsInboxPage-D6eWYxCu.js +1 -0
- package/dist/assets/{AuditLogPage-CO0HOjCA.js → AuditLogPage-F85cQBBY.js} +1 -1
- package/dist/assets/{ComponentNavView-DmByVW8F.js → ComponentNavView-g9qw3mhW.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-Cy-Ny_TS.js +1 -0
- package/dist/assets/DashboardView-mIWO-jW_.js +1 -0
- package/dist/assets/DashboardWidgetInspector-DOnyBhGN.js +1 -0
- package/dist/assets/{DeveloperHubPage-DN8UdQMr.js → DeveloperHubPage-Ci0wA8GZ.js} +1 -1
- package/dist/assets/{ExpressionProvider-CT3sX7xF.js → ExpressionProvider-NqLS0ljf.js} +1 -1
- package/dist/assets/FlowRunsPage-CNz2_VFK.js +1 -0
- package/dist/assets/{IntegrationsPage-CqLzZMOK.js → IntegrationsPage-CAZ3nsKJ.js} +2 -2
- package/dist/assets/{InterfaceListPage-GcApvEz0.js → InterfaceListPage-D1BbH0Iy.js} +1 -1
- package/dist/assets/{ManagedByBadge-5eJy46Si.js → ManagedByBadge-6DwSVsdr.js} +1 -1
- package/dist/assets/{MarketplaceAccessDenied-BGBYYv_M.js → MarketplaceAccessDenied-Cyx7lSjy.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-Fa8EY_5o.js → MarketplaceInstalledPage-C41H1YlB.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-DC6zA893.js → MarketplacePackagePage-Bihb2q1b.js} +2 -2
- package/dist/assets/{MarketplacePage-nv-oKrlO.js → MarketplacePage-C2B6TMNM.js} +1 -1
- package/dist/assets/MetadataInspector-COEBMw6y.js +1 -0
- package/dist/assets/{MetadataProvider-fKK6GbWD.js → MetadataProvider-D234gTjV.js} +1 -1
- package/dist/assets/PageView-DuiaqvzN.js +1 -0
- package/dist/assets/ProfilePage-B1oCou0F.js +1 -0
- package/dist/assets/PublicFormsPage-C2prdsH6.js +1 -0
- package/dist/assets/RecordDetailView-B-AuOKPI.js +9 -0
- package/dist/assets/{RecordFormPage-Bkn_bUyo.js → RecordFormPage-CpKMoOCj.js} +1 -1
- package/dist/assets/ReportDefaultInspector-DxP-Ac7I.js +11 -0
- package/dist/assets/{ReportView-Gq01PZlc.js → ReportView-Cw9Ompki.js} +1 -1
- package/dist/assets/{SearchResultsPage-C3SyFv3R.js → SearchResultsPage-CZ038ncU.js} +1 -1
- package/dist/assets/{SettingsHub-BLCpGzj-.js → SettingsHub-BXe-fVlJ.js} +1 -1
- package/dist/assets/{SettingsView-Cd6iNy3t.js → SettingsView-DxPgTnlF.js} +1 -1
- package/dist/assets/{SystemHubPage-DBdBlyat.js → SystemHubPage-CJq_1ITt.js} +1 -1
- package/dist/assets/{data-adapter-C8ELgvKP.js → data-adapter-02g96tfY.js} +1 -1
- package/dist/assets/{framework-CQlIjbCT.js → framework-h98DIM1k.js} +7 -7
- package/dist/assets/{highlighted-body-OFNGDK62-02fX_5a1.js → highlighted-body-OFNGDK62-DO9p_wSr.js} +1 -1
- package/dist/assets/index-BQhiWf8_.js +2 -0
- package/dist/assets/index-WhD62Q-7.css +2 -0
- package/dist/assets/infrastructure-B1z73d-r.js +3 -0
- package/dist/assets/{marketplaceApi-D36MnuCE.js → marketplaceApi-B_Gmytip.js} +1 -1
- package/dist/assets/mermaid-GHXKKRXX-DEmtnxCC.js +1 -0
- package/dist/assets/metadata-admin-DStYGsRM.js +22 -0
- package/dist/assets/plugin-calendar-BYmYEyQk.js +1 -0
- package/dist/assets/plugin-charts-BDFf0TCn.js +7 -0
- package/dist/assets/plugin-chatbot-CnuZn8AC.js +120 -0
- package/dist/assets/plugin-dashboard-CuwYQhsg.js +6 -0
- package/dist/assets/plugin-form-CH8ruD9E.js +1 -0
- package/dist/assets/plugin-gantt-BB8ZeREv.js +93 -0
- package/dist/assets/plugin-grid-D414NLNP.js +6 -0
- package/dist/assets/plugin-kanban-BRFJEEAA.js +1 -0
- package/dist/assets/{plugin-map-CIN-oBC5.js → plugin-map-rEWoyyKa.js} +1 -1
- package/dist/assets/{plugin-markdown-DU8O5B7L.js → plugin-markdown-BgV76qm3.js} +1 -1
- package/dist/assets/plugin-report-C-YPOtvZ.js +59 -0
- package/dist/assets/{plugin-timeline-BMM7P_hx.js → plugin-timeline-CC91-fmI.js} +1 -1
- package/dist/assets/{plugin-tree-CErRKxCG.js → plugin-tree-D2QWz1x1.js} +1 -1
- package/dist/assets/plugin-view-C6iEzx93.js +1 -0
- package/dist/assets/plugins-views-CcoNygsH.js +4 -0
- package/dist/assets/{skeletons-k9g6qZSy.js → skeletons-BQ5aRDUn.js} +1 -1
- package/dist/assets/{src-BcFufHSl.js → src-C4OnKiir.js} +1 -1
- package/dist/assets/src-CKHT6scJ.js +2 -0
- package/dist/assets/{types-DXihP4sI.js → types-BUZu4QOP.js} +1 -1
- package/dist/assets/ui-components-C9egdVxV.js +42 -0
- package/dist/assets/{ui-layout-C9ykUXmg.js → ui-layout-BwokMuBv.js} +1 -1
- package/dist/assets/{useActionModal-DJG5Babl.js → useActionModal-ChUaxcEW.js} +1 -1
- package/dist/assets/{useOpenRecordList-D-g511Jw.js → useOpenRecordList-BkSEs2q6.js} +1 -1
- package/dist/assets/{useReconcileOnError-QYVPx52o.js → useReconcileOnError-FPUCNTHc.js} +1 -1
- package/dist/assets/vendor-objectstack-BTQLr7T3.js +96 -0
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ApiConsolePage-WCI3DIIi.js +0 -1
- package/dist/assets/ApprovalsInboxPage-BYHBBA9y.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-C_BlXoV1.js +0 -1
- package/dist/assets/DashboardView-Cs-MC_5A.js +0 -1
- package/dist/assets/DashboardWidgetInspector-ce9fT5XA.js +0 -1
- package/dist/assets/FlowRunsPage-DPj0zPLk.js +0 -1
- package/dist/assets/MetadataInspector-XbWYccBm.js +0 -1
- package/dist/assets/PageView-C9b2DYFF.js +0 -1
- package/dist/assets/ProfilePage-D7Ie0WN7.js +0 -1
- package/dist/assets/PublicFormsPage-BaKsA3Eo.js +0 -1
- package/dist/assets/RecordDetailView-CfCIFeA9.js +0 -9
- package/dist/assets/ReportDefaultInspector-CoxrLLKh.js +0 -11
- package/dist/assets/index-Vh0-yrfs.js +0 -2
- package/dist/assets/index-_u4ypVlX.css +0 -2
- package/dist/assets/infrastructure-BtLHjSlJ.js +0 -3
- package/dist/assets/mermaid-GHXKKRXX-BeAYGylq.js +0 -1
- package/dist/assets/metadata-admin-mBijR3yo.js +0 -22
- package/dist/assets/plugin-calendar-BdTHA4Ee.js +0 -1
- package/dist/assets/plugin-charts-DoMMZZk8.js +0 -7
- package/dist/assets/plugin-chatbot-CumNGrh8.js +0 -120
- package/dist/assets/plugin-dashboard-Bl7wuG9f.js +0 -6
- package/dist/assets/plugin-form-hyYQoCHc.js +0 -1
- package/dist/assets/plugin-gantt-BsnXplf2.js +0 -93
- package/dist/assets/plugin-grid-DvI8i3CO.js +0 -6
- package/dist/assets/plugin-kanban-DmKa19Zc.js +0 -1
- package/dist/assets/plugin-report-JWTVyA2R.js +0 -59
- package/dist/assets/plugin-view-BMfFD77p.js +0 -1
- package/dist/assets/plugins-views-iYrs182B.js +0 -4
- package/dist/assets/src-Dnw5qGGv.js +0 -2
- package/dist/assets/ui-components-CgiD1ql5.js +0 -42
- package/dist/assets/vendor-objectstack-C1teU2a6.js +0 -96
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,t as r}from"./vendor-react-ClIa1CJA.js";import{Dt as i,Et as a,Q as o,i as s,kt as c,z as l}from"./framework-h98DIM1k.js";import{u}from"./vendor-objectstack-BTQLr7T3.js";import{Ac as d,Bs as f,Dc as p,Ea as m,Hr as h,Ma as g,Mc as ee,Nr as _,Oc as v,Ra as te,Tr as y,Ui as b,Vo as ne,Vs as x,Zo as re,_r as ie,a as ae,fa as oe,fr as se,gr as ce,h as S,hr as C,ji as le,k as ue,l as de,la as fe,m as pe,mr as me,o as he,p as ge,pr as _e,rs as ve,s as ye,u as be,vr as w,wr as xe,xr as T,yr as Se,zs as Ce}from"./ui-components-C9egdVxV.js";import{a as E,i as we}from"./plugins-views-CcoNygsH.js";var D=e(n(),1),Te=1e3*60*60*24,Ee=e=>e.toISOString().slice(0,10);function De(e,t){if(t.skipWeekends){let t=e.getUTCDay();if(t===0||t===6)return!1}return!(t.holidays&&t.holidays.has(Ee(e)))}function O(e){let t=new Date(e);return t.setUTCHours(0,0,0,0),t}function Oe(e,t){let n=O(e);for(;!De(n,t);)n=new Date(n.getTime()+Te);return n.getTime()}function k(e,t,n){if(t<=e)return 0;let r=0,i=O(e),a=O(t).getTime();for(;i.getTime()<a;)De(i,n)&&r++,i=new Date(i.getTime()+Te);return r}function A(e,t,n){if(t<=0)return O(e).getTime();let r=O(e),i=t;for(;i>0;)De(r,n)&&i--,r=new Date(r.getTime()+Te);return r.getTime()}function j(e,t,n){if(t<=0)return O(e).getTime();let r=O(e),i=t;for(;i>0;)r=new Date(r.getTime()-Te),De(r,n)&&i--;return r.getTime()}var M=e=>String(e);function N(e){return e===`ss`||e===`ff`||e===`sf`?e:`fs`}function ke(e){let t=new Set(e.map(e=>M(e.id))),n=[];for(let r of e){let e=M(r.id);for(let i of r.dependencies??[]){let r=typeof i==`object`&&!!i,a=r?i.id:i;if(a==null||a===``)continue;let o=M(a);o===e||!t.has(o)||n.push({pred:o,succ:e,type:N(r?i.type:void 0)})}}return n}function Ae(e){let t=new Set;for(let n of e)n.parent!=null&&n.parent!==``&&t.add(M(n.parent));return t}function je(e,t){let n=new Map,r=new Map;for(let t of e)n.set(t,0),r.set(t,[]);for(let e of t)r.get(e.pred).push(e.succ),n.set(e.succ,(n.get(e.succ)??0)+1);let i=e.filter(e=>(n.get(e)??0)===0),a=[];for(;i.length;){let e=i.shift();a.push(e);for(let t of r.get(e)??[]){let e=(n.get(t)??0)-1;n.set(t,e),e===0&&i.push(t)}}if(a.length<e.length){let t=new Set(a);for(let n of e)t.has(n)||a.push(n);return{order:a,hasCycle:!0}}return{order:a,hasCycle:!1}}function Me(e,t){let n={criticalIds:new Set,criticalEdges:new Set};if(!e.length)return n;let r=new Map;for(let n of e){let e=t?k(n.start.getTime(),n.end.getTime(),t):(n.end.getTime()-n.start.getTime())/Te;r.set(M(n.id),Number.isFinite(e)&&e>0?e:0)}let i=ke(e),a=e.map(e=>M(e.id)),{order:o,hasCycle:s}=je(a,i);if(s)return n;let c=new Map,l=new Map;for(let e of a)c.set(e,[]),l.set(e,[]);for(let e of i)c.get(e.succ).push(e),l.get(e.pred).push(e);let u=new Map,d=new Map;for(let e of o){let t=0;for(let n of c.get(e)??[])t=Math.max(t,d.get(n.pred)??0);u.set(e,t),d.set(e,t+(r.get(e)??0))}let f=Math.max(0,...a.map(e=>d.get(e)??0)),p=new Map,m=new Map;for(let e=o.length-1;e>=0;e--){let t=o[e],n=l.get(t)??[],i=f;n.length&&(i=Math.min(...n.map(e=>m.get(e.succ)??f))),p.set(t,i),m.set(t,i-(r.get(t)??0))}let h=1e-6,g=new Set;for(let e of a){let t=(m.get(e)??0)-(u.get(e)??0);Math.abs(t)<=h&&g.add(e)}let ee=new Set;for(let e of i)ee.add(e.pred),ee.add(e.succ);for(let e of[...g])!ee.has(e)&&(r.get(e)??0)===0&&g.delete(e);let _=new Set;for(let e of i)!g.has(e.pred)||!g.has(e.succ)||Math.abs((d.get(e.pred)??0)-(u.get(e.succ)??0))<=h&&_.add(`${e.pred}->${e.succ}`);return{criticalIds:g,criticalEdges:_}}function Ne(e,t){if(!e.length)return[];let n=ke(e),r=e.map(e=>M(e.id)),{order:i,hasCycle:a}=je(r,n);if(a)return[];let o=Ae(e),s=new Map;for(let t of e)s.set(M(t.id),t);let c=new Map;for(let e of r)c.set(e,[]);for(let e of n)c.get(e.succ).push(e);let l=new Map,u=new Map;for(let t of e)l.set(M(t.id),t.start.getTime()),u.set(M(t.id),t.end.getTime());for(let e of i){let n=s.get(e);if(!n)continue;let r=t?k(l.get(e),u.get(e),t):u.get(e)-l.get(e),i=n.start.getTime();for(let n of c.get(e)??[]){let e=l.get(n.pred),a=u.get(n.pred),o;switch(n.type){case`ss`:o=e;break;case`ff`:o=t?j(a,r,t):a-r;break;case`sf`:o=t?j(e,r,t):e-r;break;default:o=a;break}o>i&&(i=o)}if(!o.has(e))if(t){let n=Oe(i,t);l.set(e,n),u.set(e,A(n,r,t))}else l.set(e,i),u.set(e,i+r)}let d=[];for(let t of e){let e=M(t.id);if(o.has(e))continue;let n=l.get(e),r=u.get(e);(n!==t.start.getTime()||r!==t.end.getTime())&&d.push({id:e,start:new Date(n),end:new Date(r)})}return d}var P=6e4;1440*P;var F=1440;function I(e){if(typeof e!=`string`)return null;let t=/^(\d{1,2}):(\d{2})$/.exec(e.trim());if(!t)return null;let n=Number(t[1]),r=Number(t[2]);return n<0||n>23||r<0||r>59?null:n*60+r}function Pe(e){if(!e||!Array.isArray(e.bands)||e.bands.length===0)return null;let t=I(e.dayStart)??0,n=[];for(let t=0;t<e.bands.length;t++){let r=e.bands[t],i=I(r.start),a=I(r.end);if(i==null||a==null||!r.label)return null;let o=(a-i+F)%F||F;n.push({key:r.key??`band${t}`,label:r.label,color:r.color,durMs:o*P})}return{dayStartMin:t,bands:n,showMidnight:e.showMidnight!==!1}}function Fe(e,t){let n=new Date(e);return n.setHours(0,0,0,0),n.setMinutes(t),n.getTime()>e.getTime()&&n.setDate(n.getDate()-1),n}function Ie(e,t){if(t.bands.length===0)return null;let n=Fe(e,t.dayStartMin).getTime(),r=e.getTime()-n,i=0;for(let e of t.bands)if(i+=e.durMs,r<i)return e;return t.bands[t.bands.length-1]}var Le={"gantt.column.taskName":`Task Name`,"gantt.column.start":`Start`,"gantt.column.end":`End`,"gantt.toolbar.prevPeriod":`Previous period`,"gantt.toolbar.nextPeriod":`Next period`,"gantt.toolbar.zoomIn":`Zoom in`,"gantt.toolbar.zoomOut":`Zoom out`,"gantt.toolbar.jumpToToday":`Jump to today`,"gantt.toolbar.today":`Today`,"gantt.toolbar.thisWeek":`This week`,"gantt.toolbar.thisMonth":`This month`,"gantt.toolbar.exportPdf":`Export PDF`,"gantt.toolbar.saveLayout":`Save layout`,"gantt.toolbar.showTaskList":`Show task list`,"gantt.toolbar.hideTaskList":`Hide task list`,"gantt.toolbar.viewMode":`Timeline granularity`,"gantt.toolbar.enterFullscreen":`Enter fullscreen`,"gantt.toolbar.exitFullscreen":`Exit fullscreen`,"gantt.toolbar.criticalPath":`Highlight critical path`,"gantt.toolbar.autoSchedule":`Auto-schedule dependencies`,"gantt.toolbar.exportPng":`Export as PNG`,"gantt.toolbar.undo":`Undo`,"gantt.toolbar.redo":`Redo`,"gantt.viewMode.day":`Day`,"gantt.viewMode.week":`Week`,"gantt.viewMode.month":`Month`,"gantt.viewMode.quarter":`Quarter`,"gantt.viewMode.year":`Year`,"gantt.row.expand":`Expand`,"gantt.row.collapse":`Collapse`,"gantt.row.locate":`Locate on timeline`,"gantt.aria.taskList":`Task list`,"gantt.tooltip.days":`d`,"gantt.menu.view":`View details`,"gantt.menu.edit":`Edit inline`,"gantt.menu.delete":`Delete`,"gantt.menu.addPredecessor":`Add predecessor…`,"gantt.menu.addSuccessor":`Add successor…`,"gantt.menu.removeDependency":`Remove dependency`,"gantt.menu.noCandidates":`No available tasks`,"gantt.linkType.fs":`Finish → Start`,"gantt.linkType.ss":`Start → Start`,"gantt.linkType.ff":`Finish → Finish`,"gantt.linkType.sf":`Start → Finish`,"gantt.linkEnd.start":`start`,"gantt.linkEnd.end":`end`,"gantt.conflict.title":`Schedule conflict`,"gantt.conflict.body":`This move conflicts with dependency constraints. Auto-reschedule {count} affected task(s)?`,"gantt.conflict.confirm":`Auto-reschedule`,"gantt.conflict.cancel":`Keep as is`,"gantt.resource.header":`Resource`,"gantt.resource.peak":`Peak`,"gantt.resource.over":`overloaded`,"gantt.resource.empty":`No tasks to allocate.`,"gantt.readOnly":`Read-only`,"gantt.readOnlyHint":`Editing is disabled for this view.`};function Re(e,t){let n=Le[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function ze(){try{let e=s();return{t:(t,n)=>{let r=e.t(t,n);return typeof r==`string`&&r!==t?r:Re(t,n)},language:e.language}}catch{return{t:Re,language:void 0}}}var L=r();function Be(e){return 110}function Ve(e){return e<640?140:e<1024?220:320}function He(e){return e>=280}function Ue(e){return e<640?32:40}var We=[`day`,`week`,`month`,`quarter`,`year`],Ge={day:1,week:7,month:30.44,quarter:91.31,year:365.25},Ke=1e3*60*60*24;function qe(e,t){let n=new Date(e);return n.setHours(0,0,0,0),t===`week`?n.setDate(n.getDate()-(n.getDay()+6)%7):t===`month`?n.setDate(1):t===`quarter`?n.setMonth(Math.floor(n.getMonth()/3)*3,1):t===`year`&&n.setMonth(0,1),n}function Je(e,t,n){let r=e.length-1,i=0;for(;i<r&&e[i+1]<t;)i++;let a=i;for(;a<r&&e[a]<n;)a++;return{start:i,end:a}}function Ye(e,t,n){let r=new Date(e);if(n===`day`)r.setDate(r.getDate()+t);else if(n===`week`)r.setDate(r.getDate()+t*7);else{let e=t*(n===`month`?1:n===`quarter`?3:12),i=r.getDate();r.setDate(1),r.setMonth(r.getMonth()+e);let a=new Date(r.getFullYear(),r.getMonth()+1,0).getDate();r.setDate(Math.min(i,a))}return r}function Xe(e,t,n,r=2){return new Promise(i=>{let a=new Blob([e],{type:`image/svg+xml;charset=utf-8`}),o=URL.createObjectURL(a),s=new Image;s.onload=()=>{let e=document.createElement(`canvas`);e.width=t*r,e.height=n*r;let a=e.getContext(`2d`);a&&(a.fillStyle=`#ffffff`,a.fillRect(0,0,e.width,e.height),a.scale(r,r),a.drawImage(s,0,0)),URL.revokeObjectURL(o),i(e)},s.onerror=()=>{URL.revokeObjectURL(o),i(null)},s.src=o})}function Ze(e,t){let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=t,document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}function Qe(e,t,n){let r=e=>{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t},i=`q ${t} 0 0 ${n} 0 0 cm /Im0 Do Q`,a=[],o=[],s=0,c=e=>{a.push(e),s+=e.length},l=()=>{o.push(s)};c(r(`%PDF-1.3
|
|
2
|
+
%ÿÿÿÿ
|
|
3
|
+
`)),l(),c(r(`1 0 obj
|
|
4
|
+
<< /Type /Catalog /Pages 2 0 R >>
|
|
5
|
+
endobj
|
|
6
|
+
`)),l(),c(r(`2 0 obj
|
|
7
|
+
<< /Type /Pages /Kids [3 0 R] /Count 1 >>
|
|
8
|
+
endobj
|
|
9
|
+
`)),l(),c(r(`3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${t} ${n}] /Resources << /XObject << /Im0 4 0 R >> >> /Contents 5 0 R >>\nendobj\n`)),l(),c(r(`4 0 obj\n<< /Type /XObject /Subtype /Image /Width ${t} /Height ${n} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${e.length} >>\nstream\n`)),c(e),c(r(`
|
|
10
|
+
endstream
|
|
11
|
+
endobj
|
|
12
|
+
`)),l(),c(r(`5 0 obj\n<< /Length ${i.length} >>\nstream\n${i}\nendstream\nendobj\n`));let u=s,d=`xref
|
|
13
|
+
0 6
|
|
14
|
+
0000000000 65535 f
|
|
15
|
+
`;for(let e of o)d+=`${String(e).padStart(10,`0`)} 00000 n \n`;return d+=`trailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n${u}\n%%EOF\n`,c(r(d)),new Blob(a,{type:`application/pdf`})}function $e(e){let t=e.slice(e.indexOf(`,`)+1),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}var et=`gantt-layout:`;function tt(e){if(!e||typeof window>`u`)return null;try{let t=window.localStorage.getItem(et+e);if(!t)return null;let n=JSON.parse(t),r=n.viewMode&&We.includes(n.viewMode)?n.viewMode:null;if(!r)return null;let i=typeof n.columnWidth==`number`&&isFinite(n.columnWidth)?n.columnWidth:null,a=typeof n.taskListWidth==`number`&&isFinite(n.taskListWidth)?n.taskListWidth:null;return{viewMode:r,columnWidth:i,taskListCollapsed:!!n.taskListCollapsed,taskListWidth:a}}catch{return null}}function nt(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(et+e,JSON.stringify(t))}catch{}}function rt({tasks:e,viewMode:t,startDate:n,endDate:r,markers:i,onTaskClick:a,onTaskUpdate:o,onTaskDelete:s,onViewChange:c,onDependencyCreate:l,onDependencyDelete:u,onTaskReorder:d,className:ee,inlineEdit:ie=!1,autoSchedule:ae=!1,rescheduleOnConflict:se=!1,criticalPathDefault:ce=!1,workingCalendar:S,shiftSegments:C,showBaselines:de=!0,readOnly:pe=!1,mobileReadOnly:me=!1,groupBy:he,ungroupedLabel:ge=`Ungrouped`,defaultCollapsedDepth:_e,persistLayoutKey:ye,onLayoutChange:be}){let{t:w,language:Se}=ze(),E=Se||void 0,[we,Te]=D.useState(new Date),Ee=D.useRef(null),{width:De}=ue(Ee),O=De||(typeof window<`u`?window.innerWidth:1024),Oe=O<640,k=pe||me&&Oe,A=k?void 0:o,j=k?void 0:s,M=k?void 0:l,N=k?void 0:u,ke=k?void 0:d,Ae=k?!1:ie,je=k?!1:ae,P=k?!1:se,F=Ue(O),I=Be(O),Pe=D.useRef(void 0);Pe.current===void 0&&(Pe.current=tt(ye));let Ie=Pe.current,[Le,Re]=D.useState(Ie?Ie.columnWidth:null),[et,rt]=D.useState(Ie?Ie.taskListWidth??null:null),[R,it]=D.useState(t&&We.includes(t)?t:Ie?.viewMode??`day`);D.useEffect(()=>{t&&We.includes(t)&&it(t)},[t]);let at=D.useRef(null),ot=D.useRef(null),st=D.useRef(!0),[ct,lt]=D.useState(Ie?Ie.taskListCollapsed:!1),ut=D.useRef(!1);D.useEffect(()=>{!ut.current&&Oe&&(lt(!0),ut.current=!0)},[Oe]);let dt=Math.max(160,O-200),z=ct?0:et==null?Ve(O):Math.max(160,Math.min(et,dt)),ft=D.useMemo(()=>{if(Le!=null||r||e.length===0)return null;let t=n?new Date(n):new Date(Math.min(...e.map(e=>e.start.getTime()))),i=new Date(Math.max(...e.map(e=>e.end.getTime())));n||t.setDate(t.getDate()-7),i.setDate(i.getDate()+14),t=qe(t,R),i.setHours(23,59,59,999);let a=Math.max(1,(i.getTime()-t.getTime())/Ke),o=Math.max(0,O-z);if(o<=0)return null;let s=o/a*Ge[R];if(s<=I)return null;let c=Math.min(s,o*.6);return c>I?c:null},[Le,e,n,r,R,O,z,I]),B=Le??ft??I,pt=B/Ge[R],mt=He(z),[ht,gt]=D.useState(null),[_t,vt]=D.useState({}),[yt,bt]=D.useState(null),V=D.useMemo(()=>{if(!he)return e;let t=new Set;for(let n of e){let e=n.parent!=null&&n.parent!==``?String(n.parent):null;e&&t.add(e)}let n=new Map;for(let r of e){if(t.has(String(r.id)))continue;let e=he(r),i=e?String(e.key):`__ungrouped__`,a=e?e.label:ge,o=n.get(i);o||(o={key:i,label:a,items:[]},n.set(i,o)),o.items.push(r)}let r=[];for(let e of n.values()){let t=`__group__${e.key}`,n=e.items[0];r.push({id:t,title:e.label,start:n.start,end:n.end,progress:0,type:`summary`,parent:null,data:{__group:!0}});for(let n of e.items)r.push({...n,parent:t})}return r},[he,e,ge]),xt=D.useMemo(()=>{let e=new Set(V.map(e=>String(e.id))),t=new Map;for(let n of V){let r=n.parent!=null&&n.parent!==``?String(n.parent):null;if(r&&r!==String(n.id)&&e.has(r)){let e=t.get(r);e?e.push(n):t.set(r,[n])}}return t},[V]),St=D.useMemo(()=>{let e=new Map;for(let t of V)e.set(String(t.id),t);return e},[V]),Ct=D.useCallback(e=>{let t=[],n=new Set,r=e=>{for(let i of xt.get(e)??[]){let e=String(i.id);n.has(e)||(n.add(e),t.push(i),r(e))}};return r(String(e)),t},[xt]),[H,wt]=D.useState(null),Tt=D.useRef(null);D.useEffect(()=>{Tt.current=H},[H]);let Et=D.useRef(!1),Dt=D.useCallback(e=>{let t=R===`day`&&C&&C.bands.length>0&&C?Math.min(...C.bands.map(e=>e.durMs)):Ke,n=(e,t)=>wn.current?wn.current(e,t):Ye(e,t,R),r=new Date(e.originStart),i=new Date(e.originEnd);return e.mode===`move`?(r=n(e.originStart,e.unitDelta),i=new Date(e.originEnd.getTime()+(r.getTime()-e.originStart.getTime()))):e.mode===`resize-left`?(r=n(e.originStart,e.unitDelta),i.getTime()-r.getTime()<t&&(r=new Date(i.getTime()-t))):e.mode===`resize-right`&&(i=n(e.originEnd,e.unitDelta),i.getTime()-r.getTime()<t&&(i=new Date(r.getTime()+t))),{start:r,end:i}},[R,C]),Ot=D.useRef(e);Ot.current=e;let kt=D.useRef([]),At=D.useRef([]),[jt,Mt]=D.useState(0),Nt=D.useCallback(e=>{if(!A)return;let t=[];for(let{task:n,changes:r}of e){let e={},i={},a=!1;for(let t of Object.keys(r)){let o=r[t],s=n[t],c=o instanceof Date&&s instanceof Date?o.getTime()===s.getTime():o===s;e[t]=s,i[t]=o,c||(a=!0)}A(n,r),a&&t.push({taskId:String(n.id),before:e,after:i})}t.length&&(kt.current.push(t),At.current=[],Mt(e=>e+1))},[A]),[Pt,Ft]=D.useState(null),It=D.useCallback(e=>{if(!P)return;let t=new Map;for(let{task:n,changes:r}of e)t.set(String(n.id),{start:r.start??n.start,end:r.end??n.end});let n=Ne(Ot.current.map(e=>{let n=t.get(String(e.id));return n?{...e,start:n.start,end:n.end}:e}),S).filter(e=>{let n=t.get(e.id);return!n||e.start.getTime()!==n.start.getTime()||e.end.getTime()!==n.end.getTime()});n.length&&Ft(n)},[P,S]),Lt=D.useCallback(()=>{if(!Pt)return;let e=Pt.map(e=>{let t=Ot.current.find(t=>String(t.id)===e.id);return t?{task:t,changes:{start:e.start,end:e.end}}:null}).filter(Boolean);e.length&&Nt(e),Ft(null)},[Pt,Nt]),Rt=D.useCallback((e,t)=>{if(A)for(let n of e){let e=Ot.current.find(e=>String(e.id)===n.taskId);e&&A(e,t===`undo`?n.before:n.after)}},[A]),zt=D.useCallback(()=>{let e=kt.current.pop();e&&(Rt(e,`undo`),At.current.push(e),Mt(e=>e+1))},[Rt]),Bt=D.useCallback(()=>{let e=At.current.pop();e&&(Rt(e,`redo`),kt.current.push(e),Mt(e=>e+1))},[Rt]),{canUndo:Vt,canRedo:Ht}=D.useMemo(()=>({canUndo:kt.current.length>0,canRedo:At.current.length>0}),[jt]);D.useEffect(()=>{if(!H)return;let t=R===`day`&&C&&C.bands.length>0&&C?pt*Math.min(...C.bands.map(e=>e.durMs))/Ke:B,n=e=>{let n=Tt.current;if(!n)return;let r=Math.round((e.clientX-n.originClientX)/Math.max(t,1));r!==n.unitDelta&&wt({...n,unitDelta:r})},r=()=>{let t=Tt.current;if(t){if(t.unitDelta!==0){let n=e.find(e=>e.id===t.taskId);if(n&&A){let{start:e,end:r}=Dt(t);if(t.group){let r=e.getTime()-t.originStart.getTime(),i=[n,...Ct(n.id)].map(e=>({task:e,changes:{start:new Date(e.start.getTime()+r),end:new Date(e.end.getTime()+r)}}));Nt(i),It(i)}else{let t=[{task:n,changes:{start:e,end:r}}];Nt(t),It(t)}}Et.current=!0,window.setTimeout(()=>{Et.current=!1},0)}wt(null)}};return window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r),()=>{window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r)}},[H,B,pt,R,C,e,A,Dt,Ct,Nt,It]);let Ut=D.useCallback((e,t,n,r)=>{!A||e.data?.__group||(n.stopPropagation(),n.preventDefault(),wt({taskId:e.id,mode:t,group:r?.group??!1,originStart:new Date(r?.originStart??e.start),originEnd:new Date(r?.originEnd??e.end),originClientX:n.clientX,unitDelta:0}))},[A]),[Wt,Gt]=D.useState(null),Kt=D.useRef(null);D.useEffect(()=>{Kt.current=Wt},[Wt]),D.useEffect(()=>{if(!Wt)return;let t=e=>{let t=Kt.current;if(!t)return;let n=Math.min(100,Math.max(0,Math.round(t.originProgress+(e.clientX-t.originClientX)/Math.max(t.barWidth,1)*100)));n!==t.value&&Gt({...t,value:n})},n=()=>{let t=Kt.current;if(t){if(t.value!==t.originProgress){let n=e.find(e=>e.id===t.taskId);n&&A&&Nt([{task:n,changes:{progress:t.value}}]),Et.current=!0,window.setTimeout(()=>{Et.current=!1},0)}Gt(null)}};return window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n),()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n)}},[Wt,e,A,Nt]);let qt=D.useRef(null),[U,Jt]=D.useState(null),Yt=D.useRef(null);D.useEffect(()=>{Yt.current=U},[U]),D.useEffect(()=>{if(!U)return;let t=e=>{let t=qt.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,r=e.clientY-t.top;Jt(e=>e&&{...e,x:n,y:r})},n=()=>{let t=Yt.current;if(t&&t.targetId!=null&&String(t.targetId)!==String(t.sourceId)&&M){let n=e.find(e=>String(e.id)===String(t.sourceId)),r=e.find(e=>String(e.id)===String(t.targetId)),i=t.targetEnd??`start`,a=`${t.sourceEnd===`end`?`f`:`s`}${i===`end`?`f`:`s`}`;n&&r&&M(n,r,a)}Et.current=!0,window.setTimeout(()=>{Et.current=!1},0),Jt(null)};return window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n),()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n)}},[U,e,M]);let[Xt,Zt]=D.useState(null),Qt=D.useRef(null);D.useEffect(()=>{if(!Xt)return;let e=e=>{Qt.current&&e.target instanceof Node&&Qt.current.contains(e.target)||Zt(null)},t=e=>{e.key===`Escape`&&Zt(null)};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,t)}},[Xt]);let[W,$t]=D.useState(null),en=D.useRef(null);D.useEffect(()=>{if(!W)return;let e=e=>{en.current&&e.target instanceof Node&&en.current.contains(e.target)||$t(null)},t=e=>{e.key===`Escape`&&$t(null)};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,t)}},[W]);let[tn,nn]=D.useState(null),rn=D.useRef(null);D.useEffect(()=>{if(!tn)return;let e=e=>{rn.current&&e.target instanceof Node&&rn.current.contains(e.target)||nn(null)},t=e=>{e.key===`Escape`&&nn(null)};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,t)}},[tn]);let[an,on]=D.useState(null),sn=!!(a||A||M||j),cn=D.useCallback((e,t)=>{t.preventDefault(),t.stopPropagation(),on(e.id),sn&&Zt({x:t.clientX,y:t.clientY,taskId:e.id})},[sn]),ln=D.useCallback((e,t,n,r)=>{r.preventDefault(),r.stopPropagation(),!(!M&&!N)&&$t({x:r.clientX,y:r.clientY,sourceId:e,targetId:t,type:n})},[M,N]),[un,dn]=D.useState(()=>new Set),fn=D.useCallback(e=>{dn(t=>{let n=new Set(t),r=String(e);return n.has(r)?n.delete(r):n.add(r),n})},[]),pn=D.useRef(!1);D.useEffect(()=>{if(pn.current||_e==null||V.length===0)return;pn.current=!0;let e=new Map(V.map(e=>[String(e.id),e])),t=new Set;for(let n of V){let r=n.parent!=null&&n.parent!==``?String(n.parent):null;r&&r!==String(n.id)&&e.has(r)&&t.add(r)}let n=t=>{let n=0,r=new Set([String(t.id)]),i=t.parent!=null&&t.parent!==``?e.get(String(t.parent)):void 0;for(;i&&!r.has(String(i.id));)n+=1,r.add(String(i.id)),i=i.parent!=null&&i.parent!==``?e.get(String(i.parent)):void 0;return n},r=new Set;for(let e of V){let i=String(e.id);t.has(i)&&n(e)>=_e&&r.add(i)}r.size&&dn(e=>e.size?e:r)},[_e,V]);let G=D.useMemo(()=>{let e=new Set(V.map(e=>String(e.id))),t=new Map,n=[];for(let r of V){let i=r.parent!=null&&r.parent!==``?String(r.parent):null;if(i&&i!==String(r.id)&&e.has(i)){let e=t.get(i);e?e.push(r):t.set(i,[r])}else n.push(r)}let r=new Map,i=(e,n)=>{let a=String(e.id),o=r.get(a);if(o)return o;let s=t.get(a)??[],c;if(!s.length||n.has(a))c={start:e.start,end:e.end,progress:e.progress};else{n.add(a);let e=null,t=null,r=0,o=0;for(let a of s){let s=i(a,n);(!e||s.start<e)&&(e=s.start),(!t||s.end>t)&&(t=s.end);let c=Math.max(s.end.getTime()-s.start.getTime(),Ke);r+=c*s.progress,o+=c}n.delete(a),c={start:e,end:t,progress:o?r/o:0}}return r.set(a,c),c},a=[],o=new Set,s=e=>{for(let n of t.get(String(e.id))??[])o.has(String(n.id))||(o.add(String(n.id)),s(n))},c=(e,n)=>{let r=String(e.id);if(o.has(r))return;o.add(r);let l=t.get(r)??[],u=l.length>0,d=u||e.type===`summary`,f=u?i(e,new Set):{start:e.start,end:e.end,progress:e.progress},p=!d&&(e.type===`milestone`||e.end.getTime()<=e.start.getTime());if(a.push({task:e,depth:n,hasChildren:u,isSummary:d,isMilestone:p,...f}),u)if(un.has(r))s(e);else for(let e of l)c(e,n+1)};for(let e of n)c(e,0);for(let e of V)o.has(String(e.id))||c(e,0);return a},[V,un]),mn=D.useCallback(e=>{if(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement)return;if((e.ctrlKey||e.metaKey)&&(e.key===`z`||e.key===`Z`)){e.preventDefault(),e.shiftKey?Bt():zt();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`Y`)){e.preventDefault(),Bt();return}if(!G.length)return;let t=an==null?-1:G.findIndex(e=>String(e.task.id)===String(an));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let n=e.key===`ArrowDown`?Math.min(G.length-1,t+1):Math.max(0,t<=0?0:t-1);on(G[n].task.id);let r=X.current;if(r){let e=n*F;e<r.scrollTop?r.scrollTop=e:e+F>r.scrollTop+r.clientHeight&&(r.scrollTop=e+F-r.clientHeight)}return}if(t<0)return;let n=G[t];e.key===`Enter`?(e.preventDefault(),a?.(n.task)):e.key===`Delete`||e.key===`Backspace`?j&&(e.preventDefault(),j(n.task)):(e.key===`ArrowRight`&&n.hasChildren&&un.has(String(n.task.id))||e.key===`ArrowLeft`&&n.hasChildren&&!un.has(String(n.task.id)))&&(e.preventDefault(),fn(n.task.id))},[G,an,a,j,un,fn,F,zt,Bt]),K=D.useMemo(()=>{let t=n?new Date(n):new Date,i=r?new Date(r):new Date;return!n&&e.length>0&&(t=new Date(Math.min(...e.map(e=>e.start.getTime()))),t.setDate(t.getDate()-7)),!r&&e.length>0&&(i=new Date(Math.max(...e.map(e=>e.end.getTime()))),i.setDate(i.getDate()+14)),t=R===`day`&&C&&C.bands.length>0?Fe(t,C.dayStartMin):qe(t,R),i.setHours(23,59,59,999),{start:t,end:i}},[n,r,e,R,C]),hn=R===`day`&&!!C&&C.bands.length>0,gn=!hn&&R===`day`&&!!S&&(!!S.skipWeekends||!!(S.holidays&&S.holidays.size)),_n=D.useCallback(e=>{if(!S)return!0;if(S.skipWeekends){let t=e.getDay();if(t===0||t===6)return!1}if(S.holidays&&S.holidays.size){let t=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;if(S.holidays.has(t))return!1}return!0},[S]),q=D.useMemo(()=>{let e=[];if(hn&&C){let t=new Date(K.start);for(;t<=K.end;)for(let n of C.bands){let r=n.durMs/Ke*pt;e.push({date:new Date(t),label:n.label,isWeekend:!1,width:r,realMs:n.durMs,bandColor:n.color}),t=new Date(t.getTime()+n.durMs)}return e}let t=new Date(K.start);for(;t<=K.end;){let n=Ye(t,1,R);if(gn&&!_n(t)){t=n;continue}let r=(n.getTime()-t.getTime())/Ke*pt,i,a;R===`day`?(i=String(t.getDate()),a=t.toLocaleDateString(E,{weekday:`narrow`})):i=R===`week`?t.toLocaleDateString(E,{month:`numeric`,day:`numeric`}):R===`month`?t.toLocaleDateString(E,{month:`short`}):R===`quarter`?`Q${Math.floor(t.getMonth()/3)+1}`:String(t.getFullYear()),e.push({date:new Date(t),label:i,sublabel:a,isWeekend:R===`day`&&(t.getDay()===0||t.getDay()===6),width:r}),t=n}return e},[K,R,pt,E,gn,_n,hn,C]),J=D.useMemo(()=>{let e=Array(q.length+1),t=0;for(let n=0;n<q.length;n++)e[n]=t,t+=q[n].width;return e[q.length]=t,e},[q]),vn=J[J.length-1],yn=D.useMemo(()=>q.map(e=>e.date.getTime()),[q]),bn=D.useMemo(()=>q.map(e=>e.realMs==null?Ye(e.date,1,R).getTime()-e.date.getTime():e.realMs),[q,R]),Y=D.useCallback(e=>{let t=q.length;if(t===0)return 0;let n=e.getTime(),r=0,i=t-1,a=0;for(;r<=i;){let e=r+i>>1;yn[e]<=n?(a=e,r=e+1):i=e-1}let o=bn[a]||864e5,s=(n-yn[a])/o;return(gn||hn)&&(s=Math.max(0,Math.min(s,1))),J[a]+s*q[a].width},[q,yn,bn,J,gn,hn]),xn=D.useCallback(e=>{let t=q.length;if(t===0)return new Date(K.start);let n=0,r=t-1,i=0;for(;n<=r;){let t=n+r>>1;J[t]<=e?(i=t,n=t+1):r=t-1}let a=q[i].width||1,o=(e-J[i])/a;return new Date(yn[i]+o*(bn[i]||864e5))},[q,yn,bn,J,K]),Sn=D.useCallback(e=>{let t=X.current;ot.current==null&&t&&t.clientWidth>0&&(ot.current=xn(t.scrollLeft)),at.current=ot.current,st.current=!0,it(e),c?.(e)},[c,xn]);D.useLayoutEffect(()=>{let e=at.current;if(e==null)return;at.current=null;let t=X.current;if(!t||t.clientWidth===0)return;let n=Math.max(0,t.scrollWidth-t.clientWidth),r=Math.max(0,Math.min(Math.round(Y(qe(e,R))),n));t.scrollLeft!==r&&(t.scrollLeft=r)},[R,Y]);let Cn=D.useCallback((e,t)=>{let n=q.length;if(n===0||t===0)return new Date(e);let r=e.getTime(),i=0,a=n-1,o=0;for(;i<=a;){let e=i+a>>1;yn[e]<=r?(o=e,i=e+1):a=e-1}let s=Math.min(n-1,Math.max(0,o+t)),c=r-yn[o];return new Date(yn[s]+c)},[q,yn]),wn=D.useRef(null);wn.current=gn||hn?Cn:null;let Tn=D.useMemo(()=>{let e=[];if(hn&&C){let t=0;for(let n of q){let r=String(Fe(n.date,C.dayStartMin).getTime()),i=e[e.length-1];i&&i.key===r?i.width+=n.width:e.push({key:r,label:n.date.toLocaleDateString(E,{month:`short`,day:`numeric`}),width:n.width,offset:t}),t+=n.width}return e}let t=R===`year`?`decade`:R===`month`||R===`quarter`?`year`:`month`,n=0;for(let r of q){let i=r.date.getFullYear(),a=Math.floor(i/10)*10,o=t===`decade`?String(a):t===`year`?String(i):`${i}-${r.date.getMonth()}`,s=e[e.length-1];s&&s.key===o?s.width+=r.width:e.push({key:o,label:t===`decade`?`${a}s`:t===`year`?String(i):r.date.toLocaleDateString(E,{month:`short`,year:`numeric`}),width:r.width,offset:n}),n+=r.width}return e},[q,R,E,hn,C]),En=D.useMemo(()=>(i??[]).map((e,t)=>{let n=e.date instanceof Date?e.date:new Date(e.date);return{index:t,label:e.label,color:e.color||`hsl(var(--primary))`,left:Math.round(Y(n)),valid:!isNaN(n.getTime())&&n>=K.start&&n<=K.end}}).filter(e=>e.valid),[i,K,Y]),Dn=D.useRef(null),On=D.useRef(null),kn=D.useRef(null),X=D.useRef(null);D.useEffect(()=>{let e=X.current;if(!e)return;let t=()=>{st.current=!1},n=new Set([`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `,`Spacebar`]),r=e=>{n.has(e.key)&&t()};return e.addEventListener(`wheel`,t,{passive:!0}),e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`pointerdown`,t,{passive:!0}),e.addEventListener(`keydown`,r),()=>{e.removeEventListener(`wheel`,t),e.removeEventListener(`touchstart`,t),e.removeEventListener(`pointerdown`,t),e.removeEventListener(`keydown`,r)}},[]);let[An,jn]=D.useState(null),Mn=D.useRef([]),Nn=D.useRef(null),[Pn,Fn]=D.useState({top:0,left:0}),[In,Ln]=D.useState({width:4e3,height:600}),Rn=D.useCallback(()=>{let e=X.current;if(!e)return;let t=e.clientWidth||4e3,n=e.clientHeight||600;Ln(e=>e.width===t&&e.height===n?e:{width:t,height:n})},[]);D.useLayoutEffect(()=>{Rn();let e=X.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(Rn);return t.observe(e),()=>t.disconnect()},[Rn]);let zn=D.useMemo(()=>Je(J,Pn.left-240,Pn.left+In.width+240),[J,Pn.left,In.width]),Bn=D.useMemo(()=>{let e=Tn.map(e=>e.offset);return e.push(vn),e},[Tn,vn]),Vn=D.useMemo(()=>Je(Bn,Pn.left-240,Pn.left+In.width+240),[Bn,Pn.left,In.width]),Z=D.useMemo(()=>({startIdx:Math.max(0,Math.floor(Pn.top/F)-6),endIdx:Math.min(G.length,Math.ceil((Pn.top+In.height)/F)+6)}),[Pn.top,In.height,F,G.length]),Hn=G.length*F,[Un,Wn]=D.useState(!1);D.useEffect(()=>{let e=()=>Wn(!!document.fullscreenElement);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let Gn=D.useCallback(()=>{let e=Ee.current;e&&(document.fullscreenElement?document.exitFullscreen?.():e.requestFullscreen?.())},[]),Kn=D.useRef(null),qn=D.useCallback(e=>{if(e.touches.length===2){let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY;Kn.current={baseDistance:Math.max(1,Math.sqrt(t*t+n*n)),baseColumn:B}}},[B]),Jn=D.useCallback(e=>{if(e.touches.length!==2||!Kn.current)return;let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY,r=Math.max(1,Math.sqrt(t*t+n*n))/Kn.current.baseDistance;Re(Math.max(15,Math.min(120,Math.round(Kn.current.baseColumn*r))))},[]),Yn=D.useCallback(()=>{Kn.current=null},[]),Q=D.useMemo(()=>{let e=new Date;return e<K.start||e>K.end?null:Math.round(Y(e))},[K,Y]),Xn=D.useCallback(()=>{if(Q==null||!X.current)return;let e=Math.max(0,Q-X.current.clientWidth/2);X.current.scrollTo({left:e,behavior:`smooth`})},[Q]),Zn=D.useRef(!1);D.useEffect(()=>{if(Zn.current||e.length===0)return;let t=window.requestAnimationFrame(()=>{let t=X.current;if(!t||t.clientWidth===0)return;let n=Q;if(n==null){let t=new Date(Math.min(...e.map(e=>e.start.getTime())));n=Math.round(Y(t))}t.scrollLeft=Math.max(0,n-t.clientWidth/2),Zn.current=!0});return()=>window.cancelAnimationFrame(t)},[e,Q,Y]);let Qn=D.useCallback((e,t=`left`)=>{let n=X.current;if(!n||e<K.start||e>K.end)return!1;let r=Math.round(Y(e)),i=t===`center`?r-n.clientWidth/2:r-24;return n.scrollTo({left:Math.max(0,i),behavior:`smooth`}),!0},[K,Y]),$n=D.useCallback((e,t,n)=>{let r=X.current;if(!r)return;let i=Y(e),a=Y(t),o=Math.max(0,r.scrollWidth-r.clientWidth),s=Math.min(96,r.clientWidth*.15),c=a-i<=r.clientWidth-s?(i+a)/2-r.clientWidth/2:i-s,l=Math.max(0,Math.min(c,o));Mn.current.forEach(e=>window.clearTimeout(e)),Mn.current=[],Nn.current?.(),Nn.current=null,jn(null);let u=()=>{if(n==null)return;let e=window.requestAnimationFrame(()=>{jn(n),Mn.current.push(window.setTimeout(()=>jn(e=>e===n?null:e),1500))});Nn.current=()=>window.cancelAnimationFrame(e)},d=Math.abs(r.scrollLeft-l)>2;if(r.scrollTo({left:l,behavior:`smooth`}),!d){u();return}let f=`onscrollend`in r,p=!1,m=()=>{p||(p=!0,r.removeEventListener(`scrollend`,m),u())};r.addEventListener(`scrollend`,m),Mn.current.push(window.setTimeout(m,f?1500:500)),Nn.current=()=>r.removeEventListener(`scrollend`,m)},[Y]);D.useEffect(()=>()=>{Mn.current.forEach(e=>window.clearTimeout(e)),Nn.current?.()},[]);let er=D.useCallback(()=>Qn(qe(new Date,`week`)),[Qn]),tr=D.useCallback(()=>Qn(qe(new Date,`month`)),[Qn]),nr=e=>{let t=e.currentTarget;!st.current&&t.clientWidth>0&&(ot.current=xn(t.scrollLeft)),Dn.current&&(Dn.current.scrollLeft=t.scrollLeft),On.current&&On.current.scrollTop!==t.scrollTop&&(On.current.scrollTop=t.scrollTop),Fn(e=>e.top===t.scrollTop&&e.left===t.scrollLeft?e:{top:t.scrollTop,left:t.scrollLeft}),Rn()},rr=e=>{let t=e.currentTarget,n=X.current;n&&n.scrollTop!==t.scrollTop&&(n.scrollTop=t.scrollTop),Fn(e=>e.top===t.scrollTop?e:{...e,top:t.scrollTop})},ir=(e,t)=>{let n=Y(e),r=hn&&C?pt*Math.min(...C.bands.map(e=>e.durMs))/Ke:pt;return{left:n,width:Math.max(Y(t)-n,r,3)}},ar=H?.group?H.taskId:null,or=D.useMemo(()=>{if(ar==null)return null;let e=new Set([String(ar)]);for(let t of Ct(ar))e.add(String(t.id));return e},[ar,Ct]),sr=D.useMemo(()=>{if(!H||H.group)return null;let e=new Set,t=new Set,n=St.get(String(H.taskId));for(;n&&n.parent!=null&&n.parent!==``;){let r=String(n.parent);if(t.has(r)||!St.has(r))break;t.add(r),e.add(r),n=St.get(r)}return e.size?e:null},[H,St]),cr=e=>{if(H){if(or?.has(String(e.task.id))){let t=Dt(H).start.getTime()-H.originStart.getTime();return ir(new Date(e.start.getTime()+t),new Date(e.end.getTime()+t))}if(!e.isSummary&&H.taskId===e.task.id){let e=Dt(H);return ir(e.start,e.end)}if(e.isSummary&&sr?.has(String(e.task.id))){let t=Dt(H),n=String(H.taskId),r=null,i=null;for(let a of Ct(e.task.id)){if((xt.get(String(a.id))??[]).length!==0)continue;let e=String(a.id)===n?t.start:a.start,o=String(a.id)===n?t.end:a.end;(!r||e<r)&&(r=e),(!i||o>i)&&(i=o)}if(r&&i)return ir(r,i)}}return ir(e.start,e.end)},lr=D.useMemo(()=>{let e=new Map;G.forEach((t,n)=>e.set(String(t.task.id),n));let t=[];return G.forEach(({task:n},r)=>{for(let i of n.dependencies??[]){let a=typeof i==`object`&&!!i,o=a?i.id:i;if(o==null||o===``)continue;let s=e.get(String(o));if(s==null||s===r)continue;let c=a?i.type:void 0,l=c===`ss`||c===`ff`||c===`sf`?c:`fs`;t.push({key:`${String(o)}->${String(n.id)}:${l}`,sourceId:o,targetId:n.id,type:l,sourceIndex:s,targetIndex:r})}}),t},[G]),ur=Math.round(F*.2),dr=F-ur*2,fr=Math.max(Math.round(F*.4),12),pr=fr*Math.SQRT2/2,mr=dr,hr=ur,gr=Math.max(3,Math.round(F*.13)),_r=F-gr-1,vr=`rgba(100, 116, 139, 0.35)`,yr=`rgba(100, 116, 139, 0.6)`,br=e=>{let t=G[e.sourceIndex],n=G[e.targetIndex];if(!t||!n)return null;let r=cr(t),i=cr(n),a=e=>e.isSummary?hr+mr/2:F/2,o=e.sourceIndex*F+a(t),s=e.targetIndex*F+a(n),c=e.type===`fs`||e.type===`ff`,l=e.type===`ff`||e.type===`sf`,u=t.isMilestone?r.left+(c?pr:-pr):c?r.left+r.width:r.left,d=n.isMilestone?i.left+(l?pr:-pr):l?i.left+i.width:i.left,f=u+(c?10:-10),p=d+(l?10:-10),m=Math.round,h=[`M ${m(u)} ${m(o)}`,`L ${m(f)} ${m(o)}`];if(l?f>=p:f<=p)h.push(`L ${m(f)} ${m(s)}`,`L ${m(d)} ${m(s)}`);else{let t=s>=o?(e.sourceIndex+1)*F:e.sourceIndex*F;h.push(`L ${m(f)} ${m(t)}`,`L ${m(p)} ${m(t)}`,`L ${m(p)} ${m(s)}`,`L ${m(d)} ${m(s)}`)}return h.join(` `)},xr=H?.taskId??yt,[Sr,Cr]=D.useState(ce),wr=D.useMemo(()=>Sr?Me(e,S):null,[Sr,e,S]),Tr=D.useCallback(e=>wr?.criticalIds.has(String(e))??!1,[wr]),$=`#dc2626`,Er=D.useCallback(()=>{if(!A)return;let t=Ne(e,S),n=[];for(let r of t){let t=e.find(e=>String(e.id)===r.id);t&&n.push({task:t,changes:{start:r.start,end:r.end}})}Nt(n)},[e,A,S,Nt]),Dr=D.useCallback(()=>{if(typeof document>`u`||!e.length)return null;let t=e=>String(e).replace(/[&<>"]/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`})[e]),n=Math.max(z,200),r=Math.ceil(n+vn),i=Math.ceil(36+G.length*F),a=wr?.criticalEdges??null,o=[];o.push(`<rect x="0" y="0" width="${r}" height="${i}" fill="#ffffff"/>`),o.push(`<rect x="0" y="0" width="${r}" height="36" fill="#f8fafc"/>`),o.push(`<g transform="translate(${n},0)" font-family="sans-serif" font-size="10" fill="#475569">`),Tn.forEach(e=>{o.push(`<line x1="${e.offset.toFixed(1)}" y1="0" x2="${e.offset.toFixed(1)}" y2="36" stroke="#e2e8f0"/>`),o.push(`<text x="${(e.offset+e.width/2).toFixed(1)}" y="12" text-anchor="middle" font-weight="600">${t(e.label)}</text>`)}),q.forEach((e,n)=>{let r=J[n];o.push(`<line x1="${r.toFixed(1)}" y1="18" x2="${r.toFixed(1)}" y2="${i}" stroke="#eef2f7"/>`),o.push(`<text x="${(r+e.width/2).toFixed(1)}" y="30" text-anchor="middle" fill="#1f2937">${t(e.label)}</text>`)}),o.push(`</g>`),o.push(`<line x1="0" y1="18" x2="${r}" y2="18" stroke="#e2e8f0"/>`),o.push(`<line x1="0" y1="36" x2="${r}" y2="36" stroke="#cbd5e1"/>`),o.push(`<line x1="${n}" y1="0" x2="${n}" y2="${i}" stroke="#cbd5e1"/>`),o.push(`<g transform="translate(0,36)" font-family="sans-serif" font-size="11" fill="#1f2937">`),G.forEach((e,r)=>{let i=r*F;o.push(`<line x1="0" y1="${(i+F).toFixed(1)}" x2="${n}" y2="${(i+F).toFixed(1)}" stroke="#f1f5f9"/>`);let a=8+e.depth*14,s=Math.max(4,Math.floor((n-a)/6.5)),c=e.task.title.length>s?e.task.title.slice(0,s-1)+`…`:e.task.title,l=e.isSummary?` font-weight="600"`:``;o.push(`<text x="${a}" y="${(i+F/2+4).toFixed(1)}"${l}>${t(c)}</text>`)}),o.push(`</g>`),o.push(`<g transform="translate(${n},36)" font-family="sans-serif" font-size="9">`),G.forEach((e,t)=>{let n=t*F,{left:r,width:i}=ir(e.start,e.end),a=Tr(e.task.id),s=a?` stroke="${$}" stroke-width="2"`:``;if(de&&e.task.baselineStart&&e.task.baselineEnd){let t=ir(e.task.baselineStart,e.task.baselineEnd);o.push(`<rect x="${t.left.toFixed(1)}" y="${(n+_r).toFixed(1)}" width="${Math.max(2,t.width).toFixed(1)}" height="${gr}" rx="1" fill="${vr}" stroke="${yr}"/>`)}if(e.isMilestone){let t=r,i=n+F/2,s=fr/2,c=a?$:e.task.color||`#3b82f6`;o.push(`<polygon points="${t},${i-s} ${t+s},${i} ${t},${i+s} ${t-s},${i}" fill="${c}"/>`)}else if(e.isSummary){let t=e.task.color||`#64748b`;o.push(`<rect x="${r.toFixed(1)}" y="${(n+hr).toFixed(1)}" width="${i.toFixed(1)}" height="${mr}" rx="3" fill="${t}"${s}/>`);let a=i*Math.min(100,Math.max(0,e.progress))/100;o.push(`<rect x="${r.toFixed(1)}" y="${(n+hr).toFixed(1)}" width="${a.toFixed(1)}" height="${mr}" rx="3" fill="rgba(0,0,0,0.2)"/>`)}else{let t=e.task.color||`#3b82f6`;o.push(`<rect x="${r.toFixed(1)}" y="${(n+ur).toFixed(1)}" width="${i.toFixed(1)}" height="${dr}" rx="3" fill="${t}"${s}/>`);let a=i*Math.min(100,Math.max(0,e.progress))/100;o.push(`<rect x="${r.toFixed(1)}" y="${(n+ur).toFixed(1)}" width="${a.toFixed(1)}" height="${dr}" rx="3" fill="rgba(0,0,0,0.18)"/>`),i>=24&&o.push(`<text x="${(r+i/2).toFixed(1)}" y="${(n+F/2+3).toFixed(1)}" text-anchor="middle" fill="#ffffff">${Math.round(e.progress)}%</text>`)}}),lr.forEach(e=>{let t=br(e);if(!t)return;let n=a?.has(`${String(e.sourceId)}->${String(e.targetId)}`)??!1,r=n?$:`#94a3b8`;o.push(`<path d="${t}" fill="none" stroke="${r}" stroke-width="${n?2:1.5}"/>`)}),Q!=null&&o.push(`<line x1="${Q.toFixed(1)}" y1="0" x2="${Q.toFixed(1)}" y2="${G.length*F}" stroke="#ef4444" stroke-width="1.5"/>`);let s=G.length*F;return En.forEach(e=>{let n=/var\(/.test(e.color)?`#6366f1`:e.color;if(o.push(`<line x1="${e.left.toFixed(1)}" y1="0" x2="${e.left.toFixed(1)}" y2="${s}" stroke="${t(n)}" stroke-width="1.5"/>`),e.label){let r=e.label.length*6+8;o.push(`<rect x="${(e.left-r/2).toFixed(1)}" y="0" width="${r}" height="14" rx="2" fill="${t(n)}"/>`),o.push(`<text x="${e.left.toFixed(1)}" y="10" text-anchor="middle" font-size="9" font-weight="600" fill="#ffffff">${t(e.label)}</text>`)}}),o.push(`</g>`),{svg:`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${i}" viewBox="0 0 ${r} ${i}">${o.join(``)}</svg>`,W:r,H:i}},[e,G,lr,br,ir,Tr,wr,q,J,vn,z,F,ur,dr,hr,mr,fr,Q,R,de,_r,gr,vr,yr,En,Tn]),Or=D.useCallback(async()=>{let e=Dr();if(!e)return;let t=await Xe(e.svg,e.W,e.H);t&&t.toBlob(e=>{e&&Ze(e,`gantt-${R}.png`)},`image/png`)},[Dr,R]),kr=D.useCallback(async()=>{let e=Dr();if(!e)return;let t=await Xe(e.svg,e.W,e.H);t&&Ze(Qe($e(t.toDataURL(`image/jpeg`,.92)),t.width,t.height),`gantt-${R}.pdf`)},[Dr,R]),[Ar,jr]=D.useState(!1),Mr=D.useCallback(()=>{let e={viewMode:R,columnWidth:Le,taskListCollapsed:ct,taskListWidth:et};ye&&nt(ye,e),be?.(e),jr(!0)},[R,Le,ct,et,ye,be]);return D.useEffect(()=>{if(!Ar)return;let e=setTimeout(()=>jr(!1),1500);return()=>clearTimeout(e)},[Ar]),(0,L.jsxs)(`div`,{ref:Ee,className:v(`flex flex-col h-full bg-background overflow-hidden min-w-0`,ee),"data-readonly":k?`true`:void 0,"data-mobile-readonly":me&&Oe?`true`:void 0,children:[(0,L.jsx)(`style`,{children:`
|
|
16
|
+
.gantt-resize-handle:hover { background-color: rgba(255, 255, 255, 0.4); }
|
|
17
|
+
.gantt-bar-hover:hover { filter: brightness(1.1); }
|
|
18
|
+
.gantt-locate-btn { opacity: 0; transition: opacity 0.15s ease; }
|
|
19
|
+
.group\\/task-row:hover .gantt-locate-btn { opacity: 0.6; }
|
|
20
|
+
.gantt-locate-btn:hover, .gantt-locate-btn:focus-visible { opacity: 1; }
|
|
21
|
+
/* 定位闪烁: blink the located bar 3× with a thick ring + colored glow so
|
|
22
|
+
it's hard to miss. The ring is an outline (not box-shadow) and the glow
|
|
23
|
+
is a drop-shadow *filter* — both stay clear of the critical-path bar's
|
|
24
|
+
inline box-shadow, which they'd otherwise clobber. */
|
|
25
|
+
@keyframes gantt-flash {
|
|
26
|
+
0%, 25%, 50%, 100% {
|
|
27
|
+
outline-color: rgba(37, 99, 235, 0);
|
|
28
|
+
filter: drop-shadow(0 0 0 rgba(37, 99, 235, 0));
|
|
29
|
+
}
|
|
30
|
+
12%, 37%, 62% {
|
|
31
|
+
outline-color: rgba(37, 99, 235, 1);
|
|
32
|
+
filter: drop-shadow(0 0 9px rgba(37, 99, 235, 0.9));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
.gantt-flash {
|
|
36
|
+
outline: 3px solid transparent;
|
|
37
|
+
outline-offset: 3px;
|
|
38
|
+
border-radius: 2px;
|
|
39
|
+
animation: gantt-flash 1.5s ease-in-out;
|
|
40
|
+
}
|
|
41
|
+
@media (min-width: 640px) {
|
|
42
|
+
.gantt-sm-h50 { height: 50px; }
|
|
43
|
+
.gantt-sm-w20 { width: 80px; }
|
|
44
|
+
.gantt-sm-hidden { display: none; }
|
|
45
|
+
}
|
|
46
|
+
/* Persistent, grabbable timeline scrollbars. macOS (and iOS) default to
|
|
47
|
+
overlay scrollbars that collapse to 0px and auto-hide, so the
|
|
48
|
+
timeline's vertical scrollbar was nearly impossible to find. Defining
|
|
49
|
+
::-webkit-scrollbar opts this pane into a classic, always-visible bar
|
|
50
|
+
regardless of the OS overlay preference. The thumb gets a min size so
|
|
51
|
+
that with thousands of virtualized rows (scrollHeight in the hundreds
|
|
52
|
+
of thousands of px) it never shrinks to an un-grabbable sliver. Scoped
|
|
53
|
+
to the gantt pane so the host app's own scrollbars are untouched, and
|
|
54
|
+
themed with neutral rgba (not theme utilities, which don't always
|
|
55
|
+
reach a consuming app) so it's visible on any background. */
|
|
56
|
+
/* Firefox (and any engine without ::-webkit-scrollbar) only: the
|
|
57
|
+
standard props. We must NOT set these unconditionally — modern Chrome
|
|
58
|
+
now honors scrollbar-width and, when it's present, IGNORES the
|
|
59
|
+
::-webkit-scrollbar rule below, falling back to the 0px auto-hiding
|
|
60
|
+
overlay bar we're trying to replace. */
|
|
61
|
+
@supports not selector(::-webkit-scrollbar) {
|
|
62
|
+
[data-testid="gantt-timeline"] {
|
|
63
|
+
scrollbar-width: thin;
|
|
64
|
+
scrollbar-color: rgba(130,130,130,0.55) transparent;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
[data-testid="gantt-timeline"]::-webkit-scrollbar {
|
|
68
|
+
width: 14px;
|
|
69
|
+
height: 14px;
|
|
70
|
+
}
|
|
71
|
+
[data-testid="gantt-timeline"]::-webkit-scrollbar-track {
|
|
72
|
+
background: transparent;
|
|
73
|
+
}
|
|
74
|
+
[data-testid="gantt-timeline"]::-webkit-scrollbar-thumb {
|
|
75
|
+
background-color: rgba(130,130,130,0.55);
|
|
76
|
+
border-radius: 8px;
|
|
77
|
+
border: 3px solid transparent;
|
|
78
|
+
background-clip: padding-box;
|
|
79
|
+
min-height: 40px;
|
|
80
|
+
min-width: 40px;
|
|
81
|
+
}
|
|
82
|
+
[data-testid="gantt-timeline"]::-webkit-scrollbar-thumb:hover {
|
|
83
|
+
background-color: rgba(110,110,110,0.85);
|
|
84
|
+
}
|
|
85
|
+
[data-testid="gantt-timeline"]::-webkit-scrollbar-corner {
|
|
86
|
+
background: transparent;
|
|
87
|
+
}
|
|
88
|
+
/* The task-list pane scrolls in lockstep with the timeline, so its own
|
|
89
|
+
vertical scrollbar (butted against the divider) was a confusing second
|
|
90
|
+
bar. Hide it — the pane stays wheel/drag-scrollable and synced. */
|
|
91
|
+
.gantt-task-list::-webkit-scrollbar { width: 0; height: 0; }
|
|
92
|
+
.gantt-task-list { scrollbar-width: none; }
|
|
93
|
+
`}),(0,L.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-2 p-2 border-b bg-card`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":w(`gantt.toolbar.prevPeriod`),children:(0,L.jsx)(f,{className:`h-4 w-4`})}),(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":w(`gantt.toolbar.nextPeriod`),children:(0,L.jsx)(Ce,{className:`h-4 w-4`})}),(0,L.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:K.start.toLocaleDateString(E,{month:`long`,year:`numeric`})}),k&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground`,"data-testid":`gantt-readonly-badge`,title:w(`gantt.readOnlyHint`),children:[(0,L.jsx)(te,{className:`h-3 w-3`}),w(`gantt.readOnly`)]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`div`,{className:`flex bg-muted rounded-md p-1`,role:`group`,"aria-label":w(`gantt.toolbar.viewMode`),children:We.map(e=>(0,L.jsx)(T,{variant:`ghost`,size:`sm`,className:v(`h-6 px-1.5 sm:px-2 text-xs`,R===e&&`bg-background shadow-sm hover:bg-background`),onClick:()=>Sn(e),"aria-pressed":R===e,"data-testid":`gantt-view-mode-${e}`,children:w(`gantt.viewMode.${e}`)},e))}),(0,L.jsxs)(`div`,{className:`flex bg-muted rounded-md p-1`,children:[(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>{if(B>15)Re(Math.max(15,B-10));else{let e=We.indexOf(R);e<We.length-1&&(Sn(We[e+1]),Re(I))}},"aria-label":w(`gantt.toolbar.zoomOut`),children:(0,L.jsx)(y,{className:`h-3 w-3`})}),(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>{if(B<120)Re(Math.min(120,B+10));else{let e=We.indexOf(R);e>0&&(Sn(We[e-1]),Re(I))}},"aria-label":w(`gantt.toolbar.zoomIn`),children:(0,L.jsx)(xe,{className:`h-3 w-3`})})]}),(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>lt(e=>!e),"aria-label":w(ct?`gantt.toolbar.showTaskList`:`gantt.toolbar.hideTaskList`),"aria-pressed":ct,"data-testid":`gantt-toggle-task-list`,children:ct?(0,L.jsx)(fe,{className:`h-4 w-4`}):(0,L.jsx)(oe,{className:`h-4 w-4`})}),(0,L.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:Xn,disabled:Q==null,"aria-label":w(`gantt.toolbar.jumpToToday`),"data-testid":`gantt-jump-today`,children:w(`gantt.toolbar.today`)}),(0,L.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:er,"aria-label":w(`gantt.toolbar.thisWeek`),"data-testid":`gantt-jump-week`,children:w(`gantt.toolbar.thisWeek`)}),(0,L.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:tr,"aria-label":w(`gantt.toolbar.thisMonth`),"data-testid":`gantt-jump-month`,children:w(`gantt.toolbar.thisMonth`)}),A?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:zt,disabled:!Vt,"aria-label":w(`gantt.toolbar.undo`),"data-testid":`gantt-undo`,children:(0,L.jsx)(h,{className:`h-4 w-4`})}),(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Bt,disabled:!Ht,"aria-label":w(`gantt.toolbar.redo`),"data-testid":`gantt-redo`,children:(0,L.jsx)(b,{className:`h-4 w-4`})})]}):null,(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>Cr(e=>!e),"aria-label":w(`gantt.toolbar.criticalPath`),"aria-pressed":Sr,"data-testid":`gantt-critical-path`,style:Sr?{color:$}:void 0,children:(0,L.jsx)(p,{className:`h-4 w-4`})}),je&&A?(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Er,"aria-label":w(`gantt.toolbar.autoSchedule`),"data-testid":`gantt-auto-schedule`,children:(0,L.jsx)(_,{className:`h-4 w-4`})}):null,(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Or,"aria-label":w(`gantt.toolbar.exportPng`),"data-testid":`gantt-export-png`,children:(0,L.jsx)(re,{className:`h-4 w-4`})}),(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:kr,"aria-label":w(`gantt.toolbar.exportPdf`),"data-testid":`gantt-export-pdf`,children:(0,L.jsx)(ne,{className:`h-4 w-4`})}),be||ye?(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Mr,"aria-label":w(`gantt.toolbar.saveLayout`),"aria-pressed":Ar,"data-testid":`gantt-save-layout`,style:Ar?{color:$}:void 0,children:(0,L.jsx)(le,{className:`h-4 w-4`})}):null,(0,L.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Gn,"aria-label":w(Un?`gantt.toolbar.exitFullscreen`:`gantt.toolbar.enterFullscreen`),"aria-pressed":Un,"data-testid":`gantt-fullscreen`,children:Un?(0,L.jsx)(m,{className:`h-4 w-4`}):(0,L.jsx)(g,{className:`h-4 w-4`})})]})]}),(0,L.jsxs)(`div`,{className:`relative flex flex-col flex-1 overflow-hidden outline-none focus-visible:ring-1 focus-visible:ring-ring`,tabIndex:0,onKeyDown:mn,"data-testid":`gantt-body`,children:[!ct&&z>0&&(0,L.jsx)(`div`,{className:`absolute top-0 bottom-0 z-30 group/splitter`,style:{left:z-3,width:7,cursor:`col-resize`},"data-testid":`gantt-list-resize`,role:`separator`,"aria-orientation":`vertical`,onPointerDown:e=>{if(e.button!==0)return;e.preventDefault();let t=e.clientX,n=z,r=Math.max(160,O-200),i=e=>{rt(Math.max(160,Math.min(n+(e.clientX-t),r)))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),document.body.style.cursor=``};document.body.style.cursor=`col-resize`,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},onDoubleClick:()=>rt(null),children:(0,L.jsx)(`div`,{className:`absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover/splitter:w-[3px] group-hover/splitter:bg-primary transition-all`})}),(0,L.jsxs)(`div`,{className:`flex border-b bg-muted/30 shrink-0 h-10 gantt-sm-h50`,children:[(0,L.jsxs)(`div`,{className:`flex items-center font-medium text-xs text-muted-foreground px-2 sm:px-4 border-r bg-card z-20 shadow-sm`,style:{width:z,minWidth:z},children:[(0,L.jsx)(`div`,{className:`flex-1 truncate`,children:w(`gantt.column.taskName`)}),mt&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right`,children:w(`gantt.column.start`)}),(0,L.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right`,children:w(`gantt.column.end`)})]})]}),(0,L.jsx)(`div`,{className:`flex-1 overflow-hidden`,ref:Dn,children:(0,L.jsxs)(`div`,{className:`flex flex-col h-full`,style:{width:vn},children:[(0,L.jsx)(`div`,{className:`relative border-b`,style:{height:`45%`},"data-testid":`gantt-header-groups`,children:Tn.slice(Vn.start,Vn.end).map(e=>(0,L.jsx)(`div`,{className:`absolute top-0 bottom-0 flex items-center justify-center border-r text-[10px] font-medium text-muted-foreground overflow-hidden`,style:{left:e.offset,width:e.width},children:(0,L.jsx)(`span`,{className:`truncate px-1`,children:e.label})},e.key))}),(0,L.jsx)(`div`,{className:`relative flex-1`,"data-testid":`gantt-header-units`,children:q.slice(zn.start,zn.end).map((e,t)=>{let n=zn.start+t;return(0,L.jsxs)(`div`,{className:v(`absolute top-0 bottom-0 flex items-center justify-center gap-1 border-r text-xs text-muted-foreground overflow-hidden`,e.isWeekend&&`bg-muted/50`),style:{left:J[n],width:e.width,backgroundColor:e.bandColor?`color-mix(in srgb, ${e.bandColor} 16%, transparent)`:void 0},children:[(0,L.jsx)(`span`,{className:`font-medium text-foreground truncate`,children:e.label}),e.sublabel&&B>=32&&(0,L.jsx)(`span`,{className:`text-[10px] opacity-70`,children:e.sublabel})]},n)})})]})})]}),(0,L.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,L.jsxs)(`div`,{className:`gantt-task-list overflow-y-auto overflow-x-hidden border-r bg-card z-10 shadow-sm`,ref:On,onScroll:rr,style:{width:z,minWidth:z},role:`tree`,"aria-label":w(`gantt.aria.taskList`),children:[Z.startIdx>0&&(0,L.jsx)(`div`,{style:{height:Z.startIdx*F},"aria-hidden":`true`}),G.slice(Z.startIdx,Z.endIdx).map(e=>{let t=e.task,n=Ae&&ht===t.id,r=un.has(String(t.id)),i=an!=null&&String(an)===String(t.id);return(0,L.jsxs)(`div`,{className:v(`group/task-row relative flex items-center border-b px-2 sm:px-4 hover:bg-accent/50 cursor-pointer transition-colors`,i&&`bg-accent/50`),style:{height:F,touchAction:`manipulation`},role:`treeitem`,"aria-level":e.depth+1,"aria-selected":i,"aria-expanded":e.hasChildren?!r:void 0,draggable:!!ke&&!n&&!t.locked,onDragStart:ke?e=>{e.dataTransfer.setData(`text/plain`,String(t.id)),e.dataTransfer.effectAllowed=`move`}:void 0,onDragOver:ke?e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`}:void 0,onDrop:ke?e=>{e.preventDefault();let n=e.dataTransfer.getData(`text/plain`);if(!n||n===String(t.id))return;let r=St.get(n);r&&String(r.parent??``)===String(t.parent??``)&&ke(r,t)}:void 0,onContextMenu:e=>cn(t,e),onClick:()=>{on(t.id),n||a?.(t)},onDoubleClick:()=>{Ae&&A&&!e.isSummary&&!t.locked&&(gt(t.id),vt({title:t.title,start:t.start.toLocaleDateString(`en-CA`),end:t.end.toLocaleDateString(`en-CA`),progress:String(t.progress)}))},children:[(0,L.jsxs)(`div`,{className:`flex-1 truncate font-medium text-xs sm:text-sm flex items-center gap-2`,style:e.depth>0?{paddingLeft:e.depth*14}:void 0,children:[e.hasChildren?(0,L.jsx)(`button`,{type:`button`,className:`h-4 w-4 shrink-0 flex items-center justify-center text-muted-foreground hover:text-foreground`,style:{marginLeft:-4},onClick:e=>{e.stopPropagation(),fn(t.id)},"aria-expanded":!r,"aria-label":w(r?`gantt.row.expand`:`gantt.row.collapse`),"data-testid":`gantt-row-toggle-${t.id}`,children:r?(0,L.jsx)(Ce,{className:`h-3.5 w-3.5`}):(0,L.jsx)(x,{className:`h-3.5 w-3.5`})}):(0,L.jsx)(`span`,{className:`w-3 shrink-0`,style:{marginLeft:-4},"aria-hidden":`true`}),(0,L.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0`,style:{backgroundColor:t.color||`#3b82f6`}}),n?(0,L.jsx)(`input`,{className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:_t.title||``,onChange:e=>vt(t=>({...t,title:e.target.value})),onKeyDown:e=>{e.key===`Enter`?(Nt([{task:t,changes:{title:_t.title,start:new Date(_t.start),end:new Date(_t.end),progress:Number(_t.progress)||0}}]),gt(null)):e.key===`Escape`&>(null)},onClick:e=>e.stopPropagation(),autoFocus:!0}):(0,L.jsxs)(`span`,{className:`flex flex-col min-w-0`,children:[(0,L.jsx)(`span`,{className:v(`truncate`,e.isSummary&&`font-semibold`),children:t.title}),(0,L.jsxs)(`span`,{className:`text-[10px] text-muted-foreground gantt-sm-hidden`,children:[e.start.toLocaleDateString(E,{month:`numeric`,day:`numeric`}),` → `,e.end.toLocaleDateString(E,{month:`numeric`,day:`numeric`})]})]})]}),(0,L.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right text-xs text-muted-foreground hidden sm:block`,hidden:!mt,style:mt?void 0:{display:`none`},children:n?(0,L.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:_t.start||``,onChange:e=>vt(t=>({...t,start:e.target.value})),onClick:e=>e.stopPropagation()}):e.start.toLocaleDateString(E,{month:`numeric`,day:`numeric`})}),(0,L.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right text-xs text-muted-foreground hidden sm:block`,hidden:!mt,style:mt?void 0:{display:`none`},children:n?(0,L.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:_t.end||``,onChange:e=>vt(t=>({...t,end:e.target.value})),onClick:e=>e.stopPropagation()}):e.end.toLocaleDateString(E,{month:`numeric`,day:`numeric`})}),!n&&(0,L.jsx)(`button`,{type:`button`,title:w(`gantt.row.locate`),"aria-label":w(`gantt.row.locate`),className:`gantt-locate-btn hidden sm:block absolute top-1/2 -translate-y-1/2`,style:{right:1},onClick:t=>{t.stopPropagation(),$n(e.start,e.end,e.task.id)},children:(0,L.jsx)(ve,{className:`w-3 h-3`})})]},t.id)}),Z.endIdx<G.length&&(0,L.jsx)(`div`,{style:{height:(G.length-Z.endIdx)*F},"aria-hidden":`true`})]}),(0,L.jsx)(`div`,{className:`flex-1 overflow-auto bg-background/50 relative [-webkit-overflow-scrolling:touch]`,ref:e=>{kn.current=e,X.current=e},onScroll:nr,onTouchStart:qn,onTouchMove:Jn,onTouchEnd:Yn,"data-testid":`gantt-timeline`,children:(0,L.jsxs)(`div`,{className:`relative`,style:{width:vn},children:[Q!=null&&(0,L.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px z-20 pointer-events-none`,style:{left:Q,backgroundColor:`rgba(239, 68, 68, 0.8)`},"data-testid":`gantt-today-marker`,"aria-label":w(`gantt.toolbar.today`),children:(0,L.jsx)(`div`,{className:`absolute -translate-x-1/2 left-0 text-[10px] font-semibold text-white rounded-sm px-1 py-0.5 whitespace-nowrap z-30`,style:{top:2,backgroundColor:`#ef4444`},children:w(`gantt.toolbar.today`)})}),En.map(e=>(0,L.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px z-20 pointer-events-none`,style:{left:e.left,backgroundColor:e.color},"data-testid":`gantt-marker-${e.index}`,"aria-label":e.label,children:e.label&&(0,L.jsx)(`div`,{className:`absolute -translate-x-1/2 left-0 text-[10px] font-semibold text-white rounded-sm px-1 py-0.5 whitespace-nowrap z-30`,style:{top:2,backgroundColor:e.color},children:e.label})},e.index)),(0,L.jsxs)(`div`,{className:`relative`,ref:qt,children:[(0,L.jsx)(`div`,{className:`absolute inset-0 pointer-events-none`,style:{zIndex:0},children:q.slice(zn.start,zn.end).map((e,t)=>{let n=zn.start+t;return(0,L.jsx)(`div`,{className:`absolute top-0 bottom-0 border-r`,style:{left:J[n],width:e.width,backgroundColor:e.bandColor?`color-mix(in srgb, ${e.bandColor} 8%, transparent)`:e.isWeekend?`hsl(var(--muted) / 0.4)`:void 0}},n)})}),hn&&C&&C.showMidnight&&(0,L.jsx)(`div`,{className:`absolute inset-0 pointer-events-none`,style:{zIndex:0},children:q.slice(zn.start,zn.end).map((e,t)=>{let n=zn.start+t,r=e.realMs??0;if(!r)return null;let i=e.date.getTime(),a=e.date,o=new Date(a.getFullYear(),a.getMonth(),a.getDate()+1,0,0,0,0).getTime();return o<=i||o>=i+r?null:(0,L.jsx)(`div`,{className:`absolute top-0 bottom-0`,style:{left:J[n]+(o-i)/r*e.width,borderLeft:`1px dashed hsl(var(--muted-foreground) / 0.4)`},"data-testid":`gantt-midnight-${n}`,"aria-hidden":`true`},`midnight-${n}`)})}),Z.startIdx>0&&(0,L.jsx)(`div`,{style:{height:Z.startIdx*F},"aria-hidden":`true`}),G.slice(Z.startIdx,Z.endIdx).map(e=>{let t=e.task,n=Tr(t.id),r=ir(e.start,e.end),i=de&&t.baselineStart&&t.baselineEnd?ir(t.baselineStart,t.baselineEnd):null,o=i?(0,L.jsx)(`div`,{className:`absolute pointer-events-none rounded-[1px]`,style:{left:i.left,width:Math.max(2,i.width),top:_r,height:gr,backgroundColor:vr,border:`1px solid ${yr}`},"data-testid":`gantt-baseline-${t.id}`,"aria-hidden":`true`}):null,s=H?.taskId===t.id,c=or?.has(String(t.id))??!1,l=sr?.has(String(t.id))??!1,u=s||c||l?cr(e):r,d=!!t.locked,f=!!A&&!e.isSummary&&!d,p=U!=null&&U.targetId!=null&&String(U.targetId)===String(t.id)&&String(U.sourceId)!==String(t.id),m=U?e=>{let n=e.currentTarget.getBoundingClientRect(),r=n.width>0&&e.clientX-n.left>n.width/2?`end`:`start`;Jt(e=>e&&String(e.sourceId)!==String(t.id)?{...e,targetId:t.id,targetEnd:r}:e)}:void 0,h=U?e=>{e.target===e.currentTarget&&Jt(e=>e&&{...e,targetId:null,targetEnd:null})}:void 0,g=Math.max(1,Math.round((e.end.getTime()-e.start.getTime())/Ke)),ee=yt===t.id&&!H&&!Wt&&!U?(0,L.jsxs)(`div`,{className:`absolute z-30 pointer-events-none rounded-md border bg-popover text-popover-foreground px-2.5 py-1.5 text-xs shadow-md whitespace-nowrap`,style:{left:Math.max(u.left+8,4),top:F-8},role:`tooltip`,"data-testid":`gantt-tooltip-${t.id}`,children:[(0,L.jsx)(`div`,{className:`font-semibold`,children:t.title}),t.fields&&t.fields.length>0?(0,L.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`auto 1fr`,columnGap:10,rowGap:2,marginTop:4},children:t.fields.map((e,t)=>(0,L.jsxs)(D.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,L.jsx)(`span`,{style:{fontWeight:500},children:e.value})]},t))}):(0,L.jsxs)(`div`,{className:`text-muted-foreground`,children:[e.start.toLocaleDateString(E,{month:`short`,day:`numeric`}),` → `,e.end.toLocaleDateString(E,{month:`short`,day:`numeric`}),` · `,g,w(`gantt.tooltip.days`),` · `,Math.round(e.progress),`%`]})]}):null;if(t.type===`group`)return(0,L.jsx)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:F},onPointerMove:h,children:ee},t.id);if(e.isSummary){let r=t.color||`#0d9488`;return(0,L.jsxs)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:F},onPointerMove:h,children:[o,(0,L.jsxs)(`div`,{className:v(`gantt-bar-hover absolute rounded-sm border shadow-sm flex items-center px-2 select-none`,A?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,s&&`ring-2 ring-primary z-10`,An===t.id&&`gantt-flash z-10`),style:{left:u.left,width:u.width,top:hr,height:mr,backgroundColor:r,borderColor:n?$:`hsl(var(--primary-foreground) / 0.2)`,boxShadow:n?`0 0 0 2px ${$}`:void 0},"data-critical":n?`true`:void 0,"data-testid":`gantt-summary-bar-${t.id}`,"data-progress":Math.round(e.progress),onMouseEnter:()=>bt(t.id),onMouseLeave:()=>bt(e=>e===t.id?null:e),onPointerDown:n=>{n.button===0&&Ut(t,`move`,n,{group:!0,originStart:e.start,originEnd:e.end})},onClick:()=>{Et.current||a?.(t)},onContextMenu:e=>cn(t,e),children:[(0,L.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 pointer-events-none`,style:{width:`${Math.round(e.progress)}%`,backgroundColor:`rgba(0, 0, 0, 0.2)`,borderTopLeftRadius:`var(--radius-sm)`,borderBottomLeftRadius:`var(--radius-sm)`}}),(0,L.jsx)(`span`,{className:`relative text-[10px] text-white font-medium truncate pointer-events-none`,children:t.title})]}),s&&H&&(0,L.jsxs)(`div`,{className:`absolute z-30 pointer-events-none rounded border bg-popover text-popover-foreground px-1.5 py-0.5 text-[10px] shadow whitespace-nowrap`,style:{left:Math.max(u.left,4),top:hr+mr+2},"data-testid":`gantt-summary-drag-chip-${t.id}`,children:[Dt(H).start.toLocaleDateString(E,{month:`numeric`,day:`numeric`}),` → `,Dt(H).end.toLocaleDateString(E,{month:`numeric`,day:`numeric`})]}),ee]},t.id)}if(e.isMilestone){let e=fr;return(0,L.jsxs)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:F},onPointerMove:h,children:[o,(0,L.jsx)(`div`,{className:v(`gantt-bar-hover absolute rotate-45 rounded-[2px] border shadow-sm select-none`,f?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,s&&`ring-2 ring-primary z-10`,p&&`ring-2 ring-primary`,An===t.id&&`gantt-flash z-10`),style:{left:u.left-e/2,top:(F-e)/2,width:e,height:e,backgroundColor:n?$:t.color||`#3b82f6`,borderColor:n?$:`hsl(var(--primary-foreground) / 0.2)`,boxShadow:n?`0 0 0 2px ${$}`:void 0},"data-critical":n?`true`:void 0,"data-testid":`gantt-milestone-${t.id}`,onMouseEnter:()=>bt(t.id),onMouseLeave:()=>bt(e=>e===t.id?null:e),onClick:()=>{Et.current||a?.(t)},onContextMenu:e=>cn(t,e),onPointerMove:m,onPointerDown:f?e=>{e.button===0&&Ut(t,`move`,e)}:void 0}),ee]},t.id)}let _=Wt&&Wt.taskId===t.id?Wt.value:t.progress;return(0,L.jsxs)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:F},onPointerMove:h,onMouseEnter:()=>bt(t.id),onMouseLeave:()=>bt(e=>e===t.id?null:e),children:[s&&(0,L.jsx)(`div`,{className:`absolute rounded-sm border border-dashed pointer-events-none`,style:{left:r.left,width:r.width,top:ur,height:dr,opacity:.35,borderColor:`hsl(var(--primary) / 0.6)`},"aria-hidden":`true`}),o,(0,L.jsxs)(`div`,{className:v(`gantt-bar-hover absolute rounded-sm bg-primary border shadow-sm flex items-center px-2 group select-none`,f?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,s&&`ring-2 ring-primary z-10`,p&&`ring-2 ring-primary`,An===t.id&&`gantt-flash z-10`),style:{left:u.left,width:u.width,top:ur,height:dr,backgroundColor:t.color||`#3b82f6`,borderColor:n?$:`hsl(var(--primary-foreground) / 0.2)`,boxShadow:n?`0 0 0 2px ${$}`:void 0},"data-critical":n?`true`:void 0,"data-testid":`gantt-task-bar-${t.id}`,onClick:()=>{Et.current||a?.(t)},onContextMenu:e=>cn(t,e),onPointerMove:m,onPointerDown:f?e=>{e.button===0&&Ut(t,`move`,e)}:void 0,children:[f&&u.width>=14&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`gantt-resize-handle absolute left-0 top-0 bottom-0`,style:{width:6,cursor:`ew-resize`},"data-testid":`gantt-task-resize-left-${t.id}`,onPointerDown:e=>{e.button===0&&Ut(t,`resize-left`,e)},onClick:e=>e.stopPropagation()}),(0,L.jsx)(`div`,{className:`gantt-resize-handle absolute right-0 top-0 bottom-0`,style:{width:6,cursor:`ew-resize`},"data-testid":`gantt-task-resize-right-${t.id}`,onPointerDown:e=>{e.button===0&&Ut(t,`resize-right`,e)},onClick:e=>e.stopPropagation()})]}),_>0&&(0,L.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 pointer-events-none`,style:{width:`${_}%`,backgroundColor:`rgba(0, 0, 0, 0.2)`,borderTopLeftRadius:`var(--radius-sm)`,borderBottomLeftRadius:`var(--radius-sm)`}}),f&&u.width>=30&&(0,L.jsx)(`div`,{className:v(`absolute bottom-0 h-1/2 w-4 -translate-x-1/2 cursor-col-resize flex items-end justify-center pb-px`,Wt?.taskId===t.id?`opacity-100`:`opacity-0 group-hover:opacity-100 transition-opacity`),style:{left:`${_}%`},"data-testid":`gantt-progress-handle-${t.id}`,onPointerDown:e=>{e.button===0&&(e.stopPropagation(),e.preventDefault(),Gt({taskId:t.id,originClientX:e.clientX,originProgress:t.progress,barWidth:u.width,value:t.progress}))},onClick:e=>e.stopPropagation(),children:(0,L.jsx)(`div`,{style:{width:0,height:0,borderLeft:`5px solid transparent`,borderRight:`5px solid transparent`,borderBottom:`7px solid #fff`,filter:`drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35))`}})}),M&&!d&&[`start`,`end`].map(e=>{let n=U!=null&&String(U.sourceId)===String(t.id)&&U.sourceEnd===e,r=n||yt===t.id,i=r&&U==null;return(0,L.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 z-20 flex items-center transition-opacity`,style:{[e===`start`?`left`:`right`]:-28,height:24,width:30,cursor:`crosshair`,opacity:+!!r,pointerEvents:i?`auto`:`none`,justifyContent:e===`start`?`flex-start`:`flex-end`,paddingLeft:e===`start`?4:0,paddingRight:e===`end`?4:0},"data-testid":`gantt-link-dot-${e}-${t.id}`,onPointerDown:n=>{if(n.button!==0)return;n.stopPropagation(),n.preventDefault();let r=qt.current?.getBoundingClientRect();Jt({sourceId:t.id,sourceEnd:e,x:r?n.clientX-r.left:0,y:r?n.clientY-r.top:0,targetId:null,targetEnd:null})},onClick:e=>e.stopPropagation(),children:(0,L.jsx)(`div`,{className:`rounded-full`,style:{height:12,width:12,backgroundColor:`hsl(var(--background))`,border:`2px solid hsl(var(--primary))`,boxShadow:n?`0 0 0 3px hsl(var(--primary) / 0.25)`:`0 1px 2px rgba(0,0,0,0.25)`}})},e)}),(0,L.jsx)(`span`,{className:`relative text-[10px] text-white font-medium truncate pointer-events-none group-hover:opacity-0 transition-opacity`,children:t.title}),(0,L.jsx)(`span`,{className:`absolute inset-0 flex items-center px-2 text-[10px] text-white font-medium truncate opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none`,children:s?`${Dt(H).start.toLocaleDateString(E,{month:`numeric`,day:`numeric`})} → ${Dt(H).end.toLocaleDateString(E,{month:`numeric`,day:`numeric`})}`:`${Math.round(_)}%`})]}),ee]},t.id)}),Z.endIdx<G.length&&(0,L.jsx)(`div`,{style:{height:(G.length-Z.endIdx)*F},"aria-hidden":`true`}),(lr.length>0||U)&&(0,L.jsxs)(`svg`,{className:`absolute top-0 left-0 pointer-events-none z-10`,width:vn,height:Hn,"data-testid":`gantt-links`,"aria-hidden":`true`,children:[(0,L.jsxs)(`defs`,{children:[(0,L.jsx)(`marker`,{id:`gantt-link-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`6`,markerHeight:`6`,orient:`auto`,children:(0,L.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,fill:`hsl(var(--muted-foreground))`})}),(0,L.jsx)(`marker`,{id:`gantt-link-arrow-active`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`6`,markerHeight:`6`,orient:`auto`,children:(0,L.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,fill:`hsl(var(--primary))`})}),(0,L.jsx)(`marker`,{id:`gantt-link-arrow-critical`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`6`,markerHeight:`6`,orient:`auto`,children:(0,L.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,fill:$})})]}),lr.map(e=>{let t=Math.min(e.sourceIndex,e.targetIndex);if(Math.max(e.sourceIndex,e.targetIndex)<Z.startIdx-6||t>Z.endIdx+6)return null;let n=br(e);if(!n)return null;let r=xr!=null&&(String(e.sourceId)===String(xr)||String(e.targetId)===String(xr)),i=wr?.criticalEdges.has(`${String(e.sourceId)}->${String(e.targetId)}`)??!1,a=i?`gantt-link-arrow-critical`:r?`gantt-link-arrow-active`:`gantt-link-arrow`,o=!!(N||M);return(0,L.jsxs)(D.Fragment,{children:[(0,L.jsx)(`path`,{d:n,fill:`none`,stroke:i?$:r?`hsl(var(--primary))`:`hsl(var(--muted-foreground))`,strokeOpacity:i||r?1:.7,strokeWidth:i||r?2:1.5,markerEnd:`url(#${a})`,"data-testid":`gantt-link-${e.sourceId}-${e.targetId}`,"data-link-type":e.type,"data-active":r?`true`:`false`,"data-critical":i?`true`:void 0}),o&&(0,L.jsx)(`path`,{d:n,fill:`none`,stroke:`transparent`,strokeWidth:10,style:{pointerEvents:`stroke`,cursor:`context-menu`},"data-testid":`gantt-link-hit-${e.sourceId}-${e.targetId}`,onContextMenu:t=>ln(e.sourceId,e.targetId,e.type,t)})]},e.key)}),U&&(()=>{let e=G.findIndex(e=>String(e.task.id)===String(U.sourceId));if(e<0)return null;let t=cr(G[e]),n=G[e].isMilestone?t.left+(U.sourceEnd===`start`?-pr:pr):U.sourceEnd===`start`?t.left:t.left+t.width,r=e*F+F/2;return(0,L.jsx)(`path`,{d:`M ${Math.round(n)} ${Math.round(r)} L ${Math.round(U.x)} ${Math.round(U.y)}`,fill:`none`,stroke:`hsl(var(--primary))`,strokeWidth:1.5,strokeDasharray:`4 3`,"data-testid":`gantt-link-draft`})})()]}),U&&(()=>{let t=e.find(e=>String(e.id)===String(U.sourceId));if(!t)return null;let n=U.targetId==null?null:e.find(e=>String(e.id)===String(U.targetId)),r=e=>w(`gantt.linkEnd.${e}`),i=n?`${t.title} (${r(U.sourceEnd)}) → ${n.title} (${r(U.targetEnd??`start`)})`:`${t.title} (${r(U.sourceEnd)})`;return(0,L.jsx)(`div`,{className:`absolute z-30 pointer-events-none rounded-md border bg-popover text-popover-foreground px-2 py-1 text-[11px] font-medium shadow-md whitespace-nowrap`,style:{left:U.x+12,top:U.y+12},"data-testid":`gantt-link-draft-hint`,children:i})})()]})]})})]})]}),Xt&&(()=>{let t=e.find(e=>String(e.id)===String(Xt.taskId));if(!t)return null;let n=G.find(e=>String(e.task.id)===String(Xt.taskId)),r=`w-full text-left px-3 py-1.5 hover:bg-accent focus:bg-accent outline-none`;return(0,L.jsxs)(`div`,{ref:Qt,className:`fixed z-50 min-w-[160px] rounded-md border bg-popover text-popover-foreground shadow-md py-1 text-sm`,style:{left:Xt.x,top:Xt.y},role:`menu`,"data-testid":`gantt-context-menu`,children:[a&&(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-view`,onClick:()=>{Zt(null),a(t)},children:w(`gantt.menu.view`)}),Ae&&A&&n&&!n.isSummary&&!t.locked&&(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-edit`,onClick:()=>{Zt(null),gt(t.id),vt({title:t.title,start:t.start.toLocaleDateString(`en-CA`),end:t.end.toLocaleDateString(`en-CA`),progress:String(t.progress)})},children:w(`gantt.menu.edit`)}),M&&n&&!n.isMilestone&&!t.locked&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-add-predecessor`,onClick:()=>{let e=Xt;Zt(null),nn({x:e.x,y:e.y,taskId:t.id,relation:`pred`})},children:w(`gantt.menu.addPredecessor`)}),(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-add-successor`,onClick:()=>{let e=Xt;Zt(null),nn({x:e.x,y:e.y,taskId:t.id,relation:`succ`})},children:w(`gantt.menu.addSuccessor`)})]}),j&&!t.locked&&(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:v(r,`text-destructive`),"data-testid":`gantt-context-menu-delete`,onClick:()=>{Zt(null),j(t)},children:w(`gantt.menu.delete`)})]})})(),W&&(()=>{let t=e.find(e=>String(e.id)===String(W.sourceId)),n=e.find(e=>String(e.id)===String(W.targetId));if(!t||!n)return null;let r=`w-full text-left px-3 py-1.5 hover:bg-accent focus:bg-accent outline-none`;return(0,L.jsxs)(`div`,{ref:en,className:`fixed z-50 min-w-[180px] rounded-md border bg-popover text-popover-foreground shadow-md py-1 text-sm`,style:{left:W.x,top:W.y},role:`menu`,"data-testid":`gantt-link-context-menu`,children:[(0,L.jsxs)(`div`,{className:`px-3 py-1 text-xs text-muted-foreground truncate`,children:[t.title,` → `,n.title]}),M&&[`fs`,`ss`,`ff`,`sf`].map(e=>(0,L.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":W.type===e,className:v(r,W.type===e&&`font-semibold`),"data-testid":`gantt-link-menu-type-${e}`,onClick:()=>{$t(null),e!==W.type&&M(t,n,e)},children:[W.type===e?`✓ `:`\xA0\xA0`,w(`gantt.linkType.${e}`)]},e)),N&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`my-1 border-t`}),(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:v(r,`text-destructive`),"data-testid":`gantt-link-menu-remove`,onClick:()=>{$t(null),N(t,n)},children:w(`gantt.menu.removeDependency`)})]})]})})(),tn&&M&&(()=>{let t=e.find(e=>String(e.id)===String(tn.taskId));if(!t)return null;let n=new Set(lr.map(e=>`${String(e.sourceId)}->${String(e.targetId)}`)),r=e.filter(e=>{if(String(e.id)===String(t.id)||e.type===`summary`)return!1;let r=tn.relation===`pred`?`${String(e.id)}->${String(t.id)}`:`${String(t.id)}->${String(e.id)}`;return!n.has(r)});return(0,L.jsxs)(`div`,{ref:rn,className:`fixed z-50 min-w-[200px] max-h-[280px] overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md py-1 text-sm`,style:{left:tn.x,top:tn.y},role:`menu`,"data-testid":`gantt-dep-picker`,children:[(0,L.jsx)(`div`,{className:`px-3 py-1 text-xs text-muted-foreground`,children:tn.relation===`pred`?w(`gantt.menu.addPredecessor`):w(`gantt.menu.addSuccessor`)}),r.length===0?(0,L.jsx)(`div`,{className:`px-3 py-1.5 text-muted-foreground`,children:w(`gantt.menu.noCandidates`)}):r.map(e=>(0,L.jsx)(`button`,{type:`button`,role:`menuitem`,className:`w-full text-left px-3 py-1.5 hover:bg-accent focus:bg-accent outline-none truncate`,"data-testid":`gantt-dep-picker-option-${e.id}`,onClick:()=>{nn(null),tn.relation===`pred`?M(e,t,`fs`):M(t,e,`fs`)},children:e.title},String(e.id)))]})})(),Pt&&(0,L.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/30`,"data-testid":`gantt-conflict-overlay`,onClick:()=>Ft(null),children:(0,L.jsxs)(`div`,{className:`min-w-[280px] max-w-[360px] rounded-lg border bg-popover text-popover-foreground shadow-lg p-4`,role:`alertdialog`,"aria-modal":`true`,"data-testid":`gantt-conflict-dialog`,onClick:e=>e.stopPropagation(),children:[(0,L.jsx)(`div`,{className:`text-sm font-semibold mb-1`,"data-testid":`gantt-conflict-title`,children:w(`gantt.conflict.title`)}),(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground mb-3`,children:w(`gantt.conflict.body`).replace(`{count}`,String(Pt.length))}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,L.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-sm rounded-md border hover:bg-accent outline-none`,"data-testid":`gantt-conflict-cancel`,onClick:()=>Ft(null),children:w(`gantt.conflict.cancel`)}),(0,L.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-sm rounded-md bg-primary text-primary-foreground hover:opacity-90 outline-none`,"data-testid":`gantt-conflict-confirm`,onClick:Lt,children:w(`gantt.conflict.confirm`)})]})]})})]})}function R(e,t,n,r){return t.getTime()===e.getTime()?e.getTime()>=n.getTime()&&e.getTime()<r.getTime():e.getTime()<r.getTime()&&t.getTime()>n.getTime()}function it(e,t,n){let{assignee:r,effort:i,capacity:a=1,unassignedLabel:o=`Unassigned`}=n,s=e=>typeof a==`function`?a(e):a,c=e=>{let t=i?i(e):1;return Number.isFinite(t)&&t>0?t:0},l=new Map;for(let t of e){let e=r(t),n=e?String(e.key):`__unassigned__`,i=e?e.label:o,a=l.get(n);a||(a={key:n,label:i,items:[]},l.set(n,a)),a.items.push(t)}let u=[];for(let e of l.values()){let n=s(e.key),r=0,i=0,a=t.map(t=>{let a=0;for(let n of e.items)R(n.start,n.end,t.start,t.end)&&(a+=c(n));a>r&&(r=a);let o=a>n+1e-9;return o&&i++,{load:a,capacity:n,overloaded:o}});u.push({key:e.key,label:e.label,capacity:n,cells:a,peak:r,overloadedCount:i})}return u}var at={day:26,week:56,month:76,quarter:88,year:104},ot=48,st=34,ct=180;function lt(e,t,n){return t===`day`?String(e.getDate()):t===`week`?e.toLocaleDateString(n,{month:`numeric`,day:`numeric`}):t===`month`?e.toLocaleDateString(n,{month:`short`}):t===`year`?String(e.getFullYear()):`Q${Math.floor(e.getMonth()/3)+1}`}function ut({tasks:e,assignee:t,effort:n,capacity:r=1,viewMode:i=`day`,unassignedLabel:a=`Unassigned`,className:o}){let{t:s,language:c}=ze(),l=c||void 0,u=at[i],d=D.useMemo(()=>{if(!e.length)return[];let t=new Date(Math.min(...e.map(e=>e.start.getTime()))),n=new Date(Math.max(...e.map(e=>e.end.getTime()))),r=qe(t,i),a=Ye(qe(n,i),1,i),o=[],s=0;for(;r<a&&s++<4e3;){let e=Ye(r,1,i);o.push({date:new Date(r),col:{start:new Date(r),end:new Date(e)},label:lt(r,i,l)}),r=e}return o},[e,i,l]),f=D.useMemo(()=>it(e,d.map(e=>e.col),{assignee:t,effort:n,capacity:r,unassignedLabel:a}),[e,d,t,n,r,a]),p=D.useMemo(()=>{let e=0;for(let t of f)e=Math.max(e,t.peak,t.capacity);return e||1},[f]),m=d.length*u;return e.length?(0,L.jsx)(`div`,{className:o,"data-testid":`resource-workload`,style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`auto`},children:(0,L.jsxs)(`div`,{style:{display:`flex`,minWidth:ct+m},children:[(0,L.jsxs)(`div`,{style:{width:ct,flexShrink:0},children:[(0,L.jsx)(`div`,{style:{height:28,display:`flex`,alignItems:`center`,padding:`0 12px`,fontSize:12,fontWeight:600,borderBottom:`1px solid hsl(var(--border))`},children:s(`gantt.resource.header`)}),f.map(e=>(0,L.jsxs)(`div`,{"data-testid":`resource-row-${e.key}`,style:{height:ot,display:`flex`,flexDirection:`column`,justifyContent:`center`,padding:`0 12px`,borderBottom:`1px solid hsl(var(--border) / 0.5)`},children:[(0,L.jsx)(`span`,{style:{fontSize:13,fontWeight:500,whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},children:e.label}),(0,L.jsxs)(`span`,{"data-testid":`resource-peak-${e.key}`,"data-overloaded":e.overloadedCount>0?`true`:void 0,style:{fontSize:10,color:e.overloadedCount>0?`hsl(var(--destructive))`:`hsl(var(--muted-foreground))`},children:[s(`gantt.resource.peak`),`: `,Math.round(e.peak*100)/100,` / `,e.capacity,e.overloadedCount>0?` · ${e.overloadedCount} ${s(`gantt.resource.over`)}`:``]})]},e.key))]}),(0,L.jsxs)(`div`,{style:{flex:1},children:[(0,L.jsx)(`div`,{style:{display:`flex`,height:28,borderBottom:`1px solid hsl(var(--border))`},children:d.map((e,t)=>(0,L.jsx)(`div`,{style:{width:u,flexShrink:0,textAlign:`center`,fontSize:10,color:`hsl(var(--muted-foreground))`,borderLeft:`1px solid hsl(var(--border) / 0.4)`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:e.label},t))}),f.map(e=>{let t=st*(1-Math.min(e.capacity/p,1));return(0,L.jsxs)(`div`,{style:{position:`relative`,display:`flex`,height:ot,borderBottom:`1px solid hsl(var(--border) / 0.5)`},children:[(0,L.jsx)(`div`,{"aria-hidden":`true`,style:{position:`absolute`,left:0,right:0,top:(ot-st)/2+t,borderTop:`1px dashed hsl(var(--muted-foreground) / 0.6)`,pointerEvents:`none`,zIndex:1}}),e.cells.map((t,n)=>{let r=Math.max(t.load>0?2:0,st*Math.min(t.load/p,1));return(0,L.jsx)(`div`,{"data-testid":`resource-cell-${e.key}-${n}`,"data-load":t.load,"data-overloaded":t.overloaded?`true`:void 0,title:`${d[n]?.date.toLocaleDateString(l)} — ${Math.round(t.load*100)/100} / ${t.capacity}`,style:{width:u,flexShrink:0,position:`relative`,borderLeft:`1px solid hsl(var(--border) / 0.4)`,display:`flex`,alignItems:`flex-end`,justifyContent:`center`,paddingBottom:(ot-st)/2},children:t.load>0&&(0,L.jsx)(`div`,{style:{width:u-6,height:r,borderRadius:2,backgroundColor:t.overloaded?`hsl(var(--destructive))`:`hsl(var(--primary))`,opacity:t.overloaded?.9:.75}})},n)})]},e.key)})]})]})}):(0,L.jsx)(`div`,{className:o,"data-testid":`resource-workload`,children:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-40 text-sm text-muted-foreground`,children:s(`gantt.resource.empty`)})})}var dt={display:`flex`,flexWrap:`wrap`,alignItems:`center`,gap:8,padding:`8px 12px`,borderBottom:`1px solid hsl(var(--border))`,background:`hsl(var(--background))`,fontSize:13},z={display:`inline-flex`,alignItems:`center`,gap:6,height:30,padding:`0 10px`,borderRadius:6,border:`1px solid hsl(var(--border))`,background:`hsl(var(--background))`,color:`hsl(var(--foreground))`,cursor:`pointer`,whiteSpace:`nowrap`,lineHeight:`28px`},ft={position:`absolute`,top:`calc(100% + 4px)`,left:0,zIndex:50,minWidth:200,maxHeight:320,overflowY:`auto`,padding:4,borderRadius:8,border:`1px solid hsl(var(--border))`,background:`hsl(var(--popover, var(--background)))`,color:`hsl(var(--popover-foreground, var(--foreground)))`,boxShadow:`0 8px 24px rgba(0,0,0,0.18)`},B={display:`flex`,alignItems:`center`,gap:8,padding:`6px 8px`,borderRadius:6,cursor:`pointer`,userSelect:`none`};function pt({checked:e}){return(0,L.jsx)(`span`,{"aria-hidden":!0,style:{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:15,height:15,flex:`0 0 auto`,borderRadius:3,border:`1px solid ${e?`hsl(var(--primary))`:`hsl(var(--border))`}`,background:e?`hsl(var(--primary))`:`transparent`,color:`hsl(var(--primary-foreground, var(--background)))`,fontSize:11,lineHeight:1},children:e?`✓`:``})}function mt({filter:e,selected:t,onChange:n,labels:r}){let[i,a]=(0,D.useState)(!1),o=(0,D.useRef)(null);(0,D.useEffect)(()=>{if(!i)return;let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=new Set(t),c=t.length,l=e.options.length>0&&c===e.options.length,u=t=>{let r=new Set(s);r.has(t)?r.delete(t):r.add(t),r.size===e.options.length?n([]):n([...r])},d=()=>{n(c>0?[]:e.options.map(e=>e.value))},f=c===0?e.label:c===1?`${e.label}: ${e.options.find(e=>e.value===t[0])?.label??t[0]}`:`${e.label} · ${c}`;return(0,L.jsxs)(`div`,{ref:o,style:{position:`relative`},"data-testid":`quick-filter-${e.field}`,children:[(0,L.jsxs)(`button`,{type:`button`,style:{...z,borderColor:c>0?`hsl(var(--primary))`:`hsl(var(--border))`,color:c>0?`hsl(var(--primary))`:`hsl(var(--foreground))`},"aria-haspopup":`listbox`,"aria-expanded":i,"data-testid":`quick-filter-trigger-${e.field}`,onClick:()=>a(e=>!e),children:[(0,L.jsx)(`span`,{children:f}),(0,L.jsx)(`span`,{"aria-hidden":!0,style:{fontSize:10,opacity:.7},children:`▾`})]}),i&&(0,L.jsx)(`div`,{role:`listbox`,style:ft,"data-testid":`quick-filter-panel-${e.field}`,children:e.options.length===0?(0,L.jsx)(`div`,{style:{...B,cursor:`default`,opacity:.6},children:r.empty}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{role:`option`,"aria-selected":l,style:{...B,fontWeight:600},"data-testid":`quick-filter-all-${e.field}`,onClick:()=>d(),children:[(0,L.jsx)(pt,{checked:l}),(0,L.jsx)(`span`,{children:r.all})]}),(0,L.jsx)(`div`,{style:{height:1,background:`hsl(var(--border))`,margin:`2px 0`}}),e.options.map(t=>{let n=s.has(t.value);return(0,L.jsxs)(`div`,{role:`option`,"aria-selected":n,style:{...B,background:n?`hsl(var(--accent, var(--muted)))`:`transparent`},"data-testid":`quick-filter-option-${e.field}-${t.value}`,onClick:()=>u(t.value),children:[(0,L.jsx)(pt,{checked:n}),(0,L.jsx)(`span`,{children:t.label})]},t.value)})]})})]})}var ht=({filters:e,value:t,onChange:n,onClear:r,resultCount:i,totalCount:a,labels:o,className:s})=>{if(!e.length)return null;let c=o?.all??`All`,l=o?.empty??`No options`,u=o?.clear??`Clear`,d=e.some(e=>(t[e.field]?.length??0)>0);return(0,L.jsxs)(`div`,{style:dt,className:s,"data-testid":`quick-filter-bar`,children:[e.map(e=>(0,L.jsx)(mt,{filter:e,selected:t[e.field]??[],onChange:t=>n(e.field,t),labels:{all:c,empty:l}},e.field)),d&&(0,L.jsx)(`button`,{type:`button`,style:{...z,height:28,color:`hsl(var(--muted-foreground))`},"data-testid":`quick-filter-clear`,onClick:r,children:u}),o?.resultSummary&&i!=null&&a!=null&&(0,L.jsx)(`span`,{"data-testid":`quick-filter-summary`,style:{marginLeft:`auto`,color:`hsl(var(--muted-foreground))`},children:o.resultSummary(i,a)})]})};function gt(e){if(e==null)return;let t=String(e).toLowerCase().trim();if(t===`milestone`)return`milestone`;if(t===`group`||t===`folder`)return`group`;if(t===`summary`||t===`project`||t===`phase`)return`summary`;if(t===`task`)return`task`}var _t={fs:`fs`,ss:`ss`,ff:`ff`,sf:`sf`,finish_to_start:`fs`,start_to_start:`ss`,finish_to_finish:`ff`,start_to_finish:`sf`,end_to_start:`fs`,end_to_end:`ff`,start_to_end:`sf`};function vt(e){if(e==null||e===``)return[];if(typeof e==`string`)return e.split(`,`).map(e=>e.trim()).filter(Boolean);if(typeof e==`number`)return[e];if(!Array.isArray(e))return[];let t=[];for(let n of e)if(!(n==null||n===``))if(typeof n==`object`){let e=n.id??n._id??n.task??n.target;if(e==null||e===``)continue;let r=_t[String(n.type??``).toLowerCase().replace(/-/g,`_`)];t.push(r?{id:e,type:r}:{id:e})}else t.push(n);return t}function yt(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function bt(e){if(e){if(typeof e==`string`){let t=e.split(` `),n=t[0],r=t[1]?.toLowerCase()===`desc`?`desc`:`asc`;return{[n]:r}}if(Array.isArray(e))return e.reduce((e,t)=>(t.field&&t.order&&(e[t.field]=t.order),e),{})}}function V(e){let t=null;if(e.startDateField&&e.endDateField)return t={startDateField:e.startDateField,endDateField:e.endDateField,titleField:e.titleField||`name`,progressField:e.progressField,dependenciesField:e.dependenciesField||e.dependencyField,colorField:e.colorField,parentField:e.parentField,typeField:e.typeField,lockField:e.lockField,defaultCollapsedDepth:e.defaultCollapsedDepth,tooltipFields:e.tooltipFields,baselineStartField:e.baselineStartField,baselineEndField:e.baselineEndField,groupByField:e.groupByField,resourceView:e.resourceView,assigneeField:e.assigneeField,effortField:e.effortField,capacity:e.capacity,quickFilters:e.quickFilters,autoZoomToFilter:e.autoZoomToFilter,timeSegments:e.timeSegments},t;if(e.gantt&&(t=e.gantt),t){let e=u.safeParse(t);return e.success||console.warn(`[ObjectGantt] Invalid gantt configuration:`,e.error.format()),t}return null}var xt=({schema:e,dataSource:t,className:n,onTaskClick:r,onRowClick:o,...s})=>{let[c,u]=(0,D.useState)([]),[f,p]=(0,D.useState)(!0),[m,h]=(0,D.useState)(null),[g,_]=(0,D.useState)(null),{currency:v}=ee(),te=yt(e),y=(0,D.useMemo)(()=>te,[JSON.stringify(te)]),b=V(e),ne=y?.provider===`value`;(0,D.useEffect)(()=>{(async()=>{try{if(p(!0),s.data&&Array.isArray(s.data)){u(s.data),p(!1);return}if(ne&&y?.provider===`value`){u(y.items),p(!1);return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(y?.provider===`object`){let n=y.object,r=a(g?.fields);u(i(await t.find(n,{$filter:e.filter,$orderby:bt(e.sort),...r.length>0?{$expand:r}:{}})))}else y?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectGantt`),u([]));p(!1)}catch(e){h(e),p(!1)}})()},[y,t,ne,e.filter,e.sort,g]),(0,D.useEffect)(()=>{!ne&&t&&(async()=>{try{if(!t)return;let n=y?.provider===`object`?y.object:e.objectName;if(!n)return;_(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,ne,y]);let x=(0,D.useMemo)(()=>{if(!b||!c.length)return[];let{startDateField:e,endDateField:t,titleField:n,progressField:r,dependenciesField:i,colorField:a,parentField:o,typeField:s,lockField:l,tooltipFields:u,baselineStartField:f,baselineEndField:p}=b,m=g?.fields??{},h=(e,t)=>{if(!t)return;let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r},ee=e=>{let t=[h(e,n),e?.name,e?.title,e?.subject,e?.label,e?.account?.name,e?.opportunity?.name,e?.contact&&[e.contact.first_name,e.contact.last_name].filter(Boolean).join(` `),e?.id,e?._id];for(let e of t)if(e!=null&&String(e).trim()!==``)return String(e);return`Untitled`},_=(e,t)=>{if(t)return t;let n=m[e]??m[e.split(`.`)[0]];return n?.label?n.label:S(e)},te=(e,t)=>{if(e==null||e===``)return`—`;let n=m[t]??m[t.split(`.`)[0]],r=n?.type,i=n?.options;if(Array.isArray(i)&&i.length){let t=i.find(t=>String(t.value)===String(e));if(t)return t.label}switch(r){case`date`:return he(e);case`datetime`:return ye(e);case`number`:case`integer`:case`float`:case`decimal`:return de(Number(e));case`currency`:return ae(Number(e),d(n,v));case`percent`:return be(Number(e));case`boolean`:case`checkbox`:return e?`Yes`:`No`;default:if(Array.isArray(e)){let t=e.map(e=>{if(e==null)return``;if(typeof e==`object`){let t=e;return String(t.name??t.label??t.title??t.id??``)}return String(e)}).filter(Boolean);return t.length?t.join(`, `):`—`}if(typeof e==`object`){let t=e;return String(t.name??t.label??t.title??t.id??`—`)}return String(e)}},y=e=>{if(!u||!u.length)return;let t=[];for(let n of u){let r=typeof n==`string`?n:n?.field;if(!r)continue;let i=typeof n==`object`?n.label:void 0;t.push({label:_(r,i),value:te(h(e,r),r)})}return t.length?t:void 0};return c.map((n,c)=>{let u=n[e],d=n[t],m=f?n[f]:void 0,h=p?n[p]:void 0,g=m?new Date(m):void 0,_=h?new Date(h):void 0,v=ee(n),te=r?n[r]:0,b=i?n[i]:[],ne=a?n[a]:void 0;if(!ne){let e=n.status??n.state??n.priority??n.severity;if(e!=null&&e!==``){let t=ge(void 0,e);t&&(ne=pe(t))}}return{id:n.id||n._id||`task-${c}`,title:v,start:u?new Date(u):new Date,end:d?new Date(d):new Date,progress:Math.min(100,Math.max(0,te||0)),dependencies:vt(b),parent:o?n[o]??null:void 0,type:s?gt(n[s]):void 0,locked:l?!!n[l]:void 0,color:ne,baselineStart:g&&!isNaN(g.getTime())?g:void 0,baselineEnd:_&&!isNaN(_.getTime())?_:void 0,fields:y(n),data:n}}).filter(e=>!isNaN(e.start.getTime())&&!isNaN(e.end.getTime()))},[c,b,g]),re=(0,D.useMemo)(()=>{let e=b?.groupByField;if(!e)return;let t=g?.fields??{},n=(e,t)=>{if(!t)return;let n=e;for(let e of t.split(`.`)){if(n==null)return;n=n[e]}return n},r=n=>{let r=(t[e]??t[e.split(`.`)[0]])?.options;if(Array.isArray(r)&&r.length){let e=r.find(e=>String(e.value)===String(n));if(e)return e.label}if(typeof n==`object`&&n){let e=n;return String(e.name??e.label??e.title??e.id??n)}return String(n)};return t=>{let i=n(t.data,e);return i==null||i===``?null:{key:typeof i==`object`&&i?String(i.id??i._id??r(i)):i,label:r(i)}}},[b?.groupByField,g]),oe=(0,D.useMemo)(()=>{let e=b?.assigneeField;if(!e)return;let t=g?.fields??{},n=(e,t)=>{if(!t)return;let n=e;for(let e of t.split(`.`)){if(n==null)return;n=n[e]}return n},r=n=>{let r=(t[e]??t[e.split(`.`)[0]])?.options;if(Array.isArray(r)&&r.length){let e=r.find(e=>String(e.value)===String(n));if(e)return e.label}if(typeof n==`object`&&n){let e=n;return String(e.name??e.label??e.title??e.id??n)}return String(n)};return t=>{let i=n(t.data,e);return i==null||i===``?null:{key:typeof i==`object`&&i?String(i.id??i._id??r(i)):i,label:r(i)}}},[b?.assigneeField,g]),le=(0,D.useMemo)(()=>{let e=b?.effortField;if(e)return t=>{let n=t.data?.[e],r=Number(n);return Number.isFinite(r)&&r>0?r:1}},[b?.effortField]),ue=(0,D.useMemo)(()=>{let t=e.skipWeekends,n=e.holidays;if(!(!t&&(!n||n.length===0)))return{skipWeekends:!!t,holidays:n&&n.length?new Set(n):void 0}},[e]),fe=(0,D.useMemo)(()=>Pe(b?.timeSegments),[b?.timeSegments]),ve=(0,D.useCallback)((e,t)=>{if(!e||!t)return null;let n=e;for(let e of t.split(`.`)){if(n==null)return null;n=n[e]}if(n==null||n===``)return null;if(typeof n==`object`){let e=n;return String(e.id??e._id??e.value??e.name??``)}return String(n)},[]),xe=b?.quickFilters,[T,Ce]=(0,D.useState)({});(0,D.useEffect)(()=>{if(!xe?.length||!t||typeof t.find!=`function`)return;let e=g?.fields??{},n=!1;return(async()=>{let r={};for(let n of xe){if(n.options)continue;let a=e[n.field]??e[n.field.split(`.`)[0]],o=a?.type;if(o!==`lookup`&&o!==`master_detail`)continue;let s=a?.reference_to??a?.referenceTo;if(s)try{let e=i(await t.find(s,{$top:1e3}));r[n.field]=e.map(e=>({value:String(e.id??e._id??e.value??``),label:String(e.name??e.label??e.title??e.id??e._id??``)}))}catch(e){console.warn(`[ObjectGantt] Failed to load quick-filter options for "${n.field}":`,e)}}n||Ce(e=>({...e,...r}))})(),()=>{n=!0}},[JSON.stringify(xe),t,g]);let Te=(0,D.useMemo)(()=>{if(!xe?.length)return[];let e=g?.fields??{};return xe.map(t=>{let n=e[t.field]??e[t.field.split(`.`)[0]],r=t.label??n?.label??S(t.field),i=[];if(t.options?.length)i=t.options.map(e=>typeof e==`object`?{value:String(e.value),label:String(e.label??e.value)}:{value:String(e),label:String(e)});else if(Array.isArray(n?.options)&&n.options.length)i=n.options.map(e=>({value:String(e.value??e),label:String(e.label??e.value??e)}));else if(T[t.field]?.length)i=T[t.field];else{let e=new Map;for(let n of c){let r=ve(n,t.field);if(r!=null&&!e.has(r)){let i=n;for(let e of t.field.split(`.`))i=i?.[e];let a=i&&typeof i==`object`?String(i.name??i.label??i.title??r):r;e.set(r,a)}}i=[...e.entries()].map(([e,t])=>({value:e,label:t}))}return{field:t.field,label:r,options:i}})},[xe,g,T,c,ve]),[Ee,De]=(0,D.useState)({}),O=(0,D.useCallback)((e,t)=>{De(n=>({...n,[e]:t}))},[]),Oe=(0,D.useCallback)(()=>De({}),[]),k=(0,D.useMemo)(()=>{let e=Object.entries(Ee).filter(([,e])=>e.length>0);return e.length?x.filter(t=>e.every(([e,n])=>{let r=ve(t.data,e);return r!=null&&n.includes(r)})):x},[x,Ee,ve]),A=(0,D.useMemo)(()=>{if(b?.autoZoomToFilter!==!1||!x.length)return null;let e=x[0].start.getTime(),t=x[0].end.getTime();for(let n of x)e=Math.min(e,n.start.getTime()),t=Math.max(t,n.end.getTime());return{start:new Date(e),end:new Date(t)}},[x,b?.autoZoomToFilter]),j=e.navigation??{mode:`drawer`,width:`min(960px, 60vw)`},M=j.mode===`drawer`||j.mode===`modal`||j.mode===`split`||j.mode===`popover`,N=l({navigation:j,objectName:e.objectName,onRowClick:M?void 0:o}),ke=(0,D.useCallback)(async(n,r)=>{if(!b)return;let i=y?.provider===`object`?y.object:e.objectName;if(!i||!t||typeof t.update!=`function`)return;let{startDateField:a,endDateField:o,titleField:s,progressField:l}=b,d={};if(r.start instanceof Date&&(d[a]=r.start.toISOString()),r.end instanceof Date&&(d[o]=r.end.toISOString()),typeof r.title==`string`&&s&&(d[s]=r.title),typeof r.progress==`number`&&l&&(d[l]=r.progress),Object.keys(d).length===0)return;let f=n.data?.id??n.data?._id??n.id;if(f==null)return;let p=c;u(e=>e.map(e=>String(e.id??e._id)===String(f)?{...e,...d}:e));try{await t.update(i,String(f),d)}catch(e){console.error(`[ObjectGantt] Failed to persist task update:`,e),u(p)}},[b,y,t,e.objectName,c]),Ae=(e,t)=>{let n=t.some(e=>typeof e==`object`&&e.type&&e.type!==`fs`);return!n&&typeof e==`string`?t.map(e=>String(typeof e==`object`?e.id:e)).join(`,`):n?t.map(e=>typeof e==`object`?e.type&&e.type!==`fs`?{id:e.id,type:e.type}:e.id:e):t.map(e=>typeof e==`object`?e.id:e)},je=(0,D.useCallback)(async(n,r,i)=>{let a=b?.dependenciesField;if(!a)return;let o=y?.provider===`object`?y.object:e.objectName;if(!o||!t||typeof t.update!=`function`)return;let s=Ae(r,i),l=c;u(e=>e.map(e=>String(e.id??e._id)===String(n)?{...e,[a]:s}:e));try{await t.update(o,String(n),{[a]:s})}catch(e){console.error(`[ObjectGantt] Failed to persist dependency:`,e),u(l)}},[b,y,t,e.objectName,c]),Me=(0,D.useCallback)(async(e,t,n=`fs`)=>{let r=e.data?.id??e.data?._id??e.id,i=t.data?.id??t.data?._id??t.id;if(r==null||i==null)return;let a=b?.dependenciesField;if(!a)return;let o=c.find(e=>String(e.id??e._id)===String(i))?.[a],s=vt(o),l=e=>String(typeof e==`object`?e.id:e),u=s.find(e=>l(e)===String(r)),d=u&&typeof u==`object`?u.type??`fs`:`fs`;if(u&&d===n)return;let f=n===`fs`?r:{id:r,type:n};await je(i,o,u?s.map(e=>l(e)===String(r)?f:e):[...s,f])},[b,c,je]),Ne=(0,D.useCallback)(async(e,t)=>{let n=e.data?.id??e.data?._id??e.id,r=t.data?.id??t.data?._id??t.id;if(n==null||r==null)return;let i=b?.dependenciesField;if(!i)return;let a=c.find(e=>String(e.id??e._id)===String(r))?.[i],o=vt(a),s=e=>String(typeof e==`object`?e.id:e),l=o.filter(e=>s(e)!==String(n));l.length!==o.length&&await je(r,a,l)},[b,c,je]),[P,F]=(0,D.useState)(null),[I,Fe]=(0,D.useState)(!1),Ie=(0,D.useCallback)(e=>{F(e)},[]),Le=(0,D.useCallback)(async()=>{if(!P)return;let n=y?.provider===`object`?y.object:e.objectName;if(!n||!t?.delete){F(null);return}let r=P.data?.id??P.data?._id??P.id;if(r==null){F(null);return}Fe(!0);let i=c;u(e=>e.filter(e=>String(e.id??e._id)!==String(r)));try{await t.delete(n,String(r)),F(null)}catch(e){console.error(`[ObjectGantt] Failed to delete:`,e),u(i),F(null)}finally{Fe(!1)}},[P,y,t,e.objectName,c]);return f?(0,L.jsx)(`div`,{className:n,children:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,L.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading Gantt chart...`})})}):m?(0,L.jsx)(`div`,{className:n,children:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,L.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,m.message]})})}):b?(0,L.jsxs)(`div`,{className:n,children:[Te.length>0&&(0,L.jsx)(ht,{filters:Te,value:Ee,onChange:O,onClear:Oe,resultCount:k.length,totalCount:x.length,labels:{all:`全部`,clear:`清除筛选`,empty:`无可选项`,resultSummary:(e,t)=>`显示 ${e} / ${t} 项任务`}}),(0,L.jsx)(`div`,{className:`h-[calc(100vh-200px)] min-h-[600px]`,children:b?.resourceView&&oe?(0,L.jsx)(ut,{tasks:k,assignee:oe,effort:le,capacity:b?.capacity??1,viewMode:e.viewMode||`day`}):(0,L.jsx)(rt,{tasks:k,startDate:A?.start,endDate:A?.end,onTaskClick:e=>{N.handleClick(e.data),r?.(e.data)},onTaskUpdate:ke,onTaskDelete:Ie,onDependencyCreate:b?.dependenciesField?Me:void 0,onDependencyDelete:b?.dependenciesField?Ne:void 0,markers:e.markers,autoSchedule:!!b?.dependenciesField,rescheduleOnConflict:!!b?.dependenciesField,criticalPathDefault:!!e.criticalPath,workingCalendar:ue,shiftSegments:fe,showBaselines:e.showBaselines!==!1,readOnly:!!e.readOnly,mobileReadOnly:e.mobileReadOnly!==!1,persistLayoutKey:e.persistLayout===!1?void 0:`${e.objectName||(y?.provider===`object`?y.object:``)||`gantt`}:${e.viewName||`default`}`,groupBy:re,defaultCollapsedDepth:b?.defaultCollapsedDepth,inlineEdit:!0})}),N.isOverlay&&N.isOpen&&N.selectedRecord&&(()=>{let n=y?.provider===`object`?y.object:e.objectName,r=N.selectedRecord,i=r.id??r._id;if(!n||i==null)return null;let a=b?.titleField?String(r[b.titleField]??`Task Details`):`Task Details`;return(0,L.jsx)(we,{open:!0,onClose:N.close,title:a,record:r,objectName:n,recordId:i,dataSource:t,objectSchema:g,width:N.width,fullPageHref:E(n,i)??void 0,onFieldSave:async(e,r)=>{t?.update&&(await t.update(n,String(i),{[e]:r}),u(t=>t.map(t=>String(t.id??t._id)===String(i)?{...t,[e]:r}:t)))},onDelete:async()=>{t?.delete&&(await t.delete(n,String(i)),u(e=>e.filter(e=>String(e.id??e._id)!==String(i))))}})})(),(0,L.jsx)(se,{open:!!P,onOpenChange:e=>{!e&&!I&&F(null)},children:(0,L.jsxs)(C,{children:[(0,L.jsxs)(w,{children:[(0,L.jsx)(Se,{children:`Delete this task?`}),(0,L.jsx)(ce,{children:P?(0,L.jsxs)(L.Fragment,{children:[`"`,P.title,`" will be permanently removed. This action cannot be undone.`]}):null})]}),(0,L.jsxs)(ie,{children:[(0,L.jsx)(me,{disabled:I,children:`Cancel`}),(0,L.jsx)(_e,{onClick:e=>{e.preventDefault(),Le()},disabled:I,"data-testid":`gantt-delete-confirm`,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:I?`Deleting…`:`Delete`})]})]})})]}):(0,L.jsx)(`div`,{className:n,children:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,L.jsx)(`div`,{className:`text-muted-foreground`,children:`Gantt configuration required. Please specify startDateField, endDateField, and titleField.`})})})},St=t({GanttView:()=>rt,ObjectGantt:()=>xt,ObjectGanttRenderer:()=>Ct,QuickFilterBar:()=>ht,ResourceWorkload:()=>ut,bandAt:()=>Ie,computeWorkload:()=>it,normalizeDependencies:()=>vt,normalizeShiftSegments:()=>Pe,normalizeTaskType:()=>gt,parseHHMM:()=>I,shiftDayStart:()=>Fe}),Ct=({schema:e})=>{let{dataSource:t}=o()||{};return(0,L.jsx)(xt,{schema:e,dataSource:t})};c.register(`object-gantt`,Ct,{namespace:`plugin-gantt`,label:`Object Gantt`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]}),c.register(`gantt`,Ct,{namespace:`view`,label:`Gantt View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]});export{St as t};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,g as r,m as i,t as a}from"./vendor-react-ClIa1CJA.js";import{Et as o,I as s,K as c,Q as l,Tt as u,V as d,Z as f,_t as p,i as m,kt as h,q as g,z as _}from"./framework-h98DIM1k.js";import{$r as v,Ac as y,As as b,Bs as ee,Fc as te,Fo as ne,Gn as re,Gr as x,Gt as S,I as ie,Is as ae,J as oe,Jn as se,Jt as C,Kn as w,Kt as T,Lr as E,M as D,Mc as ce,Mi as le,N as ue,Ni as de,Ns as O,O as fe,Oc as k,Or as pe,Pi as me,Ps as he,Qs as ge,Sc as _e,Un as ve,Ur as ye,V as be,Vs as xe,Wn as Se,Xt as A,Yo as j,Yt as Ce,Zo as we,_ as Te,_t as Ee,a as De,an as Oe,ar as ke,bc as M,d as Ae,di as je,dn as Me,dt as Ne,f as Pe,fn as Fe,fo as Ie,ft as N,gt as Le,h as Re,hn as ze,hs as Be,ht as Ve,i as He,in as Ue,ji as We,mi as Ge,mt as Ke,ni as qe,o as Je,on as Ye,ot as Xe,pn as Ze,pt as Qe,qn as P,qr as F,qt as $e,rn as et,rt as I,sn as tt,tt as nt,u as rt,vs as it,xn as at,xr as L,xs as ot,za as st,zr as ct,zs as lt}from"./ui-components-C9egdVxV.js";var R=e(n(),1),ut={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},z=[`xs`,`sm`,`md`,`lg`,`xl`,`2xl`];function B(e){for(let t=z.length-1;t>=0;t--){let n=z[t];if(e>=ut[n])return n}return`xs`}function V(){let[e,t]=(0,R.useState)(()=>typeof window<`u`?window.innerWidth:1024);(0,R.useEffect)(()=>{if(typeof window>`u`)return;let e,n=()=>{clearTimeout(e),e=setTimeout(()=>{t(window.innerWidth)},100)};return window.addEventListener(`resize`,n),()=>{clearTimeout(e),window.removeEventListener(`resize`,n)}},[]);let n=B(e),r=z.indexOf(n);return{breakpoint:n,width:e,isMobile:r<z.indexOf(`md`),isTablet:r>=z.indexOf(`md`)&&r<z.indexOf(`lg`),isDesktop:r>=z.indexOf(`lg`),isAbove:t=>e>=ut[t],isBelow:t=>e<ut[t]}}function dt(e){let{onRefresh:t,threshold:n=80,enabled:r=!0}=e,i=(0,R.useRef)(null),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(0),l=(0,R.useRef)(0),u=(0,R.useCallback)(e=>{if(!r||a)return;let t=i.current;t&&t.scrollTop===0&&(l.current=e.touches[0].clientY)},[r,a]),d=(0,R.useCallback)(e=>{if(!r||a||!l.current)return;let t=e.touches[0].clientY-l.current;t>0&&c(Math.min(t,n*1.5))},[r,a,n]),f=(0,R.useCallback)(async()=>{if(!r||a)return;let e=s;if(c(0),l.current=0,e>=n){o(!0);try{await t()}finally{o(!1)}}},[r,a,s,n,t]);return(0,R.useEffect)(()=>{let e=i.current;if(!(!e||!r))return e.addEventListener(`touchstart`,u,{passive:!0}),e.addEventListener(`touchmove`,d,{passive:!0}),e.addEventListener(`touchend`,f,{passive:!0}),()=>{e.removeEventListener(`touchstart`,u),e.removeEventListener(`touchmove`,d),e.removeEventListener(`touchend`,f)}},[u,d,f,r]),{ref:i,isRefreshing:a,pullDistance:s}}var H=a(),U=(0,R.createContext)(null);U.displayName=`MobileContext`;function W({pwa:e,offline:t,children:n}){let r=V(),i=(0,R.useMemo)(()=>({...r,pwa:e,offline:t}),[r,e,t]);return(0,H.jsx)(U.Provider,{value:i,children:n})}var G={red:`bg-red-100`,green:`bg-green-100`,blue:`bg-blue-100`,yellow:`bg-yellow-100`,orange:`bg-orange-100`,purple:`bg-purple-100`,pink:`bg-pink-100`,gray:`bg-gray-100`,grey:`bg-gray-100`,indigo:`bg-indigo-100`,teal:`bg-teal-100`,cyan:`bg-cyan-100`,amber:`bg-amber-100`,lime:`bg-lime-100`,emerald:`bg-emerald-100`,rose:`bg-rose-100`,sky:`bg-sky-100`,violet:`bg-violet-100`,fuchsia:`bg-fuchsia-100`,slate:`bg-slate-100`,zinc:`bg-zinc-100`,stone:`bg-stone-100`,neutral:`bg-neutral-100`};function K(e){return e.startsWith(`bg-`)?e:G[e.toLowerCase().trim()]}function ft(e){return(0,R.useCallback)(t=>{if(!e?.field||!e.colors)return;let n=String(t[e.field]??``),r=e.colors[n];if(r)return K(r)},[e?.field,e?.colors])}function pt(e){if(e==null||e===``)return``;if(Array.isArray(e))return e.map(e=>pt(e)).join(`|`);if(typeof e==`object`){let t=e.id??e._id??e.pk??e.value;if(t!=null&&t!==``)return String(t);let n=e.name??e.label??e.title;if(n!=null&&n!==``)return String(n);try{return JSON.stringify(e)}catch{return``}}return String(e)}function q(e,t){return pt(e[t])}function mt(e,t,n){if(e==null||e===``)return`(empty)`;if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}if(Array.isArray(e))return e.map(e=>{if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}return mt(e,t)}).join(`, `)||`(empty)`;if(typeof e==`object`){let t=e.name??e.label??e.title??e.display_name??e.displayName??e.fullName??e.full_name;if(t!=null&&t!==``)return String(t);let n=e.id??e._id??e.pk;return n!=null&&n!==``?String(n):`(empty)`}return String(e)}function ht(e,t){return t.map(({field:t,type:n})=>{if(n===`count_distinct`){let r=new Set;for(let n of e){let e=n[t];e!=null&&e!==``&&r.add(e)}return{field:t,type:n,value:r.size}}if(n===`count`)return{field:t,type:n,value:e.length};let r=e.map(e=>Number(e[t])).filter(e=>Number.isFinite(e)),i;switch(n){case`sum`:i=r.reduce((e,t)=>e+t,0);break;case`avg`:i=r.length>0?r.reduce((e,t)=>e+t,0)/r.length:0;break;case`min`:i=r.length>0?Math.min(...r):0;break;case`max`:i=r.length>0?Math.max(...r):0;break;default:i=0}return{field:t,type:n,value:i}})}function gt(e,t,n){let r=e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`});return n===`desc`?-r:r}function _t(e,t,n,r){let i=e?.fields,a=!!(i&&i.length>0),[o,s]=(0,R.useState)({});return{groups:(0,R.useMemo)(()=>{if(!a||!i)return[];let e=(t,a,s)=>{if(a>=i.length)return[];let c=i[a],l=new Map,u=[];for(let e of t){let t=q(e,c.field);l.has(t)||(l.set(t,{label:mt(e[c.field],c.field,r),rows:[]}),u.push(t)),l.get(t).rows.push(e)}let d=c.order??`asc`;return u.sort((e,t)=>gt(l.get(e)?.label??e,l.get(t)?.label??t,d)),u.map(t=>{let r=l.get(t),u=s?`${s}__${a}:${t}`:`${a}:${t}`,d=!!c.collapsed,f=u in o?o[u]:d,p=n&&n.length>0?ht(r.rows,n):[],m=a+1<i.length?e(r.rows,a+1,u):[];return{key:u,label:r.label,field:c.field,depth:a,rows:r.rows,collapsed:f,aggregations:p,subgroups:m}})};return e(t,0,``)},[t,i,a,o,n,r]),isGrouped:a,toggleGroup:(0,R.useCallback)(e=>{s(t=>{let n=e.split(`__`).pop()||``,r=/^(\d+):/.exec(n),a=r?Number(r[1]):0,o=!!i?.[a]?.collapsed;return{...t,[e]:t[e]===void 0?!o:!t[e]}})},[i])}}var vt=({groupKey:e,label:t,count:n,collapsed:r,aggregations:i,fieldLabel:a,labelColorClass:o,onToggle:s,children:c})=>{let l=o?k(`inline-flex items-center rounded-md border px-2 py-0.5 text-xs font-medium`,o):`inline-flex items-center rounded-md bg-muted px-2 py-0.5 text-xs font-medium text-foreground`;return(0,H.jsxs)(`div`,{"data-testid":`group-row-${e}`,className:`group/grouprow`,children:[a&&(0,H.jsx)(`div`,{className:`px-1 pb-1 text-[11px] font-medium text-muted-foreground tracking-wide group-label-caption`,children:a}),(0,H.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-1 py-1 text-sm text-left rounded-md hover:bg-muted/40 transition-colors`,onClick:()=>s(e),"aria-expanded":!r,children:[r?(0,H.jsx)(lt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,H.jsx)(xe,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,H.jsx)(`span`,{className:k(l,`group-label`),children:t}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums group-count`,children:n}),i&&i.length>0&&(0,H.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground group-aggregations`,children:i.map(e=>(0,H.jsxs)(`span`,{className:`mr-2`,children:[e.type,`: `,Number.isInteger(e.value)?e.value:e.value.toFixed(2)]},`${e.field}-${e.type}`))})]}),!r&&(0,H.jsx)(`div`,{className:`mt-1 ml-1.5 pl-3 border-l border-border/60`,children:c})]})};function yt(e){return typeof e==`string`?{type:e}:e}function bt(e,t){if(t.length===0)return null;switch(e){case`count`:return t.length;case`sum`:return t.reduce((e,t)=>e+t,0);case`avg`:return t.reduce((e,t)=>e+t,0)/t.length;case`min`:return Math.min(...t);case`max`:return Math.max(...t);default:return null}}function xt(e,t,n,r){if(t===null)return``;let i={count:`Count`,sum:`Sum`,avg:`Avg`,min:`Min`,max:`Max`}[e]||e,a=n?.type,o;if(e!==`count`&&a===`currency`){let e=y(n,r),i=n?.precision??n?.scale??0;try{o=e?new Intl.NumberFormat(void 0,{style:`currency`,currency:e,minimumFractionDigits:i,maximumFractionDigits:i}).format(t):new Intl.NumberFormat(void 0,{minimumFractionDigits:i,maximumFractionDigits:i}).format(t)}catch{o=t.toLocaleString()}}else if(e!==`count`&&a===`percent`){let e=n?.precision??0;o=`${(t>-1&&t<1?t*100:t).toFixed(e)}%`}else o=e===`avg`?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString();return`${i}: ${o}`}function St(e,t,n){let{currency:r}=ce();return(0,R.useMemo)(()=>{let i=new Map;if(!e||e.length===0||t.length===0)return{summaries:i,hasSummary:!1};for(let a of e){if(!a.summary)continue;let e=yt(a.summary),o=e.field||a.field,s=[];for(let e of t){let t=e[o];if(t!=null&&typeof t==`number`&&!isNaN(t))s.push(t);else if(t!=null&&typeof t==`string`){let e=parseFloat(t);isNaN(e)||s.push(e)}}let c;if(e.type===`count`){let e=t.filter(e=>e[o]!=null&&e[o]!==``).length;c=e>0?e:null}else c=bt(e.type,s);let l=n?.[o],u={type:a.type??l?.type,currency:a.currency??l?.currency,defaultCurrency:a.defaultCurrency??l?.defaultCurrency,precision:a.precision??l?.precision,scale:a.scale??l?.scale};i.set(a.field,{field:a.field,value:c,label:xt(e.type,c,u,r)})}return{summaries:i,hasSummary:i.size>0}},[e,t,n,r])}function Ct(e){let t=e.userActions?.edit===!1,n=e.userActions?.delete===!1;return{canEdit:!!((e.operationsUpdate||e.wantEditAction)&&e.hasOnEdit)&&!t,canDelete:!!((e.operationsDelete||e.wantDeleteAction)&&e.hasOnDelete)&&!n}}var J={"grid.openMenu":`Open menu`,"grid.edit":`Edit`,"grid.delete":`Delete`};function wt(){try{let{t:e}=m();return t=>{let n=e(t);return n===t?J[t]??t:n}}catch{return e=>J[e]??e}}function Tt(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var Et=({def:e,row:t,onActionDef:n})=>{let r={...t&&typeof t==`object`?t:{},record:t},i=g(c(e.visible),r),a=c(e.disabled),o=g(typeof a==`string`?a:void 0,r),s=typeof a==`string`?o:a===!0;return e.visible&&!i?null:(0,H.jsx)(ze,{disabled:s,onClick:()=>{s||n?.(e,t)},"data-testid":`row-action-${e.name}`,className:e.variant===`danger`?`text-destructive focus:text-destructive`:void 0,children:e.label??Tt(e.name)})};function Dt(e){switch(e){case`danger`:return`destructive`;case`secondary`:return`secondary`;case`ghost`:return`ghost`;case`link`:return`link`;default:return`default`}}var Ot=({def:e,row:t,onActionDef:n})=>{let r=g(c(e.visible),{...t&&typeof t==`object`?t:{},record:t});return e.visible&&!r?null:(0,H.jsx)(L,{variant:Dt(e.variant),size:`sm`,className:`h-8`,"data-testid":`row-action-inline-${e.name}`,onClick:r=>{r.stopPropagation(),n?.(e,t)},children:e.label??Tt(e.name)})},kt=({row:e,rowActions:t,rowActionDefs:n,canEdit:r,canDelete:i,onEdit:a,onDelete:o,onAction:s,onActionDef:c})=>{let l=wt(),u=(n??[]).filter(e=>e.variant===`primary`),d=(n??[]).filter(e=>e.variant!==`primary`),f=!!(r&&a||i&&o||d.length>0||(t?.length??0)>0);return(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[u.map(t=>(0,H.jsx)(Ot,{def:t,row:e,onActionDef:c},t.name)),f&&(0,H.jsxs)(Fe,{children:[(0,H.jsx)(at,{asChild:!0,children:(0,H.jsxs)(L,{variant:`ghost`,size:`icon`,className:`h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0`,"data-testid":`row-action-trigger`,children:[(0,H.jsx)(j,{className:`h-4 w-4`}),(0,H.jsx)(`span`,{className:`sr-only`,children:l(`grid.openMenu`)})]})}),(0,H.jsxs)(Ze,{align:`end`,onClick:e=>e.stopPropagation(),children:[r&&a&&(0,H.jsxs)(ze,{onClick:()=>a(e),children:[(0,H.jsx)(je,{className:`mr-2 h-4 w-4`}),l(`grid.edit`)]}),i&&o&&(0,H.jsxs)(ze,{onClick:()=>o(e),children:[(0,H.jsx)(F,{className:`mr-2 h-4 w-4`}),l(`grid.delete`)]}),d.map(t=>(0,H.jsx)(Et,{def:t,row:e,onActionDef:c},t.name)),t?.map(t=>(0,H.jsx)(ze,{onClick:()=>s?.(t,e),"data-testid":`row-action-${t}`,children:Tt(t)},t))]})]})]})},At=({selectedRows:e,actions:t,actionDefs:n,onAction:r,onActionDef:i,onClearSelection:a,pageSize:o,totalMatching:s,allMatchingSelected:c,onSelectAllMatching:l})=>{let u=Array.isArray(n)&&n.length>0,d=Array.isArray(t)&&t.length>0;return!u&&!d||e.length===0?null:(0,H.jsxs)(`div`,{className:`border-t border-primary/30 px-4 py-2 flex flex-col gap-1.5 text-xs bg-primary/10 text-foreground shrink-0 shadow-sm motion-safe:animate-in motion-safe:slide-in-from-bottom-2 motion-safe:fade-in-0 motion-safe:duration-200`,role:`region`,"aria-label":`Bulk actions`,"data-testid":`bulk-actions-bar`,children:[(!c&&typeof s==`number`&&typeof o==`number`&&o>0&&e.length>=o&&s>o||c)&&(0,H.jsx)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,"data-testid":`bulk-cross-page-banner`,children:c?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Ge,{className:`h-3 w-3 text-primary shrink-0`}),(0,H.jsxs)(`span`,{children:[`All `,s,` matching records are selected.`]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[`All `,o,` on this page are selected.`]}),(0,H.jsxs)(`button`,{type:`button`,className:`font-medium text-primary underline-offset-2 hover:underline`,onClick:l,"data-testid":`bulk-select-all-matching`,children:[`Select all `,s,` matching`]})]})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Ge,{className:`h-3.5 w-3.5 text-primary shrink-0`}),(0,H.jsx)(`span`,{className:`font-medium tabular-nums`,children:(0,H.jsx)(`span`,{className:`inline-block motion-safe:animate-in motion-safe:zoom-in-90 motion-safe:duration-150`,children:c?`${s} items selected (all matches)`:`${e.length} ${e.length===1?`item`:`items`} selected`},c?`all-${s}`:e.length)}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 ml-3`,children:[u&&n.map(t=>{let n=t.variant===`danger`||t.operation===`delete`,r=t.icon?I(t.icon):null;return(0,H.jsxs)(L,{variant:n?`destructive`:`outline`,size:`sm`,className:`h-7 px-2.5 text-xs gap-1.5`,onClick:()=>i?.(t,e),"data-testid":`bulk-action-${t.name}`,children:[r?(0,H.jsx)(nt,{name:r,className:`h-3 w-3`}):n?(0,H.jsx)(F,{className:`h-3 w-3`}):null,t.label??Tt(t.name)]},t.name)}),!u&&d&&t.map(t=>{let n=String(t).toLowerCase(),i=n.includes(`delete`)||n.includes(`remove`)||n.includes(`destroy`),a=i?F:null;return(0,H.jsxs)(L,{variant:i?`destructive`:`outline`,size:`sm`,className:`h-7 px-2.5 text-xs gap-1.5`,onClick:()=>r?.(t,e),"data-testid":`bulk-action-${t}`,children:[a&&(0,H.jsx)(a,{className:`h-3 w-3`}),Tt(t)]},t)})]}),(0,H.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs ml-auto gap-1`,onClick:a,children:[(0,H.jsx)(pe,{className:`h-3 w-3`}),`Clear`]})]})]})};function jt({resource:e,dataSource:t}){let[n,r]=(0,R.useState)({total:0,done:0,failed:0,inFlight:!1}),[i,a]=(0,R.useState)(null),o=(0,R.useRef)([]),s=(0,R.useRef)(null),c=(0,R.useCallback)(()=>{r({total:0,done:0,failed:0,inFlight:!1}),a(null),o.current=[],s.current=null},[]);return{run:(0,R.useCallback)(async(n,i,c)=>{let l=i.length,u=Math.max(1,n.batchSize??200),d=[],f=0,m=0;a(null),r({total:l,done:0,failed:0,inFlight:!0});let h=()=>({...n.patch??{},...c}),g=[];if(n.operation===`update`){let e=Object.keys(h());for(let t of i){let n=String(t.id??``);if(!n)continue;let r={};for(let n of e)r[n]=t[n];g.push({id:n,prev:r})}}for(let a=0;a<i.length;a+=u){let o=i.slice(a,a+u),s=[];for(let e=0;e<o.length;e+=1){let t=o[e].id==null?``:String(o[e].id);t?s.push(t):(m+=1,d.push({id:`index_${a+e}`,error:`Missing record id`}))}if(s.length===0){r({total:l,done:f,failed:m,inFlight:!0});continue}let c=s.length>=2,g,_=`bulk`;n.operation===`update`&&typeof t.bulkUpdate==`function`?(g=n=>t.bulkUpdate(e,n,h()),_=`bulk update`):n.operation===`delete`&&typeof t.bulkDelete==`function`&&(g=n=>t.bulkDelete(e,n),_=`bulk delete`);let v=await p({ids:s,originalSize:o.length,offset:a,allowBulk:c,label:_},{bulkCall:g,perRow:r=>{switch(n.operation){case`delete`:return t.delete(e,r);case`update`:return t.update(e,r,h());case`custom`:return Promise.resolve();default:return Promise.reject(Error(`Unknown operation: ${n.operation}`))}}});f+=v.succeeded,m+=v.failed,d.push(...v.errors),r({total:l,done:f,failed:m,inFlight:!0})}let _={total:l,succeeded:f,failed:m,errors:d},v=new Set(d.map(e=>e.id));return o.current=g.filter(e=>!v.has(e.id)),s.current={def:n,rows:i,params:c},r({total:l,done:f,failed:m,inFlight:!1}),a(_),f>0&&D.invalidate(e),_},[e,t]),undo:(0,R.useCallback)(async()=>{let n=o.current;if(!n.length)return null;let i=n.length,s=[],c=0,l=0;a(null),r({total:i,done:0,failed:0,inFlight:!0}),(await Promise.allSettled(n.map(n=>t.update(e,n.id,n.prev)))).forEach((e,t)=>{e.status===`fulfilled`?c+=1:(l+=1,s.push({id:n[t].id,error:e.reason instanceof Error?e.reason.message:String(e.reason)}))});let u={total:i,succeeded:c,failed:l,errors:s};return o.current=[],r({total:i,done:c,failed:l,inFlight:!1}),a(u),u},[e,t]),retry:(0,R.useCallback)(async n=>{let r=s.current;if(!r||!r.rows.find(e=>String(e.id??``)===n))return!1;let i={...r.def.patch??{},...r.params};try{switch(r.def.operation){case`delete`:await t.delete(e,n);break;case`update`:await t.update(e,n,i);break;case`custom`:return!0;default:return!1}return a(e=>{if(!e)return e;let t=e.errors.filter(e=>e.id!==n);return{...e,errors:t,succeeded:e.succeeded+1,failed:Math.max(0,e.failed-1)}}),!0}catch{return!1}},[e,t]),progress:n,result:i,reset:c}}var Mt=({def:e,rows:t,resource:n,dataSource:r,open:i,onClose:a,labelKey:o=`name`})=>{let s=e?.params??[],c=(0,R.useMemo)(()=>{let e={};for(let t of s)t.default!==void 0&&(e[t.name]=t.default);return e},[e?.name]),[l,u]=(0,R.useState)(`params`),[d,f]=(0,R.useState)(c),[p,m]=(0,R.useState)({}),{run:h,undo:g,retry:_,progress:v,result:y,reset:ee}=jt({resource:n,dataSource:r}),[te,ne]=(0,R.useState)(null),[S,ie]=(0,R.useState)(!1),[ae,oe]=(0,R.useState)(null);(0,R.useEffect)(()=>{i&&(ee(),f(c),oe(null),ie(!1),ne(null),u(s.length===0?`confirm`:`params`))},[i,e?.name,c,s.length,ee]),(0,R.useEffect)(()=>{if(!i||typeof r.find!=`function`)return;let e=s.filter(e=>e.type===`lookup`&&e.object&&!p[e.name]);if(e.length===0)return;let t=!1;return(async()=>{let n={};for(let t of e)try{let e=await r.find(t.object,{$top:200}),i=Array.isArray(e)?e:e?.data??[];n[t.name]=i.map(e=>({value:String(e.id??e._id??``),label:String(e.name??e.full_name??e.email??e.id??`(unnamed)`)})).filter(e=>e.value)}catch{n[t.name]=[]}t||m(e=>({...e,...n}))})(),()=>{t=!0}},[i,e?.name]);let C=(0,R.useMemo)(()=>{for(let e of s)if(e.required){let t=d[e.name];if(t==null||t===``)return!1}return!0},[s,d]),T=e?.maxRecords??1/0,E=t.length>T,D=(0,R.useCallback)(async()=>{e&&(u(`running`),await h(e,t,d),u(`result`))},[e,t,d,h]),ce=(0,R.useCallback)(()=>{if(!y?.errors?.length)return;let t=[`record_id,error_message`,...y.errors.map(e=>`${e.id},"${e.error.replace(/"/g,`""`)}"`)].join(`
|
|
2
|
+
`),n=new Blob([t],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`bulk_errors_${e?.name??`action`}_${Date.now()}.csv`,i.click(),URL.revokeObjectURL(r)},[y,e?.name]),le=!!e&&e.operation===`update`&&!!y&&y.succeeded>0&&ae===null,ue=(0,R.useCallback)(async()=>{ie(!0);try{await g()&&oe(Date.now())}finally{ie(!1)}},[g]),de=(0,R.useCallback)(async e=>{ne(e);try{await _(e)}finally{ne(null)}},[_]);if(!e)return null;let O=e.label??e.name,fe=t.slice(0,5),k=Math.max(0,t.length-fe.length);return(0,H.jsx)(ve,{open:i,onOpenChange:e=>{e||a(y)},children:(0,H.jsxs)(Se,{className:`max-w-md`,children:[(0,H.jsxs)(P,{children:[(0,H.jsxs)(se,{className:`flex items-center gap-2`,children:[l===`running`&&(0,H.jsx)(st,{className:`h-4 w-4 animate-spin`}),O]}),l===`confirm`&&(0,H.jsx)(re,{children:e.confirmText??`This will apply to ${t.length} record${t.length===1?``:`s`}.`})]}),l===`params`&&(0,H.jsx)(`div`,{className:`space-y-3`,children:s.map(e=>(0,H.jsx)(Pt,{param:e,value:d[e.name],lookupOptions:p[e.name],onChange:t=>f(n=>({...n,[e.name]:t}))},e.name))}),l===`confirm`&&(0,H.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[E&&(0,H.jsxs)(`div`,{className:`rounded-md bg-destructive/10 text-destructive px-3 py-2 flex items-start gap-2`,children:[(0,H.jsx)(x,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,H.jsxs)(`div`,{children:[`Selection (`,t.length,`) exceeds the action limit (`,T,`). Reduce the selection to proceed.`]})]}),(0,H.jsxs)(`div`,{className:`text-muted-foreground`,children:[`Affected records (`,t.length,`):`]}),(0,H.jsx)(A,{className:`max-h-32 rounded border bg-muted/30 p-2`,children:(0,H.jsxs)(`ul`,{className:`text-xs space-y-1`,children:[fe.map((e,t)=>(0,H.jsxs)(`li`,{className:`truncate`,children:[`• `,String(e[o]??e.id??`Row ${t+1}`)]},String(e.id??t))),k>0&&(0,H.jsxs)(`li`,{className:`text-muted-foreground`,children:[`… and `,k,` more`]})]})}),Object.keys(d).length>0&&(0,H.jsx)(`div`,{className:`rounded border bg-muted/30 p-2 text-xs space-y-0.5`,children:Object.entries(d).map(([e,t])=>(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),` `,Nt(t)]},e))})]}),l===`running`&&(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(et,{value:v.total?(v.done+v.failed)/v.total*100:0}),(0,H.jsxs)(`div`,{className:`text-xs text-muted-foreground text-center`,children:[v.done+v.failed,` / `,v.total,` processed`,v.failed>0&&` · ${v.failed} failed`]})]}),l===`result`&&y&&(0,H.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y.failed===0?(0,H.jsx)(b,{className:`h-5 w-5 text-emerald-500`}):(0,H.jsx)(x,{className:`h-5 w-5 text-amber-500`}),(0,H.jsxs)(`span`,{children:[ae===null?``:`Undone — `,`Succeeded `,y.succeeded,` / `,y.total,y.failed>0&&` · Failed ${y.failed}`]})]}),y.errors.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(A,{className:`max-h-48 rounded border bg-destructive/5 p-2`,"data-testid":`bulk-error-inspector`,children:(0,H.jsx)(`ul`,{className:`text-xs space-y-1.5`,children:y.errors.map(t=>(0,H.jsxs)(`li`,{className:`flex items-start gap-2`,"data-testid":`bulk-error-row-${t.id}`,children:[(0,H.jsx)(ot,{className:`h-3 w-3 mt-0.5 shrink-0 text-destructive`}),(0,H.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,H.jsxs)(`div`,{className:`truncate`,children:[(0,H.jsxs)(`span`,{className:`text-muted-foreground`,children:[t.id,`:`]}),` `,t.error]})}),e.operation!==`custom`&&(0,H.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-5 px-1.5 text-[10px]`,onClick:()=>de(t.id),disabled:te===t.id,"data-testid":`bulk-error-retry-${t.id}`,children:te===t.id?`…`:`Retry`})]},t.id))})}),(0,H.jsx)(L,{variant:`outline`,size:`sm`,onClick:ce,children:`Download error CSV`})]})]}),(0,H.jsxs)(w,{children:[l===`params`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(L,{variant:`ghost`,onClick:()=>a(),children:`Cancel`}),(0,H.jsx)(L,{onClick:()=>u(`confirm`),disabled:!C,children:`Next`})]}),l===`confirm`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(L,{variant:`ghost`,onClick:()=>s.length?u(`params`):a(),children:s.length?`Back`:`Cancel`}),(0,H.jsx)(L,{variant:e.variant===`danger`?`destructive`:`default`,onClick:D,disabled:E,children:e.confirmLabel??`Run`})]}),l===`running`&&(0,H.jsx)(L,{variant:`ghost`,disabled:!0,children:`Running…`}),l===`result`&&(0,H.jsxs)(H.Fragment,{children:[le&&(0,H.jsx)(L,{variant:`outline`,onClick:ue,disabled:S,"data-testid":`bulk-undo-button`,children:S?`Undoing…`:`Undo`}),(0,H.jsx)(L,{onClick:()=>a(y),children:`Done`})]})]})]})})};function Nt(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`Yes`:`No`:String(e)}var Pt=({param:e,value:t,onChange:n,lookupOptions:r})=>{let i=`bulk-param-${e.name}`,a=(0,H.jsxs)(Me,{htmlFor:i,className:`text-xs`,children:[e.label??e.name,e.required&&(0,H.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),o=null;switch(e.type){case`boolean`:o=(0,H.jsx)(Ee,{id:i,checked:!!t,onCheckedChange:n});break;case`textarea`:o=(0,H.jsx)(Xe,{id:i,value:t??``,onChange:e=>n(e.target.value),placeholder:e.placeholder});break;case`select`:{let r=e.options??[];o=(0,H.jsxs)(S,{value:t==null?``:String(t),onValueChange:n,children:[(0,H.jsx)(C,{id:i,children:(0,H.jsx)(Ce,{placeholder:e.placeholder??`Select…`})}),(0,H.jsx)(T,{children:r.map(e=>(0,H.jsx)($e,{value:String(e.value),children:e.label},String(e.value)))})]});break}case`lookup`:{let a=r??[];o=(0,H.jsxs)(S,{value:t??``,onValueChange:n,children:[(0,H.jsx)(C,{id:i,children:(0,H.jsx)(Ce,{placeholder:a.length===0?`Loading…`:e.placeholder??`Select…`})}),(0,H.jsx)(T,{children:a.map(e=>(0,H.jsx)($e,{value:e.value,children:e.label},e.value))})]});break}case`number`:o=(0,H.jsx)(tt,{id:i,type:`number`,value:t??``,onChange:e=>n(e.target.value===``?void 0:Number(e.target.value)),placeholder:e.placeholder});break;default:o=(0,H.jsx)(tt,{id:i,type:`text`,value:t??``,onChange:e=>n(e.target.value),placeholder:e.placeholder})}return(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`div`,{className:`flex items-center justify-between`,children:a}),o,e.help&&(0,H.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.help})]})},Ft=({testId:e,onActivate:t,children:n})=>(0,H.jsx)(`span`,{role:`link`,tabIndex:0,"data-testid":e,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer truncate block max-w-full`,onClick:e=>{e.stopPropagation(),t()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),t())},children:n}),It={"grid.actions":`Actions`,"grid.edit":`Edit`,"grid.delete":`Delete`,"grid.export":`Export`,"grid.exportAs":`Export as {{format}}`,"grid.loading":`Loading grid...`,"grid.errorLoading":`Error loading grid`,"grid.pullToRefresh":`Pull to refresh`,"grid.refreshing":`Refreshing…`,"grid.openRecord":`Open record`,"grid.empty":`Empty`,"grid.yes":`Yes`,"grid.no":`No`,"grid.systemFields":`System`,"table.rowsPerPage":`Rows per page`,"table.pageInfo":`Page {{current}} of {{total}}`};function Lt(){try{let e=m();return e.t(`grid.actions`)===`grid.actions`?{t:(e,t)=>{let n=It[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}:{t:e.t}}catch{return{t:(e,t)=>{let n=It[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}}}function Rt(e){if(e!=null)return typeof e==`string`?e:void 0}function zt(e){return e.data?Array.isArray(e.data)?{provider:`value`,items:e.data}:e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function Bt(e){if(!(!e||e.length===0))return typeof e[0]==`object`&&e[0],e}var Vt=({schema:e,dataSource:t,onEdit:n,onDelete:r,onBulkDelete:i,onRowSelect:a,onRowClick:c,onCellChange:l,onRowSave:p,onBatchSave:m,onAddRecord:h,...g})=>{let[b,ne]=(0,R.useState)([]),[re,x]=(0,R.useState)(!0),[S,se]=(0,R.useState)(null),{currency:C}=ce(),{t:w}=Lt(),{fieldLabel:T,translateOptions:D}=te(),[O,k]=(0,R.useState)(null),[pe,_e]=(0,R.useState)(!1),[ve,xe]=(0,R.useState)(0),[Se,A]=(0,R.useState)(!1),[j,Ce]=(0,R.useState)(!1),Ee=fe({dataSource:t}),[M,je]=(0,R.useState)(e.rowHeight??`compact`),[Me,Ne]=(0,R.useState)([]),[Fe,N]=(0,R.useState)(!1),[Le,ze]=(0,R.useState)(void 0),[Ve,We]=(0,R.useState)(null),[Ke,Xe]=(0,R.useState)([]),Ze=R.useRef(null),[Qe,P]=(0,R.useState)(1),[F,$e]=(0,R.useState)(e.pagination?.pageSize??e.pageSize??10);R.useEffect(()=>{e.rowHeight&&e.rowHeight!==M&&je(e.rowHeight)},[e.rowHeight]);let et=R.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[I,tt]=(0,R.useState)(()=>{let t=e.columnState;if(t&&typeof t==`object`)return t;try{let e=localStorage.getItem(et);return e?JSON.parse(e):{}}catch{return{}}}),nt=R.useMemo(()=>JSON.stringify(e.columnState??null),[e.columnState]);R.useEffect(()=>{let t=e.columnState;t&&typeof t==`object`&&tt(t)},[nt]);let it=(0,R.useCallback)(e=>{tt(e);try{localStorage.setItem(et,JSON.stringify(e))}catch(e){console.warn(`Failed to persist column state:`,e)}let t=g.onColumnStateChange;if(typeof t==`function`)try{t(e)}catch(e){console.warn(`onColumnStateChange threw:`,e)}},[et,g]),{ref:at,isRefreshing:ot,pullDistance:st}=dt({onRefresh:(0,R.useCallback)(async()=>{xe(e=>e+1)},[]),enabled:!!t&&!!e.objectName});(0,R.useEffect)(()=>{let e=()=>_e(window.innerWidth<768);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let ct=g.data,ut=f(e.bind),z=zt(e),B=R.useMemo(()=>ct&&Array.isArray(ct)?{provider:`value`,items:ct}:ut&&Array.isArray(ut)?{provider:`value`,items:ut}:z,[JSON.stringify(z),ut,ct]),V=B?.provider===`value`,U=g.manualPagination===!0&&typeof g.rowCount==`number`&&typeof g.onPageChange==`function`,W=B?.provider===`object`&&B&&`object`in B?B.object:e.objectName,G=e.fields,K=e.columns,pt=e.filter,q=e.sort,mt=e.pagination,ht=e.pageSize,[gt,yt]=(0,R.useState)(1),[bt,xt]=(0,R.useState)(e.pagination?.pageSize??e.pageSize??50);(0,R.useEffect)(()=>{V&&B?.provider===`value`&&(ne(e=>{let t=B.items;return JSON.stringify(e)===JSON.stringify(t)?e:t}),x(!1))},[V,B]),(0,R.useEffect)(()=>{if(!V||!W||!t)return;let e=!1;return(async()=>{try{if(typeof t.getObjectSchema!=`function`)return;let n=await t.getObjectSchema(W);e||k(n)}catch(e){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${W}):`,e)}})(),()=>{e=!0}},[V,W,t]),(0,R.useEffect)(()=>{if(V)return;let n=!1;return(async()=>{x(!0),se(null);try{let r=null,i=Bt(K)||G;if(W&&t)if(typeof t.getObjectSchema==`function`){let e=await t.getObjectSchema(W);if(n)return;r=e}else r={name:W,fields:{}};else if(i&&W)r={name:W,fields:{}};else if(W)throw Error(`DataSource required`);else throw Error(`Object name required for data fetching`);if(n||k(r),t&&W){let i={$select:(()=>{let e=e=>e.map(e=>typeof e==`string`?e:e?.name||e?.field).includes(`id`)?e:[`id`,...e];if(G)return e(G);if(K&&Array.isArray(K))return e(K.map(e=>typeof e==`string`?e:e.field))})(),$top:bt,$skip:(gt-1)*bt};pt&&Array.isArray(pt)?i.$filter=pt:e.defaultFilters&&(i.$filter=e.defaultFilters),q?typeof q==`string`?i.$orderby=q:Array.isArray(q)&&(i.$orderby=q.map(e=>`${e.field} ${e.order}`).join(`, `)):e.defaultSort&&(i.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);let a=o(r?.fields,K??G);a.length>0&&(i.$expand=a);let s=await t.find(W,i);if(n)return;ne(s.data||[]);let c=s.total;ze(typeof c==`number`?c:void 0),Ze.current={...i},N(!1)}}catch(e){n||se(e)}finally{n||x(!1)}})(),()=>{n=!0}},[W,G,K,pt,q,mt,ht,gt,bt,t,V,B,ve]),R.useEffect(()=>{yt(1)},[W,pt,q]);let J=_({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:c}),{execute:wt,updateContext:Et}=s();R.useEffect(()=>(Et({selectedRecords:Me}),()=>{Et({selectedRecords:[]})}),[Me,Et]);let Dt=ft(e.rowColor),Ot=(0,R.useCallback)(t=>{let n=e.conditionalFormatting;if(!(!n||n.length===0))for(let e of n){let n=!1,r=(`condition`in e?e.condition:void 0)||(`expression`in e?e.expression:void 0)||void 0;if(r)n=u(r,t);else if(`field`in e&&`operator`in e&&e.field&&e.operator){let r=e,i=t[r.field];switch(r.operator){case`equals`:n=i===r.value;break;case`not_equals`:n=i!==r.value;break;case`contains`:n=typeof i==`string`&&typeof r.value==`string`&&i.includes(r.value);break;case`greater_than`:n=typeof i==`number`&&typeof r.value==`number`&&i>r.value;break;case`less_than`:n=typeof i==`number`&&typeof r.value==`number`&&i<r.value;break;case`in`:n=Array.isArray(r.value)&&r.value.includes(i);break}}if(n){let t={};return`style`in e&&e.style&&Object.assign(t,e.style),`backgroundColor`in e&&e.backgroundColor&&(t.backgroundColor=e.backgroundColor),`textColor`in e&&e.textColor&&(t.color=e.textColor),`borderColor`in e&&e.borderColor&&(t.borderColor=e.borderColor),t}}},[e.conditionalFormatting]),jt=R.useMemo(()=>{let t=e.grouping;if(!t?.fields?.length)return;let n=new Map;for(let r of t.fields){let t=r.field,i=O?.fields?.[t],a=Bt(e.columns)?.find?.(e=>typeof e==`object`&&e?.field===t),o=a?.type||i?.type,s=a?.options||i?.options,c=new Map;if(Array.isArray(s)&&s.length>0){let n=e.objectName?D(e.objectName,t,s):s;for(let e of n)if(e&&e.value!==void 0&&e.value!==null){let t=e.label;c.set(String(e.value),String(t??e.value))}}n.set(t,{type:o||void 0,options:c.size>0?c:void 0})}return(e,t)=>{let r=n.get(e);if(r){if(r.options){let e=r.options.get(String(t));if(e!==void 0)return e}if(r.type===`boolean`||typeof t==`boolean`){if(t===!0||t===`true`)return w(`grid.booleanTrue`,`Yes`);if(t===!1||t===`false`)return w(`grid.booleanFalse`,`No`)}}}},[e.grouping,e.columns,e.objectName,O,D,w]),{groups:Nt,isGrouped:Pt,toggleGroup:It}=_t(e.grouping,b,e.aggregations,jt),Vt=R.useMemo(()=>JSON.stringify(e.grouping??null),[e.grouping]);R.useEffect(()=>{P(1)},[Vt,F,ve]);let{summaries:Ht,hasSummary:Ut}=St(R.useMemo(()=>{let t=Bt(e.columns);if(t&&t.length>0&&typeof t[0]==`object`)return t},[e.columns]),b,O?.fields),Y=(0,R.useCallback)(()=>{let t=e=>e&&{text:(0,H.jsx)(ye,{className:`h-3.5 w-3.5`}),number:(0,H.jsx)(Ie,{className:`h-3.5 w-3.5`}),currency:(0,H.jsx)(Ie,{className:`h-3.5 w-3.5`}),percent:(0,H.jsx)(Ie,{className:`h-3.5 w-3.5`}),date:(0,H.jsx)(ge,{className:`h-3.5 w-3.5`}),datetime:(0,H.jsx)(Be,{className:`h-3.5 w-3.5`}),boolean:(0,H.jsx)(Ge,{className:`h-3.5 w-3.5`}),user:(0,H.jsx)(E,{className:`h-3.5 w-3.5`}),select:(0,H.jsx)(qe,{className:`h-3.5 w-3.5`})}[e]||(0,H.jsx)(ye,{className:`h-3.5 w-3.5`}),n=e=>{if(e.type)return e.type;let t=e.field.toLowerCase();if([`completed`,`is_completed`,`done`,`active`,`enabled`,`archived`].some(e=>t===e||t===`is_${e}`))return`boolean`;if([`created_time`,`modified_time`,`updated_time`,`created_at`,`updated_at`,`modified_at`,`last_login`,`logged_at`].some(e=>t===e||t.endsWith(`_${e}`)))return`datetime`;if([`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`].some(e=>t.includes(e))){if(b.length>0){let t=b.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&!isNaN(Date.parse(t)))return`date`}return`date`}if([`probability`,`percent`,`percentage`,`completion`,`progress`,`rate`].some(e=>t.includes(e))&&b.length>0&&typeof b.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`percent`;if([`status`,`priority`,`category`,`stage`,`type`,`severity`,`level`].some(e=>t.includes(e))&&b.length>0){let t=new Set(b.map(t=>t[e.field]).filter(Boolean));if(t.size>0&&t.size<=10)return`select`}if([`assignee`,`owner`,`author`,`reporter`,`creator`,`user`].some(e=>t.includes(e)))return`user`;if([`amount`,`price`,`total`,`revenue`,`cost`,`budget`,`salary`].some(e=>t.includes(e))&&b.length>0&&typeof b.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`currency`;if(b.length>0){let t=b.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return`datetime`}return null},r=Bt(K);if(r){if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let i=r[0];if(`accessorKey`in i)return r.map(r=>{if(r.cell)return r;let i=n({field:r.accessorKey,label:r.header,type:r.type});if(!i)return r;let a=Pe(i),o={name:r.accessorKey,type:i};return i===`select`&&(o.options=Array.from(new Set(b.map(e=>e[r.accessorKey]).filter(Boolean))).map(e=>({value:e,label:Re(String(e))}))),r.appearance!=null&&(o.appearance=r.appearance),{...r,type:r.type??i,...e.showColumnTypeIcons&&{headerIcon:t(i)},cell:e=>(0,H.jsx)(a,{value:e,field:o})}});if(`field`in i)return r.filter(e=>e?.field&&typeof e.field==`string`&&!e.hidden).map((r,i)=>{let a=Rt(r.label)||Rt(O?.fields?.[r.field]?.label)||r.field.charAt(0).toUpperCase()+r.field.slice(1).replace(/_/g,` `),o=e.objectName?T(e.objectName,r.field,a):a,s,c=O?.fields?.[r.field],l=r.type||c?.type||n({field:r.field})||null,u=r.format??c?.format,d=l?Te({type:l,format:u}):null,f=d?Pe(d):null,p={name:r.field,type:d||`text`};c&&(c.label&&(p.label=c.label),c.currency&&(p.currency=c.currency),c.precision!==void 0&&(p.precision=c.precision),c.format&&(p.format=c.format),c.options&&(p.options=D(e.objectName,r.field,c.options))),d===`select`&&!p.options&&(p.options=Array.from(new Set(b.map(e=>e[r.field]).filter(Boolean))).map(e=>({value:e,label:Re(String(e))}))),r.options&&(p.options=D(e.objectName,r.field,r.options));let m=r.appearance??c?.appearance;m!=null&&(p.appearance=m);let h=i===0&&!r.link&&!r.action,g=r.link||h;s=r.link&&r.action||h&&r.action||g?(e,t)=>(0,H.jsx)(Ft,{testId:h?`primary-field-link`:`link-cell`,onActivate:()=>J.handleClick(t),children:f?(0,H.jsx)(f,{value:e,field:p}):e!=null&&e!==``?String(e):(0,H.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):r.action?(e,t)=>(0,H.jsx)(L,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,"data-testid":`action-cell`,onClick:n=>{n.stopPropagation(),wt({type:r.action,params:{record:t,field:r.field,value:e}})},children:Tt(r.action)}):f?e=>(0,H.jsx)(f,{value:e,field:p}):e=>e!=null&&e!==``?(0,H.jsx)(`span`,{children:String(e)}):(0,H.jsx)(oe,{});let _=r.prefix;if(_?.field){let e=s,t=_.type===`badge`?Pe(`select`):null;s=(n,r)=>{let i=r[_.field];return(0,H.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[i!=null&&i!==``?t?(0,H.jsx)(t,{value:i,field:{name:_.field,type:`select`}}):(0,H.jsx)(`span`,{className:`text-muted-foreground text-xs mr-1.5`,children:String(i)}):null,e(n,r)]})}}let v=[`number`,`currency`,`percent`],y=d||r.type,ee=r.align||(y&&v.includes(y)?`right`:void 0),te=i===0||r.essential===!0;return{header:o,accessorKey:r.field,...l&&{type:l},...e.showColumnTypeIcons&&{headerIcon:t(d)},...!te&&{className:`hidden sm:table-cell`},...r.width&&{width:r.width},...ee&&{align:ee},sortable:r.sortable!==!1,...r.resizable!==void 0&&{resizable:r.resizable},...r.wrap!==void 0&&{wrap:r.wrap},...s&&{cell:s},...r.pinned&&{pinned:r.pinned}}})}return r.filter(e=>typeof e==`string`&&e.trim().length>0).map((r,i)=>{let a=O?.fields?.[r],o=a?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),s=e.objectName?T(e.objectName,r,o):o,c=a?.type||n({field:r})||null,l=c?Pe(c):null,u={name:r,type:c||`text`};a&&(a.label&&(u.label=a.label),a.currency&&(u.currency=a.currency),a.precision!==void 0&&(u.precision=a.precision),a.format&&(u.format=a.format),a.options&&(u.options=D(e.objectName,r,a.options))),c===`select`&&!u.options&&(u.options=Array.from(new Set(b.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:Re(String(e))}))),(c===`select`||c===`status`)&&a?.appearance!=null&&(u.appearance=a.appearance);let d=c&&[`number`,`currency`,`percent`].includes(c)?`right`:void 0,f=i===0,p;return f&&l?p=(e,t)=>(0,H.jsx)(Ft,{testId:`primary-field-link`,onActivate:()=>J.handleClick(t),children:(0,H.jsx)(l,{value:e,field:u})}):f?p=(e,t)=>(0,H.jsx)(Ft,{testId:`primary-field-link`,onActivate:()=>J.handleClick(t),children:e!=null&&e!==``?String(e):(0,H.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):l&&(p=e=>(0,H.jsx)(l,{value:e,field:u})),{header:s,accessorKey:r,...c&&{type:c},...e.showColumnTypeIcons&&c&&{headerIcon:t(c)},...d&&{align:d},...p&&{cell:p},sortable:a?.sortable!==!1}})}if(V){let r=B?.provider===`value`?B.items:[];if(r.length>0)return(G||Object.keys(r[0])).map(r=>{let i=O?.fields?.[r],a=i?.type||n({field:r})||null,o=a?Pe(a):null,s=i?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),c={name:r,type:a||`text`};i&&(i.label&&(c.label=i.label),i.currency&&(c.currency=i.currency),i.precision!==void 0&&(c.precision=i.precision),i.format&&(c.format=i.format),i.options&&(c.options=D(e.objectName,r,i.options))),a===`select`&&!c.options&&(c.options=Array.from(new Set(b.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:Re(String(e))}))),(a===`select`||a===`status`)&&i?.appearance!=null&&(c.appearance=i.appearance);let l=a&&[`number`,`currency`,`percent`].includes(a)?`right`:void 0;return{header:s,accessorKey:r,...a&&{type:a},...e.showColumnTypeIcons&&a&&{headerIcon:t(a)},...l&&{align:l},...o&&{cell:e=>(0,H.jsx)(o,{value:e,field:c})},sortable:i?.sortable!==!1}})}if(!O)return[];let i=[],a=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),o=O?.compactLayout,s=Object.keys(O.fields||{}),c;if(G)c=G;else if(o?.length)c=o.filter(e=>O.fields?.[e]);else{let e=s.filter(e=>{let t=O.fields?.[e];return!(!t||t.hidden||t.readonly&&a.has(e))});c=[...e.filter(e=>!a.has(e)),...e.filter(e=>a.has(e))]}return c.forEach(t=>{let n=O.fields?.[t];if(!n||n.permissions&&n.permissions.read===!1)return;let r=Pe(n.type),a=[`number`,`currency`,`percent`],o=n.options?{...n,options:D(e.objectName,t,n.options)}:n;i.push({header:e.objectName?T(e.objectName,t,n.label||t):n.label||t,accessorKey:t,...n.type&&{type:n.type},...a.includes(n.type)&&{align:`right`},cell:e=>(0,H.jsx)(r,{value:e,field:o}),sortable:n.sortable!==!1})}),i},[O,G,K,B,V,J.handleClick,wt,b,T,D,e.objectName]),Wt=(0,R.useCallback)(t=>{let n=e.exportOptions,r=n?.maxRecords||0,i=n?.includeHeaders!==!1,a=n?.fileNamePrefix||e.objectName||`export`;if((t===`csv`||t===`xlsx`||t===`json`)&&Ee.isSupported&&e.objectName&&!V&&n?.streaming!==!1){let n=Y().filter(e=>e.accessorKey!==`_actions`).map(e=>e.accessorKey).filter(Boolean);A(!1),Ce(!0),Ee.start(e.objectName,{format:t===`json`?`json`:t,fields:n.length?n:void 0,includeHeaders:i,limit:r>0?r:void 0});return}let o=r>0?b.slice(0,r):b,s=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)},c=e=>{let t=e==null?``:String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
3
|
+
`)||t.includes(`\r`)?`"${t.replace(/"/g,`""`)}"`:t};if(t===`csv`){let e=Y().filter(e=>e.accessorKey!==`_actions`),t=e.map(e=>e.accessorKey),n=e.map(e=>e.header),r=[];i&&r.push(n.join(`,`)),o.forEach(e=>{r.push(t.map(t=>c(e[t])).join(`,`))}),s(new Blob([r.join(`
|
|
4
|
+
`)],{type:`text/csv;charset=utf-8;`}),`${a}.csv`)}else t===`json`&&s(new Blob([JSON.stringify(o,null,2)],{type:`application/json`}),`${a}.json`);A(!1)},[b,e.exportOptions,e.objectName,Y,Ee,V]);if(S)return(0,H.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,H.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:w(`grid.errorLoading`)}),(0,H.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:S.message})]});if(re&&b.length===0)return pe?(0,H.jsx)(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>(0,H.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card animate-pulse`,children:[(0,H.jsx)(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-3`}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,H.jsx)(`div`,{className:`h-4 bg-muted rounded w-1/4`}),(0,H.jsx)(`div`,{className:`h-5 bg-muted rounded-full w-20`})]}),(0,H.jsx)(`div`,{className:`h-3 bg-muted rounded w-1/3`})]},e))}):(0,H.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,H.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-foreground`}),(0,H.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:w(`grid.loading`)})]});let Gt=[...Y()];if(I.widths&&(Gt=Gt.map(e=>{let t=I.widths?.[e.accessorKey];return t?{...e,size:t}:e})),I.order&&I.order.length>0){let e=new Map(I.order.map((e,t)=>[e,t]));Gt.sort((t,n)=>(e.get(t.accessorKey)??1/0)-(e.get(n.accessorKey)??1/0))}let X=(`operations`in e?e.operations:void 0)??{update:!!n,delete:!!r},Z=Array.isArray(e.rowActions)?e.rowActions:[],Kt=Array.isArray(e.rowActionDefs)?e.rowActionDefs:[],qt=Z.includes(`edit`),Jt=Z.includes(`delete`),Yt=Z.filter(e=>e!==`edit`&&e!==`delete`),{canEdit:Xt,canDelete:Zt}=Ct({operationsUpdate:X?.update,operationsDelete:X?.delete,wantEditAction:qt,wantDeleteAction:Jt,hasOnEdit:!!n,hasOnDelete:!!r,userActions:O?.userActions}),Qt=!!(X&&(X.update||X.delete)),$t=Yt.length>0||Kt.length>0||qt||Jt,en=Qt||$t?[...Gt,{header:w(`grid.actions`),accessorKey:`_actions`,cell:(e,t)=>(0,H.jsx)(kt,{row:t,rowActions:Yt,rowActionDefs:Kt,canEdit:Xt,canDelete:Zt,onEdit:n,onDelete:r,onAction:(e,t)=>wt({type:e,params:{record:t}}),onActionDef:(e,t)=>{let{params:n,...r}=e,i={...r};Array.isArray(n)&&n.length>0&&(i.actionParams=n),i.params={_rowRecord:t},wt(i)}}),sortable:!1}]:Gt,tn=en.filter(e=>e.pinned===`left`),nn=en.filter(e=>e.pinned===`right`),rn=en.filter(e=>!e.pinned),an=tn.length>0||nn.length>0,on=`sticky right-0 z-10 bg-background border-l border-border`,sn=M===`compact`?`px-3 py-1 h-9 text-[13px] leading-tight`:M===`short`?`px-3 py-1 h-9 text-[13px] leading-normal`:M===`tall`?`px-3 py-2.5 h-14 text-sm`:M===`extra_tall`?`px-3 py-3.5 h-16 text-sm leading-relaxed`:`px-3 py-1.5 h-11 text-[13px] leading-normal`,cn=e=>({...e,className:[`px-3`,e.className].filter(Boolean).join(` `),cellClassName:[sn,e.cellClassName].filter(Boolean).join(` `)}),ln=an?[...tn.map(cn),...rn.map(cn),...nn.map(e=>({...cn(e),className:[`px-3`,e.className,on].filter(Boolean).join(` `),cellClassName:[sn,e.cellClassName,on].filter(Boolean).join(` `)}))]:en.map(cn),un=an?tn.length:e.frozenColumns??1,dn=e.batchActions??e.bulkActions,fn=Array.isArray(e.bulkActionDefs)?e.bulkActionDefs:[],pn=dn&&dn.length>0?dn:Zt&&i&&fn.length===0?[`delete`]:[],mn=pn.length>0||fn.length>0,hn=!1;e.selection?.type?hn=e.selection.type===`none`?!1:e.selection.type:e.selectable===void 0?mn&&(hn=`multiple`):hn=e.selectable;let gn=async n=>{if(!Fe)return n;let r=e.objectName;if(!t||!r)return n;let i={...Ze.current??{}};delete i.$top,delete i.$skip;let a=5e3,o=[],s=0;for(;o.length<a;){let e=(await t.find(r,{...i,$top:500,$skip:s})).data??[];if(e.length===0||(o.push(...e),e.length<500))break;s+=500}return o.slice(0,a)},_n=(e,t)=>{(async()=>{let n=await gn(t);if(e===`delete`&&i){i(n),Ne([]),N(!1);return}wt({type:e,params:{records:n}})})()},vn=(e,t)=>{(async()=>{let n=await gn(t);We(e),Xe(n)})()},yn=e=>{We(null),Xe([]),e&&(Ne([]),N(!1),xe(e=>e+1))},bn=e=>e?._id??e?.id,xn=async(e,n,r)=>{if(!t||!W)throw Error(`Cannot persist inline edit: no dataSource/objectName configured on the grid.`);let i=bn(r);if(i==null)throw Error(`Cannot persist inline edit: row has no id/_id.`);await t.update(W,i,n),xe(e=>e+1)},Sn=async e=>{if(!t||!W)throw Error(`Cannot persist inline edits: no dataSource/objectName configured on the grid.`);await Promise.all(e.map(({changes:e,row:n})=>{let r=bn(n);if(r==null)throw Error(`Cannot persist inline edit: row has no id/_id.`);return t.update(W,r,e)})),xe(e=>e+1)},Cn=e.pagination===void 0?e.showPagination===void 0?!0:e.showPagination:!0,wn=e.pagination?.pageSize||e.pageSize||10,Tn=e.searchableFields===void 0?e.showSearch===void 0?!0:e.showSearch:e.searchableFields.length>0,En=(!V&&!Pt||U)&&!Pt,Dn=U?g.rowCount:Le,On=U?g.page:gt,kn=U?g.pageSize??bt:bt,An=U?g.onPageChange:yt,jn=U?g.onPageSizeChange:e=>{xt(e),yt(1)},Mn={type:`data-table`,caption:e.label||e.title,columns:ln,data:b,pagination:Cn,pageSize:En?kn:wn,pageSizeOptions:e.pagination?.pageSizeOptions,manualPagination:En,rowCount:En?Dn:void 0,page:En?On:void 0,onPageChange:En?An:void 0,onPageSizeChange:En?jn:void 0,searchable:Tn,selectable:hn,sortable:!0,exportable:X?.export,borderless:!0,rowActions:!!(e.editable&&Qt),resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,singleClickEdit:e.singleClickEdit??!0,className:e.className,cellClassName:M===`compact`?`px-3 py-1 text-[13px] leading-tight`:M===`short`?`px-3 py-1 text-[13px] leading-normal`:M===`tall`?`px-3 py-2.5 text-sm`:M===`extra_tall`?`px-3 py-3.5 text-sm leading-relaxed`:`px-3 py-1.5 text-[13px] leading-normal`,showRowNumbers:!0,showAddRow:!!X?.create,onAddRecord:h,rowClassName:e.rowColor?(e,t)=>Dt(e):void 0,rowStyle:e.conditionalFormatting?.length?(e,t)=>Ot(e):void 0,frozenColumns:un,onSelectionChange:e=>{Ne(e),a?.(e)},onRowClick:J.handleClick,onCellChange:l,onRowSave:p??xn,onBatchSave:m??Sn,onColumnResize:(e,t)=>{it({...I,widths:{...I.widths,[e]:t}})},onColumnReorder:e=>{it({...I,order:e})}},Nn={};for(let e of ln){let t=e.accessorKey;if(!t)continue;let n=I.widths?.[t];if(n){Nn[t]=n;continue}if(e.width){Nn[t]=e.width;continue}let r=String(e.header??``).length;for(let e of b.slice(0,50)){let n=e?.[t],i=n==null?0:String(n).length;i>r&&(r=i)}Nn[t]=Math.min(400,Math.max(80,r*8+48))}let Pn=e=>({...Mn,caption:void 0,data:e,pagination:!1,searchable:!1,borderless:!0,disableInnerScroll:!0,frozenColumns:0,columns:Mn.columns.map(e=>({...e,width:Nn[e.accessorKey]??e.width}))}),Fn=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:`Record Detail`;if(pe&&b.length>0&&!Pt){let t=Y().filter(e=>e.accessorKey!==`_actions`),n=new Map;t.forEach(e=>n.set(e.accessorKey,e));let r=t[0],i=[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`],a=[`stage`,`status`,`priority`,`category`,`severity`,`level`],o=[`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`],s=[`probability`,`percent`,`rate`,`ratio`,`confidence`,`score`],c=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)||t===`activated`||t===`success`||t===`approved`||t===`paid`?`bg-green-50 text-green-700 border-green-200 dark:bg-green-950/40 dark:text-green-300 dark:border-green-900/60`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t.includes(`closed lost`)||t===`expired`||t===`terminated`||t===`failed`||t===`overdue`?`bg-red-50 text-red-700 border-red-200 dark:bg-red-950/40 dark:text-red-300 dark:border-red-900/60`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)||t.includes(`approval`)||t===`in_approval`||t===`pending_approval`?`bg-yellow-50 text-yellow-800 border-yellow-200 dark:bg-yellow-950/40 dark:text-yellow-300 dark:border-yellow-900/60`:t.includes(`proposal`)||t.includes(`pending`)?`bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-950/40 dark:text-blue-300 dark:border-blue-900/60`:t.includes(`qualification`)||t.includes(`qualified`)?`bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-950/40 dark:text-indigo-300 dark:border-indigo-900/60`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-950/40 dark:text-purple-300 dark:border-purple-900/60`:t===`draft`||t.includes(`draft`)?`bg-slate-50 text-slate-700 border-slate-200 dark:bg-slate-950/40 dark:text-slate-300 dark:border-slate-900/60`:`bg-muted text-muted-foreground border-border`},l=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)||t===`activated`?`border-l-green-500`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t===`expired`||t===`terminated`?`border-l-red-500`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)||t.includes(`approval`)?`border-l-yellow-500`:t.includes(`proposal`)||t.includes(`pending`)?`border-l-blue-500`:t.includes(`qualification`)||t.includes(`qualified`)?`border-l-indigo-500`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`border-l-purple-500`:t===`draft`||t.includes(`draft`)?`border-l-slate-400`:`border-l-gray-300`},u=e=>{let t=e.toLowerCase();return i.some(e=>t.includes(e))?`amount`:a.some(e=>t.includes(e))?`stage`:o.some(e=>t.includes(e))?`date`:s.some(e=>t.includes(e))?`percent`:`other`},d=(t,n)=>{let r=O?.fields?.[t]?.options;if(Array.isArray(r)&&r.length>0){let i=(e.objectName?D(e.objectName,t,r):r).find(e=>e&&String(e.value)===String(n));if(i)return{label:i.label==null?String(n):String(i.label),color:i.color}}let i=String(n);return{label:/^[a-z0-9]+(_[a-z0-9]+)+$/.test(i)?Re(i):i}};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`space-y-2 p-2`,children:b.map((e,n)=>{let i=t.slice(1,5),a=i.find(e=>u(e.accessorKey)===`amount`),o=i.find(e=>u(e.accessorKey)===`stage`),s=i.filter(e=>u(e.accessorKey)===`date`),f=i.filter(e=>u(e.accessorKey)===`percent`),p=i.filter(e=>e!==a&&e!==o&&!s.includes(e)&&!f.includes(e)),m=o?String(e[o.accessorKey]??``):``,h=m?l(m):``;return(0,H.jsxs)(`div`,{className:[`border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation`,h?`border-l-[3px] ${h}`:``].filter(Boolean).join(` `),onClick:()=>J.handleClick(e),children:[r&&(0,H.jsx)(`div`,{className:`font-semibold text-sm truncate mb-1`,children:e[r.accessorKey]!=null&&typeof e[r.accessorKey]==`object`?String(e[r.accessorKey]):e[r.accessorKey]??`—`}),(a||o)&&(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[a&&(0,H.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:typeof e[a.accessorKey]==`number`?He(e[a.accessorKey],y(a,C)):e[a.accessorKey]!=null&&typeof e[a.accessorKey]==`object`?String(e[a.accessorKey]):e[a.accessorKey]??`—`}),o&&e[o.accessorKey]&&(()=>{let t=e[o.accessorKey],n=d(o.accessorKey,t);return(0,H.jsx)(ke,{variant:`outline`,className:`text-xs shrink-0 max-w-[140px] truncate ${n.color?Ae(n.color,t):c(String(t))}`,children:n.label})})()]}),(s.length>0||f.length>0)&&(0,H.jsxs)(`div`,{className:`flex items-center justify-between py-0.5 text-xs text-muted-foreground`,children:[s[0]&&(0,H.jsx)(`span`,{className:`tabular-nums`,children:e[s[0].accessorKey]?Je(e[s[0].accessorKey],`short`):`—`}),f[0]&&e[f[0].accessorKey]!=null&&(0,H.jsx)(`span`,{className:`tabular-nums`,children:rt(Number(e[f[0].accessorKey]))})]}),s.slice(1).map(t=>(0,H.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.header}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:e[t.accessorKey]?Je(e[t.accessorKey],`short`):`—`})]},t.accessorKey)),p.map(t=>{let n=e[t.accessorKey];return n==null||n===``?null:(0,H.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.header}),(0,H.jsx)(`span`,{className:`text-xs font-medium truncate ml-2 text-right`,children:t.cell?t.cell(n,e):String(n)})]},t.accessorKey)})]},e.id||e._id||n)})}),J.isOverlay&&(0,H.jsx)(be,{...J,title:Fn,children:e=>(0,H.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,H.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})}let In=()=>{je(e=>e===`compact`?`short`:e===`short`?`medium`:e===`medium`?`tall`:e===`tall`?`extra_tall`:`compact`)},Ln={compact:le,short:de,medium:me,tall:v,extra_tall:v}[M],Rn=e.rowHeight!==void 0&&!e.hideRowHeightToggle,zn=e.exportOptions||Rn?(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-1 px-2 py-1`,children:[Rn&&(0,H.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,onClick:In,title:`Row height: ${M}`,children:[(0,H.jsx)(Ln,{className:`h-3.5 w-3.5 mr-1.5`}),(0,H.jsx)(`span`,{className:`hidden sm:inline capitalize`,children:M})]}),e.exportOptions&&(0,H.jsxs)(Ue,{open:Se,onOpenChange:A,children:[(0,H.jsx)(Ye,{asChild:!0,children:(0,H.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,children:[(0,H.jsx)(we,{className:`h-3.5 w-3.5 mr-1.5`}),(0,H.jsx)(`span`,{className:`hidden sm:inline`,children:w(`grid.export`)})]})}),(0,H.jsx)(Oe,{align:`end`,className:`w-48 p-2`,children:(0,H.jsx)(`div`,{className:`space-y-1`,children:(e.exportOptions.formats||[`csv`,`json`]).map(e=>(0,H.jsxs)(L,{variant:`ghost`,size:`sm`,className:`w-full justify-start h-8 text-xs`,onClick:()=>Wt(e),children:[(0,H.jsx)(we,{className:`h-3.5 w-3.5 mr-2`}),w(`grid.exportAs`,{format:e.toUpperCase()})]},e))})})]})]}):null,Bn=e=>{let t=[`_id`,`id`,`created_at`,`updated_at`,`created_by`,`updated_by`],n=Object.entries(e),r=e=>O?.fields?.[e]?.hidden===!0,i=n.filter(([e])=>!t.includes(e)&&!r(e)),a=n.filter(([e])=>t.includes(e)&&e!==`_id`&&e!==`id`),o=e=>e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `),s=(e,t)=>{if(t==null||t===``)return(0,H.jsx)(`span`,{className:`text-muted-foreground/50 text-sm italic`,children:w(`grid.empty`)});let n=O?.fields?.[e];if(n?.type){let e=Pe(n.type);if(e)return(0,H.jsx)(e,{value:t,field:n})}return typeof t==`boolean`?(0,H.jsx)(ke,{variant:t?`default`:`outline`,children:w(t?`grid.yes`:`grid.no`)}):typeof t==`string`&&!isNaN(Date.parse(t))&&(e.includes(`date`)||e.includes(`_at`)||e.includes(`time`))?(0,H.jsx)(`span`,{className:`text-sm tabular-nums`,children:Je(t)}):typeof t==`number`&&[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`].some(t=>e.toLowerCase().includes(t))?(0,H.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:De(t,C)}):(0,H.jsx)(`span`,{className:`text-sm break-words`,children:String(t)})};return(0,H.jsxs)(`div`,{className:`space-y-4`,"data-testid":`record-detail-panel`,children:[(0,H.jsx)(`div`,{className:`rounded-lg border bg-card`,children:(0,H.jsx)(`div`,{className:`divide-y`,children:i.map(([e,t])=>(0,H.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-4 px-4 py-3`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground sm:w-1/3 sm:text-right sm:pt-0.5 uppercase tracking-wide shrink-0`,children:o(e)}),(0,H.jsx)(`div`,{className:`flex-1 min-w-0`,children:s(e,t)})]},e))})}),a.length>0&&(0,H.jsxs)(`div`,{className:`rounded-lg border bg-muted/30`,children:[(0,H.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:w(`grid.systemFields`)})}),(0,H.jsx)(`div`,{className:`divide-y divide-border/50`,children:a.map(([e,t])=>(0,H.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-1/3 text-right shrink-0`,children:o(e)}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1 min-w-0 break-words`,children:String(t??``)})]},e))})]})]})},Vn=Ut?(0,H.jsx)(`div`,{className:`border-t bg-muted/30 px-2 py-1.5`,"data-testid":`column-summary-footer`,children:(0,H.jsx)(`div`,{className:`flex gap-4 text-xs text-muted-foreground font-medium`,children:ln.filter(e=>Ht.has(e.accessorKey)).map(e=>{let t=Ht.get(e.accessorKey);return(0,H.jsxs)(`span`,{"data-testid":`summary-${e.accessorKey}`,children:[e.header,`: `,t.label]},e.accessorKey)})})}):null,Hn=(t,n)=>{let r=O?.fields?.[t],i=e.objectName?T(e.objectName,t,r?.label||t):r?.label||t,a,o=r?.type;if(o===`select`||o===`status`){let i=r?.options?D(e.objectName,t,r.options):void 0,o=Array.isArray(i)?i.find(e=>String(e.label)===n||String(e.value)===n):void 0;a=Ae(o?.color,o?.value??n)}return{fieldLabel:i,labelColorClass:a}},Un=e=>{let{fieldLabel:t,labelColorClass:n}=Hn(e.field,e.label);return(0,H.jsx)(`div`,{children:(0,H.jsx)(vt,{groupKey:e.key,label:e.label,count:e.rows.length,collapsed:e.collapsed,aggregations:e.aggregations,fieldLabel:e.depth===0?t:void 0,labelColorClass:n,onToggle:It,children:e.subgroups.length>0?(0,H.jsx)(`div`,{className:`space-y-4 mt-2`,children:e.subgroups.map(Un)}):(0,H.jsx)(d,{schema:Pn(e.rows)})})},e.key)},Q=Math.max(1,Math.ceil(Nt.length/F)),$=Math.min(Qe,Q),Wn=Nt.slice(($-1)*F,$*F),Gn=Nt.length>0&&Q>1?(0,H.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between gap-2 px-3 sm:px-4 py-2 border-t`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(`span`,{className:`text-xs sm:text-sm text-muted-foreground`,children:[w(`table.rowsPerPage`),`:`]}),(0,H.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:F,onChange:e=>{$e(Number(e.target.value)),P(1)},children:[5,10,20,50,100].map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-xs sm:text-sm text-muted-foreground`,children:w(`table.pageInfo`,{current:$,total:Q})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(L,{variant:`outline`,size:`icon`,onClick:()=>P(1),disabled:$===1,children:(0,H.jsx)(ae,{className:`h-4 w-4`})}),(0,H.jsx)(L,{variant:`outline`,size:`icon`,onClick:()=>P(Math.max(1,$-1)),disabled:$===1,children:(0,H.jsx)(ee,{className:`h-4 w-4`})}),(0,H.jsx)(L,{variant:`outline`,size:`icon`,onClick:()=>P(Math.min(Q,$+1)),disabled:$===Q,children:(0,H.jsx)(lt,{className:`h-4 w-4`})}),(0,H.jsx)(L,{variant:`outline`,size:`icon`,onClick:()=>P(Q),disabled:$===Q,children:(0,H.jsx)(he,{className:`h-4 w-4`})})]})]})]}):null,Kn=Pt?(0,H.jsxs)(`div`,{className:`flex flex-col h-full min-h-0`,children:[(0,H.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto [-webkit-overflow-scrolling:touch]`,children:(0,H.jsx)(`div`,{className:`min-w-max space-y-4 px-3 sm:px-4 pt-2 pb-4`,children:Wn.map(Un)})}),Gn]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(d,{schema:Mn}),Vn]}),qn=(0,H.jsx)(ue,{open:j,onOpenChange:Ce,job:Ee,filename:`${e.exportOptions?.fileNamePrefix||e.objectName||`export`}.${Ee.progress?.format||`csv`}`,closeAfterDownloadMs:400}),Jn=(0,H.jsx)(Mt,{def:Ve,rows:Ke,open:!!Ve,onClose:yn,dataSource:t,resource:e.objectName??``});return J.isOverlay&&J.mode===`split`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(be,{...J,title:Fn,mainContent:(0,H.jsxs)(H.Fragment,{children:[zn,Kn,(0,H.jsx)(At,{selectedRows:Me,actions:pn??[],actionDefs:fn,onAction:_n,onActionDef:vn,onClearSelection:()=>{Ne([]),N(!1)},pageSize:b.length,totalMatching:Le,allMatchingSelected:Fe,onSelectAllMatching:()=>N(!0)})]}),children:e=>Bn(e)}),qn,Jn]}):(0,H.jsxs)(`div`,{ref:at,className:`relative h-full`,children:[(0,H.jsx)(ie,{active:re&&b.length>0}),st>0&&(0,H.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:st},children:w(ot?`grid.refreshing`:`grid.pullToRefresh`)}),zn,Kn,(0,H.jsx)(At,{selectedRows:Me,actions:pn??[],actionDefs:fn,onAction:_n,onActionDef:vn,onClearSelection:()=>{Ne([]),N(!1)},pageSize:b.length,totalMatching:Le,allMatchingSelected:Fe,onSelectAllMatching:()=>N(!0)}),J.isOverlay&&(0,H.jsx)(be,{...J,title:Fn,children:e=>Bn(e)}),qn,Jn]})},Ht=e(r(),1);function Ut(e,t,n){let r=Array(e);return new Proxy(r,{get(r,i,a){if(typeof i==`string`){let a=i.charCodeAt(0);if(a>=48&&a<=57){let a=+i;if(Number.isInteger(a)&&a>=0&&a<e){let e=r[a];if(!e){let i=t[a*2];e=r[a]={index:a,key:n(a),start:i,size:t[a*2+1],end:i+t[a*2+1],lane:0}}return e}}if(i===`length`)return e}return Reflect.get(r,i,a)}})}function Y(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function Wt(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Gt=(e,t)=>Math.abs(e-t)<1.01,X=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},Z,Kt=()=>{if(Z!==void 0)return Z;if(typeof navigator>`u`)return Z=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Z=!0;let e=navigator.maxTouchPoints;return Z=navigator.platform===`MacIntel`&&e!==void 0&&e>0},qt=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Jt=e=>e,Yt=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},Xt=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(qt(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(qt(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},Zt={passive:!0},Qt=typeof window>`u`?!0:`onscrollend`in window,$t=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Qt,o=0,s=a?null:X(i,()=>t(o,!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,Zt),a&&r.addEventListener(`scrollend`,u,Zt),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},en=(e,t)=>$t(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),tn=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},nn=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},rn=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Jt,rangeExtractor:Yt,onChange:()=>{},measureElement:tn,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=e>0?s[0]?.key??n.getItemKey(0):null,l=e>0?s[e-1]?.key??n.getItemKey(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==c||t.getItemKey(o-1)!==l)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>e&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==l)&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:i,getItemKey:a}=this.options,c=0;for(;c<i&&a(c)!==e;)c++;if(c<i){let e=n[c];if(e){let n=e.start+t;n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=Y(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,!(!Kt()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,Zt),e.addEventListener(`touchend`,n,Zt),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(Kt()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=Y(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(e,t,n,r,i,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o}),{key:!1}),this.getMeasurements=Y(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o},s)=>{let c=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let l=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=this.options.gap,a=e*2,o=this._flatMeasurements;if(!o||o.length<a){let e=new Float64Array(a);o&&l>0&&e.set(o.subarray(0,l*2)),o=e,this._flatMeasurements=o}let s;if(l===0)s=t+n;else{let e=l-1;s=o[e*2]+o[e*2+1]+i}for(let t=l;t<e;t++){let e=r(t),n=c.get(e),a=typeof n==`number`?n:this.options.estimateSize(t);o[t*2]=s,o[t*2+1]=a,s+=a+i}let u=Ut(e,o,r);return this.measurementsCache=u,u}let u=this.measurementsCache.slice(0,l),d=Array(a).fill(void 0);for(let e=0;e<l;e++){let t=u[e];t&&(d[t.lane]=e)}for(let i=l;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,l,f=o===`estimate`||c.has(e);if(a!==void 0&&this.options.lanes>1){s=a;let e=d[s],r=e===void 0?void 0:u[e];l=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?u[i-1]:this.getFurthestMeasurement(u,i);l=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&f&&this.laneAssignments.set(i,s)}let p=c.get(e),m=typeof p==`number`?p:this.options.estimateSize(i),h=l+m;u[i]={index:i,start:l,size:m,end:h,key:e,lane:s},d[s]=i}return this.measurementsCache=u,u},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Y(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?on({measurements:e,outerSize:t,scrollOffset:n,lanes:r,flat:r===1&&this._flatMeasurements!=null?this._flatMeasurements:null}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Y(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(e<0||e>=this.options.count)return;let n,r,i,a=this._flatMeasurements;if(this.options.lanes===1&&a!==null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=t-(this.itemSizeCache.get(i)??n);if(o!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,s=a?this.getTotalSize():0,c=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?r<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(i)||this.scrollDirection!==`backward`):this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},o,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++,a?this.applyScrollAdjustment(this.getTotalSize()-s):c&&this.applyScrollAdjustment(o),this.notify(!1)}},this.getVirtualItems=Y(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._flatMeasurements,r=this.options.lanes===1&&n!=null;return Wt(t[an(0,t.length-1,r?e=>n[e*2]:e=>Wt(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._flatMeasurements;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){e!==0&&(Kt()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=e:this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&Gt(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},an=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function on({measurements:e,outerSize:t,scrollOffset:n,lanes:r,flat:i}){let a=e.length-1,o=i?e=>i[e*2]:t=>e[t].start,s=i?e=>i[e*2]+i[e*2+1]:t=>e[t].end;if(e.length<=r)return{startIndex:0,endIndex:a};let c=an(0,a,o,n),l=c;if(r===1)for(;l<a&&s(l)<n+t;)l++;else if(r>1){let i=Array(r).fill(0);for(;l<a&&i.some(e=>e<n+t);){let t=e[l];i[t.lane]=t.end,l++}let o=Array(r).fill(n+t);for(;c>=0&&o.some(e=>e>=n);){let t=e[c];o[t.lane]=t.start,c--}c=Math.max(0,c-c%r),l=Math.min(a,l+(r-1-l%r))}return{startIndex:c,endIndex:l}}var sn=typeof document<`u`?R.useLayoutEffect:R.useEffect;function cn({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=R.useReducer(e=>e+1,0)[1],a=R.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}let r=!!e.options.horizontal,i=t.mode===`transform`,o=r?`left`:`top`,s=e.options.scrollMargin,c=e.getVirtualItems();for(let n of c){let a=n.start-s,c=e.elementsCache.get(n.key);c&&t.lastPositions.get(c)!==a&&(t.lastPositions.set(c,a),i?c.style.transform=r?`translate3d(${a}px, 0, 0)`:`translate3d(0, ${a}px, 0)`:c.style[o]=`${a}px`)}},s={...r,onChange:(t,n)=>{var s;let c=a.current,l=!0;if(c.enabled){o(t);let e=t.range,n=c.prevRange;l=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,l&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}l&&(e&&n?(0,Ht.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[c]=R.useState(()=>{let e=new rn(s);return Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return c.setOptions(s),sn(()=>c._didMount(),[]),sn(()=>c._willUpdate()),sn(()=>{o(c)}),c}function ln(e){return cn({observeElementRect:Xt,observeElementOffset:en,scrollToFn:nn,...e})}var un={Unsupported:`IMPORT_UNSUPPORTED_FILE`,LegacyXls:`IMPORT_LEGACY_XLS`};function dn(e,t=`,`){let n=[],r=[],i=``,a=!1;for(let o=0;o<e.length;o++){let s=e[o],c=e[o+1];a?s===`"`&&c===`"`?(i+=`"`,o++):s===`"`?a=!1:i+=s:s===`"`?a=!0:s===t?(r.push(i.trim()),i=``):s===`
|
|
5
|
+
`||s===`\r`&&c===`
|
|
6
|
+
`?(r.push(i.trim()),r.some(e=>e!==``)&&n.push(r),r=[],i=``,s===`\r`&&o++):i+=s}return r.push(i.trim()),r.some(e=>e!==``)&&n.push(r),n}function fn(e){if(e==null)return``;if(e instanceof Date){let t=e.toISOString();return t.endsWith(`T00:00:00.000Z`)?t.slice(0,10):t}if(typeof e==`object`){let t=e;return`result`in t?fn(t.result):Array.isArray(t.richText)?t.richText.map(e=>String(e.text??``)).join(``):`text`in t?fn(t.text):`hyperlink`in t?String(t.hyperlink??``):`error`in t?String(t.error??``):``}return String(e)}async function pn(t){let n=await i(()=>import(`./exceljs.min-HZhgX9lC.js`).then(t=>e(t.default,1)),[],import.meta.url),r=new(n.default??n).Workbook;await r.xlsx.load(t);let a=r.worksheets[0];if(!a)return[];let o=a.columnCount,s=[];return a.eachRow({includeEmpty:!1},e=>{let t=[];for(let n=1;n<=o;n++)t.push(fn(e.getCell(n).value).trim());t.some(e=>e!==``)&&s.push(t)}),s}async function mn(e){let t=e.name.toLowerCase();if(t.endsWith(`.csv`)||t.endsWith(`.tsv`)||t.endsWith(`.txt`))return dn(await e.text(),t.endsWith(`.tsv`)?` `:`,`);if(t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`))return pn(await e.arrayBuffer());throw t.endsWith(`.xls`)?Error(un.LegacyXls):Error(un.Unsupported)}function hn(e,t){if(e&&/<table[\s>]/i.test(e)&&typeof DOMParser<`u`){let t=gn(e);if(t.length)return t}if(t&&t.trim()){let e=dn(t,t.includes(` `)?` `:`,`);if(e.length)return e}return null}function gn(e){let t=new DOMParser().parseFromString(e,`text/html`).querySelector(`table`);if(!t)return[];let n=[];return t.querySelectorAll(`tr`).forEach(e=>{let t=[];e.querySelectorAll(`th,td`).forEach(e=>t.push((e.textContent??``).trim())),t.some(e=>e!==``)&&n.push(t)}),n}var _n=new Set([`true`,`false`,`yes`,`no`,`y`,`n`,`是`,`否`]),vn=50,yn=e=>e!==``&&!isNaN(Number(e)),bn=e=>_n.has(e.toLowerCase()),xn=e=>/\d{1,2}:\d{2}/.test(e)||/T\d{2}:\d{2}/.test(e),Sn=e=>!yn(e)&&!isNaN(Date.parse(e));function Cn(e){let t=e.map(e=>(e??``).trim()).filter(e=>e!==``).slice(0,vn);return t.length===0?`text`:t.every(bn)?`boolean`:t.every(yn)?`number`:t.every(Sn)?t.some(xn)?`datetime`:`date`:`text`}function wn(e,t){switch(e){case`number`:return[`number`,`currency`,`percent`].includes(t);case`boolean`:return t===`boolean`;case`date`:case`datetime`:return t===`date`||t===`datetime`;case`text`:return!0;default:return!0}}var Tn={"grid.import.title":`Import {{object}}`,"grid.import.stepUpload":`Upload`,"grid.import.stepMapping":`Mapping`,"grid.import.stepPreview":`Preview`,"grid.import.uploadDescription":`Upload a CSV or Excel file, or paste from a spreadsheet to get started.`,"grid.import.mappingDescription":`Map columns to object fields.`,"grid.import.previewDescription":`Review data before importing.`,"grid.import.dragDrop":`Drag & drop a CSV or Excel file here, or click to browse`,"grid.import.browseFiles":`Browse Files`,"grid.import.parsing":`Parsing…`,"grid.import.pasteHint":`or paste (Ctrl/⌘+V) rows copied from Excel or Google Sheets`,"grid.import.legacyXls":`Legacy .xls files aren't supported — please re-save as .xlsx.`,"grid.import.unsupportedFile":`Unsupported file type. Use CSV, TSV, or Excel (.xlsx).`,"grid.import.parseFailed":`Could not read this file. Please check the format and try again.`,"grid.import.fileNeedsHeader":`File must contain a header row and at least one data row.`,"grid.import.mappingTemplate":`Mapping template:`,"grid.import.chooseTemplate":`Choose template…`,"grid.import.noSavedTemplates":`No saved templates`,"grid.import.noneOption":`— None —`,"grid.import.saveCurrent":`Save current`,"grid.import.templateName":`Template name`,"grid.import.save":`Save`,"grid.import.deleteTemplate":`Delete template`,"grid.import.csvColumn":`Column`,"grid.import.mapsTo":`Maps To`,"grid.import.typeMismatch":`Looks like {{type}}`,"grid.import.type.number":`Number`,"grid.import.type.boolean":`Boolean`,"grid.import.type.date":`Date`,"grid.import.type.datetime":`Date & time`,"grid.import.type.text":`Text`,"grid.import.status":`Status`,"grid.import.skipColumn":`Skip column`,"grid.import.skip":`— Skip —`,"grid.import.mapped":`Mapped`,"grid.import.skipped":`Skipped`,"grid.import.rowsWithErrors":`{{count}} row(s) with errors`,"grid.import.rowsCorrected":`{{count}} row(s) corrected`,"grid.import.clickToFix":`— click a highlighted cell to fix it inline.`,"grid.import.showingRows":`Showing {{shown}} of {{total}} rows`,"grid.import.importing":`Importing… {{progress}}%`,"grid.import.importComplete":`Import Complete`,"grid.import.imported":`{{count}} imported`,"grid.import.skippedCount":`{{count}} skipped`,"grid.import.moreErrors":`…and {{count}} more errors`,"grid.import.cancel":`Cancel`,"grid.import.back":`Back`,"grid.import.next":`Next`,"grid.import.close":`Close`,"grid.import.importNRows":`Import {{count}} Rows`,"grid.import.importingProgress":`Importing…`,"grid.import.required":`Required`,"grid.import.invalidType":`Invalid {{type}}`};function En(e,t){if(!t)return e;let n=e;for(let[e,r]of Object.entries(t))n=n.replace(RegExp(`{{${e}}}`,`g`),String(r));return n}function Dn(){let e=(e,t)=>En(Tn[e]??e,t);try{let t=m();return t.t(`grid.import.title`)===`grid.import.title`?{t:e}:{t:(n,r)=>{let i=t.t(n,r);return i===n?e(n,r):i}}}catch{return{t:e}}}var On=10;function kn(e,t){if(!e)return!0;switch(t){case`number`:case`currency`:case`percent`:return!isNaN(Number(e));case`boolean`:return[`true`,`false`,`1`,`0`,`yes`,`no`].includes(e.toLowerCase());case`date`:case`datetime`:return!isNaN(Date.parse(e));default:return!0}}var An=e=>e.toLowerCase().replace(/[_\s-]/g,``);function jn(e,t,n){let r={},i=new Set;return e.forEach((e,n)=>{let a=An(e),o=t.find(e=>An(e.name)===a||An(e.label)===a);o&&!i.has(o.name)&&(r[n]=o.name,i.add(o.name))}),n&&n.length&&e.forEach((e,a)=>{if(r[a])return;let o=An(e);if(o.length<3)return;let s=Cn(n.map(e=>e[a])),c=t.find(e=>{if(i.has(e.name)||!wn(s,e.type))return!1;let t=An(e.name),n=An(e.label);return t.includes(o)||o.includes(t)||n.includes(o)||o.includes(n)});c&&(r[a]=c.name,i.add(c.name))}),r}function Mn(){if(typeof window>`u`)return null;try{return window.localStorage}catch{return null}}function Nn(e,t){if(!e)return[];try{let n=e.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r.filter(e=>e&&e.id&&e.name&&e.mapping):[]}catch{return[]}}function Pn(e,t,n){if(e)try{e.setItem(t,JSON.stringify(n))}catch{}}function Fn(e,t){let n={};return Object.entries(t).forEach(([t,r])=>{let i=e[Number(t)];i&&(n[i.trim().toLowerCase()]=r)}),n}function In(e,t,n){let r=new Set(n.map(e=>e.name)),i={};return t.forEach((t,n)=>{let a=e.mapping[t.trim().toLowerCase()];a&&r.has(a)&&(i[n]=a)}),i}function Ln(e,t,n){let r=[],i={};for(let a of t){let t=e[a.csvIdx]??``;if(a.field.required&&!t){r.push({row:n,field:a.field.name,message:`Required field is empty`});continue}if(t&&!kn(t,a.field.type)){r.push({row:n,field:a.field.name,message:`Invalid ${a.field.type} value: "${t}"`});continue}i[a.field.name]=t}return{record:i,errors:r}}function Rn(e,t){let n=e instanceof Error?e.message:``;return n===un.LegacyXls?t(`grid.import.legacyXls`):n===un.Unsupported?t(`grid.import.unsupportedFile`):t(`grid.import.parseFailed`)}var zn=({onFileLoaded:e})=>{let{t}=Dn(),[n,r]=(0,R.useState)(!1),[i,a]=(0,R.useState)(null),[o,s]=(0,R.useState)(!1),c=(0,R.useCallback)(n=>n.length<2?(a(t(`grid.import.fileNeedsHeader`)),!1):(e(n[0],n.slice(1)),!0),[e,t]),l=(0,R.useCallback)(async e=>{a(null),s(!0);try{c(await mn(e))}catch(e){a(Rn(e,t))}finally{s(!1)}},[c,t]),u=(0,R.useCallback)(e=>{let t=e.target;if(t&&/^(input|textarea)$/i.test(t.tagName))return;let n=e.clipboardData;if(!n)return;let r=hn(n.getData(`text/html`)||null,n.getData(`text/plain`)||null);r&&(e.preventDefault(),a(null),c(r))},[c]);return(0,R.useEffect)(()=>(window.addEventListener(`paste`,u),()=>window.removeEventListener(`paste`,u)),[u]),(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-6`,children:[(0,H.jsxs)(`div`,{className:k(`flex w-full flex-col items-center justify-center gap-3 rounded-lg border-2 border-dashed p-10 transition-colors`,n?`border-primary bg-primary/5`:`border-muted-foreground/25`,o&&`pointer-events-none opacity-60`),onDragOver:e=>{e.preventDefault(),r(!0)},onDragLeave:()=>r(!1),onDrop:e=>{e.preventDefault(),r(!1);let t=e.dataTransfer.files[0];t&&l(t)},children:[(0,H.jsx)(ct,{className:`h-10 w-10 text-muted-foreground`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(o?`grid.import.parsing`:`grid.import.dragDrop`)}),(0,H.jsxs)(`label`,{children:[(0,H.jsx)(`input`,{type:`file`,accept:`.csv,.tsv,.txt,.xlsx,.xlsm`,className:`hidden`,disabled:o,onChange:e=>{let t=e.target.files?.[0];t&&l(t)}}),(0,H.jsx)(L,{variant:`outline`,size:`sm`,asChild:!0,children:(0,H.jsx)(`span`,{children:t(`grid.import.browseFiles`)})})]}),(0,H.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-muted-foreground/80`,children:[(0,H.jsx)(it,{className:`h-3.5 w-3.5`}),` `,t(`grid.import.pasteHint`)]})]}),i&&(0,H.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-destructive`,children:[(0,H.jsx)(O,{className:`h-4 w-4`}),` `,i]})]})},Bn=({templates:e,selectedId:t,onSelect:n,onSaveAs:r,onDelete:i,disabled:a})=>{let{t:o}=Dn(),[s,c]=(0,R.useState)(``),[l,u]=(0,R.useState)(!1);return(0,H.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 rounded-md border bg-muted/30 p-2`,"data-testid":`import-template-bar`,children:[(0,H.jsx)(We,{className:`h-4 w-4 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`grid.import.mappingTemplate`)}),(0,H.jsxs)(S,{value:t??`__none__`,onValueChange:e=>e!==`__none__`&&n(e),children:[(0,H.jsx)(C,{className:`h-7 w-48 text-xs`,"data-testid":`import-template-select`,children:(0,H.jsx)(Ce,{placeholder:e.length?o(`grid.import.chooseTemplate`):o(`grid.import.noSavedTemplates`)})}),(0,H.jsxs)(T,{children:[(0,H.jsx)($e,{value:`__none__`,disabled:e.length===0,children:e.length?o(`grid.import.noneOption`):o(`grid.import.noSavedTemplates`)}),e.map(e=>(0,H.jsx)($e,{value:e.id,children:e.name},e.id))]})]}),l?(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(tt,{value:s,onChange:e=>c(e.target.value),placeholder:o(`grid.import.templateName`),className:`h-7 w-40 text-xs`,"data-testid":`import-template-name-input`,autoFocus:!0}),(0,H.jsx)(L,{type:`button`,size:`sm`,onClick:()=>{s.trim()&&(r(s.trim()),c(``),u(!1))},disabled:!s.trim()||a,"data-testid":`import-template-confirm-save`,children:o(`grid.import.save`)}),(0,H.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{u(!1),c(``)},children:o(`grid.import.cancel`)})]}):(0,H.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>u(!0),disabled:a,"data-testid":`import-template-save-btn`,children:o(`grid.import.saveCurrent`)}),t&&(0,H.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,onClick:i,"aria-label":o(`grid.import.deleteTemplate`),"data-testid":`import-template-delete-btn`,children:(0,H.jsx)(F,{className:`h-3.5 w-3.5`})})]})},Vn=({headers:e,fields:t,mapping:n,onMappingChange:r,inferredTypes:i,templates:a,selectedTemplateId:o,onSelectTemplate:s,onSaveTemplate:c,onDeleteTemplate:l})=>{let{t:u}=Dn(),d=(0,R.useMemo)(()=>new Set(Object.values(n)),[n]),f=(0,R.useCallback)((e,t)=>{let i={...n};t===`__skip__`?delete i[e]:i[e]=t,r(i)},[n,r]);return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(Bn,{templates:a,selectedId:o,onSelect:s,onSaveAs:c,onDelete:l,disabled:Object.keys(n).length===0}),(0,H.jsx)(`div`,{className:`max-h-[420px] overflow-auto`,children:(0,H.jsxs)(Ne,{children:[(0,H.jsx)(Ve,{children:(0,H.jsxs)(Le,{children:[(0,H.jsx)(Ke,{children:u(`grid.import.csvColumn`)}),(0,H.jsx)(Ke,{children:u(`grid.import.mapsTo`)}),(0,H.jsx)(Ke,{className:`w-24 text-center`,children:u(`grid.import.status`)})]})}),(0,H.jsx)(N,{children:e.map((e,r)=>{let a=i[r]??`text`,o=n[r]?t.find(e=>e.name===n[r]):void 0,s=!!o&&!wn(a,o.type);return(0,H.jsxs)(Le,{children:[(0,H.jsx)(Qe,{className:`font-medium`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{children:e}),a!==`text`&&(0,H.jsx)(ke,{variant:`outline`,className:`w-fit text-[10px] font-normal text-muted-foreground`,"data-testid":`import-inferred-${r}`,children:u(`grid.import.type.${a}`)})]})}),(0,H.jsxs)(Qe,{children:[(0,H.jsxs)(S,{value:n[r]??`__skip__`,onValueChange:e=>f(r,e),children:[(0,H.jsx)(C,{className:`h-8 w-56`,children:(0,H.jsx)(Ce,{placeholder:u(`grid.import.skipColumn`)})}),(0,H.jsxs)(T,{children:[(0,H.jsx)($e,{value:`__skip__`,children:u(`grid.import.skip`)}),t.map(e=>(0,H.jsxs)($e,{value:e.name,disabled:d.has(e.name)&&n[r]!==e.name,children:[e.label,e.required?` *`:``]},e.name))]})]}),s&&(0,H.jsxs)(`p`,{className:`mt-1 flex items-center gap-1 text-[11px] text-amber-600`,"data-testid":`import-type-warn-${r}`,children:[(0,H.jsx)(O,{className:`h-3 w-3`}),` `,u(`grid.import.typeMismatch`,{type:u(`grid.import.type.${a}`)})]})]}),(0,H.jsx)(Qe,{className:`text-center`,children:n[r]?(0,H.jsx)(ke,{variant:`default`,className:`text-xs`,children:u(`grid.import.mapped`)}):(0,H.jsx)(ke,{variant:`secondary`,className:`text-xs`,children:u(`grid.import.skipped`)})})]},r)})})]})})]})},Hn=({headers:e,rows:t,mapping:n,fields:r,corrections:i,onCorrect:a})=>{let{t:o}=Dn(),s=(0,R.useMemo)(()=>Object.entries(n).map(([t,n])=>({csvIdx:Number(t),header:e[Number(t)],field:r.find(e=>e.name===n)})),[n,e,r]),c=t.slice(0,On),l=(0,R.useCallback)((e,t)=>{let n=i[e]?.[t];return n===void 0?c[e]?.[t]??``:n},[i,c]),u=(0,R.useMemo)(()=>c.map((e,t)=>{let n={};for(let e of s){let r=l(t,e.csvIdx);e.field.required&&!r?n[e.csvIdx]=o(`grid.import.required`):r&&!kn(r,e.field.type)&&(n[e.csvIdx]=o(`grid.import.invalidType`,{type:e.field.type}))}return n}),[c,s,l,o]),d=u.filter(e=>Object.keys(e).length>0).length,f=Object.keys(i).length;return(0,H.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[(d>0||f>0)&&(0,H.jsxs)(`p`,{className:`mb-2 flex items-center gap-2 text-xs`,"data-testid":`import-preview-status`,children:[d>0&&(0,H.jsxs)(`span`,{className:`flex items-center gap-1 text-destructive`,children:[(0,H.jsx)(O,{className:`h-3.5 w-3.5`}),` `,o(`grid.import.rowsWithErrors`,{count:d})]}),f>0&&(0,H.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-600`,children:[(0,H.jsx)(b,{className:`h-3.5 w-3.5`}),` `,o(`grid.import.rowsCorrected`,{count:f})]}),(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:o(`grid.import.clickToFix`)})]}),(0,H.jsxs)(Ne,{children:[(0,H.jsx)(Ve,{children:(0,H.jsxs)(Le,{children:[(0,H.jsx)(Ke,{className:`w-12`,children:`#`}),s.map(e=>(0,H.jsx)(Ke,{children:e.field.label},e.csvIdx))]})}),(0,H.jsx)(N,{children:c.map((e,t)=>{let n=u[t],r=Object.keys(n).length>0,o=i[t]!==void 0;return(0,H.jsxs)(Le,{className:k(r&&`bg-destructive/5`,!r&&o&&`bg-emerald-50 dark:bg-emerald-950/20`),"data-testid":`import-preview-row-${t}`,children:[(0,H.jsx)(Qe,{className:`text-xs text-muted-foreground`,children:t+1}),s.map(e=>{let r=l(t,e.csvIdx),o=n[e.csvIdx],s=i[t]?.[e.csvIdx]!==void 0;return(0,H.jsx)(Qe,{className:k(o&&`text-destructive`,s&&!o&&`text-emerald-600`),title:o,children:(0,H.jsx)(tt,{value:r,onChange:n=>a(t,e.csvIdx,n.target.value),className:k(`h-7 px-1 text-xs`,o&&`border-destructive`,s&&!o&&`border-emerald-500`),"data-testid":`import-preview-cell-${t}-${e.csvIdx}`,"aria-invalid":o?`true`:`false`,"aria-label":`${e.field.label} for row ${t+1}`})},e.csvIdx)})]},t)})})]}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:o(`grid.import.showingRows`,{shown:c.length,total:t.length})})]})},Un=({objectName:e,objectLabel:t,fields:n,dataSource:r,onComplete:i,onCancel:a,open:o,onOpenChange:s,onErrorMode:c=`skip`,templateStorageKey:l,templateStorage:u})=>{let[d,f]=(0,R.useState)(`upload`),[p,m]=(0,R.useState)([]),[h,g]=(0,R.useState)([]),[_,v]=(0,R.useState)({}),[y,ee]=(0,R.useState)(!1),[te,x]=(0,R.useState)(0),[S,ie]=(0,R.useState)(null),[ae,oe]=(0,R.useState)({}),C=t??e,T=(0,R.useMemo)(()=>u===void 0?Mn():u,[u]),E=l??`objectui:import-templates:${e}`,[D,ce]=(0,R.useState)(()=>Nn(T,E)),[le,ue]=(0,R.useState)(null);(0,R.useEffect)(()=>{ce(Nn(T,E))},[T,E]);let de=(0,R.useCallback)(e=>{let t=D.find(t=>t.id===e);t&&(ue(e),v(In(t,p,n)))},[D,p,n]),O=(0,R.useCallback)(e=>{let t={id:`tpl-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,name:e,mapping:Fn(p,_),updatedAt:Date.now()},n=[...D,t];ce(n),ue(t.id),Pn(T,E,n)},[D,p,_,T,E]),fe=(0,R.useCallback)(()=>{if(!le)return;let e=D.filter(e=>e.id!==le);ce(e),ue(null),Pn(T,E,e)},[D,le,T,E]),me=(0,R.useCallback)((e,t,n)=>{oe(r=>{let i={...r},a={...i[e]??{}};return n===(h[e]?.[t]??``)?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,i})},[h]),he=(0,R.useMemo)(()=>{let e=new Set(Object.values(_));return n.filter(t=>t.required&&!e.has(t.name))},[n,_]),ge=(0,R.useCallback)((e,t)=>{m(e),g(t),v(jn(e,n,t)),oe({}),f(`mapping`)},[n]),ye=(0,R.useMemo)(()=>p.map((e,t)=>Cn(h.map(e=>e[t]))),[p,h]),be=(0,R.useCallback)(async()=>{ee(!0),x(0);let t=[],a=0,o=0,s=Object.entries(_).map(([e,t])=>({csvIdx:Number(e),field:n.find(e=>e.name===t)}));for(let n=0;n<h.length;n++){let i=h[n],l=ae[n],{record:u,errors:d}=Ln(l?i.map((e,t)=>l[t]===void 0?e:l[t]):i,s,n+1);if(d.length>0){if(o++,t.push(...d),c===`stop`)break}else try{r?.create&&await r.create(e,u),a++}catch(e){o++;let r=e instanceof Error?e.message:`Failed to create record`;if(t.push({row:n+1,field:``,message:r}),c===`stop`)break}x(Math.round((n+1)/h.length*100))}let l={totalRows:h.length,importedRows:a,skippedRows:o,errors:t};ie(l),ee(!1),i?.(l)},[h,_,n,r,e,i,c,ae]),xe=(0,R.useCallback)(()=>{f(`upload`),m([]),g([]),v({}),x(0),ie(null),oe({}),ue(null)},[]),A=(0,R.useCallback)(()=>{xe(),s?.(!1),a?.()},[xe,s,a]),{t:j}=Dn();return(0,H.jsx)(ve,{open:o,onOpenChange:e=>{e?s?.(e):A()},children:(0,H.jsxs)(Se,{className:`flex max-h-[85vh] flex-col gap-4 overflow-hidden sm:max-w-4xl`,children:[(0,H.jsxs)(P,{children:[(0,H.jsxs)(se,{className:`flex items-center gap-2`,children:[(0,H.jsx)(ne,{className:`h-5 w-5`}),` `,j(`grid.import.title`,{object:C})]}),(0,H.jsxs)(re,{children:[d===`upload`&&j(`grid.import.uploadDescription`),d===`mapping`&&j(`grid.import.mappingDescription`),d===`preview`&&j(`grid.import.previewDescription`)]})]}),(0,H.jsx)(`div`,{className:`flex items-center justify-center gap-2 text-xs text-muted-foreground`,children:[`upload`,`mapping`,`preview`].map((e,t)=>(0,H.jsxs)(R.Fragment,{children:[t>0&&(0,H.jsx)(M,{className:`h-3 w-3`}),(0,H.jsxs)(`span`,{className:k(`rounded-full px-3 py-1`,d===e?`bg-primary text-primary-foreground`:`bg-muted`),children:[t+1,`. `,j(e===`upload`?`grid.import.stepUpload`:e===`mapping`?`grid.import.stepMapping`:`grid.import.stepPreview`)]})]},e))}),(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:S?(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-4`,children:[(0,H.jsx)(b,{className:`h-10 w-10 text-green-500`}),(0,H.jsx)(`p`,{className:`text-lg font-semibold`,children:j(`grid.import.importComplete`)}),(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[(0,H.jsx)(ke,{variant:`default`,children:j(`grid.import.imported`,{count:S.importedRows})}),S.skippedRows>0&&(0,H.jsx)(ke,{variant:`destructive`,children:j(`grid.import.skippedCount`,{count:S.skippedRows})})]}),S.errors.length>0&&(0,H.jsxs)(`div`,{className:`max-h-32 w-full overflow-auto rounded border p-2 text-xs`,children:[S.errors.slice(0,10).map((e,t)=>(0,H.jsxs)(`p`,{className:`text-destructive`,children:[`Row `,e.row,e.field?` (${e.field})`:``,`: `,e.message]},t)),S.errors.length>10&&(0,H.jsx)(`p`,{className:`text-muted-foreground`,children:j(`grid.import.moreErrors`,{count:S.errors.length-10})})]})]}):(0,H.jsxs)(H.Fragment,{children:[d===`upload`&&(0,H.jsx)(zn,{onFileLoaded:ge}),d===`mapping`&&(0,H.jsx)(Vn,{headers:p,fields:n,mapping:_,onMappingChange:v,inferredTypes:ye,templates:D,selectedTemplateId:le,onSelectTemplate:de,onSaveTemplate:O,onDeleteTemplate:fe}),d===`preview`&&(0,H.jsx)(Hn,{headers:p,rows:h,mapping:_,fields:n,corrections:ae,onCorrect:me}),y&&(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(et,{value:te,className:`h-2`}),(0,H.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:j(`grid.import.importing`,{progress:te})})]})]})}),(0,H.jsx)(w,{className:`gap-2 sm:gap-0`,children:S?(0,H.jsx)(L,{onClick:A,children:j(`grid.import.close`)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(L,{variant:`ghost`,onClick:A,disabled:y,children:[(0,H.jsx)(pe,{className:`mr-1 h-4 w-4`}),` `,j(`grid.import.cancel`)]}),(d===`mapping`||d===`preview`)&&(0,H.jsxs)(L,{variant:`outline`,onClick:()=>f(d===`mapping`?`upload`:`mapping`),disabled:y,children:[(0,H.jsx)(_e,{className:`mr-1 h-4 w-4`}),` `,j(`grid.import.back`)]}),d===`mapping`&&(0,H.jsxs)(L,{onClick:()=>f(`preview`),disabled:Object.keys(_).length===0||he.length>0,children:[j(`grid.import.next`),` `,(0,H.jsx)(M,{className:`ml-1 h-4 w-4`})]}),d===`preview`&&(0,H.jsx)(L,{onClick:be,disabled:y,children:y?j(`grid.import.importingProgress`):j(`grid.import.importNRows`,{count:h.length})})]})})]})})},Q=t({ImportWizard:()=>Un,ObjectGrid:()=>Vt,ObjectGridRenderer:()=>$}),$=({schema:e,...t})=>{let{dataSource:n}=l()||{};return(0,H.jsx)(Vt,{schema:e,dataSource:n,...t})};h.register(`object-grid`,$,{namespace:`plugin-grid`,label:`Object Grid`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`},{name:`filters`,type:`array`,label:`Filters`}]}),h.register(`grid`,$,{namespace:`view`,skipFallback:!0,label:`Data Grid`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`},{name:`filters`,type:`array`,label:`Filters`}]}),h.register(`import-wizard`,({schema:e,...t})=>{let{dataSource:n}=l()||{};return(0,H.jsx)(Un,{objectName:e.objectName,objectLabel:e.objectLabel,fields:e.fields??[],dataSource:n,...t})},{namespace:`plugin-grid`,label:`Import Wizard`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`,required:!0}]});export{dt as a,W as i,ln as n,Vt as r,Q as t};
|