@objectstack/console 7.2.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/assets/{AiPendingActionsPage-B6prPdE6.js → AiPendingActionsPage-DYX4ANzZ.js} +1 -1
  2. package/dist/assets/ApiConsolePage-C70S6MYv.js +1 -0
  3. package/dist/assets/{AppManagementPage-CSGa-1u0.js → AppManagementPage-BnwBNW_m.js} +1 -1
  4. package/dist/assets/ApprovalsInboxPage-CQQmK4Pz.js +1 -0
  5. package/dist/assets/{AuditLogPage-DzIHYkL6.js → AuditLogPage-C1CgKWC8.js} +1 -1
  6. package/dist/assets/{ComponentNavView-CZkyv2fY.js → ComponentNavView-g_X1YUdk.js} +1 -1
  7. package/dist/assets/{ConsoleFloatingChatbot-Dfub90-W.js → ConsoleFloatingChatbot-DJW7zeKU.js} +1 -1
  8. package/dist/assets/{DeveloperHubPage-lLRr5-aY.js → DeveloperHubPage-CcV4mWRr.js} +1 -1
  9. package/dist/assets/FlowRunsPage-Rtd6u1e_.js +1 -0
  10. package/dist/assets/{ProfilePage-B4ZMNend.js → ProfilePage-DPGkAZWG.js} +1 -1
  11. package/dist/assets/PublicFormsPage-BNIOSFr1.js +1 -0
  12. package/dist/assets/{SettingsHub-DrmQJKTl.js → SettingsHub-4RDkAyKq.js} +1 -1
  13. package/dist/assets/{SettingsView-DQ4mtooC.js → SettingsView-_5h2mExc.js} +1 -1
  14. package/dist/assets/{SystemHubPage-CjV_--P3.js → SystemHubPage-DRRxgNWV.js} +1 -1
  15. package/dist/assets/data-adapter-Bi1Re1fK.js +1 -0
  16. package/dist/assets/{framework-DpQcF_QW.js → framework-DVkqUSPj.js} +1 -1
  17. package/dist/assets/{highlighted-body-OFNGDK62-BcbCsvGi.js → highlighted-body-OFNGDK62-Dp9QBuY-.js} +1 -1
  18. package/dist/assets/index-DWtLSzKK.js +33 -0
  19. package/dist/assets/index-JLLCOoA3.css +2 -0
  20. package/dist/assets/mermaid-GHXKKRXX-PDO-QkSF.js +1 -0
  21. package/dist/assets/{plugin-calendar-BGJsyv_O.js → plugin-calendar-D1wyyvEx.js} +1 -1
  22. package/dist/assets/{plugin-charts-CRlZ01tc.js → plugin-charts-DrCI3cJo.js} +2 -2
  23. package/dist/assets/plugin-chatbot-CiVctLlf.js +120 -0
  24. package/dist/assets/plugin-dashboard-BRn9AjyQ.js +3 -0
  25. package/dist/assets/{plugin-form-BzrcwmiI.js → plugin-form-KOOMD5ZY.js} +1 -1
  26. package/dist/assets/{plugin-gantt-Dt2juPb1.js → plugin-gantt-D3OFukY1.js} +1 -1
  27. package/dist/assets/plugin-grid-DGQxmfxn.js +6 -0
  28. package/dist/assets/{plugin-kanban-lsYbj6Vr.js → plugin-kanban-C-qMP4VL.js} +1 -1
  29. package/dist/assets/{plugin-map-BKE-4AVm.js → plugin-map-DRf0LmJy.js} +1 -1
  30. package/dist/assets/{plugin-markdown-bkOWrh0-.js → plugin-markdown-BVFW0U6V.js} +1 -1
  31. package/dist/assets/plugin-report-CJSBthhg.js +59 -0
  32. package/dist/assets/plugin-timeline-RAn1F_nX.js +1 -0
  33. package/dist/assets/plugin-view-DspcF1Mc.js +1 -0
  34. package/dist/assets/plugins-views-DUx-xpiH.js +4 -0
  35. package/dist/assets/{src-0fzF-kZX.js → src-DL8N52oz.js} +1 -1
  36. package/dist/assets/{types-C7d65SSU.js → types-CbmNTewl.js} +1 -1
  37. package/dist/assets/ui-components-CIdYg6m3.js +41 -0
  38. package/dist/assets/ui-layout-DGPxy1gI.js +1 -0
  39. package/dist/assets/vendor-objectstack-B3zP6Fz_.js +65 -0
  40. package/dist/index.html +4 -4
  41. package/package.json +1 -1
  42. package/dist/assets/ApiConsolePage-KLlXE_J-.js +0 -1
  43. package/dist/assets/ApprovalsInboxPage-BOY6Xpsn.js +0 -1
  44. package/dist/assets/FlowRunsPage-DV2m0d1l.js +0 -1
  45. package/dist/assets/PublicFormsPage-CHWj3DL5.js +0 -1
  46. package/dist/assets/data-adapter-CX0Tq3Q5.js +0 -1
  47. package/dist/assets/index-DUV_YMtu.css +0 -2
  48. package/dist/assets/index-hBFJ6de4.js +0 -33
  49. package/dist/assets/mermaid-GHXKKRXX-DLb_WlhX.js +0 -1
  50. package/dist/assets/plugin-chatbot-BhnqfdW0.js +0 -120
  51. package/dist/assets/plugin-dashboard-CUH4Dbo1.js +0 -3
  52. package/dist/assets/plugin-grid-BHnAwQNY.js +0 -6
  53. package/dist/assets/plugin-report-CqzUFpeK.js +0 -59
  54. package/dist/assets/plugin-timeline-ZI65E7h4.js +0 -1
  55. package/dist/assets/plugin-view-CGR-rgKC.js +0 -1
  56. package/dist/assets/plugins-views-CzwBozRK.js +0 -4
  57. package/dist/assets/ui-components-CXy53m_o.js +0 -41
  58. package/dist/assets/ui-layout-BqvRQUkZ.js +0 -1
  59. package/dist/assets/vendor-objectstack-DdIVmQL0.js +0 -65
@@ -1 +1 @@
1
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r,v as i,y as a}from"./vendor-react-CyVA1SE-.js";import{C as o,D as s,E as c,S as l}from"./vendor-objectstack-DdIVmQL0.js";import{H as u,M as d,at as f,ot as p,ut as m}from"./framework-DpQcF_QW.js";import{N as h,_s as g,jt as ee}from"./ui-components-CXy53m_o.js";var _=e(a(),1),v=_.createContext(null);function y(e,t){let n=Array.isArray(e)?e[0]:e?e.x:0,r=Array.isArray(e)?e[1]:e?e.y:0,i=Array.isArray(t)?t[0]:t?t.x:0,a=Array.isArray(t)?t[1]:t?t.y:0;return n===i&&r===a}function b(e,t){if(e===t)return!0;if(!e||!t)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!b(e[n],t[n]))return!1;return!0}else if(Array.isArray(t))return!1;if(typeof e==`object`&&typeof t==`object`){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!t.hasOwnProperty(r)||!b(e[r],t[r]))return!1;return!0}return!1}function x(e){return{longitude:e.center.lng,latitude:e.center.lat,zoom:e.zoom,pitch:e.pitch,bearing:e.bearing,padding:e.padding}}function S(e,t){let n=t.viewState||t,r={};if(`longitude`in n&&`latitude`in n&&(n.longitude!==e.center.lng||n.latitude!==e.center.lat)){let t=e.center.constructor;r.center=new t(n.longitude,n.latitude)}return`zoom`in n&&n.zoom!==e.zoom&&(r.zoom=n.zoom),`bearing`in n&&n.bearing!==e.bearing&&(r.bearing=n.bearing),`pitch`in n&&n.pitch!==e.pitch&&(r.pitch=n.pitch),n.padding&&e.padding&&!b(n.padding,e.padding)&&(r.padding=n.padding),r}var C=[`type`,`source`,`source-layer`,`minzoom`,`maxzoom`,`filter`,`layout`];function w(e){if(!e)return null;if(typeof e==`string`||(`toJS`in e&&(e=e.toJS()),!e.layers))return e;let t={};for(let n of e.layers)t[n.id]=n;let n=e.layers.map(e=>{let n=null;`interactive`in e&&(n=Object.assign({},e),delete n.interactive);let r=t[e.ref];if(r){n||=Object.assign({},e),delete n.ref;for(let e of C)e in r&&(n[e]=r[e])}return n||e});return{...e,layers:n}}var T={version:8,sources:{},layers:[]},E={minZoom:0,maxZoom:22,minPitch:0,maxPitch:85,maxBounds:[-180,-85.051129,180,85.051129],projection:`mercator`,renderWorldCopies:!0},D={mousedown:`onMouseDown`,mouseup:`onMouseUp`,mouseover:`onMouseOver`,mousemove:`onMouseMove`,click:`onClick`,dblclick:`onDblClick`,mouseenter:`onMouseEnter`,mouseleave:`onMouseLeave`,mouseout:`onMouseOut`,contextmenu:`onContextMenu`,touchstart:`onTouchStart`,touchend:`onTouchEnd`,touchmove:`onTouchMove`,touchcancel:`onTouchCancel`},O={movestart:`onMoveStart`,move:`onMove`,moveend:`onMoveEnd`,dragstart:`onDragStart`,drag:`onDrag`,dragend:`onDragEnd`,zoomstart:`onZoomStart`,zoom:`onZoom`,zoomend:`onZoomEnd`,rotatestart:`onRotateStart`,rotate:`onRotate`,rotateend:`onRotateEnd`,pitchstart:`onPitchStart`,pitch:`onPitch`,pitchend:`onPitchEnd`},k={wheel:`onWheel`,boxzoomstart:`onBoxZoomStart`,boxzoomend:`onBoxZoomEnd`,boxzoomcancel:`onBoxZoomCancel`,resize:`onResize`,load:`onLoad`,render:`onRender`,idle:`onIdle`,remove:`onRemove`,data:`onData`,styledata:`onStyleData`,sourcedata:`onSourceData`,error:`onError`},A=[`minZoom`,`maxZoom`,`minPitch`,`maxPitch`,`maxBounds`,`projection`,`renderWorldCopies`],j=[`scrollZoom`,`boxZoom`,`dragRotate`,`dragPan`,`keyboard`,`doubleClickZoom`,`touchZoomRotate`,`touchPitch`],M=class e{constructor(e,t,n){this._map=null,this._internalUpdate=!1,this._hoveredFeatures=null,this._propsedCameraUpdate=null,this._styleComponents={},this._onEvent=e=>{let t=this.props[k[e.type]];t?t(e):e.type===`error`&&console.error(e.error)},this._onCameraEvent=e=>{if(this._internalUpdate)return;e.viewState=this._propsedCameraUpdate||x(this._map.transform);let t=this.props[O[e.type]];t&&t(e)},this._onCameraUpdate=e=>this._internalUpdate?e:(this._propsedCameraUpdate=x(e),S(e,this.props)),this._onPointerEvent=e=>{(e.type===`mousemove`||e.type===`mouseout`)&&this._updateHover(e);let t=this.props[D[e.type]];t&&(this.props.interactiveLayerIds&&e.type!==`mouseover`&&e.type!==`mouseout`&&(e.features=this._hoveredFeatures||this._queryRenderedFeatures(e.point)),t(e),delete e.features)},this._MapClass=e,this.props=t,this._initialize(n)}get map(){return this._map}setProps(e){let t=this.props;this.props=e;let n=this._updateSettings(e,t),r=this._updateSize(e),i=this._updateViewState(e);this._updateStyle(e,t),this._updateStyleComponents(e),this._updateHandlers(e,t),(n||r||i&&!this._map.isMoving())&&this.redraw()}static reuse(t,n){let r=e.savedMaps.pop();if(!r)return null;let i=r.map,a=i.getContainer();for(n.className=a.className;a.childNodes.length>0;)n.appendChild(a.childNodes[0]);i._container=n;let o=i._resizeObserver;o&&(o.disconnect(),o.observe(n)),r.setProps({...t,styleDiffing:!1}),i.resize();let{initialViewState:s}=t;return s&&(s.bounds?i.fitBounds(s.bounds,{...s.fitBoundsOptions,duration:0}):r._updateViewState(s)),i.isStyleLoaded()?i.fire(`load`):i.once(`style.load`,()=>i.fire(`load`)),i._update(),r}_initialize(e){let{props:t}=this,{mapStyle:n=T}=t,r={...t,...t.initialViewState,container:e,style:w(n)},i=r.initialViewState||r.viewState||r;if(Object.assign(r,{center:[i.longitude||0,i.latitude||0],zoom:i.zoom||0,pitch:i.pitch||0,bearing:i.bearing||0}),t.gl){let e=HTMLCanvasElement.prototype.getContext;HTMLCanvasElement.prototype.getContext=()=>(HTMLCanvasElement.prototype.getContext=e,t.gl)}let a=new this._MapClass(r);i.padding&&a.setPadding(i.padding),t.cursor&&(a.getCanvas().style.cursor=t.cursor),a.transformCameraUpdate=this._onCameraUpdate,a.on(`style.load`,()=>{this._styleComponents={light:a.getLight(),sky:a.getSky(),projection:a.getProjection?.(),terrain:a.getTerrain()},this._updateStyleComponents(this.props)}),a.on(`sourcedata`,()=>{this._updateStyleComponents(this.props)});for(let e in D)a.on(e,this._onPointerEvent);for(let e in O)a.on(e,this._onCameraEvent);for(let e in k)a.on(e,this._onEvent);this._map=a}recycle(){this.map.getContainer().querySelector(`[mapboxgl-children]`)?.remove(),e.savedMaps.push(this)}destroy(){this._map.remove()}redraw(){let e=this._map;e.style&&(e._frame&&=(e._frame.cancel(),null),e._render())}_updateSize(e){let{viewState:t}=e;if(t){let e=this._map;if(t.width!==e.transform.width||t.height!==e.transform.height)return e.resize(),!0}return!1}_updateViewState(e){let t=this._map,n=t.transform;if(!t.isMoving()){let r=S(n,e);if(Object.keys(r).length>0)return this._internalUpdate=!0,t.jumpTo(r),this._internalUpdate=!1,!0}return!1}_updateSettings(e,t){let n=this._map,r=!1;for(let i of A)if((i in e||i in t)&&!b(e[i],t[i])){r=!0;let t=i in e?e[i]:E[i];n[`set${i[0].toUpperCase()}${i.slice(1)}`]?.call(n,t)}return r}_updateStyle(e,t){if(e.cursor!==t.cursor&&(this._map.getCanvas().style.cursor=e.cursor||``),e.mapStyle!==t.mapStyle){let{mapStyle:t=T,styleDiffing:n=!0}=e,r={diff:n};`localIdeographFontFamily`in e&&(r.localIdeographFontFamily=e.localIdeographFontFamily),this._map.setStyle(w(t),r)}}_updateStyleComponents({light:e,projection:t,sky:n,terrain:r}){let i=this._map,a=this._styleComponents;i.style?._loaded&&(e&&!b(e,a.light)&&(a.light=e,i.setLight(e)),t&&!b(t,a.projection)&&t!==a.projection?.type&&(a.projection=typeof t==`string`?{type:t}:t,i.setProjection?.(a.projection)),n&&!b(n,a.sky)&&(a.sky=n,i.setSky(n)),r!==void 0&&!b(r,a.terrain)&&(!r||i.getSource(r.source))&&(a.terrain=r,i.setTerrain(r)))}_updateHandlers(e,t){let n=this._map;for(let r of j){let i=e[r]??!0;b(i,t[r]??!0)||(i?n[r].enable(i):n[r].disable())}}_queryRenderedFeatures(e){let t=this._map,{interactiveLayerIds:n=[]}=this.props;try{return t.queryRenderedFeatures(e,{layers:n.filter(t.getLayer.bind(t))})}catch{return[]}}_updateHover(e){let{props:t}=this;if(t.interactiveLayerIds&&(t.onMouseMove||t.onMouseEnter||t.onMouseLeave)){let t=e.type,n=this._hoveredFeatures?.length>0,r=this._queryRenderedFeatures(e.point),i=r.length>0;!i&&n&&(e.type=`mouseleave`,this._onPointerEvent(e)),this._hoveredFeatures=r,i&&!n&&(e.type=`mouseenter`,this._onPointerEvent(e)),e.type=t}else this._hoveredFeatures=null}};M.savedMaps=[];var N=[`setMaxBounds`,`setMinZoom`,`setMaxZoom`,`setMinPitch`,`setMaxPitch`,`setRenderWorldCopies`,`setProjection`,`setStyle`,`addSource`,`removeSource`,`addLayer`,`removeLayer`,`setLayerZoomRange`,`setFilter`,`setPaintProperty`,`setLayoutProperty`,`setLight`,`setTerrain`,`setFog`,`remove`];function P(e){if(!e)return null;let t=e.map,n={getMap:()=>t};for(let e of F(t))!(e in n)&&!N.includes(e)&&(n[e]=t[e].bind(t));return n}function F(e){let t=new Set,n=e;for(;n;){for(let r of Object.getOwnPropertyNames(n))r[0]!==`_`&&typeof e[r]==`function`&&r!==`fire`&&r!==`setEventedParent`&&t.add(r);n=Object.getPrototypeOf(n)}return Array.from(t)}var I=typeof document<`u`?_.useLayoutEffect:_.useEffect;function L(e,t){let{RTLTextPlugin:n,maxParallelImageRequests:r,workerCount:i,workerUrl:a}=t;if(n&&e.getRTLTextPluginStatus&&e.getRTLTextPluginStatus()===`unavailable`){let{pluginUrl:t,lazy:r=!0}=typeof n==`string`?{pluginUrl:n}:n;e.setRTLTextPlugin(t,e=>{e&&console.error(e)},r)}r!==void 0&&e.setMaxParallelImageRequests(r),i!==void 0&&e.setWorkerCount(i),a!==void 0&&e.setWorkerUrl(a)}var R=_.createContext(null);function z(t,r){let i=(0,_.useContext)(v),[a,o]=(0,_.useState)(null),s=(0,_.useRef)(),{current:c}=(0,_.useRef)({mapLib:null,map:null});(0,_.useEffect)(()=>{let r=t.mapLib,a=!0,l;return Promise.resolve(r||n(()=>import(`./maplibre-gl-CoREonuK.js`).then(t=>e(t.default,1)),[],import.meta.url)).then(e=>{if(!a)return;if(!e)throw Error(`Invalid mapLib`);let n=`Map`in e?e:e.default;if(!n.Map)throw Error(`Invalid mapLib`);L(n,t),t.reuseMaps&&(l=M.reuse(t,s.current)),l||=new M(n.Map,t,s.current),c.map=P(l),c.mapLib=n,o(l),i?.onMapMount(c.map,t.id)}).catch(e=>{let{onError:n}=t;n?n({type:`error`,target:null,originalEvent:null,error:e}):console.error(e)}),()=>{a=!1,l&&(i?.onMapUnmount(t.id),t.reuseMaps?l.recycle():l.destroy())}},[]),I(()=>{a&&a.setProps(t)}),(0,_.useImperativeHandle)(r,()=>c.map,[a]);let l=(0,_.useMemo)(()=>({position:`relative`,width:`100%`,height:`100%`,...t.style}),[t.style]);return _.createElement(`div`,{id:t.id,ref:s,style:l},a&&_.createElement(R.Provider,{value:c},_.createElement(`div`,{"mapboxgl-children":``,style:{height:`100%`}},t.children)))}var te=_.forwardRef(z),B=e(i(),1),V=/box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;function H(e,t){if(!e||!t)return;let n=e.style;for(let e in t){let r=t[e];Number.isFinite(r)&&!V.test(e)?n[e]=`${r}px`:n[e]=r}}function U(e,t){if(e===t)return null;let n=W(e),r=W(t),i=[];for(let e of r)n.has(e)||i.push(e);for(let e of n)r.has(e)||i.push(e);return i.length===0?null:i}function W(e){return new Set(e?e.trim().split(/\s+/):[])}var G=(0,_.memo)((0,_.forwardRef)((e,t)=>{let{map:n,mapLib:r}=(0,_.useContext)(R),i=(0,_.useRef)({props:e}),a=(0,_.useMemo)(()=>{let t=!1;_.Children.forEach(e.children,e=>{e&&(t=!0)});let n={...e,element:t?document.createElement(`div`):void 0},o=new r.Marker(n);return o.setLngLat([e.longitude,e.latitude]),o.getElement().addEventListener(`click`,e=>{i.current.props.onClick?.({type:`click`,target:o,originalEvent:e})}),o.on(`dragstart`,e=>{let t=e;t.lngLat=a.getLngLat(),i.current.props.onDragStart?.(t)}),o.on(`drag`,e=>{let t=e;t.lngLat=a.getLngLat(),i.current.props.onDrag?.(t)}),o.on(`dragend`,e=>{let t=e;t.lngLat=a.getLngLat(),i.current.props.onDragEnd?.(t)}),o},[]);(0,_.useEffect)(()=>(a.addTo(n.getMap()),()=>{a.remove()}),[]);let{longitude:o,latitude:s,offset:c,style:l,draggable:u=!1,popup:d=null,rotation:f=0,rotationAlignment:p=`auto`,pitchAlignment:m=`auto`}=e;(0,_.useEffect)(()=>{H(a.getElement(),l)},[l]),(0,_.useImperativeHandle)(t,()=>a,[]);let h=i.current.props;(a.getLngLat().lng!==o||a.getLngLat().lat!==s)&&a.setLngLat([o,s]),c&&!y(a.getOffset(),c)&&a.setOffset(c),a.isDraggable()!==u&&a.setDraggable(u),a.getRotation()!==f&&a.setRotation(f),a.getRotationAlignment()!==p&&a.setRotationAlignment(p),a.getPitchAlignment()!==m&&a.setPitchAlignment(m),a.getPopup()!==d&&a.setPopup(d);let g=U(h.className,e.className);if(g)for(let e of g)a.toggleClassName(e);return i.current.props=e,(0,B.createPortal)(e.children,a.getElement())})),ne=(0,_.memo)((0,_.forwardRef)((e,t)=>{let{map:n,mapLib:r}=(0,_.useContext)(R),i=(0,_.useMemo)(()=>document.createElement(`div`),[]),a=(0,_.useRef)({props:e}),o=(0,_.useMemo)(()=>{let t={...e},n=new r.Popup(t);return n.setLngLat([e.longitude,e.latitude]),n.once(`open`,e=>{a.current.props.onOpen?.(e)}),n},[]);if((0,_.useEffect)(()=>{let e=e=>{a.current.props.onClose?.(e)};return o.on(`close`,e),o.setDOMContent(i).addTo(n.getMap()),()=>{o.off(`close`,e),o.isOpen()&&o.remove()}},[]),(0,_.useEffect)(()=>{H(o.getElement(),e.style)},[e.style]),(0,_.useImperativeHandle)(t,()=>o,[]),o.isOpen()){let t=a.current.props;(o.getLngLat().lng!==e.longitude||o.getLngLat().lat!==e.latitude)&&o.setLngLat([e.longitude,e.latitude]),e.offset&&!b(t.offset,e.offset)&&o.setOffset(e.offset),(t.anchor!==e.anchor||t.maxWidth!==e.maxWidth)&&(o.options.anchor=e.anchor,o.setMaxWidth(e.maxWidth));let n=U(t.className,e.className);if(n)for(let e of n)o.toggleClassName(e);a.current.props=e}return(0,B.createPortal)(e.children,i)}));function K(e,t,n,r){let i=(0,_.useContext)(R),a=(0,_.useMemo)(()=>e(i),[]);return(0,_.useEffect)(()=>{let e=r||n||t,o=typeof t==`function`&&typeof n==`function`?t:null,s=typeof n==`function`?n:typeof t==`function`?t:null,{map:c}=i;return c.hasControl(a)||(c.addControl(a,e?.position),o&&o(i)),()=>{s&&s(i),c.hasControl(a)&&c.removeControl(a)}},[]),a}function q(e){let t=K(({mapLib:t})=>new t.AttributionControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}(0,_.memo)(q);function J(e){let t=K(({mapLib:t})=>new t.FullscreenControl({container:e.containerId&&document.getElementById(e.containerId)}),{position:e.position});return(0,_.useEffect)(()=>{H(t._controlContainer,e.style)},[e.style]),null}(0,_.memo)(J);function Y(e,t){let n=(0,_.useRef)({props:e}),r=K(({mapLib:t})=>{let r=new t.GeolocateControl(e),i=r._setupUI;return r._setupUI=()=>{r._container.hasChildNodes()||i()},r.on(`geolocate`,e=>{n.current.props.onGeolocate?.(e)}),r.on(`error`,e=>{n.current.props.onError?.(e)}),r.on(`outofmaxbounds`,e=>{n.current.props.onOutOfMaxBounds?.(e)}),r.on(`trackuserlocationstart`,e=>{n.current.props.onTrackUserLocationStart?.(e)}),r.on(`trackuserlocationend`,e=>{n.current.props.onTrackUserLocationEnd?.(e)}),r},{position:e.position});return n.current.props=e,(0,_.useImperativeHandle)(t,()=>r,[]),(0,_.useEffect)(()=>{H(r._container,e.style)},[e.style]),null}(0,_.memo)((0,_.forwardRef)(Y));function X(e){let t=K(({mapLib:t})=>new t.NavigationControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}var re=(0,_.memo)(X);function ie(e){let t=K(({mapLib:t})=>new t.ScaleControl(e),{position:e.position}),n=(0,_.useRef)(e),r=n.current;n.current=e;let{style:i}=e;return e.maxWidth!==void 0&&e.maxWidth!==r.maxWidth&&(t.options.maxWidth=e.maxWidth),e.unit!==void 0&&e.unit!==r.unit&&t.setUnit(e.unit),(0,_.useEffect)(()=>{H(t._container,i)},[i]),null}(0,_.memo)(ie);function ae(e){let t=K(({mapLib:t})=>new t.TerrainControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}(0,_.memo)(ae);function oe(e){let t=K(({mapLib:t})=>new t.LogoControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}(0,_.memo)(oe);var Z=r(),se=o({latitudeField:c().optional(),longitudeField:c().optional(),locationField:c().optional(),titleField:c().optional(),descriptionField:c().optional(),zoom:l().optional(),center:s([l(),l()]).optional()});function ce(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function le(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 ue(e){if(e.locationField||e.latitudeField)return{locationField:e.locationField,latitudeField:e.latitudeField,longitudeField:e.longitudeField,titleField:e.titleField||`name`,descriptionField:e.descriptionField,zoom:e.zoom,center:e.center};let t=null;if(e.filter&&typeof e.filter==`object`&&`map`in e.filter?t=e.filter.map:e.map&&(t=e.map),t){let e=se.safeParse(t);return e.success||console.warn(`[ObjectMap] Invalid map configuration:`,e.error.format()),t}return{latitudeField:`latitude`,longitudeField:`longitude`,locationField:`location`,titleField:`name`,descriptionField:`description`,zoom:10,center:[0,0]}}function de(e,t){if(t.latitudeField&&t.longitudeField){let n=e[t.latitudeField],r=e[t.longitudeField];if(typeof n==`number`&&typeof r==`number`)return[n,r]}if(t.locationField){let n=e[t.locationField];if(typeof n==`object`&&n){let e=n.lat||n.latitude,t=n.lng||n.lon||n.longitude;if(typeof e==`number`&&typeof t==`number`)return[e,t]}if(typeof n==`string`){let e=n.split(`,`).map(e=>parseFloat(e.trim()));if(e.length===2&&!isNaN(e[0])&&!isNaN(e[1]))return[e[0],e[1]]}if(Array.isArray(n)&&n.length===2){let e=parseFloat(n[0]),t=parseFloat(n[1]);if(!isNaN(e)&&!isNaN(t))return[e,t]}}return null}function fe(e,t,n=50){if(e.length<=1||t>=15)return e.map(e=>({id:e.id,coordinates:e.coordinates,markers:[e],isCluster:!1}));let r=n/2**t,i=new Map;e.forEach(e=>{let t=`${Math.floor(e.coordinates[0]/r)}:${Math.floor(e.coordinates[1]/r)}`;i.has(t)||i.set(t,[]),i.get(t).push(e)});let a=[];return i.forEach((e,t)=>{if(e.length===1)a.push({id:e[0].id,coordinates:e[0].coordinates,markers:e,isCluster:!1});else{let n=e.reduce((e,t)=>e+t.coordinates[0],0)/e.length,r=e.reduce((e,t)=>e+t.coordinates[1],0)/e.length;a.push({id:`cluster-${t}`,coordinates:[n,r],markers:e,isCluster:!0})}}),a}var Q=({schema:e,dataSource:t,className:n,onMarkerClick:r,onRowClick:i,onEdit:a,onDelete:o,enableClustering:s,clusterRadius:c=50,...l})=>{let[u,m]=(0,_.useState)([]),[v,y]=(0,_.useState)(!0),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(null),[E,D]=(0,_.useState)(``),O=ee(),k=(0,_.useRef)(null),[A,j]=(0,_.useState)(null),[M,N]=(0,_.useState)(null),[P,F]=(0,_.useState)(!1),I=(0,_.useCallback)(()=>{if(typeof navigator>`u`||!navigator.geolocation){N(`Geolocation is not available in this browser.`);return}F(!0),N(null),navigator.geolocation.getCurrentPosition(e=>{let{longitude:t,latitude:n}=e.coords;j({lng:t,lat:n}),F(!1);try{k.current?.flyTo({center:[t,n],zoom:12,duration:800})}catch{}},e=>{F(!1),N(e.message||`Unable to retrieve location.`)},{enableHighAccuracy:!1,timeout:8e3,maximumAge:6e4})},[]),L=ce(e),R=(0,_.useMemo)(()=>L,[JSON.stringify(L)]),z=ue(e),B=R?.provider===`value`;(0,_.useEffect)(()=>{(async()=>{try{if(y(!0),l.data){let e=l.data;if(Array.isArray(e)){m(e),y(!1);return}}if(e.data){let t=e.data;if(Array.isArray(t)){m(t),y(!1);return}}if(B&&R?.provider===`value`){m(R.items),y(!1);return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(R?.provider===`object`){let n=R.object,r=f(S?.fields);m(p(await t.find(n,{$filter:e.filter,$orderby:le(e.sort),...r.length>0?{$expand:r}:{}})))}else R?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectMap`),m([]));y(!1)}catch(e){x(e),y(!1)}})()},[R,t,B,e.filter,e.sort,S]),(0,_.useEffect)(()=>{!B&&t&&(async()=>{try{if(!t)return;let n=R?.provider===`object`?R.object:e.objectName;if(!n)return;C(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,B,R]);let{markers:V,invalidCount:H}=(0,_.useMemo)(()=>{let e=0;return{markers:u.map((t,n)=>{let r=de(t,z);if(!r)return e++,null;let i=z.titleField?t[z.titleField]:`Marker`,a=z.descriptionField?t[z.descriptionField]:void 0,[o,s]=r;return!isFinite(o)||!isFinite(s)||o<-90||o>90||s<-180||s>180?(e++,null):{id:t.id||t._id||`marker-${n}`,title:i,description:a,coordinates:[s,o],data:t}}).filter(e=>e!==null),invalidCount:e}},[u,z]),U=(0,_.useMemo)(()=>V.find(e=>e.id===w),[V,w]),[W,K]=(0,_.useState)(z.zoom||3),q=d({navigation:e.navigation,objectName:e.objectName,onRowClick:i}),J=(0,_.useMemo)(()=>{if(!E.trim())return V;let e=E.toLowerCase();return V.filter(t=>t.title?.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[V,E]),Y=(0,_.useMemo)(()=>s??(e.enableClustering||J.length>100)?fe(J,W,c):J.map(e=>({id:e.id,coordinates:e.coordinates,markers:[e],isCluster:!1})),[J,W,s,c,e]),X=(0,_.useMemo)(()=>{if(!J.length)return{longitude:z.center?.[1]||0,latitude:z.center?.[0]||0,zoom:z.zoom||2};let e=J.map(e=>e.coordinates[0]),t=J.map(e=>e.coordinates[1]),n=Math.min(...e),r=Math.max(...e),i=Math.min(...t),a=Math.max(...t);return{longitude:(n+r)/2,latitude:(i+a)/2,zoom:z.zoom||3}},[J,z]);return v?(0,Z.jsx)(`div`,{className:g(`min-w-0 overflow-hidden`,n),children:(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-96 bg-muted rounded-lg border`,children:(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading map...`})})}):b?(0,Z.jsx)(`div`,{className:g(`min-w-0 overflow-hidden`,n),children:(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-96 bg-muted rounded-lg border`,children:(0,Z.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,b.message]})})}):(0,Z.jsxs)(`div`,{className:g(`min-w-0 overflow-hidden`,n),children:[H>0&&(0,Z.jsx)(`div`,{className:`mb-2 p-2 text-sm text-yellow-800 bg-yellow-50 border border-yellow-200 rounded`,children:`${H} record${H===1?``:`s`} with missing or invalid coordinates excluded from the map.`}),V.length>0&&(0,Z.jsx)(`div`,{className:`mb-2`,children:(0,Z.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`Search locations…`,className:`w-full px-3 py-2 text-sm border rounded-md bg-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})}),(0,Z.jsxs)(`div`,{className:`relative border rounded-lg overflow-hidden bg-muted h-[300px] sm:h-[400px] md:h-[500px] lg:h-[600px] w-full`,children:[(0,Z.jsxs)(te,{ref:e=>{k.current=e},initialViewState:X,style:{width:`100%`,height:`100%`},mapStyle:`https://demotiles.maplibre.org/style.json`,touchZoomRotate:!0,dragRotate:!0,touchPitch:!0,onZoom:e=>K(Math.round(e.viewState.zoom)),children:[(0,Z.jsx)(re,{position:`top-right`,showCompass:!0,showZoom:!0}),(0,Z.jsx)(`button`,{type:`button`,onClick:I,disabled:P,className:`absolute top-2 left-2 z-10 inline-flex items-center justify-center size-9 rounded-md bg-background/95 border shadow-sm hover:bg-background disabled:opacity-50`,"aria-label":`Show my location`,"data-testid":`map-geolocate`,children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:P?`⏳`:`🧭`})}),A&&(0,Z.jsx)(G,{longitude:A.lng,latitude:A.lat,anchor:`center`,children:(0,Z.jsx)(`div`,{className:`size-3 rounded-full bg-blue-500 ring-4 ring-blue-500/30 shadow`,"aria-label":`Your location`,"data-testid":`map-user-location`})}),Y.map(e=>e.isCluster?(0,Z.jsx)(G,{longitude:e.coordinates[0],latitude:e.coordinates[1],anchor:`center`,onClick:t=>{t.originalEvent.stopPropagation();try{let t=Math.min(20,Math.max(W+2,8));k.current?.flyTo({center:[e.coordinates[0],e.coordinates[1]],zoom:t,duration:600})}catch{}},children:(0,Z.jsx)(`div`,{className:`flex items-center justify-center rounded-full bg-primary text-primary-foreground font-bold text-xs cursor-pointer hover:scale-110 transition-transform shadow-md`,style:{width:Math.min(48,24+e.markers.length*2),height:Math.min(48,24+e.markers.length*2)},title:`${e.markers.length} markers`,"data-testid":`map-cluster`,children:e.markers.length})},e.id):(0,Z.jsx)(G,{longitude:e.coordinates[0],latitude:e.coordinates[1],anchor:`bottom`,onClick:t=>{t.originalEvent.stopPropagation();let n=e.markers[0];T(n.id),q.handleClick(n.data),r?.(n.data)},children:(0,Z.jsx)(`div`,{className:`text-2xl cursor-pointer hover:scale-110 transition-transform`,children:`📍`})},e.id)),U&&!O&&(0,Z.jsx)(ne,{longitude:U.coordinates[0],latitude:U.coordinates[1],anchor:`top`,onClose:()=>T(null),closeOnClick:!1,children:(0,Z.jsxs)(`div`,{className:`p-2 min-w-[150px] sm:min-w-[200px]`,children:[(0,Z.jsx)(`h3`,{className:`font-bold text-sm mb-1`,children:U.title}),U.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:U.description}),(0,Z.jsxs)(`div`,{className:`mt-2 text-xs flex gap-2`,children:[a&&(0,Z.jsx)(`button`,{className:`text-blue-500 hover:underline`,onClick:()=>a(U.data),children:`Edit`}),o&&(0,Z.jsx)(`button`,{className:`text-red-500 hover:underline`,onClick:()=>o(U.data),children:`Delete`})]})]})})]}),U&&O&&(0,Z.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 z-30 bg-background border-t shadow-lg rounded-t-2xl p-4 pb-[max(env(safe-area-inset-bottom),1rem)]`,role:`dialog`,"aria-label":`Location details`,"data-testid":`map-mobile-record-sheet`,children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-2 h-1 w-10 rounded-full bg-muted`,"aria-hidden":`true`}),(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold truncate`,children:U.title}),U.description&&(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground line-clamp-3`,children:U.description})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>T(null),className:`text-muted-foreground hover:text-foreground text-lg leading-none px-2`,"aria-label":`Close details`,"data-testid":`map-mobile-record-close`,children:`×`})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-xs`,children:[a&&(0,Z.jsx)(`button`,{className:`px-3 py-1.5 rounded-md border bg-card hover:bg-accent`,onClick:()=>a(U.data),children:`Edit`}),o&&(0,Z.jsx)(`button`,{className:`px-3 py-1.5 rounded-md border border-destructive/30 text-destructive hover:bg-destructive/10`,onClick:()=>o(U.data),children:`Delete`})]})]}),M&&(0,Z.jsx)(`div`,{className:`absolute top-2 left-14 right-2 z-10 text-xs px-3 py-1.5 rounded-md bg-destructive/10 text-destructive border border-destructive/30`,children:M})]}),q.isOverlay&&(0,Z.jsx)(h,{...q,title:`Location Details`,children:e=>(0,Z.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,Z.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},pe=t({ObjectMap:()=>Q,ObjectMapRenderer:()=>$}),$=({schema:e,...t})=>{let{dataSource:n}=u()||{};return(0,Z.jsx)(Q,{schema:e,dataSource:n,...t})};console.log(`Registering object-map...`),m.register(`object-map`,$,{namespace:`plugin-map`,label:`Object Map`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`map`,type:`object`,label:`Map Config`,description:`latitudeField, longitudeField, titleField`}]}),m.register(`map`,$,{namespace:`view`,label:`Map View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`map`,type:`object`,label:`Map Config`,description:`latitudeField, longitudeField, titleField`}]});export{pe as t};
1
+ import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r,v as i,y as a}from"./vendor-react-CyVA1SE-.js";import{E as o,S as s,T as c,x as l}from"./vendor-objectstack-B3zP6Fz_.js";import{H as u,M as d,at as f,ot as p,ut as m}from"./framework-DVkqUSPj.js";import{As as h,N as g,jt as ee}from"./ui-components-CIdYg6m3.js";var _=e(a(),1),v=_.createContext(null);function y(e,t){let n=Array.isArray(e)?e[0]:e?e.x:0,r=Array.isArray(e)?e[1]:e?e.y:0,i=Array.isArray(t)?t[0]:t?t.x:0,a=Array.isArray(t)?t[1]:t?t.y:0;return n===i&&r===a}function b(e,t){if(e===t)return!0;if(!e||!t)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!b(e[n],t[n]))return!1;return!0}else if(Array.isArray(t))return!1;if(typeof e==`object`&&typeof t==`object`){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!t.hasOwnProperty(r)||!b(e[r],t[r]))return!1;return!0}return!1}function x(e){return{longitude:e.center.lng,latitude:e.center.lat,zoom:e.zoom,pitch:e.pitch,bearing:e.bearing,padding:e.padding}}function S(e,t){let n=t.viewState||t,r={};if(`longitude`in n&&`latitude`in n&&(n.longitude!==e.center.lng||n.latitude!==e.center.lat)){let t=e.center.constructor;r.center=new t(n.longitude,n.latitude)}return`zoom`in n&&n.zoom!==e.zoom&&(r.zoom=n.zoom),`bearing`in n&&n.bearing!==e.bearing&&(r.bearing=n.bearing),`pitch`in n&&n.pitch!==e.pitch&&(r.pitch=n.pitch),n.padding&&e.padding&&!b(n.padding,e.padding)&&(r.padding=n.padding),r}var C=[`type`,`source`,`source-layer`,`minzoom`,`maxzoom`,`filter`,`layout`];function w(e){if(!e)return null;if(typeof e==`string`||(`toJS`in e&&(e=e.toJS()),!e.layers))return e;let t={};for(let n of e.layers)t[n.id]=n;let n=e.layers.map(e=>{let n=null;`interactive`in e&&(n=Object.assign({},e),delete n.interactive);let r=t[e.ref];if(r){n||=Object.assign({},e),delete n.ref;for(let e of C)e in r&&(n[e]=r[e])}return n||e});return{...e,layers:n}}var T={version:8,sources:{},layers:[]},E={minZoom:0,maxZoom:22,minPitch:0,maxPitch:85,maxBounds:[-180,-85.051129,180,85.051129],projection:`mercator`,renderWorldCopies:!0},D={mousedown:`onMouseDown`,mouseup:`onMouseUp`,mouseover:`onMouseOver`,mousemove:`onMouseMove`,click:`onClick`,dblclick:`onDblClick`,mouseenter:`onMouseEnter`,mouseleave:`onMouseLeave`,mouseout:`onMouseOut`,contextmenu:`onContextMenu`,touchstart:`onTouchStart`,touchend:`onTouchEnd`,touchmove:`onTouchMove`,touchcancel:`onTouchCancel`},O={movestart:`onMoveStart`,move:`onMove`,moveend:`onMoveEnd`,dragstart:`onDragStart`,drag:`onDrag`,dragend:`onDragEnd`,zoomstart:`onZoomStart`,zoom:`onZoom`,zoomend:`onZoomEnd`,rotatestart:`onRotateStart`,rotate:`onRotate`,rotateend:`onRotateEnd`,pitchstart:`onPitchStart`,pitch:`onPitch`,pitchend:`onPitchEnd`},k={wheel:`onWheel`,boxzoomstart:`onBoxZoomStart`,boxzoomend:`onBoxZoomEnd`,boxzoomcancel:`onBoxZoomCancel`,resize:`onResize`,load:`onLoad`,render:`onRender`,idle:`onIdle`,remove:`onRemove`,data:`onData`,styledata:`onStyleData`,sourcedata:`onSourceData`,error:`onError`},A=[`minZoom`,`maxZoom`,`minPitch`,`maxPitch`,`maxBounds`,`projection`,`renderWorldCopies`],j=[`scrollZoom`,`boxZoom`,`dragRotate`,`dragPan`,`keyboard`,`doubleClickZoom`,`touchZoomRotate`,`touchPitch`],M=class e{constructor(e,t,n){this._map=null,this._internalUpdate=!1,this._hoveredFeatures=null,this._propsedCameraUpdate=null,this._styleComponents={},this._onEvent=e=>{let t=this.props[k[e.type]];t?t(e):e.type===`error`&&console.error(e.error)},this._onCameraEvent=e=>{if(this._internalUpdate)return;e.viewState=this._propsedCameraUpdate||x(this._map.transform);let t=this.props[O[e.type]];t&&t(e)},this._onCameraUpdate=e=>this._internalUpdate?e:(this._propsedCameraUpdate=x(e),S(e,this.props)),this._onPointerEvent=e=>{(e.type===`mousemove`||e.type===`mouseout`)&&this._updateHover(e);let t=this.props[D[e.type]];t&&(this.props.interactiveLayerIds&&e.type!==`mouseover`&&e.type!==`mouseout`&&(e.features=this._hoveredFeatures||this._queryRenderedFeatures(e.point)),t(e),delete e.features)},this._MapClass=e,this.props=t,this._initialize(n)}get map(){return this._map}setProps(e){let t=this.props;this.props=e;let n=this._updateSettings(e,t),r=this._updateSize(e),i=this._updateViewState(e);this._updateStyle(e,t),this._updateStyleComponents(e),this._updateHandlers(e,t),(n||r||i&&!this._map.isMoving())&&this.redraw()}static reuse(t,n){let r=e.savedMaps.pop();if(!r)return null;let i=r.map,a=i.getContainer();for(n.className=a.className;a.childNodes.length>0;)n.appendChild(a.childNodes[0]);i._container=n;let o=i._resizeObserver;o&&(o.disconnect(),o.observe(n)),r.setProps({...t,styleDiffing:!1}),i.resize();let{initialViewState:s}=t;return s&&(s.bounds?i.fitBounds(s.bounds,{...s.fitBoundsOptions,duration:0}):r._updateViewState(s)),i.isStyleLoaded()?i.fire(`load`):i.once(`style.load`,()=>i.fire(`load`)),i._update(),r}_initialize(e){let{props:t}=this,{mapStyle:n=T}=t,r={...t,...t.initialViewState,container:e,style:w(n)},i=r.initialViewState||r.viewState||r;if(Object.assign(r,{center:[i.longitude||0,i.latitude||0],zoom:i.zoom||0,pitch:i.pitch||0,bearing:i.bearing||0}),t.gl){let e=HTMLCanvasElement.prototype.getContext;HTMLCanvasElement.prototype.getContext=()=>(HTMLCanvasElement.prototype.getContext=e,t.gl)}let a=new this._MapClass(r);i.padding&&a.setPadding(i.padding),t.cursor&&(a.getCanvas().style.cursor=t.cursor),a.transformCameraUpdate=this._onCameraUpdate,a.on(`style.load`,()=>{this._styleComponents={light:a.getLight(),sky:a.getSky(),projection:a.getProjection?.(),terrain:a.getTerrain()},this._updateStyleComponents(this.props)}),a.on(`sourcedata`,()=>{this._updateStyleComponents(this.props)});for(let e in D)a.on(e,this._onPointerEvent);for(let e in O)a.on(e,this._onCameraEvent);for(let e in k)a.on(e,this._onEvent);this._map=a}recycle(){this.map.getContainer().querySelector(`[mapboxgl-children]`)?.remove(),e.savedMaps.push(this)}destroy(){this._map.remove()}redraw(){let e=this._map;e.style&&(e._frame&&=(e._frame.cancel(),null),e._render())}_updateSize(e){let{viewState:t}=e;if(t){let e=this._map;if(t.width!==e.transform.width||t.height!==e.transform.height)return e.resize(),!0}return!1}_updateViewState(e){let t=this._map,n=t.transform;if(!t.isMoving()){let r=S(n,e);if(Object.keys(r).length>0)return this._internalUpdate=!0,t.jumpTo(r),this._internalUpdate=!1,!0}return!1}_updateSettings(e,t){let n=this._map,r=!1;for(let i of A)if((i in e||i in t)&&!b(e[i],t[i])){r=!0;let t=i in e?e[i]:E[i];n[`set${i[0].toUpperCase()}${i.slice(1)}`]?.call(n,t)}return r}_updateStyle(e,t){if(e.cursor!==t.cursor&&(this._map.getCanvas().style.cursor=e.cursor||``),e.mapStyle!==t.mapStyle){let{mapStyle:t=T,styleDiffing:n=!0}=e,r={diff:n};`localIdeographFontFamily`in e&&(r.localIdeographFontFamily=e.localIdeographFontFamily),this._map.setStyle(w(t),r)}}_updateStyleComponents({light:e,projection:t,sky:n,terrain:r}){let i=this._map,a=this._styleComponents;i.style?._loaded&&(e&&!b(e,a.light)&&(a.light=e,i.setLight(e)),t&&!b(t,a.projection)&&t!==a.projection?.type&&(a.projection=typeof t==`string`?{type:t}:t,i.setProjection?.(a.projection)),n&&!b(n,a.sky)&&(a.sky=n,i.setSky(n)),r!==void 0&&!b(r,a.terrain)&&(!r||i.getSource(r.source))&&(a.terrain=r,i.setTerrain(r)))}_updateHandlers(e,t){let n=this._map;for(let r of j){let i=e[r]??!0;b(i,t[r]??!0)||(i?n[r].enable(i):n[r].disable())}}_queryRenderedFeatures(e){let t=this._map,{interactiveLayerIds:n=[]}=this.props;try{return t.queryRenderedFeatures(e,{layers:n.filter(t.getLayer.bind(t))})}catch{return[]}}_updateHover(e){let{props:t}=this;if(t.interactiveLayerIds&&(t.onMouseMove||t.onMouseEnter||t.onMouseLeave)){let t=e.type,n=this._hoveredFeatures?.length>0,r=this._queryRenderedFeatures(e.point),i=r.length>0;!i&&n&&(e.type=`mouseleave`,this._onPointerEvent(e)),this._hoveredFeatures=r,i&&!n&&(e.type=`mouseenter`,this._onPointerEvent(e)),e.type=t}else this._hoveredFeatures=null}};M.savedMaps=[];var N=[`setMaxBounds`,`setMinZoom`,`setMaxZoom`,`setMinPitch`,`setMaxPitch`,`setRenderWorldCopies`,`setProjection`,`setStyle`,`addSource`,`removeSource`,`addLayer`,`removeLayer`,`setLayerZoomRange`,`setFilter`,`setPaintProperty`,`setLayoutProperty`,`setLight`,`setTerrain`,`setFog`,`remove`];function P(e){if(!e)return null;let t=e.map,n={getMap:()=>t};for(let e of F(t))!(e in n)&&!N.includes(e)&&(n[e]=t[e].bind(t));return n}function F(e){let t=new Set,n=e;for(;n;){for(let r of Object.getOwnPropertyNames(n))r[0]!==`_`&&typeof e[r]==`function`&&r!==`fire`&&r!==`setEventedParent`&&t.add(r);n=Object.getPrototypeOf(n)}return Array.from(t)}var I=typeof document<`u`?_.useLayoutEffect:_.useEffect;function L(e,t){let{RTLTextPlugin:n,maxParallelImageRequests:r,workerCount:i,workerUrl:a}=t;if(n&&e.getRTLTextPluginStatus&&e.getRTLTextPluginStatus()===`unavailable`){let{pluginUrl:t,lazy:r=!0}=typeof n==`string`?{pluginUrl:n}:n;e.setRTLTextPlugin(t,e=>{e&&console.error(e)},r)}r!==void 0&&e.setMaxParallelImageRequests(r),i!==void 0&&e.setWorkerCount(i),a!==void 0&&e.setWorkerUrl(a)}var R=_.createContext(null);function z(t,r){let i=(0,_.useContext)(v),[a,o]=(0,_.useState)(null),s=(0,_.useRef)(),{current:c}=(0,_.useRef)({mapLib:null,map:null});(0,_.useEffect)(()=>{let r=t.mapLib,a=!0,l;return Promise.resolve(r||n(()=>import(`./maplibre-gl-CoREonuK.js`).then(t=>e(t.default,1)),[],import.meta.url)).then(e=>{if(!a)return;if(!e)throw Error(`Invalid mapLib`);let n=`Map`in e?e:e.default;if(!n.Map)throw Error(`Invalid mapLib`);L(n,t),t.reuseMaps&&(l=M.reuse(t,s.current)),l||=new M(n.Map,t,s.current),c.map=P(l),c.mapLib=n,o(l),i?.onMapMount(c.map,t.id)}).catch(e=>{let{onError:n}=t;n?n({type:`error`,target:null,originalEvent:null,error:e}):console.error(e)}),()=>{a=!1,l&&(i?.onMapUnmount(t.id),t.reuseMaps?l.recycle():l.destroy())}},[]),I(()=>{a&&a.setProps(t)}),(0,_.useImperativeHandle)(r,()=>c.map,[a]);let l=(0,_.useMemo)(()=>({position:`relative`,width:`100%`,height:`100%`,...t.style}),[t.style]);return _.createElement(`div`,{id:t.id,ref:s,style:l},a&&_.createElement(R.Provider,{value:c},_.createElement(`div`,{"mapboxgl-children":``,style:{height:`100%`}},t.children)))}var te=_.forwardRef(z),B=e(i(),1),V=/box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;function H(e,t){if(!e||!t)return;let n=e.style;for(let e in t){let r=t[e];Number.isFinite(r)&&!V.test(e)?n[e]=`${r}px`:n[e]=r}}function U(e,t){if(e===t)return null;let n=W(e),r=W(t),i=[];for(let e of r)n.has(e)||i.push(e);for(let e of n)r.has(e)||i.push(e);return i.length===0?null:i}function W(e){return new Set(e?e.trim().split(/\s+/):[])}var G=(0,_.memo)((0,_.forwardRef)((e,t)=>{let{map:n,mapLib:r}=(0,_.useContext)(R),i=(0,_.useRef)({props:e}),a=(0,_.useMemo)(()=>{let t=!1;_.Children.forEach(e.children,e=>{e&&(t=!0)});let n={...e,element:t?document.createElement(`div`):void 0},o=new r.Marker(n);return o.setLngLat([e.longitude,e.latitude]),o.getElement().addEventListener(`click`,e=>{i.current.props.onClick?.({type:`click`,target:o,originalEvent:e})}),o.on(`dragstart`,e=>{let t=e;t.lngLat=a.getLngLat(),i.current.props.onDragStart?.(t)}),o.on(`drag`,e=>{let t=e;t.lngLat=a.getLngLat(),i.current.props.onDrag?.(t)}),o.on(`dragend`,e=>{let t=e;t.lngLat=a.getLngLat(),i.current.props.onDragEnd?.(t)}),o},[]);(0,_.useEffect)(()=>(a.addTo(n.getMap()),()=>{a.remove()}),[]);let{longitude:o,latitude:s,offset:c,style:l,draggable:u=!1,popup:d=null,rotation:f=0,rotationAlignment:p=`auto`,pitchAlignment:m=`auto`}=e;(0,_.useEffect)(()=>{H(a.getElement(),l)},[l]),(0,_.useImperativeHandle)(t,()=>a,[]);let h=i.current.props;(a.getLngLat().lng!==o||a.getLngLat().lat!==s)&&a.setLngLat([o,s]),c&&!y(a.getOffset(),c)&&a.setOffset(c),a.isDraggable()!==u&&a.setDraggable(u),a.getRotation()!==f&&a.setRotation(f),a.getRotationAlignment()!==p&&a.setRotationAlignment(p),a.getPitchAlignment()!==m&&a.setPitchAlignment(m),a.getPopup()!==d&&a.setPopup(d);let g=U(h.className,e.className);if(g)for(let e of g)a.toggleClassName(e);return i.current.props=e,(0,B.createPortal)(e.children,a.getElement())})),ne=(0,_.memo)((0,_.forwardRef)((e,t)=>{let{map:n,mapLib:r}=(0,_.useContext)(R),i=(0,_.useMemo)(()=>document.createElement(`div`),[]),a=(0,_.useRef)({props:e}),o=(0,_.useMemo)(()=>{let t={...e},n=new r.Popup(t);return n.setLngLat([e.longitude,e.latitude]),n.once(`open`,e=>{a.current.props.onOpen?.(e)}),n},[]);if((0,_.useEffect)(()=>{let e=e=>{a.current.props.onClose?.(e)};return o.on(`close`,e),o.setDOMContent(i).addTo(n.getMap()),()=>{o.off(`close`,e),o.isOpen()&&o.remove()}},[]),(0,_.useEffect)(()=>{H(o.getElement(),e.style)},[e.style]),(0,_.useImperativeHandle)(t,()=>o,[]),o.isOpen()){let t=a.current.props;(o.getLngLat().lng!==e.longitude||o.getLngLat().lat!==e.latitude)&&o.setLngLat([e.longitude,e.latitude]),e.offset&&!b(t.offset,e.offset)&&o.setOffset(e.offset),(t.anchor!==e.anchor||t.maxWidth!==e.maxWidth)&&(o.options.anchor=e.anchor,o.setMaxWidth(e.maxWidth));let n=U(t.className,e.className);if(n)for(let e of n)o.toggleClassName(e);a.current.props=e}return(0,B.createPortal)(e.children,i)}));function K(e,t,n,r){let i=(0,_.useContext)(R),a=(0,_.useMemo)(()=>e(i),[]);return(0,_.useEffect)(()=>{let e=r||n||t,o=typeof t==`function`&&typeof n==`function`?t:null,s=typeof n==`function`?n:typeof t==`function`?t:null,{map:c}=i;return c.hasControl(a)||(c.addControl(a,e?.position),o&&o(i)),()=>{s&&s(i),c.hasControl(a)&&c.removeControl(a)}},[]),a}function q(e){let t=K(({mapLib:t})=>new t.AttributionControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}(0,_.memo)(q);function J(e){let t=K(({mapLib:t})=>new t.FullscreenControl({container:e.containerId&&document.getElementById(e.containerId)}),{position:e.position});return(0,_.useEffect)(()=>{H(t._controlContainer,e.style)},[e.style]),null}(0,_.memo)(J);function Y(e,t){let n=(0,_.useRef)({props:e}),r=K(({mapLib:t})=>{let r=new t.GeolocateControl(e),i=r._setupUI;return r._setupUI=()=>{r._container.hasChildNodes()||i()},r.on(`geolocate`,e=>{n.current.props.onGeolocate?.(e)}),r.on(`error`,e=>{n.current.props.onError?.(e)}),r.on(`outofmaxbounds`,e=>{n.current.props.onOutOfMaxBounds?.(e)}),r.on(`trackuserlocationstart`,e=>{n.current.props.onTrackUserLocationStart?.(e)}),r.on(`trackuserlocationend`,e=>{n.current.props.onTrackUserLocationEnd?.(e)}),r},{position:e.position});return n.current.props=e,(0,_.useImperativeHandle)(t,()=>r,[]),(0,_.useEffect)(()=>{H(r._container,e.style)},[e.style]),null}(0,_.memo)((0,_.forwardRef)(Y));function X(e){let t=K(({mapLib:t})=>new t.NavigationControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}var re=(0,_.memo)(X);function ie(e){let t=K(({mapLib:t})=>new t.ScaleControl(e),{position:e.position}),n=(0,_.useRef)(e),r=n.current;n.current=e;let{style:i}=e;return e.maxWidth!==void 0&&e.maxWidth!==r.maxWidth&&(t.options.maxWidth=e.maxWidth),e.unit!==void 0&&e.unit!==r.unit&&t.setUnit(e.unit),(0,_.useEffect)(()=>{H(t._container,i)},[i]),null}(0,_.memo)(ie);function ae(e){let t=K(({mapLib:t})=>new t.TerrainControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}(0,_.memo)(ae);function oe(e){let t=K(({mapLib:t})=>new t.LogoControl(e),{position:e.position});return(0,_.useEffect)(()=>{H(t._container,e.style)},[e.style]),null}(0,_.memo)(oe);var Z=r(),se=s({latitudeField:c().optional(),longitudeField:c().optional(),locationField:c().optional(),titleField:c().optional(),descriptionField:c().optional(),zoom:l().optional(),center:o([l(),l()]).optional()});function ce(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function le(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 ue(e){if(e.locationField||e.latitudeField)return{locationField:e.locationField,latitudeField:e.latitudeField,longitudeField:e.longitudeField,titleField:e.titleField||`name`,descriptionField:e.descriptionField,zoom:e.zoom,center:e.center};let t=null;if(e.filter&&typeof e.filter==`object`&&`map`in e.filter?t=e.filter.map:e.map&&(t=e.map),t){let e=se.safeParse(t);return e.success||console.warn(`[ObjectMap] Invalid map configuration:`,e.error.format()),t}return{latitudeField:`latitude`,longitudeField:`longitude`,locationField:`location`,titleField:`name`,descriptionField:`description`,zoom:10,center:[0,0]}}function de(e,t){if(t.latitudeField&&t.longitudeField){let n=e[t.latitudeField],r=e[t.longitudeField];if(typeof n==`number`&&typeof r==`number`)return[n,r]}if(t.locationField){let n=e[t.locationField];if(typeof n==`object`&&n){let e=n.lat||n.latitude,t=n.lng||n.lon||n.longitude;if(typeof e==`number`&&typeof t==`number`)return[e,t]}if(typeof n==`string`){let e=n.split(`,`).map(e=>parseFloat(e.trim()));if(e.length===2&&!isNaN(e[0])&&!isNaN(e[1]))return[e[0],e[1]]}if(Array.isArray(n)&&n.length===2){let e=parseFloat(n[0]),t=parseFloat(n[1]);if(!isNaN(e)&&!isNaN(t))return[e,t]}}return null}function fe(e,t,n=50){if(e.length<=1||t>=15)return e.map(e=>({id:e.id,coordinates:e.coordinates,markers:[e],isCluster:!1}));let r=n/2**t,i=new Map;e.forEach(e=>{let t=`${Math.floor(e.coordinates[0]/r)}:${Math.floor(e.coordinates[1]/r)}`;i.has(t)||i.set(t,[]),i.get(t).push(e)});let a=[];return i.forEach((e,t)=>{if(e.length===1)a.push({id:e[0].id,coordinates:e[0].coordinates,markers:e,isCluster:!1});else{let n=e.reduce((e,t)=>e+t.coordinates[0],0)/e.length,r=e.reduce((e,t)=>e+t.coordinates[1],0)/e.length;a.push({id:`cluster-${t}`,coordinates:[n,r],markers:e,isCluster:!0})}}),a}var Q=({schema:e,dataSource:t,className:n,onMarkerClick:r,onRowClick:i,onEdit:a,onDelete:o,enableClustering:s,clusterRadius:c=50,...l})=>{let[u,m]=(0,_.useState)([]),[v,y]=(0,_.useState)(!0),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(null),[E,D]=(0,_.useState)(``),O=ee(),k=(0,_.useRef)(null),[A,j]=(0,_.useState)(null),[M,N]=(0,_.useState)(null),[P,F]=(0,_.useState)(!1),I=(0,_.useCallback)(()=>{if(typeof navigator>`u`||!navigator.geolocation){N(`Geolocation is not available in this browser.`);return}F(!0),N(null),navigator.geolocation.getCurrentPosition(e=>{let{longitude:t,latitude:n}=e.coords;j({lng:t,lat:n}),F(!1);try{k.current?.flyTo({center:[t,n],zoom:12,duration:800})}catch{}},e=>{F(!1),N(e.message||`Unable to retrieve location.`)},{enableHighAccuracy:!1,timeout:8e3,maximumAge:6e4})},[]),L=ce(e),R=(0,_.useMemo)(()=>L,[JSON.stringify(L)]),z=ue(e),B=R?.provider===`value`;(0,_.useEffect)(()=>{(async()=>{try{if(y(!0),l.data){let e=l.data;if(Array.isArray(e)){m(e),y(!1);return}}if(e.data){let t=e.data;if(Array.isArray(t)){m(t),y(!1);return}}if(B&&R?.provider===`value`){m(R.items),y(!1);return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(R?.provider===`object`){let n=R.object,r=f(S?.fields);m(p(await t.find(n,{$filter:e.filter,$orderby:le(e.sort),...r.length>0?{$expand:r}:{}})))}else R?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectMap`),m([]));y(!1)}catch(e){x(e),y(!1)}})()},[R,t,B,e.filter,e.sort,S]),(0,_.useEffect)(()=>{!B&&t&&(async()=>{try{if(!t)return;let n=R?.provider===`object`?R.object:e.objectName;if(!n)return;C(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,B,R]);let{markers:V,invalidCount:H}=(0,_.useMemo)(()=>{let e=0;return{markers:u.map((t,n)=>{let r=de(t,z);if(!r)return e++,null;let i=z.titleField?t[z.titleField]:`Marker`,a=z.descriptionField?t[z.descriptionField]:void 0,[o,s]=r;return!isFinite(o)||!isFinite(s)||o<-90||o>90||s<-180||s>180?(e++,null):{id:t.id||t._id||`marker-${n}`,title:i,description:a,coordinates:[s,o],data:t}}).filter(e=>e!==null),invalidCount:e}},[u,z]),U=(0,_.useMemo)(()=>V.find(e=>e.id===w),[V,w]),[W,K]=(0,_.useState)(z.zoom||3),q=d({navigation:e.navigation,objectName:e.objectName,onRowClick:i}),J=(0,_.useMemo)(()=>{if(!E.trim())return V;let e=E.toLowerCase();return V.filter(t=>t.title?.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[V,E]),Y=(0,_.useMemo)(()=>s??(e.enableClustering||J.length>100)?fe(J,W,c):J.map(e=>({id:e.id,coordinates:e.coordinates,markers:[e],isCluster:!1})),[J,W,s,c,e]),X=(0,_.useMemo)(()=>{if(!J.length)return{longitude:z.center?.[1]||0,latitude:z.center?.[0]||0,zoom:z.zoom||2};let e=J.map(e=>e.coordinates[0]),t=J.map(e=>e.coordinates[1]),n=Math.min(...e),r=Math.max(...e),i=Math.min(...t),a=Math.max(...t);return{longitude:(n+r)/2,latitude:(i+a)/2,zoom:z.zoom||3}},[J,z]);return v?(0,Z.jsx)(`div`,{className:h(`min-w-0 overflow-hidden`,n),children:(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-96 bg-muted rounded-lg border`,children:(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading map...`})})}):b?(0,Z.jsx)(`div`,{className:h(`min-w-0 overflow-hidden`,n),children:(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-96 bg-muted rounded-lg border`,children:(0,Z.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,b.message]})})}):(0,Z.jsxs)(`div`,{className:h(`min-w-0 overflow-hidden`,n),children:[H>0&&(0,Z.jsx)(`div`,{className:`mb-2 p-2 text-sm text-yellow-800 bg-yellow-50 border border-yellow-200 rounded`,children:`${H} record${H===1?``:`s`} with missing or invalid coordinates excluded from the map.`}),V.length>0&&(0,Z.jsx)(`div`,{className:`mb-2`,children:(0,Z.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`Search locations…`,className:`w-full px-3 py-2 text-sm border rounded-md bg-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})}),(0,Z.jsxs)(`div`,{className:`relative border rounded-lg overflow-hidden bg-muted h-[300px] sm:h-[400px] md:h-[500px] lg:h-[600px] w-full`,children:[(0,Z.jsxs)(te,{ref:e=>{k.current=e},initialViewState:X,style:{width:`100%`,height:`100%`},mapStyle:`https://demotiles.maplibre.org/style.json`,touchZoomRotate:!0,dragRotate:!0,touchPitch:!0,onZoom:e=>K(Math.round(e.viewState.zoom)),children:[(0,Z.jsx)(re,{position:`top-right`,showCompass:!0,showZoom:!0}),(0,Z.jsx)(`button`,{type:`button`,onClick:I,disabled:P,className:`absolute top-2 left-2 z-10 inline-flex items-center justify-center size-9 rounded-md bg-background/95 border shadow-sm hover:bg-background disabled:opacity-50`,"aria-label":`Show my location`,"data-testid":`map-geolocate`,children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:P?`⏳`:`🧭`})}),A&&(0,Z.jsx)(G,{longitude:A.lng,latitude:A.lat,anchor:`center`,children:(0,Z.jsx)(`div`,{className:`size-3 rounded-full bg-blue-500 ring-4 ring-blue-500/30 shadow`,"aria-label":`Your location`,"data-testid":`map-user-location`})}),Y.map(e=>e.isCluster?(0,Z.jsx)(G,{longitude:e.coordinates[0],latitude:e.coordinates[1],anchor:`center`,onClick:t=>{t.originalEvent.stopPropagation();try{let t=Math.min(20,Math.max(W+2,8));k.current?.flyTo({center:[e.coordinates[0],e.coordinates[1]],zoom:t,duration:600})}catch{}},children:(0,Z.jsx)(`div`,{className:`flex items-center justify-center rounded-full bg-primary text-primary-foreground font-bold text-xs cursor-pointer hover:scale-110 transition-transform shadow-md`,style:{width:Math.min(48,24+e.markers.length*2),height:Math.min(48,24+e.markers.length*2)},title:`${e.markers.length} markers`,"data-testid":`map-cluster`,children:e.markers.length})},e.id):(0,Z.jsx)(G,{longitude:e.coordinates[0],latitude:e.coordinates[1],anchor:`bottom`,onClick:t=>{t.originalEvent.stopPropagation();let n=e.markers[0];T(n.id),q.handleClick(n.data),r?.(n.data)},children:(0,Z.jsx)(`div`,{className:`text-2xl cursor-pointer hover:scale-110 transition-transform`,children:`📍`})},e.id)),U&&!O&&(0,Z.jsx)(ne,{longitude:U.coordinates[0],latitude:U.coordinates[1],anchor:`top`,onClose:()=>T(null),closeOnClick:!1,children:(0,Z.jsxs)(`div`,{className:`p-2 min-w-[150px] sm:min-w-[200px]`,children:[(0,Z.jsx)(`h3`,{className:`font-bold text-sm mb-1`,children:U.title}),U.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:U.description}),(0,Z.jsxs)(`div`,{className:`mt-2 text-xs flex gap-2`,children:[a&&(0,Z.jsx)(`button`,{className:`text-blue-500 hover:underline`,onClick:()=>a(U.data),children:`Edit`}),o&&(0,Z.jsx)(`button`,{className:`text-red-500 hover:underline`,onClick:()=>o(U.data),children:`Delete`})]})]})})]}),U&&O&&(0,Z.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 z-30 bg-background border-t shadow-lg rounded-t-2xl p-4 pb-[max(env(safe-area-inset-bottom),1rem)]`,role:`dialog`,"aria-label":`Location details`,"data-testid":`map-mobile-record-sheet`,children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-2 h-1 w-10 rounded-full bg-muted`,"aria-hidden":`true`}),(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold truncate`,children:U.title}),U.description&&(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground line-clamp-3`,children:U.description})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>T(null),className:`text-muted-foreground hover:text-foreground text-lg leading-none px-2`,"aria-label":`Close details`,"data-testid":`map-mobile-record-close`,children:`×`})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-xs`,children:[a&&(0,Z.jsx)(`button`,{className:`px-3 py-1.5 rounded-md border bg-card hover:bg-accent`,onClick:()=>a(U.data),children:`Edit`}),o&&(0,Z.jsx)(`button`,{className:`px-3 py-1.5 rounded-md border border-destructive/30 text-destructive hover:bg-destructive/10`,onClick:()=>o(U.data),children:`Delete`})]})]}),M&&(0,Z.jsx)(`div`,{className:`absolute top-2 left-14 right-2 z-10 text-xs px-3 py-1.5 rounded-md bg-destructive/10 text-destructive border border-destructive/30`,children:M})]}),q.isOverlay&&(0,Z.jsx)(g,{...q,title:`Location Details`,children:e=>(0,Z.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,Z.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},pe=t({ObjectMap:()=>Q,ObjectMapRenderer:()=>$}),$=({schema:e,...t})=>{let{dataSource:n}=u()||{};return(0,Z.jsx)(Q,{schema:e,dataSource:n,...t})};console.log(`Registering object-map...`),m.register(`object-map`,$,{namespace:`plugin-map`,label:`Object Map`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`map`,type:`object`,label:`Map Config`,description:`latitudeField, longitudeField, titleField`}]}),m.register(`map`,$,{namespace:`view`,label:`Map View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`map`,type:`object`,label:`Map Config`,description:`latitudeField, longitudeField, titleField`}]});export{pe as t};
@@ -1,4 +1,4 @@
1
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{ut as a}from"./framework-DpQcF_QW.js";import{At as o}from"./ui-components-CXy53m_o.js";import{c as s,l as c,t as l}from"./vendor-markdown-B0mCB2Nu.js";var u=t({default:()=>p}),d=e(i(),1),f=r();function p({content:e,className:t}){return(0,f.jsx)(`div`,{"data-slot":`markdown`,className:((...e)=>e.filter(Boolean).join(` `))(`prose prose-sm dark:prose-invert max-w-none`,`prose-headings:font-semibold prose-headings:tracking-tight`,`prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl`,`prose-p:leading-relaxed prose-p:text-foreground`,`prose-a:text-primary prose-a:no-underline hover:prose-a:underline`,`prose-code:text-foreground prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none`,`prose-pre:bg-muted prose-pre:text-foreground prose-pre:border`,`prose-blockquote:border-l-primary prose-blockquote:text-muted-foreground`,`prose-strong:text-foreground prose-strong:font-semibold`,`prose-ul:list-disc prose-ol:list-decimal`,`prose-li:text-foreground prose-li:marker:text-muted-foreground`,`prose-table:border prose-th:border prose-th:bg-muted prose-td:border`,`prose-img:rounded-md prose-img:border`,t),children:(0,f.jsx)(l,{remarkPlugins:[s],rehypePlugins:[c],disallowedElements:[`script`,`style`,`iframe`,`object`,`embed`],unwrapDisallowed:!0,children:e})})}var m=t({MarkdownRenderer:()=>g,markdownComponents:()=>_}),h=d.lazy(()=>n(()=>Promise.resolve().then(()=>u),void 0,import.meta.url)),g=({schema:e})=>(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(o,{className:`w-full h-[200px]`}),children:(0,f.jsx)(h,{content:e.content||``,className:e.className})});a.register(`markdown`,g,{namespace:`plugin-markdown`,label:`Markdown`,category:`plugin`,inputs:[{name:`content`,type:`string`,label:`Markdown Content`,required:!0,inputType:`textarea`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{content:`# Hello World
1
+ import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{ut as a}from"./framework-DVkqUSPj.js";import{At as o}from"./ui-components-CIdYg6m3.js";import{c as s,l as c,t as l}from"./vendor-markdown-B0mCB2Nu.js";var u=t({default:()=>p}),d=e(i(),1),f=r();function p({content:e,className:t}){return(0,f.jsx)(`div`,{"data-slot":`markdown`,className:((...e)=>e.filter(Boolean).join(` `))(`prose prose-sm dark:prose-invert max-w-none`,`prose-headings:font-semibold prose-headings:tracking-tight`,`prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl`,`prose-p:leading-relaxed prose-p:text-foreground`,`prose-a:text-primary prose-a:no-underline hover:prose-a:underline`,`prose-code:text-foreground prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none`,`prose-pre:bg-muted prose-pre:text-foreground prose-pre:border`,`prose-blockquote:border-l-primary prose-blockquote:text-muted-foreground`,`prose-strong:text-foreground prose-strong:font-semibold`,`prose-ul:list-disc prose-ol:list-decimal`,`prose-li:text-foreground prose-li:marker:text-muted-foreground`,`prose-table:border prose-th:border prose-th:bg-muted prose-td:border`,`prose-img:rounded-md prose-img:border`,t),children:(0,f.jsx)(l,{remarkPlugins:[s],rehypePlugins:[c],disallowedElements:[`script`,`style`,`iframe`,`object`,`embed`],unwrapDisallowed:!0,children:e})})}var m=t({MarkdownRenderer:()=>g,markdownComponents:()=>_}),h=d.lazy(()=>n(()=>Promise.resolve().then(()=>u),void 0,import.meta.url)),g=({schema:e})=>(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(o,{className:`w-full h-[200px]`}),children:(0,f.jsx)(h,{content:e.content||``,className:e.className})});a.register(`markdown`,g,{namespace:`plugin-markdown`,label:`Markdown`,category:`plugin`,inputs:[{name:`content`,type:`string`,label:`Markdown Content`,required:!0,inputType:`textarea`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{content:`# Hello World
2
2
 
3
3
  This is a **markdown** component with *formatting* support.
4
4
 
@@ -0,0 +1,59 @@
1
+ import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{$ as i,L as a,et as o,ut as s,z as c}from"./framework-DVkqUSPj.js";import{n as l}from"./vendor-i18n-DPyFo2xM.js";import{$ as u,$a as d,As as f,At as p,Bn as m,Fi as h,Fn as g,Gn as _,In as v,Jn as y,Kn as b,Ko as x,Ln as S,Lr as C,Ni as w,Ns as T,Oi as E,Oo as D,Pr as O,Qn as k,Rn as A,Ts as j,V as M,Vn as N,Wo as P,Xn as F,Yn as I,_a as ee,_i as te,bi as ne,en as L,et as R,go as re,in as z,ja as ie,l as ae,m as oe,mi as se,mr as B,ns as ce,nt as V,qn as H,tt as le,w as ue,ys as de,zn as fe}from"./ui-components-CIdYg6m3.js";import{r as pe}from"./plugin-grid-DGQxmfxn.js";var U=e(r(),1),W=n(),me=({schema:e})=>{let{title:t,description:n,data:r,columns:i}=e;e.chart?.type;let a=!!e.chart;return(0,W.jsxs)(b,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,W.jsxs)(I,{children:[t&&(0,W.jsx)(F,{children:t}),n&&(0,W.jsx)(y,{children:n})]}),(0,W.jsxs)(H,{className:`flex-1 overflow-auto space-y-4`,children:[a&&(()=>{let t=e.chart?.type,n=t?s.get(t):null;return n||=s.get(`chart`),n?(0,W.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,W.jsx)(n,{schema:{...e.chart,data:e.chart.data||r}})}):(0,W.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,t||`chart`]})})(),r&&r.length>0&&(0,W.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=s.get(`grid`)||s.get(`table`);return e?(0,W.jsx)(e,{schema:{type:`grid`,rowData:r,columnDefs:i,domLayout:`autoHeight`}}):(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,W.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,W.jsx)(`tr`,{children:i?.map(e=>(0,W.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,W.jsx)(`tbody`,{children:r.map((e,t)=>(0,W.jsx)(`tr`,{className:`bg-background border-b`,children:i?.map(t=>(0,W.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function G(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function he(e,t){if(e==null)return null;let n=e instanceof Date?e:new Date(String(e));if(Number.isNaN(n.getTime()))return null;let r=n.getUTCFullYear(),i=n.getUTCMonth(),a=n.getUTCDate();switch(t){case`year`:return String(r);case`quarter`:return`${r}-Q${Math.floor(i/3)+1}`;case`month`:return`${r}-${String(i+1).padStart(2,`0`)}`;case`week`:{let e=new Date(Date.UTC(r,i,a)),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),o=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${String(o).padStart(2,`0`)}`}case`day`:return`${r}-${String(i+1).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`;default:return String(e)}}function K(e,t){let n=e[t.field];return t.dateGranularity?he(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function q(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[G(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[G(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[G(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[G(r)]=e;break}case`avg`:{let e=0,i=0;for(let n of t){if(n==null||n===``)continue;let t=Number(n);Number.isNaN(t)||(e+=t,i+=1)}n[G(r)]=i===0?null:e/i;break}case`min`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t<e)&&(e=t)}n[G(r)]=e;break}case`max`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t>e)&&(e=t)}n[G(r)]=e;break}default:n[G(r)]=null}}return n}function ge(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=K(t,a),n=s.get(e);n||(n=[],s.set(e,n)),n.push(t)}let c=[];for(let[e,t]of s){let s={...r,[a.field]:e},l=[...i,e],u=q(t,n),d=o.length>0?ge(t,o,n,s,l):void 0;c.push({groupKey:s,groupPath:l,values:u,count:t.length,children:d})}let l=a.sort===`desc`?-1:1;return c.sort((e,t)=>{let n=String(e.groupPath[e.groupPath.length-1]),r=String(t.groupPath[t.groupPath.length-1]);return n.localeCompare(r)*l}),typeof a.limit==`number`&&a.limit>0?c.slice(0,a.limit):c}function _e(e,t,n,r){let i=ve(e,n),a=ve(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=ye(e,c.key,n);s[c.id]=q(i,t);for(let e of a){let n=ye(i,e.key,r);n.length!==0&&(o[c.id][e.id]=q(n,t))}}for(let n of a){let i=ye(e,n.key,r);c[n.id]=q(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:q(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function ve(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=K(r,n);e.push(t),i[n.field]=t}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0});let i=t[0].limit;if(typeof i==`number`&&i>0){let e=new Set;for(let t of r)e.size>=i&&!e.has(t.path[0])||e.add(t.path[0]);return r.filter(t=>e.has(t.path[0]))}return r}function ye(e,t,n){let r=Object.entries(t);if(r.length===0)return e;let i=new Map;for(let e of n)i.set(e.field,e);return e.filter(e=>{for(let[t,n]of r){let r=i.get(t);if((r?K(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function be(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=G(r),i=0,a=0,o=null,s=null;for(let n of e){let e=n[t];typeof e==`number`&&(i+=e,a+=1,(o==null||e<o)&&(o=e),(s==null||e>s)&&(s=e))}r.aggregate===`min`?n[t]=o:r.aggregate===`max`?n[t]=s:r.aggregate===`avg`?n[t]=a===0?null:i/a:n[t]=i}return n}function xe(e,t,n,r){let i=Se(e,n),a=Se(e,r),o={},s={},c={};for(let n of i){o[n.id]={};let r=e.filter(e=>Ce(e,n.key));s[n.id]=be(r,t);for(let e of a){let i=r.filter(t=>Ce(t,e.key));if(i.length===0)continue;let a={};for(let e of t){if(!e.aggregate)continue;let t=G(e);a[t]=i[0][t]}o[n.id][e.id]=a}}for(let n of a){let r=e.filter(e=>Ce(e,n.key));c[n.id]=be(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:be(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function Se(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=r[n.field],a=t==null?`(null)`:String(t);e.push(a),i[n.field]=a}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());return r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0}),r}function Ce(e,t){for(let[n,r]of Object.entries(t))if((e[n]==null?`(null)`:String(e[n]))!==String(r))return!1;return!0}function J(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function we(e){let t=new Set;for(let n of e.groupingsDown??[])t.add(n.field);for(let n of e.groupingsAcross??[])t.add(n.field);for(let n of e.columns??[])t.add(n.field);for(let n of e.sort??[])t.add(n.field);return Array.from(t)}function Te(e,t,n){let r=[...e.groupingsDown??[],...e.groupingsAcross??[]],i=(e.columns??[]).filter(e=>!!e.aggregate);if(r.length===0&&i.length===0)return null;let a=r.map(e=>e.dateGranularity?{field:e.field,dateGranularity:e.dateGranularity}:e.field),o=i.map(e=>({function:e.aggregate===`unique`?`count_distinct`:e.aggregate,field:e.field,alias:G(e)})),s=J(e.filter,t),c={object:e.objectName,limit:n};return a.length>0&&(c.groupBy=a),o.length>0&&(c.aggregations=o),s&&(c.where=s),c}function Ee(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?K(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var Y=[];function De(e,t={}){let{dataSource:n,runtimeFilter:r,maxRows:i=5e3,enabled:a=!0,rows:o,preferServerAggregation:s=!0}=t,[c,l]=(0,U.useState)(o??Y),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(()=>o?!1:!!(e&&a&&n)),[m,h]=(0,U.useState)(null),g=(0,U.useRef)(0),_=(0,U.useCallback)(async()=>{if(!e||!a)return;if(o){l(o),d(!1);return}if(!n){l(Y);return}let t=++g.current;p(!0),h(null);try{let a=s?Te(e,r,i):null;if(a&&typeof n.aggregate==`function`)try{let r=Oe(await n.aggregate(e.objectName,a));if(t!==g.current)return;l(r),d(!0);return}catch(e){typeof console<`u`&&console.warn&&console.warn(`[useReportData] dataSource.aggregate() failed, falling back to find():`,e)}if(typeof n.find!=`function`){l(Y),d(!1);return}let o=J(e.filter,r),c=we(e),u={$top:i};o&&(u.$filter=o),c.length>0&&(u.$select=c),e.sort&&e.sort.length>0&&(u.$orderBy=e.sort.map(e=>`${e.field} ${e.direction??`asc`}`).join(`,`));let f=Oe(await n.find(e.objectName,u));if(t!==g.current)return;l(f),d(!1)}catch(e){if(t!==g.current)return;h(e instanceof Error?e:Error(String(e))),l(Y),d(!1)}finally{t===g.current&&p(!1)}},[e,a,o,n,r,i,s]);(0,U.useEffect)(()=>{_()},[_]);let{rows:v,totals:y,pivot:b}=(0,U.useMemo)(()=>{if(!e)return{rows:[],totals:{},pivot:null};let t=e.groupingsDown??[],n=e.groupingsAcross??[],r=e.columns??[],i=n.length>0;if(u){let e=[...t,...n],a=c.map(t=>{let n={},r=[];for(let i of e){let e=t[i.field];n[i.field]=e,r.push(e==null?`(null)`:String(e))}let i={...t};for(let t of e)delete i[t.field];return{groupKey:n,groupPath:r,values:i,count:1}}),o=be(c,r),s=i?xe(c,r,t,n):null;return{rows:i&&s?s.rowHeaders.map(e=>({groupKey:e.key,groupPath:e.path,values:s.rowTotals[e.id]??{},count:1})):a,totals:o,pivot:s}}let a=i?t:[...t,...n];return{rows:a.length>0?ge(c,a,r):c.map(e=>({groupKey:{},groupPath:[],values:r.length>0?q([e],r):{...e},count:1})),totals:q(c,r),pivot:i?_e(c,r,t,n):null}},[e,c,u]);return{rows:v,rawRows:c,totals:y,pivot:b,serverAggregated:u,loading:f,error:m,refetch:_,drillDown:(0,U.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return c.filter(e=>Ee(e,t,n))},[e,c])}}function Oe(e){if(Array.isArray(e))return e;if(e&&typeof e==`object`){let t=e;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.records))return t.records;if(Array.isArray(t.results))return t.results;if(Array.isArray(t.value))return t.value}return Y}function ke(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function Ae(e){let t=[],n=e=>{e.children&&e.children.length>0?e.children.forEach(n):t.push(e)};return e.forEach(n),t}function je({report:e,rows:t,labels:n}){let r=e.chart;if(!r||!r.type)return{schema:null};let i=e.groupingsDown??[],a=r.xAxis||(i.length>0?i[0]?.field:void 0);if(!a)return{schema:null,diagnostic:`chart.xAxis missing and no groupingsDown[0] to default to.`};let o=e.columns??[],s=r.yAxis,c=`count`,l=`Count`,u=!0;if(s){let e=o.find(e=>e.field===s&&e.aggregate);e?(c=ke(e),l=n?.resolveColumnLabel?.(e)??(typeof e.label==`string`?e.label:`${e.aggregate}(${e.field})`),u=!1):(c=`count`,l=n?.resolveCountLabel?.(s)??`Count of ${s}`)}let d=Ae(t),f=new Map;for(let e of d){let t=e.groupKey[a];if(t===void 0)continue;let n=String(t??``),r=u?e.count:Number(e.values[c]??0),i=f.get(n);i?i.measure+=Number.isFinite(r)?r:0:f.set(n,{x:t,measure:Number.isFinite(r)?r:0})}let p=Array.from(f.values()).map(e=>{let t=n?.resolveAxisValue?.(a,e.x)??e.x??`(null)`;return{[a]:t,[c]:e.measure}});return(r.type===`pie`||r.type===`donut`||r.type===`funnel`)&&(p=[...p].sort((e,t)=>Number(t[c]??0)-Number(e[c]??0))),{schema:{type:`chart`,chartType:r.type,data:p,xAxisKey:a,series:[{dataKey:c,label:l}],title:r.title,showLegend:r.showLegend??!0,showDataLabels:r.showDataLabels??!1,className:`w-full h-[320px]`}}}function Me(e,t,n={}){let r=J(J(e.filter,n.runtimeFilter),Object.keys(t).length>0?t:void 0);return{type:`drill`,name:`drill-${e.name}`,objectName:e.objectName,...r?{filter:r}:{},view:n.view??`list`,...n.recordId===void 0?{}:{recordId:n.recordId},openIn:n.openIn??`current`}}function Ne(e){return!!e&&e.type===`drill`}function Pe(e){return async t=>{if(!Ne(t))return{success:!1,error:`drill handler invoked with non-drill action`};try{return await e.navigate({objectName:t.objectName,filter:t.filter,view:t.view,recordId:t.recordId,openIn:t.openIn}),{success:!0}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}}function Fe(e,t){return e.registerHandler(`drill`,Pe(t)),()=>e.unregisterHandler(`drill`)}function Ie(e){return e?e===`unique`?`count_distinct`:e:null}function Le(e){if(!(!e||e.length===0))return{fields:e.map(e=>({field:e.field,order:e.sort??`asc`,collapsed:!1}))}}function Re(e){return(e.columns??[]).map(e=>{let t={field:e.field};return e.label&&(t.label=typeof e.label==`string`?e.label:String(e.label)),e.format&&(t.format=e.format),e.width&&(t.width=e.width),t})}var ze={padding:`12px 16px`,border:`1px dashed rgb(203 213 225)`,borderRadius:8,color:`rgb(100 116 139)`,fontSize:14},Be=({report:e,dataSource:t,rows:n,runtimeFilter:r,onDrillDown:i,actionRunner:o,drillView:s,drillOpenIn:c,className:u})=>{let d=e.type??`tabular`,{t:f}=l(),{fieldLabel:p,translateOptions:m}=T(),[h,g]=U.useState(null);U.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||g(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let _=U.useCallback(t=>{if(t.label)return String(t.label);let n=h?.fields?.[t.field]?.label??t.field,r=p(e.objectName,t.field,n);return t.aggregate?`${r} · ${f(`report.aggregate.${t.aggregate}`,t.aggregate)}`:r},[h,e.objectName,p,f]),v=U.useCallback((t,n)=>{if(n==null)return;let r=h?.fields?.[t];if(!r||!(r.type===`select`||r.type===`status`)||!Array.isArray(r.options)||r.options.length===0)return;let i=m(e.objectName,t,r.options),a=String(n);for(let e of i)if(e&&e.value!==void 0&&e.value!==null&&String(e.value)===a)return e.label==null?a:String(e.label)},[h,e.objectName,m]),{rawRows:y,rows:b,totals:x,serverAggregated:S,loading:C,error:w,drillDown:E}=De(e,{dataSource:t,rows:n,runtimeFilter:r});if(d===`matrix`||d===`joined`)return(0,W.jsxs)(`div`,{className:u,style:ze,children:[`Report type `,(0,W.jsx)(`code`,{children:d}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let D=U.useMemo(()=>{if(S){let t=(e.groupingsDown??[]).map(e=>({field:e.field,label:e.field.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})),n=(e.columns??[]).filter(e=>e.aggregate).map(e=>({field:G(e),label:`${(typeof e.label==`string`?e.label:null)??e.field} (${e.aggregate})`,...e.format?{format:e.format}:{}}));return{type:`object-grid`,objectName:e.objectName,columns:[...t,...n]}}let t=d===`summary`?Le(e.groupingsDown):void 0,n=(e.columns??[]).map(e=>{let t=Ie(e.aggregate);return t?{field:e.field,type:t}:null}).filter(e=>e!==null);return{type:`object-grid`,objectName:e.objectName,columns:Re(e),grouping:t,aggregations:n.length>0?n:void 0}},[e,d,S]),O=y,k=U.useCallback(t=>{let n=e.groupingsDown??[],a={};for(let e of n)a[e.field]=t[e.field];if(o){let t=Me(e,a,{runtimeFilter:r,view:s,openIn:c});o.execute(t)}i&&i(a,E(a))},[o,E,c,s,i,e,r]),A=!!i||!!o,j=(e.columns??[]).filter(e=>e.aggregate),M=j.length>0&&x&&Object.keys(x).length>0,N=U.useMemo(()=>d!==`summary`||!e.chart||!e.chart.type?null:je({report:e,rows:b,labels:{resolveColumnLabel:_,resolveCountLabel:t=>{let n=h?.fields?.[t]?.label??t;return`${p(e.objectName,t,n)} · ${f(`report.aggregate.count`,`Count`)}`},resolveAxisValue:v}}).schema,[e,b,d,_,v,h,p,f]);return(0,W.jsxs)(`div`,{className:u,"data-testid":`spec-report-grid`,"aria-busy":C||void 0,children:[w?(0,W.jsx)(`div`,{role:`alert`,style:{...ze,color:`rgb(190 18 60)`},children:w.message}):null,M?(0,W.jsxs)(`div`,{"data-testid":`spec-report-totals`,className:`mb-3 flex flex-wrap items-baseline gap-x-6 gap-y-1 rounded-md border bg-muted/40 px-3 py-2 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:f(`report.totals`,`Totals`)}),j.map(e=>{let t=G(e),n=x[t],r=_(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,W.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,W.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,N?(0,W.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,W.jsx)(a,{schema:N})}):null,(0,W.jsx)(pe,{schema:D,data:O,dataSource:t,onRowClick:A?k:void 0})]})};Be.displayName=`SpecReportGrid`;var Ve=`—`;function He(e){return e==null?Ve:typeof e==`number`?e.toLocaleString():String(e)}function Ue(e,t,n){if(e==null||e===``||e===`(null)`)return n;let r=t?.options;if(r){let t=r.get(e);if(t!==void 0&&t!==``)return t}return e}function We({header:e,groupings:t,metaByField:n,fallback:r,emptyLabel:i}){return e.path.length===0?(0,W.jsx)(W.Fragment,{children:r}):(0,W.jsx)(W.Fragment,{children:e.path.map((e,r)=>{let a=t[r]?.field;return Ue(e,a?n.get(a):void 0,i)}).join(` / `)})}var Ge=({report:e,dataSource:t,rows:n,runtimeFilter:r,onCellClick:i,actionRunner:a,drillView:o,drillOpenIn:s,className:c,emptyCellText:u=Ve})=>{let{pivot:d,loading:p,error:m}=De(e,{dataSource:t,rows:n,runtimeFilter:r}),h=e.columns??[],g=h.length>1,{fieldLabel:_,translateOptions:v}=T(),{t:y}=l(),b=y(`report.emptyLabel`,`(Empty)`),x=y(`report.allLabel`,`(All)`),[S,C]=U.useState(null);U.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||C(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let w=e.groupingsDown??[],E=e.groupingsAcross??[],D=U.useMemo(()=>{let t=new Map,n=S?.fields??{},r=[...w,...E];for(let i of r){let r=n[i.field],a=r?.label??i.field,o=_(e.objectName,i.field,a),s=r?.type===`select`||r?.type===`status`,c;if(s&&Array.isArray(r?.options)&&r.options.length>0){let t=v(e.objectName,i.field,r.options);c=new Map;for(let e of t)e&&e.value!==void 0&&e.value!==null&&c.set(String(e.value),e.label==null?String(e.value):String(e.label))}t.set(i.field,{fieldLabel:o,options:c})}return t},[S,w,E,e.objectName,_,v]),O=U.useMemo(()=>{let t=new Map,n=S?.fields??{};for(let r of h){let i=G(r);if(r.label){t.set(i,String(r.label));continue}let a=n[r.field]?.label??r.field,o=_(e.objectName,r.field,a);if(r.aggregate){let e=y(`report.aggregate.${r.aggregate}`,r.aggregate);t.set(i,`${o} · ${e}`)}else t.set(i,o)}return t},[h,S,e.objectName,_,y]),k=U.useCallback((t,n,c)=>{let l={...t.key,...n.key};if(a){let t=Me(e,l,{runtimeFilter:r,view:o,openIn:s});a.execute(t)}i&&i({rowKey:t.key,colKey:n.key,combinedKey:l,values:c})},[a,s,o,i,e,r]);if(m)return(0,W.jsx)(`div`,{className:f(`rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive`,c),role:`alert`,"data-testid":`matrix-error`,children:y(`report.failedToLoad`,`Failed to load matrix: {{message}}`,{message:m.message})});if(!d)return(0,W.jsx)(`div`,{className:f(`rounded-md border border-dashed border-border bg-muted/30 px-4 py-6 text-center text-sm text-muted-foreground`,c),"aria-busy":p||void 0,"data-testid":`matrix-empty`,children:p?y(`report.loading`,`Loading…`):y(`report.needsAcross`,"Matrix report requires at least one `groupingsAcross` field.")});let A=!!i||!!a,j=w.map(e=>D.get(e.field)?.fieldLabel??e.field).join(` / `)||y(`report.rowsLabel`,`Row`),M=E.map(e=>D.get(e.field)?.fieldLabel??e.field).join(` / `)||y(`report.columnsLabel`,`Column`),N=h.length>0?G(h[0]):null,P=0;if(N)for(let e of d.rowHeaders)for(let t of d.colHeaders){let n=d.cells[e.id]?.[t.id]?.[N];typeof n==`number`&&n>P&&(P=n)}let F=e=>{if(!N||P<=0||!e)return 0;let t=e[N];return typeof t!=`number`||t<=0?0:Math.min(1,t/P)};return(0,W.jsx)(`div`,{className:f(`overflow-auto rounded-lg border border-border bg-card shadow-sm`,c),"data-testid":`matrix-renderer`,"aria-busy":p||void 0,children:(0,W.jsxs)(`table`,{role:`table`,className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{children:[(0,W.jsxs)(`th`,{scope:`col`,className:f(`sticky left-0 top-0 z-30 border-b border-r border-border bg-muted/60`,`px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-muted-foreground`),"aria-label":`${j} \u2192 ${M}`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground/70`,children:j}),(0,W.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`\\`}),(0,W.jsx)(`span`,{className:`text-foreground/80`,children:M})]}),d.colHeaders.map(e=>(0,W.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-border bg-muted/60 px-3 py-2 text-right text-xs font-semibold text-foreground`,children:(0,W.jsx)(We,{header:e,groupings:E,metaByField:D,fallback:x,emptyLabel:b})},`col-${e.id}`)),(0,W.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-l border-border bg-muted px-3 py-2 text-right text-xs font-semibold uppercase tracking-wide text-foreground`,children:y(`report.rowTotal`,`Row Total`)})]})}),(0,W.jsx)(`tbody`,{children:d.rowHeaders.map((e,t)=>(0,W.jsxs)(`tr`,{className:`group`,children:[(0,W.jsx)(`th`,{scope:`row`,className:f(`sticky left-0 z-10 whitespace-nowrap border-b border-r border-border bg-card px-3 py-2 text-left text-sm font-medium text-foreground`,`group-hover:bg-muted/50`,t===0&&`border-t-0`),children:(0,W.jsx)(We,{header:e,groupings:w,metaByField:D,fallback:x,emptyLabel:b})}),d.colHeaders.map(t=>{let n=d.cells[e.id]?.[t.id],r=!n,i=F(n);return(0,W.jsx)(`td`,{className:f(`border-b border-border px-3 py-2 text-right tabular-nums transition-colors`,r?`text-muted-foreground/40`:`text-foreground`,A&&!r&&`cursor-pointer hover:outline hover:outline-2 hover:-outline-offset-2 hover:outline-primary/50`,`group-hover:bg-muted/30`),style:i>0?{backgroundColor:`rgba(59, 130, 246, ${.06+i*.28})`}:void 0,onClick:A&&!r?()=>k(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?u:Ke(h,n,g,O)},`cell-${e.id}-${t.id}`)}),(0,W.jsx)(`td`,{className:f(`border-b border-l border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,`group-hover:bg-muted/60`),children:Ke(h,d.rowTotals[e.id]??{},g,O)})]},`row-${e.id}`))}),(0,W.jsx)(`tfoot`,{children:(0,W.jsxs)(`tr`,{children:[(0,W.jsx)(`th`,{scope:`row`,className:`sticky left-0 z-10 whitespace-nowrap border-t-2 border-r border-border bg-muted px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-foreground`,children:y(`report.columnTotal`,`Column Total`)}),d.colHeaders.map(e=>(0,W.jsx)(`td`,{className:`border-t-2 border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,children:Ke(h,d.colTotals[e.id]??{},g,O)},`coltotal-${e.id}`)),(0,W.jsx)(`td`,{className:`border-l border-t-2 border-border bg-primary/10 px-3 py-2 text-right text-sm font-bold tabular-nums text-foreground`,children:Ke(h,d.grandTotal,g,O)})]})})]})})};function Ke(e,t,n,r){return e.length?n?(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>{let n=G(e);return(0,W.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r?.get(n)??e.label??n}),(0,W.jsx)(`span`,{className:`tabular-nums`,children:He(t[n])})]},n)})}):He(t[G(e[0])]):Ve}function qe(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function Je(e,t){if(!t||Object.keys(t).length===0)return e;let n=J(t,e.filter);return{...e,filter:n}}var Ye=({report:e,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:a,drillOpenIn:o,className:s,renderBlock:c})=>{if(!i(e))return(0,W.jsxs)(`div`,{className:s,"data-testid":`joined-report-invalid`,style:{color:`var(--color-destructive, #b91c1c)`,fontSize:13,padding:12},children:[`JoinedReportRenderer requires a report with `,(0,W.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,W.jsx)(`code`,{children:`blocks`}),` array.`]});let l=e.blocks??[],u=e.filter,d=e.objectName;return(0,W.jsx)(`div`,{className:s,"data-testid":`joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:l.map((e,i)=>{let s=e.objectName??d??``,l=Je({...e,objectName:s,type:e.type??`tabular`,columns:e.columns??[]},u),f=qe(e.label,e.name),p=e.description?qe(e.description,``):``,m=e.name??`block-${i}`,h=(0,W.jsxs)(`section`,{"data-testid":`joined-report-block`,"data-block-id":m,style:{display:`flex`,flexDirection:`column`,gap:8,border:`1px solid var(--color-border, #e4e4e7)`,borderRadius:8,padding:16,background:`var(--color-card, #ffffff)`},children:[(0,W.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,W.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:f}),p?(0,W.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:p}):null]}),(0,W.jsx)(Ze,{schema:l,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:a,drillOpenIn:o})]},m);return c?c(e,i,h):h})})},Xe={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},Ze=e=>{let{dataSource:t,rows:n,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u}=e,d=U.useContext(c),f=t??d?.dataSource,p=e.schema;if(p&&typeof p==`object`&&p.type===`spec-report`&&p.report&&typeof p.report==`object`&&(p=p.report),o(p)){let e=p.type??`tabular`;return e===`matrix`?(0,W.jsx)(Ge,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u}):e===`joined`?i(p)?(0,W.jsx)(Ye,{report:p,dataSource:f,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u}):(0,W.jsxs)(`div`,{className:u,style:Xe,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,W.jsx)(`code`,{children:p.name}),`) is missing a `,(0,W.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,W.jsx)(Be,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u})}return(0,W.jsx)(me,{schema:p})};function Qe(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=it(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
2
+ `))?`"${n.replace(/"/g,`""`)}"`:n??``}));Z([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
3
+ `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function $e(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};Z(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function et(e,t,n){let r=e.fields||[],i=ot(n?.orientation),a=at(n?.pageSize);Z(`<!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <meta charset="utf-8">
7
+ <title>${X(e.title||`Report`)}</title>
8
+ <style>
9
+ @page { size: ${a} ${i}; margin: 20mm; }
10
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
11
+ h1 { font-size: 24px; margin-bottom: 8px; }
12
+ .description { color: #666; margin-bottom: 24px; }
13
+ .meta { color: #999; font-size: 12px; margin-bottom: 16px; }
14
+ table { width: 100%; border-collapse: collapse; margin-top: 16px; }
15
+ th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
16
+ td { padding: 8px 12px; border: 1px solid #ddd; }
17
+ tr:nth-child(even) { background: #fafafa; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <h1>${X(e.title||`Report`)}</h1>
22
+ ${e.description?`<p class="description">${X(e.description)}</p>`:``}
23
+ <p class="meta">Generated: ${new Date().toLocaleString()}</p>
24
+ <table>
25
+ <thead><tr>${r.map(e=>`<th>${X(e.label||e.name)}</th>`).join(``)}</tr></thead>
26
+ <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${X(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
27
+ </table>
28
+ </body>
29
+ </html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function tt(e,t,n){let r=e.fields||[],i=ot(n?.orientation),a=at(n?.pageSize),o=window.open(``,`_blank`);if(!o){et(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
30
+ <html>
31
+ <head>
32
+ <meta charset="utf-8">
33
+ <title>${X(e.title||`Report`)}</title>
34
+ <style>
35
+ @page { size: ${a} ${i}; margin: 20mm; }
36
+ @media print { .no-print { display: none; } }
37
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
38
+ h1 { font-size: 24px; margin-bottom: 8px; }
39
+ .description { color: #666; margin-bottom: 24px; }
40
+ .meta { color: #999; font-size: 12px; margin-bottom: 16px; }
41
+ table { width: 100%; border-collapse: collapse; margin-top: 16px; }
42
+ th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
43
+ td { padding: 8px 12px; border: 1px solid #ddd; }
44
+ tr:nth-child(even) { background: #fafafa; }
45
+ </style>
46
+ </head>
47
+ <body>
48
+ <h1>${X(e.title||`Report`)}</h1>
49
+ ${e.description?`<p class="description">${X(e.description)}</p>`:``}
50
+ <p class="meta">Generated: ${new Date().toLocaleString()}</p>
51
+ <table>
52
+ <thead><tr>${r.map(e=>`<th>${X(e.label||e.name)}</th>`).join(``)}</tr></thead>
53
+ <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${X(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
54
+ </table>
55
+ </body>
56
+ </html>`),o.document.close(),o.onload=()=>{o.print()}}function nt(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=it(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
+ `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));Z(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
+ `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function rt(e,t,n,r){switch(e){case`csv`:Qe(t,n,r);break;case`json`:$e(t,n,r);break;case`html`:et(t,n,r);break;case`pdf`:tt(t,n,r);break;case`excel`:nt(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function X(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function it(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function at(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function ot(e){return e===`landscape`?`landscape`:`portrait`}function Z(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function st(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||ct(e))return lt(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function ct(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function lt(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function ut(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var dt=({schema:e,onRefresh:t})=>{let{report:n,data:r,showToolbar:i=!0,allowExport:o=!0,allowPrint:c=!0,loading:l=!1}=e,u=e=>{if(!n){console.warn(`ReportViewer: Cannot export, no report defined`);return}rt(e,n,r||[],n.exportConfigs?.[e])},d=()=>{window.print()},f=()=>{t?.()},m=(e,t)=>{if(!r)return 0;let n=r.map(t=>Number(t[e])||0);switch(t){case`count`:return r.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},h=(e,t)=>{let r=n?.conditionalFormatting;if(!(!r||!Array.isArray(r)))for(let n of r){if(n.field!==e)continue;let r=String(t??``),i=String(n.value??``),a=!1;switch(n.operator){case`equals`:a=r===i;break;case`not_equals`:a=r!==i;break;case`contains`:a=r.includes(i);break;case`greater_than`:a=Number(t)>Number(n.value);break;case`less_than`:a=Number(t)<Number(n.value);break}if(a){let e={};return n.backgroundColor&&(e.backgroundColor=n.backgroundColor),n.textColor&&(e.color=n.textColor),e}}},g=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,W.jsx)(k,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return st(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,W.jsx)(ae(oe(n)),{value:e,field:n})}return st(e,t)};return n?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[i&&(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold`,children:n.title}),n.description&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n.refreshInterval&&(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:f,children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Refresh`]}),c&&(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:d,children:[(0,W.jsx)(w,{className:`h-4 w-4 mr-2`}),`Print`]}),o&&n.showExportButtons&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>u(`pdf`),children:[(0,W.jsx)(re,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>u(`excel`),children:[(0,W.jsx)(re,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>u(`csv`),children:[(0,W.jsx)(re,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,W.jsxs)(b,{children:[(0,W.jsxs)(I,{children:[!i&&n.title&&(0,W.jsx)(F,{children:n.title}),!i&&n.description&&(0,W.jsx)(y,{children:n.description})]}),(0,W.jsxs)(H,{className:`space-y-6`,children:[l&&(0,W.jsxs)(`div`,{className:`space-y-6`,children:[(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,W.jsx)(b,{children:(0,W.jsxs)(H,{className:`p-4 space-y-2`,children:[(0,W.jsx)(p,{className:`h-4 w-20`}),(0,W.jsx)(p,{className:`h-8 w-28`})]})},e))}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(p,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,W.jsx)(p,{className:`h-8 w-full`},e))]})]}),!l&&n.sections?.map((e,t)=>e.visible===!1?null:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,W.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,W.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:n.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,W.jsx)(b,{children:(0,W.jsxs)(H,{className:`p-4`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,W.jsx)(`div`,{className:`text-2xl font-bold`,children:st(m(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,W.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let t=e.chart.type,n=!!e.chart.chartType;!t&&n&&(t=`chart`),t&&s.get(t)||(t=`chart`);let i=t===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,W.jsx)(a,{schema:{...e.chart,type:t,...i,data:r||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,W.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,W.jsx)(`thead`,{className:`bg-muted`,children:(0,W.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,W.jsx)(`tbody`,{children:(()=>{let t=ut(r||[],n.groupBy||[]);return t?t.map(t=>(0,W.jsxs)(U.Fragment,{children:[(0,W.jsx)(`tr`,{className:`bg-muted/60`,children:(0,W.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:h(e.name,t[e.name]),children:g(t[e.name],e)},n))},n))]},t.key)):r?.map((t,n)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:h(e.name,t[e.name]),children:g(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,W.jsx)(`div`,{className:`prose max-w-none`,children:(0,W.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,W.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,W.jsx)(a,{schema:e.content})]},t)),!n.sections&&r&&r.length>0&&(0,W.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,W.jsx)(`thead`,{className:`bg-muted`,children:(0,W.jsx)(`tr`,{children:n.fields?.map((e,t)=>(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,W.jsx)(`tbody`,{children:r.map((e,t)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:n.fields?.map((t,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:h(t.name,e[t.name]),children:g(e[t.name],t)},n))},t))})]})})]})]})]}):(0,W.jsx)(b,{children:(0,W.jsx)(H,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},ft=({schedule:e,onChange:t})=>{let[n,r]=(0,U.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),i=e=>{let i={...n,...e};r(i),t?.(i)};return(0,W.jsxs)(b,{children:[(0,W.jsx)(I,{children:(0,W.jsxs)(F,{className:`flex items-center gap-2`,children:[(0,W.jsx)(ce,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,W.jsxs)(H,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:n.enabled||!1,onChange:e=>i({enabled:e.target.checked}),className:`rounded`}),(0,W.jsx)(z,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),n.enabled&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Frequency`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.frequency||`weekly`,onChange:e=>i({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`weekly`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Day of Week`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.dayOfWeek??1,onChange:e=>i({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`monthly`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Day of Month`}),(0,W.jsx)(L,{type:`number`,min:1,max:31,value:n.dayOfMonth??1,onChange:e=>i({dayOfMonth:Number(e.target.value)})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,W.jsx)(D,{className:`h-4 w-4`}),`Time`]}),(0,W.jsx)(L,{type:`time`,value:n.time||`09:00`,onChange:e=>i({time:e.target.value})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Timezone`}),(0,W.jsx)(L,{value:n.timezone||``,onChange:e=>i({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Export Formats`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n.formats?.includes(e.value)||!1,onChange:t=>{let r=n.formats||[];i({formats:t.target.checked?[...r,e.value]:r.filter(t=>t!==e.value)})},className:`rounded`}),(0,W.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,W.jsx)(ee,{className:`h-4 w-4`}),`Email Recipients`]}),(0,W.jsx)(L,{placeholder:`email1@example.com, email2@example.com`,value:n.recipients?.join(`, `)||``,onChange:e=>i({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Email Subject`}),(0,W.jsx)(L,{value:n.subject||``,onChange:e=>i({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},pt=({schema:e})=>{let{report:t,dataSources:n=[],availableFields:r=[],showPreview:i=!0,onSave:a,onCancel:o}=e,[s,c]=(0,U.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[l,f]=(0,U.useState)(s.fields||[]),[p,m]=(0,U.useState)(s.filters||[]),[g,_]=(0,U.useState)(s.groupBy||[]),[v,x]=(0,U.useState)(s.sections||[]),S=()=>{if(r.length>0&&l.length<r.length){let e=r.find(e=>!l.some(t=>t.name===e.name));if(e){let t=[...l,e];f(t),c({...s,fields:t})}}},w=e=>{let t=l.filter((t,n)=>n!==e);f(t),c({...s,fields:t})},T=(e,t)=>{let n=[...l];n[e]=t,f(n),c({...s,fields:n})},E=()=>{let e={field:r[0]?.name||``,operator:`equals`,value:``},t=[...p,e];m(t),c({...s,filters:t})},D=e=>{let t=p.filter((t,n)=>n!==e);m(t),c({...s,filters:t})},O=(e,t)=>{let n=[...p];n[e]=t,m(n),c({...s,filters:n})},k=()=>{let e={field:r[0]?.name||``,sort:`asc`},t=[...g,e];_(t),c({...s,groupBy:t})},A=e=>{let t=g.filter((t,n)=>n!==e);_(t),c({...s,groupBy:t})},j=(e,t)=>{let n=[...g];n[e]=t,_(n),c({...s,groupBy:n})},M=e=>{let t={type:e,title:`New ${e} Section`},n=[...v,t];x(n),c({...s,sections:n})},N=e=>{let t=v.filter((t,n)=>n!==e);x(t),c({...s,sections:t})},P=(e,t)=>{let n=[...v];n[e]=t,x(n),c({...s,sections:n})};return(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(b,{children:[(0,W.jsxs)(I,{children:[(0,W.jsx)(F,{children:`Report Builder`}),(0,W.jsx)(y,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,W.jsxs)(H,{children:[(0,W.jsxs)(u,{defaultValue:`basic`,className:`w-full`,children:[(0,W.jsxs)(le,{className:`grid w-full grid-cols-6`,children:[(0,W.jsxs)(V,{value:`basic`,children:[(0,W.jsx)(se,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,W.jsxs)(V,{value:`fields`,children:[(0,W.jsx)(ie,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,W.jsxs)(V,{value:`filters`,children:[(0,W.jsx)(d,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,W.jsxs)(V,{value:`grouping`,children:[(0,W.jsx)(ie,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,W.jsxs)(V,{value:`sections`,children:[(0,W.jsx)(ie,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,W.jsxs)(V,{value:`schedule`,children:[(0,W.jsx)(ce,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,W.jsx)(R,{value:`basic`,className:`space-y-4 mt-4`,children:(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{htmlFor:`report-title`,children:`Report Title`}),(0,W.jsx)(L,{id:`report-title`,value:s.title||``,onChange:e=>c({...s,title:e.target.value}),placeholder:`Enter report title`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{htmlFor:`report-description`,children:`Description`}),(0,W.jsx)(L,{id:`report-description`,value:s.description||``,onChange:e=>c({...s,description:e.target.value}),placeholder:`Enter report description`})]}),n.length>0&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Data Source`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,W.jsx)(`option`,{value:``,children:`Select a data source`}),n.map((e,t)=>(0,W.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Export Options`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:s.showExportButtons||!1,onChange:e=>c({...s,showExportButtons:e.target.checked})}),(0,W.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:s.showPrintButton||!1,onChange:e=>c({...s,showPrintButton:e.target.checked})}),(0,W.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{htmlFor:`export-format`,children:`Default Export Format`}),(0,W.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:s.defaultExportFormat||`pdf`,onChange:e=>c({...s,defaultExportFormat:e.target.value}),children:[(0,W.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,W.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,W.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,W.jsx)(`option`,{value:`json`,children:`JSON`}),(0,W.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,W.jsxs)(R,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Report Fields`}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:S,disabled:l.length>=r.length,children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[l.map((e,t)=>(0,W.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Field Name`}),(0,W.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Label`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>T(t,{...e,label:n.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Aggregation`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>T(t,{...e,aggregation:n.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`None`}),(0,W.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,W.jsx)(`option`,{value:`count`,children:`Count`}),(0,W.jsx)(`option`,{value:`avg`,children:`Average`}),(0,W.jsx)(`option`,{value:`min`,children:`Min`}),(0,W.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,W.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>w(t),children:(0,W.jsx)(C,{className:`h-4 w-4`})})})]})},t)),l.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,W.jsxs)(R,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Report Filters`}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:E,children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Field`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>O(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Operator`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>O(t,{...e,operator:n.target.value}),children:[(0,W.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,W.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,W.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,W.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,W.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Value`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>O(t,{...e,value:n.target.value})})]})]}),(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>D(t),children:(0,W.jsx)(C,{className:`h-4 w-4`})})]},t)),p.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,W.jsxs)(R,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Grouping Rules`}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:k,children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[g.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Field`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>j(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Sort Order`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>j(t,{...e,sort:n.target.value}),children:[(0,W.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,W.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>A(t),children:(0,W.jsx)(C,{className:`h-4 w-4`})})]},t)),g.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,W.jsxs)(R,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Report Sections`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>M(`header`),children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>M(`chart`),children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>M(`table`),children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[v.map((e,t)=>(0,W.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>N(t),children:(0,W.jsx)(C,{className:`h-4 w-4`})})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Title`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>P(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,W.jsxs)(`div`,{className:`col-span-2`,children:[(0,W.jsx)(z,{className:`text-xs`,children:`Content`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>P(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,W.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,W.jsx)(`div`,{className:`col-span-2`,children:(0,W.jsx)(z,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Chart Type`}),(0,W.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,W.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,W.jsx)(`option`,{value:`line`,children:`Line`}),(0,W.jsx)(`option`,{value:`area`,children:`Area`}),(0,W.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`X-Axis Field`}),(0,W.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,W.jsx)(`option`,{value:``,children:`Select Field...`}),r.map(e=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),r.length===0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`option`,{value:`name`,children:`Name`}),(0,W.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,W.jsxs)(`div`,{className:`col-span-2`,children:[(0,W.jsx)(z,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,W.jsx)(L,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),v.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,W.jsx)(R,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,W.jsx)(ft,{schedule:s.schedule,onChange:e=>c({...s,schedule:e})})})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,W.jsx)(B,{variant:`outline`,onClick:()=>{o&&console.log(`Report cancelled:`,o)},children:`Cancel`}),(0,W.jsxs)(B,{onClick:()=>{console.log(`Saving report:`,s),a&&alert(`Report saved! (Handler: `+a+`)`)},children:[(0,W.jsx)(ne,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),i&&(0,W.jsxs)(b,{className:`mt-8 border-2 border-blue-100`,children:[(0,W.jsx)(I,{className:`bg-blue-50/50`,children:(0,W.jsx)(F,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,W.jsx)(H,{className:`pt-6`,children:(0,W.jsx)(dt,{schema:{type:`report-viewer`,report:{...s,fields:l,filters:p,groupBy:g,sections:v},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},mt=[`tabular`,`summary`,`matrix`];function ht(e){let t=e.length+1,n=new Set(e.map(e=>e.name).filter(Boolean)),r=`block_${t}`;for(;n.has(r);)t+=1,r=`block_${t}`;return{name:r,type:`tabular`,columns:[]}}function gt(e){return typeof e.label==`string`?e.label:e.label&&typeof e.label==`object`?e.label.default??``:``}function _t(e){return typeof e.description==`string`?e.description:e.description&&typeof e.description==`object`?e.description.default??``:``}function vt({block:e,index:t,total:n,availableFields:r,t:i,duplicateName:a,onChange:o,onRemove:s,onMove:c}){let[l,u]=U.useState(t===0),d=e.type??`tabular`,f=d===`summary`,p=d===`matrix`,m=f||p,h=!e.name||!e.name.trim(),g=h||a,_=t=>o({...e,...t});return(0,W.jsxs)(`div`,{className:`border rounded-md bg-card text-card-foreground`,"data-testid":`joined-block-${t}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 border-b bg-muted/30`,children:[(0,W.jsx)(B,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0`,onClick:()=>u(e=>!e),"aria-label":l?`Collapse block`:`Expand block`,"aria-expanded":l,"data-testid":`joined-block-toggle-${t}`,children:l?(0,W.jsx)(x,{className:`h-3.5 w-3.5`}):(0,W.jsx)(P,{className:`h-3.5 w-3.5`})}),(0,W.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background flex-1 min-w-0 ${g?`border-destructive`:``}`,value:e.name??``,onChange:e=>_({name:e.target.value}),placeholder:i(`report.editor.blockNamePlaceholder`),"aria-label":i(`report.editor.blockName`),"aria-invalid":g,"data-testid":`joined-block-name-${t}`}),(0,W.jsx)(`select`,{className:`h-6 text-xs border rounded px-1 bg-background shrink-0`,value:d,onChange:e=>_({type:e.target.value}),"aria-label":i(`report.editor.type`),"data-testid":`joined-block-type-${t}`,children:mt.map(e=>(0,W.jsx)(`option`,{value:e,children:i(`report.editor.type${e.charAt(0).toUpperCase()}${e.slice(1)}`)},e))}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>c(-1),"aria-label":`Move block up`,children:(0,W.jsx)(de,{className:`h-2.5 w-2.5`})}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n-1,onClick:()=>c(1),"aria-label":`Move block down`,children:(0,W.jsx)(j,{className:`h-2.5 w-2.5`})})]}),(0,W.jsx)(B,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0 text-destructive hover:text-destructive`,onClick:s,"aria-label":i(`report.editor.removeBlock`),"data-testid":`joined-block-remove-${t}`,children:(0,W.jsx)(C,{className:`h-3 w-3`})})]}),g&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 text-[10px] text-destructive bg-destructive/5 border-b`,children:[(0,W.jsx)(O,{className:`h-3 w-3`}),i(h?`report.editor.validationBlockNameRequired`:`report.editor.validationBlockNameDuplicate`)]}),l&&(0,W.jsxs)(`div`,{className:`p-2 space-y-2 text-xs`,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockLabel`)}),(0,W.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:gt(e),onChange:e=>_({label:e.target.value||void 0}),placeholder:i(`report.editor.blockLabelPlaceholder`),"data-testid":`joined-block-label-${t}`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.objectName`)}),(0,W.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:e.objectName??``,onChange:e=>_({objectName:e.target.value||void 0}),placeholder:i(`report.editor.objectNamePlaceholder`),"data-testid":`joined-block-object-${t}`})]})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockDescription`)}),(0,W.jsx)(`textarea`,{className:`text-xs border rounded px-1.5 py-1 bg-background resize-y min-h-[2rem]`,rows:2,value:_t(e),onChange:e=>_({description:e.target.value||void 0}),placeholder:i(`report.editor.blockDescriptionPlaceholder`),"data-testid":`joined-block-description-${t}`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columns`)}),(0,W.jsx)(Lt,{availableFields:r,value:e.columns,onChange:e=>_({columns:e}),t:i})]}),(f||p)&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.rows`)}),(0,W.jsx)($,{availableFields:r,value:e.groupingsDown,onChange:e=>_({groupingsDown:e}),t:i})]}),p&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columnsAxis`)}),(0,W.jsx)($,{availableFields:r,value:e.groupingsAcross,onChange:e=>_({groupingsAcross:e}),t:i})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.filters`)}),(0,W.jsx)(At,{availableFields:r,value:e.filter,onChange:e=>_({filter:e}),t:i})]}),m&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.chart`)}),(0,W.jsx)(Rt,{availableFields:r,columns:It(e.columns),value:e.chart,onChange:e=>_({chart:e}),t:i})]})]})]})}function yt(e){return Array.isArray(e)?e.map(e=>{let t=e??{};return{name:t.name??``,type:t.type??`tabular`,columns:Array.isArray(t.columns)?t.columns:[],...t}}):[]}function bt({value:e,onChange:t,availableFields:n,getFieldsForObject:r,containerObjectName:i,t:a}){let o=yt(e),s=e=>r?r(e.objectName??i)??n:n,c={};for(let e of o)e.name&&(c[e.name]=(c[e.name]??0)+1);let l=(e,n)=>{t(o.map((t,r)=>r===e?n:t))},u=e=>{t(o.filter((t,n)=>n!==e))},d=(e,n)=>{let r=e+n;if(r<0||r>=o.length)return;let i=[...o];[i[e],i[r]]=[i[r],i[e]],t(i)};return(0,W.jsxs)(`div`,{className:`space-y-2`,"data-testid":`joined-blocks-editor`,children:[o.length===0&&(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic px-1`,children:a(`report.editor.validationJoinedNeedsBlocks`)}),o.map((e,t)=>(0,W.jsx)(vt,{block:e,index:t,total:o.length,availableFields:s(e),t:a,duplicateName:!!e.name&&(c[e.name]??0)>1,onChange:e=>l(t,e),onRemove:()=>u(t),onMove:e=>d(t,e)},t)),(0,W.jsxs)(B,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs w-full`,onClick:()=>{t([...o,ht(o)])},"data-testid":`joined-block-add`,children:[(0,W.jsx)(h,{className:`h-3 w-3 mr-1`}),a(`report.editor.addBlock`)]})]})}function xt(e,t){let n=[];if(!Array.isArray(e)||e.length===0)return n.push(t(`report.editor.validationJoinedNeedsBlocks`)),n;let r=new Map,i=!1,a=!1,o=!1;for(let t of e){let e=t??{};if(!e.name||!String(e.name).trim())i=!0;else{let t=(r.get(e.name)??0)+1;r.set(e.name,t),t===2&&(a=!0)}(!Array.isArray(e.columns)||e.columns.length===0)&&(o=!0)}return i&&n.push(t(`report.editor.validationBlockNameRequired`)),a&&n.push(t(`report.editor.validationBlockNameDuplicate`)),o&&n.push(t(`report.editor.validationBlockNeedsColumns`)),n}var St={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$in:`in`,$nin:`notIn`,$contains:`contains`,$notContains:`notContains`,$exists:`isNotEmpty`},Ct={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,in:`$in`,notIn:`$nin`,contains:`$contains`,notContains:`$notContains`},wt=()=>({id:`root`,logic:`and`,conditions:[]});function Tt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Q(){return Math.random().toString(36).slice(2,10)}function Et(e,t){if(typeof t!=`object`||!t||Array.isArray(t))return[{id:Q(),field:e,operator:Array.isArray(t)?`in`:`equals`,value:t}];let n=[];for(let[r,i]of Object.entries(t)){if(r===`$exists`){n.push({id:Q(),field:e,operator:i===!1?`isEmpty`:`isNotEmpty`,value:``});continue}if(r===`$null`){n.push({id:Q(),field:e,operator:i===!1?`isNotEmpty`:`isEmpty`,value:``});continue}let t=St[r];if(!t||Tt(i)&&`$field`in i)return null;n.push({id:Q(),field:e,operator:t,value:i})}return n.length>0?n:null}function Dt(e){if(e==null)return{group:wt(),complex:!1};if(!Tt(e))return{group:wt(),complex:!0};let t=Object.keys(e);if(t.length===1&&(t[0]===`$and`||t[0]===`$or`)){let n=t[0]===`$or`?`or`:`and`,r=e[t[0]];if(!Array.isArray(r))return{group:wt(),complex:!0};let i=[],a=!1;for(let e of r){if(!Tt(e)){a=!0;continue}if(Object.keys(e).some(e=>e===`$and`||e===`$or`||e===`$not`)){a=!0;continue}for(let[t,n]of Object.entries(e)){let e=Et(t,n);e?i.push(...e):a=!0}}return{group:{id:`root`,logic:n,conditions:i},complex:a}}if(t.includes(`$not`)||t.includes(`$and`)||t.includes(`$or`))return{group:wt(),complex:!0};let n=[],r=!1;for(let[t,i]of Object.entries(e)){let e=Et(t,i);e?n.push(...e):r=!0}return{group:{id:`root`,logic:`and`,conditions:n},complex:r}}function Ot(e){if(!e||!Array.isArray(e.conditions)||e.conditions.length===0)return;let t=e.conditions.filter(e=>e.field).map(e=>kt(e));if(t.length!==0)return t.length===1?t[0]:{[e.logic===`or`?`$or`:`$and`]:t}}function kt(e){let{field:t,operator:n,value:r}=e;if(n===`isEmpty`)return{[t]:{$exists:!1}};if(n===`isNotEmpty`)return{[t]:{$exists:!0}};if(n===`equals`)return{[t]:r};let i=Ct[n];return i?{[t]:{[i]:r}}:{[t]:r}}function At({availableFields:e,value:t,onChange:n,t:r}){let i=U.useMemo(()=>JSON.stringify(t??null),[t]),a=U.useMemo(()=>Dt(t),[i]),[o,s]=U.useState(a.group),c=U.useRef(i);U.useEffect(()=>{c.current!==i&&(s(a.group),c.current=i)},[i,a.group]);let l=e=>{s(e);let t=Ot(e);c.current=JSON.stringify(t??null),n(t)};if(a.complex)return(0,W.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-[11px]`,children:[(0,W.jsx)(O,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:r(`report.editor.filtersComplex`)})]});let u=()=>{l({...o,conditions:[...o.conditions,{id:Q(),field:e[0]?.value??``,operator:`equals`,value:``}]})},d=e=>{l({...o,conditions:o.conditions.filter(t=>t.id!==e)})},f=(e,t)=>{l({...o,conditions:o.conditions.map(n=>n.id===e?{...n,...t}:n)})},p=[{value:`equals`,label:`=`},{value:`notEquals`,label:`≠`},{value:`greaterThan`,label:`>`},{value:`greaterOrEqual`,label:`≥`},{value:`lessThan`,label:`<`},{value:`lessOrEqual`,label:`≤`},{value:`contains`,label:r(`report.editor.opContains`,`contains`)},{value:`in`,label:`in`},{value:`notIn`,label:`not in`},{value:`isEmpty`,label:r(`report.editor.opIsEmpty`,`is empty`)},{value:`isNotEmpty`,label:r(`report.editor.opIsNotEmpty`,`is not empty`)}];return(0,W.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`spec-filter-adapter`,children:[o.conditions.length>1&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:r(`report.editor.combineLogic`,`Combine with`)}),(0,W.jsxs)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:o.logic,onChange:e=>l({...o,logic:e.target.value}),"data-testid":`filter-logic-select`,children:[(0,W.jsx)(`option`,{value:`and`,children:`AND`}),(0,W.jsx)(`option`,{value:`or`,children:`OR`})]})]}),o.conditions.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,W.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:t.field,onChange:e=>f(t.id,{field:e.target.value}),"data-testid":`filter-field-${t.id}`,children:e.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-20 shrink-0`,value:t.operator,onChange:e=>f(t.id,{operator:e.target.value}),"data-testid":`filter-op-${t.id}`,children:p.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),t.operator!==`isEmpty`&&t.operator!==`isNotEmpty`&&(0,W.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-24 shrink-0`,value:Array.isArray(t.value)?t.value.join(`,`):(t.value??``).toString(),placeholder:`value`,onChange:e=>{let n=e.target.value,r=t.operator===`in`||t.operator===`notIn`?n.split(`,`).map(e=>e.trim()).filter(Boolean):n;f(t.id,{value:r})},"data-testid":`filter-value-${t.id}`}),(0,W.jsx)(B,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>d(t.id),"data-testid":`filter-remove-${t.id}`,children:(0,W.jsx)(C,{className:`h-3 w-3`})})]},t.id)),(0,W.jsxs)(B,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:u,disabled:e.length===0,"data-testid":`filter-add`,children:[(0,W.jsx)(h,{className:`h-3 w-3 mr-1`}),r(`report.editor.addCondition`,`Add condition`)]})]})}var jt=new Set([`date`,`datetime`,`time`]),Mt=new Set([`number`,`currency`,`percent`,`rating`,`integer`]);function Nt({availableFields:e,selectedValues:t,onAdd:n,t:r,triggerLabel:i,title:a,description:o,testIdPrefix:s=`field-picker`,singleSelect:c=!1,commitOnSelect:l=!1,disabled:u=!1,triggerClassName:d,trigger:f}){let[p,y]=U.useState(!1),[b,x]=U.useState(``),[C,w]=U.useState(new Set),T=U.useMemo(()=>new Set(t),[t]);U.useEffect(()=>{p&&(x(``),w(new Set))},[p]);let E=b.trim().toLowerCase(),D=e.filter(e=>!T.has(e.value)),O=E?D.filter(e=>e.label.toLowerCase().includes(E)||e.value.toLowerCase().includes(E)):D,k=e=>{if(c&&l){n([e]),y(!1);return}w(t=>{let n=new Set(c?[]:t);return t.has(e)?n.delete(e):n.add(e),n})},j=()=>{if(C.size===0){y(!1);return}n(D.map(e=>e.value).filter(e=>C.has(e))),y(!1)},M=()=>{y(!1)},P=e.length===0,F=!P&&D.length===0,I=i??r(`report.editor.addColumns`,`Add fields`),ee=a??r(`report.editor.fieldPickerTitle`,`Select fields`),ne=o??r(`report.editor.fieldPickerDescription`,`Pick one or more fields to add. Use the search box to narrow the list.`);return(0,W.jsxs)(g,{open:p,onOpenChange:y,children:[(0,W.jsx)(N,{asChild:!0,children:f??(0,W.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,className:d??`h-8 gap-1.5`,disabled:u||P||F,"data-testid":`${s}-trigger`,children:[(0,W.jsx)(h,{className:`h-3.5 w-3.5`}),(0,W.jsx)(`span`,{children:I})]})}),(0,W.jsxs)(v,{className:`sm:max-w-md max-w-[92vw] gap-3`,"data-testid":`${s}-dialog`,children:[(0,W.jsxs)(fe,{children:[(0,W.jsx)(m,{children:ee}),(0,W.jsx)(S,{children:ne})]}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsx)(te,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,W.jsx)(`input`,{type:`text`,className:`h-9 w-full text-sm border rounded pl-7 pr-2 bg-background`,placeholder:r(`report.editor.searchFields`,`Search fields…`),value:b,onChange:e=>x(e.target.value),"data-testid":`${s}-search`,autoFocus:!0})]}),(0,W.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{children:[O.length,`/`,D.length,C.size>0?` · ${r(`report.editor.fieldPickerSelected`,`{n} selected`).replace(`{n}`,String(C.size))}`:``]}),C.size>0&&(0,W.jsx)(`button`,{type:`button`,className:`text-[11px] underline-offset-2 hover:underline text-muted-foreground`,onClick:()=>w(new Set),"data-testid":`${s}-clear`,children:r(`report.editor.fieldPickerClear`,`Clear selection`)})]}),(0,W.jsx)(`div`,{className:`max-h-72 overflow-auto border rounded bg-background/40 p-1 space-y-0.5`,"data-testid":`${s}-list`,children:P?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):F?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFieldsAvailable`,`All fields already added.`)}):O.length===0?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noMatchingFields`,`No fields match your search.`)}):O.map(e=>{let t=C.has(e.value);return(0,W.jsxs)(`label`,{className:`flex items-center gap-2 px-2 py-1.5 rounded hover:bg-muted/50 text-sm cursor-pointer`,"data-testid":`${s}-row-${e.value}`,children:[(0,W.jsx)(_,{checked:t,onCheckedChange:()=>k(e.value),"data-testid":`${s}-toggle-${e.value}`}),(0,W.jsx)(`span`,{className:`flex-1 truncate`,title:e.label,children:e.label}),e.type&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:e.type})]},e.value)})}),!(c&&l)&&(0,W.jsxs)(A,{className:`gap-2 sm:gap-2`,children:[(0,W.jsx)(B,{type:`button`,variant:`ghost`,size:`sm`,onClick:M,"data-testid":`${s}-cancel`,children:r(`common.cancel`,`Cancel`)}),(0,W.jsx)(B,{type:`button`,size:`sm`,onClick:j,disabled:C.size===0,"data-testid":`${s}-confirm`,children:C.size>0?r(`report.editor.fieldPickerAddN`,`Add {n}`).replace(`{n}`,String(C.size)):r(`report.editor.fieldPickerAdd`,`Add`)})]})]})]})}function Pt(e){return[{value:``,label:e(`report.editor.noneOption`)},{value:`sum`,label:e(`report.aggregate.sum`)},{value:`count`,label:e(`report.aggregate.count`)},{value:`unique`,label:e(`report.aggregate.countDistinct`)},{value:`avg`,label:e(`report.aggregate.avg`)},{value:`min`,label:e(`report.aggregate.min`)},{value:`max`,label:e(`report.aggregate.max`)}]}function Ft(e){return[{value:``,label:e(`report.editor.formatAuto`,`Auto`)},{value:`currency`,label:e(`report.editor.formatCurrency`,`Currency`)},{value:`percent`,label:e(`report.editor.formatPercent`,`Percent`)},{value:`integer`,label:e(`report.editor.formatInteger`,`Integer`)},{value:`date`,label:e(`report.editor.formatDate`,`Date`)},{value:`datetime`,label:e(`report.editor.formatDatetime`,`Date & time`)}]}function It(e){return Array.isArray(e)?e.map(e=>typeof e==`string`?{field:e,label:e,type:`string`}:{field:e.field||e.name||e.value,label:e.label,type:e.type||`string`,aggregate:e.aggregate??e.aggregation,format:e.format}):[]}function Lt({availableFields:e,value:t,onChange:n,t:r}){let i=It(t),a=new Set(i.map(e=>e.field)),o=Pt(r),s=Ft(r),c=t=>{if(t.length===0)return;let r=t.filter(e=>!a.has(e)).map(t=>{let n=e.find(e=>e.value===t);return{field:t,label:n?.label,type:n?.type||`string`}});r.length!==0&&n([...i,...r])},l=e=>{n(i.filter(t=>t.field!==e))},u=(e,t)=>{n(i.map(n=>n.field===e?{...n,...t}:n))},d=(e,t)=>{let r=[...i],a=e+t;a<0||a>=r.length||([r[e],r[a]]=[r[a],r[e]],n(r))};return e.length===0?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`columns-editor-empty`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):(0,W.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`columns-editor`,children:[i.length>0&&(0,W.jsx)(`div`,{className:`space-y-1.5`,"data-testid":`columns-selected`,children:i.map((t,n)=>{let a=e.find(e=>e.value===t.field);return(0,W.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-1.5 p-1.5 border rounded bg-muted/30 text-xs`,"data-testid":`column-row-${t.field}`,children:[(0,W.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center justify-center gap-0.5`,children:[(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>d(n,-1),"aria-label":`Move up`,"data-testid":`column-up-${t.field}`,children:(0,W.jsx)(de,{className:`h-3 w-3`})}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===i.length-1,onClick:()=>d(n,1),"aria-label":`Move down`,"data-testid":`column-down-${t.field}`,children:(0,W.jsx)(j,{className:`h-3 w-3`})})]}),(0,W.jsx)(`input`,{className:`h-7 text-xs border rounded px-2 bg-background min-w-0 w-full`,value:t.label??``,placeholder:a?.label??t.field,onChange:e=>u(t.field,{label:e.target.value||void 0}),"data-testid":`column-label-${t.field}`,title:a?.label??t.field}),(0,W.jsx)(B,{type:`button`,size:`sm`,variant:`ghost`,className:`row-span-2 h-7 w-7 p-0 shrink-0 self-start`,onClick:()=>l(t.field),"data-testid":`column-remove-${t.field}`,"aria-label":`Remove column`,children:(0,W.jsx)(C,{className:`h-3.5 w-3.5`})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.aggregateColumn`,`Aggregate`)}),(0,W.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.aggregate??``,onChange:e=>u(t.field,{aggregate:e.target.value===``?void 0:e.target.value}),"data-testid":`column-agg-${t.field}`,children:o.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.formatColumn`,`Format`)}),(0,W.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.format??``,onChange:e=>u(t.field,{format:e.target.value===``?void 0:e.target.value}),"data-testid":`column-fmt-${t.field}`,children:s.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]})]},t.field)})}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i.length>0?r(`report.editor.columnsCount`,`{n} column(s) selected`).replace(`{n}`,String(i.length)):r(`report.editor.columnsEmpty`,`No columns selected yet.`)}),(0,W.jsx)(Nt,{availableFields:e,selectedValues:i.map(e=>e.field),onAdd:c,t:r,testIdPrefix:`columns-picker`,triggerLabel:r(`report.editor.addColumns`,`Add fields`)})]})]})}function $({availableFields:e,value:t,onChange:n,t:r,testIdPrefix:i=`grouping`}){let a=Array.isArray(t)?t.map(e=>({field:e.field??``,sortOrder:e.sortOrder??e.sort??`asc`,dateGranularity:e.dateGranularity})):[],o=[{value:``,label:r(`report.editor.dateGranularityNone`)},{value:`day`,label:r(`report.editor.day`)},{value:`week`,label:r(`report.editor.week`)},{value:`month`,label:r(`report.editor.month`)},{value:`quarter`,label:r(`report.editor.quarter`)},{value:`year`,label:r(`report.editor.year`)}],s=a.map(e=>e.field).filter(Boolean),c=e=>{n(a.filter((t,n)=>n!==e))},l=(e,t)=>{n(a.map((n,r)=>r===e?{...n,...t}:n))},u=(e,t)=>{let r=[...a],i=e+t;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],n(r))},d=e=>{if(e.length===0)return;let t=e.map(e=>({field:e,sortOrder:`asc`}));n([...a,...t])},f=(t,n)=>{let r=n[0];if(!r)return;let i=e.find(e=>e.value===r);l(t,{field:r,dateGranularity:i&&jt.has(i.type??``)?a[t]?.dateGranularity:void 0})};return(0,W.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`${i}s-builder`,children:[a.map((t,n)=>{let d=e.find(e=>e.value===t.field),p=d&&jt.has(d.type??``),m=d?.label??t.field??r(`report.editor.fieldPickerEmpty`,`(pick field)`);return(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5 border rounded bg-muted/20 text-xs`,"data-testid":`${i}-row-${n}`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>u(n,-1),"aria-label":`Move up`,"data-testid":`${i}-up-${n}`,children:(0,W.jsx)(de,{className:`h-3 w-3`})}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===a.length-1,onClick:()=>u(n,1),"aria-label":`Move down`,"data-testid":`${i}-down-${n}`,children:(0,W.jsx)(j,{className:`h-3 w-3`})})]}),(0,W.jsx)(Nt,{availableFields:e,selectedValues:s.filter(e=>e!==t.field),onAdd:e=>f(n,e),t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-field-picker-${n}`,title:r(`report.editor.fieldPickerChangeTitle`,`Change field`),trigger:(0,W.jsxs)(`button`,{type:`button`,className:`h-7 flex-1 min-w-0 text-left text-xs border rounded px-2 bg-background hover:bg-muted/40 inline-flex items-center justify-between gap-1.5`,"data-testid":`${i}-field-${n}`,title:m,children:[(0,W.jsx)(`span`,{className:`truncate`,children:m}),(0,W.jsx)(x,{className:`h-3 w-3 text-muted-foreground shrink-0`})]})}),(0,W.jsxs)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-20 shrink-0`,value:t.sortOrder??`asc`,onChange:e=>l(n,{sortOrder:e.target.value}),"data-testid":`${i}-sort-${n}`,children:[(0,W.jsx)(`option`,{value:`asc`,children:r(`report.editor.sortAsc`)}),(0,W.jsx)(`option`,{value:`desc`,children:r(`report.editor.sortDesc`)})]}),p&&(0,W.jsx)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-24 shrink-0`,value:t.dateGranularity??``,onChange:e=>l(n,{dateGranularity:e.target.value||void 0}),"data-testid":`${i}-granularity-${n}`,children:o.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.jsx)(B,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 shrink-0`,onClick:()=>c(n),"aria-label":`Remove grouping`,"data-testid":`${i}-remove-${n}`,children:(0,W.jsx)(C,{className:`h-3.5 w-3.5`})})]},n)}),(0,W.jsx)(Nt,{availableFields:e,selectedValues:s,onAdd:d,t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-add-picker`,triggerLabel:r(`report.editor.addGrouping`),title:r(`report.editor.fieldPickerAddGroupingTitle`,`Add grouping`),triggerClassName:`h-8 w-full justify-center gap-1.5`})]})}function Rt({availableFields:e,columns:t,value:n,onChange:r,t:i}){let a=n||{},o=a.type??a.chartType??``,s=a.xAxis??a.xAxisField??``,c=a.yAxis??a.yAxisFields?.[0]??``,l=e=>{let t={...a,...e};if(`type`in e&&delete t.chartType,`xAxis`in e&&delete t.xAxisField,`yAxis`in e&&delete t.yAxisFields,!e.type&&e.type===``)return r(void 0);r(t)},u=()=>r(void 0),d=[{value:``,label:i(`report.editor.chartNone`)},{value:`bar`,label:i(`report.editor.chartBar`)},{value:`line`,label:i(`report.editor.chartLine`)},{value:`area`,label:i(`report.editor.chartArea`)},{value:`pie`,label:i(`report.editor.chartPie`)},{value:`donut`,label:i(`report.editor.chartDonut`)},{value:`funnel`,label:i(`report.editor.chartFunnel`)}],f=t.filter(e=>e.aggregate).map(e=>e.field),p=e.filter(e=>Mt.has(e.type??``)).map(e=>e.value),m=new Set([...f,...p]),h=e.filter(e=>m.has(e.value));return(0,W.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartType`)}),(0,W.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:o,onChange:e=>{let t=e.target.value;t?l({type:t}):u()},"data-testid":`chart-type-select`,children:d.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),o&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartTitle`)}),(0,W.jsx)(`input`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:a.title??``,placeholder:i(`report.editor.chartTitlePlaceholder`),onChange:e=>l({title:e.target.value||void 0}),"data-testid":`chart-title`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartXAxis`)}),(0,W.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s,onChange:e=>l({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,W.jsx)(`option`,{value:``,children:`—`}),e.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartYAxis`)}),(0,W.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:c,onChange:e=>l({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,W.jsx)(`option`,{value:``,children:`—`}),(h.length>0?h:e).map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,W.jsx)(_,{checked:a.showLegend!==!1,onCheckedChange:e=>l({showLegend:e===!0}),"data-testid":`chart-show-legend`}),(0,W.jsx)(`span`,{children:i(`report.editor.chartShowLegend`)})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,W.jsx)(_,{checked:!!a.showDataLabels,onCheckedChange:e=>l({showDataLabels:e===!0}),"data-testid":`chart-show-data-labels`}),(0,W.jsx)(`span`,{children:i(`report.editor.chartShowDataLabels`)})]})]})]})}function zt(e,t,n){let r=e=>e.type===`summary`,i=e=>e.type===`matrix`,a=e=>e.type===`summary`||e.type===`matrix`,o=[{key:`basic`,title:t(`report.editor.basic`),fields:[{key:`label`,label:t(`report.editor.title`),type:`input`,placeholder:t(`report.editor.titlePlaceholder`)},{key:`description`,label:t(`report.editor.description`),type:`textarea`,placeholder:t(`report.editor.descriptionPlaceholder`)},{key:`type`,label:t(`report.editor.type`),type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:t(`report.editor.typeTabular`)},{value:`summary`,label:t(`report.editor.typeSummary`)},{value:`matrix`,label:t(`report.editor.typeMatrix`)},{value:`joined`,label:t(`report.editor.typeJoined`)}],helpText:t(`report.editor.typeHelp`)}]},{key:`data`,title:t(`report.editor.data`),collapsible:!0,fields:[{key:`objectName`,label:t(`report.editor.objectName`),type:`input`,placeholder:t(`report.editor.objectNamePlaceholder`),helpText:t(`report.editor.objectNameHelp`)},{key:`limit`,label:t(`report.editor.limit`),type:`input`,placeholder:t(`report.editor.limitPlaceholder`)}]},{key:`rows`,title:t(`report.editor.rows`),collapsible:!0,hint:t(`report.editor.rowsHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`groupingsDown`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,W.jsx)($,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`rows-grouping`})}]},{key:`columnsAxis`,title:t(`report.editor.columnsAxis`),collapsible:!0,hint:t(`report.editor.columnsAxisHint`),visibleWhen:e=>i(e),fields:[{key:`groupingsAcross`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,W.jsx)($,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`cols-grouping`})}]},{key:`tabular-columns`,title:t(`report.editor.columns`),collapsible:!0,hint:t(`report.editor.columnsHint`),visibleWhen:e=>e.type!==`joined`&&!r(e)&&!i(e),fields:[{key:`columns`,label:t(`report.editor.columns`),type:`custom`,render:(n,r)=>(0,W.jsx)(Lt,{availableFields:e,value:n,onChange:r,t})}]},{key:`values`,title:t(`report.editor.values`),collapsible:!0,hint:t(`report.editor.valuesHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`columns`,label:t(`report.editor.values`),type:`custom`,render:(n,r)=>(0,W.jsx)(Lt,{availableFields:e,value:n,onChange:r,t})}]},{key:`filters`,title:t(`report.editor.filters`),collapsible:!0,hint:t(`report.editor.filtersHint`),visibleWhen:e=>e.type!==`joined`,fields:[{key:`filter`,label:t(`report.editor.filters`),type:`custom`,render:(n,r)=>(0,W.jsx)(At,{availableFields:e,value:n,onChange:r,t})}]},{key:`blocks`,title:t(`report.editor.blocks`),collapsible:!0,hint:t(`report.editor.blocksHint`),visibleWhen:e=>e.type===`joined`,fields:[{key:`blocks`,label:t(`report.editor.blocks`),type:`custom`,render:(r,i,a)=>(0,W.jsx)(bt,{value:r,onChange:i,availableFields:e,getFieldsForObject:n,containerObjectName:a?.objectName,t})}]},{key:`chart`,title:t(`report.editor.chart`),collapsible:!0,defaultCollapsed:!0,hint:t(`report.editor.chartHint`),visibleWhen:e=>a(e),fields:[{key:`chart`,label:t(`report.editor.chart`),type:`custom`,render:(n,r,i)=>(0,W.jsx)(Rt,{availableFields:e,columns:It(i.columns),value:n,onChange:r,t})}]}];return{breadcrumb:[t(`report.editor.breadcrumb`,`Configuration`)],sections:o}}function Bt(e,t){let n=[],r=e.type??`tabular`,i=Array.isArray(e.groupingsDown)?e.groupingsDown.length:0,a=Array.isArray(e.groupingsAcross)?e.groupingsAcross.length:0,o=Array.isArray(e.columns)?e.columns.length:0;if(e.objectName||n.push({level:o>0?`error`:`warning`,message:t(`report.editor.validationNeedsObject`)}),r===`matrix`&&(i===0||a===0)&&n.push({level:`error`,message:t(`report.editor.validationMatrixNeedsRowsCols`)}),r===`summary`&&i===0&&n.push({level:`error`,message:t(`report.editor.validationSummaryNeedsRows`)}),r===`joined`)for(let r of xt(e.blocks,t))n.push({level:`error`,message:r});return n}function Vt({problems:e}){return e.length===0?null:(0,W.jsx)(`div`,{className:`space-y-1 p-2 border-b`,"data-testid":`report-validation-banner`,children:e.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] rounded px-2 py-1 `+(e.level===`error`?`bg-red-50 border border-red-200 text-red-900`:`bg-amber-50 border border-amber-200 text-amber-900`),children:[(0,W.jsx)(O,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:e.message})]},t))})}function Ht({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,availableFields:a,getFieldsForObject:o}){let{t:s}=l(),c=U.useCallback((e,t,n)=>t===void 0?s(e,n):s(e,{defaultValue:t,...n||{}}),[s]),u=a??[],d=U.useMemo(()=>zt(u,c,o),[u,c,o]),{draft:f,isDirty:p,updateField:m,discard:h}=ue(U.useMemo(()=>n??{},[n])),g=U.useCallback((e,t)=>{m(e,t),i?.(e,t,{...f,[e]:t})},[m,i,f]),_=U.useCallback(()=>{r(f),t()},[f,r,t]),v=U.useMemo(()=>Bt(f,c),[f,c]);return e?(0,W.jsx)(M,{open:e,onClose:t,schema:d,draft:f,isDirty:p,onFieldChange:g,onSave:_,onDiscard:h,headerExtra:(0,W.jsx)(Vt,{problems:v}),style:{"--config-panel-width":`440px`}}):null}async function Ut(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return rt(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function Wt(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(Kt),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return qt(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=Yt(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}Zt(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
+ `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function Gt(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await Ut(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function Kt(e){return{name:e.name,header:e.label||e.name}}function qt(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,Jt(t)):Xt(String(e))}function Jt(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function Yt(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function Xt(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function Zt(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}var Qt=t({JoinedBlocksEditor:()=>bt,JoinedReportRenderer:()=>Ye,LegacyReportRenderer:()=>me,MatrixRenderer:()=>Ge,ReportBuilder:()=>pt,ReportConfigPanel:()=>Ht,ReportRenderer:()=>Ze,ReportViewer:()=>dt,ScheduleConfig:()=>ft,SpecReportGrid:()=>Be,aggregateRows:()=>q,bucketDate:()=>he,buildAggregateQuery:()=>Te,buildDrillAction:()=>Me,collectFields:()=>we,columnKey:()=>G,createDrillHandler:()=>Pe,createScheduleTrigger:()=>Gt,exportAsCSV:()=>Qe,exportAsExcel:()=>nt,exportAsHTML:()=>et,exportAsJSON:()=>$e,exportAsPDF:()=>tt,exportExcelWithFormulas:()=>Wt,exportReport:()=>rt,exportWithLiveData:()=>Ut,formatValue:()=>st,groupAndAggregate:()=>ge,groupingValue:()=>K,isDrillAction:()=>Ne,mergeFilters:()=>J,pivotRows:()=>_e,registerDrillHandler:()=>Fe,useReportData:()=>De,validateJoinedBlocks:()=>xt});s.register(`report`,Ze,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),s.register(`spec-report`,Ze,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`type`,type:`string`,label:`Report Type`}]}),s.register(`report-viewer`,dt,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),s.register(`report-builder`,pt,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]});export{Qt as t};
@@ -0,0 +1 @@
1
+ import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{S as i,T as a,d as o}from"./vendor-objectstack-B3zP6Fz_.js";import{H as s,M as c,V as l,at as u,ot as d,r as f,ut as p}from"./framework-DVkqUSPj.js";import{As as m,Ms as h,N as g,js as _}from"./ui-components-CIdYg6m3.js";import{n as v}from"./vendor-ui-utils-BbOuugky.js";import{a as y}from"./plugin-grid-DGQxmfxn.js";var b=e(r(),1),x=n(),S=10080*60*1e3;function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t){let n=new Date(e);return t===`short`?n.toLocaleDateString():t===`long`?n.toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`}):n.toISOString().split(`T`)[0]}function E({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,x.jsx)(`span`,{className:m(`inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium`,!t&&`bg-muted text-muted-foreground border-transparent`),style:n,children:e})}function D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=D(i),r=e.some(e=>e.key!==``),s=(e,t)=>{let n=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,r=e.time?T(e.time,a):e.startDate?T(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?T(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,x.jsxs)(I,{density:`compact`,className:m(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(z,{children:[(r||i)&&(0,x.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,x.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,x.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,x.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,x.jsx)(H,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&_(e.content)]})]},t)};return r?(0,x.jsx)(`div`,{className:m(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,x.jsx)(`span`,{children:e.key}),(0,x.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,x.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,x.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,x.jsx)(U,{className:m(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,x.jsxs)(W,{className:m(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,x.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,x.jsx)(V,{dateTime:e.time,children:T(e.time,a)}),e.title&&(0,x.jsx)(B,{children:e.title}),e.description&&(0,x.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&_(e.content)]})]}),t<i.length-1&&(0,x.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=C(i),s=e.minDate||r.minDate,c=e.maxDate||r.maxDate,l=e.timeScale||`month`,u=(()=>{let e=[],t=new Date(s),n=new Date(c);if(l===`month`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`})),r.setMonth(r.getMonth()+1)}else if(l===`week`){let r=new Date(t);for(;r<=n;)e.push(`Week ${Math.ceil((r.getTime()-t.getTime())/S)+1}`),r.setDate(r.getDate()+7)}else if(l===`day`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})),r.setDate(r.getDate()+1)}return e})();return(0,x.jsxs)(G,{className:m(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,x.jsxs)(K,{children:[(0,x.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,x.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,x.jsx)(J,{children:(0,x.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,x.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,x.jsx)(`div`,{children:(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(q,{children:i.map((e,t)=>(0,x.jsx)(Y,{children:(0,x.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,x.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,x.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=w(n.startDate,n.endDate,s,c);return(0,x.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${T(n.startDate,a)} - ${T(n.endDate,a)}`,children:(0,x.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};p.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`},A=`timeline.bucket.today`;function j(e,t){let n=k[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function ee(){try{let e=f();return e.t(A)===A?{t:j}:{t:e.t}}catch{return{t:j}}}function te(){try{return h()}catch{return{fieldOptionLabel:(e,t,n,r)=>r,translateOptions:(e,t,n)=>n,fieldLabel:(e,t,n)=>n}}}var ne=i({mapping:i({title:a().optional(),date:a().optional(),description:a().optional(),variant:a().optional()}).optional(),objectName:a().optional(),titleField:a().optional(),dateField:a().optional(),startDateField:a().optional(),endDateField:a().optional(),descriptionField:a().optional(),groupByField:a().optional(),colorField:a().optional(),scale:o([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),M=({schema:e,dataSource:t,className:n,onRowClick:r,onItemClick:i,...a})=>{let[o,s]=(0,b.useState)([]),[f,p]=(0,b.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(a.data)&&a.data.length>0;return!t&&!n&&!!e.objectName}),[m,h]=(0,b.useState)(null),[_,v]=(0,b.useState)(0),[S,C]=(0,b.useState)(null),w=e.timeline;(0,b.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let T=l(e.bind);(0,b.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&C(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,b.useEffect)(()=>{e.objectName&&!T&&!e.items&&!a.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){p(!1);return}p(!0);try{let n=u(S?.fields);s(d(await t.find(e.objectName,{options:{$top:100},...n.length>0?{$expand:n}:{}})))}catch(e){console.error(e),h(e)}finally{p(!1)}})():p(!1)},[e.objectName,t,T,e.items,a.data,_,S]);let E=a.data||T||o,{t:D}=ee(),{fieldOptionLabel:k}=te(),A=w?.titleField??e.mapping?.title??e.titleField??`name`,j=w?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=w?.endDateField??e.endDateField??j,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=w?.groupByField??e.groupByField,I=w?.colorField??e.colorField,L=(0,b.useMemo)(()=>{if(e.items)return e.items;if(!E||!Array.isArray(E))return[];let t=S?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(I),a=Array.isArray(w?.metaFields)?w.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?k(n,e,String(t),i.label):String(t),color:i?.color}},l=E.map(e=>{let t=e[j],r=e[M],i=I?e[I]:void 0,l=F?e[F]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[A],time:t,startDate:t,endDate:r,description:e[N],variant:e[P]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return D(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?D(`timeline.bucket.noDate`):t<f?D(`timeline.bucket.overdue`):t===f?D(`timeline.bucket.today`):t===f+p?D(`timeline.bucket.tomorrow`):D(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(F&&!l.every(e=>e.group==null||e.group===``)){let e=r(F);return l.map(t=>{let n=c(F,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):D(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,E,S,e.objectName,A,j,M,N,P,I,F,D,k]),{ref:R,isRefreshing:z,pullDistance:B}=y({onRefresh:(0,b.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=c({navigation:e.navigation,objectName:e.objectName,onRowClick:r??i}),H=w?.scale??e.scale,U={...e,items:L||[],className:n||e.className,...H?{timeScale:H}:{},onItemClick:e=>{let t=e._data||e;V.handleClick(t),i?.(t)}};return m?(0,x.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,m.message]}):f&&(!L||L.length===0)?(0,x.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,x.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,x.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,x.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,x.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,x.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,x.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,x.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,x.jsx)(O,{schema:U}),V.isOverlay&&(0,x.jsx)(g,{...V,title:`Timeline Item`,children:e=>(0,x.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex flex-col`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,x.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},N=t({ObjectTimeline:()=>M,ObjectTimelineRenderer:()=>$,Timeline:()=>P,TimelineContent:()=>z,TimelineDescription:()=>H,TimelineGantt:()=>G,TimelineGanttBar:()=>Z,TimelineGanttBarContent:()=>Q,TimelineGanttGrid:()=>J,TimelineGanttHeader:()=>K,TimelineGanttLabel:()=>X,TimelineGanttRow:()=>Y,TimelineGanttRowLabels:()=>q,TimelineHorizontal:()=>U,TimelineHorizontalItem:()=>W,TimelineItem:()=>I,TimelineMarker:()=>R,TimelineRenderer:()=>O,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`ol`,{ref:n,className:m(`relative ml-3 border-l border-gray-200`,e),...t}));P.displayName=`Timeline`;var F=v(`ml-6`,{variants:{density:{default:`mb-10`,compact:`mb-3`,comfortable:`mb-6`}},defaultVariants:{density:`default`}}),I=b.forwardRef(({className:e,density:t,...n},r)=>(0,x.jsx)(`li`,{ref:r,className:m(F({density:t}),e),...n}));I.displayName=`TimelineItem`;var L=v(`absolute -left-3 w-6 h-6 rounded-full border-2 flex items-center justify-center`,{variants:{variant:{default:`bg-blue-200 border-blue-400`,success:`bg-emerald-200 border-emerald-500`,warning:`bg-amber-200 border-amber-500`,danger:`bg-red-200 border-red-500`,info:`bg-purple-200 border-purple-500`,todo:`bg-slate-200 border-slate-400`,"in-progress":`bg-blue-200 border-blue-500`,done:`bg-emerald-200 border-emerald-500`}},defaultVariants:{variant:`default`}}),R=b.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,x.jsx)(`div`,{ref:r,className:m(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`h3`,{ref:n,className:m(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`time`,{ref:n,className:m(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`p`,{ref:n,className:m(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=b.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,x.jsx)(`div`,{ref:a,className:m(`absolute h-8 rounded-md transition-colors cursor-pointer`,{default:`bg-blue-500 hover:bg-blue-600`,success:`bg-green-500 hover:bg-green-600`,warning:`bg-yellow-500 hover:bg-yellow-600`,danger:`bg-red-500 hover:bg-red-600`,info:`bg-purple-500 hover:bg-purple-600`}[r],e),style:{left:`${t}%`,width:`${n}%`},...i}));Z.displayName=`TimelineGanttBar`;var Q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:m(`px-2 py-1 text-white text-xs font-medium truncate`,e),...t}));Q.displayName=`TimelineGanttBarContent`;var $=({schema:e,...t})=>{let{dataSource:n}=s()||{};return(0,x.jsx)(M,{schema:e,dataSource:n,...t})};p.register(`object-timeline`,$,{namespace:`plugin-timeline`,label:`Object Timeline`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),p.register(`timeline`,$,{namespace:`view`,label:`Timeline View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]});export{N as t};