@warkypublic/oranguru 0.0.36 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs.js +6 -6
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.d.ts +2 -1
- package/dist/lib.es.js +1144 -1126
- package/dist/lib.es.js.map +1 -1
- package/package.json +1 -1
package/dist/lib.cjs.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),w=require("@mantine/core"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),w=require("@mantine/core"),Et=require("react-dom"),pe=require("@warkypublic/zustandsyncstore"),U=require("immer"),V=require("@tabler/icons-react"),ee=require("react-hook-form"),Te=require("@warkypublic/artemis-kit"),rt=require("idb-keyval"),H=require("@glideapps/glide-data-grid"),ie=require("@mantine/hooks");function Rt(r){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(o,e,t.get?t:{enumerable:!0,get:()=>r[e]})}}return o.default=r,Object.freeze(o)}const he=Rt(p);function Ot(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ce={exports:{}},oe={};var De;function It(){if(De)return oe;De=1;var r=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function e(t,n,s){var i=null;if(s!==void 0&&(i=""+s),n.key!==void 0&&(i=""+n.key),"key"in n){s={};for(var l in n)l!=="key"&&(s[l]=n[l])}else s=n;return n=s.ref,{$$typeof:r,type:t,key:i,ref:n!==void 0?n:null,props:s}}return oe.Fragment=o,oe.jsx=e,oe.jsxs=e,oe}var se={};var ze;function kt(){return ze||(ze=1,process.env.NODE_ENV!=="production"&&(function(){function r(f){if(f==null)return null;if(typeof f=="function")return f.$$typeof===M?null:f.displayName||f.name||null;if(typeof f=="string")return f;switch(f){case E:return"Fragment";case R:return"Profiler";case _:return"StrictMode";case x:return"Suspense";case S:return"SuspenseList";case B:return"Activity"}if(typeof f=="object")switch(typeof f.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),f.$$typeof){case b:return"Portal";case I:return f.displayName||"Context";case k:return(f._context.displayName||"Context")+".Consumer";case N:var C=f.render;return f=f.displayName,f||(f=C.displayName||C.name||"",f=f!==""?"ForwardRef("+f+")":"ForwardRef"),f;case O:return C=f.displayName||null,C!==null?C:r(f.type)||"Memo";case z:C=f._payload,f=f._init;try{return r(f(C))}catch{}}return null}function o(f){return""+f}function e(f){try{o(f);var C=!1}catch{C=!0}if(C){C=console;var A=C.error,v=typeof Symbol=="function"&&Symbol.toStringTag&&f[Symbol.toStringTag]||f.constructor.name||"Object";return A.call(C,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",v),o(f)}}function t(f){if(f===E)return"<>";if(typeof f=="object"&&f!==null&&f.$$typeof===z)return"<...>";try{var C=r(f);return C?"<"+C+">":"<...>"}catch{return"<...>"}}function n(){var f=P.A;return f===null?null:f.getOwner()}function s(){return Error("react-stack-top-frame")}function i(f){if(T.call(f,"key")){var C=Object.getOwnPropertyDescriptor(f,"key").get;if(C&&C.isReactWarning)return!1}return f.key!==void 0}function l(f,C){function A(){j||(j=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",C))}A.isReactWarning=!0,Object.defineProperty(f,"key",{get:A,configurable:!0})}function a(){var f=r(this.type);return J[f]||(J[f]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),f=this.props.ref,f!==void 0?f:null}function h(f,C,A,v,$,D){var F=A.ref;return f={$$typeof:y,type:f,key:C,props:A,_owner:v},(F!==void 0?F:null)!==null?Object.defineProperty(f,"ref",{enumerable:!1,get:a}):Object.defineProperty(f,"ref",{enumerable:!1,value:null}),f._store={},Object.defineProperty(f._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(f,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(f,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:$}),Object.defineProperty(f,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(f.props),Object.freeze(f)),f}function c(f,C,A,v,$,D){var F=C.children;if(F!==void 0)if(v)if(G(F)){for(v=0;v<F.length;v++)u(F[v]);Object.freeze&&Object.freeze(F)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else u(F);if(T.call(C,"key")){F=r(f);var Z=Object.keys(C).filter(function(ve){return ve!=="key"});v=0<Z.length?"{key: someKey, "+Z.join(": ..., ")+": ...}":"{key: someKey}",K[F+v]||(Z=0<Z.length?"{"+Z.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,v,
|
|
6
|
+
<%s key={someKey} {...props} />`,v,F,Z,F),K[F+v]=!0)}if(F=null,A!==void 0&&(e(A),F=""+A),i(C)&&(e(C.key),F=""+C.key),"key"in C){A={};for(var te in C)te!=="key"&&(A[te]=C[te])}else A=C;return F&&l(A,typeof f=="function"?f.displayName||f.name||"Unknown":f),h(f,F,A,n(),$,D)}function u(f){m(f)?f._store&&(f._store.validated=1):typeof f=="object"&&f!==null&&f.$$typeof===z&&(f._payload.status==="fulfilled"?m(f._payload.value)&&f._payload.value._store&&(f._payload.value._store.validated=1):f._store&&(f._store.validated=1))}function m(f){return typeof f=="object"&&f!==null&&f.$$typeof===y}var g=p,y=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),R=Symbol.for("react.profiler"),k=Symbol.for("react.consumer"),I=Symbol.for("react.context"),N=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),S=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),B=Symbol.for("react.activity"),M=Symbol.for("react.client.reference"),P=g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,T=Object.prototype.hasOwnProperty,G=Array.isArray,q=console.createTask?console.createTask:function(){return null};g={react_stack_bottom_frame:function(f){return f()}};var j,J={},Y=g.react_stack_bottom_frame.bind(g,s)(),Q=q(t(s)),K={};se.Fragment=E,se.jsx=function(f,C,A){var v=1e4>P.recentlyCreatedOwnerStacks++;return c(f,C,A,!1,v?Error("react-stack-top-frame"):Y,v?q(t(f)):Q)},se.jsxs=function(f,C,A){var v=1e4>P.recentlyCreatedOwnerStacks++;return c(f,C,A,!0,v?Error("react-stack-top-frame"):Y,v?q(t(f)):Q)}})()),se}var $e;function At(){return $e||($e=1,process.env.NODE_ENV==="production"?ce.exports=It():ce.exports=kt()),ce.exports}var d=At();function ne(r,o,e){let t=e.initialDeps??[],n,s=!0;function i(){var l,a,h;let c;e.key&&((l=e.debug)!=null&&l.call(e))&&(c=Date.now());const u=r();if(!(u.length!==t.length||u.some((y,b)=>t[b]!==y)))return n;t=u;let g;if(e.key&&((a=e.debug)!=null&&a.call(e))&&(g=Date.now()),n=o(...u),e.key&&((h=e.debug)!=null&&h.call(e))){const y=Math.round((Date.now()-c)*100)/100,b=Math.round((Date.now()-g)*100)/100,E=b/16,_=(R,k)=>{for(R=String(R);R.length<k;)R=" "+R;return R};console.info(`%c⏱ ${_(b,5)} /${_(y,5)} ms`,`
|
|
7
7
|
font-size: .6rem;
|
|
8
8
|
font-weight: bold;
|
|
9
|
-
color: hsl(${Math.max(0,Math.min(120-120*_,120))}deg 100% 31%);`,e?.key)}return e?.onChange&&!(s&&e.skipInitialOnChange)&&e.onChange(n),s=!1,n}return i.updateDeps=l=>{t=l},i}function De(r,o){if(r===void 0)throw new Error("Unexpected undefined");return r}const Ot=(r,o)=>Math.abs(r-o)<1.01,It=(r,o,e)=>{let t;return function(...n){r.clearTimeout(t),t=r.setTimeout(()=>o.apply(this,n),e)}},$e=r=>{const{offsetWidth:o,offsetHeight:e}=r;return{width:o,height:e}},kt=r=>r,At=r=>{const o=Math.max(r.startIndex-r.overscan,0),e=Math.min(r.endIndex+r.overscan,r.count-1),t=[];for(let n=o;n<=e;n++)t.push(n);return t},jt=(r,o)=>{const e=r.scrollElement;if(!e)return;const t=r.targetWindow;if(!t)return;const n=i=>{const{width:l,height:a}=i;o({width:Math.round(l),height:Math.round(a)})};if(n($e(e)),!t.ResizeObserver)return()=>{};const s=new t.ResizeObserver(i=>{const l=()=>{const a=i[0];if(a?.borderBoxSize){const h=a.borderBoxSize[0];if(h){n({width:h.inlineSize,height:h.blockSize});return}}n($e(e))};r.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(e,{box:"border-box"}),()=>{s.unobserve(e)}},ze={passive:!0},Ne=typeof window>"u"?!0:"onscrollend"in window,Tt=(r,o)=>{const e=r.scrollElement;if(!e)return;const t=r.targetWindow;if(!t)return;let n=0;const s=r.options.useScrollendEvent&&Ne?()=>{}:It(t,()=>{o(n,!1)},r.options.isScrollingResetDelay),i=c=>()=>{const{horizontal:u,isRtl:m}=r.options;n=u?e.scrollLeft*(m&&-1||1):e.scrollTop,s(),o(n,c)},l=i(!0),a=i(!1);e.addEventListener("scroll",l,ze);const h=r.options.useScrollendEvent&&Ne;return h&&e.addEventListener("scrollend",a,ze),()=>{e.removeEventListener("scroll",l),h&&e.removeEventListener("scrollend",a)}},Mt=(r,o,e)=>{if(o?.borderBoxSize){const t=o.borderBoxSize[0];if(t)return Math.round(t[e.options.horizontal?"inlineSize":"blockSize"])}return r[e.options.horizontal?"offsetWidth":"offsetHeight"]},Ft=(r,{adjustments:o=0,behavior:e},t)=>{var n,s;const i=r+o;(s=(n=t.scrollElement)==null?void 0:n.scrollTo)==null||s.call(n,{[t.options.horizontal?"left":"top"]:i,behavior:e})};class Pt{constructor(o){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.currentScrollToIndex=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let e=null;const t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(n=>{n.forEach(s=>{const i=()=>{this._measureElement(s.target,s)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:n=>{var s;return(s=t())==null?void 0:s.observe(n,{box:"border-box"})},unobserve:n=>{var s;return(s=t())==null?void 0:s.unobserve(n)}}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,n])=>{typeof n>"u"&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:kt,rangeExtractor:At,onChange:()=>{},measureElement:Mt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...e}},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=ne(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:process.env.NODE_ENV!=="production"&&"maybeNotify",debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var e;const t=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==t){if(this.cleanup(),!t){this.maybeNotify();return}this.scrollElement=t,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((e=this.scrollElement)==null?void 0:e.window)??null,this.elementsCache.forEach(n=>{this.observer.observe(n)}),this.unsubs.push(this.options.observeElementRect(this,n=>{this.scrollRect=n,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(n,s)=>{this.scrollAdjustments=0,this.scrollDirection=s?this.getScrollOffset()<n?"forward":"backward":null,this.scrollOffset=n,this.isScrolling=s,this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{const n=new Map,s=new Map;for(let i=t-1;i>=0;i--){const l=e[i];if(n.has(l.lane))continue;const a=s.get(l.lane);if(a==null||l.end>a.end?s.set(l.lane,l):l.end<a.end&&n.set(l.lane,!0),n.size===this.options.lanes)break}return s.size===this.options.lanes?Array.from(s.values()).sort((i,l)=>i.end===l.end?i.index-l.index:i.end-l.end)[0]:void 0},this.getMeasurementOptions=ne(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(e,t,n,s,i,l)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:t,scrollMargin:n,getItemKey:s,enabled:i,lanes:l}),{key:!1}),this.getMeasurements=ne(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:t,scrollMargin:n,getItemKey:s,enabled:i,lanes:l},a)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(const m of this.laneAssignments.keys())m>=e&&this.laneAssignments.delete(m);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(m=>{this.itemSizeCache.set(m.key,m.size)}));const h=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1);const c=this.measurementsCache.slice(0,h),u=new Array(l).fill(void 0);for(let m=0;m<h;m++){const g=c[m];g&&(u[g.lane]=m)}for(let m=h;m<e;m++){const g=s(m),b=this.laneAssignments.get(m);let y,_;if(b!==void 0&&this.options.lanes>1){y=b;const I=u[y],N=I!==void 0?c[I]:void 0;_=N?N.end+this.options.gap:t+n}else{const I=this.options.lanes===1?c[m-1]:this.getFurthestMeasurement(c,m);_=I?I.end+this.options.gap:t+n,y=I?I.lane:m%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(m,y)}const E=a.get(g),R=typeof E=="number"?E:this.options.estimateSize(m),k=_+R;c[m]={index:m,start:_,size:R,end:k,key:g,lane:y},u[y]=m}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=ne(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,s)=>this.range=e.length>0&&t>0?Dt({measurements:e,outerSize:t,scrollOffset:n,lanes:s}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=ne(()=>{let e=null,t=null;const n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,s,i)=>s===null||i===null?[]:e({startIndex:s,endIndex:i,overscan:t,count:n}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=e=>{const t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this._measureElement=(e,t)=>{const n=this.indexFromElement(e),s=this.measurementsCache[n];if(!s)return;const i=s.key,l=this.elementsCache.get(i);l!==e&&(l&&this.observer.unobserve(l),this.observer.observe(e),this.elementsCache.set(i,e)),e.isConnected&&this.resizeItem(n,this.options.measureElement(e,t,this))},this.resizeItem=(e,t)=>{const n=this.measurementsCache[e];if(!n)return;const s=this.itemSizeCache.get(n.key)??n.size,i=t-s;i!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(n,i,this):n.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",i),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=i,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,t)),this.notify(!1))},this.measureElement=e=>{if(!e){this.elementsCache.forEach((t,n)=>{t.isConnected||(this.observer.unobserve(t),this.elementsCache.delete(n))});return}this._measureElement(e,void 0)},this.getVirtualItems=ne(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{const n=[];for(let s=0,i=e.length;s<i;s++){const l=e[s],a=t[l];n.push(a)}return n},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{const t=this.getMeasurements();if(t.length!==0)return De(t[et(0,t.length-1,n=>De(t[n]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;const s=this.getSize(),i=this.getScrollOffset();t==="auto"&&(t=e>=i+s?"end":"start"),t==="center"?e+=(n-s)/2:t==="end"&&(e-=s);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,e),0)},this.getOffsetForIndex=(e,t="auto")=>{e=Math.max(0,Math.min(e,this.options.count-1));const n=this.measurementsCache[e];if(!n)return;const s=this.getSize(),i=this.getScrollOffset();if(t==="auto")if(n.end>=i+s-this.options.scrollPaddingEnd)t="end";else if(n.start<=i+this.options.scrollPaddingStart)t="start";else return[i,t];if(t==="end"&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];const l=t==="end"?n.end+this.options.scrollPaddingEnd:n.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,t,n.size),t]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(e,{align:t="start",behavior:n}={})=>{n==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(e,t),{adjustments:void 0,behavior:n})},this.scrollToIndex=(e,{align:t="auto",behavior:n}={})=>{n==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),e=Math.max(0,Math.min(e,this.options.count-1)),this.currentScrollToIndex=e;let s=0;const i=10,l=h=>{if(!this.targetWindow)return;const c=this.getOffsetForIndex(e,h);if(!c){console.warn("Failed to get offset for index:",e);return}const[u,m]=c;this._scrollToOffset(u,{adjustments:void 0,behavior:n}),this.targetWindow.requestAnimationFrame(()=>{const g=()=>{if(this.currentScrollToIndex!==e)return;const b=this.getScrollOffset(),y=this.getOffsetForIndex(e,m);if(!y){console.warn("Failed to get offset for index:",e);return}Ot(y[0],b)||a(m)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(g):g()})},a=h=>{this.targetWindow&&this.currentScrollToIndex===e&&(s++,s<i?(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("Schedule retry",s,i),this.targetWindow.requestAnimationFrame(()=>l(h))):console.warn(`Failed to scroll to index ${e} after ${i} attempts.`))};l(t)},this.scrollBy=(e,{behavior:t}={})=>{t==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+e,{adjustments:void 0,behavior:t})},this.getTotalSize=()=>{var e;const t=this.getMeasurements();let n;if(t.length===0)n=this.options.paddingStart;else if(this.options.lanes===1)n=((e=t[t.length-1])==null?void 0:e.end)??0;else{const s=Array(this.options.lanes).fill(null);let i=t.length-1;for(;i>=0&&s.some(l=>l===null);){const l=t[i];s[l.lane]===null&&(s[l.lane]=l.end),i--}n=Math.max(...s.filter(l=>l!==null))}return Math.max(n-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(o)}}const et=(r,o,e,t)=>{for(;r<=o;){const n=(r+o)/2|0,s=e(n);if(s<t)r=n+1;else if(s>t)o=n-1;else return n}return r>0?r-1:0};function Dt({measurements:r,outerSize:o,scrollOffset:e,lanes:t}){const n=r.length-1,s=a=>r[a].start;if(r.length<=t)return{startIndex:0,endIndex:n};let i=et(0,n,s,e),l=i;if(t===1)for(;l<n&&r[l].end<e+o;)l++;else if(t>1){const a=Array(t).fill(0);for(;l<n&&a.some(c=>c<e+o);){const c=r[l];a[c.lane]=c.end,l++}const h=Array(t).fill(e+o);for(;i>=0&&h.some(c=>c>=e);){const c=r[i];h[c.lane]=c.start,i--}i=Math.max(0,i-i%t),l=Math.min(n,l+(t-1-l%t))}return{startIndex:i,endIndex:l}}const Be=typeof document<"u"?he.useLayoutEffect:he.useEffect;function $t({useFlushSync:r=!0,...o}){const e=he.useReducer(()=>({}),{})[1],t={...o,onChange:(s,i)=>{var l;r&&i?wt.flushSync(e):e(),(l=o.onChange)==null||l.call(o,s,i)}},[n]=he.useState(()=>new Pt(t));return n.setOptions(t),Be(()=>n._didMount(),[]),Be(()=>n._willUpdate()),n}function zt(r){return $t({observeElementRect:jt,observeElementOffset:Tt,scrollToFn:Ft,...r})}const{Provider:tt,useStore:nt}=ge.createSyncStore((r,o)=>({boxerData:[],fetchData:async(e,t)=>{const n=o();if(n.dataSource==="local"||!n.onAPICall){const s=n.data??[];if(!e){r({boxerData:s,hasMore:!1,total:s.length});return}const i=s.filter(l=>l.label.toLowerCase().includes(e.toLowerCase()));r({boxerData:i,hasMore:!1,total:i.length});return}if(n.onAPICall)try{r({isFetching:!0});const s=t?0:n.page,i=await n.onAPICall({page:s,pageSize:n.pageSize,search:e});r(U.produce(l=>{t?(l.boxerData=i.data,l.page=0):l.boxerData=[...l.boxerData??[],...i.data],l.total=i.total,l.hasMore=l.boxerData.length<i.total,l.isFetching=!1}))}catch(s){console.error("Boxer fetchData error:",s),r({isFetching:!1})}},fetchMoreOnBottomReached:e=>{const t=o();if(!t.hasMore||t.isFetching)return;(e.scrollTop+e.clientHeight)/e.scrollHeight>.8&&t.loadMore()},getState:e=>o()?.[e],hasMore:!0,input:"",isFetching:!1,loadMore:async()=>{const e=o();!e.hasMore||e.isFetching||(r(U.produce(t=>{t.page=t.page+1})),await e.fetchData(e.search))},opened:!1,page:0,pageSize:50,search:"",selectedOptionIndex:-1,setInput:e=>{r({input:e})},setOpened:e=>{r({opened:e})},setSearch:e=>{r({search:e})},setSelectedOptionIndex:e=>{r({selectedOptionIndex:e})},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},total:0}),({data:r=[],dataSource:o="local",pageSize:e=50,...t})=>({...t,boxerData:r,data:r,dataSource:o,hasMore:o==="server",pageSize:e,total:r.length})),rt=p.forwardRef((r,o)=>{const{clearable:e=!0,combobox:t,disabled:n,error:s,isFetching:i,label:l,leftSection:a,onBlur:h,onClear:c,onSearch:u,placeholder:m,search:g}=r,b=i?d.jsx(w.Loader,{size:"xs"}):g&&e?d.jsx(w.ActionIcon,{onClick:y=>{y.stopPropagation(),c()},size:"sm",variant:"subtle",children:d.jsx(V.IconX,{size:16})}):null;return d.jsx(w.TextInput,{disabled:n,error:s,label:l,leftSection:a,onBlur:h,onChange:u,onClick:()=>t.openDropdown(),onFocus:()=>t.openDropdown(),placeholder:m,ref:o,rightSection:b,value:g})});rt.displayName="BoxerTarget";const Nt=r=>{const{boxerData:o,multiSelect:e,onOptionSubmit:t,value:n}=r;return{options:p.useMemo(()=>o.map((i,l)=>{const a=e?Array.isArray(n)&&n.includes(i.value):n===i.value;return d.jsx(w.Combobox.Option,{active:a,onClick:()=>{t(l)},value:String(l),children:e?d.jsxs("div",{style:{alignItems:"center",display:"flex",gap:"8px"},children:[d.jsx(w.Checkbox,{checked:a,onChange:()=>{},tabIndex:-1}),d.jsx("span",{children:i.label})]}):i.label},`${i.value}-${l}`)}),[o,n,e,t])}},ot=p.forwardRef((r,o)=>{const e=p.useRef(null),t=p.useRef(null),n=p.useRef(null),s=p.useRef(null),{boxerData:i,clearable:l,comboBoxProps:a,dropDownProps:h,error:c,fetchData:u,fetchMoreOnBottomReached:m,input:g,isFetching:b,label:y,mah:_,multiSelect:E,onBufferChange:R,onChange:k,opened:I,openOnClear:N,placeholder:x,scrollAreaProps:S,search:O,selectedOptionIndex:$,selectFirst:B,setInput:F,setOpened:P,setSearch:T,setSelectedOptionIndex:G,showAll:q,value:j}=nt(v=>({boxerData:v.boxerData,clearable:v.clearable,comboBoxProps:v.comboBoxProps,dropDownProps:v.dropDownProps,error:v.error,fetchData:v.fetchData,fetchMoreOnBottomReached:v.fetchMoreOnBottomReached,input:v.input,isFetching:v.isFetching,label:v.label,mah:v.mah,multiSelect:v.multiSelect,onBufferChange:v.onBufferChange,onChange:v.onChange,opened:v.opened,openOnClear:v.openOnClear,placeholder:v.placeholder,scrollAreaProps:v.scrollAreaProps,search:v.search,selectedOptionIndex:v.selectedOptionIndex,selectFirst:v.selectFirst,setInput:v.setInput,setOpened:v.setOpened,setSearch:v.setSearch,setSelectedOptionIndex:v.setSelectedOptionIndex,showAll:v.showAll,value:v.value})),J=i.length,Y=zt({count:J,estimateSize:()=>36,getScrollElement:()=>e.current}),Q=Y.getVirtualItems(),K=p.useCallback(v=>{const z=typeof v=="string"?parseInt(v,10):v,D=i[z];if(D)if(E){const M=Array.isArray(j)?j:[],te=M.includes(D.value)?M.filter(ve=>ve!==D.value):[...M,D.value];k?.(te);const Se=i.filter(ve=>te.includes(ve.value));R?.(Se)}else k?.(D.value),T(""),F(D.label),n.current=D.value,P(!1)},[i,E,j,k,R,T,F,P]),f=p.useCallback(()=>{q&&B?K(0):(k?.(E?[]:null),T(""),F(""),t.current?.focus()),N&&P(!0)},[q,B,E,k,T,F,N,P,K]),C=w.useVirtualizedCombobox({getOptionId:v=>String(v),onDropdownClose:()=>{P(!1)},onDropdownOpen:()=>{(!j||E&&(!Array.isArray(j)||j.length===0))&&(T(""),F("")),C.selectFirstOption()},onSelectedOptionSubmit:K,opened:I,selectedOptionIndex:$,setSelectedOptionIndex:v=>{G(v),v!==-1&&Y.scrollToIndex(v)},totalOptionsCount:i.length}),{options:A}=Nt({boxerData:i,multiSelect:E,onOptionSubmit:K,value:j});return p.useEffect(()=>{u("",!0)},[]),p.useEffect(()=>{const v=setTimeout(()=>{O!==void 0&&I&&u(O,!0)},300);return()=>clearTimeout(v)},[O,I]),p.useEffect(()=>{if(E){const v=i.filter(z=>Array.isArray(j)&&j.includes(z.value)).map(z=>z.label).join(", ");!I&&g!==v&&(F(v),T(""))}else{const v=i.find(z=>z.value===j)?.label;g!==v&&(O??"")===""&&n.current!==j&&j?F(v??""):!j&&!n.current&&(O??"")===""&&(T(""),F(""))}if(E){const v=i.filter(z=>Array.isArray(j)&&j.includes(z.value))??[];JSON.stringify(s.current)!==JSON.stringify(v)&&(R?.(v),s.current=v)}else{const v=i?.find(z=>z.value===j)??null;s.current?.value!==v?.value&&(R?.(v),s.current=v)}},[j,i,g,O,E,I,R,F,T]),p.useEffect(()=>{B&&(i?.length??0)>0&&!E&&(j||K?.(0))},[B,i,E]),p.useImperativeHandle(o,()=>({clear:()=>{f()},close:()=>{P(!1),C.closeDropdown()},focus:()=>{t.current?.focus()},getValue:()=>j,open:()=>{P(!0),C.openDropdown()},setValue:v=>{k?.(v)}})),d.jsxs(w.Combobox,{...a,resetSelectionOnOptionHover:!1,store:C,withinPortal:!0,children:[d.jsx(w.Combobox.Target,{children:d.jsx(w.Combobox.EventsTarget,{children:d.jsx(rt,{clearable:l,combobox:C,error:c,isFetching:b,label:y,onBlur:()=>{!j&&!E&&(T(""),F(""),C.closeDropdown(),P(!1))},onClear:f,onSearch:v=>{T(v.currentTarget.value),F(v.currentTarget.value),P(!0)},placeholder:x,ref:t,search:g})})}),d.jsx(w.Combobox.Dropdown,{onKeyDown:()=>{t.current&&(t.current.value="",t.current?.focus())},p:2,...h,children:I&&A.length>0?d.jsx(w.Combobox.Options,{children:d.jsx(w.ScrollArea.Autosize,{...S,mah:_??200,viewportProps:{...S?.viewportProps,onScroll:v=>{m(v.currentTarget)},style:{border:"1px solid gray",borderRadius:4}},viewportRef:e,children:d.jsx("div",{style:{height:`${Y.getTotalSize()}px`,position:"relative",width:"100%"},children:d.jsx("div",{style:{left:0,position:"absolute",top:0,transform:`translateY(${Q[0]?.start??0}px)`,width:"100%"},children:Q.map(v=>d.jsx("div",{"data-index":v.index,ref:Y.measureElement,children:A[v.index]},v.key))})})})}):d.jsx(w.Combobox.Empty,{children:"Nothing found"})})]})});ot.displayName="BoxerInner";const st=p.forwardRef((r,o)=>d.jsx(tt,{...r,children:d.jsx(ot,{ref:o})}));st.displayName="Boxer";class Bt{config={enabled:!0};reporters=[];sentryInstance=null;configure(o){this.config={...this.config,...o},this.reporters=[],o.sentry&&this.setupSentry(o.sentry),o.customAPI&&this.setupCustomAPI(o.customAPI),o.reporters&&this.reporters.push(...o.reporters)}destroy(){this.reporters=[],this.sentryInstance=null,this.config={enabled:!0}}getReporters(){return[...this.reporters]}isEnabled(){return!!this.config.enabled}async reportError(o,e,t){if(!this.config.enabled)return;let n={context:t,error:o,errorInfo:e,severity:"error",timestamp:Date.now()};if(this.config.beforeReport){const i=this.config.beforeReport(n);if(!i)return;n=i}const s=this.reporters.filter(i=>i.isEnabled()).map(async i=>{try{await i.captureError(n)}catch(l){console.error(`Error reporter "${i.name}" failed:`,l),this.config.onReportFailure&&this.config.onReportFailure(l,n)}});try{await Promise.all(s),this.config.onReportSuccess&&this.config.onReportSuccess(n)}catch(i){console.error("Error reporting failed:",i)}}setupCustomAPI(o){const e={captureError:async t=>{try{const n=o.transformPayload?o.transformPayload(t):{context:t.context,message:t.error.message,severity:t.severity||"error",stack:t.error.stack,timestamp:t.timestamp||Date.now()},s=await fetch(o.endpoint,{body:JSON.stringify(n),headers:{"Content-Type":"application/json",...o.headers},method:o.method||"POST"});if(!s.ok)throw new Error(`API request failed: ${s.statusText}`)}catch(n){console.error("Failed to send error to custom API:",n)}},isEnabled:()=>!!o.endpoint,name:"CustomAPI"};this.reporters.push(e)}setupSentry(o){const e={captureError:async t=>{if(!this.sentryInstance)try{const n=await Promise.resolve().then(()=>require("./index-wyM2YQFr.cjs"));n.init({beforeSend:o.beforeSend,dsn:o.dsn,environment:o.environment,ignoreErrors:o.ignoreErrors,release:o.release,tracesSampleRate:o.sampleRate||1}),this.sentryInstance=n}catch(n){console.error("Failed to initialize Sentry:",n);return}this.sentryInstance.withScope(n=>{t.severity&&n.setLevel(t.severity),t.context?.namespace&&n.setTag("namespace",t.context.namespace),t.context?.tags&&Object.entries(t.context.tags).forEach(([s,i])=>{n.setTag(s,i)}),t.context?.user&&n.setUser(t.context.user),t.context?.extra&&n.setExtras(t.context.extra),t.context?.componentStack&&n.setContext("react",{componentStack:t.context.componentStack}),this.sentryInstance.captureException(t.error)})},isEnabled:()=>!!this.sentryInstance,name:"Sentry"};this.reporters.push(e)}}const me=new Bt;class Lt extends p.PureComponent{constructor(o){super(o),this.state={error:null,errorInfo:null,showDetail:!1,timer:void 0,try:!1,tryCnt:0}}componentDidCatch(o,e){this.setState({error:o,errorInfo:e,try:!1}),me.reportError(o,e,{componentStack:e?.componentStack,namespace:this.props.namespace})}render(){return this.state.errorInfo?d.jsxs("div",{children:[d.jsx("h2",{children:"Error"}),this.state.error&&d.jsxs(d.Fragment,{children:[d.jsxs("h3",{children:["In: ",this.props.namespace??"default"]}),d.jsx("main",{children:this.state.error.toString()})]})]}):this.props.children}}let Gt={disabled:!1,onError:void 0};const ye=()=>({...Gt});class qt extends p.Component{constructor(o){super(o),this.state={error:null,errorInfo:null,showDetail:!1,timer:void 0,try:!1,tryCnt:0}}componentDidCatch(o,e){if(ye()?.disabled)throw Error("ErrorBoundary pass through enabled, rethrowing error",{cause:o,info:e});this.setState({error:o,errorInfo:e,try:!1}),typeof ye()?.onError=="function"&&ye()?.onError?.(o,e),me.reportError(o,e,{componentStack:e?.componentStack,namespace:this.props.namespace})}render(){if(this.state.errorInfo)return d.jsxs("div",{children:[d.jsxs("h2",{style:{color:"var(--mantine-color-error)",display:"flex",gap:"8px"},children:[d.jsx(V.IconExclamationCircle,{color:"var(--mantine-color-error)",style:{height:w.rem(20),width:w.rem(20)}}),"A react error has occurred!"]}),d.jsx("h4",{children:"You can try one of these solutions to get back on track:"}),d.jsxs("ul",{children:[d.jsx("li",{children:"Report the error to our team"}),d.jsx("li",{children:"Hit the keys Ctrl-Shift-R"}),d.jsx("li",{children:"Make sure your web browser is up to date"}),d.jsx("li",{children:"Clear your browser cache and cookies"}),d.jsx("li",{children:"Try using a different web browser"}),d.jsx("li",{children:"Reset your layout and settings"}),d.jsx("li",{children:"Retry loading the application"})]}),d.jsxs(w.Group,{children:[d.jsx(w.Button,{color:"red",my:"md",onClick:()=>this.setState(o=>({showDetail:!o.showDetail})),size:"compact-xs",variant:"outline",children:"More"}),d.jsxs(w.Button,{color:"blue",disabled:this.state.tryCnt>2||this.state.try,my:"md",onClick:()=>this.retry(),size:"compact-xs",variant:"outline",children:["Retry ",this.state.tryCnt>0?`(${this.state.tryCnt})`:""]}),d.jsx(w.Button,{color:"yellow",disabled:this.state.wasReset,my:"md",onClick:()=>this.reset(),size:"compact-xs",variant:"outline",children:"Reset Layout or Settings"}),d.jsx(w.Button,{color:"green",disabled:this.state.reported,my:"md",onClick:()=>this.report(),size:"compact-xs",variant:"outline",children:"Report"})]}),this.state.error&&d.jsxs(w.Paper,{p:"md",shadow:"xs",style:{textAlign:"justify"},w:"50%",withBorder:!0,children:[this.props.namespace&&d.jsxs(w.Text,{size:"sm",children:["In: ",this.props.namespace]}),d.jsx(w.Text,{size:"sm",children:this.state.error.toString()})]}),d.jsx(w.Collapse,{in:this.state.showDetail,children:d.jsx(w.Code,{block:!0,color:"rgba(235, 86, 5, 0.6)",mah:"100vh",w:"100%",children:this.state.errorInfo.componentStack})})]});if(this.state.try){if(!this.state.timer){const o=setTimeout(()=>{clearTimeout(this.state.timer),this.setState(e=>({...e,timer:void 0,try:!1}))},1e3);this.setState(e=>({...e,timer:o}))}return d.jsxs("div",{children:["Retrying ",this.state.tryCnt,"..."]})}return this.props.children}async report(){if(this.props?.onReportClick){this.props.onReportClick(),this.setState(()=>({reported:!0}));return}this.state.error&&this.state.errorInfo&&(await me.reportError(this.state.error,this.state.errorInfo,{componentStack:this.state.errorInfo?.componentStack,namespace:this.props.namespace,tags:{reportedBy:"user"}}),this.setState(()=>({reported:!0})))}reset(){if(this.props?.onResetClick){this.props.onResetClick(),this.setState(()=>({wasReset:!0}));return}this.setState(()=>({wasReset:!0})),window.location.reload()}retry(){if(this.setState({try:!0,tryCnt:this.state.tryCnt+1}),this.props?.onRetryClick){this.props.onRetryClick();return}this.setState({error:void 0,errorInfo:void 0}),this.forceUpdate()}}const{Provider:Vt,useStore:ae}=ge.createSyncStore((r,o)=>({getState:e=>o()?.[e],load:async e=>{try{r({loading:!0});const t=o()?.uniqueKeyField||"id",n=o().values?.[t]??o().primeData?.[t];if(o().onAPICall&&n!==void 0){let s=await o().onAPICall("read",o().request||"insert",o().values,n);o().afterGet&&(s=await o().afterGet({...s})),r({loading:!1,values:s}),o().onChange?.(s)}e&&o().getFormMethods&&o().getFormMethods().reset()}catch(t){r({error:t?.message??t,loading:!1})}r({loading:!1})},onChange:e=>{r({values:e})},request:"insert",reset:async()=>{const e=o();e.getFormMethods&&(e.request!=="insert"&&await e.load(!0),e.getFormMethods().reset({...e.values,...e.primeData}))},save:async e=>{try{const t=o().keepOpen??!1;if(r({loading:!0}),o().getFormMethods){const n=o().getFormMethods();let s=n.getValues();o().beforeSave&&(s=await o().beforeSave(s));let i=!1;if(await n.handleSubmit(a=>{s=a},a=>{r({error:a.root?.message||"Validation errors",loading:!1}),i=!0})(e),i){r({loading:!1});return}if(o().request==="delete"&&!o().deleteConfirmed&&!(await o().onConfirmDelete?.(s)??!1)){r({loading:!1});return}if(o().onAPICall){const a=o()?.uniqueKeyField||"id",h=o().values?.[a]??o().primeData?.[a],c=await o().onAPICall("mutate",o().request||"insert",s,h);return o().afterSave&&await o().afterSave(c),r({loading:!1,values:c}),o().onChange?.(c),n.reset(c),t||o().onClose?.(c),c}return r({loading:!1,values:s}),n.reset(s),o().onChange?.(s),t||o().onClose?.(s),s}}catch(t){r({error:t?.message??t,loading:!1})}},setRequest:e=>{r({request:e})},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},setStateFN:(e,t)=>new Promise((s,i)=>{r(U.produce(l=>{if(typeof t=="function")l[e]=t(l[e]);else throw i(new Error(`Not a function ${t}`)),Error(`Not a function ${t}`)})),s()}),validate:async()=>o().getFormMethods?await o().getFormMethods().trigger():!0,values:void 0}),({id:r,onClose:o,onConfirmDelete:e,primeData:t,request:n,useStoreApi:s,values:i})=>{let l=e;return e||(l=async()=>confirm("Are you sure you want to delete this item?")),{id:r||ke.newUUID(),onClose:()=>{const a=s.getState().dirty,h=s.getState().setState;a?confirm("You have unsaved changes. Are you sure you want to close?")&&(o?o():h("opened",!1)):o?o():h("opened",!1)},onConfirmDelete:l,primeData:t,request:(n||"insert").replace("change","update"),values:{...t,...i}}}),le=()=>{const{buttonAreaGroupProps:r,closeButtonProps:o,closeButtonTitle:e,dirty:t,onClose:n,request:s,save:i,saveButtonProps:l,saveButtonTitle:a}=ae(c=>({buttonAreaGroupProps:c.layout?.buttonAreaGroupProps,closeButtonProps:c.layout?.closeButtonProps,closeButtonTitle:c.layout?.closeButtonTitle,dirty:c.dirty,onClose:c.onClose,request:c.request,save:c.save,saveButtonProps:c.layout?.saveButtonProps,saveButtonTitle:c.layout?.saveButtonTitle})),h=["select","view"].includes(s||"")||["update"].includes(s||"")&&!t;return d.jsx(w.Group,{justify:"center",p:"xs",style:{boxShadow:"2px 2px 5px rgba(47, 47, 47, 0.1)"},w:"100%",...r,children:d.jsxs(w.Group,{grow:!0,justify:"space-evenly",children:[typeof n=="function"&&d.jsx(w.Button,{color:"orange",leftSection:d.jsx(V.IconX,{}),miw:"8rem",px:"md",size:"sm",...o,onClick:()=>{n()},children:e||"Close"}),d.jsx(w.Tooltip,{label:h?d.jsxs("p",{children:["Cannot save in view or select mode, or no changes made. ",d.jsx("br",{}),"Try changing some values."]}):d.jsx("p",{children:"Save the current record"}),children:d.jsx(w.Button,{bg:s==="delete"?"red":void 0,color:"green",leftSection:d.jsx(V.IconDeviceFloppy,{}),miw:"8rem",px:"md",size:"sm",...l,disabled:h,onClick:()=>i(),children:a||"Save"})})]})})},Ht=()=>{const{buttonArea:r,getState:o,opened:e,renderBottom:t,setState:n}=ae(s=>({buttonArea:s.layout?.buttonArea,getState:s.getState,opened:s.opened,renderBottom:s.layout?.renderBottom,setState:s.setState}));return t?t(d.jsx(le,{}),e??!1,o("onClose")??(()=>{n("opened",!1)}),o("onOpen")??(()=>{n("opened",!0)}),o):r==="bottom"?d.jsx(le,{}):d.jsx(d.Fragment,{})},Wt=()=>{const{buttonArea:r,getState:o,opened:e,renderTop:t,setState:n}=ae(s=>({buttonArea:s.layout?.buttonArea,getState:s.getState,opened:s.opened,renderTop:s.layout?.renderTop,setState:s.setState}));return t?t(d.jsx(le,{}),e??!1,o("onClose")??(()=>{n("opened",!1)}),o("onOpen")??(()=>{n("opened",!0)}),o):r==="top"?d.jsx(le,{}):d.jsx(d.Fragment,{})},Le=r=>{const{disableHTMlForm:o,getFormMethods:e,id:t,load:n,loading:s,loadingOverlayProps:i,opened:l,request:a,reset:h,save:c,scrollAreaProps:u}=ae(m=>({disableHTMlForm:m.disableHTMlForm,getFormMethods:m.getFormMethods,id:m.id,load:m.load,loading:m.loading,loadingOverlayProps:m.loadingOverlayProps,opened:m.opened,request:m.request,reset:m.reset,save:m.save,scrollAreaProps:m.scrollAreaProps}));return p.useEffect(()=>{e&&e()&&a!=="insert"&&n(!0)},[e,a,l]),d.jsxs(d.Fragment,{children:[d.jsx(Wt,{}),d.jsxs(w.ScrollAreaAutosize,{offsetScrollbars:!0,scrollbarSize:4,type:"auto",...u,style:{height:"100%",padding:"0.25rem",width:"100%",...u?.style},children:[o?d.jsx("div",{"x-data-request":a,children:r.children},`former_d${t}`):d.jsx("form",{id:`former_f${t}`,onReset:m=>h(m),onSubmit:m=>c(m),"x-data-request":a,children:r.children},`former_${t}`),d.jsx(w.LoadingOverlay,{loaderProps:{type:"bars"},overlayProps:{backgroundOpacity:.5},...i,visible:s})]}),d.jsx(Ht,{})]})},Kt=p.forwardRef(function(o,e){const{getState:t,onChange:n,onClose:s,onOpen:i,opened:l,primeData:a,reset:h,save:c,setState:u,useFormProps:m,validate:g,values:b,wrapper:y}=ae(E=>({getState:E.getState,onChange:E.onChange,onClose:E.onClose,onOpen:E.onOpen,opened:E.opened,primeData:E.primeData,reset:E.reset,save:E.save,setState:E.setState,useFormProps:E.useFormProps,validate:E.validate,values:E.values,wrapper:E.wrapper})),_=ee.useForm({defaultValues:a,mode:"all",shouldUseNativeValidation:!0,values:b,...m});return p.useImperativeHandle(e,()=>({close:async()=>{s?.(),u("opened",!1)},getValue:()=>t("values"),reset:()=>{h()},save:async()=>await c(),setValue:E=>{n?.(E)},show:async()=>{u("opened",!0),i?.()},validate:async()=>await g()}),[t,n,g,c,h,u,s,i]),p.useEffect(()=>{u("getFormMethods",()=>_),_&&_.subscribe({callback:({isDirty:E})=>{u("dirty",E)},formState:{isDirty:!0}})},[_]),d.jsx(ee.FormProvider,{..._,children:typeof y=="function"?y(d.jsx(Le,{children:o.children}),l??!1,s??(()=>{u("opened",!1)}),i??(()=>{u("opened",!0)}),t):d.jsx(Le,{children:o.children||null})})}),pe=p.forwardRef(function(o,e){return!o.opened&&typeof o.wrapper=="function"?null:d.jsx(Vt,{...o,children:d.jsx(Kt,{ref:e,children:o.children})})});function Ut(r){return async(o,e,t,n)=>{let i=`${r.url.replace(/\/$/,"")}`;e!=="insert"&&n&&(i=`${i}/${n}`);const l={operation:o==="read"?"read":e==="delete"?"delete":e==="update"?"update":"create"};o==="mutate"&&(l.data=t);const a={cache:"no-cache",signal:r.signal,...r.fetchOptions,body:JSON.stringify(l),headers:{Authorization:`Bearer ${r.authToken}`,"Content-Type":"application/json",...r.fetchOptions?.headers},method:"POST"},h=await fetch(i,a);if(!h.ok)throw new Error(`API request failed with status ${h.status}`);return await h.json()}}function Jt(r){return async(o,e,t,n)=>{const s=r.url??"";let i=s;const l={cache:"no-cache",signal:r.signal,...r.fetchOptions,body:o==="mutate"&&e!=="delete"?JSON.stringify(t):void 0,headers:{Authorization:`Bearer ${r.authToken}`,"Content-Type":"application/json",...r.fetchOptions?.headers},method:o==="read"?"GET":e==="delete"?"DELETE":e==="update"?"PUT":"POST"};e!=="insert"&&(i=`${s}/${n}`);const a=await fetch(i,l);if(!a.ok)throw new Error(`API request failed with status ${a.status}`);return await a.json()}}const Yt=r=>{const{children:o,former:e,onClose:t,opened:n,...s}=r;return d.jsx(pe,{...e,onClose:t,opened:n,wrapper:(i,l,a,h,c)=>{const u=c("values"),m=c("request"),g=c("uniqueKeyField")??"id";return d.jsx(w.Drawer,{closeOnClickOutside:!1,h:"100%",title:m==="delete"?`Delete Record - ${u?.[g]}`:m==="insert"?"New Record":`Edit Record - ${u?.[g]}`,...s,onClose:()=>a?.(),opened:l??!1,children:i})},children:o})},Xt=r=>{const{children:o,former:e,onClose:t,opened:n,...s}=r;return d.jsx(pe,{...e,onClose:t,opened:n,wrapper:(i,l,a,h,c)=>{const u=c("values"),m=c("request"),g=c("uniqueKeyField")??"id";return d.jsx(w.Modal,{closeOnClickOutside:!1,h:"100%",title:m==="delete"?`Delete Record - ${u?.[g]}`:m==="insert"?"New Record":`Edit Record - ${u?.[g]}`,...s,onClose:()=>a?.(),opened:l??!1,children:i})},children:o})},Qt=r=>{const{children:o,former:e,onClose:t,opened:n,target:s,...i}=r;return d.jsx(pe,{...e,onClose:t,opened:n,wrapper:(l,a,h)=>d.jsxs(w.Popover,{closeOnClickOutside:!1,middlewares:{inline:!0},trapFocus:!0,width:250,withArrow:!0,...i,onClose:()=>h?.(),opened:a??!1,children:[d.jsx(w.Popover.Target,{children:s}),d.jsx(w.Popover.Dropdown,{children:l})]}),children:o})},Zt=r=>{const[o,e]=p.useState(!1);return d.jsx(w.Tooltip,{label:r.tooltip??"",withArrow:!0,children:d.jsx(w.Button,{loaderProps:{type:"bars"},...r,loading:o||r.loading,onClick:t=>{r.onClick&&(e(!0),r.onClick(t).finally(()=>e(!1)))},children:r.children})})},en=r=>{const[o,e]=p.useState(!1);return d.jsx(w.Tooltip,{label:r.tooltip??"",withArrow:!0,children:d.jsxs(w.ActionIcon,{loaderProps:{type:"bars"},...r,loading:o||r.loading,onClick:t=>{r.onClick&&(e(!0),r.onClick(t).finally(()=>e(!1)))},children:[r.children,d.jsxs(w.VisuallyHidden,{children:["Action Button: ",r.tooltip??r.sid??""]})]})})},tn=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.NativeSelect,{...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},nn=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.PasswordInput,{...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},rn=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.Switch,{...s,...i,checked:!!i.value,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`,onChange:a=>{i.onChange((a.currentTarget??a.target)?.checked)}})})})},on=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.Textarea,{minRows:4,...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},sn=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.TextInput,{...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},Ge=r=>Symbol.iterator in r,qe=r=>"entries"in r,Ve=(r,o)=>{const e=r instanceof Map?r:new Map(r.entries()),t=o instanceof Map?o:new Map(o.entries());if(e.size!==t.size)return!1;for(const[n,s]of e)if(!t.has(n)||!Object.is(s,t.get(n)))return!1;return!0},ln=(r,o)=>{const e=r[Symbol.iterator](),t=o[Symbol.iterator]();let n=e.next(),s=t.next();for(;!n.done&&!s.done;){if(!Object.is(n.value,s.value))return!1;n=e.next(),s=t.next()}return!!n.done&&!!s.done};function an(r,o){return Object.is(r,o)?!0:typeof r!="object"||r===null||typeof o!="object"||o===null||Object.getPrototypeOf(r)!==Object.getPrototypeOf(o)?!1:Ge(r)&&Ge(o)?qe(r)&&qe(o)?Ve(r,o):ln(r,o):Ve({entries:()=>Object.entries(r)},{entries:()=>Object.entries(o)})}var ue={exports:{}},be={},de={exports:{}},we={};var He;function cn(){if(He)return we;He=1;var r=p;function o(u,m){return u===m&&(u!==0||1/u===1/m)||u!==u&&m!==m}var e=typeof Object.is=="function"?Object.is:o,t=r.useState,n=r.useEffect,s=r.useLayoutEffect,i=r.useDebugValue;function l(u,m){var g=m(),b=t({inst:{value:g,getSnapshot:m}}),y=b[0].inst,_=b[1];return s(function(){y.value=g,y.getSnapshot=m,a(y)&&_({inst:y})},[u,g,m]),n(function(){return a(y)&&_({inst:y}),u(function(){a(y)&&_({inst:y})})},[u]),i(g),g}function a(u){var m=u.getSnapshot;u=u.value;try{var g=m();return!e(u,g)}catch{return!0}}function h(u,m){return m()}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?h:l;return we.useSyncExternalStore=r.useSyncExternalStore!==void 0?r.useSyncExternalStore:c,we}var xe={};var We;function un(){return We||(We=1,process.env.NODE_ENV!=="production"&&(function(){function r(g,b){return g===b&&(g!==0||1/g===1/b)||g!==g&&b!==b}function o(g,b){c||n.startTransition===void 0||(c=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var y=b();if(!u){var _=b();s(y,_)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}_=i({inst:{value:y,getSnapshot:b}});var E=_[0].inst,R=_[1];return a(function(){E.value=y,E.getSnapshot=b,e(E)&&R({inst:E})},[g,y,b]),l(function(){return e(E)&&R({inst:E}),g(function(){e(E)&&R({inst:E})})},[g]),h(y),y}function e(g){var b=g.getSnapshot;g=g.value;try{var y=b();return!s(g,y)}catch{return!0}}function t(g,b){return b()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=p,s=typeof Object.is=="function"?Object.is:r,i=n.useState,l=n.useEffect,a=n.useLayoutEffect,h=n.useDebugValue,c=!1,u=!1,m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?t:o;xe.useSyncExternalStore=n.useSyncExternalStore!==void 0?n.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),xe}var Ke;function it(){return Ke||(Ke=1,process.env.NODE_ENV==="production"?de.exports=cn():de.exports=un()),de.exports}var Ue;function dn(){if(Ue)return be;Ue=1;var r=p,o=it();function e(h,c){return h===c&&(h!==0||1/h===1/c)||h!==h&&c!==c}var t=typeof Object.is=="function"?Object.is:e,n=o.useSyncExternalStore,s=r.useRef,i=r.useEffect,l=r.useMemo,a=r.useDebugValue;return be.useSyncExternalStoreWithSelector=function(h,c,u,m,g){var b=s(null);if(b.current===null){var y={hasValue:!1,value:null};b.current=y}else y=b.current;b=l(function(){function E(x){if(!R){if(R=!0,k=x,x=m(x),g!==void 0&&y.hasValue){var S=y.value;if(g(S,x))return I=S}return I=x}if(S=I,t(k,x))return S;var O=m(x);return g!==void 0&&g(S,O)?(k=x,S):(k=x,I=O)}var R=!1,k,I,N=u===void 0?null:u;return[function(){return E(c())},N===null?void 0:function(){return E(N())}]},[c,u,m,g]);var _=n(h,b[0],b[1]);return i(function(){y.hasValue=!0,y.value=_},[_]),a(_),_},be}var Ce={};var Je;function fn(){return Je||(Je=1,process.env.NODE_ENV!=="production"&&(function(){function r(h,c){return h===c&&(h!==0||1/h===1/c)||h!==h&&c!==c}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=p,e=it(),t=typeof Object.is=="function"?Object.is:r,n=e.useSyncExternalStore,s=o.useRef,i=o.useEffect,l=o.useMemo,a=o.useDebugValue;Ce.useSyncExternalStoreWithSelector=function(h,c,u,m,g){var b=s(null);if(b.current===null){var y={hasValue:!1,value:null};b.current=y}else y=b.current;b=l(function(){function E(x){if(!R){if(R=!0,k=x,x=m(x),g!==void 0&&y.hasValue){var S=y.value;if(g(S,x))return I=S}return I=x}if(S=I,t(k,x))return S;var O=m(x);return g!==void 0&&g(S,O)?(k=x,S):(k=x,I=O)}var R=!1,k,I,N=u===void 0?null:u;return[function(){return E(c())},N===null?void 0:function(){return E(N())}]},[c,u,m,g]);var _=n(h,b[0],b[1]);return i(function(){y.hasValue=!0,y.value=_},[_]),a(_),_},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),Ce}var Ye;function hn(){return Ye||(Ye=1,process.env.NODE_ENV==="production"?ue.exports=dn():ue.exports=fn()),ue.exports}var mn=hn();const gn=Ct(mn),Xe=r=>{let o;const e=new Set,t=(h,c)=>{const u=typeof h=="function"?h(o):h;if(!Object.is(u,o)){const m=o;o=c??(typeof u!="object"||u===null)?u:Object.assign({},o,u),e.forEach(g=>g(o,m))}},n=()=>o,l={setState:t,getState:n,getInitialState:()=>a,subscribe:h=>(e.add(h),()=>e.delete(h))},a=o=r(t,n,l);return l},pn=(r=>r?Xe(r):Xe),{useSyncExternalStoreWithSelector:Sn}=gn,vn=r=>r;function yn(r,o=vn,e){const t=Sn(r.subscribe,r.getState,r.getInitialState,o,e);return p.useDebugValue(t),t}const lt="APP_GLO",bn=new Set(["app.controls","session.connected","session.error","session.loading"]),wn=r=>bn.has(r),_e=(r,o="")=>{if(typeof r=="function")return;if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map((t,n)=>_e(t,`${o}[${n}]`));const e={};for(const[t,n]of Object.entries(r)){const s=o?`${o}.${t}`:t;wn(s)||typeof n=="function"||(e[t]=_e(n,s))}return e};async function at(){const r={},o=["layout","navigation","owner","program","session","user"];for(const e of o){const t=`${lt}:${e}`;if(e==="session"){try{if(typeof localStorage<"u"){const n=localStorage.getItem(t);n&&(r[e]=JSON.parse(n))}}catch(n){console.error(`Failed to load ${e} from localStorage:`,n)}continue}try{if(typeof indexedDB<"u"){const n=await Ze.get(t);if(n){r[e]=JSON.parse(n);continue}}}catch(n){console.error(`Failed to load ${e} from IndexedDB, falling back to localStorage:`,n)}try{if(typeof localStorage<"u"){const n=localStorage.getItem(t);n&&(r[e]=JSON.parse(n))}}catch(n){console.error(`Failed to load ${e} from localStorage:`,n)}}return r}async function xn(r){const o=["layout","navigation","owner","program","session","user"];for(const e of o){const t=`${lt}:${e}`,n=_e(r[e],e),s=JSON.stringify(n);if(e==="session"){try{typeof localStorage<"u"&&localStorage.setItem(t,s)}catch(i){console.error(`Failed to save ${e} to localStorage:`,i)}continue}try{if(typeof indexedDB<"u"){await Ze.set(t,s);continue}}catch(i){console.error(`Failed to save ${e} to IndexedDB, falling back to localStorage:`,i)}try{typeof localStorage<"u"&&localStorage.setItem(t,s)}catch(i){console.error(`Failed to save ${e} to localStorage:`,i)}}}const Ee={layout:{bottomBar:{open:!1},leftBar:{open:!1},rightBar:{open:!1},topBar:{open:!1}},navigation:{menu:[]},owner:{guid:"",id:0,name:""},program:{controls:{},environment:"production",guid:"",name:"",slug:""},session:{apiURL:"",authToken:"",connected:!0,loading:!1,loggedIn:!1},user:{guid:"",username:""}},Cn=r=>({setProgram:o=>r(e=>({program:{...e.program,...o}}))}),_n=r=>({setApiURL:o=>r(e=>({session:{...e.session,apiURL:o}})),setAuthToken:o=>r(e=>({session:{...e.session,authToken:o}})),setSession:o=>r(e=>({session:{...e.session,...o}}))}),En=r=>({setOwner:o=>r(e=>({owner:{...e.owner,...o}}))}),Rn=r=>({setUser:o=>r(e=>({user:{...e.user,...o}}))}),On=r=>({setBottomBar:o=>r(e=>({layout:{...e.layout,bottomBar:{...e.layout.bottomBar,...o}}})),setLayout:o=>r(e=>({layout:{...e.layout,...o}})),setLeftBar:o=>r(e=>({layout:{...e.layout,leftBar:{...e.layout.leftBar,...o}}})),setRightBar:o=>r(e=>({layout:{...e.layout,rightBar:{...e.layout.rightBar,...o}}})),setTopBar:o=>r(e=>({layout:{...e.layout,topBar:{...e.layout.topBar,...o}}}))}),In=r=>({setCurrentPage:o=>r(e=>({navigation:{...e.navigation,currentPage:o}})),setMenu:o=>r(e=>({navigation:{...e.navigation,menu:o}})),setNavigation:o=>r(e=>({navigation:{...e.navigation,...o}}))}),kn=(r,o)=>({fetchData:async e=>{try{r(s=>({session:{...s.session,apiURL:e??s.session.apiURL,loading:!0}}));const t=o(),n=await t.onFetchSession?.(t);r(s=>({...s,...n,layout:{...s.layout,...n?.layout},navigation:{...s.navigation,...n?.navigation},owner:{...s.owner,...n?.owner},program:{...s.program,...n?.program,updatedAt:new Date().toISOString()},session:{...s.session,...n?.session,connected:!0,loading:!1},user:{...s.user,...n?.user}}))}catch(t){r(n=>({session:{...n.session,connected:!1,error:`Load Exception: ${String(t)}`,loading:!1}}))}},isLoggedIn:()=>{const e=o().session;return!(!e.loggedIn||!e.authToken||e.expiryDate&&new Date(e.expiryDate)<new Date)},login:async e=>{try{r(s=>({session:{...s.session,authToken:e??"",expiryDate:new Date(Date.now()+1440*60*1e3).toISOString(),loading:!0,loggedIn:!0}})),await o().fetchData();const t=o(),n=await t.onLogin?.(t);n&&r(s=>({...s,owner:n.owner?{...s.owner,...n.owner}:s.owner,program:n.program?{...s.program,...n.program}:s.program,session:n.session?{...s.session,...n.session}:s.session,user:n.user?{...s.user,...n.user}:s.user}))}catch(t){r(n=>({session:{...n.session,connected:!1,error:`Login Exception: ${String(t)}`,loading:!1,loggedIn:!1}}))}finally{r(t=>({session:{...t.session,loading:!1}}))}},logout:async()=>{try{r(n=>({...Ee,session:{...Ee.session,apiURL:n.session.apiURL,expiryDate:void 0,loading:!0,loggedIn:!1}})),await o().fetchData();const e=o(),t=await e.onLogout?.(e);t&&r(n=>({...n,owner:t.owner?{...n.owner,...t.owner}:n.owner,program:t.program?{...n.program,...t.program}:n.program,session:t.session?{...n.session,...t.session}:n.session,user:t.user?{...n.user,...t.user}:n.user}))}catch(e){r(t=>({session:{...t.session,connected:!1,error:`Logout Exception: ${String(e)}`,loading:!1}}))}finally{r(e=>({session:{...e.session,loading:!1}}))}}}),L=pn((r,o)=>({...Ee,...Cn(r),..._n(r),...En(r),...Rn(r),...On(r),...In(r),...kn(r,o)}));at().then(r=>{L.setState(o=>({...o,...r,session:{...o.session,...r.session,connected:!0,loading:!1}}))}).catch(r=>{console.error("Error loading storage:",r)});L.subscribe(r=>{xn(r).catch(o=>{console.error("Error saving storage:",o)})});const An=(r=>o=>yn(r,o,an)),jn=An(L),Tn=r=>{L.getState().setApiURL(r)},Mn=()=>L.getState().session.apiURL??"",Fn=()=>L.getState().session.authToken??"",Pn=()=>L.getState().isLoggedIn(),Dn=r=>{L.getState().setAuthToken(r)},ct=()=>L.getState(),ut=p.createContext(null);function $n({apiURL:r,autoFetch:o=!0,children:e,fetchOnMount:t=!0,onFetchSession:n,onLogin:s,onLogout:i,program:l,throttleMs:a=0}){const h=p.useRef(0),c=p.useRef(!1),u=p.useRef(!1),m=p.useCallback(async y=>{const _=Date.now(),E=_-h.current;if(!c.current&&!(a>0&&E<a))try{c.current=!0,h.current=_,await L.getState().fetchData(y)}finally{c.current=!1}},[a]),g=p.useCallback(async()=>{await m()},[m]);p.useEffect(()=>{at().then(y=>{L.setState(_=>({..._,...y,session:{..._.session,...y.session}}))}).catch(y=>{console.error("Error loading storage on mount:",y)})},[]),p.useEffect(()=>{r&&L.getState().setApiURL(r)},[r]),p.useEffect(()=>{l&&L.getState().setProgram(l)},[l]),p.useEffect(()=>{n&&L.setState({onFetchSession:n})},[n]),p.useEffect(()=>{s&&L.setState({onLogin:s})},[s]),p.useEffect(()=>{i&&L.setState({onLogout:i})},[i]),p.useEffect(()=>{u.current||(u.current=!0,o&&t&&m(r).catch(y=>{console.error("Failed to fetch on mount:",y)}))},[r,o,t,m]);const b=p.useMemo(()=>({fetchData:m,getState:ct,refetch:g}),[m,g]);return d.jsx(ut.Provider,{value:b,children:e})}function zn(){const r=p.useContext(ut);if(!r)throw new Error("useGlobalStateStoreContext must be used within GlobalStateStoreProvider");return r}function X(r){return btoa(encodeURIComponent(r).replace(/%([0-9A-F]{2})/g,(o,e)=>String.fromCharCode(Number.parseInt(e,16))))}const Nn="gridler_golang_restapi_v2_token",Bn=(r,o)=>{const e=[...r.filter(t=>t!==void 0&&t.type!==void 0)];for(let t=0;t<e.length;t++)(!e[t].name||e[t].name==="")&&(e[t].name=""),e[t].type==="files"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="advsql"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="custom-sql-or"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="custom-sql-join"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="not-select-fields"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="custom-sql-w"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="select-fields"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="cql-sel"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),o&&((!e||e.length===0)&&o.set("x-limit","10"),e[t].type==="association_autoupdate"&&o.set("association_autoupdate",e[t].value??"1"),e[t].type==="association_autocreate"&&o.set("association_autocreate",e[t].value??"1"),e[t].type==="searchop"||e[t].type==="searchor"||e[t].type==="searchand"?o.set(encodeURIComponent(`x-${e[t].type}-${e[t].op}-${e[t].name}`),String(e[t].value)):o.set(encodeURIComponent(`x-${e[t].type}${e[t].name&&e[t].name!==""?"-"+e[t].name:""}`),String(e[t].value)));return e},re=(r,o)=>{const e=new Headers,t={},n=Qe?.();if(n&&n!=="")e.set("Authorization",`Token ${n}`);else{const i=Qe();i&&e.set("Authorization",`Token ${i}`)}o&&o.forEach((i,l)=>{e.set(l,i)});const s=[];for(const i of r?.filter(l=>!!l)??[]){const l=s.findIndex(a=>a.name===i.name&&a.type===i.type);l===-1?s.push(i):s[l]=i}if(Bn(s,e),e?.forEach((i,l)=>{t[l]=i}),o)for(const i of Object.keys(t))o.set(i,t[i]);return t},Ln={getAuthToken:()=>{if(localStorage){const r=localStorage.getItem(Nn);if(r)return r}}},Qe=()=>Ln?.getAuthToken?.();function Gn(r,o){if(!r||!o||r.includes("..")||r.includes("[]")||/\[\s*\]/.test(r))return;const e=r.replace(/\[(\w+)\]/g,".$1").split(".").filter(Boolean);if(e.length!==0)return e.reduce((t,n)=>{if(t!=null&&typeof t=="object")return t[n]},o)}const{Provider:qn,useStore:Ae}=ge.createSyncStore((r,o)=>({hide:e=>{o().setInstanceState(e,"visible",!1)},menus:[],setInstanceState:(e,t,n)=>{r(U.produce(s=>{const i=s?.menus?.findIndex(l=>l.id===e);i>=0&&(s.menus[i][t]=n)}))},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},show:(e,t)=>{const n=o(),s=n.menus.findIndex(l=>l.id===e),i=n.menus[s]?{...n.menus[s]}:{};Object.assign(i,t),i.id=i.id??e,i.visible=!(i.visible??!1),s<0?n.setState("menus",[...n.menus,i]):r(U.produce(l=>{l.menus||(l.menus=[]),l.menus[s]={...l.menus[s],...i}}))}}),r=>({providerID:r.providerID??`MenuStore-${ke.getUUID()}`}));function Vn(){const{menus:r,providerID:o,setInstanceState:e,width:t}=Ae(n=>({menus:n.menus,providerID:n.providerID,setInstanceState:n.setInstanceState,setState:n.setState,width:n.width}));return d.jsx(w.Portal,{id:`bmm_portal_${o}`,children:p.Children.toArray(r?.map((n,s)=>p.createElement(w.Menu,{shadow:"md",width:t??"300",...n.menuProps,key:`bmm_menu_${o}_${s}`,onClose:()=>{e(n.id,"visible",!1),n.menuProps?.onClose?.()},opened:n.visible},d.jsx(w.Menu.Target,{children:d.jsx("div",{id:`bmm_${o}_${s}_target`,style:{left:n.x,position:"fixed",top:n.y,visibility:"hidden"}})}),d.jsx(w.Menu.Dropdown,{children:n.renderer?n.renderer:p.Children.toArray(n.items?.map((i,l)=>d.jsx(dt,{...i},`bmm_${o}_${s}_item${l}`)))}))))},`bmm_portal_${o}`)}const dt=({children:r,label:o,...e})=>{const[t,n]=p.useState(!1);return typeof e.renderer=="function"?e.renderer({...e,loading:t,renderer:void 0,setLoading:n}):typeof e.renderer=="object"?e.renderer:e.isDivider?d.jsx(w.Menu.Divider,{}):e.items&&e.items.length>0?d.jsxs(w.Menu.Sub,{children:[d.jsx(w.Menu.Sub.Target,{children:d.jsx(w.Menu.Sub.Item,{...e,disabled:t,onClick:s=>{e.onClick?.(s),e.onClickAsync&&(n(!0),e.onClickAsync(s).finally(()=>n(!1)))},styles:{itemLabel:{overflow:"auto",wordWrap:"break-word"},...e.styles},children:r??o})}),d.jsx(w.Menu.Sub.Dropdown,{children:p.Children.toArray(e.items.map((s,i)=>d.jsx(dt,{...s},`bmm_subitem_${s?.id??""}${i}`)))})]}):!e.onClick&&!e.onClickAsync?d.jsxs(w.Menu.Label,{...e,children:[" ",r??o]}):d.jsx(w.Menu.Item,{...e,disabled:t,onClick:s=>{e.onClick?.(s),e.onClickAsync&&(n(!0),e.onClickAsync(s).finally(()=>n(!1)))},styles:{itemLabel:{overflow:"auto",wordWrap:"break-word"},...e.styles},children:r??o})};function ft(r){return d.jsxs(qn,{...r,children:[d.jsx(Vn,{}),r.children]})}const ht=[{label:"Contains",value:"contains"},{label:"Equal",value:"eq"},{label:"Not Equal",value:"neq"},{label:"Greater Than",value:"gt"},{label:"Greater Than or Equal",value:"gte"},{label:"Less Than",value:"lt"},{label:"Less Than or Equal",value:"lte"}],mt=r=>{const o=r.storeState?.colFilters?.findIndex(i=>i.id===r.column.id)??-1,e=r.storeState?.colFilters?.[o]??{id:r.column.id,value:""},[t,n]=p.useState(e?.value??""),[s]=ie.useDebouncedValue(t,900);return p.useEffect(()=>{r.storeState.setStateFN("colFilters",i=>{const l=i?.findIndex(h=>h.id===r.column.id)??-1,a=i??[];return l>=0?a[l]={...a[l],...r.options,id:r.column.id,value:s}:a.push({operator:"contains",...r.options,id:r.column.id,value:s}),a})},[s,r.column.id,r.options,r.storeState]),d.jsx(w.TextInput,{onChange:i=>n(i.target.value),rightSection:d.jsx(w.ActionIcon,{color:"gray",onClick:()=>n(""),variant:"filled",children:d.jsx(V.IconX,{color:"red"})}),value:t??e?.value})},gt=r=>{const o=r.storeState?.colFilters?.findIndex(i=>i.id===r.column.id)??-1,e=r.storeState?.colFilters?.[o]??{id:r.column.id,operator:"contains"},[t,n]=p.useState(e?.operator??"contains"),[s]=ie.useDebouncedValue(t,900);return p.useEffect(()=>{r.storeState.setStateFN("colFilters",i=>{const l=i?.findIndex(h=>h.id===r.column.id)??-1,a=i??[];return l>=0?a[l]={...a[l],...r.options,id:r.column.id,operator:s}:a.push({...r.options,id:r.column.id,operator:s,value:""}),a})},[s,r.column.id,r.options,r.storeState]),d.jsx(w.Select,{comboboxProps:{withinPortal:!1},data:ht,maxDropdownHeight:150,onChange:i=>n(i),placeholder:"Operator",searchable:!0,value:t??e?.operator,withScrollArea:!0})},Re=r=>d.jsxs(w.Stack,{onClick:o=>o.stopPropagation(),children:[d.jsx(gt,{...r}),d.jsx(mt,{...r})]}),Oe=r=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
9
|
+
color: hsl(${Math.max(0,Math.min(120-120*E,120))}deg 100% 31%);`,e?.key)}return e?.onChange&&!(s&&e.skipInitialOnChange)&&e.onChange(n),s=!1,n}return i.updateDeps=l=>{t=l},i}function Ne(r,o){if(r===void 0)throw new Error("Unexpected undefined");return r}const jt=(r,o)=>Math.abs(r-o)<1.01,Tt=(r,o,e)=>{let t;return function(...n){r.clearTimeout(t),t=r.setTimeout(()=>o.apply(this,n),e)}},Be=r=>{const{offsetWidth:o,offsetHeight:e}=r;return{width:o,height:e}},Ft=r=>r,Mt=r=>{const o=Math.max(r.startIndex-r.overscan,0),e=Math.min(r.endIndex+r.overscan,r.count-1),t=[];for(let n=o;n<=e;n++)t.push(n);return t},Pt=(r,o)=>{const e=r.scrollElement;if(!e)return;const t=r.targetWindow;if(!t)return;const n=i=>{const{width:l,height:a}=i;o({width:Math.round(l),height:Math.round(a)})};if(n(Be(e)),!t.ResizeObserver)return()=>{};const s=new t.ResizeObserver(i=>{const l=()=>{const a=i[0];if(a?.borderBoxSize){const h=a.borderBoxSize[0];if(h){n({width:h.inlineSize,height:h.blockSize});return}}n(Be(e))};r.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(e,{box:"border-box"}),()=>{s.unobserve(e)}},Le={passive:!0},Ge=typeof window>"u"?!0:"onscrollend"in window,Dt=(r,o)=>{const e=r.scrollElement;if(!e)return;const t=r.targetWindow;if(!t)return;let n=0;const s=r.options.useScrollendEvent&&Ge?()=>{}:Tt(t,()=>{o(n,!1)},r.options.isScrollingResetDelay),i=c=>()=>{const{horizontal:u,isRtl:m}=r.options;n=u?e.scrollLeft*(m&&-1||1):e.scrollTop,s(),o(n,c)},l=i(!0),a=i(!1);e.addEventListener("scroll",l,Le);const h=r.options.useScrollendEvent&&Ge;return h&&e.addEventListener("scrollend",a,Le),()=>{e.removeEventListener("scroll",l),h&&e.removeEventListener("scrollend",a)}},zt=(r,o,e)=>{if(o?.borderBoxSize){const t=o.borderBoxSize[0];if(t)return Math.round(t[e.options.horizontal?"inlineSize":"blockSize"])}return r[e.options.horizontal?"offsetWidth":"offsetHeight"]},$t=(r,{adjustments:o=0,behavior:e},t)=>{var n,s;const i=r+o;(s=(n=t.scrollElement)==null?void 0:n.scrollTo)==null||s.call(n,{[t.options.horizontal?"left":"top"]:i,behavior:e})};class Nt{constructor(o){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.currentScrollToIndex=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let e=null;const t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(n=>{n.forEach(s=>{const i=()=>{this._measureElement(s.target,s)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:n=>{var s;return(s=t())==null?void 0:s.observe(n,{box:"border-box"})},unobserve:n=>{var s;return(s=t())==null?void 0:s.unobserve(n)}}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,n])=>{typeof n>"u"&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Ft,rangeExtractor:Mt,onChange:()=>{},measureElement:zt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...e}},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=ne(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:process.env.NODE_ENV!=="production"&&"maybeNotify",debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var e;const t=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==t){if(this.cleanup(),!t){this.maybeNotify();return}this.scrollElement=t,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((e=this.scrollElement)==null?void 0:e.window)??null,this.elementsCache.forEach(n=>{this.observer.observe(n)}),this.unsubs.push(this.options.observeElementRect(this,n=>{this.scrollRect=n,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(n,s)=>{this.scrollAdjustments=0,this.scrollDirection=s?this.getScrollOffset()<n?"forward":"backward":null,this.scrollOffset=n,this.isScrolling=s,this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{const n=new Map,s=new Map;for(let i=t-1;i>=0;i--){const l=e[i];if(n.has(l.lane))continue;const a=s.get(l.lane);if(a==null||l.end>a.end?s.set(l.lane,l):l.end<a.end&&n.set(l.lane,!0),n.size===this.options.lanes)break}return s.size===this.options.lanes?Array.from(s.values()).sort((i,l)=>i.end===l.end?i.index-l.index:i.end-l.end)[0]:void 0},this.getMeasurementOptions=ne(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(e,t,n,s,i,l)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:t,scrollMargin:n,getItemKey:s,enabled:i,lanes:l}),{key:!1}),this.getMeasurements=ne(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:t,scrollMargin:n,getItemKey:s,enabled:i,lanes:l},a)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(const m of this.laneAssignments.keys())m>=e&&this.laneAssignments.delete(m);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(m=>{this.itemSizeCache.set(m.key,m.size)}));const h=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1);const c=this.measurementsCache.slice(0,h),u=new Array(l).fill(void 0);for(let m=0;m<h;m++){const g=c[m];g&&(u[g.lane]=m)}for(let m=h;m<e;m++){const g=s(m),y=this.laneAssignments.get(m);let b,E;if(y!==void 0&&this.options.lanes>1){b=y;const I=u[b],N=I!==void 0?c[I]:void 0;E=N?N.end+this.options.gap:t+n}else{const I=this.options.lanes===1?c[m-1]:this.getFurthestMeasurement(c,m);E=I?I.end+this.options.gap:t+n,b=I?I.lane:m%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(m,b)}const _=a.get(g),R=typeof _=="number"?_:this.options.estimateSize(m),k=E+R;c[m]={index:m,start:E,size:R,end:k,key:g,lane:b},u[b]=m}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=ne(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,s)=>this.range=e.length>0&&t>0?Bt({measurements:e,outerSize:t,scrollOffset:n,lanes:s}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=ne(()=>{let e=null,t=null;const n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,s,i)=>s===null||i===null?[]:e({startIndex:s,endIndex:i,overscan:t,count:n}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=e=>{const t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this._measureElement=(e,t)=>{const n=this.indexFromElement(e),s=this.measurementsCache[n];if(!s)return;const i=s.key,l=this.elementsCache.get(i);l!==e&&(l&&this.observer.unobserve(l),this.observer.observe(e),this.elementsCache.set(i,e)),e.isConnected&&this.resizeItem(n,this.options.measureElement(e,t,this))},this.resizeItem=(e,t)=>{const n=this.measurementsCache[e];if(!n)return;const s=this.itemSizeCache.get(n.key)??n.size,i=t-s;i!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(n,i,this):n.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",i),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=i,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,t)),this.notify(!1))},this.measureElement=e=>{if(!e){this.elementsCache.forEach((t,n)=>{t.isConnected||(this.observer.unobserve(t),this.elementsCache.delete(n))});return}this._measureElement(e,void 0)},this.getVirtualItems=ne(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{const n=[];for(let s=0,i=e.length;s<i;s++){const l=e[s],a=t[l];n.push(a)}return n},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{const t=this.getMeasurements();if(t.length!==0)return Ne(t[ot(0,t.length-1,n=>Ne(t[n]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;const s=this.getSize(),i=this.getScrollOffset();t==="auto"&&(t=e>=i+s?"end":"start"),t==="center"?e+=(n-s)/2:t==="end"&&(e-=s);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,e),0)},this.getOffsetForIndex=(e,t="auto")=>{e=Math.max(0,Math.min(e,this.options.count-1));const n=this.measurementsCache[e];if(!n)return;const s=this.getSize(),i=this.getScrollOffset();if(t==="auto")if(n.end>=i+s-this.options.scrollPaddingEnd)t="end";else if(n.start<=i+this.options.scrollPaddingStart)t="start";else return[i,t];if(t==="end"&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];const l=t==="end"?n.end+this.options.scrollPaddingEnd:n.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,t,n.size),t]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(e,{align:t="start",behavior:n}={})=>{n==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(e,t),{adjustments:void 0,behavior:n})},this.scrollToIndex=(e,{align:t="auto",behavior:n}={})=>{n==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),e=Math.max(0,Math.min(e,this.options.count-1)),this.currentScrollToIndex=e;let s=0;const i=10,l=h=>{if(!this.targetWindow)return;const c=this.getOffsetForIndex(e,h);if(!c){console.warn("Failed to get offset for index:",e);return}const[u,m]=c;this._scrollToOffset(u,{adjustments:void 0,behavior:n}),this.targetWindow.requestAnimationFrame(()=>{const g=()=>{if(this.currentScrollToIndex!==e)return;const y=this.getScrollOffset(),b=this.getOffsetForIndex(e,m);if(!b){console.warn("Failed to get offset for index:",e);return}jt(b[0],y)||a(m)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(g):g()})},a=h=>{this.targetWindow&&this.currentScrollToIndex===e&&(s++,s<i?(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("Schedule retry",s,i),this.targetWindow.requestAnimationFrame(()=>l(h))):console.warn(`Failed to scroll to index ${e} after ${i} attempts.`))};l(t)},this.scrollBy=(e,{behavior:t}={})=>{t==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+e,{adjustments:void 0,behavior:t})},this.getTotalSize=()=>{var e;const t=this.getMeasurements();let n;if(t.length===0)n=this.options.paddingStart;else if(this.options.lanes===1)n=((e=t[t.length-1])==null?void 0:e.end)??0;else{const s=Array(this.options.lanes).fill(null);let i=t.length-1;for(;i>=0&&s.some(l=>l===null);){const l=t[i];s[l.lane]===null&&(s[l.lane]=l.end),i--}n=Math.max(...s.filter(l=>l!==null))}return Math.max(n-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(o)}}const ot=(r,o,e,t)=>{for(;r<=o;){const n=(r+o)/2|0,s=e(n);if(s<t)r=n+1;else if(s>t)o=n-1;else return n}return r>0?r-1:0};function Bt({measurements:r,outerSize:o,scrollOffset:e,lanes:t}){const n=r.length-1,s=a=>r[a].start;if(r.length<=t)return{startIndex:0,endIndex:n};let i=ot(0,n,s,e),l=i;if(t===1)for(;l<n&&r[l].end<e+o;)l++;else if(t>1){const a=Array(t).fill(0);for(;l<n&&a.some(c=>c<e+o);){const c=r[l];a[c.lane]=c.end,l++}const h=Array(t).fill(e+o);for(;i>=0&&h.some(c=>c>=e);){const c=r[i];h[c.lane]=c.start,i--}i=Math.max(0,i-i%t),l=Math.min(n,l+(t-1-l%t))}return{startIndex:i,endIndex:l}}const qe=typeof document<"u"?he.useLayoutEffect:he.useEffect;function Lt({useFlushSync:r=!0,...o}){const e=he.useReducer(()=>({}),{})[1],t={...o,onChange:(s,i)=>{var l;r&&i?Et.flushSync(e):e(),(l=o.onChange)==null||l.call(o,s,i)}},[n]=he.useState(()=>new Nt(t));return n.setOptions(t),qe(()=>n._didMount(),[]),qe(()=>n._willUpdate()),n}function Gt(r){return Lt({observeElementRect:Pt,observeElementOffset:Dt,scrollToFn:$t,...r})}const{Provider:st,useStore:it}=pe.createSyncStore((r,o)=>({boxerData:[],fetchData:async(e,t)=>{const n=o();if(n.dataSource==="local"||!n.onAPICall){const s=n.data??[];if(!e){r({boxerData:s,hasMore:!1,total:s.length});return}const i=s.filter(l=>l.label.toLowerCase().includes(e.toLowerCase()));r({boxerData:i,hasMore:!1,total:i.length});return}if(n.onAPICall)try{r({isFetching:!0});const s=t?0:n.page,i=await n.onAPICall({page:s,pageSize:n.pageSize,search:e});r(U.produce(l=>{t?(l.boxerData=i.data,l.page=0):l.boxerData=[...l.boxerData??[],...i.data],l.total=i.total,l.hasMore=l.boxerData.length<i.total,l.isFetching=!1}))}catch(s){console.error("Boxer fetchData error:",s),r({isFetching:!1})}},fetchMoreOnBottomReached:e=>{const t=o();if(!t.hasMore||t.isFetching)return;(e.scrollTop+e.clientHeight)/e.scrollHeight>.8&&t.loadMore()},getState:e=>o()?.[e],hasMore:!0,input:"",isFetching:!1,loadMore:async()=>{const e=o();!e.hasMore||e.isFetching||(r(U.produce(t=>{t.page=t.page+1})),await e.fetchData(e.search))},opened:!1,page:0,pageSize:50,search:"",selectedOptionIndex:-1,setInput:e=>{r({input:e})},setOpened:e=>{r({opened:e})},setSearch:e=>{r({search:e})},setSelectedOptionIndex:e=>{r({selectedOptionIndex:e})},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},total:0}),({data:r=[],dataSource:o="local",pageSize:e=50,...t})=>({...t,boxerData:r,data:r,dataSource:o,hasMore:o==="server",pageSize:e,total:r.length})),lt=p.forwardRef((r,o)=>{const{clearable:e=!0,combobox:t,disabled:n,error:s,isFetching:i,label:l,leftSection:a,onBlur:h,onClear:c,onSearch:u,placeholder:m,search:g}=r,y=i?d.jsx(w.Loader,{size:"xs"}):g&&e?d.jsx(w.ActionIcon,{onClick:b=>{b.stopPropagation(),c()},size:"sm",variant:"subtle",children:d.jsx(V.IconX,{size:16})}):null;return d.jsx(w.TextInput,{disabled:n,error:s,label:l,leftSection:a,onBlur:h,onChange:u,onClick:()=>t.openDropdown(),onFocus:()=>t.openDropdown(),placeholder:m,ref:o,rightSection:y,value:g})});lt.displayName="BoxerTarget";const qt=r=>{const{boxerData:o,multiSelect:e,onOptionSubmit:t,value:n}=r;return{options:p.useMemo(()=>o.map((i,l)=>{const a=e?Array.isArray(n)&&n.includes(i.value):n===i.value;return d.jsx(w.Combobox.Option,{active:a,onClick:()=>{t(l)},value:String(l),children:e?d.jsxs("div",{style:{alignItems:"center",display:"flex",gap:"8px"},children:[d.jsx(w.Checkbox,{checked:a,onChange:()=>{},tabIndex:-1}),d.jsx("span",{children:i.label})]}):i.label},`${i.value}-${l}`)}),[o,n,e,t])}},at=p.forwardRef((r,o)=>{const e=p.useRef(null),t=p.useRef(null),n=p.useRef(null),s=p.useRef(null),{boxerData:i,clearable:l,comboBoxProps:a,dropDownProps:h,error:c,fetchData:u,fetchMoreOnBottomReached:m,input:g,isFetching:y,label:b,mah:E,multiSelect:_,onBufferChange:R,onChange:k,opened:I,openOnClear:N,placeholder:x,scrollAreaProps:S,search:O,selectedOptionIndex:z,selectFirst:B,setInput:M,setOpened:P,setSearch:T,setSelectedOptionIndex:G,showAll:q,value:j}=it(v=>({boxerData:v.boxerData,clearable:v.clearable,comboBoxProps:v.comboBoxProps,dropDownProps:v.dropDownProps,error:v.error,fetchData:v.fetchData,fetchMoreOnBottomReached:v.fetchMoreOnBottomReached,input:v.input,isFetching:v.isFetching,label:v.label,mah:v.mah,multiSelect:v.multiSelect,onBufferChange:v.onBufferChange,onChange:v.onChange,opened:v.opened,openOnClear:v.openOnClear,placeholder:v.placeholder,scrollAreaProps:v.scrollAreaProps,search:v.search,selectedOptionIndex:v.selectedOptionIndex,selectFirst:v.selectFirst,setInput:v.setInput,setOpened:v.setOpened,setSearch:v.setSearch,setSelectedOptionIndex:v.setSelectedOptionIndex,showAll:v.showAll,value:v.value})),J=i.length,Y=Gt({count:J,estimateSize:()=>36,getScrollElement:()=>e.current}),Q=Y.getVirtualItems(),K=p.useCallback(v=>{const $=typeof v=="string"?parseInt(v,10):v,D=i[$];if(D)if(_){const F=Array.isArray(j)?j:[],te=F.includes(D.value)?F.filter(ye=>ye!==D.value):[...F,D.value];k?.(te);const ve=i.filter(ye=>te.includes(ye.value));R?.(ve)}else k?.(D.value),T(""),M(D.label),n.current=D.value,P(!1)},[i,_,j,k,R,T,M,P]),f=p.useCallback(()=>{q&&B?K(0):(k?.(_?[]:null),T(""),M(""),t.current?.focus()),N&&P(!0)},[q,B,_,k,T,M,N,P,K]),C=w.useVirtualizedCombobox({getOptionId:v=>String(v),onDropdownClose:()=>{P(!1)},onDropdownOpen:()=>{(!j||_&&(!Array.isArray(j)||j.length===0))&&(T(""),M("")),C.selectFirstOption()},onSelectedOptionSubmit:K,opened:I,selectedOptionIndex:z,setSelectedOptionIndex:v=>{G(v),v!==-1&&Y.scrollToIndex(v)},totalOptionsCount:i.length}),{options:A}=qt({boxerData:i,multiSelect:_,onOptionSubmit:K,value:j});return p.useEffect(()=>{u("",!0)},[]),p.useEffect(()=>{const v=setTimeout(()=>{O!==void 0&&I&&u(O,!0)},300);return()=>clearTimeout(v)},[O,I]),p.useEffect(()=>{if(_){const v=i.filter($=>Array.isArray(j)&&j.includes($.value)).map($=>$.label).join(", ");!I&&g!==v&&(M(v),T(""))}else{const v=i.find($=>$.value===j)?.label;g!==v&&(O??"")===""&&n.current!==j&&j?M(v??""):!j&&!n.current&&(O??"")===""&&(T(""),M(""))}if(_){const v=i.filter($=>Array.isArray(j)&&j.includes($.value))??[];JSON.stringify(s.current)!==JSON.stringify(v)&&(R?.(v),s.current=v)}else{const v=i?.find($=>$.value===j)??null;s.current?.value!==v?.value&&(R?.(v),s.current=v)}},[j,i,g,O,_,I,R,M,T]),p.useEffect(()=>{B&&(i?.length??0)>0&&!_&&(j||K?.(0))},[B,i,_]),p.useImperativeHandle(o,()=>({clear:()=>{f()},close:()=>{P(!1),C.closeDropdown()},focus:()=>{t.current?.focus()},getValue:()=>j,open:()=>{P(!0),C.openDropdown()},setValue:v=>{k?.(v)}})),d.jsxs(w.Combobox,{...a,resetSelectionOnOptionHover:!1,store:C,withinPortal:!0,children:[d.jsx(w.Combobox.Target,{children:d.jsx(w.Combobox.EventsTarget,{children:d.jsx(lt,{clearable:l,combobox:C,error:c,isFetching:y,label:b,onBlur:()=>{!j&&!_&&(T(""),M(""),C.closeDropdown(),P(!1))},onClear:f,onSearch:v=>{T(v.currentTarget.value),M(v.currentTarget.value),P(!0)},placeholder:x,ref:t,search:g})})}),d.jsx(w.Combobox.Dropdown,{onKeyDown:()=>{t.current&&(t.current.value="",t.current?.focus())},p:2,...h,children:I&&A.length>0?d.jsx(w.Combobox.Options,{children:d.jsx(w.ScrollArea.Autosize,{...S,mah:E??200,viewportProps:{...S?.viewportProps,onScroll:v=>{m(v.currentTarget)},style:{border:"1px solid gray",borderRadius:4}},viewportRef:e,children:d.jsx("div",{style:{height:`${Y.getTotalSize()}px`,position:"relative",width:"100%"},children:d.jsx("div",{style:{left:0,position:"absolute",top:0,transform:`translateY(${Q[0]?.start??0}px)`,width:"100%"},children:Q.map(v=>d.jsx("div",{"data-index":v.index,ref:Y.measureElement,children:A[v.index]},v.key))})})})}):d.jsx(w.Combobox.Empty,{children:"Nothing found"})})]})});at.displayName="BoxerInner";const ct=p.forwardRef((r,o)=>d.jsx(st,{...r,children:d.jsx(at,{ref:o})}));ct.displayName="Boxer";class Vt{config={enabled:!0};reporters=[];sentryInstance=null;configure(o){this.config={...this.config,...o},this.reporters=[],o.sentry&&this.setupSentry(o.sentry),o.customAPI&&this.setupCustomAPI(o.customAPI),o.reporters&&this.reporters.push(...o.reporters)}destroy(){this.reporters=[],this.sentryInstance=null,this.config={enabled:!0}}getReporters(){return[...this.reporters]}isEnabled(){return!!this.config.enabled}async reportError(o,e,t){if(!this.config.enabled)return;let n={context:t,error:o,errorInfo:e,severity:"error",timestamp:Date.now()};if(this.config.beforeReport){const i=this.config.beforeReport(n);if(!i)return;n=i}const s=this.reporters.filter(i=>i.isEnabled()).map(async i=>{try{await i.captureError(n)}catch(l){console.error(`Error reporter "${i.name}" failed:`,l),this.config.onReportFailure&&this.config.onReportFailure(l,n)}});try{await Promise.all(s),this.config.onReportSuccess&&this.config.onReportSuccess(n)}catch(i){console.error("Error reporting failed:",i)}}setupCustomAPI(o){const e={captureError:async t=>{try{const n=o.transformPayload?o.transformPayload(t):{context:t.context,message:t.error.message,severity:t.severity||"error",stack:t.error.stack,timestamp:t.timestamp||Date.now()},s=await fetch(o.endpoint,{body:JSON.stringify(n),headers:{"Content-Type":"application/json",...o.headers},method:o.method||"POST"});if(!s.ok)throw new Error(`API request failed: ${s.statusText}`)}catch(n){console.error("Failed to send error to custom API:",n)}},isEnabled:()=>!!o.endpoint,name:"CustomAPI"};this.reporters.push(e)}setupSentry(o){const e={captureError:async t=>{if(!this.sentryInstance)try{const n=await Promise.resolve().then(()=>require("./index-wyM2YQFr.cjs"));n.init({beforeSend:o.beforeSend,dsn:o.dsn,environment:o.environment,ignoreErrors:o.ignoreErrors,release:o.release,tracesSampleRate:o.sampleRate||1}),this.sentryInstance=n}catch(n){console.error("Failed to initialize Sentry:",n);return}this.sentryInstance.withScope(n=>{t.severity&&n.setLevel(t.severity),t.context?.namespace&&n.setTag("namespace",t.context.namespace),t.context?.tags&&Object.entries(t.context.tags).forEach(([s,i])=>{n.setTag(s,i)}),t.context?.user&&n.setUser(t.context.user),t.context?.extra&&n.setExtras(t.context.extra),t.context?.componentStack&&n.setContext("react",{componentStack:t.context.componentStack}),this.sentryInstance.captureException(t.error)})},isEnabled:()=>!!this.sentryInstance,name:"Sentry"};this.reporters.push(e)}}const me=new Vt;class Ht extends p.PureComponent{constructor(o){super(o),this.state={error:null,errorInfo:null,showDetail:!1,timer:void 0,try:!1,tryCnt:0}}componentDidCatch(o,e){this.setState({error:o,errorInfo:e,try:!1}),me.reportError(o,e,{componentStack:e?.componentStack,namespace:this.props.namespace})}render(){return this.state.errorInfo?d.jsxs("div",{children:[d.jsx("h2",{children:"Error"}),this.state.error&&d.jsxs(d.Fragment,{children:[d.jsxs("h3",{children:["In: ",this.props.namespace??"default"]}),d.jsx("main",{children:this.state.error.toString()})]})]}):this.props.children}}let Wt={disabled:!1,onError:void 0};const be=()=>({...Wt});class Kt extends p.Component{constructor(o){super(o),this.state={error:null,errorInfo:null,showDetail:!1,timer:void 0,try:!1,tryCnt:0}}componentDidCatch(o,e){if(be()?.disabled)throw Error("ErrorBoundary pass through enabled, rethrowing error",{cause:o,info:e});this.setState({error:o,errorInfo:e,try:!1}),typeof be()?.onError=="function"&&be()?.onError?.(o,e),me.reportError(o,e,{componentStack:e?.componentStack,namespace:this.props.namespace})}render(){if(this.state.errorInfo)return d.jsxs("div",{children:[d.jsxs("h2",{style:{color:"var(--mantine-color-error)",display:"flex",gap:"8px"},children:[d.jsx(V.IconExclamationCircle,{color:"var(--mantine-color-error)",style:{height:w.rem(20),width:w.rem(20)}}),"A react error has occurred!"]}),d.jsx("h4",{children:"You can try one of these solutions to get back on track:"}),d.jsxs("ul",{children:[d.jsx("li",{children:"Report the error to our team"}),d.jsx("li",{children:"Hit the keys Ctrl-Shift-R"}),d.jsx("li",{children:"Make sure your web browser is up to date"}),d.jsx("li",{children:"Clear your browser cache and cookies"}),d.jsx("li",{children:"Try using a different web browser"}),d.jsx("li",{children:"Reset your layout and settings"}),d.jsx("li",{children:"Retry loading the application"})]}),d.jsxs(w.Group,{children:[d.jsx(w.Button,{color:"red",my:"md",onClick:()=>this.setState(o=>({showDetail:!o.showDetail})),size:"compact-xs",variant:"outline",children:"More"}),d.jsxs(w.Button,{color:"blue",disabled:this.state.tryCnt>2||this.state.try,my:"md",onClick:()=>this.retry(),size:"compact-xs",variant:"outline",children:["Retry ",this.state.tryCnt>0?`(${this.state.tryCnt})`:""]}),d.jsx(w.Button,{color:"yellow",disabled:this.state.wasReset,my:"md",onClick:()=>this.reset(),size:"compact-xs",variant:"outline",children:"Reset Layout or Settings"}),d.jsx(w.Button,{color:"green",disabled:this.state.reported,my:"md",onClick:()=>this.report(),size:"compact-xs",variant:"outline",children:"Report"})]}),this.state.error&&d.jsxs(w.Paper,{p:"md",shadow:"xs",style:{textAlign:"justify"},w:"50%",withBorder:!0,children:[this.props.namespace&&d.jsxs(w.Text,{size:"sm",children:["In: ",this.props.namespace]}),d.jsx(w.Text,{size:"sm",children:this.state.error.toString()})]}),d.jsx(w.Collapse,{in:this.state.showDetail,children:d.jsx(w.Code,{block:!0,color:"rgba(235, 86, 5, 0.6)",mah:"100vh",w:"100%",children:this.state.errorInfo.componentStack})})]});if(this.state.try){if(!this.state.timer){const o=setTimeout(()=>{clearTimeout(this.state.timer),this.setState(e=>({...e,timer:void 0,try:!1}))},1e3);this.setState(e=>({...e,timer:o}))}return d.jsxs("div",{children:["Retrying ",this.state.tryCnt,"..."]})}return this.props.children}async report(){if(this.props?.onReportClick){this.props.onReportClick(),this.setState(()=>({reported:!0}));return}this.state.error&&this.state.errorInfo&&(await me.reportError(this.state.error,this.state.errorInfo,{componentStack:this.state.errorInfo?.componentStack,namespace:this.props.namespace,tags:{reportedBy:"user"}}),this.setState(()=>({reported:!0})))}reset(){if(this.props?.onResetClick){this.props.onResetClick(),this.setState(()=>({wasReset:!0}));return}this.setState(()=>({wasReset:!0})),window.location.reload()}retry(){if(this.setState({try:!0,tryCnt:this.state.tryCnt+1}),this.props?.onRetryClick){this.props.onRetryClick();return}this.setState({error:void 0,errorInfo:void 0}),this.forceUpdate()}}const{Provider:Ut,useStore:ae}=pe.createSyncStore((r,o)=>({getState:e=>o()?.[e],load:async e=>{try{r({loading:!0});const t=o()?.uniqueKeyField||"id",n=o().values?.[t]??o().primeData?.[t];if(o().onAPICall&&n!==void 0){let s=await o().onAPICall("read",o().request||"insert",o().values,n);o().afterGet&&(s=await o().afterGet({...s})),r({loading:!1,values:s}),o().onChange?.(s)}e&&o().getFormMethods&&o().getFormMethods().reset()}catch(t){r({error:t?.message??t,loading:!1})}r({loading:!1})},onChange:e=>{r({values:e})},request:"insert",reset:async()=>{const e=o();e.getFormMethods&&(e.request!=="insert"&&await e.load(!0),e.getFormMethods().reset({...e.values,...e.primeData}))},save:async e=>{try{const t=o().keepOpen??!1;if(r({loading:!0}),o().getFormMethods){const n=o().getFormMethods();let s=n.getValues();o().beforeSave&&(s=await o().beforeSave(s));let i=!1;if(await n.handleSubmit(a=>{s=a},a=>{r({error:a.root?.message||"Validation errors",loading:!1}),i=!0})(e),i){r({loading:!1});return}if(o().request==="delete"&&!o().deleteConfirmed&&!(await o().onConfirmDelete?.(s)??!1)){r({loading:!1});return}if(o().onAPICall){const a=o()?.uniqueKeyField||"id",h=o().values?.[a]??o().primeData?.[a],c=await o().onAPICall("mutate",o().request||"insert",s,h);return o().afterSave&&await o().afterSave(c),r({loading:!1,values:c}),o().onChange?.(c),n.reset(c),t||o().onClose?.(c),c}return r({loading:!1,values:s}),n.reset(s),o().onChange?.(s),t||o().onClose?.(s),s}}catch(t){r({error:t?.message??t,loading:!1})}},setRequest:e=>{r({request:e})},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},setStateFN:(e,t)=>new Promise((s,i)=>{r(U.produce(l=>{if(typeof t=="function")l[e]=t(l[e]);else throw i(new Error(`Not a function ${t}`)),Error(`Not a function ${t}`)})),s()}),validate:async()=>o().getFormMethods?await o().getFormMethods().trigger():!0,values:void 0}),({id:r,onClose:o,onConfirmDelete:e,primeData:t,request:n,useStoreApi:s,values:i})=>{let l=e;return e||(l=async()=>confirm("Are you sure you want to delete this item?")),{id:r||Te.newUUID(),onClose:()=>{const a=s.getState().dirty,h=s.getState().setState;a?confirm("You have unsaved changes. Are you sure you want to close?")&&(o?o():h("opened",!1)):o?o():h("opened",!1)},onConfirmDelete:l,primeData:t,request:(n||"insert").replace("change","update"),values:{...t,...i}}}),le=()=>{const{buttonAreaGroupProps:r,closeButtonProps:o,closeButtonTitle:e,dirty:t,onClose:n,request:s,save:i,saveButtonProps:l,saveButtonTitle:a}=ae(c=>({buttonAreaGroupProps:c.layout?.buttonAreaGroupProps,closeButtonProps:c.layout?.closeButtonProps,closeButtonTitle:c.layout?.closeButtonTitle,dirty:c.dirty,onClose:c.onClose,request:c.request,save:c.save,saveButtonProps:c.layout?.saveButtonProps,saveButtonTitle:c.layout?.saveButtonTitle})),h=["select","view"].includes(s||"")||["update"].includes(s||"")&&!t;return d.jsx(w.Group,{justify:"center",p:"xs",style:{boxShadow:"2px 2px 5px rgba(47, 47, 47, 0.1)"},w:"100%",...r,children:d.jsxs(w.Group,{grow:!0,justify:"space-evenly",children:[typeof n=="function"&&d.jsx(w.Button,{color:"orange",leftSection:d.jsx(V.IconX,{}),miw:"8rem",px:"md",size:"sm",...o,onClick:()=>{n()},children:e||"Close"}),d.jsx(w.Tooltip,{label:h?d.jsxs("p",{children:["Cannot save in view or select mode, or no changes made. ",d.jsx("br",{}),"Try changing some values."]}):d.jsx("p",{children:"Save the current record"}),children:d.jsx(w.Button,{bg:s==="delete"?"red":void 0,color:"green",leftSection:d.jsx(V.IconDeviceFloppy,{}),miw:"8rem",px:"md",size:"sm",...l,disabled:h,onClick:()=>i(),children:a||"Save"})})]})})},Jt=()=>{const{buttonArea:r,getState:o,opened:e,renderBottom:t,setState:n}=ae(s=>({buttonArea:s.layout?.buttonArea,getState:s.getState,opened:s.opened,renderBottom:s.layout?.renderBottom,setState:s.setState}));return t?t(d.jsx(le,{}),e??!1,o("onClose")??(()=>{n("opened",!1)}),o("onOpen")??(()=>{n("opened",!0)}),o):r==="bottom"?d.jsx(le,{}):d.jsx(d.Fragment,{})},Yt=()=>{const{buttonArea:r,getState:o,opened:e,renderTop:t,setState:n}=ae(s=>({buttonArea:s.layout?.buttonArea,getState:s.getState,opened:s.opened,renderTop:s.layout?.renderTop,setState:s.setState}));return t?t(d.jsx(le,{}),e??!1,o("onClose")??(()=>{n("opened",!1)}),o("onOpen")??(()=>{n("opened",!0)}),o):r==="top"?d.jsx(le,{}):d.jsx(d.Fragment,{})},Ve=r=>{const{disableHTMlForm:o,getFormMethods:e,id:t,load:n,loading:s,loadingOverlayProps:i,opened:l,request:a,reset:h,save:c,scrollAreaProps:u}=ae(m=>({disableHTMlForm:m.disableHTMlForm,getFormMethods:m.getFormMethods,id:m.id,load:m.load,loading:m.loading,loadingOverlayProps:m.loadingOverlayProps,opened:m.opened,request:m.request,reset:m.reset,save:m.save,scrollAreaProps:m.scrollAreaProps}));return p.useEffect(()=>{e&&e()&&a!=="insert"&&n(!0)},[e,a,l]),d.jsxs(d.Fragment,{children:[d.jsx(Yt,{}),d.jsxs(w.ScrollAreaAutosize,{offsetScrollbars:!0,scrollbarSize:4,type:"auto",...u,style:{height:"100%",padding:"0.25rem",width:"100%",...u?.style},children:[o?d.jsx("div",{"x-data-request":a,children:r.children},`former_d${t}`):d.jsx("form",{id:`former_f${t}`,onReset:m=>h(m),onSubmit:m=>c(m),"x-data-request":a,children:r.children},`former_${t}`),d.jsx(w.LoadingOverlay,{loaderProps:{type:"bars"},overlayProps:{backgroundOpacity:.5},...i,visible:s})]}),d.jsx(Jt,{})]})},Xt=p.forwardRef(function(o,e){const{getState:t,onChange:n,onClose:s,onOpen:i,opened:l,primeData:a,reset:h,save:c,setState:u,useFormProps:m,validate:g,values:y,wrapper:b}=ae(_=>({getState:_.getState,onChange:_.onChange,onClose:_.onClose,onOpen:_.onOpen,opened:_.opened,primeData:_.primeData,reset:_.reset,save:_.save,setState:_.setState,useFormProps:_.useFormProps,validate:_.validate,values:_.values,wrapper:_.wrapper})),E=ee.useForm({defaultValues:a,mode:"all",shouldUseNativeValidation:!0,values:y,...m});return p.useImperativeHandle(e,()=>({close:async()=>{s?.(),u("opened",!1)},getValue:()=>t("values"),reset:()=>{h()},save:async()=>await c(),setValue:_=>{n?.(_)},show:async()=>{u("opened",!0),i?.()},validate:async()=>await g()}),[t,n,g,c,h,u,s,i]),p.useEffect(()=>{u("getFormMethods",()=>E),E&&E.subscribe({callback:({isDirty:_})=>{u("dirty",_)},formState:{isDirty:!0}})},[E]),d.jsx(ee.FormProvider,{...E,children:typeof b=="function"?b(d.jsx(Ve,{children:o.children}),l??!1,s??(()=>{u("opened",!1)}),i??(()=>{u("opened",!0)}),t):d.jsx(Ve,{children:o.children||null})})}),Se=p.forwardRef(function(o,e){return!o.opened&&typeof o.wrapper=="function"?null:d.jsx(Ut,{...o,children:d.jsx(Xt,{ref:e,children:o.children})})});function Qt(r){return async(o,e,t,n)=>{let i=`${r.url.replace(/\/$/,"")}`;e!=="insert"&&n&&(i=`${i}/${n}`);const l={operation:o==="read"?"read":e==="delete"?"delete":e==="update"?"update":"create"};o==="mutate"&&(l.data=t);const a={cache:"no-cache",signal:r.signal,...r.fetchOptions,body:JSON.stringify(l),headers:{Authorization:`Bearer ${r.authToken}`,"Content-Type":"application/json",...r.fetchOptions?.headers},method:"POST"},h=await fetch(i,a);if(!h.ok)throw new Error(`API request failed with status ${h.status}`);return await h.json()}}function Zt(r){return async(o,e,t,n)=>{const s=r.url??"";let i=s;const l={cache:"no-cache",signal:r.signal,...r.fetchOptions,body:o==="mutate"&&e!=="delete"?JSON.stringify(t):void 0,headers:{Authorization:`Bearer ${r.authToken}`,"Content-Type":"application/json",...r.fetchOptions?.headers},method:o==="read"?"GET":e==="delete"?"DELETE":e==="update"?"PUT":"POST"};e!=="insert"&&(i=`${s}/${n}`);const a=await fetch(i,l);if(!a.ok)throw new Error(`API request failed with status ${a.status}`);return await a.json()}}const en=r=>{const{children:o,former:e,onClose:t,opened:n,...s}=r;return d.jsx(Se,{...e,onClose:t,opened:n,wrapper:(i,l,a,h,c)=>{const u=c("values"),m=c("request"),g=c("uniqueKeyField")??"id";return d.jsx(w.Drawer,{closeOnClickOutside:!1,h:"100%",title:m==="delete"?`Delete Record - ${u?.[g]}`:m==="insert"?"New Record":`Edit Record - ${u?.[g]}`,...s,onClose:()=>a?.(),opened:l??!1,children:i})},children:o})},tn=r=>{const{children:o,former:e,onClose:t,opened:n,...s}=r;return d.jsx(Se,{...e,onClose:t,opened:n,wrapper:(i,l,a,h,c)=>{const u=c("values"),m=c("request"),g=c("uniqueKeyField")??"id";return d.jsx(w.Modal,{closeOnClickOutside:!1,h:"100%",title:m==="delete"?`Delete Record - ${u?.[g]}`:m==="insert"?"New Record":`Edit Record - ${u?.[g]}`,...s,onClose:()=>a?.(),opened:l??!1,children:i})},children:o})},nn=r=>{const{children:o,former:e,onClose:t,opened:n,target:s,...i}=r;return d.jsx(Se,{...e,onClose:t,opened:n,wrapper:(l,a,h)=>d.jsxs(w.Popover,{closeOnClickOutside:!1,middlewares:{inline:!0},trapFocus:!0,width:250,withArrow:!0,...i,onClose:()=>h?.(),opened:a??!1,children:[d.jsx(w.Popover.Target,{children:s}),d.jsx(w.Popover.Dropdown,{children:l})]}),children:o})},rn=r=>{const[o,e]=p.useState(!1);return d.jsx(w.Tooltip,{label:r.tooltip??"",withArrow:!0,children:d.jsx(w.Button,{loaderProps:{type:"bars"},...r,loading:o||r.loading,onClick:t=>{r.onClick&&(e(!0),r.onClick(t).finally(()=>e(!1)))},children:r.children})})},on=r=>{const[o,e]=p.useState(!1);return d.jsx(w.Tooltip,{label:r.tooltip??"",withArrow:!0,children:d.jsxs(w.ActionIcon,{loaderProps:{type:"bars"},...r,loading:o||r.loading,onClick:t=>{r.onClick&&(e(!0),r.onClick(t).finally(()=>e(!1)))},children:[r.children,d.jsxs(w.VisuallyHidden,{children:["Action Button: ",r.tooltip??r.sid??""]})]})})},sn=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.NativeSelect,{...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},ln=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.PasswordInput,{...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},an=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.Switch,{...s,...i,checked:!!i.value,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`,onChange:a=>{i.onChange((a.currentTarget??a.target)?.checked)}})})})},cn=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.Textarea,{minRows:4,...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},un=r=>{const{control:o,name:e,sid:t,tooltip:n,...s}=r;return d.jsx(ee.Controller,{control:o,name:e,render:({field:i,formState:l})=>d.jsx(w.Tooltip,{label:n??"",withArrow:!0,children:p.createElement(w.TextInput,{...s,...i,disabled:l.disabled,id:`field_${e}_${t??""}`,key:`field_${e}_${t??""}`},r.children)})})},He=r=>Symbol.iterator in r,We=r=>"entries"in r,Ke=(r,o)=>{const e=r instanceof Map?r:new Map(r.entries()),t=o instanceof Map?o:new Map(o.entries());if(e.size!==t.size)return!1;for(const[n,s]of e)if(!t.has(n)||!Object.is(s,t.get(n)))return!1;return!0},dn=(r,o)=>{const e=r[Symbol.iterator](),t=o[Symbol.iterator]();let n=e.next(),s=t.next();for(;!n.done&&!s.done;){if(!Object.is(n.value,s.value))return!1;n=e.next(),s=t.next()}return!!n.done&&!!s.done};function fn(r,o){return Object.is(r,o)?!0:typeof r!="object"||r===null||typeof o!="object"||o===null||Object.getPrototypeOf(r)!==Object.getPrototypeOf(o)?!1:He(r)&&He(o)?We(r)&&We(o)?Ke(r,o):dn(r,o):Ke({entries:()=>Object.entries(r)},{entries:()=>Object.entries(o)})}var ue={exports:{}},we={},de={exports:{}},xe={};var Ue;function hn(){if(Ue)return xe;Ue=1;var r=p;function o(u,m){return u===m&&(u!==0||1/u===1/m)||u!==u&&m!==m}var e=typeof Object.is=="function"?Object.is:o,t=r.useState,n=r.useEffect,s=r.useLayoutEffect,i=r.useDebugValue;function l(u,m){var g=m(),y=t({inst:{value:g,getSnapshot:m}}),b=y[0].inst,E=y[1];return s(function(){b.value=g,b.getSnapshot=m,a(b)&&E({inst:b})},[u,g,m]),n(function(){return a(b)&&E({inst:b}),u(function(){a(b)&&E({inst:b})})},[u]),i(g),g}function a(u){var m=u.getSnapshot;u=u.value;try{var g=m();return!e(u,g)}catch{return!0}}function h(u,m){return m()}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?h:l;return xe.useSyncExternalStore=r.useSyncExternalStore!==void 0?r.useSyncExternalStore:c,xe}var Ce={};var Je;function mn(){return Je||(Je=1,process.env.NODE_ENV!=="production"&&(function(){function r(g,y){return g===y&&(g!==0||1/g===1/y)||g!==g&&y!==y}function o(g,y){c||n.startTransition===void 0||(c=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var b=y();if(!u){var E=y();s(b,E)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}E=i({inst:{value:b,getSnapshot:y}});var _=E[0].inst,R=E[1];return a(function(){_.value=b,_.getSnapshot=y,e(_)&&R({inst:_})},[g,b,y]),l(function(){return e(_)&&R({inst:_}),g(function(){e(_)&&R({inst:_})})},[g]),h(b),b}function e(g){var y=g.getSnapshot;g=g.value;try{var b=y();return!s(g,b)}catch{return!0}}function t(g,y){return y()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=p,s=typeof Object.is=="function"?Object.is:r,i=n.useState,l=n.useEffect,a=n.useLayoutEffect,h=n.useDebugValue,c=!1,u=!1,m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?t:o;Ce.useSyncExternalStore=n.useSyncExternalStore!==void 0?n.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),Ce}var Ye;function ut(){return Ye||(Ye=1,process.env.NODE_ENV==="production"?de.exports=hn():de.exports=mn()),de.exports}var Xe;function gn(){if(Xe)return we;Xe=1;var r=p,o=ut();function e(h,c){return h===c&&(h!==0||1/h===1/c)||h!==h&&c!==c}var t=typeof Object.is=="function"?Object.is:e,n=o.useSyncExternalStore,s=r.useRef,i=r.useEffect,l=r.useMemo,a=r.useDebugValue;return we.useSyncExternalStoreWithSelector=function(h,c,u,m,g){var y=s(null);if(y.current===null){var b={hasValue:!1,value:null};y.current=b}else b=y.current;y=l(function(){function _(x){if(!R){if(R=!0,k=x,x=m(x),g!==void 0&&b.hasValue){var S=b.value;if(g(S,x))return I=S}return I=x}if(S=I,t(k,x))return S;var O=m(x);return g!==void 0&&g(S,O)?(k=x,S):(k=x,I=O)}var R=!1,k,I,N=u===void 0?null:u;return[function(){return _(c())},N===null?void 0:function(){return _(N())}]},[c,u,m,g]);var E=n(h,y[0],y[1]);return i(function(){b.hasValue=!0,b.value=E},[E]),a(E),E},we}var _e={};var Qe;function pn(){return Qe||(Qe=1,process.env.NODE_ENV!=="production"&&(function(){function r(h,c){return h===c&&(h!==0||1/h===1/c)||h!==h&&c!==c}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=p,e=ut(),t=typeof Object.is=="function"?Object.is:r,n=e.useSyncExternalStore,s=o.useRef,i=o.useEffect,l=o.useMemo,a=o.useDebugValue;_e.useSyncExternalStoreWithSelector=function(h,c,u,m,g){var y=s(null);if(y.current===null){var b={hasValue:!1,value:null};y.current=b}else b=y.current;y=l(function(){function _(x){if(!R){if(R=!0,k=x,x=m(x),g!==void 0&&b.hasValue){var S=b.value;if(g(S,x))return I=S}return I=x}if(S=I,t(k,x))return S;var O=m(x);return g!==void 0&&g(S,O)?(k=x,S):(k=x,I=O)}var R=!1,k,I,N=u===void 0?null:u;return[function(){return _(c())},N===null?void 0:function(){return _(N())}]},[c,u,m,g]);var E=n(h,y[0],y[1]);return i(function(){b.hasValue=!0,b.value=E},[E]),a(E),E},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),_e}var Ze;function Sn(){return Ze||(Ze=1,process.env.NODE_ENV==="production"?ue.exports=gn():ue.exports=pn()),ue.exports}var vn=Sn();const yn=Ot(vn),et=r=>{let o;const e=new Set,t=(h,c)=>{const u=typeof h=="function"?h(o):h;if(!Object.is(u,o)){const m=o;o=c??(typeof u!="object"||u===null)?u:Object.assign({},o,u),e.forEach(g=>g(o,m))}},n=()=>o,l={setState:t,getState:n,getInitialState:()=>a,subscribe:h=>(e.add(h),()=>e.delete(h))},a=o=r(t,n,l);return l},bn=(r=>r?et(r):et),{useSyncExternalStoreWithSelector:wn}=yn,xn=r=>r;function Cn(r,o=xn,e){const t=wn(r.subscribe,r.getState,r.getInitialState,o,e);return p.useDebugValue(t),t}const dt="APP_GLO",_n=new Set(["app.controls","initialized","session.connected","session.error","session.loading"]),En=r=>_n.has(r),Oe=(r,o="")=>{if(typeof r=="function")return;if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map((t,n)=>Oe(t,`${o}[${n}]`));const e={};for(const[t,n]of Object.entries(r)){const s=o?`${o}.${t}`:t;En(s)||typeof n=="function"||(e[t]=Oe(n,s))}return e};async function Rn(){const r={},o=["layout","navigation","owner","program","session","user"];for(const e of o){const t=`${dt}:${e}`;if(e==="session"){try{if(typeof localStorage<"u"){const n=localStorage.getItem(t);n&&(r[e]=JSON.parse(n))}}catch(n){console.error(`Failed to load ${e} from localStorage:`,n)}continue}try{if(typeof indexedDB<"u"){const n=await rt.get(t);if(n){r[e]=JSON.parse(n);continue}}}catch(n){console.error(`Failed to load ${e} from IndexedDB, falling back to localStorage:`,n)}try{if(typeof localStorage<"u"){const n=localStorage.getItem(t);n&&(r[e]=JSON.parse(n))}}catch(n){console.error(`Failed to load ${e} from localStorage:`,n)}}return r}async function On(r){const o=["layout","navigation","owner","program","session","user"];for(const e of o){const t=`${dt}:${e}`,n=Oe(r[e],e),s=JSON.stringify(n);if(e==="session"){try{typeof localStorage<"u"&&localStorage.setItem(t,s)}catch(i){console.error(`Failed to save ${e} to localStorage:`,i)}continue}try{if(typeof indexedDB<"u"){await rt.set(t,s);continue}}catch(i){console.error(`Failed to save ${e} to IndexedDB, falling back to localStorage:`,i)}try{typeof localStorage<"u"&&localStorage.setItem(t,s)}catch(i){console.error(`Failed to save ${e} to localStorage:`,i)}}}const Ie={initialized:!1,layout:{bottomBar:{open:!1},leftBar:{open:!1},rightBar:{open:!1},topBar:{open:!1}},navigation:{menu:[]},owner:{guid:"",id:0,name:""},program:{controls:{},environment:"production",guid:"",name:"",slug:""},session:{apiURL:"",authToken:"",connected:!0,loading:!1,loggedIn:!1},user:{guid:"",username:""}},In=r=>({setProgram:o=>r(e=>({program:{...e.program,...o}}))}),kn=r=>({setApiURL:o=>r(e=>({session:{...e.session,apiURL:o}})),setAuthToken:o=>r(e=>({session:{...e.session,authToken:o}})),setSession:o=>r(e=>({session:{...e.session,...o}}))}),An=r=>({setOwner:o=>r(e=>({owner:{...e.owner,...o}}))}),jn=r=>({setUser:o=>r(e=>({user:{...e.user,...o}}))}),Tn=r=>({setBottomBar:o=>r(e=>({layout:{...e.layout,bottomBar:{...e.layout.bottomBar,...o}}})),setLayout:o=>r(e=>({layout:{...e.layout,...o}})),setLeftBar:o=>r(e=>({layout:{...e.layout,leftBar:{...e.layout.leftBar,...o}}})),setRightBar:o=>r(e=>({layout:{...e.layout,rightBar:{...e.layout.rightBar,...o}}})),setTopBar:o=>r(e=>({layout:{...e.layout,topBar:{...e.layout.topBar,...o}}}))}),Fn=r=>({setCurrentPage:o=>r(e=>({navigation:{...e.navigation,currentPage:o}})),setMenu:o=>r(e=>({navigation:{...e.navigation,menu:o}})),setNavigation:o=>r(e=>({navigation:{...e.navigation,...o}}))}),Mn=(r,o)=>{const e=async t=>{try{r(i=>({session:{...i.session,apiURL:t||i.session.apiURL,loading:!0}}));const n=o(),s=await n.onFetchSession?.(n);r(i=>({...i,...s,layout:{...i.layout,...s?.layout},navigation:{...i.navigation,...s?.navigation},owner:{...i.owner,...s?.owner},program:{...i.program,...s?.program,updatedAt:new Date().toISOString()},session:{...i.session,...s?.session,connected:!0,loading:!1},user:{...i.user,...s?.user}}))}catch(n){r(s=>({session:{...s.session,connected:!1,error:`Load Exception: ${String(n)}`,loading:!1}}))}};return{fetchData:async t=>(await Ee(),Re(()=>e(t))),isLoggedIn:()=>{const t=o().session;return!(!t.loggedIn||!t.authToken||t.expiryDate&&new Date(t.expiryDate)<new Date)},login:async(t,n)=>(await Ee(),Re(async()=>{try{r(l=>({session:{...l.session,authToken:t??"",expiryDate:new Date(Date.now()+1440*60*1e3).toISOString(),loading:!0,loggedIn:!0},user:{...l.user,...n}}));const s=o(),i=await s.onLogin?.(s);i&&r(l=>({...l,owner:i.owner?{...l.owner,...i.owner}:l.owner,program:i.program?{...l.program,...i.program}:l.program,session:i.session?{...l.session,...i.session}:l.session,user:i.user?{...l.user,...i.user}:l.user})),await e()}catch(s){r(i=>({session:{...i.session,connected:!1,error:`Login Exception: ${String(s)}`,loading:!1,loggedIn:!1}}))}finally{r(s=>({session:{...s.session,loading:!1}}))}})),logout:async()=>(await Ee(),Re(async()=>{try{r(s=>({...Ie,session:{...Ie.session,apiURL:s.session.apiURL,expiryDate:void 0,loading:!0,loggedIn:!1}}));const t=o(),n=await t.onLogout?.(t);n&&r(s=>({...s,owner:n.owner?{...s.owner,...n.owner}:s.owner,program:n.program?{...s.program,...n.program}:s.program,session:n.session?{...s.session,...n.session}:s.session,user:n.user?{...s.user,...n.user}:s.user})),await e()}catch(t){r(n=>({session:{...n.session,connected:!1,error:`Logout Exception: ${String(t)}`,loading:!1}}))}finally{r(t=>({session:{...t.session,loading:!1}}))}}))}};let ft=!1,ge=null,tt=Promise.resolve();const Ee=async()=>{ge&&await ge},Re=async r=>{const o=tt;let e;tt=new Promise(t=>{e=t});try{return await o,await r()}finally{e()}},L=bn((r,o)=>({...Ie,...In(r),...kn(r),...An(r),...jn(r),...Tn(r),...Fn(r),...Mn(r,o)}));ge=Rn().then(r=>{L.setState(o=>({...o,...r,initialized:!0,session:{...o.session,...r.session,connected:!0,loading:!1}}),!0)}).catch(r=>{console.error("Error loading storage:",r),L.setState({initialized:!0})}).finally(()=>{ft=!0,ge=null});L.subscribe(r=>{ft&&On(r).catch(o=>{console.error("Error saving storage:",o)})});const Pn=(r=>o=>Cn(r,o,fn)),Dn=Pn(L),zn=r=>{L.getState().setApiURL(r)},$n=()=>L.getState().session.apiURL??"",Nn=()=>L.getState().session.authToken??"",Bn=()=>L.getState().isLoggedIn(),Ln=r=>{L.getState().setAuthToken(r)},ht=()=>L.getState(),mt=p.createContext(null);function Gn({apiURL:r,autoFetch:o=!0,children:e,fetchOnMount:t=!0,onFetchSession:n,onLogin:s,onLogout:i,program:l,throttleMs:a=0}){const h=p.useRef(0),c=p.useRef(!1),u=p.useRef(!1),m=p.useCallback(async b=>{const E=Date.now(),_=E-h.current;if(!c.current&&!(a>0&&_<a))try{c.current=!0,h.current=E,await L.getState().fetchData(b)}finally{c.current=!1}},[a]),g=p.useCallback(async()=>{await m()},[m]);p.useEffect(()=>{r&&L.getState().setApiURL(r)},[r]),p.useEffect(()=>{l&&L.getState().setProgram(l)},[l]),p.useEffect(()=>{n&&L.setState({onFetchSession:n})},[n]),p.useEffect(()=>{s&&L.setState({onLogin:s})},[s]),p.useEffect(()=>{i&&L.setState({onLogout:i})},[i]),p.useEffect(()=>{u.current||(u.current=!0,o&&t&&m(r).catch(b=>{console.error("Failed to fetch on mount:",b)}))},[r,o,t,m]);const y=p.useMemo(()=>({fetchData:m,getState:ht,refetch:g}),[m,g]);return d.jsx(mt.Provider,{value:y,children:e})}function qn(){const r=p.useContext(mt);if(!r)throw new Error("useGlobalStateStoreContext must be used within GlobalStateStoreProvider");return r}function X(r){return btoa(encodeURIComponent(r).replace(/%([0-9A-F]{2})/g,(o,e)=>String.fromCharCode(Number.parseInt(e,16))))}const Vn="gridler_golang_restapi_v2_token",Hn=(r,o)=>{const e=[...r.filter(t=>t!==void 0&&t.type!==void 0)];for(let t=0;t<e.length;t++)(!e[t].name||e[t].name==="")&&(e[t].name=""),e[t].type==="files"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="advsql"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="custom-sql-or"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="custom-sql-join"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="not-select-fields"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="custom-sql-w"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="select-fields"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),e[t].type==="cql-sel"&&!e[t].value.startsWith("__")&&(e[t].value=`__${X(e[t].value)}__`),o&&((!e||e.length===0)&&o.set("x-limit","10"),e[t].type==="association_autoupdate"&&o.set("association_autoupdate",e[t].value??"1"),e[t].type==="association_autocreate"&&o.set("association_autocreate",e[t].value??"1"),e[t].type==="searchop"||e[t].type==="searchor"||e[t].type==="searchand"?o.set(encodeURIComponent(`x-${e[t].type}-${e[t].op}-${e[t].name}`),String(e[t].value)):o.set(encodeURIComponent(`x-${e[t].type}${e[t].name&&e[t].name!==""?"-"+e[t].name:""}`),String(e[t].value)));return e},re=(r,o)=>{const e=new Headers,t={},n=nt?.();if(n&&n!=="")e.set("Authorization",`Token ${n}`);else{const i=nt();i&&e.set("Authorization",`Token ${i}`)}o&&o.forEach((i,l)=>{e.set(l,i)});const s=[];for(const i of r?.filter(l=>!!l)??[]){const l=s.findIndex(a=>a.name===i.name&&a.type===i.type);l===-1?s.push(i):s[l]=i}if(Hn(s,e),e?.forEach((i,l)=>{t[l]=i}),o)for(const i of Object.keys(t))o.set(i,t[i]);return t},Wn={getAuthToken:()=>{if(localStorage){const r=localStorage.getItem(Vn);if(r)return r}}},nt=()=>Wn?.getAuthToken?.();function Kn(r,o){if(!r||!o||r.includes("..")||r.includes("[]")||/\[\s*\]/.test(r))return;const e=r.replace(/\[(\w+)\]/g,".$1").split(".").filter(Boolean);if(e.length!==0)return e.reduce((t,n)=>{if(t!=null&&typeof t=="object")return t[n]},o)}const{Provider:Un,useStore:Fe}=pe.createSyncStore((r,o)=>({hide:e=>{o().setInstanceState(e,"visible",!1)},menus:[],setInstanceState:(e,t,n)=>{r(U.produce(s=>{const i=s?.menus?.findIndex(l=>l.id===e);i>=0&&(s.menus[i][t]=n)}))},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},show:(e,t)=>{const n=o(),s=n.menus.findIndex(l=>l.id===e),i=n.menus[s]?{...n.menus[s]}:{};Object.assign(i,t),i.id=i.id??e,i.visible=!(i.visible??!1),s<0?n.setState("menus",[...n.menus,i]):r(U.produce(l=>{l.menus||(l.menus=[]),l.menus[s]={...l.menus[s],...i}}))}}),r=>({providerID:r.providerID??`MenuStore-${Te.getUUID()}`}));function Jn(){const{menus:r,providerID:o,setInstanceState:e,width:t}=Fe(n=>({menus:n.menus,providerID:n.providerID,setInstanceState:n.setInstanceState,setState:n.setState,width:n.width}));return d.jsx(w.Portal,{id:`bmm_portal_${o}`,children:p.Children.toArray(r?.map((n,s)=>p.createElement(w.Menu,{shadow:"md",width:t??"300",...n.menuProps,key:`bmm_menu_${o}_${s}`,onClose:()=>{e(n.id,"visible",!1),n.menuProps?.onClose?.()},opened:n.visible},d.jsx(w.Menu.Target,{children:d.jsx("div",{id:`bmm_${o}_${s}_target`,style:{left:n.x,position:"fixed",top:n.y,visibility:"hidden"}})}),d.jsx(w.Menu.Dropdown,{children:n.renderer?n.renderer:p.Children.toArray(n.items?.map((i,l)=>d.jsx(gt,{...i},`bmm_${o}_${s}_item${l}`)))}))))},`bmm_portal_${o}`)}const gt=({children:r,label:o,...e})=>{const[t,n]=p.useState(!1);return typeof e.renderer=="function"?e.renderer({...e,loading:t,renderer:void 0,setLoading:n}):typeof e.renderer=="object"?e.renderer:e.isDivider?d.jsx(w.Menu.Divider,{}):e.items&&e.items.length>0?d.jsxs(w.Menu.Sub,{children:[d.jsx(w.Menu.Sub.Target,{children:d.jsx(w.Menu.Sub.Item,{...e,disabled:t,onClick:s=>{e.onClick?.(s),e.onClickAsync&&(n(!0),e.onClickAsync(s).finally(()=>n(!1)))},styles:{itemLabel:{overflow:"auto",wordWrap:"break-word"},...e.styles},children:r??o})}),d.jsx(w.Menu.Sub.Dropdown,{children:p.Children.toArray(e.items.map((s,i)=>d.jsx(gt,{...s},`bmm_subitem_${s?.id??""}${i}`)))})]}):!e.onClick&&!e.onClickAsync?d.jsxs(w.Menu.Label,{...e,children:[" ",r??o]}):d.jsx(w.Menu.Item,{...e,disabled:t,onClick:s=>{e.onClick?.(s),e.onClickAsync&&(n(!0),e.onClickAsync(s).finally(()=>n(!1)))},styles:{itemLabel:{overflow:"auto",wordWrap:"break-word"},...e.styles},children:r??o})};function pt(r){return d.jsxs(Un,{...r,children:[d.jsx(Jn,{}),r.children]})}const St=[{label:"Contains",value:"contains"},{label:"Equal",value:"eq"},{label:"Not Equal",value:"neq"},{label:"Greater Than",value:"gt"},{label:"Greater Than or Equal",value:"gte"},{label:"Less Than",value:"lt"},{label:"Less Than or Equal",value:"lte"}],vt=r=>{const o=r.storeState?.colFilters?.findIndex(i=>i.id===r.column.id)??-1,e=r.storeState?.colFilters?.[o]??{id:r.column.id,value:""},[t,n]=p.useState(e?.value??""),[s]=ie.useDebouncedValue(t,900);return p.useEffect(()=>{r.storeState.setStateFN("colFilters",i=>{const l=i?.findIndex(h=>h.id===r.column.id)??-1,a=i??[];return l>=0?a[l]={...a[l],...r.options,id:r.column.id,value:s}:a.push({operator:"contains",...r.options,id:r.column.id,value:s}),a})},[s,r.column.id,r.options,r.storeState]),d.jsx(w.TextInput,{onChange:i=>n(i.target.value),rightSection:d.jsx(w.ActionIcon,{color:"gray",onClick:()=>n(""),variant:"filled",children:d.jsx(V.IconX,{color:"red"})}),value:t??e?.value})},yt=r=>{const o=r.storeState?.colFilters?.findIndex(i=>i.id===r.column.id)??-1,e=r.storeState?.colFilters?.[o]??{id:r.column.id,operator:"contains"},[t,n]=p.useState(e?.operator??"contains"),[s]=ie.useDebouncedValue(t,900);return p.useEffect(()=>{r.storeState.setStateFN("colFilters",i=>{const l=i?.findIndex(h=>h.id===r.column.id)??-1,a=i??[];return l>=0?a[l]={...a[l],...r.options,id:r.column.id,operator:s}:a.push({...r.options,id:r.column.id,operator:s,value:""}),a})},[s,r.column.id,r.options,r.storeState]),d.jsx(w.Select,{comboboxProps:{withinPortal:!1},data:St,maxDropdownHeight:150,onChange:i=>n(i),placeholder:"Operator",searchable:!0,value:t??e?.operator,withScrollArea:!0})},ke=r=>d.jsxs(w.Stack,{onClick:o=>o.stopPropagation(),children:[d.jsx(yt,{...r}),d.jsx(vt,{...r})]}),Ae=r=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
10
10
|
<path
|
|
11
11
|
fill="${r.fgColor??"currentColor"}"
|
|
12
12
|
d="M15 2.5a.5.5 0 0 0-1 0v13.793l-2.146-2.147a.5.5 0 0 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L15 16.293zM2.5 4a.5.5 0 0 0 0 1h9a.5.5 0 0 0 0-1zM5 7.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5M8.5 10a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1z"
|
|
13
13
|
></path>
|
|
14
14
|
</svg>
|
|
15
|
-
`,
|
|
15
|
+
`,je=r=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
16
16
|
<path
|
|
17
17
|
fill="${r.fgColor??"currentColor"}"
|
|
18
18
|
d="M15 17.5a.5.5 0 0 1-1 0V3.707l-2.146 2.147a.5.5 0 0 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L15 3.707zM2.5 16a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1zM5 12.5a.5.5 0 0 0 .5.5h6a.5.5 0 0 0 0-1h-6a.5.5 0 0 0-.5.5M8.5 10a.5.5 0 0 1 0-1h3a.5.5 0 0 1 0 1z"
|
|
19
19
|
></path>
|
|
20
20
|
</svg>
|
|
21
|
-
`,fe=r=>d.jsx("img",{alt:r.alt??"Sprite Image",src:`data:image/svg+xml;utf8,${r.sprite({...r,sprite:void 0})}`}),{Provider:Hn,useStore:W}=ge.createSyncStore((r,o)=>({_events:new EventTarget,_loadingList:H.CompactSelection.empty(),_page_data:{},_refresh:async()=>{const e=o();await e.loadPage(0,"all"),await e.refreshCells(),await e.reload?.()},_visibleArea:{height:1e4,width:1e3,x:0,y:0},_visiblePages:{height:0,width:0,x:0,y:0},addError:(e,...t)=>{const n=o();console.log("Gridler Error",n.uniqueid,e,t),r(U.produce(s=>{s.errors=[...s.errors,e]}))},errors:[],get:()=>o(),getCellContent:e=>{const t=o(),[n,s]=e,i=t.getRowBuffer(s);return i!==void 0?t.toCell(i,n):{allowOverlay:!1,kind:H.GridCellKind.Loading}},getCellsForSelection:(e,t)=>async()=>{const n=o();await n.setStateFN("_visibleArea",i=>e);const s=[];for(let i=e.y;i<e.y+e.height;i++){const l=[];for(let a=e.x;a<e.x+e.width;a++)l.push(n.getCellContent([a,i]));s.push(l)}return s},getGridSelectedRows:()=>{const e=o(),t=[],n=e._page_data,s=e.pageSize;if(e._gridSelectionRows)for(const i of e._gridSelectionRows){let l;for(const a in n)for(const h in n[a]){const c=Number(a)*s+Number(h);if(!isNaN(c)){if(Number(n[a][h]?._rownumber)===i+1){l=n[a][h];break}else if(c===i+1){l=n[a][h];break}}}l!==void 0&&t.push(l)}return t},getRowBuffer:e=>{const t=o();if(t.data&&t.data.length>0)return t.data[e]===void 0?{allowOverlay:!1,kind:H.GridCellKind.Loading}:t.data[e];const n=Math.max(0,Math.floor(e/t.pageSize)),s=t.pageSize*n,i=e-s;return t._page_data?.[n]?.[i]},getRowIndexByKey:async e=>{const t=o();let n=-1;if(t.ready){const s=t._page_data,i=t.pageSize,l=t.keyField??"id";for(const a in s){for(const h in s[a]){const c=Number(a)*i+Number(h);if(String(s[a][h]?.[l])===String(e)){n=s[a][h]?._rownumber>0?s[a][h]?._rownumber:c>0?c:-1;break}}if(n>0)return console.log("Local row index",n,e),n}if(n>0)return n;if(typeof t.askAPIRowNumber=="function"){const a=await t.askAPIRowNumber(String(e));if(a&&a>=0)return console.log("Remote row index",n,e),a}}},getState:e=>o()[e],hasLocalData:!1,isEmpty:!0,isValuesInPages:()=>{const e=o();if(e.values&&Object.keys(e._page_data).length>0){let t=!1;for(const n in e._page_data){const s=e._page_data[Number(n)];for(const i of s){const l=e.keyField??"id",a=i?.[l];if(a!==void 0&&e.values.find(c=>String(c?.[l])===String(a))){t=!0;break}}if(t)return!0}}return!1},keyField:"id",loadPage:async(e,t)=>{const n=o(),s=e<0?0:e;if(!n._events.dispatchEvent(new CustomEvent("before_loadPage",{detail:{clearMode:t,page:e,state:n}})))return;const l=[],a=Object.keys(n.renderColumns??[1,2,3]).length,h=n.pageSize*s,c=n._page_data?.[s]?.length>0;if(t==="all"){n._active_requests?.forEach(u=>{u.controller?.abort?.()}),n.setState("_page_data",{}),n.setState("_active_requests",[]),n.loadPage(s);return}if(!n.useAPIQuery){console.warn("No useAPIQuery function defined, cannot load page",s);return}!c&&t!=="page"&&n.useAPIQuery?.(s).then(u=>{n.setStateFN("_page_data",m=>({...m,[s]:u}));for(let m=s;m<=h+n.pageSize;m++)for(let g=0;g<=a;g++)l.push({cell:[g,m]});n._glideref?.updateCells(l),n._events.dispatchEvent(new CustomEvent("loadPage",{detail:{clearMode:t,data:u,page:e,state:n}}))}).catch(u=>{console.error("loadPage Error: ",s,u),n._events.dispatchEvent(new CustomEvent("loadPage_error",{detail:{clearMode:t,error:u,page:e,state:n}}))})},maxConcurrency:1,mounted:!1,onCellActivated:e=>{const t=o(),[n,s]=e;t._events.dispatchEvent(new CustomEvent("onCellActivated",{detail:{cell:e,col:n,row:s,state:t}})),t.glideProps?.onCellActivated?.(e)},onCellClicked:(e,t)=>{const n=o(),[s,i]=e;n.glideProps?.onCellClicked&&n.glideProps?.onCellClicked?.(e,t),n.values?.length&&n.onChange&&n.onChange(n.values),n._events.dispatchEvent(new CustomEvent("onCellClicked",{detail:{cell:e,col:s,row:i,state:n}}))},onCellEdited:(e,t)=>{const n=o(),[,s]=e;n._events.dispatchEvent(new CustomEvent("onCellEdited",{detail:{cell:e,newVal:t,row:s,state:n}})),n.glideProps?.onCellEdited?.(e,t)},onColumnMoved:(e,t)=>{const n=o(),s=n.renderColumns?.[e],i=n.renderColumns?.[t];s?.disableMove||i?.disableMove||n.setStateFN("colOrder",l=>{const a=l??n.renderColumns?.map((h,c)=>[h.id,c]).reduce((h,[c,u])=>({...h,[c]:u}),{});return!s?.id||!i?.id?a:{...a,[s?.id]:t,[i?.id]:e}})},onColumnProposeMove:(e,t)=>{const n=o(),s=n.renderColumns?.[e],i=n.renderColumns?.[t];return!(s?.disableMove||i?.disableMove)},onColumnResize:(e,t,n,s)=>{const i=o(),l=i.renderColumns?.find(a=>a.id===e.id);l?.disableResize||l?.maxWidth&&t<l?.maxWidth||l&&i.setStateFN("colSize",a=>a&&l&&a[l.id]===t?a:{...a,[l.id]:t})},onContextClick:(e,t,n,s)=>{const i=o(),l=i.renderColumns?.[n??-1],a=e==="menu"?[{leftSection:d.jsx(V.IconGrid4x4,{size:16}),title:i.title??"Grid"}]:l?[{leftSection:d.jsx(V.IconGrid4x4,{size:16}),title:i.title??"Grid"},{items:[{label:"Sort Ascending",leftSection:d.jsx(fe,{sprite:Ie}),onClick:()=>{i.setStateFN("colSort",h=>{const c=[...h??[]],u=c.findIndex(g=>g.id===l.id),m="asc";if(u<0){const g={direction:m,id:l.id,order:c?.length};c.push(g)}else u>=0&&(c[u].direction=m);return c})}},{label:"Sort Descending",leftSection:d.jsx(fe,{sprite:Oe}),onClick:()=>{i.setStateFN("colSort",h=>{const c=[...h??[]],u=c.findIndex(g=>g.id===l.id),m="desc";if(u<0){const g={direction:m,id:l.id,order:c?.length};c.push(g)}else u>=0&&(c[u].direction=m);return c})}},{label:`Filter ${l?.title??l?.id}`},{renderer:d.jsx(Re,{column:l,storeState:o()})}],label:`Column Settings for ${l?.title??l?.id}`,leftSection:d.jsx(V.IconGrid4x4,{size:16})}]:[];i.hideMenu?.(e),i.showMenu?.(e,{items:l?.getMenuItems?.(e,i,n&&s?i.getRowBuffer(s):void 0,l,a)??i.getMenuItems?.(e,i,n&&s?i.getRowBuffer(s):void 0,l,a)??a,x:t.clientX??t.bounds?.x,y:t.clientY??t.bounds?.y})},onHeaderClicked:(e,t)=>{const n=o();t.preventDefault();const s=n.renderColumns?.[e];s&&(s.disableSort||n.setStateFN("colSort",i=>{const l=[...i??[]],a=l.findIndex(h=>h.id===s.id);if(a<0){const h={direction:"asc",id:s.id,order:l?.length};l.push(h)}else a>=0&&l[a].direction==="asc"?l[a].direction="desc":a>=0&&l[a].direction==="desc"&&l.splice(a,1);return l}))},onHeaderMenuClick:(e,t)=>{const n=o(),s=n.renderColumns?.[e];if(!s)return;const i=[{label:`Sort ${s?.title??s?.id}`},{label:"Sort Ascending",leftSection:d.jsx(fe,{sprite:Ie}),onClick:()=>{n.setStateFN("colSort",a=>{const h=[...a??[]],c=h.findIndex(m=>m.id===s.id),u="asc";if(c<0){const m={direction:u,id:s.id,order:h?.length};h.push(m)}else c>=0&&(h[c].direction=u);return h})}},{label:"Sort Descending",leftSection:d.jsx(fe,{sprite:Oe}),onClick:()=>{n.setStateFN("colSort",a=>{const h=[...a??[]],c=h.findIndex(m=>m.id===s.id),u="desc";if(c<0){const m={direction:u,id:s.id,order:h?.length};h.push(m)}else c>=0&&(h[c].direction=u);return h})}},{isDivider:!0}],l=[...s.disableSort?[]:i,{label:`Filter ${s?.title??s?.id}`},{renderer:d.jsx(Re,{column:s,storeState:o()})},{isDivider:!0},{id:"refesh",label:"Refresh",onClick:()=>{o()._refresh?.()}}];n.hideMenu?.("header-menu"),n.showMenu?.("header-menu",{items:s?.getMenuItems?.("header-menu",n,void 0,s,l)??n.getMenuItems?.("header-menu",n,void 0,s,l),x:t.x,y:t.y})},onItemHovered:e=>{const t=o();if(t.setState("_activeTooltip",void 0),e.kind==="cell"){const n=t.renderColumns?.[e.location[0]];if(n?.tooltip&&typeof n?.tooltip=="string")t.setState("_activeTooltip",n?.tooltip);else if(n?.tooltip&&typeof n?.tooltip=="function"){const s=t.getRowBuffer(e.location[1]);t.setState("_activeTooltip",n?.tooltip(s,e.location[1],e.location[0]))}}},onVisibleRegionChanged:(e,t,n,s)=>{const i=o();i._scrollTimeout&&clearTimeout(i._scrollTimeout);const l=()=>{const a=o(),h=Math.max(0,Math.floor(e.y/a.pageSize)),c=Math.max(0,Math.floor(a._visiblePages.y/a.pageSize)),u=h-c;if(a.progressiveScroll&&u>1){const m=o(),g=(c+2)*m.pageSize*(m.rowHeight??22);m._glideref?.scrollTo(0,{amount:g,unit:"px"},"vertical");return}a.setState("_visiblePages",e)};i.setState("_scrollTimeout",setTimeout(()=>{l()},100))},pageSize:50,ready:!1,refreshCells:(e,t,n)=>{const s=o(),i=[],l=Object.keys(s.renderColumns??[1,2,3]).length,a=e&&e>0?e:0,h=t&&t>=a?t:a+s.pageSize;for(let c=a;c<=h;c++)if(n&&n>0)i.push({cell:[n,c]});else for(let u=0;u<=l;u++)i.push({cell:[u,c]});s._glideref?.updateCells(i)},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},setStateFN:(e,t)=>new Promise((s,i)=>{r(U.produce(l=>{if(typeof t=="function")l[e]=t(l[e]);else throw i(new Error(`Not a function ${t}`)),Error(`Not a function ${t}`)})),s()}),toCell:(e,t)=>{const n=o(),i=n.renderColumns?.[t],l=i?.id??i?.title??String(t);if(l==null||e===void 0||e===null)return i?.Cell?i?.Cell(e,t,l,void 0,n):n.RenderCell?n.RenderCell(e,t,l,void 0,n):{allowOverlay:!1,kind:H.GridCellKind.Loading};try{const a=String(l).includes(".")?Gn(l,e)??"":e?.[l];return i?.Cell?{kind:H.GridCellKind.Text,...i?.Cell(e,t,l,a,n)}:n.RenderCell?n.RenderCell(e,t,l,a,n):{allowOverlay:!0,data:a??"",displayData:String(a??""),kind:H.GridCellKind.Text}}catch{return n.RenderCell?n.RenderCell(e,t,l,e?.[l??""],n):{allowOverlay:!1,kind:H.GridCellKind.Loading,skeletonWidthVariability:50}}},total_rows:1e3,uniqueid:ke.getUUID()}),r=>{const[o,e]=r.useStore(n=>[n.setState,n.getState]),t=Ae();return p.useEffect(()=>{const n=e("onMounted");if(typeof n=="function"&&n(e,o),o("mounted",!0),window&&window.document&&!window.document.getElementById("portal")){const i=window.document.createElement("div");i.id="portal",i.setAttribute("data-gridler-portal",r.uniqueid),window.document.body.appendChild(i)}return e("_events").dispatchEvent(new CustomEvent("mounted",{detail:{}})),()=>{const s=e("onUnMounted");o("mounted",!1),e("_events").dispatchEvent(new CustomEvent("unmounted",{detail:{}})),typeof s=="function"&&s()}},[o,e]),e("_events").addEventListener("reload",n=>{e("_refresh")?.()}),{...r,colSort:r.defaultSort??e("colSort")??[],hideMenu:r.hideMenu??t.hide,scrollToRowKey:r.scrollToRowKey??r.selectedRowKey??e("scrollToRowKey"),showMenu:r.showMenu??t.show,total_rows:e("total_rows")??r.total_rows}});function Wn(r){const[o,e,t,n,s]=W(a=>[a.setStateFN,a.setState,a.getState,a.addError,a.mounted]),i=p.useCallback(async a=>{const h=t("columns"),c=t("colSort"),u=t("pageSize"),m=t("colFilters"),g=t("searchStr"),b=t("searchFields"),y=t("_active_requests"),_=t("keyField");e("loadingData",!0);try{if(r&&r.url){const E=new Headers;E.set("Authorization",`Token ${r.authtoken}`);const R=[{type:"limit",value:String(u??50)},{type:"offset",value:String((u??50)*a)}];c?.length&&c.length>0&&R.push({type:"sort",value:c?.map(S=>`${S.id} ${S.direction}`).reduce((S,O)=>`${S},${O}`)}),m?.filter(S=>S.value?.length>0)?.forEach(S=>{S.value&&S.value!==""&&R.push({name:`${S.id}`,op:S.operator,type:"searchop",value:S.value})}),g&&g!==""&&h?.filter(S=>!S.disableFilter&&!S.disableSearch&&!S.virtual&&S.id&&((b??[]).length==0||b?.includes(S.id)))?.forEach(S=>{R.push({name:`${S.id??""}`,op:"contains",type:"searchor",value:g})}),r.filter&&r.filter!==""&&R.push({name:"sql_filter",type:"custom-sql-w",value:r.filter}),(r.options??[]).length>0&&R.push(...r.options??[]);const k=h?.filter(S=>!S.virtual)?.map(S=>S.id)??[];if(r.hotfields&&r.hotfields.length>0&&k?.push(r.hotfields.join(",")),_&&(k.includes(_)||k.push(_)),k&&k.length>0&&R.push({type:"select-fields",value:k.join(",")}),R&&R.length>0){const S=re(R);for(const O in re(R))E.set(O,S[O])}const I=y?.findIndex(S=>S.page===a)??-1;if(y?.forEach(S=>{(S.page>=0&&S.page<a-2||a>=0&&S.page>a+2)&&S.controller?.abort?.()}),y&&I>=0&&y[I]){e("loadingData",!1);return}const N=new AbortController;await o("_active_requests",S=>[...S??[],{controller:N,page:a}]);const x=await fetch(`${r.url}?x-limit=${String(u??50)}&x-offset=${String((u??50)*a)}`,{headers:E,method:"GET",signal:N?.signal});if(x.ok){const S=x.headers.get("Content-Range")?.split("/");S?.[1]&&parseInt(S[1],10)>0&&e("total_rows",parseInt(S[1],10));const O=await x.json();return e("loadingData",!1),O??[]}n(`${x.status} ${x.statusText}`,"api",r.url),await o("_active_requests",S=>[...(S??[]).filter(O=>O.page!==a)])}}catch{}return e("loadingData",!1),[]},[t,r.authtoken,r.url,r.filter,JSON.stringify(r.options),e,o,n]),l=p.useCallback(async a=>{const h=t("colFilters");if(r&&r.url){const c=new Headers,u=[{type:"limit",value:String(10)},{type:"fetch-rownumber",value:a}];if(c.set("Authorization",`Token ${r.authtoken}`),h?.length&&h.length>0&&h?.filter(b=>b.value?.length>0)?.forEach(b=>{b.value&&b.value!==""&&c.set(`x-searchop-${b.operator}-${b.id}`,`${b.value}`)}),r.filter&&r.filter!==""&&u.push({name:"sql_filter",type:"custom-sql-w",value:`(${r.filter})`}),r.options&&r.options.length>0){const b=re(r.options);for(const y in b)c.set(y,b[y])}if(u&&u.length>0){const b=re(u);for(const y in re(u))c.set(y,b[y])}const m=new AbortController,g=await fetch(`${r.url}?x-fetch-rownumber=${a}}`,{headers:c,method:"GET",signal:m?.signal});if(g.ok){const b=await g.json();return b?.[0]?._rownumber??b?._rownumber??0}n(`${g.status} ${g.statusText}`,"api",r.url)}return[]},[r.url,r.authtoken,r.filter,r.options,t,n]);return p.useEffect(()=>{e("useAPIQuery",i),e("askAPIRowNumber",l);const a=t("isValuesInPages"),h=t("_refresh");a||e("values",[]),h?.().then(()=>{const c=t("onChange"),u=t("getGridSelectedRows");if(c&&typeof c=="function"){const m=u?.();c(m)}})},[r.url,r.authtoken,r.filter,JSON.stringify(r.options),s,e]),d.jsx(d.Fragment,{})}const pt=p.memo(Wn);pt.displayName="Gridler-GlidlerAPIAdaptorForGoLangv2";function St(r){const[o,e,t,n]=W(i=>[i.getState,i.mounted,i.setState,i._events]);p.useEffect(()=>{if(e&&r.changeOnActiveClick){const i=l=>{const{row:a,state:h}=l.detail,c=h.getRowBuffer;if(c){const u=c(a);if(!u)return;r.onRequestForm("change",u)}};return n?.addEventListener("onCellActivated",i),()=>{i&&n?.removeEventListener("onCellActivated",i)}}},[r.changeOnActiveClick,e,n]);const s=p.useCallback((i,l,a,h,c)=>{if(i==="header-menu")return c||[];const u=[];u.push(...c);const m=o("_gridSelection")?.rows.toArray()??[],g=m.length>1;if(!a){const _=m[0];_!==void 0&&(a=l.getRowBuffer(_))}const b=typeof r.descriptionField=="string"?a?.[r.descriptionField]:typeof r.descriptionField=="function"&&a?r.descriptionField(a):void 0;i==="other"&&u.push({c:"blue",label:"Add",onClick:()=>{r.onRequestForm("insert",a)}}),i==="cell"&&a||i==="menu"&&a?(u.push({c:"teal",label:"Add",leftSection:d.jsx(V.IconSquarePlus,{color:"teal",size:16}),onClick:()=>{r.onRequestForm("insert",a)}}),g?(u.push({c:"green",label:`Modify All Selected (${m.length})`,leftSection:d.jsx(V.IconEdit,{color:"green",size:16}),onClick:()=>{r.onRequestForm("change",m.map(_=>l.getRowBuffer(_)))}}),u.push({c:"red",label:`Remove All Selected (${m.length})`,leftSection:d.jsx(V.IconTrashX,{color:"maroon",size:16}),onClick:()=>{r.onRequestForm("delete",m.map(_=>l.getRowBuffer(_)))}})):(u.push({c:"green",label:`Modify${b&&r.showDescriptionInMenu?` (${b})`:""}`,leftSection:d.jsx(V.IconEdit,{color:"green",size:16}),onClick:()=>{r.onRequestForm("change",a)}}),u.push({c:"red",label:`Remove${b&&r.showDescriptionInMenu?` (${b})`:""}`,leftSection:d.jsx(V.IconTrashX,{color:"maroon",size:16}),onClick:()=>{r.onRequestForm("delete",a)}})),u.push({isDivider:!0})):(i==="cell"&&!a||i==="menu"&&!a)&&u.push({c:"red",label:"Nothing Selected",leftSection:d.jsx(V.IconExclamationMark,{color:"yellow",size:16})}),u.push({c:"orange",label:"Refresh",leftSection:d.jsx(V.IconRefresh,{color:"orange",size:16}),onClickAsync:async()=>{await o("_refresh")?.()}});const y=r.getMenuItems?r.getMenuItems(i,l,a,h,u):u;return!u||u.length===0?c||[]:y},[r.onRequestForm,o]);return p.useEffect(()=>(e&&typeof t=="function"&&o("getMenuItems")!==s&&t("getMenuItems",s),()=>{}),[r.getMenuItems,e]),d.jsx(d.Fragment,{})}function Kn(r){const[o,e,t]=W(c=>[c.setState,c.getState,c.mounted]),{colFilters:n,colSort:s,columns:i,searchStr:l}=W(c=>({colFilters:c.colFilters,colOrder:c.colOrder,colSize:c.colSize,colSort:c.colSort,columns:c.columns,searchStr:c.searchStr})),a=p.useRef({colFilters:n,colSort:s,searchStr:l}),h=async c=>{const u=e("pageSize");return r.data&&Array.isArray(r.data)?(o("total_rows",r.data.length),r.data.slice(c*(u??50),(c+1)*(u??50))):[]};return p.useEffect(()=>{o("useAPIQuery",h)},[t,o]),p.useEffect(()=>{if(r.onColumnSort&&s!==a?.current?.colSort){const c=r.onColumnSort(s,i,r.data);o("total_rows",c.length),o("data",c),a.current.colSort=s,e("refreshCells")?.()}},[s,r.onColumnSort]),p.useEffect(()=>{if(r.onColumnFilter&&n!==a?.current?.colFilters){const c=r.onColumnFilter(n,i,r.data);o("total_rows",c.length),o("data",c),a.current.colFilters=n,e("refreshCells")?.()}},[n,r.onColumnFilter]),p.useEffect(()=>{if(r.onSearch&&l!==a?.current?.searchStr){const c=r.onSearch(l,i,r.data);o("total_rows",c.length),o("data",c),a.current.colFilters=n,e("refreshCells")?.()}},[l,r.onSearch]),d.jsx(d.Fragment,{})}const je=p.memo(Kn);je.displayName="Gridler-GlidlerLocalDataAdaptor";function vt(){const{loadingData:r,onContextClick:o}=W(e=>({loadingData:e.loadingData,onContextClick:e.onContextClick}));return d.jsx(w.ActionIcon,{loading:r,mr:"xs",mt:"2px",onClick:e=>o("menu",e),variant:"subtle",children:d.jsx(V.IconMenu2,{})})}function Un(r,o){const[e,t]=W(n=>[n.setStateFN,n.getState]);return p.useImperativeHandle(o,()=>({getGlideRef:()=>t("_glideref"),getState:t,isEmpty:()=>t("isEmpty"),refresh:async n=>{const s=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{s?.()})},reload:async n=>{const s=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{s?.()})},reloadRow:async n=>{const s=t("refreshCells"),l=await t("getRowIndexByKey")?.(String(n));l&&l>=0&&s?.(l,l+1)},scrollToRow:async n=>{n&&Number(n)>=0&&e("scrollToRowKey",s=>Number(n??s))},selectRow:async n=>{n&&Number(n)>=0&&e("selectedRowKey",s=>Number(n??s))},setStateFN:e}),[]),d.jsx(d.Fragment,{children:r.children})}const Jn=p.forwardRef(Un);function Yn(){const{_activeTooltip:r,tooltipBarProps:o}=W(e=>({_activeTooltip:e._activeTooltip,tooltipBarProps:e.tooltipBarProps}));return d.jsx("div",{"data-tooltip-bar":!0,style:{minHeight:"24px"},...o,children:r})}const yt=p.memo(()=>{const r=p.useRef(0),o=p.useRef(""),e=p.useRef(null),{_glideref:t,_gridSelectionRows:n,colFilters:s,colOrder:i,colSize:l,colSort:a,columns:h,getRowIndexByKey:c,getState:u,loadPage:m,ready:g,scrollToRowKey:b,searchStr:y,selectedRowKey:_,selectFirstRowOnMount:E,setState:R,setStateFN:k,values:I}=W(x=>({_glideref:x._glideref,_gridSelectionRows:x._gridSelectionRows,colFilters:x.colFilters,colOrder:x.colOrder,colSize:x.colSize,colSort:x.colSort,columns:x.columns,getRowIndexByKey:x.getRowIndexByKey,getState:x.getState,loadPage:x.loadPage,ready:x.ready,scrollToRowKey:x.scrollToRowKey,searchStr:x.searchStr,selectedRowKey:x.selectedRowKey,selectFirstRowOnMount:x.selectFirstRowOnMount,setState:x.setState,setStateFN:x.setStateFN,uniqueid:x.uniqueid,values:x.values})),N=ie.useDebouncedCallback(x=>{m(0,"all").then(()=>{u("refreshCells")?.(),u("_events")?.dispatchEvent?.(new CustomEvent("onSearched",{detail:{search:x}}))})},{delay:300,leading:!1});return p.useEffect(()=>{I&&(async()=>{const S=u("_page_data"),O=u("pageSize"),$=u("keyField")??"id",B=[];for(const F in I){let P=-1;const T=String(typeof I?.[F]=="object"?I?.[F]?.[$]:typeof I?.[F]=="string"?I?.[F]:void 0);for(const G in S){for(const q in S[G]){const j=Number(G)*O+Number(q);if(String(S[G][q]?.[$])===T){P=j;break}}if(P>=0){B.push(P);break}}if(!(P>=0)){const G=await c(T);G&&B.push(G)}}return B})().then(S=>{let O=H.CompactSelection.empty();S.forEach($=>{O=O.add($)}),k("_gridSelectionRows",()=>O),k("_gridSelection",$=>({columns:$?.columns??H.CompactSelection.empty(),...$,rows:O}))})},[I]),p.useEffect(()=>{const x=u("onChange");if(x&&typeof x=="function"){const O=u("getGridSelectedRows")(),$=u("values");JSON.stringify($)!==JSON.stringify(O)&&x(O)}},[n,n?.length,u]),p.useEffect(()=>{R("renderColumns",h?.map(x=>({...x,hasMenu:x?.hasMenu??!0,icon:"sort"})))},[h]),p.useEffect(()=>{if(y==null){o.current="";return}o.current!==y&&(N(y),o.current=y)},[y]),p.useEffect(()=>{a&&(R("_gridSelection",{columns:H.CompactSelection.empty(),current:void 0,rows:H.CompactSelection.empty()}),R("_gridSelectionRows",H.CompactSelection.empty()),k("renderColumns",x=>x?.map(S=>({...S,icon:S.id&&a?.find(O=>O.id===S.id)?.direction?a?.find(O=>O.id===S.id)?.direction==="asc"?"sortup":"sortdown":S.defaultIcon??"sort"}))).then(()=>{m(0,"all").then(()=>{u("refreshCells")?.(),u("_events")?.dispatchEvent?.(new CustomEvent("onColumnSorted",{detail:{cols:a}}))})}))},[a]),p.useEffect(()=>{s&&JSON.stringify(e.current)!==JSON.stringify(s)&&(m(0,"all").then(()=>{u("refreshCells")?.(),u("_events")?.dispatchEvent?.(new CustomEvent("onColumnFiltered",{detail:{filters:s}}))}),e.current=s)},[s]),p.useEffect(()=>{l&&k("renderColumns",x=>x?.map(S=>({...S,width:S.id&&l?.[S.id]?l?.[S.id]:S.width}))).then(()=>{u("refreshCells")?.()})},[l]),p.useEffect(()=>{i&&k("renderColumns",x=>x?.sort((O,$)=>i[O.id]>i[$.id]?1:-1)).then(()=>{u("refreshCells")?.()})},[i]),p.useEffect(()=>{t&&(r.current>0||(r.current=1,m(0).then(()=>{u("refreshCells")?.()})))},[g,m]),p.useEffect(()=>{const x=u("_events"),S=()=>{const O=u("selectFirstRowOnMount");if(u("ready")&&O){const B=u("scrollToRowKey");if(B&&B>=0)return;const F=u("keyField")??"id",T=u("_page_data")?.[0]?.[0],G=T?.[F]??-1,q=u("values")??[];if(!(I&&I.length>0)&&G&&G>0&&(q.length??0)===0){const j=[T,...q],J=u("onChange");J?J(j):R("values",j),R("scrollToRowKey",G)}}};return x?.addEventListener("loadPage",S),()=>{x?.removeEventListener("loadPage",S)}},[g,E]),p.useEffect(()=>{const x=u("ready"),S=u("_glideref"),O=u("getRowIndexByKey"),$=_??b;$&&S&&x&&O?.($).then(B=>{if(B!==void 0){if(_){const F=u("onChange"),P=[{[u("keyField")??"id"]:_}];JSON.stringify(u("values"))!==JSON.stringify(P)&&(F?F(P):R("values",P))}S.scrollTo(0,B),u("_events").dispatchEvent(new CustomEvent("scrollToRowKeyFound",{detail:{rowNumber:B,scrollToRowKey:b,selectedRowKey:_}}))}})},[b,_]),d.jsx(d.Fragment,{})});yt.displayName="Gridler-Computer";function Xn(r,o,e=1){let t;if(o===void 0?(t=0,o=r):t=r,e===0)throw new Error("Step cannot be zero");const n=[];if(e>0)for(let s=t;s<o;s+=e)n.push(s);else for(let s=t;s>o;s+=e)n.push(s);return n}const bt=p.memo(()=>{const[r,o,e,t,n,s,i,l]=W(a=>[a.setState,a.getState,a._glideref,a._visiblePages,a.pageSize,a.loadPage,a._loadingList,a.hasLocalData]);return p.useEffect(()=>{e&&r("mounted",!0)},[r]),p.useEffect(()=>{if(!e)return;const a=Math.max(0,Math.floor(t.y/n)),h=Math.floor((t.y+t.height)/n);for(const c of Xn(a,h+1,1))s(c).then(()=>{const u=o("_page_data")?.[0]??{};r("isEmpty",u&&u.length>0)})},[s,n,t,e,i,l]),d.jsx(d.Fragment,{})});bt.displayName="Gridler-Pager";const Qn=r=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
21
|
+
`,fe=r=>d.jsx("img",{alt:r.alt??"Sprite Image",src:`data:image/svg+xml;utf8,${r.sprite({...r,sprite:void 0})}`}),{Provider:Yn,useStore:W}=pe.createSyncStore((r,o)=>({_events:new EventTarget,_loadingList:H.CompactSelection.empty(),_page_data:{},_refresh:async()=>{const e=o();await e.loadPage(0,"all"),await e.refreshCells(),await e.reload?.()},_visibleArea:{height:1e4,width:1e3,x:0,y:0},_visiblePages:{height:0,width:0,x:0,y:0},addError:(e,...t)=>{const n=o();console.log("Gridler Error",n.uniqueid,e,t),r(U.produce(s=>{s.errors=[...s.errors,e]}))},errors:[],get:()=>o(),getCellContent:e=>{const t=o(),[n,s]=e,i=t.getRowBuffer(s);return i!==void 0?t.toCell(i,n):{allowOverlay:!1,kind:H.GridCellKind.Loading}},getCellsForSelection:(e,t)=>async()=>{const n=o();await n.setStateFN("_visibleArea",i=>e);const s=[];for(let i=e.y;i<e.y+e.height;i++){const l=[];for(let a=e.x;a<e.x+e.width;a++)l.push(n.getCellContent([a,i]));s.push(l)}return s},getGridSelectedRows:()=>{const e=o(),t=[],n=e._page_data,s=e.pageSize;if(e._gridSelectionRows)for(const i of e._gridSelectionRows){let l;for(const a in n)for(const h in n[a]){const c=Number(a)*s+Number(h);if(!isNaN(c)){if(Number(n[a][h]?._rownumber)===i+1){l=n[a][h];break}else if(c===i+1){l=n[a][h];break}}}l!==void 0&&t.push(l)}return t},getRowBuffer:e=>{const t=o();if(t.data&&t.data.length>0)return t.data[e]===void 0?{allowOverlay:!1,kind:H.GridCellKind.Loading}:t.data[e];const n=Math.max(0,Math.floor(e/t.pageSize)),s=t.pageSize*n,i=e-s;return t._page_data?.[n]?.[i]},getRowIndexByKey:async e=>{const t=o();let n=-1;if(t.ready){const s=t._page_data,i=t.pageSize,l=t.keyField??"id";for(const a in s){for(const h in s[a]){const c=Number(a)*i+Number(h);if(String(s[a][h]?.[l])===String(e)){n=s[a][h]?._rownumber>0?s[a][h]?._rownumber:c>0?c:-1;break}}if(n>0)return console.log("Local row index",n,e),n}if(n>0)return n;if(typeof t.askAPIRowNumber=="function"){const a=await t.askAPIRowNumber(String(e));if(a&&a>=0)return console.log("Remote row index",n,e),a}}},getState:e=>o()[e],hasLocalData:!1,isEmpty:!0,isValuesInPages:()=>{const e=o();if(e.values&&Object.keys(e._page_data).length>0){let t=!1;for(const n in e._page_data){const s=e._page_data[Number(n)];for(const i of s){const l=e.keyField??"id",a=i?.[l];if(a!==void 0&&e.values.find(c=>String(c?.[l])===String(a))){t=!0;break}}if(t)return!0}}return!1},keyField:"id",loadPage:async(e,t)=>{const n=o(),s=e<0?0:e;if(!n._events.dispatchEvent(new CustomEvent("before_loadPage",{detail:{clearMode:t,page:e,state:n}})))return;const l=[],a=Object.keys(n.renderColumns??[1,2,3]).length,h=n.pageSize*s,c=n._page_data?.[s]?.length>0;if(t==="all"){n._active_requests?.forEach(u=>{u.controller?.abort?.()}),n.setState("_page_data",{}),n.setState("_active_requests",[]),n.loadPage(s);return}if(!n.useAPIQuery){console.warn("No useAPIQuery function defined, cannot load page",s);return}!c&&t!=="page"&&n.useAPIQuery?.(s).then(u=>{n.setStateFN("_page_data",m=>({...m,[s]:u}));for(let m=s;m<=h+n.pageSize;m++)for(let g=0;g<=a;g++)l.push({cell:[g,m]});n._glideref?.updateCells(l),n._events.dispatchEvent(new CustomEvent("loadPage",{detail:{clearMode:t,data:u,page:e,state:n}}))}).catch(u=>{console.error("loadPage Error: ",s,u),n._events.dispatchEvent(new CustomEvent("loadPage_error",{detail:{clearMode:t,error:u,page:e,state:n}}))})},maxConcurrency:1,mounted:!1,onCellActivated:e=>{const t=o(),[n,s]=e;t._events.dispatchEvent(new CustomEvent("onCellActivated",{detail:{cell:e,col:n,row:s,state:t}})),t.glideProps?.onCellActivated?.(e)},onCellClicked:(e,t)=>{const n=o(),[s,i]=e;n.glideProps?.onCellClicked&&n.glideProps?.onCellClicked?.(e,t),n.values?.length&&n.onChange&&n.onChange(n.values),n._events.dispatchEvent(new CustomEvent("onCellClicked",{detail:{cell:e,col:s,row:i,state:n}}))},onCellEdited:(e,t)=>{const n=o(),[,s]=e;n._events.dispatchEvent(new CustomEvent("onCellEdited",{detail:{cell:e,newVal:t,row:s,state:n}})),n.glideProps?.onCellEdited?.(e,t)},onColumnMoved:(e,t)=>{const n=o(),s=n.renderColumns?.[e],i=n.renderColumns?.[t];s?.disableMove||i?.disableMove||n.setStateFN("colOrder",l=>{const a=l??n.renderColumns?.map((h,c)=>[h.id,c]).reduce((h,[c,u])=>({...h,[c]:u}),{});return!s?.id||!i?.id?a:{...a,[s?.id]:t,[i?.id]:e}})},onColumnProposeMove:(e,t)=>{const n=o(),s=n.renderColumns?.[e],i=n.renderColumns?.[t];return!(s?.disableMove||i?.disableMove)},onColumnResize:(e,t,n,s)=>{const i=o(),l=i.renderColumns?.find(a=>a.id===e.id);l?.disableResize||l?.maxWidth&&t<l?.maxWidth||l&&i.setStateFN("colSize",a=>a&&l&&a[l.id]===t?a:{...a,[l.id]:t})},onContextClick:(e,t,n,s)=>{const i=o(),l=i.renderColumns?.[n??-1],a=e==="menu"?[{leftSection:d.jsx(V.IconGrid4x4,{size:16}),title:i.title??"Grid"}]:l?[{leftSection:d.jsx(V.IconGrid4x4,{size:16}),title:i.title??"Grid"},{items:[{label:"Sort Ascending",leftSection:d.jsx(fe,{sprite:je}),onClick:()=>{i.setStateFN("colSort",h=>{const c=[...h??[]],u=c.findIndex(g=>g.id===l.id),m="asc";if(u<0){const g={direction:m,id:l.id,order:c?.length};c.push(g)}else u>=0&&(c[u].direction=m);return c})}},{label:"Sort Descending",leftSection:d.jsx(fe,{sprite:Ae}),onClick:()=>{i.setStateFN("colSort",h=>{const c=[...h??[]],u=c.findIndex(g=>g.id===l.id),m="desc";if(u<0){const g={direction:m,id:l.id,order:c?.length};c.push(g)}else u>=0&&(c[u].direction=m);return c})}},{label:`Filter ${l?.title??l?.id}`},{renderer:d.jsx(ke,{column:l,storeState:o()})}],label:`Column Settings for ${l?.title??l?.id}`,leftSection:d.jsx(V.IconGrid4x4,{size:16})}]:[];i.hideMenu?.(e),i.showMenu?.(e,{items:l?.getMenuItems?.(e,i,n&&s?i.getRowBuffer(s):void 0,l,a)??i.getMenuItems?.(e,i,n&&s?i.getRowBuffer(s):void 0,l,a)??a,x:t.clientX??t.bounds?.x,y:t.clientY??t.bounds?.y})},onHeaderClicked:(e,t)=>{const n=o();t.preventDefault();const s=n.renderColumns?.[e];s&&(s.disableSort||n.setStateFN("colSort",i=>{const l=[...i??[]],a=l.findIndex(h=>h.id===s.id);if(a<0){const h={direction:"asc",id:s.id,order:l?.length};l.push(h)}else a>=0&&l[a].direction==="asc"?l[a].direction="desc":a>=0&&l[a].direction==="desc"&&l.splice(a,1);return l}))},onHeaderMenuClick:(e,t)=>{const n=o(),s=n.renderColumns?.[e];if(!s)return;const i=[{label:`Sort ${s?.title??s?.id}`},{label:"Sort Ascending",leftSection:d.jsx(fe,{sprite:je}),onClick:()=>{n.setStateFN("colSort",a=>{const h=[...a??[]],c=h.findIndex(m=>m.id===s.id),u="asc";if(c<0){const m={direction:u,id:s.id,order:h?.length};h.push(m)}else c>=0&&(h[c].direction=u);return h})}},{label:"Sort Descending",leftSection:d.jsx(fe,{sprite:Ae}),onClick:()=>{n.setStateFN("colSort",a=>{const h=[...a??[]],c=h.findIndex(m=>m.id===s.id),u="desc";if(c<0){const m={direction:u,id:s.id,order:h?.length};h.push(m)}else c>=0&&(h[c].direction=u);return h})}},{isDivider:!0}],l=[...s.disableSort?[]:i,{label:`Filter ${s?.title??s?.id}`},{renderer:d.jsx(ke,{column:s,storeState:o()})},{isDivider:!0},{id:"refesh",label:"Refresh",onClick:()=>{o()._refresh?.()}}];n.hideMenu?.("header-menu"),n.showMenu?.("header-menu",{items:s?.getMenuItems?.("header-menu",n,void 0,s,l)??n.getMenuItems?.("header-menu",n,void 0,s,l),x:t.x,y:t.y})},onItemHovered:e=>{const t=o();if(t.setState("_activeTooltip",void 0),e.kind==="cell"){const n=t.renderColumns?.[e.location[0]];if(n?.tooltip&&typeof n?.tooltip=="string")t.setState("_activeTooltip",n?.tooltip);else if(n?.tooltip&&typeof n?.tooltip=="function"){const s=t.getRowBuffer(e.location[1]);t.setState("_activeTooltip",n?.tooltip(s,e.location[1],e.location[0]))}}},onVisibleRegionChanged:(e,t,n,s)=>{const i=o();i._scrollTimeout&&clearTimeout(i._scrollTimeout);const l=()=>{const a=o(),h=Math.max(0,Math.floor(e.y/a.pageSize)),c=Math.max(0,Math.floor(a._visiblePages.y/a.pageSize)),u=h-c;if(a.progressiveScroll&&u>1){const m=o(),g=(c+2)*m.pageSize*(m.rowHeight??22);m._glideref?.scrollTo(0,{amount:g,unit:"px"},"vertical");return}a.setState("_visiblePages",e)};i.setState("_scrollTimeout",setTimeout(()=>{l()},100))},pageSize:50,ready:!1,refreshCells:(e,t,n)=>{const s=o(),i=[],l=Object.keys(s.renderColumns??[1,2,3]).length,a=e&&e>0?e:0,h=t&&t>=a?t:a+s.pageSize;for(let c=a;c<=h;c++)if(n&&n>0)i.push({cell:[n,c]});else for(let u=0;u<=l;u++)i.push({cell:[u,c]});s._glideref?.updateCells(i)},setState:(e,t)=>{r(U.produce(n=>{n[e]=t}))},setStateFN:(e,t)=>new Promise((s,i)=>{r(U.produce(l=>{if(typeof t=="function")l[e]=t(l[e]);else throw i(new Error(`Not a function ${t}`)),Error(`Not a function ${t}`)})),s()}),toCell:(e,t)=>{const n=o(),i=n.renderColumns?.[t],l=i?.id??i?.title??String(t);if(l==null||e===void 0||e===null)return i?.Cell?i?.Cell(e,t,l,void 0,n):n.RenderCell?n.RenderCell(e,t,l,void 0,n):{allowOverlay:!1,kind:H.GridCellKind.Loading};try{const a=String(l).includes(".")?Kn(l,e)??"":e?.[l];return i?.Cell?{kind:H.GridCellKind.Text,...i?.Cell(e,t,l,a,n)}:n.RenderCell?n.RenderCell(e,t,l,a,n):{allowOverlay:!0,data:a??"",displayData:String(a??""),kind:H.GridCellKind.Text}}catch{return n.RenderCell?n.RenderCell(e,t,l,e?.[l??""],n):{allowOverlay:!1,kind:H.GridCellKind.Loading,skeletonWidthVariability:50}}},total_rows:1e3,uniqueid:Te.getUUID()}),r=>{const[o,e]=r.useStore(n=>[n.setState,n.getState]),t=Fe();return p.useEffect(()=>{const n=e("onMounted");if(typeof n=="function"&&n(e,o),o("mounted",!0),window&&window.document&&!window.document.getElementById("portal")){const i=window.document.createElement("div");i.id="portal",i.setAttribute("data-gridler-portal",r.uniqueid),window.document.body.appendChild(i)}return e("_events").dispatchEvent(new CustomEvent("mounted",{detail:{}})),()=>{const s=e("onUnMounted");o("mounted",!1),e("_events").dispatchEvent(new CustomEvent("unmounted",{detail:{}})),typeof s=="function"&&s()}},[o,e]),e("_events").addEventListener("reload",n=>{e("_refresh")?.()}),{...r,colSort:r.defaultSort??e("colSort")??[],hideMenu:r.hideMenu??t.hide,scrollToRowKey:r.scrollToRowKey??r.selectedRowKey??e("scrollToRowKey"),showMenu:r.showMenu??t.show,total_rows:e("total_rows")??r.total_rows}});function Xn(r){const[o,e,t,n,s]=W(a=>[a.setStateFN,a.setState,a.getState,a.addError,a.mounted]),i=p.useCallback(async a=>{const h=t("columns"),c=t("colSort"),u=t("pageSize"),m=t("colFilters"),g=t("searchStr"),y=t("searchFields"),b=t("_active_requests"),E=t("keyField");e("loadingData",!0);try{if(r&&r.url){const _=new Headers;_.set("Authorization",`Token ${r.authtoken}`);const R=[{type:"limit",value:String(u??50)},{type:"offset",value:String((u??50)*a)}];c?.length&&c.length>0&&R.push({type:"sort",value:c?.map(S=>`${S.id} ${S.direction}`).reduce((S,O)=>`${S},${O}`)}),m?.filter(S=>S.value?.length>0)?.forEach(S=>{S.value&&S.value!==""&&R.push({name:`${S.id}`,op:S.operator,type:"searchop",value:S.value})}),g&&g!==""&&h?.filter(S=>!S.disableFilter&&!S.disableSearch&&!S.virtual&&S.id&&((y??[]).length==0||y?.includes(S.id)))?.forEach(S=>{R.push({name:`${S.id??""}`,op:"contains",type:"searchor",value:g})}),r.filter&&r.filter!==""&&R.push({name:"sql_filter",type:"custom-sql-w",value:r.filter}),(r.options??[]).length>0&&R.push(...r.options??[]);const k=h?.filter(S=>!S.virtual)?.map(S=>S.id)??[];if(r.hotfields&&r.hotfields.length>0&&k?.push(r.hotfields.join(",")),E&&(k.includes(E)||k.push(E)),k&&k.length>0&&R.push({type:"select-fields",value:k.join(",")}),R&&R.length>0){const S=re(R);for(const O in re(R))_.set(O,S[O])}const I=b?.findIndex(S=>S.page===a)??-1;if(b?.forEach(S=>{(S.page>=0&&S.page<a-2||a>=0&&S.page>a+2)&&S.controller?.abort?.()}),b&&I>=0&&b[I]){e("loadingData",!1);return}const N=new AbortController;await o("_active_requests",S=>[...S??[],{controller:N,page:a}]);const x=await fetch(`${r.url}?x-limit=${String(u??50)}&x-offset=${String((u??50)*a)}`,{headers:_,method:"GET",signal:N?.signal});if(x.ok){const S=x.headers.get("Content-Range")?.split("/");S?.[1]&&parseInt(S[1],10)>0&&e("total_rows",parseInt(S[1],10));const O=await x.json();return e("loadingData",!1),O??[]}n(`${x.status} ${x.statusText}`,"api",r.url),await o("_active_requests",S=>[...(S??[]).filter(O=>O.page!==a)])}}catch{}return e("loadingData",!1),[]},[t,r.authtoken,r.url,r.filter,JSON.stringify(r.options),e,o,n]),l=p.useCallback(async a=>{const h=t("colFilters");if(r&&r.url){const c=new Headers,u=[{type:"limit",value:String(10)},{type:"fetch-rownumber",value:a}];if(c.set("Authorization",`Token ${r.authtoken}`),h?.length&&h.length>0&&h?.filter(y=>y.value?.length>0)?.forEach(y=>{y.value&&y.value!==""&&c.set(`x-searchop-${y.operator}-${y.id}`,`${y.value}`)}),r.filter&&r.filter!==""&&u.push({name:"sql_filter",type:"custom-sql-w",value:`(${r.filter})`}),r.options&&r.options.length>0){const y=re(r.options);for(const b in y)c.set(b,y[b])}if(u&&u.length>0){const y=re(u);for(const b in re(u))c.set(b,y[b])}const m=new AbortController,g=await fetch(`${r.url}?x-fetch-rownumber=${a}}`,{headers:c,method:"GET",signal:m?.signal});if(g.ok){const y=await g.json();return y?.[0]?._rownumber??y?._rownumber??0}n(`${g.status} ${g.statusText}`,"api",r.url)}return[]},[r.url,r.authtoken,r.filter,r.options,t,n]);return p.useEffect(()=>{e("useAPIQuery",i),e("askAPIRowNumber",l);const a=t("isValuesInPages"),h=t("_refresh");a||e("values",[]),h?.().then(()=>{const c=t("onChange"),u=t("getGridSelectedRows");if(c&&typeof c=="function"){const m=u?.();c(m)}})},[r.url,r.authtoken,r.filter,JSON.stringify(r.options),s,e]),d.jsx(d.Fragment,{})}const bt=p.memo(Xn);bt.displayName="Gridler-GlidlerAPIAdaptorForGoLangv2";function wt(r){const[o,e,t,n]=W(i=>[i.getState,i.mounted,i.setState,i._events]);p.useEffect(()=>{if(e&&r.changeOnActiveClick){const i=l=>{const{row:a,state:h}=l.detail,c=h.getRowBuffer;if(c){const u=c(a);if(!u)return;r.onRequestForm("change",u)}};return n?.addEventListener("onCellActivated",i),()=>{i&&n?.removeEventListener("onCellActivated",i)}}},[r.changeOnActiveClick,e,n]);const s=p.useCallback((i,l,a,h,c)=>{if(i==="header-menu")return c||[];const u=[];u.push(...c);const m=o("_gridSelection")?.rows.toArray()??[],g=m.length>1;if(!a){const E=m[0];E!==void 0&&(a=l.getRowBuffer(E))}const y=typeof r.descriptionField=="string"?a?.[r.descriptionField]:typeof r.descriptionField=="function"&&a?r.descriptionField(a):void 0;i==="other"&&u.push({c:"blue",label:"Add",onClick:()=>{r.onRequestForm("insert",a)}}),i==="cell"&&a||i==="menu"&&a?(u.push({c:"teal",label:"Add",leftSection:d.jsx(V.IconSquarePlus,{color:"teal",size:16}),onClick:()=>{r.onRequestForm("insert",a)}}),g?(u.push({c:"green",label:`Modify All Selected (${m.length})`,leftSection:d.jsx(V.IconEdit,{color:"green",size:16}),onClick:()=>{r.onRequestForm("change",m.map(E=>l.getRowBuffer(E)))}}),u.push({c:"red",label:`Remove All Selected (${m.length})`,leftSection:d.jsx(V.IconTrashX,{color:"maroon",size:16}),onClick:()=>{r.onRequestForm("delete",m.map(E=>l.getRowBuffer(E)))}})):(u.push({c:"green",label:`Modify${y&&r.showDescriptionInMenu?` (${y})`:""}`,leftSection:d.jsx(V.IconEdit,{color:"green",size:16}),onClick:()=>{r.onRequestForm("change",a)}}),u.push({c:"red",label:`Remove${y&&r.showDescriptionInMenu?` (${y})`:""}`,leftSection:d.jsx(V.IconTrashX,{color:"maroon",size:16}),onClick:()=>{r.onRequestForm("delete",a)}})),u.push({isDivider:!0})):(i==="cell"&&!a||i==="menu"&&!a)&&u.push({c:"red",label:"Nothing Selected",leftSection:d.jsx(V.IconExclamationMark,{color:"yellow",size:16})}),u.push({c:"orange",label:"Refresh",leftSection:d.jsx(V.IconRefresh,{color:"orange",size:16}),onClickAsync:async()=>{await o("_refresh")?.()}});const b=r.getMenuItems?r.getMenuItems(i,l,a,h,u):u;return!u||u.length===0?c||[]:b},[r.onRequestForm,o]);return p.useEffect(()=>(e&&typeof t=="function"&&o("getMenuItems")!==s&&t("getMenuItems",s),()=>{}),[r.getMenuItems,e]),d.jsx(d.Fragment,{})}function Qn(r){const[o,e,t]=W(c=>[c.setState,c.getState,c.mounted]),{colFilters:n,colSort:s,columns:i,searchStr:l}=W(c=>({colFilters:c.colFilters,colOrder:c.colOrder,colSize:c.colSize,colSort:c.colSort,columns:c.columns,searchStr:c.searchStr})),a=p.useRef({colFilters:n,colSort:s,searchStr:l}),h=async c=>{const u=e("pageSize");return r.data&&Array.isArray(r.data)?(o("total_rows",r.data.length),r.data.slice(c*(u??50),(c+1)*(u??50))):[]};return p.useEffect(()=>{o("useAPIQuery",h)},[t,o]),p.useEffect(()=>{if(r.onColumnSort&&s!==a?.current?.colSort){const c=r.onColumnSort(s,i,r.data);o("total_rows",c.length),o("data",c),a.current.colSort=s,e("refreshCells")?.()}},[s,r.onColumnSort]),p.useEffect(()=>{if(r.onColumnFilter&&n!==a?.current?.colFilters){const c=r.onColumnFilter(n,i,r.data);o("total_rows",c.length),o("data",c),a.current.colFilters=n,e("refreshCells")?.()}},[n,r.onColumnFilter]),p.useEffect(()=>{if(r.onSearch&&l!==a?.current?.searchStr){const c=r.onSearch(l,i,r.data);o("total_rows",c.length),o("data",c),a.current.colFilters=n,e("refreshCells")?.()}},[l,r.onSearch]),d.jsx(d.Fragment,{})}const Me=p.memo(Qn);Me.displayName="Gridler-GlidlerLocalDataAdaptor";function xt(){const{loadingData:r,onContextClick:o}=W(e=>({loadingData:e.loadingData,onContextClick:e.onContextClick}));return d.jsx(w.ActionIcon,{loading:r,mr:"xs",mt:"2px",onClick:e=>o("menu",e),variant:"subtle",children:d.jsx(V.IconMenu2,{})})}function Zn(r,o){const[e,t]=W(n=>[n.setStateFN,n.getState]);return p.useImperativeHandle(o,()=>({getGlideRef:()=>t("_glideref"),getState:t,isEmpty:()=>t("isEmpty"),refresh:async n=>{const s=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{s?.()})},reload:async n=>{const s=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{s?.()})},reloadRow:async n=>{const s=t("refreshCells"),l=await t("getRowIndexByKey")?.(String(n));l&&l>=0&&s?.(l,l+1)},scrollToRow:async n=>{n&&Number(n)>=0&&e("scrollToRowKey",s=>Number(n??s))},selectRow:async n=>{n&&Number(n)>=0&&e("selectedRowKey",s=>Number(n??s))},setStateFN:e}),[]),d.jsx(d.Fragment,{children:r.children})}const er=p.forwardRef(Zn);function tr(){const{_activeTooltip:r,tooltipBarProps:o}=W(e=>({_activeTooltip:e._activeTooltip,tooltipBarProps:e.tooltipBarProps}));return d.jsx("div",{"data-tooltip-bar":!0,style:{minHeight:"24px"},...o,children:r})}const Ct=p.memo(()=>{const r=p.useRef(0),o=p.useRef(""),e=p.useRef(null),{_glideref:t,_gridSelectionRows:n,colFilters:s,colOrder:i,colSize:l,colSort:a,columns:h,getRowIndexByKey:c,getState:u,loadPage:m,ready:g,scrollToRowKey:y,searchStr:b,selectedRowKey:E,selectFirstRowOnMount:_,setState:R,setStateFN:k,values:I}=W(x=>({_glideref:x._glideref,_gridSelectionRows:x._gridSelectionRows,colFilters:x.colFilters,colOrder:x.colOrder,colSize:x.colSize,colSort:x.colSort,columns:x.columns,getRowIndexByKey:x.getRowIndexByKey,getState:x.getState,loadPage:x.loadPage,ready:x.ready,scrollToRowKey:x.scrollToRowKey,searchStr:x.searchStr,selectedRowKey:x.selectedRowKey,selectFirstRowOnMount:x.selectFirstRowOnMount,setState:x.setState,setStateFN:x.setStateFN,uniqueid:x.uniqueid,values:x.values})),N=ie.useDebouncedCallback(x=>{m(0,"all").then(()=>{u("refreshCells")?.(),u("_events")?.dispatchEvent?.(new CustomEvent("onSearched",{detail:{search:x}}))})},{delay:300,leading:!1});return p.useEffect(()=>{I&&(async()=>{const S=u("_page_data"),O=u("pageSize"),z=u("keyField")??"id",B=[];for(const M in I){let P=-1;const T=String(typeof I?.[M]=="object"?I?.[M]?.[z]:typeof I?.[M]=="string"?I?.[M]:void 0);for(const G in S){for(const q in S[G]){const j=Number(G)*O+Number(q);if(String(S[G][q]?.[z])===T){P=j;break}}if(P>=0){B.push(P);break}}if(!(P>=0)){const G=await c(T);G&&B.push(G)}}return B})().then(S=>{let O=H.CompactSelection.empty();S.forEach(z=>{O=O.add(z)}),k("_gridSelectionRows",()=>O),k("_gridSelection",z=>({columns:z?.columns??H.CompactSelection.empty(),...z,rows:O}))})},[I]),p.useEffect(()=>{const x=u("onChange");if(x&&typeof x=="function"){const O=u("getGridSelectedRows")(),z=u("values");JSON.stringify(z)!==JSON.stringify(O)&&x(O)}},[n,n?.length,u]),p.useEffect(()=>{R("renderColumns",h?.map(x=>({...x,hasMenu:x?.hasMenu??!0,icon:"sort"})))},[h]),p.useEffect(()=>{if(b==null){o.current="";return}o.current!==b&&(N(b),o.current=b)},[b]),p.useEffect(()=>{a&&(R("_gridSelection",{columns:H.CompactSelection.empty(),current:void 0,rows:H.CompactSelection.empty()}),R("_gridSelectionRows",H.CompactSelection.empty()),k("renderColumns",x=>x?.map(S=>({...S,icon:S.id&&a?.find(O=>O.id===S.id)?.direction?a?.find(O=>O.id===S.id)?.direction==="asc"?"sortup":"sortdown":S.defaultIcon??"sort"}))).then(()=>{m(0,"all").then(()=>{u("refreshCells")?.(),u("_events")?.dispatchEvent?.(new CustomEvent("onColumnSorted",{detail:{cols:a}}))})}))},[a]),p.useEffect(()=>{s&&JSON.stringify(e.current)!==JSON.stringify(s)&&(m(0,"all").then(()=>{u("refreshCells")?.(),u("_events")?.dispatchEvent?.(new CustomEvent("onColumnFiltered",{detail:{filters:s}}))}),e.current=s)},[s]),p.useEffect(()=>{l&&k("renderColumns",x=>x?.map(S=>({...S,width:S.id&&l?.[S.id]?l?.[S.id]:S.width}))).then(()=>{u("refreshCells")?.()})},[l]),p.useEffect(()=>{i&&k("renderColumns",x=>x?.sort((O,z)=>i[O.id]>i[z.id]?1:-1)).then(()=>{u("refreshCells")?.()})},[i]),p.useEffect(()=>{t&&(r.current>0||(r.current=1,m(0).then(()=>{u("refreshCells")?.()})))},[g,m]),p.useEffect(()=>{const x=u("_events"),S=()=>{const O=u("selectFirstRowOnMount");if(u("ready")&&O){const B=u("scrollToRowKey");if(B&&B>=0)return;const M=u("keyField")??"id",T=u("_page_data")?.[0]?.[0],G=T?.[M]??-1,q=u("values")??[];if(!(I&&I.length>0)&&G&&G>0&&(q.length??0)===0){const j=[T,...q],J=u("onChange");J?J(j):R("values",j),R("scrollToRowKey",G)}}};return x?.addEventListener("loadPage",S),()=>{x?.removeEventListener("loadPage",S)}},[g,_]),p.useEffect(()=>{const x=u("ready"),S=u("_glideref"),O=u("getRowIndexByKey"),z=E??y;z&&S&&x&&O?.(z).then(B=>{if(B!==void 0){if(E){const M=u("onChange"),P=[{[u("keyField")??"id"]:E}];JSON.stringify(u("values"))!==JSON.stringify(P)&&(M?M(P):R("values",P))}S.scrollTo(0,B),u("_events").dispatchEvent(new CustomEvent("scrollToRowKeyFound",{detail:{rowNumber:B,scrollToRowKey:y,selectedRowKey:E}}))}})},[y,E]),d.jsx(d.Fragment,{})});Ct.displayName="Gridler-Computer";function nr(r,o,e=1){let t;if(o===void 0?(t=0,o=r):t=r,e===0)throw new Error("Step cannot be zero");const n=[];if(e>0)for(let s=t;s<o;s+=e)n.push(s);else for(let s=t;s>o;s+=e)n.push(s);return n}const _t=p.memo(()=>{const[r,o,e,t,n,s,i,l]=W(a=>[a.setState,a.getState,a._glideref,a._visiblePages,a.pageSize,a.loadPage,a._loadingList,a.hasLocalData]);return p.useEffect(()=>{e&&r("mounted",!0)},[r]),p.useEffect(()=>{if(!e)return;const a=Math.max(0,Math.floor(t.y/n)),h=Math.floor((t.y+t.height)/n);for(const c of nr(a,h+1,1))s(c).then(()=>{const u=o("_page_data")?.[0]??{};r("isEmpty",u&&u.length>0)})},[s,n,t,e,i,l]),d.jsx(d.Fragment,{})});_t.displayName="Gridler-Pager";const rr=r=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
22
22
|
<path
|
|
23
23
|
fill="${r.fgColor??"currentColor"}"
|
|
24
24
|
d="M2.22 9.967L7.97 4.22l.085-.074l.058-.038l.072-.039l.105-.04l.105-.022l.052-.005L8.5 4l.057.002l.092.013l.107.03l.085.037l.054.03l.063.044l.072.064l5.75 5.747a.75.75 0 0 1-.976 1.133l-.084-.072L9.25 6.56v16.69a.75.75 0 0 1-1.493.102l-.007-.102V6.56l-4.47 4.468a.75.75 0 0 1-.976.072l-.084-.072a.75.75 0 0 1-.073-.977zM19.5 4a.75.75 0 0 1 .743.648l.007.102v16.687l4.47-4.467l.084-.073a.75.75 0 0 1 1.049 1.05l-.073.083l-5.728 5.727a.75.75 0 0 1-1.031.07l-.073-.07l-5.728-5.727l-.073-.084a.75.75 0 0 1-.007-.882l.08-.094l.084-.073a.75.75 0 0 1 .882-.007l.094.08l4.47 4.469V4.75l.007-.102A.75.75 0 0 1 19.5 4"
|
|
25
25
|
></path>
|
|
26
|
-
</svg>`,
|
|
26
|
+
</svg>`,or="_container_1nbyf_1",sr={container:or},ir=r=>o=>o%2===0?void 0:{bgCell:r==="dark"?"#303030":"#e1effc"},lr=()=>{const r=w.useMantineTheme(),{colorScheme:o}=w.useMantineColorScheme(),{enableOddEvenRowColor:e,focused:t}=W(u=>({enableOddEvenRowColor:u.enableOddEvenRowColor,focused:u.focused})),n={auto:t?w.lighten(r.colors.blue[4],.9):"#ffffff",dark:t?w.darken("#bacfe0",.2):r.colors.dark[7],light:t?w.lighten(r.colors.blue[4],.8):"#ffffff"}[o],s={accentColor:"none",accentLight:r.colors.blue[9],baseFontStyle:"13px",bgBubble:"#212121",bgBubbleSelected:"#000000",bgCell:n,bgCellMedium:"#202027",bgHeader:"#2A2A2A",bgHeaderHasFocus:"#181818",bgHeaderHovered:"#404040",bgIconHeader:"#b8b8b8",bgSearchResult:"#423c24",borderColor:"#eee1",drilldownBorder:"rgba(225,225,225,0.4)",fgIconHeader:"#000000",fontFamily:"Inter, Roboto, -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, noto, arial, sans-serif",headerFontStyle:"500 13px",linkColor:r.colors.blue[4],textBubble:"#ffffff",textDark:"#dedede",textGroupHeader:"#dedede",textHeader:"#a1a1a1",textHeaderSelected:"#000000",textLight:"#a0a0a0",textMedium:"#b8b8b8"},l=o==="dark"?s:{bgCell:n,textGroupHeader:"#2c5491"},[a,h]=p.useState(l);return p.useEffect(()=>{h(l)},[o,t]),{getRowThemeOverride:u=>e?ir(o)(u):void 0,gridTheme:a}},ar=()=>{const r=p.useRef(null),o=p.useRef(!1),{height:e,ref:t,width:n}=ie.useElementSize({box:"content-box"}),{_gridSelection:s,allowMultiSelect:i,focused:l,getCellContent:a,getCellsForSelection:h,getState:c,glideProps:u,hasLocalData:m,headerHeight:g,heightProp:y,mounted:b,onCellActivated:E,onCellClicked:_,onCellEdited:R,onColumnMoved:k,onColumnProposeMove:I,onColumnResize:N,onContextClick:x,onHeaderClicked:S,onHeaderMenuClick:O,onItemHovered:z,onVisibleRegionChanged:B,renderColumns:M,rowHeight:P,sections:T,selectMode:G,setState:q,setStateFN:j,total_rows:J,widthProp:Y}=W(f=>({_gridSelection:f._gridSelection,allowMultiSelect:f.allowMultiSelect,focused:f.focused,getCellContent:f.getCellContent,getCellsForSelection:f.getCellsForSelection,getState:f.getState,glideProps:f.glideProps,hasLocalData:f.hasLocalData,headerHeight:f.headerHeight,heightProp:f.height,mounted:f.mounted,onCellActivated:f.onCellActivated,onCellClicked:f.onCellClicked,onCellEdited:f.onCellEdited,onColumnMoved:f.onColumnMoved,onColumnProposeMove:f.onColumnProposeMove,onColumnResize:f.onColumnResize,onContextClick:f.onContextClick,onHeaderClicked:f.onHeaderClicked,onHeaderMenuClick:f.onHeaderMenuClick,onItemHovered:f.onItemHovered,onVisibleRegionChanged:f.onVisibleRegionChanged,renderColumns:f.renderColumns,rowHeight:f.rowHeight,sections:f.sections,selectMode:f.selectMode,setState:f.setState,setStateFN:f.setStateFN,total_rows:f.total_rows,widthProp:f.width})),Q=ie.useMergedRef(r,f=>{j("_glideref",()=>f??void 0);const C=c("ready"),A=!!(f&&b);C!==A&&q("ready",A)}),K=lr();return d.jsxs(w.Stack,{align:"stretch",gap:0,h:y??"100%",justify:"stretch",w:Y??"100%",children:[T?.top,d.jsxs("div",{className:sr.container,"data-focused":l,onContextMenu:f=>{f.preventDefault(),o.current||(o.current=!0,x("other",f),setTimeout(()=>{o.current=!1},100))},ref:t,style:{display:"flex",height:"100%",minHeight:"64px",minWidth:"32px",width:"100%"},children:[T?.left,n&&n>0&&e&&e>0&&d.jsx(H.DataEditor,{cellActivationBehavior:"double-click",columns:M??[],columnSelect:"none",drawFocusRing:!0,height:e??400,overscrollX:16,overscrollY:32,rangeSelect:i?"multi-rect":"cell",rightElementProps:{fill:!1,sticky:!0},rowMarkers:{checkboxStyle:"square",kind:i?"both":"clickable-number"},rowSelect:i?"multi":"single",rowSelectionMode:"auto",spanRangeBehavior:"default",...u,getCellContent:a,getCellsForSelection:h,getRowThemeOverride:K.getRowThemeOverride,gridSelection:s,headerHeight:g??32,headerIcons:{sort:rr,sortdown:Ae,sortup:je},onCellActivated:E,onCellClicked:_,onCellContextMenu:(f,C)=>{C.preventDefault(),u?.onCellContextMenu?.(f,C),o.current||(o.current=!0,x("cell",C,f[0],f[1]),setTimeout(()=>{o.current=!1},100))},onCellEdited:R,onColumnMoved:k,onColumnProposeMove:I,onColumnResize:N,onGridSelectionChange:f=>{let C=H.CompactSelection.empty();const A=c("_gridSelection"),v=c("keyField")??"id",$=c("getRowBuffer");for(const D of f.rows)$&&$(D)?.[v]&&(C=C.hasIndex(D)?C:C.add(D));if(G==="row"&&f.current?.range)for(let D=f.current.range.y;D<f.current.range.y+f.current.range.height;D++)$&&$(D)?.[v]&&(C=C.hasIndex(D)?C:C.add(D));if(C.length===0)for(const D of A?.rows??[])$&&$(D)?.[v]&&(C=C.hasIndex(D)?C:C.add(D));console.log("Debug:onGridSelectionChange",A,f),(JSON.stringify(A?.columns)!==JSON.stringify(f.columns)||JSON.stringify(A?.rows)!==JSON.stringify(C)||JSON.stringify(A?.current)!==JSON.stringify(f.current))&&(q("_gridSelection",{...f,rows:C}),q("_gridSelectionRows",C))},onHeaderClicked:S,onHeaderContextMenu:(f,C)=>{C.preventDefault(),o.current||(o.current=!0,x("header",C,f),setTimeout(()=>{o.current=!1},100))},onHeaderMenuClick:O,onItemHovered:z,onVisibleRegionChanged:B,ref:Q,rightElement:T?.rightElementDisabled?void 0:d.jsxs(w.Group,{children:[T?.rightElementStart,d.jsx(xt,{}),T?.rightElementEnd]}),rowHeight:P??22,rows:J??0,theme:K.gridTheme,width:n??200}),d.jsx(Ct,{}),!m&&d.jsx(_t,{}),T?.right]}),d.jsxs("div",{style:{flexGrow:0},children:[d.jsx(tr,{}),T?.bottom]})]})},cr=(r,o)=>d.jsx(pt,{children:d.jsxs(Yn,{...r,persist:{name:`Gridler_${r.uniqueid}`,partialize:e=>({colOrder:e.colOrder,colSize:e.colSize}),version:1},children:[d.jsx(ar,{}),d.jsx(er,{ref:o}),r.children]})}),Pe=p.forwardRef(cr);Pe.FormAdaptor=wt;Pe.LocalDataAdaptor=Me;exports.Boxer=ct;exports.BoxerProvider=st;exports.ButtonCtrl=rn;exports.ColumnFilterInput=vt;exports.ColumnFilterInputOperator=yt;exports.ColumnFilterSet=ke;exports.FilterOperators=St;exports.Former=Se;exports.FormerButtonArea=le;exports.FormerDialog=en;exports.FormerModel=tn;exports.FormerPopover=nn;exports.FormerResolveSpecAPI=Qt;exports.FormerRestHeadSpecAPI=Zt;exports.GetGlobalState=ht;exports.GlidlerAPIAdaptorForGoLangv2=bt;exports.GlidlerFormAdaptor=wt;exports.GlidlerLocalDataAdaptor=Me;exports.GlobalStateStore=L;exports.GlobalStateStoreProvider=Gn;exports.GoAPIHeaders=re;exports.Gridler=Pe;exports.GridlerRightMenuIcon=xt;exports.IconButtonCtrl=on;exports.MantineBetterMenusProvider=pt;exports.NativeSelectCtrl=sn;exports.PasswordInputCtrl=ln;exports.ReactBasicErrorBoundary=Ht;exports.ReactErrorBoundary=Kt;exports.SwitchCtrl=an;exports.TextAreaCtrl=cn;exports.TextInputCtrl=un;exports.errorManager=me;exports.getApiURL=$n;exports.getAuthToken=Nn;exports.isLoggedIn=Bn;exports.setApiURL=zn;exports.setAuthToken=Ln;exports.useBoxerStore=it;exports.useGlobalStateStore=Dn;exports.useGlobalStateStoreContext=qn;exports.useGridlerStore=W;exports.useMantineBetterMenus=Fe;
|
|
27
27
|
//# sourceMappingURL=lib.cjs.js.map
|