@compill/admin 1.0.26 → 1.0.28

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/index.js CHANGED
@@ -245,4 +245,4 @@ See more info here: https://nextjs.org/docs/messages/no-stylesheets-in-head-comp
245
245
  */function TE(t,e){return t?jB(t)?hi.createElement(t,e):t:null}function jB(t){return FB(t)||typeof t=="function"||HB(t)}function FB(t){return typeof t=="function"&&(()=>{const e=Object.getPrototypeOf(t);return e.prototype&&e.prototype.isReactComponent})()}function HB(t){return typeof t=="object"&&typeof t.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(t.$$typeof.description)}function BB(t){const e={state:{},onStateChange:()=>{},renderFallbackValue:null,...t},[n]=hi.useState(()=>({current:MB(e)})),[r,i]=hi.useState(()=>n.current.initialState);return n.current.setOptions(o=>({...o,...t,state:{...r,...t.state},onStateChange:s=>{i(s),t.onStateChange==null||t.onStateChange(s)}})),n.current}function Ii(t,e,n){let r=n.initialDeps??[],i;function o(){var s,a,l,c;let u;n.key&&((s=n.debug)!=null&&s.call(n))&&(u=Date.now());const d=t();if(!(d.length!==r.length||d.some((p,g)=>r[g]!==p)))return i;r=d;let f;if(n.key&&((a=n.debug)!=null&&a.call(n))&&(f=Date.now()),i=e(...d),n.key&&((l=n.debug)!=null&&l.call(n))){const p=Math.round((Date.now()-u)*100)/100,g=Math.round((Date.now()-f)*100)/100,m=g/16,v=(x,w)=>{for(x=String(x);x.length<w;)x=" "+x;return x};console.info(`%c⏱ ${v(g,5)} /${v(p,5)} ms`,`
246
246
  font-size: .6rem;
247
247
  font-weight: bold;
248
- color: hsl(${Math.max(0,Math.min(120-120*m,120))}deg 100% 31%);`,n==null?void 0:n.key)}return(c=n==null?void 0:n.onChange)==null||c.call(n,i),i}return o.updateDeps=s=>{r=s},o}function _f(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}const $B=(t,e)=>Math.abs(t-e)<1,VB=(t,e,n)=>{let r;return function(...i){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,i),n)}},zB=t=>t,UB=t=>{const e=Math.max(t.startIndex-t.overscan,0),n=Math.min(t.endIndex+t.overscan,t.count-1),r=[];for(let i=e;i<=n;i++)r.push(i);return r},qB=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;const i=s=>{const{width:a,height:l}=s;e({width:Math.round(a),height:Math.round(l)})};if(i(n.getBoundingClientRect()),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(s=>{const a=()=>{const l=s[0];if(l!=null&&l.borderBoxSize){const c=l.borderBoxSize[0];if(c){i({width:c.inlineSize,height:c.blockSize});return}}i(n.getBoundingClientRect())};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},jv={passive:!0},Fv=typeof window>"u"?!0:"onscrollend"in window,WB=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;let i=0;const o=t.options.useScrollendEvent&&Fv?()=>{}:VB(r,()=>{e(i,!1)},t.options.isScrollingResetDelay),s=u=>()=>{const{horizontal:d,isRtl:h}=t.options;i=d?n.scrollLeft*(h&&-1||1):n.scrollTop,o(),e(i,u)},a=s(!0),l=s(!1);l(),n.addEventListener("scroll",a,jv);const c=t.options.useScrollendEvent&&Fv;return c&&n.addEventListener("scrollend",l,jv),()=>{n.removeEventListener("scroll",a),c&&n.removeEventListener("scrollend",l)}},KB=(t,e,n)=>{if(e!=null&&e.borderBoxSize){const r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}return Math.round(t.getBoundingClientRect()[n.options.horizontal?"width":"height"])},GB=(t,{adjustments:e=0,behavior:n},r)=>{var i,o;const s=t+e;(o=(i=r.scrollElement)==null?void 0:i.scrollTo)==null||o.call(i,{[r.options.horizontal?"left":"top"]:s,behavior:n})};class JB{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(i=>{i.forEach(o=>{const s=()=>{this._measureElement(o.target,o)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(s):s()})}));return{disconnect:()=>{var i;(i=r())==null||i.disconnect(),n=null},observe:i=>{var o;return(o=r())==null?void 0:o.observe(i,{box:"border-box"})},unobserve:i=>{var o;return(o=r())==null?void 0:o.unobserve(i)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([r,i])=>{typeof i>"u"&&delete n[r]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:zB,rangeExtractor:UB,onChange:()=>{},measureElement:KB,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,...n}},this.notify=n=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,n)},this.maybeNotify=Ii(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this.maybeNotify()}))}},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=(n,r)=>{const i=new Map,o=new Map;for(let s=r-1;s>=0;s--){const a=n[s];if(i.has(a.lane))continue;const l=o.get(a.lane);if(l==null||a.end>l.end?o.set(a.lane,a):a.end<l.end&&i.set(a.lane,!0),i.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((s,a)=>s.end===a.end?s.index-a.index:s.end-a.end)[0]:void 0},this.getMeasurementOptions=Ii(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled],(n,r,i,o,s)=>(this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:i,getItemKey:o,enabled:s}),{key:!1}),this.getMeasurements=Ii(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:i,getItemKey:o,enabled:s},a)=>{if(!s)return this.measurementsCache=[],this.itemSizeCache.clear(),[];this.measurementsCache.length===0&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const l=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const c=this.measurementsCache.slice(0,l);for(let u=l;u<n;u++){const d=o(u),h=this.options.lanes===1?c[u-1]:this.getFurthestMeasurement(c,u),f=h?h.end+this.options.gap:r+i,p=a.get(d),g=typeof p=="number"?p:this.options.estimateSize(u),m=f+g,v=h?h.lane:u%this.options.lanes;c[u]={index:u,start:f,size:g,end:m,key:d,lane:v}}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=Ii(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,o)=>this.range=n.length>0&&r>0?XB({measurements:n,outerSize:r,scrollOffset:i,lanes:o}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=Ii(()=>{let n=null,r=null;const i=this.calculateRange();return i&&(n=i.startIndex,r=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,i,o,s)=>o===null||s===null?[]:n({startIndex:o,endIndex:s,overscan:r,count:i}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,i=n.getAttribute(r);return i?parseInt(i,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this._measureElement=(n,r)=>{const i=this.indexFromElement(n),o=this.measurementsCache[i];if(!o)return;const s=o.key,a=this.elementsCache.get(s);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(s,n)),n.isConnected&&this.resizeItem(i,this.options.measureElement(n,r,this))},this.resizeItem=(n,r)=>{const i=this.measurementsCache[n];if(!i)return;const o=this.itemSizeCache.get(i.key)??i.size,s=r-o;s!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(i,s,this):i.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",s),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(i.index),this.itemSizeCache=new Map(this.itemSizeCache.set(i.key,r)),this.notify(!1))},this.measureElement=n=>{if(!n){this.elementsCache.forEach((r,i)=>{r.isConnected||(this.observer.unobserve(r),this.elementsCache.delete(i))});return}this._measureElement(n,void 0)},this.getVirtualItems=Ii(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const i=[];for(let o=0,s=n.length;o<s;o++){const a=n[o],l=r[a];i.push(l)}return i},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length!==0)return _f(r[OE(0,r.length-1,i=>_f(r[i]).start,n)])},this.getOffsetForAlignment=(n,r,i=0)=>{const o=this.getSize(),s=this.getScrollOffset();r==="auto"&&(r=n>=s+o?"end":"start"),r==="center"?n+=(i-o)/2:r==="end"&&(n-=o);const a=this.options.horizontal?"scrollWidth":"scrollHeight",c=(this.scrollElement?"document"in this.scrollElement?this.scrollElement.document.documentElement[a]:this.scrollElement[a]:0)-o;return Math.max(Math.min(c,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.measurementsCache[n];if(!i)return;const o=this.getSize(),s=this.getScrollOffset();if(r==="auto")if(i.end>=s+o-this.options.scrollPaddingEnd)r="end";else if(i.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];const a=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,r,i.size),r]},this.isDynamicMode=()=>this.elementsCache.size>0,this.cancelScrollToIndex=()=>{this.scrollToIndexTimeoutId!==null&&this.targetWindow&&(this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId),this.scrollToIndexTimeoutId=null)},this.scrollToOffset=(n,{align:r="start",behavior:i}={})=>{this.cancelScrollToIndex(),i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(n,r),{adjustments:void 0,behavior:i})},this.scrollToIndex=(n,{align:r="auto",behavior:i}={})=>{n=Math.max(0,Math.min(n,this.options.count-1)),this.cancelScrollToIndex(),i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");const o=this.getOffsetForIndex(n,r);if(!o)return;const[s,a]=o;this._scrollToOffset(s,{adjustments:void 0,behavior:i}),i!=="smooth"&&this.isDynamicMode()&&this.targetWindow&&(this.scrollToIndexTimeoutId=this.targetWindow.setTimeout(()=>{if(this.scrollToIndexTimeoutId=null,this.elementsCache.has(this.options.getItemKey(n))){const[c]=_f(this.getOffsetForIndex(n,a));$B(c,this.getScrollOffset())||this.scrollToIndex(n,{align:a,behavior:i})}else this.scrollToIndex(n,{align:a,behavior:i})}))},this.scrollBy=(n,{behavior:r}={})=>{this.cancelScrollToIndex(),r==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+n,{adjustments:void 0,behavior:r})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((n=r[r.length-1])==null?void 0:n.end)??0;else{const o=Array(this.options.lanes).fill(null);let s=r.length-1;for(;s>0&&o.some(a=>a===null);){const a=r[s];o[a.lane]===null&&(o[a.lane]=a.end),s--}i=Math.max(...o.filter(a=>a!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:i})=>{this.options.scrollToFn(n,{behavior:i,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.notify(!1)},this.setOptions(e)}}const OE=(t,e,n,r)=>{for(;t<=e;){const i=(t+e)/2|0,o=n(i);if(o<r)t=i+1;else if(o>r)e=i-1;else return i}return t>0?t-1:0};function XB({measurements:t,outerSize:e,scrollOffset:n,lanes:r}){const i=t.length-1;let s=OE(0,i,l=>t[l].start,n),a=s;if(r===1)for(;a<i&&t[a].end<n+e;)a++;else if(r>1){const l=Array(r).fill(0);for(;a<i&&l.some(u=>u<n+e);){const u=t[a];l[u.lane]=u.end,a++}const c=Array(r).fill(n+e);for(;s>0&&c.some(u=>u>=n);){const u=t[s];c[u.lane]=u.start,s--}s=Math.max(0,s-s%r),a=Math.min(i,a+(r-1-a%r))}return{startIndex:s,endIndex:a}}const Hv=typeof document<"u"?hi.useLayoutEffect:hi.useEffect;function YB(t){const e=hi.useReducer(()=>({}),{})[1],n={...t,onChange:(i,o)=>{var s;o?co.flushSync(e):e(),(s=t.onChange)==null||s.call(t,i,o)}},[r]=hi.useState(()=>new JB(n));return r.setOptions(n),Hv(()=>r._didMount(),[]),Hv(()=>r._willUpdate()),r}function QB(t){return YB({observeElementRect:qB,observeElementOffset:WB,scrollToFn:GB,...t})}function ZB(t,e){const{rows:n}=t.getRowModel(),r=QB({getScrollElement:()=>e,count:n.length,estimateSize:()=>35,overscan:10});return{rows:n,virtualRows:r.getVirtualItems(),totalSize:r.getTotalSize(),virtualizer:r}}function e$(t,e){const n=t.getIsPinned(),r=n==="left"&&t.getIsLastColumn("left"),i=n==="right"&&t.getIsFirstColumn("right");return{shadow:r?"-2px 0 2px -2px gray inset":i?"2px 0 2px -2px gray inset":void 0,start:n==="left"?`${t.getStart("left")}px`:void 0,end:n==="right"?`${t.getAfter("right")}px`:void 0,position:n?"sticky":"relative",w:t.getSize(),z:n?1:0,bgColor:n?e?"gray.50":"white":e?"gray.50":void 0}}function t$({table:t,containerRef:e,onRowClick:n,disabledRow:r}){var u,d;const{rows:i,virtualRows:o,totalSize:s,virtualizer:a}=ZB(t,e),l=o.length>0&&((u=o==null?void 0:o[0])==null?void 0:u.start)||0,c=o.length>0?s-(((d=o==null?void 0:o[o.length-1])==null?void 0:d.end)||0):0;return y.jsxs("tbody",{children:[l>0&&y.jsx("tr",{children:y.jsx("td",{h:`${l}px`})}),o.map(h=>{const f=i[h.index],p=n$(f.original,r);return y.jsx("tr",{borderB:"px",borderBColor:"#F4F4F4",borderStyle:"dashed",hover_bgColor:"slate-50",cursor:n?"pointer":"default",onClick:n?()=>n(f.original):void 0,w:"fit-content",group:!0,children:f.getVisibleCells().map((g,m)=>y.jsx("td",{px:"3",py:"2",textSize:"sm",textColor:p?"gray.400":"gray.700",fontWeight:"500",borderTColor:"--bg-3",borderT:"0.5",cursor:n&&!p?"pointer":"default",w:`${g.column.getSize()}px`,groupHover_bgColor:p?void 0:"gray.100",...e$(g.column,p),children:TE(g.column.columnDef.cell,g.getContext())},g.id))},f.id)}),c>0&&y.jsx("tr",{children:y.jsx("td",{h:`${c}px`})})]})}function n$(t,e){return e?typeof e=="string"?t[e]:e(t):!1}function r$({headers:t}){const e=Fe.useThemeAwareColor("slate-500","slate-700");return y.jsx("thead",{children:t.map(n=>y.jsx("tr",{w:"fit",children:n.headers.map(r=>y.jsx("th",{position:"relative",colSpan:r.colSpan,textAlign:"start",fontWeight:"600",textColor:e,px:"3",py:"2",textSize:"sm",w:`${r.getSize()}px`,children:y.jsxs("div",{dflex:!0,flexRow:!0,children:[r.isPlaceholder?null:y.jsxs(y.Fragment,{children:[TE(r.column.columnDef.header,r.getContext()),y.jsx("span",{cursor:r.column.getCanSort()?"pointer":"default",onClick:r.column.getToggleSortingHandler(),opacity:"0",hover_opacity:"100",flexGrow:!0,textAlign:"end",children:{asc:y.jsx(y.Fragment,{children:" ▲"}),desc:y.jsx(y.Fragment,{children:" ▼"})}[r.column.getIsSorted()]??y.jsx(y.Fragment,{children:" ▲"})})]}),y.jsx("div",{onMouseDown:r.getResizeHandler(),onTouchStart:r.getResizeHandler(),onClick:i=>{i.preventDefault(),i.stopPropagation()},position:"absolute",end:"0",top:"0",h:"full",w:"2",bgColor:r.column.getIsResizing()?"primary-500":"slate-900",bgOpacity:r.column.getIsResizing()?"70":"30",cursor:"col-resize",userSelect:"none",style:{touchAction:"none"},opacity:r.column.getIsResizing()?"100":"0",hover_opacity:"100"})]})},r.id))},n.id))})}const[i$,Mg]=Fe.createContext();function o$({initialPageSize:t,children:e}){const[n,r]=rn.useSearchParams(),{pageIndex:i,pageSize:o}=A.useMemo(()=>({pageIndex:n.get("page")??1,pageSize:n.get("sizePerPage")??t??25}),[n,t]),s=A.useCallback(c=>{const u=Fe.runIfFn(c,{pageIndex:i,pageSize:o});r(d=>(d.set("page",`${u.pageIndex}`),d.set("sizePerPage",`${u.pageSize}`),d))},[r,i,o]),a=i$,l={pageIndex:typeof i=="string"?parseInt(i):i,pageSize:typeof o=="string"?parseInt(o):o,setPagination:s};return y.jsx(a,{value:l,children:e})}function kE({page:t,...e}){const{pageSize:n,pageIndex:r,setPagination:i}=Mg(),o=A.useCallback(()=>i({pageIndex:1,pageSize:n}),[n,i]);return y.jsxs("div",{dflex:!0,flexCol:!0,gap:"10",w:"full",h:"full",alignItems:"center",placeContent:"center",py:"16",...e,children:[y.jsx(N.Icon,{path:l_,w:"24",h:"24",textColor:"gray.400"}),y.jsx("div",{textSize:"xl",textColor:"gray.600",children:"No Data"}),t>1&&y.jsx(N.Button,{onClick:o,children:"Back To First Page"})]})}function s$({table:t,isLoading:e}){const n=t.getPageCount(),r=t.getState().pagination.pageIndex+1,i=a$(r,n,5);return y.jsxs(y.Fragment,{children:[n<2&&y.jsx(y.Fragment,{}),n>1&&y.jsx(y.Fragment,{children:y.jsxs("div",{dflex:!0,flexRow:!0,spaceX:"2",py:"2",children:[y.jsx(Li,{onClick:()=>t.setPageIndex(0),disabled:e||r==1,children:y.jsx(N.Icon,{path:YE})}),y.jsx(Li,{onClick:()=>t.previousPage(),disabled:e||r==1,children:y.jsx(N.Icon,{path:e_})}),i.length>0&&i[0]>1&&y.jsx("a",{children:"..."}),i.map(o=>y.jsx(Li,{onClick:()=>t.setPageIndex(o-1),disabled:e,variant:r==o?"default":"glass",scheme:"secondary",children:o},o)),i.length>0&&i[i.length-1]<n&&y.jsx(Li,{disabled:e,children:"..."}),y.jsx(Li,{onClick:()=>t.nextPage(),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:t_})}),y.jsx(Li,{onClick:()=>t.setPageIndex(t.getPageCount()-1),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:QE})})]})})]})}function Li({...t}){return y.jsx(N.Button,{scheme:"secondary",variant:"glass",corners:"pill",w:"8",h:"8",p:"0",dflex:!0,alignItems:"center",placeContent:"center",...t})}function a$(t,e,n){const r=[];if(!t)return r;if(e===1)return r.push(1),r;if(e<t)return r;if(e<n+1){for(let o=1;o<e+1;o++)r.push(o);return r}if(t===1){for(let o=1;o<n+1;o++)o<e&&r.push(o);return r}if(t===e){for(let o=e-n+1;o<=e;o++)o<=e&&r.push(o);return r}const i=Math.floor(n/2);if(i<1)return r.push(t),r;if(t<i+2){for(let o=1;o<n+1;o++)r.push(o);return r}if(e-t<i+2){for(let o=e-n;o<e+1;o++)r.push(o);return r}for(let o=t-i;o<t;o++)o>0&&r.push(o);r.push(t);for(let o=t+1;o<t+i+1;o++)o<=e&&r.push(o);return r}const l$=[{label:"25",value:25},{label:"50",value:50},{label:"100",value:100}];function c$({table:t,total:e,isLoading:n,reverseOrder:r,sizePerPageList:i}){const o=t.getState().pagination.pageIndex,s=t.getState().pagination.pageSize;return y.jsxs("div",{dflex:!0,flexDirection:r?"row-reverse":"row",alignItems:"center",py:"3",spaceX:"3",children:[y.jsx(N.Select,{disabled:e===0||n,onChange:a=>t.setPageSize(Number(a.target.value)),value:s,w:"20",children:(i??l$).map(a=>{const l=s===a.value;return y.jsx("option",{value:a.value,className:`btn ${l?"active":""}`,children:a.label},a.label)})}),y.jsxs("div",{children:["Showing rows ",1+o*s," to ",Math.min((o+1)*s,e)," of ",e]}),n&&y.jsx(N.Spinner,{size:"sm"})]})}function ME({isLoading:t,table:e,total:n,show:r,toolbarPosition:i="both",reverseOrder:o=!1,sizePerPageList:s,children:a,...l}){return y.jsxs("div",{...l,children:[r&&["top","both"].includes(i)&&y.jsx(Bv,{isLoading:t,table:e,total:n,reverseOrder:o,sizePerPageList:s}),a,r&&["bottom","both"].includes(i)&&y.jsx(Bv,{isLoading:t,table:e,total:n,reverseOrder:o,sizePerPageList:s})]})}function Bv({isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:i}){return y.jsxs("div",{dflex:!0,justifyContent:"between",alignItems:"center",flexWrap:!0,flexDirection:r?"row-reverse":"row",children:[y.jsx(c$,{isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:i}),y.jsx("div",{className:"d-flex flex-wrap"}),y.jsx(s$,{isLoading:t,table:e})]})}const[u$,PE]=Fe.createContext();function d$({sortBy:t,sortDir:e,children:n}){const[r,i]=rn.useSearchParams(),{sortBy:o,sortDir:s}=A.useMemo(()=>({sortBy:r.get("sortBy")??t??"",sortDir:r.get("sortDir")??e??"asc"}),[r]),a=A.useCallback(u=>{const d=Fe.runIfFn(u,[{id:o,desc:s==="desc"}]);i(h=>{var f,p;return h.set("sortBy",`${((f=d==null?void 0:d[0])==null?void 0:f.id)??""}`),h.set("sortDir",`${(p=d==null?void 0:d[0])!=null&&p.desc?"desc":"asc"}`),h})},[i,o,s]),l=u$,c={sortBy:o,sortDir:s,setSorting:a};return y.jsx(l,{value:c,children:n})}function f$(t,e,n){const{setPagination:r}=Mg(),{sortBy:i,sortDir:o,setSorting:s}=PE(),[a,l]=A.useState((n==null?void 0:n.rowSelection)??{}),c=A.useCallback(h=>{var f;l(h),(f=n==null?void 0:n.onSelectionChange)==null||f.call(n,Fe.runIfFn(h,a))},[l,a]),u=A.useCallback(h=>{var f;if(n!=null&&n.enableSelection&&(n!=null&&n.enableSelectOnRowClick)){h.toggleSelected();return}(f=n==null?void 0:n.onRowClick)==null||f.call(n,h.original)},[]);return{table:BB(ko({data:t??[],getRowId:h=>h.id,columns:e,columnResizeMode:"onChange",enableColumnResizing:!0,enableSortingRemoval:!1,defaultColumn:{size:150,minSize:40,maxSize:1e3},state:{sorting:[{id:i,desc:o==="desc"}],rowSelection:a},filterFns:{},enableRowSelection:n==null?void 0:n.enableSelection,onRowSelectionChange:c,onSortingChange:s,getCoreRowModel:PB(),getFilteredRowModel:NB(),onPaginationChange:r},n==null?void 0:n.tableOptions)),onRowClick:u}}const IE=A.createContext({});function Yc(){return A.useContext(IE)}const h$=["sortBy","sortDir","page","sizePerPage"];function p$({sortBy:t,sortDir:e,initialPageSize:n,children:r}){const[i,o]=rn.useSearchParams(),s=A.useCallback(h=>{o(f=>(Object.keys(h).forEach(p=>{f.set(p,h[p]===void 0?"":h[p])}),f.set("page","1"),f))},[o]),a=A.useCallback(()=>{const h={},f=i.entries();for(const[p,g]of f)h$.includes(p)||(h[p]=g);return h},[i]),[l,c]=A.useState(),d={ids:A.useMemo(()=>{const h=Object.keys(l??{});return(h==null?void 0:h.filter(f=>l==null?void 0:l[f]))??[]},[l]),setRowSelection:c,getFilters:a,setFilters:s};return y.jsx(IE.Provider,{value:d,children:y.jsx(o$,{initialPageSize:n,children:y.jsx(d$,{sortBy:t,sortDir:e,children:r})})})}function g$(t,e,n){const r=je.useInvalidateQuery(t),i=A.useMemo(()=>({onError:()=>Ne.error((n==null?void 0:n.errorMessage)??"Oops, something went wrong :("),refetchOnWindowFocus:!1,keepPreviousData:!0,retry:!1,staleTime:1e8}),[n]),{pageIndex:o,pageSize:s,setPagination:a}=Mg(),{sortBy:l,sortDir:c}=PE(),{getFilters:u}=Yc(),d={pageSize:s,pageNumber:o,sortBy:l,sortDir:c,...n!=null&&n.transformFilters?n.transformFilters(u()):u()},h=A.useMemo(()=>({...i,...n==null?void 0:n.queryOptions}),[n]),{data:f,isError:p,isFetching:g,isLoading:m}=je.useApiQuery(t,e,d,h),v=A.useCallback(r,[r]),{data:x}=f??{data:{data:void 0,meta:void 0}},{data:w,meta:b}=x;return{data:w&&(n!=null&&n.transformResponse)?n.transformResponse(w):w,response:x,retry:v,isError:p,isLoading:m,isFetching:g,page:(b==null?void 0:b.current_page)??1??o,pageSize:(b==null?void 0:b.per_page)??s,total:(b==null?void 0:b.total)??0,onPaginationChange:a}}function m$({columns:t,keyField:e="id",queryKey:n,queryFn:r,queryOptions:i,errorMessage:o,transformFilters:s,transformResponse:a,defaultSorted:l="name",defaultSortOrder:c="desc",nonSelectable:u,enableFilters:d=!1,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,onRowClick:g,onSelectionChange:m,sizePerPageList:v,paginationPosition:x,reversePaginationTools:w,containerEl:b,emptyMessage:S,title:C,disabledRow:_,pinnedColumnsLeft:E,pinnedColumnsRight:R,...T}){const O=A.useRef(null),{data:k,response:P,retry:M,isError:j,isLoading:z,isFetching:B,page:J,pageSize:K,total:D,onPaginationChange:Q}=g$(n,r,{errorMessage:o,queryOptions:i,transformResponse:a,transformFilters:s}),oe=f$(k??[],b$(t,h),{defaultSorted:l,defaultSortOrder:c,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,nonSelectable:u,onRowClick:g,onSelectionChange:m,tableOptions:{enableColumnFilters:d,initialState:{columnPinning:{left:E??[],right:R??[]}},state:{pagination:{pageIndex:J,pageSize:K}},autoResetPageIndex:!1,pageCount:Math.ceil(D/K),onPaginationChange:Q}}).table;return y.jsxs("div",{px:"8",pt:"8",ref:O,h:"100%",children:[j&&y.jsx(xi,{onClick:M,label:o}),(z||B&&(!k||(k==null?void 0:k.length)==0))&&y.jsx(Br,{}),!j&&!z&&k&&y.jsxs("div",{children:[C&&(Fe.isFunction(C)?C(P):C),T.mode=="table"&&y.jsx(y$,{table:oe,total:D??0,data:k,isLoading:B,containerEl:b??O.current,onRowClick:g,sizePerPageList:v,disabledRow:_}),T.mode=="grid"&&y.jsx(v$,{table:oe,total:D??0,data:k,isLoading:B,onRowClick:g,sizePerPageList:v,gridCols:T.gridCols,renderGridItem:T.renderGridItem})]})]})}function y$({table:t,total:e,data:n,isLoading:r,onRowClick:i,containerEl:o,sizePerPageList:s,disabledRow:a}){return y.jsxs(ME,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:s,children:[n.length==0&&y.jsx(kE,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",border:"2px",borderColor:"#F4F4F4",rounded:"base",my:"3",overflowX:"auto",children:y.jsxs("table",{style:{width:"max(1400px, 100%)",tableLayout:"fixed"},children:[y.jsx(r$,{headers:t.getHeaderGroups()}),y.jsx(t$,{table:t,containerRef:o,onRowClick:i,disabledRow:a})]})})]})}function v$({table:t,total:e,data:n,isLoading:r,onRowClick:i,sizePerPageList:o,gridCols:s,renderGridItem:a}){return y.jsxs(ME,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:o,children:[n.length==0&&y.jsx(kE,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",children:y.jsx("div",{grid:!0,gridCols:`${s??3}`,gap:"5",w:"full",children:n.map(l=>a==null?void 0:a(l,i))})})]})}function b$(t,e){return e?[{id:"select-col",header:({table:n})=>y.jsx(N.Checkbox,{checked:n.getIsAllRowsSelected(),onChange:n.getToggleAllRowsSelectedHandler()}),cell:({row:n})=>y.jsx(N.Checkbox,{checked:n.getIsSelected(),disabled:!n.getCanSelect(),onChange:n.getToggleSelectedHandler()}),size:10,maxSize:1,enableResizing:!1}].concat(t):t}const[w$,S$]=Fe.createContext();function $v(t){return t.accessorKey??t.id}function x$({initialVisibleColumns:t,columns:e,children:n}){const[r,i]=A.useState(!1),[o,s]=A.useState(!1),[a,l]=A.useState(t??(e==null?void 0:e.map(p=>$v(p)))??[]),c=(e==null?void 0:e.filter(p=>a.includes($v(p))))??[],u=A.useCallback(p=>{const g=a.indexOf(p);if(g>-1){const m=a.concat();m.splice(g,1),l(m)}else l(a.concat(p))},[a,l]),d=A.useCallback(p=>a.includes(p),[a]),h=w$,f={showFilters:r,setShowFilters:i,showMassActions:o,setShowMassActions:s,columns:e??[],filteredColumns:c,toggleColumnVisibility:u,isColumnVisible:d};return y.jsx(h,{value:f,children:n})}function LE({initialPageSize:t,initialVisibleColumns:e,columns:n,children:r,...i}){return y.jsx(N.Tile,{shadow:!0,rounded:"md",px:"0",py:"4",w:"full",dflex:!0,flexCol:!0,...i,children:y.jsx(p$,{initialPageSize:t,children:y.jsx(x$,{columns:n,initialVisibleColumns:e,children:r})})})}function DE({children:t,...e}){return y.jsx(cc,{scheme:"default",corners:"pill",h:"10",variant:"glass",...e,children:t??y.jsx(N.Icon,{path:w_})})}function NE({...t}){return y.jsxs(N.Popover,{side:"bottom-end",modal:!0,children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",...t,children:y.jsx(N.Icon,{path:a_})}),y.jsxs("div",{bgColor:"white",rounded:!0,shadow:!0,children:[y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"First Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Second Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Third Item"})]})]})}function jE({title:t,queryKey:e,children:n,...r}){const i=je.useInvalidateQuery(e);return cw("ctrl+r",()=>i(),{preventDefault:!0},[i]),y.jsxs("div",{dflex:!0,flexRow:!0,pb:"4",alignItems:"center",gap:"3",px:"8",borderB:"0.5",borderBColor:"--bg-2",...r,children:[t&&y.jsx("h2",{textSize:"x3",fontWeight:"600",textColor:"#3f4254",textTransform:"capitalize",children:t}),y.jsx("div",{flexGrow:!0,children:" "}),y.jsxs("div",{spaceX:"2",dflex:!0,alignItems:"center",children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",onClick:i,children:y.jsx(N.Icon,{path:sb})}),n]})]})}const Vv="Oops, something went wrong...";function zv(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function Pg({initialValues:t,itemLabel:e,queryId:n="",api:r,queryFetchOptions:i,querySaveOptions:o,onSuccess:s,onFetchError:a,fetchErrorMsg:l=Vv,onSaveError:c,saveErrorMsg:u=Vv,fetchToFormData:d,formToQueryData:h,invalidateQueriesOnSuccess:f=!0,invalidateQueryKey:p,retryText:g="Retry",cancelLabel:m="Cancel",saveLabel:v,size:x="lg",title:w,form:b,show:S,onClose:C,formikProps:_,...E}){const{isInitialLoading:R,isFetching:T,data:O,isError:k,error:P,refetch:M}=je.useApiQuery(r.queryKey,r.get,n,{enabled:!(n==""||n==null||n==null),onError:a,...i}),j=f?je.useInvalidateParentMutation(r.upsert,p??r.queryKey,o):je.useApiMutation(r.upsert,r.queryKey,n,o),z=A.useCallback(()=>M(),[M]),B=A.useCallback((J,K)=>{j.reset();const D=h?h(J):{...J};j.mutateAsync(D).then(Q=>{s?s(D,Q):Ne.success(`${w?w(D):D.name??D.title} ${n?"saved":"created"}`),C==null||C()}).catch(Q=>{console.error("on error",Q),c?c(J):Ne.error(`Couldn't save ${w?w(D):D.name??D.title}`),K.setSubmitting(!1)})},[j,h,s,c,C]);return y.jsxs(N.Modal,{size:x,show:S,onClose:C,scheme:"light",transition:!0,...E,children:[y.jsxs(N.Modal.Header,{children:[!R&&n&&`Edit ${w?w(O):(O==null?void 0:O.name)??(O==null?void 0:O.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(b)&&y.jsx(y.Fragment,{})]}),R&&y.jsx(N.Modal.Body,{children:y.jsx(Br,{minW:"72"})}),k&&y.jsx(N.Modal.Body,{children:y.jsx(xi,{label:`${l} ${P}`,onClick:z})}),!R&&!k&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:d&&n&&O?d(zv(O)):zv(t(O))??{},onSubmit:B,..._,children:({setFieldValue:J,dirty:K,handleSubmit:D,isValid:Q,values:se})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[A.isValidElement(b)&&b,Array.isArray(b)&&y.jsx(Mr,{form:b}),Fe.isFunction(b)&&y.jsx(Mr,{form:b(O??se)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:j.isLoading,onClick:C,variant:"borderless",me:"2",children:m}),y.jsx(N.Button,{type:"submit",disabled:!K||j.isLoading,onClick:()=>D(),children:v||(n?"Update":"Create")})]})]})})}),j.isLoading&&y.jsx(Ps,{})]})}function C$({api:t,fn:e,transformFn:n,config:r,onClose:i,queryId:o,invalidateQueryKey:s}){const{data:a,isFetching:l}=je.useApiQuery(t.queryKey,e==="get"||e==="getTransformed"?t.get:t.getAll,void 0,{retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1}),c=A.useMemo(()=>a&&(e==="getTransformed"||e==="getAllTransformed")?(n||console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${e}`),n==null?void 0:n(a)):a,[a,e,n]);return l?null:y.jsx(Pg,{...r(c),queryId:o,invalidateQueryKey:s,show:!0,onClose:i})}function E$({queries:t,config:e,onClose:n,queryId:r,invalidateQueryKey:i}){const{data:o,isFetching:s,isError:a}=je.useApiQueries(t.map(c=>({queryKey:c.api.queryKey,queryFn:c.fn=="get"?c.api.get:c.api.getAll,queryOptions:{cacheTime:c.cache===!1?0:void 0,staleTime:c.cache===!1?0:void 0}}))),l=A.useMemo(()=>o==null?void 0:o.map((c,u)=>{var d,h;return t[u].transformFn?(h=(d=t[u])==null?void 0:d.transformFn)==null?void 0:h.call(d,c):c}),[o,t]);return y.jsx(Pg,{isPreloading:s,...e(...l),queryId:r,invalidateQueryKey:i,show:!0,onClose:n})}function FE({config:t,onClose:e,invalidateQueryKey:n,queryId:r}){const{type:i,...o}=t;return t.type==="dialog"?y.jsx(Pg,{...o,queryId:r,invalidateQueryKey:n,show:!0,onClose:e}):t.type==="query"?y.jsx(C$,{...o,queryId:r,invalidateQueryKey:n,onClose:e}):t.type==="multiQuery"?y.jsx(E$,{...o,queryId:r,invalidateQueryKey:n,onClose:e}):null}function _$({itemLabel:t,queryId:e="",api:n,invalidateQueriesOnSuccess:r=!0,invalidateQueryKey:i,size:o="lg",show:s,onClose:a,...l}){const c=r?je.useInvalidateParentMutation(n.delete,i??n.queryKey):je.useApiMutation(n.upsert,n.queryKey),u=je.useMutate(c,{onSuccess:()=>a==null?void 0:a()}),d=A.useCallback(()=>u(e),[u,e]);return y.jsxs(N.Modal,{size:o,show:s,onClose:a,scheme:"danger",variant:"glass",transition:!0,...l,children:[y.jsx(N.Modal.Header,{children:`Delete ${t}`}),y.jsxs(N.Modal.Body,{pb:"6",children:["Do you really want to delete ",t,"?"]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:c.isLoading,onClick:a,variant:"borderless",scheme:"secondary",me:"2",children:"Cancel"}),y.jsx(N.Button,{scheme:"danger",disabled:c.isLoading,onClick:d,children:"Delete"})]}),c.isLoading&&y.jsx(Ps,{})]})}const[R$,HE]=Fe.createContext();function A$({editView:t,deleteItem:e,queryKey:n,children:r}){const i=Xb(),o=rn.useNavigate(),[s,a]=A.useState(null),l=A.useCallback(()=>a(null),[a]),c=A.useCallback((h,f)=>{switch(h.type){case"view":{o(Fe.runIfFn(h.path,f));break}case"link":{i(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(h.path,f)}`);break}case"edit":{t.type=="customDialog"?a(t.render({show:!0,onClose:l})):a(y.jsx(FE,{onClose:l,config:t,queryId:f.id,invalidateQueryKey:n}));break}case"delete":{a(y.jsx(_$,{show:!0,onClose:l,queryId:f.id,invalidateQueryKey:n,...e,itemLabel:Fe.runIfFn(e.itemLabel,f)}));break}}},[o,t,e]),u=R$,d={dialog:s,onAction:c};return y.jsx(u,{value:d,children:r})}function T$({id:t,api:e,status:n,invalidateQueryKey:r,...i}){const o=n=="draft",s=je.useInvalidateParentMutation(o?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=A.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>Ne.success(o?"Published!":"Unpublished!")).catch(c=>Ne.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...i,children:y.jsx(N.Icon,{path:o?ib:ob})})}function O$({row:t,onAction:e,rowActions:n,api:r,queryKey:i}){const o=t.original;return y.jsx("div",{dflex:!0,spaceX:"1",placeContent:"end",children:n==null?void 0:n.map((s,a)=>y.jsxs(A.Fragment,{children:[s.type==="publish"&&y.jsx(T$,{id:o.id,api:r,status:o.status,invalidateQueryKey:i}),s.type=="custom"&&y.jsx(y.Fragment,{children:s.component(o,i,s.icon,s.label)}),!["publish","custom"].includes(s.type)&&y.jsx(k$,{onClick:()=>e(s,o),scheme:P$[s.type],children:y.jsx(N.Icon,{path:M$[s.type]})})]},a))})}function k$({onClick:t,...e}){const n=A.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),t==null||t(r)},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",onClick:n,...e})}const M$={link:Jh,view:Gh,edit:rb,delete:Rf,publish:Rf,custom:""},P$={link:"dark",view:"secondary",edit:"warning",delete:"danger",publish:"warning",custom:"default"};function I$(t,e,n){const r=rn.useNavigate(),i=Xb(),{onAction:o}=HE(),{onRowClick:s,columns:a,...l}=e,c=A.useCallback(h=>{(s==null?void 0:s.type)==="navigate"?r(Fe.runIfFn(s.path,h)):(s==null?void 0:s.type)=="link"&&i(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(s.path,h)}`)},[r,s]),u=A.useMemo(()=>{const h=e.columns.concat([]);return n&&h.push(K4().display({id:"actions",header:"Actions",cell:f=>y.jsx(O$,{row:f.row,onAction:o,rowActions:n,api:t,queryKey:t.queryKey})})),h},[e]),d={...l};return d.columns=u,d.onRowClick=c,d.queryKey=t.queryKey,d.queryFn=t.search,d}function L$({form:t,initialValues:e,schema:n,processInput:r}){const{showFilters:i}=S$(),{getFilters:o,setFilters:s}=Yc(),a=A.useCallback((c,u)=>{const d=(r==null?void 0:r(c))??c;Kb(d,o())||s(d),u.setSubmitting(!1)},[s,r]),l=A.useCallback(c=>{s(e),c()},[s,e]);return A.useEffect(()=>s(e),[]),y.jsx(N.Collapse,{in:i,style:{overflow:i?"initial":"hidden"},children:y.jsx("div",{p:"8",borderT:"px",borderB:"px",borderColor:"slate-100",children:y.jsx(vc,{initialValues:rw(o(),e),onSubmit:a,validationSchema:n,enableReinitialize:!0,children:c=>y.jsxs("div",{dflex:!0,gap:"3",placeContent:"start",children:[y.jsx(Mr,{flexRow:!0,w:"auto",form:t}),y.jsx(D$,{handleReset:()=>l(c.resetForm)})]})})})})}function D$({handleReset:t}){return y.jsxs("div",{dflex:!0,gap:"3",children:[y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(wn,{name:"",label:" "}),y.jsx(gp,{children:"Filter"})]}),y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(wn,{name:"",label:" "}),y.jsx(N.Button,{scheme:"neutral",onClick:t,children:"Reset"})]})]})}function N$({label:t,buttonProps:e,icon:n,queryKey:r,queryFn:i,successMsg:o,errorMsg:s,invalidateParent:a}){const l=a?je.useInvalidateParentMutation(i,r):je.useApiMutation(i,r),c=je.useMutate(l,{successMsg:o,errorMsg:s});return y.jsxs(N.Button,{display:"flex",alignItems:"center",gap:"3",...e,onClick:c,disabled:l.isLoading,children:[n&&y.jsx(N.Icon,{path:n}),t]})}function j$({actions:t}){const{ids:e}=Yc(),n=e&&e.length>0;return y.jsx(N.Collapse,{in:n,style:{overflow:n?"initial":"hidden"},children:y.jsx("div",{dflex:!0,gap:"3",flexWrap:!0,alignItems:"center",px:"8",pt:"5",children:t.map((r,i)=>y.jsx("div",{children:r.type=="button"&&!r.showConfirmationDialog&&y.jsx(N$,{label:r.label,queryFn:r.queryFn,queryKey:r.queryKey,buttonProps:r.buttonProps})},i))})})}function F$(t){const e=rn.useParams();if(t===void 0)return;const{[t]:n}=e;return n}function H$({queryField:t,title:e,subtitle:n,screen:r,...i}){const o=F$(t),s=Fe.runIfFn(r,o);return y.jsx(bc,{p:"5",...i,children:y.jsx(LE,{columns:s.table.columns,initialVisibleColumns:s.table.initialVisibleColumns,children:y.jsx(B$,{id:o,title:e,subtitle:n,screen:s})})})}function B$({id:t,title:e,subtitle:n,screen:r}){const{setRowSelection:i}=Yc(),{api:o,table:s,filters:a,massActions:l,buttonBar:c,rowActions:u,createView:d,editView:h,deleteItem:f,breadcrumbs:p}=r,g=Fe.runIfFn(o,t??"");return y.jsxs(y.Fragment,{children:[p&&y.jsx(Rg,{breadcrumbs:p}),y.jsxs(jE,{title:e,queryKey:g.queryKey,children:[y.jsx($$,{buttonBar:c,createView:d,editView:h,api:g}),a&&y.jsx(NE,{})]}),a&&y.jsx(L$,{form:a.form,initialValues:a.initialValues,schema:a.schema,processInput:a.processInput}),l&&y.jsx(j$,{actions:l.items}),y.jsxs(A$,{queryKey:g.queryKey,editView:h,deleteItem:f,children:[y.jsx(V$,{table:{...s,onSelectionChange:i},rowActions:u,api:g,subtitle:n}),y.jsx(z$,{})]})]})}function $$({buttonBar:t,createView:e,editView:n,api:r}){const i=A.useCallback(o=>{const s=e??n;return s.type=="customDialog"?s.render({show:!0,onClose:o}):y.jsx(FE,{config:s,onClose:o,invalidateQueryKey:r.queryKey})},[n,r]);return y.jsx(y.Fragment,{children:t&&t.map((o,s)=>y.jsxs("div",{children:[o.type==="create"&&n&&y.jsx(DE,{buildDialog:i}),o.type==="invalidate"&&y.jsx(up,{pathOrPermalink:o.pathOrPermalink}),o.type==="custom"&&o.render()]},s))})}function V$({table:t,subtitle:e,rowActions:n,api:r}){const i=I$(r,t,n),o=A.useMemo(()=>{if(e)return s=>y.jsx("div",{textSize:"lg",textColor:"#475569",fontWeight:"600",children:Fe.isFunction(e)?e(s):e})},[e]);return y.jsx(m$,{...i,title:o})}function z$(){const{dialog:t}=HE();return t}function U$(t){const e=rn.useParams(),{data:n,isFetching:r,isError:i}=je.useApiQueries(t.map(s=>{if(!s.queryField||!Fe.isFunction(s.api)){const c=s.api;return{queryKey:c.queryKey,queryFn:s.fn=="get"?c.get:c.getAll,queryParam:s.params}}const a=e[s.queryField],l=Fe.runIfFn(s.api,a);return{queryKey:l.queryKey,queryFn:s.fn=="get"?l.get:l.getAll,queryParam:s.fn=="getAll"?s.params:Fe.isFunction(s.api)?void 0:a}}));let o;return!r&&!i&&(o=n==null?void 0:n.map((s,a)=>{var l,c;return t[a].transformFn?(c=(l=t[a]).transformFn)==null?void 0:c.call(l,s):s})),{data:o,isFetching:r,isError:i}}function q$(t){const e=Kv.useQueryClient(),n=rn.useParams();return A.useCallback(()=>{const i=[];t.forEach(o=>{if(!o.queryField||!Fe.isFunction(o.api))i.push(o.api.queryKey);else{const s=n[o.queryField],a=Fe.runIfFn(o.api,s);i.push(a.queryKey)}}),e.invalidateQueries({predicate:o=>i.includes(o.queryKey)})},[t,e,n])}function W$({queries:t,config:e,tabbed:n,...r}){const{data:i,isFetching:o,isError:s}=U$(t),a=q$(t);return o?y.jsx(Br,{w:"full",h:"100vh"}):s||!i?y.jsx(xi,{p:"0",w:"full",h:"100vh",onClick:a}):y.jsx(Qc,{config:e(...i),tabbed:n,...r})}function Qc({config:t,tabbed:e,...n}){return t.type==="table"?y.jsx(H$,{...t,...n}):t.type==="tabbed"?y.jsx(q4,{...t,...n}):t.type==="details"?y.jsx(B4,{...t,tabbed:e,...n}):t.type==="query"?y.jsx(U4,{...t,tabbed:e,...n}):t.type==="multiQuery"?y.jsx(W$,{...t,tabbed:e,...n}):y.jsx(y.Fragment,{})}const Uv="Oops, something went wrong...";function K$({queryId:t,queryKey:e,queryFetchFn:n,queryFetchAllKey:r,queryFetchAllFn:i,querySaveFn:o,matchKey:s,size:a="lg",show:l,onClose:c,itemLabel:u,onSuccess:d,onFetchError:h,fetchErrorMsg:f=Uv,onSaveError:p,saveErrorMsg:g=Uv,invalidateQueriesOnSuccess:m=!0,retryText:v="Retry",cancelLabel:x="Cancel",saveLabel:w,formikProps:b,getItemName:S,...C}){const _=Kv.useQueryClient(),{data:E,isInitialLoading:R,isError:T,refetch:O,error:k}=je.useApiQuery(e,n),{data:P,isInitialLoading:M,isError:j,refetch:z,error:B}=je.useApiQuery(r,i),[J,K]=A.useState([]),D=R||M,Q=T||j,se=je.useApiMutation(o,e,t),oe=A.useCallback(L=>{const ce=(L==null?void 0:L.currentTarget.dataset.id)??"",me=J.concat([]),be=J.indexOf(ce);be!=-1?me.splice(be,1):me.push(ce),K(me)},[J,K]),de=A.useCallback(()=>{T&&O(),j&&z()},[O,z,T,j]),ue=A.useCallback(()=>{se.reset(),se.mutateAsync({resources:J}).then(L=>{d?d(L):Ne.success(`${u} saved`),m&&_.invalidateQueries({queryKey:e}),c==null||c()}).catch(L=>{console.error("on error",L),p?p():Ne.error(`Error adding ${u}`)})},[se,t,d,_,p,c]),pe=A.useMemo(()=>{let L=[];return E&&P&&(L=[].concat(P),E.forEach(ce=>L.splice(L.findIndex(me=>me.id==ce[s]),1)),S&&(L=L.map(ce=>({...ce,name:S(ce)}))),L=nT(L,["name"])),L},[E,P]);return y.jsxs(N.Modal,{size:a,show:l,onClose:c,scheme:"light",transition:!0,...C,children:[y.jsx(N.Modal.Header,{children:`Add ${u}`}),D&&y.jsx(N.Modal.Body,{children:y.jsx(Br,{minW:"72"})}),Q&&y.jsx(N.Modal.Body,{children:y.jsx(xi,{label:`${f} ${k}`,onClick:de})}),!D&&!Q&&y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{px:"0",pb:"6",maxH:"750px",overflow:"auto",children:y.jsx("div",{dflex:!0,flexCol:!0,overflow:"auto",children:pe.map(L=>y.jsx(G$,{label:L.name,value:L.id,"data-id":L.id,checked:J.includes(`${L.id}`),onClick:oe},L.id))})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:se.isLoading,onClick:c,variant:"borderless",me:"2",children:x}),y.jsx(N.Button,{type:"submit",disabled:J.length==0||se.isLoading,onClick:ue,children:w||(t?"Update":"Create")})]})]}),se.isLoading&&y.jsx(Ps,{})]})}function G$({label:t,value:e,checked:n,...r}){return y.jsxs("div",{dflex:!0,alignItems:"center",hover_bgColor:"slate-100",px:"5",py:"2",cursor:"pointer",...r,children:[y.jsx("span",{flexGrow:!0,children:t}),y.jsx(N.Checkbox,{name:`resources.${e}`,value:e,checked:n})]})}function J$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFn:i,queryOptions:o,onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h,invalidateQueriesOnSuccess:f=!0,cancelLabel:p="Cancel",saveLabel:g="Send",size:m="lg",title:v,form:x,show:w,onClose:b,formikProps:S,...C}){const _=f?je.useInvalidateParentMutation(i,r,o):je.useApiMutation(i,r,n,o),E=je.useMutate(_,{onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h});return y.jsxs(N.Modal,{size:m,show:w,onClose:b,scheme:"light",transition:!0,...C,children:[y.jsx(N.Modal.Header,{children:v}),y.jsxs(vc,{initialValues:t??{},onSubmit:E,...S,children:[y.jsxs(N.Modal.Body,{pb:"6",children:[A.isValidElement(x)&&x,Array.isArray(x)&&y.jsx(Mr,{form:x})]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:_.isLoading,onClick:b,variant:"borderless",me:"2",children:p}),y.jsx(gp,{disabled:_.isLoading,children:g})]})]}),_.isLoading&&y.jsx(Ps,{})]})}const qv="Oops, something went wrong...";function Wv(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function X$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFetchFn:i,queryFetchOptions:o,querySaveFn:s,querySaveOptions:a,onSuccess:l,onFetchError:c,fetchErrorMsg:u=qv,onSaveError:d,saveErrorMsg:h=qv,fetchToFormData:f,formToQueryData:p,invalidateQueriesOnSuccess:g=!0,invalidateQueryKey:m,retryText:v="Retry",cancelLabel:x="Cancel",saveLabel:w,size:b="lg",title:S,form:C,show:_,onClose:E,formikProps:R,...T}){const{isInitialLoading:O,isFetching:k,data:P,isError:M,error:j,refetch:z}=je.useApiQuery(r,i,n,{enabled:!(n==""||n==null||n==null),onError:c,...o}),B=g?je.useInvalidateParentMutation(s,m??r,a):je.useApiMutation(s,r,n,a),J=A.useCallback(()=>z(),[z]),K=A.useCallback((D,Q)=>{B.reset();const se=p?p(D):{...D};B.mutateAsync(se).then(oe=>{l?l(se,oe):Ne.success(`${S?S(se):se.name??se.title} ${n?"saved":"created"}`),E==null||E()}).catch(oe=>{console.error("on error",oe),d?d(D):Ne.error(`Couldn't save ${S?S(se):se.name??se.title}`),Q.setSubmitting(!1)})},[B,p,l,d,E]);return y.jsxs(N.Modal,{size:b,show:_,onClose:E,scheme:"light",transition:!0,...T,children:[y.jsxs(N.Modal.Header,{children:[!O&&n&&`Edit ${S?S(P):(P==null?void 0:P.name)??(P==null?void 0:P.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(C)&&y.jsx(y.Fragment,{})]}),O&&y.jsx(N.Modal.Body,{children:y.jsx(Br,{minW:"72"})}),M&&y.jsx(N.Modal.Body,{children:y.jsx(xi,{label:`${u} ${j}`,onClick:J})}),!O&&!M&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:f&&n&&P?f(Wv(P)):Wv(P)??t??{},onSubmit:K,...R,children:({setFieldValue:D,dirty:Q,handleSubmit:se,isValid:oe,values:de})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[A.isValidElement(C)&&C,Array.isArray(C)&&y.jsx(Mr,{form:C}),Fe.isFunction(C)&&y.jsx(Mr,{form:C(P??de)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:B.isLoading,onClick:E,variant:"borderless",me:"2",children:x}),y.jsx(N.Button,{type:"submit",disabled:!Q||B.isLoading,onClick:()=>se(),children:w||(n?"Update":"Create")})]})]})})}),B.isLoading&&y.jsx(Ps,{})]})}function BE({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"5",...e,children:t})}const Y$=A.forwardRef(({loading:t=!1,children:e,...n},r)=>y.jsxs(y.Fragment,{children:[t&&y.jsx(Br,{w:"full",h:"100%"}),!t&&y.jsx(N.Container,{ref:r,center:!0,size:"x2",dflex:!0,flexCol:!0,gap:"8",...n,children:e})]}));function Q$({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"3",...e,children:t})}const Z$={draft:"Draft",published:"Published",pending:"Pending",approved:"Approved",partially_approved:"Partially Approved",rejected:"Rejected"},eV={draft:"warning",published:"success",pending:"secondary",approved:"success",partially_approved:"warning",rejected:"danger"};function tV({status:t,...e}){return y.jsx(N.Badge,{size:"sm",variant:"glass",whiteSpace:"nowrap",rounded:"full",px:"3",scheme:eV[t],...e,children:Z$[t]})}function $E({path:t,...e}){const n=A.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),window.open(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${t}`,"_blank")},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"dark",onClick:n,...e,children:y.jsx(N.Icon,{path:Jh})})}function VE({path:t,...e}){const n=rn.useNavigate(),r=A.useCallback(i=>{i==null||i.preventDefault(),i==null||i.stopPropagation(),n(`${t}`)},[n,t]);return y.jsx(N.Button,{scheme:"secondary",w:"10",h:"10",variant:"borderless",corners:"pill",onClick:r,...e,children:y.jsx(N.Icon,{path:Gh})})}function zE({children:t,...e}){return y.jsx(cc,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"warning",...e,children:t??y.jsx(N.Icon,{path:rb})})}function UE({children:t,...e}){return y.jsx(cc,{w:"10",h:"10",scheme:"danger",variant:"borderless",corners:"pill",...e,children:t??y.jsx(N.Icon,{path:Rf})})}function nV({publishId:t,viewPath:e,navigatePath:n,editDialog:r,deleteDialog:i,children:o,...s}){return y.jsxs("div",{dflex:!0,spaceX:"1",placeContent:"end",...s,children:[e&&y.jsx($E,{path:e}),n&&y.jsx(VE,{path:n}),r&&y.jsx(zE,{buildDialog:r}),i&&y.jsx(UE,{buildDialog:i}),o]})}function rV({id:t,api:e,status:n,invalidateQueryKey:r,...i}){const o=n=="draft",s=je.useInvalidateParentMutation(o?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=A.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>Ne.success(o?"Published!":"Unpublished!")).catch(c=>Ne.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...i,children:y.jsx(N.Icon,{path:o?ib:ob})})}exports.AttachDialog=K$;exports.Breadcrumbs=rp;exports.DialogButton=cc;exports.FormActionDialog=J$;exports.IconButton=z_;exports.InvalidateButton=up;exports.ItemEditDialog=X$;exports.NavigateButton=aA;exports.OrderCell=gk;exports.PageContainer=bc;exports.PageContentEditor=fE;exports.PageMain=dE;exports.PageQueryStateContainer=Eg;exports.PageSectionTitle=BE;exports.PageSidebar=hE;exports.PageSidebarSection=pE;exports.PageStateContainer=Y$;exports.PageSubSectionTitle=Q$;exports.PageTabbedTopBar=yE;exports.PageTabbedTopBarProvider=mE;exports.PageTitle=_g;exports.PageTopBar=Rg;exports.PageTopBarToolbar=vE;exports.PublishButton=Wb;exports.ScreenRenderer=Qc;exports.SectionTitle=GE;exports.StatusBadge=tV;exports.TableContainer=LE;exports.TableCreateButton=DE;exports.TableFilterButton=NE;exports.TableRowActionBar=nV;exports.TableRowDeleteButton=UE;exports.TableRowEditButton=zE;exports.TableRowNavigateButton=VE;exports.TableRowPublishPostButton=rV;exports.TableRowViewButton=$E;exports.TableTopBar=jE;exports.UpdateButton=uw;exports.ViewButton=dw;
248
+ color: hsl(${Math.max(0,Math.min(120-120*m,120))}deg 100% 31%);`,n==null?void 0:n.key)}return(c=n==null?void 0:n.onChange)==null||c.call(n,i),i}return o.updateDeps=s=>{r=s},o}function _f(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}const $B=(t,e)=>Math.abs(t-e)<1,VB=(t,e,n)=>{let r;return function(...i){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,i),n)}},zB=t=>t,UB=t=>{const e=Math.max(t.startIndex-t.overscan,0),n=Math.min(t.endIndex+t.overscan,t.count-1),r=[];for(let i=e;i<=n;i++)r.push(i);return r},qB=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;const i=s=>{const{width:a,height:l}=s;e({width:Math.round(a),height:Math.round(l)})};if(i(n.getBoundingClientRect()),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(s=>{const a=()=>{const l=s[0];if(l!=null&&l.borderBoxSize){const c=l.borderBoxSize[0];if(c){i({width:c.inlineSize,height:c.blockSize});return}}i(n.getBoundingClientRect())};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},jv={passive:!0},Fv=typeof window>"u"?!0:"onscrollend"in window,WB=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;let i=0;const o=t.options.useScrollendEvent&&Fv?()=>{}:VB(r,()=>{e(i,!1)},t.options.isScrollingResetDelay),s=u=>()=>{const{horizontal:d,isRtl:h}=t.options;i=d?n.scrollLeft*(h&&-1||1):n.scrollTop,o(),e(i,u)},a=s(!0),l=s(!1);l(),n.addEventListener("scroll",a,jv);const c=t.options.useScrollendEvent&&Fv;return c&&n.addEventListener("scrollend",l,jv),()=>{n.removeEventListener("scroll",a),c&&n.removeEventListener("scrollend",l)}},KB=(t,e,n)=>{if(e!=null&&e.borderBoxSize){const r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}return Math.round(t.getBoundingClientRect()[n.options.horizontal?"width":"height"])},GB=(t,{adjustments:e=0,behavior:n},r)=>{var i,o;const s=t+e;(o=(i=r.scrollElement)==null?void 0:i.scrollTo)==null||o.call(i,{[r.options.horizontal?"left":"top"]:s,behavior:n})};class JB{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(i=>{i.forEach(o=>{const s=()=>{this._measureElement(o.target,o)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(s):s()})}));return{disconnect:()=>{var i;(i=r())==null||i.disconnect(),n=null},observe:i=>{var o;return(o=r())==null?void 0:o.observe(i,{box:"border-box"})},unobserve:i=>{var o;return(o=r())==null?void 0:o.unobserve(i)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([r,i])=>{typeof i>"u"&&delete n[r]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:zB,rangeExtractor:UB,onChange:()=>{},measureElement:KB,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,...n}},this.notify=n=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,n)},this.maybeNotify=Ii(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this.maybeNotify()}))}},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=(n,r)=>{const i=new Map,o=new Map;for(let s=r-1;s>=0;s--){const a=n[s];if(i.has(a.lane))continue;const l=o.get(a.lane);if(l==null||a.end>l.end?o.set(a.lane,a):a.end<l.end&&i.set(a.lane,!0),i.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((s,a)=>s.end===a.end?s.index-a.index:s.end-a.end)[0]:void 0},this.getMeasurementOptions=Ii(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled],(n,r,i,o,s)=>(this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:i,getItemKey:o,enabled:s}),{key:!1}),this.getMeasurements=Ii(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:i,getItemKey:o,enabled:s},a)=>{if(!s)return this.measurementsCache=[],this.itemSizeCache.clear(),[];this.measurementsCache.length===0&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const l=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const c=this.measurementsCache.slice(0,l);for(let u=l;u<n;u++){const d=o(u),h=this.options.lanes===1?c[u-1]:this.getFurthestMeasurement(c,u),f=h?h.end+this.options.gap:r+i,p=a.get(d),g=typeof p=="number"?p:this.options.estimateSize(u),m=f+g,v=h?h.lane:u%this.options.lanes;c[u]={index:u,start:f,size:g,end:m,key:d,lane:v}}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=Ii(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,o)=>this.range=n.length>0&&r>0?XB({measurements:n,outerSize:r,scrollOffset:i,lanes:o}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=Ii(()=>{let n=null,r=null;const i=this.calculateRange();return i&&(n=i.startIndex,r=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,i,o,s)=>o===null||s===null?[]:n({startIndex:o,endIndex:s,overscan:r,count:i}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,i=n.getAttribute(r);return i?parseInt(i,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this._measureElement=(n,r)=>{const i=this.indexFromElement(n),o=this.measurementsCache[i];if(!o)return;const s=o.key,a=this.elementsCache.get(s);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(s,n)),n.isConnected&&this.resizeItem(i,this.options.measureElement(n,r,this))},this.resizeItem=(n,r)=>{const i=this.measurementsCache[n];if(!i)return;const o=this.itemSizeCache.get(i.key)??i.size,s=r-o;s!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(i,s,this):i.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",s),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(i.index),this.itemSizeCache=new Map(this.itemSizeCache.set(i.key,r)),this.notify(!1))},this.measureElement=n=>{if(!n){this.elementsCache.forEach((r,i)=>{r.isConnected||(this.observer.unobserve(r),this.elementsCache.delete(i))});return}this._measureElement(n,void 0)},this.getVirtualItems=Ii(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const i=[];for(let o=0,s=n.length;o<s;o++){const a=n[o],l=r[a];i.push(l)}return i},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length!==0)return _f(r[OE(0,r.length-1,i=>_f(r[i]).start,n)])},this.getOffsetForAlignment=(n,r,i=0)=>{const o=this.getSize(),s=this.getScrollOffset();r==="auto"&&(r=n>=s+o?"end":"start"),r==="center"?n+=(i-o)/2:r==="end"&&(n-=o);const a=this.options.horizontal?"scrollWidth":"scrollHeight",c=(this.scrollElement?"document"in this.scrollElement?this.scrollElement.document.documentElement[a]:this.scrollElement[a]:0)-o;return Math.max(Math.min(c,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.measurementsCache[n];if(!i)return;const o=this.getSize(),s=this.getScrollOffset();if(r==="auto")if(i.end>=s+o-this.options.scrollPaddingEnd)r="end";else if(i.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];const a=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,r,i.size),r]},this.isDynamicMode=()=>this.elementsCache.size>0,this.cancelScrollToIndex=()=>{this.scrollToIndexTimeoutId!==null&&this.targetWindow&&(this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId),this.scrollToIndexTimeoutId=null)},this.scrollToOffset=(n,{align:r="start",behavior:i}={})=>{this.cancelScrollToIndex(),i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(n,r),{adjustments:void 0,behavior:i})},this.scrollToIndex=(n,{align:r="auto",behavior:i}={})=>{n=Math.max(0,Math.min(n,this.options.count-1)),this.cancelScrollToIndex(),i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");const o=this.getOffsetForIndex(n,r);if(!o)return;const[s,a]=o;this._scrollToOffset(s,{adjustments:void 0,behavior:i}),i!=="smooth"&&this.isDynamicMode()&&this.targetWindow&&(this.scrollToIndexTimeoutId=this.targetWindow.setTimeout(()=>{if(this.scrollToIndexTimeoutId=null,this.elementsCache.has(this.options.getItemKey(n))){const[c]=_f(this.getOffsetForIndex(n,a));$B(c,this.getScrollOffset())||this.scrollToIndex(n,{align:a,behavior:i})}else this.scrollToIndex(n,{align:a,behavior:i})}))},this.scrollBy=(n,{behavior:r}={})=>{this.cancelScrollToIndex(),r==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+n,{adjustments:void 0,behavior:r})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((n=r[r.length-1])==null?void 0:n.end)??0;else{const o=Array(this.options.lanes).fill(null);let s=r.length-1;for(;s>0&&o.some(a=>a===null);){const a=r[s];o[a.lane]===null&&(o[a.lane]=a.end),s--}i=Math.max(...o.filter(a=>a!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:i})=>{this.options.scrollToFn(n,{behavior:i,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.notify(!1)},this.setOptions(e)}}const OE=(t,e,n,r)=>{for(;t<=e;){const i=(t+e)/2|0,o=n(i);if(o<r)t=i+1;else if(o>r)e=i-1;else return i}return t>0?t-1:0};function XB({measurements:t,outerSize:e,scrollOffset:n,lanes:r}){const i=t.length-1;let s=OE(0,i,l=>t[l].start,n),a=s;if(r===1)for(;a<i&&t[a].end<n+e;)a++;else if(r>1){const l=Array(r).fill(0);for(;a<i&&l.some(u=>u<n+e);){const u=t[a];l[u.lane]=u.end,a++}const c=Array(r).fill(n+e);for(;s>0&&c.some(u=>u>=n);){const u=t[s];c[u.lane]=u.start,s--}s=Math.max(0,s-s%r),a=Math.min(i,a+(r-1-a%r))}return{startIndex:s,endIndex:a}}const Hv=typeof document<"u"?hi.useLayoutEffect:hi.useEffect;function YB(t){const e=hi.useReducer(()=>({}),{})[1],n={...t,onChange:(i,o)=>{var s;o?co.flushSync(e):e(),(s=t.onChange)==null||s.call(t,i,o)}},[r]=hi.useState(()=>new JB(n));return r.setOptions(n),Hv(()=>r._didMount(),[]),Hv(()=>r._willUpdate()),r}function QB(t){return YB({observeElementRect:qB,observeElementOffset:WB,scrollToFn:GB,...t})}function ZB(t,e){const{rows:n}=t.getRowModel(),r=QB({getScrollElement:()=>e,count:n.length,estimateSize:()=>35,overscan:10});return{rows:n,virtualRows:r.getVirtualItems(),totalSize:r.getTotalSize(),virtualizer:r}}function e$(t,e){const n=t.getIsPinned(),r=n==="left"&&t.getIsLastColumn("left"),i=n==="right"&&t.getIsFirstColumn("right");return{shadow:r?"-2px 0 2px -2px gray inset":i?"2px 0 2px -2px gray inset":void 0,start:n==="left"?`${t.getStart("left")}px`:void 0,end:n==="right"?`${t.getAfter("right")}px`:void 0,position:n?"sticky":"relative",w:t.getSize(),z:n?1:0,bgColor:n?e?"gray.50":"white":e?"gray.50":void 0}}function t$({table:t,containerRef:e,onRowClick:n,disabledRow:r}){var u,d;const{rows:i,virtualRows:o,totalSize:s,virtualizer:a}=ZB(t,e),l=o.length>0&&((u=o==null?void 0:o[0])==null?void 0:u.start)||0,c=o.length>0?s-(((d=o==null?void 0:o[o.length-1])==null?void 0:d.end)||0):0;return y.jsxs("tbody",{children:[l>0&&y.jsx("tr",{children:y.jsx("td",{h:`${l}px`})}),o.map(h=>{const f=i[h.index],p=n$(f.original,r);return y.jsx("tr",{borderB:"px",borderBColor:"#F4F4F4",borderStyle:"dashed",hover_bgColor:"slate-50",cursor:n?"pointer":"default",onClick:n?()=>n(f.original):void 0,w:"fit-content",group:!0,children:f.getVisibleCells().map((g,m)=>y.jsx("td",{px:"3",py:"2",textSize:"sm",textColor:p?"gray.400":"gray.700",fontWeight:"500",borderTColor:"--bg-3",borderT:"0.5",cursor:n&&!p?"pointer":"default",w:`${g.column.getSize()}px`,groupHover_bgColor:p?void 0:"gray.100",...e$(g.column,p),children:TE(g.column.columnDef.cell,g.getContext())},g.id))},f.id)}),c>0&&y.jsx("tr",{children:y.jsx("td",{h:`${c}px`})})]})}function n$(t,e){return e?typeof e=="string"?t[e]:e(t):!1}function r$({headers:t}){const e=Fe.useThemeAwareColor("slate-500","slate-700");return y.jsx("thead",{children:t.map(n=>y.jsx("tr",{w:"fit",children:n.headers.map(r=>y.jsx("th",{position:"relative",colSpan:r.colSpan,textAlign:"start",fontWeight:"600",textColor:e,px:"3",py:"2",textSize:"sm",w:`${r.getSize()}px`,children:y.jsxs("div",{dflex:!0,flexRow:!0,children:[r.isPlaceholder?null:y.jsxs(y.Fragment,{children:[TE(r.column.columnDef.header,r.getContext()),y.jsx("span",{cursor:r.column.getCanSort()?"pointer":"default",onClick:r.column.getToggleSortingHandler(),opacity:"0",hover_opacity:"100",flexGrow:!0,textAlign:"end",children:{asc:y.jsx(y.Fragment,{children:" ▲"}),desc:y.jsx(y.Fragment,{children:" ▼"})}[r.column.getIsSorted()]??y.jsx(y.Fragment,{children:" ▲"})})]}),y.jsx("div",{onMouseDown:r.getResizeHandler(),onTouchStart:r.getResizeHandler(),onClick:i=>{i.preventDefault(),i.stopPropagation()},position:"absolute",end:"0",top:"0",h:"full",w:"2",bgColor:r.column.getIsResizing()?"primary-500":"slate-900",bgOpacity:r.column.getIsResizing()?"70":"30",cursor:"col-resize",userSelect:"none",style:{touchAction:"none"},opacity:r.column.getIsResizing()?"100":"0",hover_opacity:"100"})]})},r.id))},n.id))})}const[i$,Mg]=Fe.createContext();function o$({initialPageSize:t,children:e}){const[n,r]=rn.useSearchParams(),{pageIndex:i,pageSize:o}=A.useMemo(()=>({pageIndex:n.get("page")??1,pageSize:n.get("sizePerPage")??t??25}),[n,t]),s=A.useCallback(c=>{const u=Fe.runIfFn(c,{pageIndex:i,pageSize:o});r(d=>(d.set("page",`${u.pageIndex}`),d.set("sizePerPage",`${u.pageSize}`),d))},[r,i,o]),a=i$,l={pageIndex:typeof i=="string"?parseInt(i):i,pageSize:typeof o=="string"?parseInt(o):o,setPagination:s};return y.jsx(a,{value:l,children:e})}function kE({page:t,...e}){const{pageSize:n,pageIndex:r,setPagination:i}=Mg(),o=A.useCallback(()=>i({pageIndex:1,pageSize:n}),[n,i]);return y.jsxs("div",{dflex:!0,flexCol:!0,gap:"10",w:"full",h:"full",alignItems:"center",placeContent:"center",py:"16",...e,children:[y.jsx(N.Icon,{path:l_,w:"24",h:"24",textColor:"gray.400"}),y.jsx("div",{textSize:"xl",textColor:"gray.600",children:"No Data"}),t>1&&y.jsx(N.Button,{onClick:o,children:"Back To First Page"})]})}function s$({table:t,isLoading:e}){const n=t.getPageCount(),r=t.getState().pagination.pageIndex+1,i=a$(r,n,5);return y.jsxs(y.Fragment,{children:[n<2&&y.jsx(y.Fragment,{}),n>1&&y.jsx(y.Fragment,{children:y.jsxs("div",{dflex:!0,flexRow:!0,spaceX:"2",py:"2",children:[y.jsx(Li,{onClick:()=>t.setPageIndex(0),disabled:e||r==1,children:y.jsx(N.Icon,{path:YE})}),y.jsx(Li,{onClick:()=>t.previousPage(),disabled:e||r==1,children:y.jsx(N.Icon,{path:e_})}),i.length>0&&i[0]>1&&y.jsx("a",{children:"..."}),i.map(o=>y.jsx(Li,{onClick:()=>t.setPageIndex(o-1),disabled:e,variant:r==o?"default":"glass",scheme:"secondary",children:o},o)),i.length>0&&i[i.length-1]<n&&y.jsx(Li,{disabled:e,children:"..."}),y.jsx(Li,{onClick:()=>t.nextPage(),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:t_})}),y.jsx(Li,{onClick:()=>t.setPageIndex(t.getPageCount()-1),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:QE})})]})})]})}function Li({...t}){return y.jsx(N.Button,{scheme:"secondary",variant:"glass",corners:"pill",w:"8",h:"8",p:"0",dflex:!0,alignItems:"center",placeContent:"center",...t})}function a$(t,e,n){const r=[];if(!t)return r;if(e===1)return r.push(1),r;if(e<t)return r;if(e<n+1){for(let o=1;o<e+1;o++)r.push(o);return r}if(t===1){for(let o=1;o<n+1;o++)o<e&&r.push(o);return r}if(t===e){for(let o=e-n+1;o<=e;o++)o<=e&&r.push(o);return r}const i=Math.floor(n/2);if(i<1)return r.push(t),r;if(t<i+2){for(let o=1;o<n+1;o++)r.push(o);return r}if(e-t<i+2){for(let o=e-n;o<e+1;o++)r.push(o);return r}for(let o=t-i;o<t;o++)o>0&&r.push(o);r.push(t);for(let o=t+1;o<t+i+1;o++)o<=e&&r.push(o);return r}const l$=[{label:"25",value:25},{label:"50",value:50},{label:"100",value:100}];function c$({table:t,total:e,isLoading:n,reverseOrder:r,sizePerPageList:i}){const o=t.getState().pagination.pageIndex,s=t.getState().pagination.pageSize;return y.jsxs("div",{dflex:!0,flexDirection:r?"row-reverse":"row",alignItems:"center",py:"3",spaceX:"3",children:[y.jsx(N.Select,{disabled:e===0||n,onChange:a=>t.setPageSize(Number(a.target.value)),value:s,w:"20",children:(i??l$).map(a=>{const l=s===a.value;return y.jsx("option",{value:a.value,className:`btn ${l?"active":""}`,children:a.label},a.label)})}),y.jsxs("div",{children:["Showing rows ",1+o*s," to ",Math.min((o+1)*s,e)," of ",e]}),n&&y.jsx(N.Spinner,{size:"sm"})]})}function ME({isLoading:t,table:e,total:n,show:r,toolbarPosition:i="both",reverseOrder:o=!1,sizePerPageList:s,children:a,...l}){return y.jsxs("div",{...l,children:[r&&["top","both"].includes(i)&&y.jsx(Bv,{isLoading:t,table:e,total:n,reverseOrder:o,sizePerPageList:s}),a,r&&["bottom","both"].includes(i)&&y.jsx(Bv,{isLoading:t,table:e,total:n,reverseOrder:o,sizePerPageList:s})]})}function Bv({isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:i}){return y.jsxs("div",{dflex:!0,justifyContent:"between",alignItems:"center",flexWrap:!0,flexDirection:r?"row-reverse":"row",children:[y.jsx(c$,{isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:i}),y.jsx("div",{className:"d-flex flex-wrap"}),y.jsx(s$,{isLoading:t,table:e})]})}const[u$,PE]=Fe.createContext();function d$({sortBy:t,sortDir:e,children:n}){const[r,i]=rn.useSearchParams(),{sortBy:o,sortDir:s}=A.useMemo(()=>({sortBy:r.get("sortBy")??t??"",sortDir:r.get("sortDir")??e??"asc"}),[r]),a=A.useCallback(u=>{const d=Fe.runIfFn(u,[{id:o,desc:s==="desc"}]);i(h=>{var f,p;return h.set("sortBy",`${((f=d==null?void 0:d[0])==null?void 0:f.id)??""}`),h.set("sortDir",`${(p=d==null?void 0:d[0])!=null&&p.desc?"desc":"asc"}`),h})},[i,o,s]),l=u$,c={sortBy:o,sortDir:s,setSorting:a};return y.jsx(l,{value:c,children:n})}function f$(t,e,n){const{setPagination:r}=Mg(),{sortBy:i,sortDir:o,setSorting:s}=PE(),[a,l]=A.useState((n==null?void 0:n.rowSelection)??{}),c=A.useCallback(h=>{var f;l(h),(f=n==null?void 0:n.onSelectionChange)==null||f.call(n,Fe.runIfFn(h,a))},[l,a]),u=A.useCallback(h=>{var f;if(n!=null&&n.enableSelection&&(n!=null&&n.enableSelectOnRowClick)){h.toggleSelected();return}(f=n==null?void 0:n.onRowClick)==null||f.call(n,h.original)},[]);return{table:BB(ko({data:t??[],getRowId:h=>h.id,columns:e,columnResizeMode:"onChange",enableColumnResizing:!0,enableSortingRemoval:!1,defaultColumn:{size:150,minSize:40,maxSize:1e3},state:{sorting:[{id:i,desc:o==="desc"}],rowSelection:a},filterFns:{},enableRowSelection:n==null?void 0:n.enableSelection,onRowSelectionChange:c,onSortingChange:s,getCoreRowModel:PB(),getFilteredRowModel:NB(),onPaginationChange:r},n==null?void 0:n.tableOptions)),onRowClick:u}}const IE=A.createContext({});function Yc(){return A.useContext(IE)}const h$=["sortBy","sortDir","page","sizePerPage"];function p$({sortBy:t,sortDir:e,initialPageSize:n,children:r}){const[i,o]=rn.useSearchParams(),s=A.useCallback(h=>{o(f=>(Object.keys(h).forEach(p=>{f.set(p,h[p]===void 0?"":h[p])}),f.set("page","1"),f))},[o]),a=A.useCallback(()=>{const h={},f=i.entries();for(const[p,g]of f)h$.includes(p)||(h[p]=g);return h},[i]),[l,c]=A.useState(),d={ids:A.useMemo(()=>{const h=Object.keys(l??{});return(h==null?void 0:h.filter(f=>l==null?void 0:l[f]))??[]},[l]),setRowSelection:c,getFilters:a,setFilters:s};return y.jsx(IE.Provider,{value:d,children:y.jsx(o$,{initialPageSize:n,children:y.jsx(d$,{sortBy:t,sortDir:e,children:r})})})}function g$(t,e,n){const r=je.useInvalidateQuery(t),i=A.useMemo(()=>({onError:()=>Ne.error((n==null?void 0:n.errorMessage)??"Oops, something went wrong :("),refetchOnWindowFocus:!1,keepPreviousData:!0,retry:!1,staleTime:1e8}),[n]),{pageIndex:o,pageSize:s,setPagination:a}=Mg(),{sortBy:l,sortDir:c}=PE(),{getFilters:u}=Yc(),d={pageSize:s,pageNumber:o,sortBy:l,sortDir:c,...n!=null&&n.transformFilters?n.transformFilters(u()):u()},h=A.useMemo(()=>({...i,...n==null?void 0:n.queryOptions}),[n]),{data:f,isError:p,isFetching:g,isLoading:m}=je.useApiQuery(t,e,d,h),v=A.useCallback(r,[r]),{data:x}=f??{data:{data:void 0,meta:void 0}},{data:w,meta:b}=x;return{data:w&&(n!=null&&n.transformResponse)?n.transformResponse(w):w,response:x,retry:v,isError:p,isLoading:m,isFetching:g,page:(b==null?void 0:b.current_page)??1??o,pageSize:(b==null?void 0:b.per_page)??s,total:(b==null?void 0:b.total)??0,onPaginationChange:a}}function m$({columns:t,keyField:e="id",queryKey:n,queryFn:r,queryOptions:i,errorMessage:o,transformFilters:s,transformResponse:a,defaultSorted:l="name",defaultSortOrder:c="desc",nonSelectable:u,enableFilters:d=!1,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,onRowClick:g,onSelectionChange:m,sizePerPageList:v,paginationPosition:x,reversePaginationTools:w,containerEl:b,emptyMessage:S,title:C,disabledRow:_,pinnedColumnsLeft:E,pinnedColumnsRight:R,...T}){const O=A.useRef(null),{data:k,response:P,retry:M,isError:j,isLoading:z,isFetching:B,page:J,pageSize:K,total:D,onPaginationChange:Q}=g$(n,r,{errorMessage:o,queryOptions:i,transformResponse:a,transformFilters:s}),oe=f$(k??[],b$(t,h),{defaultSorted:l,defaultSortOrder:c,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,nonSelectable:u,onRowClick:g,onSelectionChange:m,tableOptions:{enableColumnFilters:d,initialState:{columnPinning:{left:E??[],right:R??[]}},state:{pagination:{pageIndex:J,pageSize:K}},autoResetPageIndex:!1,pageCount:Math.ceil(D/K),onPaginationChange:Q}}).table;return y.jsxs("div",{px:"8",pt:"8",ref:O,h:"100%",children:[j&&y.jsx(xi,{onClick:M,label:o}),(z||B&&(!k||(k==null?void 0:k.length)==0))&&y.jsx(Br,{}),!j&&!z&&k&&y.jsxs("div",{children:[C&&(Fe.isFunction(C)?C(P):C),T.mode=="table"&&y.jsx(y$,{table:oe,total:D??0,data:k,isLoading:B,containerEl:b??O.current,onRowClick:g,sizePerPageList:v,disabledRow:_}),T.mode=="grid"&&y.jsx(v$,{table:oe,total:D??0,data:k,isLoading:B,onRowClick:g,sizePerPageList:v,gridCols:T.gridCols,renderGridItem:T.renderGridItem})]})]})}function y$({table:t,total:e,data:n,isLoading:r,onRowClick:i,containerEl:o,sizePerPageList:s,disabledRow:a}){return y.jsxs(ME,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:s,children:[n.length==0&&y.jsx(kE,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",border:"2px",borderColor:"#F4F4F4",rounded:"base",my:"3",overflowX:"auto",children:y.jsxs("table",{style:{width:"max(1400px, 100%)",tableLayout:"fixed"},children:[y.jsx(r$,{headers:t.getHeaderGroups()}),y.jsx(t$,{table:t,containerRef:o,onRowClick:i,disabledRow:a})]})})]})}function v$({table:t,total:e,data:n,isLoading:r,onRowClick:i,sizePerPageList:o,gridCols:s,renderGridItem:a}){return y.jsxs(ME,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:o,children:[n.length==0&&y.jsx(kE,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",children:y.jsx("div",{grid:!0,gridCols:`${s??3}`,gap:"5",w:"full",children:n.map(l=>a==null?void 0:a(l,i))})})]})}function b$(t,e){return e?[{id:"select-col",header:({table:n})=>y.jsx(N.Checkbox,{checked:n.getIsAllRowsSelected(),onChange:n.getToggleAllRowsSelectedHandler()}),cell:({row:n})=>y.jsx(N.Checkbox,{checked:n.getIsSelected(),disabled:!n.getCanSelect(),onChange:n.getToggleSelectedHandler()}),size:10,maxSize:1,enableResizing:!1}].concat(t):t}const[w$,S$]=Fe.createContext();function $v(t){return t.accessorKey??t.id}function x$({initialVisibleColumns:t,columns:e,children:n}){const[r,i]=A.useState(!1),[o,s]=A.useState(!1),[a,l]=A.useState(t??(e==null?void 0:e.map(p=>$v(p)))??[]),c=(e==null?void 0:e.filter(p=>a.includes($v(p))))??[],u=A.useCallback(p=>{const g=a.indexOf(p);if(g>-1){const m=a.concat();m.splice(g,1),l(m)}else l(a.concat(p))},[a,l]),d=A.useCallback(p=>a.includes(p),[a]),h=w$,f={showFilters:r,setShowFilters:i,showMassActions:o,setShowMassActions:s,columns:e??[],filteredColumns:c,toggleColumnVisibility:u,isColumnVisible:d};return y.jsx(h,{value:f,children:n})}function LE({initialPageSize:t,initialVisibleColumns:e,columns:n,children:r,...i}){return y.jsx(N.Tile,{scheme:"light",shadow:!0,rounded:"md",px:"0",py:"4",w:"full",dflex:!0,flexCol:!0,...i,children:y.jsx(p$,{initialPageSize:t,children:y.jsx(x$,{columns:n,initialVisibleColumns:e,children:r})})})}function DE({children:t,...e}){return y.jsx(cc,{scheme:"default",corners:"pill",h:"10",variant:"glass",...e,children:t??y.jsx(N.Icon,{path:w_})})}function NE({...t}){return y.jsxs(N.Popover,{side:"bottom-end",modal:!0,children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",...t,children:y.jsx(N.Icon,{path:a_})}),y.jsxs("div",{bgColor:"white",rounded:!0,shadow:!0,children:[y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"First Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Second Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Third Item"})]})]})}function jE({title:t,queryKey:e,children:n,...r}){const i=je.useInvalidateQuery(e);return cw("ctrl+r",()=>i(),{preventDefault:!0},[i]),y.jsxs("div",{dflex:!0,flexRow:!0,pb:"4",alignItems:"center",gap:"3",px:"8",borderB:"0.5",borderBColor:"--bg-2",...r,children:[t&&y.jsx("h2",{textSize:"x3",fontWeight:"600",textColor:"#3f4254",textTransform:"capitalize",children:t}),y.jsx("div",{flexGrow:!0,children:" "}),y.jsxs("div",{spaceX:"2",dflex:!0,alignItems:"center",children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",onClick:i,children:y.jsx(N.Icon,{path:sb})}),n]})]})}const Vv="Oops, something went wrong...";function zv(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function Pg({initialValues:t,itemLabel:e,queryId:n="",api:r,queryFetchOptions:i,querySaveOptions:o,onSuccess:s,onFetchError:a,fetchErrorMsg:l=Vv,onSaveError:c,saveErrorMsg:u=Vv,fetchToFormData:d,formToQueryData:h,invalidateQueriesOnSuccess:f=!0,invalidateQueryKey:p,retryText:g="Retry",cancelLabel:m="Cancel",saveLabel:v,size:x="lg",title:w,form:b,show:S,onClose:C,formikProps:_,...E}){const{isInitialLoading:R,isFetching:T,data:O,isError:k,error:P,refetch:M}=je.useApiQuery(r.queryKey,r.get,n,{enabled:!(n==""||n==null||n==null),onError:a,...i}),j=f?je.useInvalidateParentMutation(r.upsert,p??r.queryKey,o):je.useApiMutation(r.upsert,r.queryKey,n,o),z=A.useCallback(()=>M(),[M]),B=A.useCallback(async(J,K)=>{j.reset();const D=h?h(J):{...J};await j.mutateAsync(D).then(Q=>{s?s(D,Q):Ne.success(`${w?w(D):D.name??D.title} ${n?"saved":"created"}`),C==null||C()}).catch(Q=>{console.error("on error",Q),c?c(J):Ne.error(`Couldn't save ${w?w(D):D.name??D.title}`),K.setSubmitting(!1)})},[j,h,s,c,C]);return y.jsxs(N.Modal,{size:x,show:S,onClose:C,scheme:"light",transition:!0,...E,children:[y.jsxs(N.Modal.Header,{children:[!R&&n&&`Edit ${w?w(O):(O==null?void 0:O.name)??(O==null?void 0:O.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(b)&&y.jsx(y.Fragment,{})]}),R&&y.jsx(N.Modal.Body,{children:y.jsx(Br,{minW:"72"})}),k&&y.jsx(N.Modal.Body,{children:y.jsx(xi,{label:`${l} ${P}`,onClick:z})}),!R&&!k&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:d&&n&&O?d(zv(O)):zv(t(O))??{},onSubmit:B,..._,children:({setFieldValue:J,dirty:K,handleSubmit:D,isValid:Q,values:se})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[A.isValidElement(b)&&b,Array.isArray(b)&&y.jsx(Mr,{form:b}),Fe.isFunction(b)&&y.jsx(Mr,{form:b(O??se)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:j.isLoading,onClick:C,variant:"borderless",me:"2",children:m}),y.jsx(N.Button,{type:"submit",disabled:!K||j.isLoading,onClick:()=>D(),children:v||(n?"Update":"Create")})]})]})})}),j.isLoading&&y.jsx(Ps,{})]})}function C$({api:t,fn:e,transformFn:n,config:r,onClose:i,queryId:o,invalidateQueryKey:s}){const{data:a,isFetching:l}=je.useApiQuery(t.queryKey,e==="get"||e==="getTransformed"?t.get:t.getAll,void 0,{retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1}),c=A.useMemo(()=>a&&(e==="getTransformed"||e==="getAllTransformed")?(n||console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${e}`),n==null?void 0:n(a)):a,[a,e,n]);return l?null:y.jsx(Pg,{...r(c),queryId:o,invalidateQueryKey:s,show:!0,onClose:i})}function E$({queries:t,config:e,onClose:n,queryId:r,invalidateQueryKey:i}){const{data:o,isFetching:s,isError:a}=je.useApiQueries(t.map(c=>({queryKey:c.api.queryKey,queryFn:c.fn=="get"?c.api.get:c.api.getAll,queryOptions:{cacheTime:c.cache===!1?0:void 0,staleTime:c.cache===!1?0:void 0}}))),l=A.useMemo(()=>o==null?void 0:o.map((c,u)=>{var d,h;return t[u].transformFn?(h=(d=t[u])==null?void 0:d.transformFn)==null?void 0:h.call(d,c):c}),[o,t]);return y.jsx(Pg,{isPreloading:s,...e(...l),queryId:r,invalidateQueryKey:i,show:!0,onClose:n})}function FE({config:t,onClose:e,invalidateQueryKey:n,queryId:r}){const{type:i,...o}=t;return t.type==="dialog"?y.jsx(Pg,{...o,queryId:r,invalidateQueryKey:n,show:!0,onClose:e}):t.type==="query"?y.jsx(C$,{...o,queryId:r,invalidateQueryKey:n,onClose:e}):t.type==="multiQuery"?y.jsx(E$,{...o,queryId:r,invalidateQueryKey:n,onClose:e}):null}function _$({itemLabel:t,queryId:e="",api:n,invalidateQueriesOnSuccess:r=!0,invalidateQueryKey:i,size:o="lg",show:s,onClose:a,...l}){const c=r?je.useInvalidateParentMutation(n.delete,i??n.queryKey):je.useApiMutation(n.upsert,n.queryKey),u=je.useMutate(c,{onSuccess:()=>a==null?void 0:a()}),d=A.useCallback(()=>u(e),[u,e]);return y.jsxs(N.Modal,{size:o,show:s,onClose:a,scheme:"danger",variant:"glass",transition:!0,...l,children:[y.jsx(N.Modal.Header,{children:`Delete ${t}`}),y.jsxs(N.Modal.Body,{pb:"6",children:["Do you really want to delete ",t,"?"]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:c.isLoading,onClick:a,variant:"borderless",scheme:"secondary",me:"2",children:"Cancel"}),y.jsx(N.Button,{scheme:"danger",disabled:c.isLoading,onClick:d,children:"Delete"})]}),c.isLoading&&y.jsx(Ps,{})]})}const[R$,HE]=Fe.createContext();function A$({editView:t,deleteItem:e,queryKey:n,children:r}){const i=Xb(),o=rn.useNavigate(),[s,a]=A.useState(null),l=A.useCallback(()=>a(null),[a]),c=A.useCallback((h,f)=>{switch(h.type){case"view":{o(Fe.runIfFn(h.path,f));break}case"link":{i(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(h.path,f)}`);break}case"edit":{t.type=="customDialog"?a(t.render({show:!0,onClose:l})):a(y.jsx(FE,{onClose:l,config:t,queryId:f.id,invalidateQueryKey:n}));break}case"delete":{a(y.jsx(_$,{show:!0,onClose:l,queryId:f.id,invalidateQueryKey:n,...e,itemLabel:Fe.runIfFn(e.itemLabel,f)}));break}}},[o,t,e]),u=R$,d={dialog:s,onAction:c};return y.jsx(u,{value:d,children:r})}function T$({id:t,api:e,status:n,invalidateQueryKey:r,...i}){const o=n=="draft",s=je.useInvalidateParentMutation(o?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=A.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>Ne.success(o?"Published!":"Unpublished!")).catch(c=>Ne.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...i,children:y.jsx(N.Icon,{path:o?ib:ob})})}function O$({row:t,onAction:e,rowActions:n,api:r,queryKey:i}){const o=t.original;return y.jsx("div",{dflex:!0,spaceX:"1",placeContent:"end",children:n==null?void 0:n.map((s,a)=>y.jsxs(A.Fragment,{children:[s.type==="publish"&&y.jsx(T$,{id:o.id,api:r,status:o.status,invalidateQueryKey:i}),s.type=="custom"&&y.jsx(y.Fragment,{children:s.component(o,i,s.icon,s.label)}),!["publish","custom"].includes(s.type)&&y.jsx(k$,{onClick:()=>e(s,o),scheme:P$[s.type],children:y.jsx(N.Icon,{path:M$[s.type]})})]},a))})}function k$({onClick:t,...e}){const n=A.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),t==null||t(r)},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",onClick:n,...e})}const M$={link:Jh,view:Gh,edit:rb,delete:Rf,publish:Rf,custom:""},P$={link:"dark",view:"secondary",edit:"warning",delete:"danger",publish:"warning",custom:"default"};function I$(t,e,n){const r=rn.useNavigate(),i=Xb(),{onAction:o}=HE(),{onRowClick:s,columns:a,...l}=e,c=A.useCallback(h=>{(s==null?void 0:s.type)==="navigate"?r(Fe.runIfFn(s.path,h)):(s==null?void 0:s.type)=="link"&&i(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(s.path,h)}`)},[r,s]),u=A.useMemo(()=>{const h=e.columns.concat([]);return n&&h.push(K4().display({id:"actions",header:"Actions",cell:f=>y.jsx(O$,{row:f.row,onAction:o,rowActions:n,api:t,queryKey:t.queryKey})})),h},[e]),d={...l};return d.columns=u,d.onRowClick=c,d.queryKey=t.queryKey,d.queryFn=t.search,d}function L$({form:t,initialValues:e,schema:n,processInput:r}){const{showFilters:i}=S$(),{getFilters:o,setFilters:s}=Yc(),a=A.useCallback((c,u)=>{const d=(r==null?void 0:r(c))??c;Kb(d,o())||s(d),u.setSubmitting(!1)},[s,r]),l=A.useCallback(c=>{s(e),c()},[s,e]);return A.useEffect(()=>s(e),[]),y.jsx(N.Collapse,{in:i,style:{overflow:i?"initial":"hidden"},children:y.jsx("div",{p:"8",borderT:"px",borderB:"px",borderColor:"slate-100",children:y.jsx(vc,{initialValues:rw(o(),e),onSubmit:a,validationSchema:n,enableReinitialize:!0,children:c=>y.jsxs("div",{dflex:!0,gap:"3",placeContent:"start",children:[y.jsx(Mr,{flexRow:!0,w:"auto",form:t}),y.jsx(D$,{handleReset:()=>l(c.resetForm)})]})})})})}function D$({handleReset:t}){return y.jsxs("div",{dflex:!0,gap:"3",children:[y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(wn,{name:"",label:" "}),y.jsx(gp,{children:"Filter"})]}),y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(wn,{name:"",label:" "}),y.jsx(N.Button,{scheme:"neutral",onClick:t,children:"Reset"})]})]})}function N$({label:t,buttonProps:e,icon:n,queryKey:r,queryFn:i,successMsg:o,errorMsg:s,invalidateParent:a}){const l=a?je.useInvalidateParentMutation(i,r):je.useApiMutation(i,r),c=je.useMutate(l,{successMsg:o,errorMsg:s});return y.jsxs(N.Button,{display:"flex",alignItems:"center",gap:"3",...e,onClick:c,disabled:l.isLoading,children:[n&&y.jsx(N.Icon,{path:n}),t]})}function j$({actions:t}){const{ids:e}=Yc(),n=e&&e.length>0;return y.jsx(N.Collapse,{in:n,style:{overflow:n?"initial":"hidden"},children:y.jsx("div",{dflex:!0,gap:"3",flexWrap:!0,alignItems:"center",px:"8",pt:"5",children:t.map((r,i)=>y.jsx("div",{children:r.type=="button"&&!r.showConfirmationDialog&&y.jsx(N$,{label:r.label,queryFn:r.queryFn,queryKey:r.queryKey,buttonProps:r.buttonProps})},i))})})}function F$(t){const e=rn.useParams();if(t===void 0)return;const{[t]:n}=e;return n}function H$({queryField:t,title:e,subtitle:n,screen:r,...i}){const o=F$(t),s=Fe.runIfFn(r,o);return y.jsx(bc,{p:"5",...i,children:y.jsx(LE,{columns:s.table.columns,initialVisibleColumns:s.table.initialVisibleColumns,children:y.jsx(B$,{id:o,title:e,subtitle:n,screen:s})})})}function B$({id:t,title:e,subtitle:n,screen:r}){const{setRowSelection:i}=Yc(),{api:o,table:s,filters:a,massActions:l,buttonBar:c,rowActions:u,createView:d,editView:h,deleteItem:f,breadcrumbs:p}=r,g=Fe.runIfFn(o,t??"");return y.jsxs(y.Fragment,{children:[p&&y.jsx(Rg,{breadcrumbs:p}),y.jsxs(jE,{title:e,queryKey:g.queryKey,children:[y.jsx($$,{buttonBar:c,createView:d,editView:h,api:g}),a&&y.jsx(NE,{})]}),a&&y.jsx(L$,{form:a.form,initialValues:a.initialValues,schema:a.schema,processInput:a.processInput}),l&&y.jsx(j$,{actions:l.items}),y.jsxs(A$,{queryKey:g.queryKey,editView:h,deleteItem:f,children:[y.jsx(V$,{table:{...s,onSelectionChange:i},rowActions:u,api:g,subtitle:n}),y.jsx(z$,{})]})]})}function $$({buttonBar:t,createView:e,editView:n,api:r}){const i=A.useCallback(o=>{const s=e??n;return s.type=="customDialog"?s.render({show:!0,onClose:o}):y.jsx(FE,{config:s,onClose:o,invalidateQueryKey:r.queryKey})},[n,r]);return y.jsx(y.Fragment,{children:t&&t.map((o,s)=>y.jsxs("div",{children:[o.type==="create"&&n&&y.jsx(DE,{buildDialog:i}),o.type==="invalidate"&&y.jsx(up,{pathOrPermalink:o.pathOrPermalink}),o.type==="custom"&&o.render()]},s))})}function V$({table:t,subtitle:e,rowActions:n,api:r}){const i=I$(r,t,n),o=A.useMemo(()=>{if(e)return s=>y.jsx("div",{textSize:"lg",textColor:"#475569",fontWeight:"600",children:Fe.isFunction(e)?e(s):e})},[e]);return y.jsx(m$,{...i,title:o})}function z$(){const{dialog:t}=HE();return t}function U$(t){const e=rn.useParams(),{data:n,isFetching:r,isError:i}=je.useApiQueries(t.map(s=>{if(!s.queryField||!Fe.isFunction(s.api)){const c=s.api;return{queryKey:c.queryKey,queryFn:s.fn=="get"?c.get:c.getAll,queryParam:s.params}}const a=e[s.queryField],l=Fe.runIfFn(s.api,a);return{queryKey:l.queryKey,queryFn:s.fn=="get"?l.get:l.getAll,queryParam:s.fn=="getAll"?s.params:Fe.isFunction(s.api)?void 0:a}}));let o;return!r&&!i&&(o=n==null?void 0:n.map((s,a)=>{var l,c;return t[a].transformFn?(c=(l=t[a]).transformFn)==null?void 0:c.call(l,s):s})),{data:o,isFetching:r,isError:i}}function q$(t){const e=Kv.useQueryClient(),n=rn.useParams();return A.useCallback(()=>{const i=[];t.forEach(o=>{if(!o.queryField||!Fe.isFunction(o.api))i.push(o.api.queryKey);else{const s=n[o.queryField],a=Fe.runIfFn(o.api,s);i.push(a.queryKey)}}),e.invalidateQueries({predicate:o=>i.includes(o.queryKey)})},[t,e,n])}function W$({queries:t,config:e,tabbed:n,...r}){const{data:i,isFetching:o,isError:s}=U$(t),a=q$(t);return o?y.jsx(Br,{w:"full",h:"100vh"}):s||!i?y.jsx(xi,{p:"0",w:"full",h:"100vh",onClick:a}):y.jsx(Qc,{config:e(...i),tabbed:n,...r})}function Qc({config:t,tabbed:e,...n}){return t.type==="table"?y.jsx(H$,{...t,...n}):t.type==="tabbed"?y.jsx(q4,{...t,...n}):t.type==="details"?y.jsx(B4,{...t,tabbed:e,...n}):t.type==="query"?y.jsx(U4,{...t,tabbed:e,...n}):t.type==="multiQuery"?y.jsx(W$,{...t,tabbed:e,...n}):y.jsx(y.Fragment,{})}const Uv="Oops, something went wrong...";function K$({queryId:t,queryKey:e,queryFetchFn:n,queryFetchAllKey:r,queryFetchAllFn:i,querySaveFn:o,matchKey:s,size:a="lg",show:l,onClose:c,itemLabel:u,onSuccess:d,onFetchError:h,fetchErrorMsg:f=Uv,onSaveError:p,saveErrorMsg:g=Uv,invalidateQueriesOnSuccess:m=!0,retryText:v="Retry",cancelLabel:x="Cancel",saveLabel:w,formikProps:b,getItemName:S,...C}){const _=Kv.useQueryClient(),{data:E,isInitialLoading:R,isError:T,refetch:O,error:k}=je.useApiQuery(e,n),{data:P,isInitialLoading:M,isError:j,refetch:z,error:B}=je.useApiQuery(r,i),[J,K]=A.useState([]),D=R||M,Q=T||j,se=je.useApiMutation(o,e,t),oe=A.useCallback(L=>{const ce=(L==null?void 0:L.currentTarget.dataset.id)??"",me=J.concat([]),be=J.indexOf(ce);be!=-1?me.splice(be,1):me.push(ce),K(me)},[J,K]),de=A.useCallback(()=>{T&&O(),j&&z()},[O,z,T,j]),ue=A.useCallback(()=>{se.reset(),se.mutateAsync({resources:J}).then(L=>{d?d(L):Ne.success(`${u} saved`),m&&_.invalidateQueries({queryKey:e}),c==null||c()}).catch(L=>{console.error("on error",L),p?p():Ne.error(`Error adding ${u}`)})},[se,t,d,_,p,c]),pe=A.useMemo(()=>{let L=[];return E&&P&&(L=[].concat(P),E.forEach(ce=>L.splice(L.findIndex(me=>me.id==ce[s]),1)),S&&(L=L.map(ce=>({...ce,name:S(ce)}))),L=nT(L,["name"])),L},[E,P]);return y.jsxs(N.Modal,{size:a,show:l,onClose:c,scheme:"light",transition:!0,...C,children:[y.jsx(N.Modal.Header,{children:`Add ${u}`}),D&&y.jsx(N.Modal.Body,{children:y.jsx(Br,{minW:"72"})}),Q&&y.jsx(N.Modal.Body,{children:y.jsx(xi,{label:`${f} ${k}`,onClick:de})}),!D&&!Q&&y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{px:"0",pb:"6",maxH:"750px",overflow:"auto",children:y.jsx("div",{dflex:!0,flexCol:!0,overflow:"auto",children:pe.map(L=>y.jsx(G$,{label:L.name,value:L.id,"data-id":L.id,checked:J.includes(`${L.id}`),onClick:oe},L.id))})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:se.isLoading,onClick:c,variant:"borderless",me:"2",children:x}),y.jsx(N.Button,{type:"submit",disabled:J.length==0||se.isLoading,onClick:ue,children:w||(t?"Update":"Create")})]})]}),se.isLoading&&y.jsx(Ps,{})]})}function G$({label:t,value:e,checked:n,...r}){return y.jsxs("div",{dflex:!0,alignItems:"center",hover_bgColor:"slate-100",px:"5",py:"2",cursor:"pointer",...r,children:[y.jsx("span",{flexGrow:!0,children:t}),y.jsx(N.Checkbox,{name:`resources.${e}`,value:e,checked:n})]})}function J$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFn:i,queryOptions:o,onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h,invalidateQueriesOnSuccess:f=!0,cancelLabel:p="Cancel",saveLabel:g="Send",size:m="lg",title:v,form:x,show:w,onClose:b,formikProps:S,...C}){const _=f?je.useInvalidateParentMutation(i,r,o):je.useApiMutation(i,r,n,o),E=je.useMutate(_,{onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h});return y.jsxs(N.Modal,{size:m,show:w,onClose:b,scheme:"light",transition:!0,...C,children:[y.jsx(N.Modal.Header,{children:v}),y.jsxs(vc,{initialValues:t??{},onSubmit:E,...S,children:[y.jsxs(N.Modal.Body,{pb:"6",children:[A.isValidElement(x)&&x,Array.isArray(x)&&y.jsx(Mr,{form:x})]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:_.isLoading,onClick:b,variant:"borderless",me:"2",children:p}),y.jsx(gp,{disabled:_.isLoading,children:g})]})]}),_.isLoading&&y.jsx(Ps,{})]})}const qv="Oops, something went wrong...";function Wv(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function X$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFetchFn:i,queryFetchOptions:o,querySaveFn:s,querySaveOptions:a,onSuccess:l,onFetchError:c,fetchErrorMsg:u=qv,onSaveError:d,saveErrorMsg:h=qv,fetchToFormData:f,formToQueryData:p,invalidateQueriesOnSuccess:g=!0,invalidateQueryKey:m,retryText:v="Retry",cancelLabel:x="Cancel",saveLabel:w,size:b="lg",title:S,form:C,show:_,onClose:E,formikProps:R,...T}){const{isInitialLoading:O,isFetching:k,data:P,isError:M,error:j,refetch:z}=je.useApiQuery(r,i,n,{enabled:!(n==""||n==null||n==null),onError:c,...o}),B=g?je.useInvalidateParentMutation(s,m??r,a):je.useApiMutation(s,r,n,a),J=A.useCallback(()=>z(),[z]),K=A.useCallback((D,Q)=>{B.reset();const se=p?p(D):{...D};B.mutateAsync(se).then(oe=>{l?l(se,oe):Ne.success(`${S?S(se):se.name??se.title} ${n?"saved":"created"}`),E==null||E()}).catch(oe=>{console.error("on error",oe),d?d(D):Ne.error(`Couldn't save ${S?S(se):se.name??se.title}`),Q.setSubmitting(!1)})},[B,p,l,d,E]);return y.jsxs(N.Modal,{size:b,show:_,onClose:E,scheme:"light",transition:!0,...T,children:[y.jsxs(N.Modal.Header,{children:[!O&&n&&`Edit ${S?S(P):(P==null?void 0:P.name)??(P==null?void 0:P.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(C)&&y.jsx(y.Fragment,{})]}),O&&y.jsx(N.Modal.Body,{children:y.jsx(Br,{minW:"72"})}),M&&y.jsx(N.Modal.Body,{children:y.jsx(xi,{label:`${u} ${j}`,onClick:J})}),!O&&!M&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:f&&n&&P?f(Wv(P)):Wv(P)??t??{},onSubmit:K,...R,children:({setFieldValue:D,dirty:Q,handleSubmit:se,isValid:oe,values:de})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[A.isValidElement(C)&&C,Array.isArray(C)&&y.jsx(Mr,{form:C}),Fe.isFunction(C)&&y.jsx(Mr,{form:C(P??de)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:B.isLoading,onClick:E,variant:"borderless",me:"2",children:x}),y.jsx(N.Button,{type:"submit",disabled:!Q||B.isLoading,onClick:()=>se(),children:w||(n?"Update":"Create")})]})]})})}),B.isLoading&&y.jsx(Ps,{})]})}function BE({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"5",...e,children:t})}const Y$=A.forwardRef(({loading:t=!1,children:e,...n},r)=>y.jsxs(y.Fragment,{children:[t&&y.jsx(Br,{w:"full",h:"100%"}),!t&&y.jsx(N.Container,{ref:r,center:!0,size:"x2",dflex:!0,flexCol:!0,gap:"8",...n,children:e})]}));function Q$({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"3",...e,children:t})}const Z$={draft:"Draft",published:"Published",pending:"Pending",approved:"Approved",partially_approved:"Partially Approved",rejected:"Rejected"},eV={draft:"warning",published:"success",pending:"secondary",approved:"success",partially_approved:"warning",rejected:"danger"};function tV({status:t,...e}){return y.jsx(N.Badge,{size:"sm",variant:"glass",whiteSpace:"nowrap",rounded:"full",px:"3",scheme:eV[t],...e,children:Z$[t]})}function $E({path:t,...e}){const n=A.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),window.open(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${t}`,"_blank")},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"dark",onClick:n,...e,children:y.jsx(N.Icon,{path:Jh})})}function VE({path:t,...e}){const n=rn.useNavigate(),r=A.useCallback(i=>{i==null||i.preventDefault(),i==null||i.stopPropagation(),n(`${t}`)},[n,t]);return y.jsx(N.Button,{scheme:"secondary",w:"10",h:"10",variant:"borderless",corners:"pill",onClick:r,...e,children:y.jsx(N.Icon,{path:Gh})})}function zE({children:t,...e}){return y.jsx(cc,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"warning",...e,children:t??y.jsx(N.Icon,{path:rb})})}function UE({children:t,...e}){return y.jsx(cc,{w:"10",h:"10",scheme:"danger",variant:"borderless",corners:"pill",...e,children:t??y.jsx(N.Icon,{path:Rf})})}function nV({publishId:t,viewPath:e,navigatePath:n,editDialog:r,deleteDialog:i,children:o,...s}){return y.jsxs("div",{dflex:!0,spaceX:"1",placeContent:"end",...s,children:[e&&y.jsx($E,{path:e}),n&&y.jsx(VE,{path:n}),r&&y.jsx(zE,{buildDialog:r}),i&&y.jsx(UE,{buildDialog:i}),o]})}function rV({id:t,api:e,status:n,invalidateQueryKey:r,...i}){const o=n=="draft",s=je.useInvalidateParentMutation(o?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=A.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>Ne.success(o?"Published!":"Unpublished!")).catch(c=>Ne.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...i,children:y.jsx(N.Icon,{path:o?ib:ob})})}exports.AttachDialog=K$;exports.Breadcrumbs=rp;exports.DialogButton=cc;exports.FormActionDialog=J$;exports.IconButton=z_;exports.InvalidateButton=up;exports.ItemEditDialog=X$;exports.NavigateButton=aA;exports.OrderCell=gk;exports.PageContainer=bc;exports.PageContentEditor=fE;exports.PageMain=dE;exports.PageQueryStateContainer=Eg;exports.PageSectionTitle=BE;exports.PageSidebar=hE;exports.PageSidebarSection=pE;exports.PageStateContainer=Y$;exports.PageSubSectionTitle=Q$;exports.PageTabbedTopBar=yE;exports.PageTabbedTopBarProvider=mE;exports.PageTitle=_g;exports.PageTopBar=Rg;exports.PageTopBarToolbar=vE;exports.PublishButton=Wb;exports.ScreenRenderer=Qc;exports.SectionTitle=GE;exports.StatusBadge=tV;exports.TableContainer=LE;exports.TableCreateButton=DE;exports.TableFilterButton=NE;exports.TableRowActionBar=nV;exports.TableRowDeleteButton=UE;exports.TableRowEditButton=zE;exports.TableRowNavigateButton=VE;exports.TableRowPublishPostButton=rV;exports.TableRowViewButton=$E;exports.TableTopBar=jE;exports.UpdateButton=uw;exports.ViewButton=dw;
package/index.mjs CHANGED
@@ -41381,7 +41381,7 @@ function pj({ initialVisibleColumns: t, columns: e, children: n }) {
41381
41381
  }, children: n });
41382
41382
  }
41383
41383
  function gj({ initialPageSize: t, initialVisibleColumns: e, columns: n, children: r, ...i }) {
41384
- return /* @__PURE__ */ w(qr, { shadow: !0, rounded: "md", px: "0", py: "4", w: "full", dflex: !0, flexCol: !0, ...i, children: /* @__PURE__ */ w(sj, { initialPageSize: t, children: /* @__PURE__ */ w(pj, { columns: n, initialVisibleColumns: e, children: r }) }) });
41384
+ return /* @__PURE__ */ w(qr, { scheme: "light", shadow: !0, rounded: "md", px: "0", py: "4", w: "full", dflex: !0, flexCol: !0, ...i, children: /* @__PURE__ */ w(sj, { initialPageSize: t, children: /* @__PURE__ */ w(pj, { columns: n, initialVisibleColumns: e, children: r }) }) });
41385
41385
  }
41386
41386
  function mj({ children: t, ...e }) {
41387
41387
  return /* @__PURE__ */ w(Hp, { scheme: "default", corners: "pill", h: "10", variant: "glass", ...e, children: t ?? /* @__PURE__ */ w(Te, { path: oR }) });
@@ -41464,10 +41464,10 @@ function um({
41464
41464
  // means than this query is only enabled if the id is defined
41465
41465
  onError: a,
41466
41466
  ...i
41467
- }), N = f ? Wr(r.upsert, p ?? r.queryKey, o) : Di(r.upsert, r.queryKey, n, o), j = I.useCallback(() => k(), [k]), $ = I.useCallback((G, W) => {
41467
+ }), N = f ? Wr(r.upsert, p ?? r.queryKey, o) : Di(r.upsert, r.queryKey, n, o), j = I.useCallback(() => k(), [k]), $ = I.useCallback(async (G, W) => {
41468
41468
  N.reset();
41469
41469
  const D = h ? h(G) : { ...G };
41470
- N.mutateAsync(D).then((Y) => {
41470
+ await N.mutateAsync(D).then((Y) => {
41471
41471
  s ? s(D, Y) : He.success(`${b ? b(D) : D.name ?? D.title} ${n ? "saved" : "created"}`), E == null || E();
41472
41472
  }).catch((Y) => {
41473
41473
  console.error("on error", Y), c ? c(G) : He.error(`Couldn't save ${b ? b(D) : D.name ?? D.title}`), W.setSubmitting(!1);
package/index.umd.js CHANGED
@@ -245,4 +245,4 @@ See more info here: https://nextjs.org/docs/messages/no-stylesheets-in-head-comp
245
245
  */function u_(t,e){return t?YB(t)?Wr.createElement(t,e):t:null}function YB(t){return QB(t)||typeof t=="function"||ZB(t)}function QB(t){return typeof t=="function"&&(()=>{const e=Object.getPrototypeOf(t);return e.prototype&&e.prototype.isReactComponent})()}function ZB(t){return typeof t=="object"&&typeof t.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(t.$$typeof.description)}function eV(t){const e={state:{},onStateChange:()=>{},renderFallbackValue:null,...t},[n]=Wr.useState(()=>({current:qB(e)})),[r,o]=Wr.useState(()=>n.current.initialState);return n.current.setOptions(i=>({...i,...t,state:{...r,...t.state},onStateChange:s=>{o(s),t.onStateChange==null||t.onStateChange(s)}})),n.current}function bi(t,e,n){let r=n.initialDeps??[],o;function i(){var s,a,l,c;let u;n.key&&((s=n.debug)!=null&&s.call(n))&&(u=Date.now());const d=t();if(!(d.length!==r.length||d.some((p,g)=>r[g]!==p)))return o;r=d;let f;if(n.key&&((a=n.debug)!=null&&a.call(n))&&(f=Date.now()),o=e(...d),n.key&&((l=n.debug)!=null&&l.call(n))){const p=Math.round((Date.now()-u)*100)/100,g=Math.round((Date.now()-f)*100)/100,m=g/16,v=(C,w)=>{for(C=String(C);C.length<w;)C=" "+C;return C};console.info(`%c⏱ ${v(g,5)} /${v(p,5)} ms`,`
246
246
  font-size: .6rem;
247
247
  font-weight: bold;
248
- color: hsl(${Math.max(0,Math.min(120-120*m,120))}deg 100% 31%);`,n==null?void 0:n.key)}return(c=n==null?void 0:n.onChange)==null||c.call(n,o),o}return i.updateDeps=s=>{r=s},i}function Tg(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}const tV=(t,e)=>Math.abs(t-e)<1,nV=(t,e,n)=>{let r;return function(...o){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,o),n)}},rV=t=>t,oV=t=>{const e=Math.max(t.startIndex-t.overscan,0),n=Math.min(t.endIndex+t.overscan,t.count-1),r=[];for(let o=e;o<=n;o++)r.push(o);return r},iV=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;const o=s=>{const{width:a,height:l}=s;e({width:Math.round(a),height:Math.round(l)})};if(o(n.getBoundingClientRect()),!r.ResizeObserver)return()=>{};const i=new r.ResizeObserver(s=>{const a=()=>{const l=s[0];if(l!=null&&l.borderBoxSize){const c=l.borderBoxSize[0];if(c){o({width:c.inlineSize,height:c.blockSize});return}}o(n.getBoundingClientRect())};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return i.observe(n,{box:"border-box"}),()=>{i.unobserve(n)}},d_={passive:!0},f_=typeof window>"u"?!0:"onscrollend"in window,sV=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;let o=0;const i=t.options.useScrollendEvent&&f_?()=>{}:nV(r,()=>{e(o,!1)},t.options.isScrollingResetDelay),s=u=>()=>{const{horizontal:d,isRtl:h}=t.options;o=d?n.scrollLeft*(h&&-1||1):n.scrollTop,i(),e(o,u)},a=s(!0),l=s(!1);l(),n.addEventListener("scroll",a,d_);const c=t.options.useScrollendEvent&&f_;return c&&n.addEventListener("scrollend",l,d_),()=>{n.removeEventListener("scroll",a),c&&n.removeEventListener("scrollend",l)}},aV=(t,e,n)=>{if(e!=null&&e.borderBoxSize){const r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}return Math.round(t.getBoundingClientRect()[n.options.horizontal?"width":"height"])},lV=(t,{adjustments:e=0,behavior:n},r)=>{var o,i;const s=t+e;(i=(o=r.scrollElement)==null?void 0:o.scrollTo)==null||i.call(o,{[r.options.horizontal?"left":"top"]:s,behavior:n})};class cV{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(o=>{o.forEach(i=>{const s=()=>{this._measureElement(i.target,i)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(s):s()})}));return{disconnect:()=>{var o;(o=r())==null||o.disconnect(),n=null},observe:o=>{var i;return(i=r())==null?void 0:i.observe(o,{box:"border-box"})},unobserve:o=>{var i;return(i=r())==null?void 0:i.unobserve(o)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([r,o])=>{typeof o>"u"&&delete n[r]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:rV,rangeExtractor:oV,onChange:()=>{},measureElement:aV,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,...n}},this.notify=n=>{var r,o;(o=(r=this.options).onChange)==null||o.call(r,this,n)},this.maybeNotify=bi(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{this.scrollAdjustments=0,this.scrollDirection=i?this.getScrollOffset()<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this.maybeNotify()}))}},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=(n,r)=>{const o=new Map,i=new Map;for(let s=r-1;s>=0;s--){const a=n[s];if(o.has(a.lane))continue;const l=i.get(a.lane);if(l==null||a.end>l.end?i.set(a.lane,a):a.end<l.end&&o.set(a.lane,!0),o.size===this.options.lanes)break}return i.size===this.options.lanes?Array.from(i.values()).sort((s,a)=>s.end===a.end?s.index-a.index:s.end-a.end)[0]:void 0},this.getMeasurementOptions=bi(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled],(n,r,o,i,s)=>(this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:o,getItemKey:i,enabled:s}),{key:!1}),this.getMeasurements=bi(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:o,getItemKey:i,enabled:s},a)=>{if(!s)return this.measurementsCache=[],this.itemSizeCache.clear(),[];this.measurementsCache.length===0&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const l=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const c=this.measurementsCache.slice(0,l);for(let u=l;u<n;u++){const d=i(u),h=this.options.lanes===1?c[u-1]:this.getFurthestMeasurement(c,u),f=h?h.end+this.options.gap:r+o,p=a.get(d),g=typeof p=="number"?p:this.options.estimateSize(u),m=f+g,v=h?h.lane:u%this.options.lanes;c[u]={index:u,start:f,size:g,end:m,key:d,lane:v}}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=bi(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,o,i)=>this.range=n.length>0&&r>0?uV({measurements:n,outerSize:r,scrollOffset:o,lanes:i}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=bi(()=>{let n=null,r=null;const o=this.calculateRange();return o&&(n=o.startIndex,r=o.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,o,i,s)=>i===null||s===null?[]:n({startIndex:i,endIndex:s,overscan:r,count:o}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,o=n.getAttribute(r);return o?parseInt(o,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this._measureElement=(n,r)=>{const o=this.indexFromElement(n),i=this.measurementsCache[o];if(!i)return;const s=i.key,a=this.elementsCache.get(s);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(s,n)),n.isConnected&&this.resizeItem(o,this.options.measureElement(n,r,this))},this.resizeItem=(n,r)=>{const o=this.measurementsCache[n];if(!o)return;const i=this.itemSizeCache.get(o.key)??o.size,s=r-i;s!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(o,s,this):o.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",s),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(o.index),this.itemSizeCache=new Map(this.itemSizeCache.set(o.key,r)),this.notify(!1))},this.measureElement=n=>{if(!n){this.elementsCache.forEach((r,o)=>{r.isConnected||(this.observer.unobserve(r),this.elementsCache.delete(o))});return}this._measureElement(n,void 0)},this.getVirtualItems=bi(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const o=[];for(let i=0,s=n.length;i<s;i++){const a=n[i],l=r[a];o.push(l)}return o},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length!==0)return Tg(r[h_(0,r.length-1,o=>Tg(r[o]).start,n)])},this.getOffsetForAlignment=(n,r,o=0)=>{const i=this.getSize(),s=this.getScrollOffset();r==="auto"&&(r=n>=s+i?"end":"start"),r==="center"?n+=(o-i)/2:r==="end"&&(n-=i);const a=this.options.horizontal?"scrollWidth":"scrollHeight",c=(this.scrollElement?"document"in this.scrollElement?this.scrollElement.document.documentElement[a]:this.scrollElement[a]:0)-i;return Math.max(Math.min(c,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const o=this.measurementsCache[n];if(!o)return;const i=this.getSize(),s=this.getScrollOffset();if(r==="auto")if(o.end>=s+i-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];const a=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,r,o.size),r]},this.isDynamicMode=()=>this.elementsCache.size>0,this.cancelScrollToIndex=()=>{this.scrollToIndexTimeoutId!==null&&this.targetWindow&&(this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId),this.scrollToIndexTimeoutId=null)},this.scrollToOffset=(n,{align:r="start",behavior:o}={})=>{this.cancelScrollToIndex(),o==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(n,r),{adjustments:void 0,behavior:o})},this.scrollToIndex=(n,{align:r="auto",behavior:o}={})=>{n=Math.max(0,Math.min(n,this.options.count-1)),this.cancelScrollToIndex(),o==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");const i=this.getOffsetForIndex(n,r);if(!i)return;const[s,a]=i;this._scrollToOffset(s,{adjustments:void 0,behavior:o}),o!=="smooth"&&this.isDynamicMode()&&this.targetWindow&&(this.scrollToIndexTimeoutId=this.targetWindow.setTimeout(()=>{if(this.scrollToIndexTimeoutId=null,this.elementsCache.has(this.options.getItemKey(n))){const[c]=Tg(this.getOffsetForIndex(n,a));tV(c,this.getScrollOffset())||this.scrollToIndex(n,{align:a,behavior:o})}else this.scrollToIndex(n,{align:a,behavior:o})}))},this.scrollBy=(n,{behavior:r}={})=>{this.cancelScrollToIndex(),r==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+n,{adjustments:void 0,behavior:r})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let o;if(r.length===0)o=this.options.paddingStart;else if(this.options.lanes===1)o=((n=r[r.length-1])==null?void 0:n.end)??0;else{const i=Array(this.options.lanes).fill(null);let s=r.length-1;for(;s>0&&i.some(a=>a===null);){const a=r[s];i[a.lane]===null&&(i[a.lane]=a.end),s--}o=Math.max(...i.filter(a=>a!==null))}return Math.max(o-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:o})=>{this.options.scrollToFn(n,{behavior:o,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.notify(!1)},this.setOptions(e)}}const h_=(t,e,n,r)=>{for(;t<=e;){const o=(t+e)/2|0,i=n(o);if(i<r)t=o+1;else if(i>r)e=o-1;else return o}return t>0?t-1:0};function uV({measurements:t,outerSize:e,scrollOffset:n,lanes:r}){const o=t.length-1;let s=h_(0,o,l=>t[l].start,n),a=s;if(r===1)for(;a<o&&t[a].end<n+e;)a++;else if(r>1){const l=Array(r).fill(0);for(;a<o&&l.some(u=>u<n+e);){const u=t[a];l[u.lane]=u.end,a++}const c=Array(r).fill(n+e);for(;s>0&&c.some(u=>u>=n);){const u=t[s];c[u.lane]=u.start,s--}s=Math.max(0,s-s%r),a=Math.min(o,a+(r-1-a%r))}return{startIndex:s,endIndex:a}}const p_=typeof document<"u"?Wr.useLayoutEffect:Wr.useEffect;function dV(t){const e=Wr.useReducer(()=>({}),{})[1],n={...t,onChange:(o,i)=>{var s;i?Mo.flushSync(e):e(),(s=t.onChange)==null||s.call(t,o,i)}},[r]=Wr.useState(()=>new cV(n));return r.setOptions(n),p_(()=>r._didMount(),[]),p_(()=>r._willUpdate()),r}function fV(t){return dV({observeElementRect:iV,observeElementOffset:sV,scrollToFn:lV,...t})}function hV(t,e){const{rows:n}=t.getRowModel(),r=fV({getScrollElement:()=>e,count:n.length,estimateSize:()=>35,overscan:10});return{rows:n,virtualRows:r.getVirtualItems(),totalSize:r.getTotalSize(),virtualizer:r}}function pV(t,e){const n=t.getIsPinned(),r=n==="left"&&t.getIsLastColumn("left"),o=n==="right"&&t.getIsFirstColumn("right");return{shadow:r?"-2px 0 2px -2px gray inset":o?"2px 0 2px -2px gray inset":void 0,start:n==="left"?`${t.getStart("left")}px`:void 0,end:n==="right"?`${t.getAfter("right")}px`:void 0,position:n?"sticky":"relative",w:t.getSize(),z:n?1:0,bgColor:n?e?"gray.50":"white":e?"gray.50":void 0}}function gV({table:t,containerRef:e,onRowClick:n,disabledRow:r}){var u,d;const{rows:o,virtualRows:i,totalSize:s,virtualizer:a}=hV(t,e),l=i.length>0&&((u=i==null?void 0:i[0])==null?void 0:u.start)||0,c=i.length>0?s-(((d=i==null?void 0:i[i.length-1])==null?void 0:d.end)||0):0;return y.jsxs("tbody",{children:[l>0&&y.jsx("tr",{children:y.jsx("td",{h:`${l}px`})}),i.map(h=>{const f=o[h.index],p=mV(f.original,r);return y.jsx("tr",{borderB:"px",borderBColor:"#F4F4F4",borderStyle:"dashed",hover_bgColor:"slate-50",cursor:n?"pointer":"default",onClick:n?()=>n(f.original):void 0,w:"fit-content",group:!0,children:f.getVisibleCells().map((g,m)=>y.jsx("td",{px:"3",py:"2",textSize:"sm",textColor:p?"gray.400":"gray.700",fontWeight:"500",borderTColor:"--bg-3",borderT:"0.5",cursor:n&&!p?"pointer":"default",w:`${g.column.getSize()}px`,groupHover_bgColor:p?void 0:"gray.100",...pV(g.column,p),children:u_(g.column.columnDef.cell,g.getContext())},g.id))},f.id)}),c>0&&y.jsx("tr",{children:y.jsx("td",{h:`${c}px`})})]})}function mV(t,e){return e?typeof e=="string"?t[e]:e(t):!1}function yV({headers:t}){const e=Fe.useThemeAwareColor("slate-500","slate-700");return y.jsx("thead",{children:t.map(n=>y.jsx("tr",{w:"fit",children:n.headers.map(r=>y.jsx("th",{position:"relative",colSpan:r.colSpan,textAlign:"start",fontWeight:"600",textColor:e,px:"3",py:"2",textSize:"sm",w:`${r.getSize()}px`,children:y.jsxs("div",{dflex:!0,flexRow:!0,children:[r.isPlaceholder?null:y.jsxs(y.Fragment,{children:[u_(r.column.columnDef.header,r.getContext()),y.jsx("span",{cursor:r.column.getCanSort()?"pointer":"default",onClick:r.column.getToggleSortingHandler(),opacity:"0",hover_opacity:"100",flexGrow:!0,textAlign:"end",children:{asc:y.jsx(y.Fragment,{children:" ▲"}),desc:y.jsx(y.Fragment,{children:" ▼"})}[r.column.getIsSorted()]??y.jsx(y.Fragment,{children:" ▲"})})]}),y.jsx("div",{onMouseDown:r.getResizeHandler(),onTouchStart:r.getResizeHandler(),onClick:o=>{o.preventDefault(),o.stopPropagation()},position:"absolute",end:"0",top:"0",h:"full",w:"2",bgColor:r.column.getIsResizing()?"primary-500":"slate-900",bgOpacity:r.column.getIsResizing()?"70":"30",cursor:"col-resize",userSelect:"none",style:{touchAction:"none"},opacity:r.column.getIsResizing()?"100":"0",hover_opacity:"100"})]})},r.id))},n.id))})}const[vV,Og]=Fe.createContext();function bV({initialPageSize:t,children:e}){const[n,r]=Qt.useSearchParams(),{pageIndex:o,pageSize:i}=T.useMemo(()=>({pageIndex:n.get("page")??1,pageSize:n.get("sizePerPage")??t??25}),[n,t]),s=T.useCallback(c=>{const u=Fe.runIfFn(c,{pageIndex:o,pageSize:i});r(d=>(d.set("page",`${u.pageIndex}`),d.set("sizePerPage",`${u.pageSize}`),d))},[r,o,i]),a=vV,l={pageIndex:typeof o=="string"?parseInt(o):o,pageSize:typeof i=="string"?parseInt(i):i,setPagination:s};return y.jsx(a,{value:l,children:e})}function g_({page:t,...e}){const{pageSize:n,pageIndex:r,setPagination:o}=Og(),i=T.useCallback(()=>o({pageIndex:1,pageSize:n}),[n,o]);return y.jsxs("div",{dflex:!0,flexCol:!0,gap:"10",w:"full",h:"full",alignItems:"center",placeContent:"center",py:"16",...e,children:[y.jsx(N.Icon,{path:ax,w:"24",h:"24",textColor:"gray.400"}),y.jsx("div",{textSize:"xl",textColor:"gray.600",children:"No Data"}),t>1&&y.jsx(N.Button,{onClick:i,children:"Back To First Page"})]})}function wV({table:t,isLoading:e}){const n=t.getPageCount(),r=t.getState().pagination.pageIndex+1,o=SV(r,n,5);return y.jsxs(y.Fragment,{children:[n<2&&y.jsx(y.Fragment,{}),n>1&&y.jsx(y.Fragment,{children:y.jsxs("div",{dflex:!0,flexRow:!0,spaceX:"2",py:"2",children:[y.jsx(wi,{onClick:()=>t.setPageIndex(0),disabled:e||r==1,children:y.jsx(N.Icon,{path:X_})}),y.jsx(wi,{onClick:()=>t.previousPage(),disabled:e||r==1,children:y.jsx(N.Icon,{path:Z_})}),o.length>0&&o[0]>1&&y.jsx("a",{children:"..."}),o.map(i=>y.jsx(wi,{onClick:()=>t.setPageIndex(i-1),disabled:e,variant:r==i?"default":"glass",scheme:"secondary",children:i},i)),o.length>0&&o[o.length-1]<n&&y.jsx(wi,{disabled:e,children:"..."}),y.jsx(wi,{onClick:()=>t.nextPage(),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:ex})}),y.jsx(wi,{onClick:()=>t.setPageIndex(t.getPageCount()-1),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:Y_})})]})})]})}function wi({...t}){return y.jsx(N.Button,{scheme:"secondary",variant:"glass",corners:"pill",w:"8",h:"8",p:"0",dflex:!0,alignItems:"center",placeContent:"center",...t})}function SV(t,e,n){const r=[];if(!t)return r;if(e===1)return r.push(1),r;if(e<t)return r;if(e<n+1){for(let i=1;i<e+1;i++)r.push(i);return r}if(t===1){for(let i=1;i<n+1;i++)i<e&&r.push(i);return r}if(t===e){for(let i=e-n+1;i<=e;i++)i<=e&&r.push(i);return r}const o=Math.floor(n/2);if(o<1)return r.push(t),r;if(t<o+2){for(let i=1;i<n+1;i++)r.push(i);return r}if(e-t<o+2){for(let i=e-n;i<e+1;i++)r.push(i);return r}for(let i=t-o;i<t;i++)i>0&&r.push(i);r.push(t);for(let i=t+1;i<t+o+1;i++)i<=e&&r.push(i);return r}const CV=[{label:"25",value:25},{label:"50",value:50},{label:"100",value:100}];function EV({table:t,total:e,isLoading:n,reverseOrder:r,sizePerPageList:o}){const i=t.getState().pagination.pageIndex,s=t.getState().pagination.pageSize;return y.jsxs("div",{dflex:!0,flexDirection:r?"row-reverse":"row",alignItems:"center",py:"3",spaceX:"3",children:[y.jsx(N.Select,{disabled:e===0||n,onChange:a=>t.setPageSize(Number(a.target.value)),value:s,w:"20",children:(o??CV).map(a=>{const l=s===a.value;return y.jsx("option",{value:a.value,className:`btn ${l?"active":""}`,children:a.label},a.label)})}),y.jsxs("div",{children:["Showing rows ",1+i*s," to ",Math.min((i+1)*s,e)," of ",e]}),n&&y.jsx(N.Spinner,{size:"sm"})]})}function m_({isLoading:t,table:e,total:n,show:r,toolbarPosition:o="both",reverseOrder:i=!1,sizePerPageList:s,children:a,...l}){return y.jsxs("div",{...l,children:[r&&["top","both"].includes(o)&&y.jsx(y_,{isLoading:t,table:e,total:n,reverseOrder:i,sizePerPageList:s}),a,r&&["bottom","both"].includes(o)&&y.jsx(y_,{isLoading:t,table:e,total:n,reverseOrder:i,sizePerPageList:s})]})}function y_({isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:o}){return y.jsxs("div",{dflex:!0,justifyContent:"between",alignItems:"center",flexWrap:!0,flexDirection:r?"row-reverse":"row",children:[y.jsx(EV,{isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:o}),y.jsx("div",{className:"d-flex flex-wrap"}),y.jsx(wV,{isLoading:t,table:e})]})}const[_V,v_]=Fe.createContext();function xV({sortBy:t,sortDir:e,children:n}){const[r,o]=Qt.useSearchParams(),{sortBy:i,sortDir:s}=T.useMemo(()=>({sortBy:r.get("sortBy")??t??"",sortDir:r.get("sortDir")??e??"asc"}),[r]),a=T.useCallback(u=>{const d=Fe.runIfFn(u,[{id:i,desc:s==="desc"}]);o(h=>{var f,p;return h.set("sortBy",`${((f=d==null?void 0:d[0])==null?void 0:f.id)??""}`),h.set("sortDir",`${(p=d==null?void 0:d[0])!=null&&p.desc?"desc":"asc"}`),h})},[o,i,s]),l=_V,c={sortBy:i,sortDir:s,setSorting:a};return y.jsx(l,{value:c,children:n})}function AV(t,e,n){const{setPagination:r}=Og(),{sortBy:o,sortDir:i,setSorting:s}=v_(),[a,l]=T.useState((n==null?void 0:n.rowSelection)??{}),c=T.useCallback(h=>{var f;l(h),(f=n==null?void 0:n.onSelectionChange)==null||f.call(n,Fe.runIfFn(h,a))},[l,a]),u=T.useCallback(h=>{var f;if(n!=null&&n.enableSelection&&(n!=null&&n.enableSelectOnRowClick)){h.toggleSelected();return}(f=n==null?void 0:n.onRowClick)==null||f.call(n,h.original)},[]);return{table:eV(Li({data:t??[],getRowId:h=>h.id,columns:e,columnResizeMode:"onChange",enableColumnResizing:!0,enableSortingRemoval:!1,defaultColumn:{size:150,minSize:40,maxSize:1e3},state:{sorting:[{id:o,desc:i==="desc"}],rowSelection:a},filterFns:{},enableRowSelection:n==null?void 0:n.enableSelection,onRowSelectionChange:c,onSortingChange:s,getCoreRowModel:WB(),getFilteredRowModel:XB(),onPaginationChange:r},n==null?void 0:n.tableOptions)),onRowClick:u}}const b_=T.createContext({});function Qc(){return T.useContext(b_)}const TV=["sortBy","sortDir","page","sizePerPage"];function OV({sortBy:t,sortDir:e,initialPageSize:n,children:r}){const[o,i]=Qt.useSearchParams(),s=T.useCallback(h=>{i(f=>(Object.keys(h).forEach(p=>{f.set(p,h[p]===void 0?"":h[p])}),f.set("page","1"),f))},[i]),a=T.useCallback(()=>{const h={},f=o.entries();for(const[p,g]of f)TV.includes(p)||(h[p]=g);return h},[o]),[l,c]=T.useState(),d={ids:T.useMemo(()=>{const h=Object.keys(l??{});return(h==null?void 0:h.filter(f=>l==null?void 0:l[f]))??[]},[l]),setRowSelection:c,getFilters:a,setFilters:s};return y.jsx(b_.Provider,{value:d,children:y.jsx(bV,{initialPageSize:n,children:y.jsx(xV,{sortBy:t,sortDir:e,children:r})})})}function kV(t,e,n){const r=Re.useInvalidateQuery(t),o=T.useMemo(()=>({onError:()=>He.error((n==null?void 0:n.errorMessage)??"Oops, something went wrong :("),refetchOnWindowFocus:!1,keepPreviousData:!0,retry:!1,staleTime:1e8}),[n]),{pageIndex:i,pageSize:s,setPagination:a}=Og(),{sortBy:l,sortDir:c}=v_(),{getFilters:u}=Qc(),d={pageSize:s,pageNumber:i,sortBy:l,sortDir:c,...n!=null&&n.transformFilters?n.transformFilters(u()):u()},h=T.useMemo(()=>({...o,...n==null?void 0:n.queryOptions}),[n]),{data:f,isError:p,isFetching:g,isLoading:m}=Re.useApiQuery(t,e,d,h),v=T.useCallback(r,[r]),{data:C}=f??{data:{data:void 0,meta:void 0}},{data:w,meta:b}=C;return{data:w&&(n!=null&&n.transformResponse)?n.transformResponse(w):w,response:C,retry:v,isError:p,isLoading:m,isFetching:g,page:(b==null?void 0:b.current_page)??1??i,pageSize:(b==null?void 0:b.per_page)??s,total:(b==null?void 0:b.total)??0,onPaginationChange:a}}function MV({columns:t,keyField:e="id",queryKey:n,queryFn:r,queryOptions:o,errorMessage:i,transformFilters:s,transformResponse:a,defaultSorted:l="name",defaultSortOrder:c="desc",nonSelectable:u,enableFilters:d=!1,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,onRowClick:g,onSelectionChange:m,sizePerPageList:v,paginationPosition:C,reversePaginationTools:w,containerEl:b,emptyMessage:S,title:E,disabledRow:x,pinnedColumnsLeft:_,pinnedColumnsRight:A,...O}){const k=T.useRef(null),{data:M,response:I,retry:P,isError:F,isLoading:z,isFetching:V,page:J,pageSize:K,total:R,onPaginationChange:Q}=kV(n,r,{errorMessage:i,queryOptions:o,transformResponse:a,transformFilters:s}),ie=AV(M??[],LV(t,h),{defaultSorted:l,defaultSortOrder:c,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,nonSelectable:u,onRowClick:g,onSelectionChange:m,tableOptions:{enableColumnFilters:d,initialState:{columnPinning:{left:_??[],right:A??[]}},state:{pagination:{pageIndex:J,pageSize:K}},autoResetPageIndex:!1,pageCount:Math.ceil(R/K),onPaginationChange:Q}}).table;return y.jsxs("div",{px:"8",pt:"8",ref:k,h:"100%",children:[F&&y.jsx(Jr,{onClick:P,label:i}),(z||V&&(!M||(M==null?void 0:M.length)==0))&&y.jsx(hr,{}),!F&&!z&&M&&y.jsxs("div",{children:[E&&(Fe.isFunction(E)?E(I):E),O.mode=="table"&&y.jsx(PV,{table:ie,total:R??0,data:M,isLoading:V,containerEl:b??k.current,onRowClick:g,sizePerPageList:v,disabledRow:x}),O.mode=="grid"&&y.jsx(IV,{table:ie,total:R??0,data:M,isLoading:V,onRowClick:g,sizePerPageList:v,gridCols:O.gridCols,renderGridItem:O.renderGridItem})]})]})}function PV({table:t,total:e,data:n,isLoading:r,onRowClick:o,containerEl:i,sizePerPageList:s,disabledRow:a}){return y.jsxs(m_,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:s,children:[n.length==0&&y.jsx(g_,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",border:"2px",borderColor:"#F4F4F4",rounded:"base",my:"3",overflowX:"auto",children:y.jsxs("table",{style:{width:"max(1400px, 100%)",tableLayout:"fixed"},children:[y.jsx(yV,{headers:t.getHeaderGroups()}),y.jsx(gV,{table:t,containerRef:i,onRowClick:o,disabledRow:a})]})})]})}function IV({table:t,total:e,data:n,isLoading:r,onRowClick:o,sizePerPageList:i,gridCols:s,renderGridItem:a}){return y.jsxs(m_,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:i,children:[n.length==0&&y.jsx(g_,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",children:y.jsx("div",{grid:!0,gridCols:`${s??3}`,gap:"5",w:"full",children:n.map(l=>a==null?void 0:a(l,o))})})]})}function LV(t,e){return e?[{id:"select-col",header:({table:n})=>y.jsx(N.Checkbox,{checked:n.getIsAllRowsSelected(),onChange:n.getToggleAllRowsSelectedHandler()}),cell:({row:n})=>y.jsx(N.Checkbox,{checked:n.getIsSelected(),disabled:!n.getCanSelect(),onChange:n.getToggleSelectedHandler()}),size:10,maxSize:1,enableResizing:!1}].concat(t):t}const[DV,NV]=Fe.createContext();function w_(t){return t.accessorKey??t.id}function RV({initialVisibleColumns:t,columns:e,children:n}){const[r,o]=T.useState(!1),[i,s]=T.useState(!1),[a,l]=T.useState(t??(e==null?void 0:e.map(p=>w_(p)))??[]),c=(e==null?void 0:e.filter(p=>a.includes(w_(p))))??[],u=T.useCallback(p=>{const g=a.indexOf(p);if(g>-1){const m=a.concat();m.splice(g,1),l(m)}else l(a.concat(p))},[a,l]),d=T.useCallback(p=>a.includes(p),[a]),h=DV,f={showFilters:r,setShowFilters:o,showMassActions:i,setShowMassActions:s,columns:e??[],filteredColumns:c,toggleColumnVisibility:u,isColumnVisible:d};return y.jsx(h,{value:f,children:n})}function S_({initialPageSize:t,initialVisibleColumns:e,columns:n,children:r,...o}){return y.jsx(N.Tile,{shadow:!0,rounded:"md",px:"0",py:"4",w:"full",dflex:!0,flexCol:!0,...o,children:y.jsx(OV,{initialPageSize:t,children:y.jsx(RV,{columns:n,initialVisibleColumns:e,children:r})})})}function C_({children:t,...e}){return y.jsx(ia,{scheme:"default",corners:"pill",h:"10",variant:"glass",...e,children:t??y.jsx(N.Icon,{path:bx})})}function E_({...t}){return y.jsxs(N.Popover,{side:"bottom-end",modal:!0,children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",...t,children:y.jsx(N.Icon,{path:sx})}),y.jsxs("div",{bgColor:"white",rounded:!0,shadow:!0,children:[y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"First Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Second Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Third Item"})]})]})}function __({title:t,queryKey:e,children:n,...r}){const o=Re.useInvalidateQuery(e);return q0("ctrl+r",()=>o(),{preventDefault:!0},[o]),y.jsxs("div",{dflex:!0,flexRow:!0,pb:"4",alignItems:"center",gap:"3",px:"8",borderB:"0.5",borderBColor:"--bg-2",...r,children:[t&&y.jsx("h2",{textSize:"x3",fontWeight:"600",textColor:"#3f4254",textTransform:"capitalize",children:t}),y.jsx("div",{flexGrow:!0,children:" "}),y.jsxs("div",{spaceX:"2",dflex:!0,alignItems:"center",children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",onClick:o,children:y.jsx(N.Icon,{path:Kg})}),n]})]})}const x_="Oops, something went wrong...";function A_(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function kg({initialValues:t,itemLabel:e,queryId:n="",api:r,queryFetchOptions:o,querySaveOptions:i,onSuccess:s,onFetchError:a,fetchErrorMsg:l=x_,onSaveError:c,saveErrorMsg:u=x_,fetchToFormData:d,formToQueryData:h,invalidateQueriesOnSuccess:f=!0,invalidateQueryKey:p,retryText:g="Retry",cancelLabel:m="Cancel",saveLabel:v,size:C="lg",title:w,form:b,show:S,onClose:E,formikProps:x,..._}){const{isInitialLoading:A,isFetching:O,data:k,isError:M,error:I,refetch:P}=Re.useApiQuery(r.queryKey,r.get,n,{enabled:!(n==""||n==null||n==null),onError:a,...o}),F=f?Re.useInvalidateParentMutation(r.upsert,p??r.queryKey,i):Re.useApiMutation(r.upsert,r.queryKey,n,i),z=T.useCallback(()=>P(),[P]),V=T.useCallback((J,K)=>{F.reset();const R=h?h(J):{...J};F.mutateAsync(R).then(Q=>{s?s(R,Q):He.success(`${w?w(R):R.name??R.title} ${n?"saved":"created"}`),E==null||E()}).catch(Q=>{console.error("on error",Q),c?c(J):He.error(`Couldn't save ${w?w(R):R.name??R.title}`),K.setSubmitting(!1)})},[F,h,s,c,E]);return y.jsxs(N.Modal,{size:C,show:S,onClose:E,scheme:"light",transition:!0,..._,children:[y.jsxs(N.Modal.Header,{children:[!A&&n&&`Edit ${w?w(k):(k==null?void 0:k.name)??(k==null?void 0:k.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(b)&&y.jsx(y.Fragment,{})]}),A&&y.jsx(N.Modal.Body,{children:y.jsx(hr,{minW:"72"})}),M&&y.jsx(N.Modal.Body,{children:y.jsx(Jr,{label:`${l} ${I}`,onClick:z})}),!A&&!M&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:d&&n&&k?d(A_(k)):A_(t(k))??{},onSubmit:V,...x,children:({setFieldValue:J,dirty:K,handleSubmit:R,isValid:Q,values:se})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[T.isValidElement(b)&&b,Array.isArray(b)&&y.jsx(pr,{form:b}),Fe.isFunction(b)&&y.jsx(pr,{form:b(k??se)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:F.isLoading,onClick:E,variant:"borderless",me:"2",children:m}),y.jsx(N.Button,{type:"submit",disabled:!K||F.isLoading,onClick:()=>R(),children:v||(n?"Update":"Create")})]})]})})}),F.isLoading&&y.jsx(Fi,{})]})}function FV({api:t,fn:e,transformFn:n,config:r,onClose:o,queryId:i,invalidateQueryKey:s}){const{data:a,isFetching:l}=Re.useApiQuery(t.queryKey,e==="get"||e==="getTransformed"?t.get:t.getAll,void 0,{retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1}),c=T.useMemo(()=>a&&(e==="getTransformed"||e==="getAllTransformed")?(n||console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${e}`),n==null?void 0:n(a)):a,[a,e,n]);return l?null:y.jsx(kg,{...r(c),queryId:i,invalidateQueryKey:s,show:!0,onClose:o})}function HV({queries:t,config:e,onClose:n,queryId:r,invalidateQueryKey:o}){const{data:i,isFetching:s,isError:a}=Re.useApiQueries(t.map(c=>({queryKey:c.api.queryKey,queryFn:c.fn=="get"?c.api.get:c.api.getAll,queryOptions:{cacheTime:c.cache===!1?0:void 0,staleTime:c.cache===!1?0:void 0}}))),l=T.useMemo(()=>i==null?void 0:i.map((c,u)=>{var d,h;return t[u].transformFn?(h=(d=t[u])==null?void 0:d.transformFn)==null?void 0:h.call(d,c):c}),[i,t]);return y.jsx(kg,{isPreloading:s,...e(...l),queryId:r,invalidateQueryKey:o,show:!0,onClose:n})}function T_({config:t,onClose:e,invalidateQueryKey:n,queryId:r}){const{type:o,...i}=t;return t.type==="dialog"?y.jsx(kg,{...i,queryId:r,invalidateQueryKey:n,show:!0,onClose:e}):t.type==="query"?y.jsx(FV,{...i,queryId:r,invalidateQueryKey:n,onClose:e}):t.type==="multiQuery"?y.jsx(HV,{...i,queryId:r,invalidateQueryKey:n,onClose:e}):null}function BV({itemLabel:t,queryId:e="",api:n,invalidateQueriesOnSuccess:r=!0,invalidateQueryKey:o,size:i="lg",show:s,onClose:a,...l}){const c=r?Re.useInvalidateParentMutation(n.delete,o??n.queryKey):Re.useApiMutation(n.upsert,n.queryKey),u=Re.useMutate(c,{onSuccess:()=>a==null?void 0:a()}),d=T.useCallback(()=>u(e),[u,e]);return y.jsxs(N.Modal,{size:i,show:s,onClose:a,scheme:"danger",variant:"glass",transition:!0,...l,children:[y.jsx(N.Modal.Header,{children:`Delete ${t}`}),y.jsxs(N.Modal.Body,{pb:"6",children:["Do you really want to delete ",t,"?"]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:c.isLoading,onClick:a,variant:"borderless",scheme:"secondary",me:"2",children:"Cancel"}),y.jsx(N.Button,{scheme:"danger",disabled:c.isLoading,onClick:d,children:"Delete"})]}),c.isLoading&&y.jsx(Fi,{})]})}const[VV,O_]=Fe.createContext();function $V({editView:t,deleteItem:e,queryKey:n,children:r}){const o=Vy(),i=Qt.useNavigate(),[s,a]=T.useState(null),l=T.useCallback(()=>a(null),[a]),c=T.useCallback((h,f)=>{switch(h.type){case"view":{i(Fe.runIfFn(h.path,f));break}case"link":{o(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(h.path,f)}`);break}case"edit":{t.type=="customDialog"?a(t.render({show:!0,onClose:l})):a(y.jsx(T_,{onClose:l,config:t,queryId:f.id,invalidateQueryKey:n}));break}case"delete":{a(y.jsx(BV,{show:!0,onClose:l,queryId:f.id,invalidateQueryKey:n,...e,itemLabel:Fe.runIfFn(e.itemLabel,f)}));break}}},[i,t,e]),u=VV,d={dialog:s,onAction:c};return y.jsx(u,{value:d,children:r})}function jV({id:t,api:e,status:n,invalidateQueryKey:r,...o}){const i=n=="draft",s=Re.useInvalidateParentMutation(i?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=T.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>He.success(i?"Published!":"Unpublished!")).catch(c=>He.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...o,children:y.jsx(N.Icon,{path:i?qg:Wg})})}function zV({row:t,onAction:e,rowActions:n,api:r,queryKey:o}){const i=t.original;return y.jsx("div",{dflex:!0,spaceX:"1",placeContent:"end",children:n==null?void 0:n.map((s,a)=>y.jsxs(T.Fragment,{children:[s.type==="publish"&&y.jsx(jV,{id:i.id,api:r,status:i.status,invalidateQueryKey:o}),s.type=="custom"&&y.jsx(y.Fragment,{children:s.component(i,o,s.icon,s.label)}),!["publish","custom"].includes(s.type)&&y.jsx(UV,{onClick:()=>e(s,i),scheme:WV[s.type],children:y.jsx(N.Icon,{path:qV[s.type]})})]},a))})}function UV({onClick:t,...e}){const n=T.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),t==null||t(r)},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",onClick:n,...e})}const qV={link:ru,view:nu,edit:Ug,delete:tu,publish:tu,custom:""},WV={link:"dark",view:"secondary",edit:"warning",delete:"danger",publish:"warning",custom:"default"};function KV(t,e,n){const r=Qt.useNavigate(),o=Vy(),{onAction:i}=O_(),{onRowClick:s,columns:a,...l}=e,c=T.useCallback(h=>{(s==null?void 0:s.type)==="navigate"?r(Fe.runIfFn(s.path,h)):(s==null?void 0:s.type)=="link"&&o(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(s.path,h)}`)},[r,s]),u=T.useMemo(()=>{const h=e.columns.concat([]);return n&&h.push(yB().display({id:"actions",header:"Actions",cell:f=>y.jsx(zV,{row:f.row,onAction:i,rowActions:n,api:t,queryKey:t.queryKey})})),h},[e]),d={...l};return d.columns=u,d.onRowClick=c,d.queryKey=t.queryKey,d.queryFn=t.search,d}function GV({form:t,initialValues:e,schema:n,processInput:r}){const{showFilters:o}=NV(),{getFilters:i,setFilters:s}=Qc(),a=T.useCallback((c,u)=>{const d=(r==null?void 0:r(c))??c;Fy(d,i())||s(d),u.setSubmitting(!1)},[s,r]),l=T.useCallback(c=>{s(e),c()},[s,e]);return T.useEffect(()=>s(e),[]),y.jsx(N.Collapse,{in:o,style:{overflow:o?"initial":"hidden"},children:y.jsx("div",{p:"8",borderT:"px",borderB:"px",borderColor:"slate-100",children:y.jsx(Ra,{initialValues:H0(i(),e),onSubmit:a,validationSchema:n,enableReinitialize:!0,children:c=>y.jsxs("div",{dflex:!0,gap:"3",placeContent:"start",children:[y.jsx(pr,{flexRow:!0,w:"auto",form:t}),y.jsx(JV,{handleReset:()=>l(c.resetForm)})]})})})})}function JV({handleReset:t}){return y.jsxs("div",{dflex:!0,gap:"3",children:[y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(vn,{name:"",label:" "}),y.jsx(Bd,{children:"Filter"})]}),y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(vn,{name:"",label:" "}),y.jsx(N.Button,{scheme:"neutral",onClick:t,children:"Reset"})]})]})}function XV({label:t,buttonProps:e,icon:n,queryKey:r,queryFn:o,successMsg:i,errorMsg:s,invalidateParent:a}){const l=a?Re.useInvalidateParentMutation(o,r):Re.useApiMutation(o,r),c=Re.useMutate(l,{successMsg:i,errorMsg:s});return y.jsxs(N.Button,{display:"flex",alignItems:"center",gap:"3",...e,onClick:c,disabled:l.isLoading,children:[n&&y.jsx(N.Icon,{path:n}),t]})}function YV({actions:t}){const{ids:e}=Qc(),n=e&&e.length>0;return y.jsx(N.Collapse,{in:n,style:{overflow:n?"initial":"hidden"},children:y.jsx("div",{dflex:!0,gap:"3",flexWrap:!0,alignItems:"center",px:"8",pt:"5",children:t.map((r,o)=>y.jsx("div",{children:r.type=="button"&&!r.showConfirmationDialog&&y.jsx(XV,{label:r.label,queryFn:r.queryFn,queryKey:r.queryKey,buttonProps:r.buttonProps})},o))})})}function QV(t){const e=Qt.useParams();if(t===void 0)return;const{[t]:n}=e;return n}function ZV({queryField:t,title:e,subtitle:n,screen:r,...o}){const i=QV(t),s=Fe.runIfFn(r,i);return y.jsx(Fa,{p:"5",...o,children:y.jsx(S_,{columns:s.table.columns,initialVisibleColumns:s.table.initialVisibleColumns,children:y.jsx(e$,{id:i,title:e,subtitle:n,screen:s})})})}function e$({id:t,title:e,subtitle:n,screen:r}){const{setRowSelection:o}=Qc(),{api:i,table:s,filters:a,massActions:l,buttonBar:c,rowActions:u,createView:d,editView:h,deleteItem:f,breadcrumbs:p}=r,g=Fe.runIfFn(i,t??"");return y.jsxs(y.Fragment,{children:[p&&y.jsx(ug,{breadcrumbs:p}),y.jsxs(__,{title:e,queryKey:g.queryKey,children:[y.jsx(t$,{buttonBar:c,createView:d,editView:h,api:g}),a&&y.jsx(E_,{})]}),a&&y.jsx(GV,{form:a.form,initialValues:a.initialValues,schema:a.schema,processInput:a.processInput}),l&&y.jsx(YV,{actions:l.items}),y.jsxs($V,{queryKey:g.queryKey,editView:h,deleteItem:f,children:[y.jsx(n$,{table:{...s,onSelectionChange:o},rowActions:u,api:g,subtitle:n}),y.jsx(r$,{})]})]})}function t$({buttonBar:t,createView:e,editView:n,api:r}){const o=T.useCallback(i=>{const s=e??n;return s.type=="customDialog"?s.render({show:!0,onClose:i}):y.jsx(T_,{config:s,onClose:i,invalidateQueryKey:r.queryKey})},[n,r]);return y.jsx(y.Fragment,{children:t&&t.map((i,s)=>y.jsxs("div",{children:[i.type==="create"&&n&&y.jsx(C_,{buildDialog:o}),i.type==="invalidate"&&y.jsx(Zu,{pathOrPermalink:i.pathOrPermalink}),i.type==="custom"&&i.render()]},s))})}function n$({table:t,subtitle:e,rowActions:n,api:r}){const o=KV(r,t,n),i=T.useMemo(()=>{if(e)return s=>y.jsx("div",{textSize:"lg",textColor:"#475569",fontWeight:"600",children:Fe.isFunction(e)?e(s):e})},[e]);return y.jsx(MV,{...o,title:i})}function r$(){const{dialog:t}=O_();return t}function o$(t){const e=Qt.useParams(),{data:n,isFetching:r,isError:o}=Re.useApiQueries(t.map(s=>{if(!s.queryField||!Fe.isFunction(s.api)){const c=s.api;return{queryKey:c.queryKey,queryFn:s.fn=="get"?c.get:c.getAll,queryParam:s.params}}const a=e[s.queryField],l=Fe.runIfFn(s.api,a);return{queryKey:l.queryKey,queryFn:s.fn=="get"?l.get:l.getAll,queryParam:s.fn=="getAll"?s.params:Fe.isFunction(s.api)?void 0:a}}));let i;return!r&&!o&&(i=n==null?void 0:n.map((s,a)=>{var l,c;return t[a].transformFn?(c=(l=t[a]).transformFn)==null?void 0:c.call(l,s):s})),{data:i,isFetching:r,isError:o}}function i$(t){const e=Dg.useQueryClient(),n=Qt.useParams();return T.useCallback(()=>{const o=[];t.forEach(i=>{if(!i.queryField||!Fe.isFunction(i.api))o.push(i.api.queryKey);else{const s=n[i.queryField],a=Fe.runIfFn(i.api,s);o.push(a.queryKey)}}),e.invalidateQueries({predicate:i=>o.includes(i.queryKey)})},[t,e,n])}function s$({queries:t,config:e,tabbed:n,...r}){const{data:o,isFetching:i,isError:s}=o$(t),a=i$(t);return i?y.jsx(hr,{w:"full",h:"100vh"}):s||!o?y.jsx(Jr,{p:"0",w:"full",h:"100vh",onClick:a}):y.jsx(Zc,{config:e(...o),tabbed:n,...r})}function Zc({config:t,tabbed:e,...n}){return t.type==="table"?y.jsx(ZV,{...t,...n}):t.type==="tabbed"?y.jsx(gB,{...t,...n}):t.type==="details"?y.jsx(uB,{...t,tabbed:e,...n}):t.type==="query"?y.jsx(pB,{...t,tabbed:e,...n}):t.type==="multiQuery"?y.jsx(s$,{...t,tabbed:e,...n}):y.jsx(y.Fragment,{})}const k_="Oops, something went wrong...";function a$({queryId:t,queryKey:e,queryFetchFn:n,queryFetchAllKey:r,queryFetchAllFn:o,querySaveFn:i,matchKey:s,size:a="lg",show:l,onClose:c,itemLabel:u,onSuccess:d,onFetchError:h,fetchErrorMsg:f=k_,onSaveError:p,saveErrorMsg:g=k_,invalidateQueriesOnSuccess:m=!0,retryText:v="Retry",cancelLabel:C="Cancel",saveLabel:w,formikProps:b,getItemName:S,...E}){const x=Dg.useQueryClient(),{data:_,isInitialLoading:A,isError:O,refetch:k,error:M}=Re.useApiQuery(e,n),{data:I,isInitialLoading:P,isError:F,refetch:z,error:V}=Re.useApiQuery(r,o),[J,K]=T.useState([]),R=A||P,Q=O||F,se=Re.useApiMutation(i,e,t),ie=T.useCallback(D=>{const ce=(D==null?void 0:D.currentTarget.dataset.id)??"",ye=J.concat([]),be=J.indexOf(ce);be!=-1?ye.splice(be,1):ye.push(ce),K(ye)},[J,K]),de=T.useCallback(()=>{O&&k(),F&&z()},[k,z,O,F]),ue=T.useCallback(()=>{se.reset(),se.mutateAsync({resources:J}).then(D=>{d?d(D):He.success(`${u} saved`),m&&x.invalidateQueries({queryKey:e}),c==null||c()}).catch(D=>{console.error("on error",D),p?p():He.error(`Error adding ${u}`)})},[se,t,d,x,p,c]),pe=T.useMemo(()=>{let D=[];return _&&I&&(D=[].concat(I),_.forEach(ce=>D.splice(D.findIndex(ye=>ye.id==ce[s]),1)),S&&(D=D.map(ce=>({...ce,name:S(ce)}))),D=GT(D,["name"])),D},[_,I]);return y.jsxs(N.Modal,{size:a,show:l,onClose:c,scheme:"light",transition:!0,...E,children:[y.jsx(N.Modal.Header,{children:`Add ${u}`}),R&&y.jsx(N.Modal.Body,{children:y.jsx(hr,{minW:"72"})}),Q&&y.jsx(N.Modal.Body,{children:y.jsx(Jr,{label:`${f} ${M}`,onClick:de})}),!R&&!Q&&y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{px:"0",pb:"6",maxH:"750px",overflow:"auto",children:y.jsx("div",{dflex:!0,flexCol:!0,overflow:"auto",children:pe.map(D=>y.jsx(l$,{label:D.name,value:D.id,"data-id":D.id,checked:J.includes(`${D.id}`),onClick:ie},D.id))})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:se.isLoading,onClick:c,variant:"borderless",me:"2",children:C}),y.jsx(N.Button,{type:"submit",disabled:J.length==0||se.isLoading,onClick:ue,children:w||(t?"Update":"Create")})]})]}),se.isLoading&&y.jsx(Fi,{})]})}function l$({label:t,value:e,checked:n,...r}){return y.jsxs("div",{dflex:!0,alignItems:"center",hover_bgColor:"slate-100",px:"5",py:"2",cursor:"pointer",...r,children:[y.jsx("span",{flexGrow:!0,children:t}),y.jsx(N.Checkbox,{name:`resources.${e}`,value:e,checked:n})]})}function c$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFn:o,queryOptions:i,onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h,invalidateQueriesOnSuccess:f=!0,cancelLabel:p="Cancel",saveLabel:g="Send",size:m="lg",title:v,form:C,show:w,onClose:b,formikProps:S,...E}){const x=f?Re.useInvalidateParentMutation(o,r,i):Re.useApiMutation(o,r,n,i),_=Re.useMutate(x,{onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h});return y.jsxs(N.Modal,{size:m,show:w,onClose:b,scheme:"light",transition:!0,...E,children:[y.jsx(N.Modal.Header,{children:v}),y.jsxs(Ra,{initialValues:t??{},onSubmit:_,...S,children:[y.jsxs(N.Modal.Body,{pb:"6",children:[T.isValidElement(C)&&C,Array.isArray(C)&&y.jsx(pr,{form:C})]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:x.isLoading,onClick:b,variant:"borderless",me:"2",children:p}),y.jsx(Bd,{disabled:x.isLoading,children:g})]})]}),x.isLoading&&y.jsx(Fi,{})]})}const M_="Oops, something went wrong...";function P_(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function u$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFetchFn:o,queryFetchOptions:i,querySaveFn:s,querySaveOptions:a,onSuccess:l,onFetchError:c,fetchErrorMsg:u=M_,onSaveError:d,saveErrorMsg:h=M_,fetchToFormData:f,formToQueryData:p,invalidateQueriesOnSuccess:g=!0,invalidateQueryKey:m,retryText:v="Retry",cancelLabel:C="Cancel",saveLabel:w,size:b="lg",title:S,form:E,show:x,onClose:_,formikProps:A,...O}){const{isInitialLoading:k,isFetching:M,data:I,isError:P,error:F,refetch:z}=Re.useApiQuery(r,o,n,{enabled:!(n==""||n==null||n==null),onError:c,...i}),V=g?Re.useInvalidateParentMutation(s,m??r,a):Re.useApiMutation(s,r,n,a),J=T.useCallback(()=>z(),[z]),K=T.useCallback((R,Q)=>{V.reset();const se=p?p(R):{...R};V.mutateAsync(se).then(ie=>{l?l(se,ie):He.success(`${S?S(se):se.name??se.title} ${n?"saved":"created"}`),_==null||_()}).catch(ie=>{console.error("on error",ie),d?d(R):He.error(`Couldn't save ${S?S(se):se.name??se.title}`),Q.setSubmitting(!1)})},[V,p,l,d,_]);return y.jsxs(N.Modal,{size:b,show:x,onClose:_,scheme:"light",transition:!0,...O,children:[y.jsxs(N.Modal.Header,{children:[!k&&n&&`Edit ${S?S(I):(I==null?void 0:I.name)??(I==null?void 0:I.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(E)&&y.jsx(y.Fragment,{})]}),k&&y.jsx(N.Modal.Body,{children:y.jsx(hr,{minW:"72"})}),P&&y.jsx(N.Modal.Body,{children:y.jsx(Jr,{label:`${u} ${F}`,onClick:J})}),!k&&!P&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:f&&n&&I?f(P_(I)):P_(I)??t??{},onSubmit:K,...A,children:({setFieldValue:R,dirty:Q,handleSubmit:se,isValid:ie,values:de})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[T.isValidElement(E)&&E,Array.isArray(E)&&y.jsx(pr,{form:E}),Fe.isFunction(E)&&y.jsx(pr,{form:E(I??de)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:V.isLoading,onClick:_,variant:"borderless",me:"2",children:C}),y.jsx(N.Button,{type:"submit",disabled:!Q||V.isLoading,onClick:()=>se(),children:w||(n?"Update":"Create")})]})]})})}),V.isLoading&&y.jsx(Fi,{})]})}function I_({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"5",...e,children:t})}const d$=T.forwardRef(({loading:t=!1,children:e,...n},r)=>y.jsxs(y.Fragment,{children:[t&&y.jsx(hr,{w:"full",h:"100%"}),!t&&y.jsx(N.Container,{ref:r,center:!0,size:"x2",dflex:!0,flexCol:!0,gap:"8",...n,children:e})]}));function f$({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"3",...e,children:t})}const h$={draft:"Draft",published:"Published",pending:"Pending",approved:"Approved",partially_approved:"Partially Approved",rejected:"Rejected"},p$={draft:"warning",published:"success",pending:"secondary",approved:"success",partially_approved:"warning",rejected:"danger"};function g$({status:t,...e}){return y.jsx(N.Badge,{size:"sm",variant:"glass",whiteSpace:"nowrap",rounded:"full",px:"3",scheme:p$[t],...e,children:h$[t]})}function L_({path:t,...e}){const n=T.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),window.open(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${t}`,"_blank")},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"dark",onClick:n,...e,children:y.jsx(N.Icon,{path:ru})})}function D_({path:t,...e}){const n=Qt.useNavigate(),r=T.useCallback(o=>{o==null||o.preventDefault(),o==null||o.stopPropagation(),n(`${t}`)},[n,t]);return y.jsx(N.Button,{scheme:"secondary",w:"10",h:"10",variant:"borderless",corners:"pill",onClick:r,...e,children:y.jsx(N.Icon,{path:nu})})}function N_({children:t,...e}){return y.jsx(ia,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"warning",...e,children:t??y.jsx(N.Icon,{path:Ug})})}function R_({children:t,...e}){return y.jsx(ia,{w:"10",h:"10",scheme:"danger",variant:"borderless",corners:"pill",...e,children:t??y.jsx(N.Icon,{path:tu})})}function m$({publishId:t,viewPath:e,navigatePath:n,editDialog:r,deleteDialog:o,children:i,...s}){return y.jsxs("div",{dflex:!0,spaceX:"1",placeContent:"end",...s,children:[e&&y.jsx(L_,{path:e}),n&&y.jsx(D_,{path:n}),r&&y.jsx(N_,{buildDialog:r}),o&&y.jsx(R_,{buildDialog:o}),i]})}function y$({id:t,api:e,status:n,invalidateQueryKey:r,...o}){const i=n=="draft",s=Re.useInvalidateParentMutation(i?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=T.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>He.success(i?"Published!":"Unpublished!")).catch(c=>He.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...o,children:y.jsx(N.Icon,{path:i?qg:Wg})})}Ae.AttachDialog=a$,Ae.Breadcrumbs=Fu,Ae.DialogButton=ia,Ae.FormActionDialog=c$,Ae.IconButton=jx,Ae.InvalidateButton=Zu,Ae.ItemEditDialog=u$,Ae.NavigateButton=ZA,Ae.OrderCell=iM,Ae.PageContainer=Fa,Ae.PageContentEditor=qE,Ae.PageMain=UE,Ae.PageQueryStateContainer=lg,Ae.PageSectionTitle=I_,Ae.PageSidebar=WE,Ae.PageSidebarSection=KE,Ae.PageStateContainer=d$,Ae.PageSubSectionTitle=f$,Ae.PageTabbedTopBar=XE,Ae.PageTabbedTopBarProvider=JE,Ae.PageTitle=cg,Ae.PageTopBar=ug,Ae.PageTopBarToolbar=YE,Ae.PublishButton=Ly,Ae.ScreenRenderer=Zc,Ae.SectionTitle=K_,Ae.StatusBadge=g$,Ae.TableContainer=S_,Ae.TableCreateButton=C_,Ae.TableFilterButton=E_,Ae.TableRowActionBar=m$,Ae.TableRowDeleteButton=R_,Ae.TableRowEditButton=N_,Ae.TableRowNavigateButton=D_,Ae.TableRowPublishPostButton=y$,Ae.TableRowViewButton=L_,Ae.TableTopBar=__,Ae.UpdateButton=W0,Ae.ViewButton=K0,Object.defineProperty(Ae,Symbol.toStringTag,{value:"Module"})});
248
+ color: hsl(${Math.max(0,Math.min(120-120*m,120))}deg 100% 31%);`,n==null?void 0:n.key)}return(c=n==null?void 0:n.onChange)==null||c.call(n,o),o}return i.updateDeps=s=>{r=s},i}function Tg(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}const tV=(t,e)=>Math.abs(t-e)<1,nV=(t,e,n)=>{let r;return function(...o){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,o),n)}},rV=t=>t,oV=t=>{const e=Math.max(t.startIndex-t.overscan,0),n=Math.min(t.endIndex+t.overscan,t.count-1),r=[];for(let o=e;o<=n;o++)r.push(o);return r},iV=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;const o=s=>{const{width:a,height:l}=s;e({width:Math.round(a),height:Math.round(l)})};if(o(n.getBoundingClientRect()),!r.ResizeObserver)return()=>{};const i=new r.ResizeObserver(s=>{const a=()=>{const l=s[0];if(l!=null&&l.borderBoxSize){const c=l.borderBoxSize[0];if(c){o({width:c.inlineSize,height:c.blockSize});return}}o(n.getBoundingClientRect())};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return i.observe(n,{box:"border-box"}),()=>{i.unobserve(n)}},d_={passive:!0},f_=typeof window>"u"?!0:"onscrollend"in window,sV=(t,e)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;let o=0;const i=t.options.useScrollendEvent&&f_?()=>{}:nV(r,()=>{e(o,!1)},t.options.isScrollingResetDelay),s=u=>()=>{const{horizontal:d,isRtl:h}=t.options;o=d?n.scrollLeft*(h&&-1||1):n.scrollTop,i(),e(o,u)},a=s(!0),l=s(!1);l(),n.addEventListener("scroll",a,d_);const c=t.options.useScrollendEvent&&f_;return c&&n.addEventListener("scrollend",l,d_),()=>{n.removeEventListener("scroll",a),c&&n.removeEventListener("scrollend",l)}},aV=(t,e,n)=>{if(e!=null&&e.borderBoxSize){const r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}return Math.round(t.getBoundingClientRect()[n.options.horizontal?"width":"height"])},lV=(t,{adjustments:e=0,behavior:n},r)=>{var o,i;const s=t+e;(i=(o=r.scrollElement)==null?void 0:o.scrollTo)==null||i.call(o,{[r.options.horizontal?"left":"top"]:s,behavior:n})};class cV{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(o=>{o.forEach(i=>{const s=()=>{this._measureElement(i.target,i)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(s):s()})}));return{disconnect:()=>{var o;(o=r())==null||o.disconnect(),n=null},observe:o=>{var i;return(i=r())==null?void 0:i.observe(o,{box:"border-box"})},unobserve:o=>{var i;return(i=r())==null?void 0:i.unobserve(o)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([r,o])=>{typeof o>"u"&&delete n[r]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:rV,rangeExtractor:oV,onChange:()=>{},measureElement:aV,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,...n}},this.notify=n=>{var r,o;(o=(r=this.options).onChange)==null||o.call(r,this,n)},this.maybeNotify=bi(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{this.scrollAdjustments=0,this.scrollDirection=i?this.getScrollOffset()<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this.maybeNotify()}))}},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=(n,r)=>{const o=new Map,i=new Map;for(let s=r-1;s>=0;s--){const a=n[s];if(o.has(a.lane))continue;const l=i.get(a.lane);if(l==null||a.end>l.end?i.set(a.lane,a):a.end<l.end&&o.set(a.lane,!0),o.size===this.options.lanes)break}return i.size===this.options.lanes?Array.from(i.values()).sort((s,a)=>s.end===a.end?s.index-a.index:s.end-a.end)[0]:void 0},this.getMeasurementOptions=bi(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled],(n,r,o,i,s)=>(this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:o,getItemKey:i,enabled:s}),{key:!1}),this.getMeasurements=bi(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:o,getItemKey:i,enabled:s},a)=>{if(!s)return this.measurementsCache=[],this.itemSizeCache.clear(),[];this.measurementsCache.length===0&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const l=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const c=this.measurementsCache.slice(0,l);for(let u=l;u<n;u++){const d=i(u),h=this.options.lanes===1?c[u-1]:this.getFurthestMeasurement(c,u),f=h?h.end+this.options.gap:r+o,p=a.get(d),g=typeof p=="number"?p:this.options.estimateSize(u),m=f+g,v=h?h.lane:u%this.options.lanes;c[u]={index:u,start:f,size:g,end:m,key:d,lane:v}}return this.measurementsCache=c,c},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=bi(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,o,i)=>this.range=n.length>0&&r>0?uV({measurements:n,outerSize:r,scrollOffset:o,lanes:i}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=bi(()=>{let n=null,r=null;const o=this.calculateRange();return o&&(n=o.startIndex,r=o.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,o,i,s)=>i===null||s===null?[]:n({startIndex:i,endIndex:s,overscan:r,count:o}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,o=n.getAttribute(r);return o?parseInt(o,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this._measureElement=(n,r)=>{const o=this.indexFromElement(n),i=this.measurementsCache[o];if(!i)return;const s=i.key,a=this.elementsCache.get(s);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(s,n)),n.isConnected&&this.resizeItem(o,this.options.measureElement(n,r,this))},this.resizeItem=(n,r)=>{const o=this.measurementsCache[n];if(!o)return;const i=this.itemSizeCache.get(o.key)??o.size,s=r-i;s!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(o,s,this):o.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",s),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(o.index),this.itemSizeCache=new Map(this.itemSizeCache.set(o.key,r)),this.notify(!1))},this.measureElement=n=>{if(!n){this.elementsCache.forEach((r,o)=>{r.isConnected||(this.observer.unobserve(r),this.elementsCache.delete(o))});return}this._measureElement(n,void 0)},this.getVirtualItems=bi(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const o=[];for(let i=0,s=n.length;i<s;i++){const a=n[i],l=r[a];o.push(l)}return o},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length!==0)return Tg(r[h_(0,r.length-1,o=>Tg(r[o]).start,n)])},this.getOffsetForAlignment=(n,r,o=0)=>{const i=this.getSize(),s=this.getScrollOffset();r==="auto"&&(r=n>=s+i?"end":"start"),r==="center"?n+=(o-i)/2:r==="end"&&(n-=i);const a=this.options.horizontal?"scrollWidth":"scrollHeight",c=(this.scrollElement?"document"in this.scrollElement?this.scrollElement.document.documentElement[a]:this.scrollElement[a]:0)-i;return Math.max(Math.min(c,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const o=this.measurementsCache[n];if(!o)return;const i=this.getSize(),s=this.getScrollOffset();if(r==="auto")if(o.end>=s+i-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];const a=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,r,o.size),r]},this.isDynamicMode=()=>this.elementsCache.size>0,this.cancelScrollToIndex=()=>{this.scrollToIndexTimeoutId!==null&&this.targetWindow&&(this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId),this.scrollToIndexTimeoutId=null)},this.scrollToOffset=(n,{align:r="start",behavior:o}={})=>{this.cancelScrollToIndex(),o==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(n,r),{adjustments:void 0,behavior:o})},this.scrollToIndex=(n,{align:r="auto",behavior:o}={})=>{n=Math.max(0,Math.min(n,this.options.count-1)),this.cancelScrollToIndex(),o==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");const i=this.getOffsetForIndex(n,r);if(!i)return;const[s,a]=i;this._scrollToOffset(s,{adjustments:void 0,behavior:o}),o!=="smooth"&&this.isDynamicMode()&&this.targetWindow&&(this.scrollToIndexTimeoutId=this.targetWindow.setTimeout(()=>{if(this.scrollToIndexTimeoutId=null,this.elementsCache.has(this.options.getItemKey(n))){const[c]=Tg(this.getOffsetForIndex(n,a));tV(c,this.getScrollOffset())||this.scrollToIndex(n,{align:a,behavior:o})}else this.scrollToIndex(n,{align:a,behavior:o})}))},this.scrollBy=(n,{behavior:r}={})=>{this.cancelScrollToIndex(),r==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+n,{adjustments:void 0,behavior:r})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let o;if(r.length===0)o=this.options.paddingStart;else if(this.options.lanes===1)o=((n=r[r.length-1])==null?void 0:n.end)??0;else{const i=Array(this.options.lanes).fill(null);let s=r.length-1;for(;s>0&&i.some(a=>a===null);){const a=r[s];i[a.lane]===null&&(i[a.lane]=a.end),s--}o=Math.max(...i.filter(a=>a!==null))}return Math.max(o-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:o})=>{this.options.scrollToFn(n,{behavior:o,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.notify(!1)},this.setOptions(e)}}const h_=(t,e,n,r)=>{for(;t<=e;){const o=(t+e)/2|0,i=n(o);if(i<r)t=o+1;else if(i>r)e=o-1;else return o}return t>0?t-1:0};function uV({measurements:t,outerSize:e,scrollOffset:n,lanes:r}){const o=t.length-1;let s=h_(0,o,l=>t[l].start,n),a=s;if(r===1)for(;a<o&&t[a].end<n+e;)a++;else if(r>1){const l=Array(r).fill(0);for(;a<o&&l.some(u=>u<n+e);){const u=t[a];l[u.lane]=u.end,a++}const c=Array(r).fill(n+e);for(;s>0&&c.some(u=>u>=n);){const u=t[s];c[u.lane]=u.start,s--}s=Math.max(0,s-s%r),a=Math.min(o,a+(r-1-a%r))}return{startIndex:s,endIndex:a}}const p_=typeof document<"u"?Wr.useLayoutEffect:Wr.useEffect;function dV(t){const e=Wr.useReducer(()=>({}),{})[1],n={...t,onChange:(o,i)=>{var s;i?Mo.flushSync(e):e(),(s=t.onChange)==null||s.call(t,o,i)}},[r]=Wr.useState(()=>new cV(n));return r.setOptions(n),p_(()=>r._didMount(),[]),p_(()=>r._willUpdate()),r}function fV(t){return dV({observeElementRect:iV,observeElementOffset:sV,scrollToFn:lV,...t})}function hV(t,e){const{rows:n}=t.getRowModel(),r=fV({getScrollElement:()=>e,count:n.length,estimateSize:()=>35,overscan:10});return{rows:n,virtualRows:r.getVirtualItems(),totalSize:r.getTotalSize(),virtualizer:r}}function pV(t,e){const n=t.getIsPinned(),r=n==="left"&&t.getIsLastColumn("left"),o=n==="right"&&t.getIsFirstColumn("right");return{shadow:r?"-2px 0 2px -2px gray inset":o?"2px 0 2px -2px gray inset":void 0,start:n==="left"?`${t.getStart("left")}px`:void 0,end:n==="right"?`${t.getAfter("right")}px`:void 0,position:n?"sticky":"relative",w:t.getSize(),z:n?1:0,bgColor:n?e?"gray.50":"white":e?"gray.50":void 0}}function gV({table:t,containerRef:e,onRowClick:n,disabledRow:r}){var u,d;const{rows:o,virtualRows:i,totalSize:s,virtualizer:a}=hV(t,e),l=i.length>0&&((u=i==null?void 0:i[0])==null?void 0:u.start)||0,c=i.length>0?s-(((d=i==null?void 0:i[i.length-1])==null?void 0:d.end)||0):0;return y.jsxs("tbody",{children:[l>0&&y.jsx("tr",{children:y.jsx("td",{h:`${l}px`})}),i.map(h=>{const f=o[h.index],p=mV(f.original,r);return y.jsx("tr",{borderB:"px",borderBColor:"#F4F4F4",borderStyle:"dashed",hover_bgColor:"slate-50",cursor:n?"pointer":"default",onClick:n?()=>n(f.original):void 0,w:"fit-content",group:!0,children:f.getVisibleCells().map((g,m)=>y.jsx("td",{px:"3",py:"2",textSize:"sm",textColor:p?"gray.400":"gray.700",fontWeight:"500",borderTColor:"--bg-3",borderT:"0.5",cursor:n&&!p?"pointer":"default",w:`${g.column.getSize()}px`,groupHover_bgColor:p?void 0:"gray.100",...pV(g.column,p),children:u_(g.column.columnDef.cell,g.getContext())},g.id))},f.id)}),c>0&&y.jsx("tr",{children:y.jsx("td",{h:`${c}px`})})]})}function mV(t,e){return e?typeof e=="string"?t[e]:e(t):!1}function yV({headers:t}){const e=Fe.useThemeAwareColor("slate-500","slate-700");return y.jsx("thead",{children:t.map(n=>y.jsx("tr",{w:"fit",children:n.headers.map(r=>y.jsx("th",{position:"relative",colSpan:r.colSpan,textAlign:"start",fontWeight:"600",textColor:e,px:"3",py:"2",textSize:"sm",w:`${r.getSize()}px`,children:y.jsxs("div",{dflex:!0,flexRow:!0,children:[r.isPlaceholder?null:y.jsxs(y.Fragment,{children:[u_(r.column.columnDef.header,r.getContext()),y.jsx("span",{cursor:r.column.getCanSort()?"pointer":"default",onClick:r.column.getToggleSortingHandler(),opacity:"0",hover_opacity:"100",flexGrow:!0,textAlign:"end",children:{asc:y.jsx(y.Fragment,{children:" ▲"}),desc:y.jsx(y.Fragment,{children:" ▼"})}[r.column.getIsSorted()]??y.jsx(y.Fragment,{children:" ▲"})})]}),y.jsx("div",{onMouseDown:r.getResizeHandler(),onTouchStart:r.getResizeHandler(),onClick:o=>{o.preventDefault(),o.stopPropagation()},position:"absolute",end:"0",top:"0",h:"full",w:"2",bgColor:r.column.getIsResizing()?"primary-500":"slate-900",bgOpacity:r.column.getIsResizing()?"70":"30",cursor:"col-resize",userSelect:"none",style:{touchAction:"none"},opacity:r.column.getIsResizing()?"100":"0",hover_opacity:"100"})]})},r.id))},n.id))})}const[vV,Og]=Fe.createContext();function bV({initialPageSize:t,children:e}){const[n,r]=Qt.useSearchParams(),{pageIndex:o,pageSize:i}=T.useMemo(()=>({pageIndex:n.get("page")??1,pageSize:n.get("sizePerPage")??t??25}),[n,t]),s=T.useCallback(c=>{const u=Fe.runIfFn(c,{pageIndex:o,pageSize:i});r(d=>(d.set("page",`${u.pageIndex}`),d.set("sizePerPage",`${u.pageSize}`),d))},[r,o,i]),a=vV,l={pageIndex:typeof o=="string"?parseInt(o):o,pageSize:typeof i=="string"?parseInt(i):i,setPagination:s};return y.jsx(a,{value:l,children:e})}function g_({page:t,...e}){const{pageSize:n,pageIndex:r,setPagination:o}=Og(),i=T.useCallback(()=>o({pageIndex:1,pageSize:n}),[n,o]);return y.jsxs("div",{dflex:!0,flexCol:!0,gap:"10",w:"full",h:"full",alignItems:"center",placeContent:"center",py:"16",...e,children:[y.jsx(N.Icon,{path:ax,w:"24",h:"24",textColor:"gray.400"}),y.jsx("div",{textSize:"xl",textColor:"gray.600",children:"No Data"}),t>1&&y.jsx(N.Button,{onClick:i,children:"Back To First Page"})]})}function wV({table:t,isLoading:e}){const n=t.getPageCount(),r=t.getState().pagination.pageIndex+1,o=SV(r,n,5);return y.jsxs(y.Fragment,{children:[n<2&&y.jsx(y.Fragment,{}),n>1&&y.jsx(y.Fragment,{children:y.jsxs("div",{dflex:!0,flexRow:!0,spaceX:"2",py:"2",children:[y.jsx(wi,{onClick:()=>t.setPageIndex(0),disabled:e||r==1,children:y.jsx(N.Icon,{path:X_})}),y.jsx(wi,{onClick:()=>t.previousPage(),disabled:e||r==1,children:y.jsx(N.Icon,{path:Z_})}),o.length>0&&o[0]>1&&y.jsx("a",{children:"..."}),o.map(i=>y.jsx(wi,{onClick:()=>t.setPageIndex(i-1),disabled:e,variant:r==i?"default":"glass",scheme:"secondary",children:i},i)),o.length>0&&o[o.length-1]<n&&y.jsx(wi,{disabled:e,children:"..."}),y.jsx(wi,{onClick:()=>t.nextPage(),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:ex})}),y.jsx(wi,{onClick:()=>t.setPageIndex(t.getPageCount()-1),disabled:e||!t.getCanNextPage(),children:y.jsx(N.Icon,{path:Y_})})]})})]})}function wi({...t}){return y.jsx(N.Button,{scheme:"secondary",variant:"glass",corners:"pill",w:"8",h:"8",p:"0",dflex:!0,alignItems:"center",placeContent:"center",...t})}function SV(t,e,n){const r=[];if(!t)return r;if(e===1)return r.push(1),r;if(e<t)return r;if(e<n+1){for(let i=1;i<e+1;i++)r.push(i);return r}if(t===1){for(let i=1;i<n+1;i++)i<e&&r.push(i);return r}if(t===e){for(let i=e-n+1;i<=e;i++)i<=e&&r.push(i);return r}const o=Math.floor(n/2);if(o<1)return r.push(t),r;if(t<o+2){for(let i=1;i<n+1;i++)r.push(i);return r}if(e-t<o+2){for(let i=e-n;i<e+1;i++)r.push(i);return r}for(let i=t-o;i<t;i++)i>0&&r.push(i);r.push(t);for(let i=t+1;i<t+o+1;i++)i<=e&&r.push(i);return r}const CV=[{label:"25",value:25},{label:"50",value:50},{label:"100",value:100}];function EV({table:t,total:e,isLoading:n,reverseOrder:r,sizePerPageList:o}){const i=t.getState().pagination.pageIndex,s=t.getState().pagination.pageSize;return y.jsxs("div",{dflex:!0,flexDirection:r?"row-reverse":"row",alignItems:"center",py:"3",spaceX:"3",children:[y.jsx(N.Select,{disabled:e===0||n,onChange:a=>t.setPageSize(Number(a.target.value)),value:s,w:"20",children:(o??CV).map(a=>{const l=s===a.value;return y.jsx("option",{value:a.value,className:`btn ${l?"active":""}`,children:a.label},a.label)})}),y.jsxs("div",{children:["Showing rows ",1+i*s," to ",Math.min((i+1)*s,e)," of ",e]}),n&&y.jsx(N.Spinner,{size:"sm"})]})}function m_({isLoading:t,table:e,total:n,show:r,toolbarPosition:o="both",reverseOrder:i=!1,sizePerPageList:s,children:a,...l}){return y.jsxs("div",{...l,children:[r&&["top","both"].includes(o)&&y.jsx(y_,{isLoading:t,table:e,total:n,reverseOrder:i,sizePerPageList:s}),a,r&&["bottom","both"].includes(o)&&y.jsx(y_,{isLoading:t,table:e,total:n,reverseOrder:i,sizePerPageList:s})]})}function y_({isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:o}){return y.jsxs("div",{dflex:!0,justifyContent:"between",alignItems:"center",flexWrap:!0,flexDirection:r?"row-reverse":"row",children:[y.jsx(EV,{isLoading:t,table:e,total:n,reverseOrder:r,sizePerPageList:o}),y.jsx("div",{className:"d-flex flex-wrap"}),y.jsx(wV,{isLoading:t,table:e})]})}const[_V,v_]=Fe.createContext();function xV({sortBy:t,sortDir:e,children:n}){const[r,o]=Qt.useSearchParams(),{sortBy:i,sortDir:s}=T.useMemo(()=>({sortBy:r.get("sortBy")??t??"",sortDir:r.get("sortDir")??e??"asc"}),[r]),a=T.useCallback(u=>{const d=Fe.runIfFn(u,[{id:i,desc:s==="desc"}]);o(h=>{var f,p;return h.set("sortBy",`${((f=d==null?void 0:d[0])==null?void 0:f.id)??""}`),h.set("sortDir",`${(p=d==null?void 0:d[0])!=null&&p.desc?"desc":"asc"}`),h})},[o,i,s]),l=_V,c={sortBy:i,sortDir:s,setSorting:a};return y.jsx(l,{value:c,children:n})}function AV(t,e,n){const{setPagination:r}=Og(),{sortBy:o,sortDir:i,setSorting:s}=v_(),[a,l]=T.useState((n==null?void 0:n.rowSelection)??{}),c=T.useCallback(h=>{var f;l(h),(f=n==null?void 0:n.onSelectionChange)==null||f.call(n,Fe.runIfFn(h,a))},[l,a]),u=T.useCallback(h=>{var f;if(n!=null&&n.enableSelection&&(n!=null&&n.enableSelectOnRowClick)){h.toggleSelected();return}(f=n==null?void 0:n.onRowClick)==null||f.call(n,h.original)},[]);return{table:eV(Li({data:t??[],getRowId:h=>h.id,columns:e,columnResizeMode:"onChange",enableColumnResizing:!0,enableSortingRemoval:!1,defaultColumn:{size:150,minSize:40,maxSize:1e3},state:{sorting:[{id:o,desc:i==="desc"}],rowSelection:a},filterFns:{},enableRowSelection:n==null?void 0:n.enableSelection,onRowSelectionChange:c,onSortingChange:s,getCoreRowModel:WB(),getFilteredRowModel:XB(),onPaginationChange:r},n==null?void 0:n.tableOptions)),onRowClick:u}}const b_=T.createContext({});function Qc(){return T.useContext(b_)}const TV=["sortBy","sortDir","page","sizePerPage"];function OV({sortBy:t,sortDir:e,initialPageSize:n,children:r}){const[o,i]=Qt.useSearchParams(),s=T.useCallback(h=>{i(f=>(Object.keys(h).forEach(p=>{f.set(p,h[p]===void 0?"":h[p])}),f.set("page","1"),f))},[i]),a=T.useCallback(()=>{const h={},f=o.entries();for(const[p,g]of f)TV.includes(p)||(h[p]=g);return h},[o]),[l,c]=T.useState(),d={ids:T.useMemo(()=>{const h=Object.keys(l??{});return(h==null?void 0:h.filter(f=>l==null?void 0:l[f]))??[]},[l]),setRowSelection:c,getFilters:a,setFilters:s};return y.jsx(b_.Provider,{value:d,children:y.jsx(bV,{initialPageSize:n,children:y.jsx(xV,{sortBy:t,sortDir:e,children:r})})})}function kV(t,e,n){const r=Re.useInvalidateQuery(t),o=T.useMemo(()=>({onError:()=>He.error((n==null?void 0:n.errorMessage)??"Oops, something went wrong :("),refetchOnWindowFocus:!1,keepPreviousData:!0,retry:!1,staleTime:1e8}),[n]),{pageIndex:i,pageSize:s,setPagination:a}=Og(),{sortBy:l,sortDir:c}=v_(),{getFilters:u}=Qc(),d={pageSize:s,pageNumber:i,sortBy:l,sortDir:c,...n!=null&&n.transformFilters?n.transformFilters(u()):u()},h=T.useMemo(()=>({...o,...n==null?void 0:n.queryOptions}),[n]),{data:f,isError:p,isFetching:g,isLoading:m}=Re.useApiQuery(t,e,d,h),v=T.useCallback(r,[r]),{data:C}=f??{data:{data:void 0,meta:void 0}},{data:w,meta:b}=C;return{data:w&&(n!=null&&n.transformResponse)?n.transformResponse(w):w,response:C,retry:v,isError:p,isLoading:m,isFetching:g,page:(b==null?void 0:b.current_page)??1??i,pageSize:(b==null?void 0:b.per_page)??s,total:(b==null?void 0:b.total)??0,onPaginationChange:a}}function MV({columns:t,keyField:e="id",queryKey:n,queryFn:r,queryOptions:o,errorMessage:i,transformFilters:s,transformResponse:a,defaultSorted:l="name",defaultSortOrder:c="desc",nonSelectable:u,enableFilters:d=!1,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,onRowClick:g,onSelectionChange:m,sizePerPageList:v,paginationPosition:C,reversePaginationTools:w,containerEl:b,emptyMessage:S,title:E,disabledRow:x,pinnedColumnsLeft:_,pinnedColumnsRight:A,...O}){const k=T.useRef(null),{data:M,response:I,retry:P,isError:F,isLoading:z,isFetching:V,page:J,pageSize:K,total:R,onPaginationChange:Q}=kV(n,r,{errorMessage:i,queryOptions:o,transformResponse:a,transformFilters:s}),ie=AV(M??[],LV(t,h),{defaultSorted:l,defaultSortOrder:c,enableSelection:h,enableSelectOnRowClick:f,selectMode:p,nonSelectable:u,onRowClick:g,onSelectionChange:m,tableOptions:{enableColumnFilters:d,initialState:{columnPinning:{left:_??[],right:A??[]}},state:{pagination:{pageIndex:J,pageSize:K}},autoResetPageIndex:!1,pageCount:Math.ceil(R/K),onPaginationChange:Q}}).table;return y.jsxs("div",{px:"8",pt:"8",ref:k,h:"100%",children:[F&&y.jsx(Jr,{onClick:P,label:i}),(z||V&&(!M||(M==null?void 0:M.length)==0))&&y.jsx(hr,{}),!F&&!z&&M&&y.jsxs("div",{children:[E&&(Fe.isFunction(E)?E(I):E),O.mode=="table"&&y.jsx(PV,{table:ie,total:R??0,data:M,isLoading:V,containerEl:b??k.current,onRowClick:g,sizePerPageList:v,disabledRow:x}),O.mode=="grid"&&y.jsx(IV,{table:ie,total:R??0,data:M,isLoading:V,onRowClick:g,sizePerPageList:v,gridCols:O.gridCols,renderGridItem:O.renderGridItem})]})]})}function PV({table:t,total:e,data:n,isLoading:r,onRowClick:o,containerEl:i,sizePerPageList:s,disabledRow:a}){return y.jsxs(m_,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:s,children:[n.length==0&&y.jsx(g_,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",border:"2px",borderColor:"#F4F4F4",rounded:"base",my:"3",overflowX:"auto",children:y.jsxs("table",{style:{width:"max(1400px, 100%)",tableLayout:"fixed"},children:[y.jsx(yV,{headers:t.getHeaderGroups()}),y.jsx(gV,{table:t,containerRef:i,onRowClick:o,disabledRow:a})]})})]})}function IV({table:t,total:e,data:n,isLoading:r,onRowClick:o,sizePerPageList:i,gridCols:s,renderGridItem:a}){return y.jsxs(m_,{table:t,total:e??0,show:n&&n.length>0,isLoading:r,sizePerPageList:i,children:[n.length==0&&y.jsx(g_,{page:t.getState().pagination.pageIndex}),n.length>0&&y.jsx("div",{w:"full",children:y.jsx("div",{grid:!0,gridCols:`${s??3}`,gap:"5",w:"full",children:n.map(l=>a==null?void 0:a(l,o))})})]})}function LV(t,e){return e?[{id:"select-col",header:({table:n})=>y.jsx(N.Checkbox,{checked:n.getIsAllRowsSelected(),onChange:n.getToggleAllRowsSelectedHandler()}),cell:({row:n})=>y.jsx(N.Checkbox,{checked:n.getIsSelected(),disabled:!n.getCanSelect(),onChange:n.getToggleSelectedHandler()}),size:10,maxSize:1,enableResizing:!1}].concat(t):t}const[DV,NV]=Fe.createContext();function w_(t){return t.accessorKey??t.id}function RV({initialVisibleColumns:t,columns:e,children:n}){const[r,o]=T.useState(!1),[i,s]=T.useState(!1),[a,l]=T.useState(t??(e==null?void 0:e.map(p=>w_(p)))??[]),c=(e==null?void 0:e.filter(p=>a.includes(w_(p))))??[],u=T.useCallback(p=>{const g=a.indexOf(p);if(g>-1){const m=a.concat();m.splice(g,1),l(m)}else l(a.concat(p))},[a,l]),d=T.useCallback(p=>a.includes(p),[a]),h=DV,f={showFilters:r,setShowFilters:o,showMassActions:i,setShowMassActions:s,columns:e??[],filteredColumns:c,toggleColumnVisibility:u,isColumnVisible:d};return y.jsx(h,{value:f,children:n})}function S_({initialPageSize:t,initialVisibleColumns:e,columns:n,children:r,...o}){return y.jsx(N.Tile,{scheme:"light",shadow:!0,rounded:"md",px:"0",py:"4",w:"full",dflex:!0,flexCol:!0,...o,children:y.jsx(OV,{initialPageSize:t,children:y.jsx(RV,{columns:n,initialVisibleColumns:e,children:r})})})}function C_({children:t,...e}){return y.jsx(ia,{scheme:"default",corners:"pill",h:"10",variant:"glass",...e,children:t??y.jsx(N.Icon,{path:bx})})}function E_({...t}){return y.jsxs(N.Popover,{side:"bottom-end",modal:!0,children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",...t,children:y.jsx(N.Icon,{path:sx})}),y.jsxs("div",{bgColor:"white",rounded:!0,shadow:!0,children:[y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"First Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Second Item"}),y.jsx("div",{py:"3",hover_bgColor:"#ff0000",px:"5",hover_textColor:"white",children:"Third Item"})]})]})}function __({title:t,queryKey:e,children:n,...r}){const o=Re.useInvalidateQuery(e);return q0("ctrl+r",()=>o(),{preventDefault:!0},[o]),y.jsxs("div",{dflex:!0,flexRow:!0,pb:"4",alignItems:"center",gap:"3",px:"8",borderB:"0.5",borderBColor:"--bg-2",...r,children:[t&&y.jsx("h2",{textSize:"x3",fontWeight:"600",textColor:"#3f4254",textTransform:"capitalize",children:t}),y.jsx("div",{flexGrow:!0,children:" "}),y.jsxs("div",{spaceX:"2",dflex:!0,alignItems:"center",children:[y.jsx(N.Button,{scheme:"default",corners:"pill",w:"10",h:"10",variant:"glass",onClick:o,children:y.jsx(N.Icon,{path:Kg})}),n]})]})}const x_="Oops, something went wrong...";function A_(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function kg({initialValues:t,itemLabel:e,queryId:n="",api:r,queryFetchOptions:o,querySaveOptions:i,onSuccess:s,onFetchError:a,fetchErrorMsg:l=x_,onSaveError:c,saveErrorMsg:u=x_,fetchToFormData:d,formToQueryData:h,invalidateQueriesOnSuccess:f=!0,invalidateQueryKey:p,retryText:g="Retry",cancelLabel:m="Cancel",saveLabel:v,size:C="lg",title:w,form:b,show:S,onClose:E,formikProps:x,..._}){const{isInitialLoading:A,isFetching:O,data:k,isError:M,error:I,refetch:P}=Re.useApiQuery(r.queryKey,r.get,n,{enabled:!(n==""||n==null||n==null),onError:a,...o}),F=f?Re.useInvalidateParentMutation(r.upsert,p??r.queryKey,i):Re.useApiMutation(r.upsert,r.queryKey,n,i),z=T.useCallback(()=>P(),[P]),V=T.useCallback(async(J,K)=>{F.reset();const R=h?h(J):{...J};await F.mutateAsync(R).then(Q=>{s?s(R,Q):He.success(`${w?w(R):R.name??R.title} ${n?"saved":"created"}`),E==null||E()}).catch(Q=>{console.error("on error",Q),c?c(J):He.error(`Couldn't save ${w?w(R):R.name??R.title}`),K.setSubmitting(!1)})},[F,h,s,c,E]);return y.jsxs(N.Modal,{size:C,show:S,onClose:E,scheme:"light",transition:!0,..._,children:[y.jsxs(N.Modal.Header,{children:[!A&&n&&`Edit ${w?w(k):(k==null?void 0:k.name)??(k==null?void 0:k.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(b)&&y.jsx(y.Fragment,{})]}),A&&y.jsx(N.Modal.Body,{children:y.jsx(hr,{minW:"72"})}),M&&y.jsx(N.Modal.Body,{children:y.jsx(Jr,{label:`${l} ${I}`,onClick:z})}),!A&&!M&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:d&&n&&k?d(A_(k)):A_(t(k))??{},onSubmit:V,...x,children:({setFieldValue:J,dirty:K,handleSubmit:R,isValid:Q,values:se})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[T.isValidElement(b)&&b,Array.isArray(b)&&y.jsx(pr,{form:b}),Fe.isFunction(b)&&y.jsx(pr,{form:b(k??se)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:F.isLoading,onClick:E,variant:"borderless",me:"2",children:m}),y.jsx(N.Button,{type:"submit",disabled:!K||F.isLoading,onClick:()=>R(),children:v||(n?"Update":"Create")})]})]})})}),F.isLoading&&y.jsx(Fi,{})]})}function FV({api:t,fn:e,transformFn:n,config:r,onClose:o,queryId:i,invalidateQueryKey:s}){const{data:a,isFetching:l}=Re.useApiQuery(t.queryKey,e==="get"||e==="getTransformed"?t.get:t.getAll,void 0,{retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1}),c=T.useMemo(()=>a&&(e==="getTransformed"||e==="getAllTransformed")?(n||console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${e}`),n==null?void 0:n(a)):a,[a,e,n]);return l?null:y.jsx(kg,{...r(c),queryId:i,invalidateQueryKey:s,show:!0,onClose:o})}function HV({queries:t,config:e,onClose:n,queryId:r,invalidateQueryKey:o}){const{data:i,isFetching:s,isError:a}=Re.useApiQueries(t.map(c=>({queryKey:c.api.queryKey,queryFn:c.fn=="get"?c.api.get:c.api.getAll,queryOptions:{cacheTime:c.cache===!1?0:void 0,staleTime:c.cache===!1?0:void 0}}))),l=T.useMemo(()=>i==null?void 0:i.map((c,u)=>{var d,h;return t[u].transformFn?(h=(d=t[u])==null?void 0:d.transformFn)==null?void 0:h.call(d,c):c}),[i,t]);return y.jsx(kg,{isPreloading:s,...e(...l),queryId:r,invalidateQueryKey:o,show:!0,onClose:n})}function T_({config:t,onClose:e,invalidateQueryKey:n,queryId:r}){const{type:o,...i}=t;return t.type==="dialog"?y.jsx(kg,{...i,queryId:r,invalidateQueryKey:n,show:!0,onClose:e}):t.type==="query"?y.jsx(FV,{...i,queryId:r,invalidateQueryKey:n,onClose:e}):t.type==="multiQuery"?y.jsx(HV,{...i,queryId:r,invalidateQueryKey:n,onClose:e}):null}function BV({itemLabel:t,queryId:e="",api:n,invalidateQueriesOnSuccess:r=!0,invalidateQueryKey:o,size:i="lg",show:s,onClose:a,...l}){const c=r?Re.useInvalidateParentMutation(n.delete,o??n.queryKey):Re.useApiMutation(n.upsert,n.queryKey),u=Re.useMutate(c,{onSuccess:()=>a==null?void 0:a()}),d=T.useCallback(()=>u(e),[u,e]);return y.jsxs(N.Modal,{size:i,show:s,onClose:a,scheme:"danger",variant:"glass",transition:!0,...l,children:[y.jsx(N.Modal.Header,{children:`Delete ${t}`}),y.jsxs(N.Modal.Body,{pb:"6",children:["Do you really want to delete ",t,"?"]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:c.isLoading,onClick:a,variant:"borderless",scheme:"secondary",me:"2",children:"Cancel"}),y.jsx(N.Button,{scheme:"danger",disabled:c.isLoading,onClick:d,children:"Delete"})]}),c.isLoading&&y.jsx(Fi,{})]})}const[VV,O_]=Fe.createContext();function $V({editView:t,deleteItem:e,queryKey:n,children:r}){const o=Vy(),i=Qt.useNavigate(),[s,a]=T.useState(null),l=T.useCallback(()=>a(null),[a]),c=T.useCallback((h,f)=>{switch(h.type){case"view":{i(Fe.runIfFn(h.path,f));break}case"link":{o(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(h.path,f)}`);break}case"edit":{t.type=="customDialog"?a(t.render({show:!0,onClose:l})):a(y.jsx(T_,{onClose:l,config:t,queryId:f.id,invalidateQueryKey:n}));break}case"delete":{a(y.jsx(BV,{show:!0,onClose:l,queryId:f.id,invalidateQueryKey:n,...e,itemLabel:Fe.runIfFn(e.itemLabel,f)}));break}}},[i,t,e]),u=VV,d={dialog:s,onAction:c};return y.jsx(u,{value:d,children:r})}function jV({id:t,api:e,status:n,invalidateQueryKey:r,...o}){const i=n=="draft",s=Re.useInvalidateParentMutation(i?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=T.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>He.success(i?"Published!":"Unpublished!")).catch(c=>He.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...o,children:y.jsx(N.Icon,{path:i?qg:Wg})})}function zV({row:t,onAction:e,rowActions:n,api:r,queryKey:o}){const i=t.original;return y.jsx("div",{dflex:!0,spaceX:"1",placeContent:"end",children:n==null?void 0:n.map((s,a)=>y.jsxs(T.Fragment,{children:[s.type==="publish"&&y.jsx(jV,{id:i.id,api:r,status:i.status,invalidateQueryKey:o}),s.type=="custom"&&y.jsx(y.Fragment,{children:s.component(i,o,s.icon,s.label)}),!["publish","custom"].includes(s.type)&&y.jsx(UV,{onClick:()=>e(s,i),scheme:WV[s.type],children:y.jsx(N.Icon,{path:qV[s.type]})})]},a))})}function UV({onClick:t,...e}){const n=T.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),t==null||t(r)},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",onClick:n,...e})}const qV={link:ru,view:nu,edit:Ug,delete:tu,publish:tu,custom:""},WV={link:"dark",view:"secondary",edit:"warning",delete:"danger",publish:"warning",custom:"default"};function KV(t,e,n){const r=Qt.useNavigate(),o=Vy(),{onAction:i}=O_(),{onRowClick:s,columns:a,...l}=e,c=T.useCallback(h=>{(s==null?void 0:s.type)==="navigate"?r(Fe.runIfFn(s.path,h)):(s==null?void 0:s.type)=="link"&&o(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${Fe.runIfFn(s.path,h)}`)},[r,s]),u=T.useMemo(()=>{const h=e.columns.concat([]);return n&&h.push(yB().display({id:"actions",header:"Actions",cell:f=>y.jsx(zV,{row:f.row,onAction:i,rowActions:n,api:t,queryKey:t.queryKey})})),h},[e]),d={...l};return d.columns=u,d.onRowClick=c,d.queryKey=t.queryKey,d.queryFn=t.search,d}function GV({form:t,initialValues:e,schema:n,processInput:r}){const{showFilters:o}=NV(),{getFilters:i,setFilters:s}=Qc(),a=T.useCallback((c,u)=>{const d=(r==null?void 0:r(c))??c;Fy(d,i())||s(d),u.setSubmitting(!1)},[s,r]),l=T.useCallback(c=>{s(e),c()},[s,e]);return T.useEffect(()=>s(e),[]),y.jsx(N.Collapse,{in:o,style:{overflow:o?"initial":"hidden"},children:y.jsx("div",{p:"8",borderT:"px",borderB:"px",borderColor:"slate-100",children:y.jsx(Ra,{initialValues:H0(i(),e),onSubmit:a,validationSchema:n,enableReinitialize:!0,children:c=>y.jsxs("div",{dflex:!0,gap:"3",placeContent:"start",children:[y.jsx(pr,{flexRow:!0,w:"auto",form:t}),y.jsx(JV,{handleReset:()=>l(c.resetForm)})]})})})})}function JV({handleReset:t}){return y.jsxs("div",{dflex:!0,gap:"3",children:[y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(vn,{name:"",label:" "}),y.jsx(Bd,{children:"Filter"})]}),y.jsxs("div",{dflex:!0,flexCol:!0,children:[y.jsx(vn,{name:"",label:" "}),y.jsx(N.Button,{scheme:"neutral",onClick:t,children:"Reset"})]})]})}function XV({label:t,buttonProps:e,icon:n,queryKey:r,queryFn:o,successMsg:i,errorMsg:s,invalidateParent:a}){const l=a?Re.useInvalidateParentMutation(o,r):Re.useApiMutation(o,r),c=Re.useMutate(l,{successMsg:i,errorMsg:s});return y.jsxs(N.Button,{display:"flex",alignItems:"center",gap:"3",...e,onClick:c,disabled:l.isLoading,children:[n&&y.jsx(N.Icon,{path:n}),t]})}function YV({actions:t}){const{ids:e}=Qc(),n=e&&e.length>0;return y.jsx(N.Collapse,{in:n,style:{overflow:n?"initial":"hidden"},children:y.jsx("div",{dflex:!0,gap:"3",flexWrap:!0,alignItems:"center",px:"8",pt:"5",children:t.map((r,o)=>y.jsx("div",{children:r.type=="button"&&!r.showConfirmationDialog&&y.jsx(XV,{label:r.label,queryFn:r.queryFn,queryKey:r.queryKey,buttonProps:r.buttonProps})},o))})})}function QV(t){const e=Qt.useParams();if(t===void 0)return;const{[t]:n}=e;return n}function ZV({queryField:t,title:e,subtitle:n,screen:r,...o}){const i=QV(t),s=Fe.runIfFn(r,i);return y.jsx(Fa,{p:"5",...o,children:y.jsx(S_,{columns:s.table.columns,initialVisibleColumns:s.table.initialVisibleColumns,children:y.jsx(e$,{id:i,title:e,subtitle:n,screen:s})})})}function e$({id:t,title:e,subtitle:n,screen:r}){const{setRowSelection:o}=Qc(),{api:i,table:s,filters:a,massActions:l,buttonBar:c,rowActions:u,createView:d,editView:h,deleteItem:f,breadcrumbs:p}=r,g=Fe.runIfFn(i,t??"");return y.jsxs(y.Fragment,{children:[p&&y.jsx(ug,{breadcrumbs:p}),y.jsxs(__,{title:e,queryKey:g.queryKey,children:[y.jsx(t$,{buttonBar:c,createView:d,editView:h,api:g}),a&&y.jsx(E_,{})]}),a&&y.jsx(GV,{form:a.form,initialValues:a.initialValues,schema:a.schema,processInput:a.processInput}),l&&y.jsx(YV,{actions:l.items}),y.jsxs($V,{queryKey:g.queryKey,editView:h,deleteItem:f,children:[y.jsx(n$,{table:{...s,onSelectionChange:o},rowActions:u,api:g,subtitle:n}),y.jsx(r$,{})]})]})}function t$({buttonBar:t,createView:e,editView:n,api:r}){const o=T.useCallback(i=>{const s=e??n;return s.type=="customDialog"?s.render({show:!0,onClose:i}):y.jsx(T_,{config:s,onClose:i,invalidateQueryKey:r.queryKey})},[n,r]);return y.jsx(y.Fragment,{children:t&&t.map((i,s)=>y.jsxs("div",{children:[i.type==="create"&&n&&y.jsx(C_,{buildDialog:o}),i.type==="invalidate"&&y.jsx(Zu,{pathOrPermalink:i.pathOrPermalink}),i.type==="custom"&&i.render()]},s))})}function n$({table:t,subtitle:e,rowActions:n,api:r}){const o=KV(r,t,n),i=T.useMemo(()=>{if(e)return s=>y.jsx("div",{textSize:"lg",textColor:"#475569",fontWeight:"600",children:Fe.isFunction(e)?e(s):e})},[e]);return y.jsx(MV,{...o,title:i})}function r$(){const{dialog:t}=O_();return t}function o$(t){const e=Qt.useParams(),{data:n,isFetching:r,isError:o}=Re.useApiQueries(t.map(s=>{if(!s.queryField||!Fe.isFunction(s.api)){const c=s.api;return{queryKey:c.queryKey,queryFn:s.fn=="get"?c.get:c.getAll,queryParam:s.params}}const a=e[s.queryField],l=Fe.runIfFn(s.api,a);return{queryKey:l.queryKey,queryFn:s.fn=="get"?l.get:l.getAll,queryParam:s.fn=="getAll"?s.params:Fe.isFunction(s.api)?void 0:a}}));let i;return!r&&!o&&(i=n==null?void 0:n.map((s,a)=>{var l,c;return t[a].transformFn?(c=(l=t[a]).transformFn)==null?void 0:c.call(l,s):s})),{data:i,isFetching:r,isError:o}}function i$(t){const e=Dg.useQueryClient(),n=Qt.useParams();return T.useCallback(()=>{const o=[];t.forEach(i=>{if(!i.queryField||!Fe.isFunction(i.api))o.push(i.api.queryKey);else{const s=n[i.queryField],a=Fe.runIfFn(i.api,s);o.push(a.queryKey)}}),e.invalidateQueries({predicate:i=>o.includes(i.queryKey)})},[t,e,n])}function s$({queries:t,config:e,tabbed:n,...r}){const{data:o,isFetching:i,isError:s}=o$(t),a=i$(t);return i?y.jsx(hr,{w:"full",h:"100vh"}):s||!o?y.jsx(Jr,{p:"0",w:"full",h:"100vh",onClick:a}):y.jsx(Zc,{config:e(...o),tabbed:n,...r})}function Zc({config:t,tabbed:e,...n}){return t.type==="table"?y.jsx(ZV,{...t,...n}):t.type==="tabbed"?y.jsx(gB,{...t,...n}):t.type==="details"?y.jsx(uB,{...t,tabbed:e,...n}):t.type==="query"?y.jsx(pB,{...t,tabbed:e,...n}):t.type==="multiQuery"?y.jsx(s$,{...t,tabbed:e,...n}):y.jsx(y.Fragment,{})}const k_="Oops, something went wrong...";function a$({queryId:t,queryKey:e,queryFetchFn:n,queryFetchAllKey:r,queryFetchAllFn:o,querySaveFn:i,matchKey:s,size:a="lg",show:l,onClose:c,itemLabel:u,onSuccess:d,onFetchError:h,fetchErrorMsg:f=k_,onSaveError:p,saveErrorMsg:g=k_,invalidateQueriesOnSuccess:m=!0,retryText:v="Retry",cancelLabel:C="Cancel",saveLabel:w,formikProps:b,getItemName:S,...E}){const x=Dg.useQueryClient(),{data:_,isInitialLoading:A,isError:O,refetch:k,error:M}=Re.useApiQuery(e,n),{data:I,isInitialLoading:P,isError:F,refetch:z,error:V}=Re.useApiQuery(r,o),[J,K]=T.useState([]),R=A||P,Q=O||F,se=Re.useApiMutation(i,e,t),ie=T.useCallback(D=>{const ce=(D==null?void 0:D.currentTarget.dataset.id)??"",ye=J.concat([]),be=J.indexOf(ce);be!=-1?ye.splice(be,1):ye.push(ce),K(ye)},[J,K]),de=T.useCallback(()=>{O&&k(),F&&z()},[k,z,O,F]),ue=T.useCallback(()=>{se.reset(),se.mutateAsync({resources:J}).then(D=>{d?d(D):He.success(`${u} saved`),m&&x.invalidateQueries({queryKey:e}),c==null||c()}).catch(D=>{console.error("on error",D),p?p():He.error(`Error adding ${u}`)})},[se,t,d,x,p,c]),pe=T.useMemo(()=>{let D=[];return _&&I&&(D=[].concat(I),_.forEach(ce=>D.splice(D.findIndex(ye=>ye.id==ce[s]),1)),S&&(D=D.map(ce=>({...ce,name:S(ce)}))),D=GT(D,["name"])),D},[_,I]);return y.jsxs(N.Modal,{size:a,show:l,onClose:c,scheme:"light",transition:!0,...E,children:[y.jsx(N.Modal.Header,{children:`Add ${u}`}),R&&y.jsx(N.Modal.Body,{children:y.jsx(hr,{minW:"72"})}),Q&&y.jsx(N.Modal.Body,{children:y.jsx(Jr,{label:`${f} ${M}`,onClick:de})}),!R&&!Q&&y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{px:"0",pb:"6",maxH:"750px",overflow:"auto",children:y.jsx("div",{dflex:!0,flexCol:!0,overflow:"auto",children:pe.map(D=>y.jsx(l$,{label:D.name,value:D.id,"data-id":D.id,checked:J.includes(`${D.id}`),onClick:ie},D.id))})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:se.isLoading,onClick:c,variant:"borderless",me:"2",children:C}),y.jsx(N.Button,{type:"submit",disabled:J.length==0||se.isLoading,onClick:ue,children:w||(t?"Update":"Create")})]})]}),se.isLoading&&y.jsx(Fi,{})]})}function l$({label:t,value:e,checked:n,...r}){return y.jsxs("div",{dflex:!0,alignItems:"center",hover_bgColor:"slate-100",px:"5",py:"2",cursor:"pointer",...r,children:[y.jsx("span",{flexGrow:!0,children:t}),y.jsx(N.Checkbox,{name:`resources.${e}`,value:e,checked:n})]})}function c$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFn:o,queryOptions:i,onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h,invalidateQueriesOnSuccess:f=!0,cancelLabel:p="Cancel",saveLabel:g="Send",size:m="lg",title:v,form:C,show:w,onClose:b,formikProps:S,...E}){const x=f?Re.useInvalidateParentMutation(o,r,i):Re.useApiMutation(o,r,n,i),_=Re.useMutate(x,{onSuccess:s,successMsg:a,showSuccessMsg:l,onError:c,errorMsg:u,showErrorMsg:d,processInput:h});return y.jsxs(N.Modal,{size:m,show:w,onClose:b,scheme:"light",transition:!0,...E,children:[y.jsx(N.Modal.Header,{children:v}),y.jsxs(Ra,{initialValues:t??{},onSubmit:_,...S,children:[y.jsxs(N.Modal.Body,{pb:"6",children:[T.isValidElement(C)&&C,Array.isArray(C)&&y.jsx(pr,{form:C})]}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:x.isLoading,onClick:b,variant:"borderless",me:"2",children:p}),y.jsx(Bd,{disabled:x.isLoading,children:g})]})]}),x.isLoading&&y.jsx(Fi,{})]})}const M_="Oops, something went wrong...";function P_(t){if(t){const e={...t};for(const n in t)e[n]=e[n]??"";return e}return t}function u$({initialValues:t,itemLabel:e,queryId:n="",queryKey:r,queryFetchFn:o,queryFetchOptions:i,querySaveFn:s,querySaveOptions:a,onSuccess:l,onFetchError:c,fetchErrorMsg:u=M_,onSaveError:d,saveErrorMsg:h=M_,fetchToFormData:f,formToQueryData:p,invalidateQueriesOnSuccess:g=!0,invalidateQueryKey:m,retryText:v="Retry",cancelLabel:C="Cancel",saveLabel:w,size:b="lg",title:S,form:E,show:x,onClose:_,formikProps:A,...O}){const{isInitialLoading:k,isFetching:M,data:I,isError:P,error:F,refetch:z}=Re.useApiQuery(r,o,n,{enabled:!(n==""||n==null||n==null),onError:c,...i}),V=g?Re.useInvalidateParentMutation(s,m??r,a):Re.useApiMutation(s,r,n,a),J=T.useCallback(()=>z(),[z]),K=T.useCallback((R,Q)=>{V.reset();const se=p?p(R):{...R};V.mutateAsync(se).then(ie=>{l?l(se,ie):He.success(`${S?S(se):se.name??se.title} ${n?"saved":"created"}`),_==null||_()}).catch(ie=>{console.error("on error",ie),d?d(R):He.error(`Couldn't save ${S?S(se):se.name??se.title}`),Q.setSubmitting(!1)})},[V,p,l,d,_]);return y.jsxs(N.Modal,{size:b,show:x,onClose:_,scheme:"light",transition:!0,...O,children:[y.jsxs(N.Modal.Header,{children:[!k&&n&&`Edit ${S?S(I):(I==null?void 0:I.name)??(I==null?void 0:I.title)??""}`,!n&&`Create new ${e??"item"}`,Array.isArray(E)&&y.jsx(y.Fragment,{})]}),k&&y.jsx(N.Modal.Body,{children:y.jsx(hr,{minW:"72"})}),P&&y.jsx(N.Modal.Body,{children:y.jsx(Jr,{label:`${u} ${F}`,onClick:J})}),!k&&!P&&y.jsx(y.Fragment,{children:y.jsx(Xe.Formik,{initialValues:f&&n&&I?f(P_(I)):P_(I)??t??{},onSubmit:K,...A,children:({setFieldValue:R,dirty:Q,handleSubmit:se,isValid:ie,values:de})=>y.jsxs(y.Fragment,{children:[y.jsx(N.Modal.Body,{pb:"6",children:y.jsxs(Xe.Form,{children:[T.isValidElement(E)&&E,Array.isArray(E)&&y.jsx(pr,{form:E}),Fe.isFunction(E)&&y.jsx(pr,{form:E(I??de)})]})}),y.jsxs(N.Modal.Footer,{dflex:!0,placeContent:"end",spaceX:"3",children:[y.jsx(N.Button,{disabled:V.isLoading,onClick:_,variant:"borderless",me:"2",children:C}),y.jsx(N.Button,{type:"submit",disabled:!Q||V.isLoading,onClick:()=>se(),children:w||(n?"Update":"Create")})]})]})})}),V.isLoading&&y.jsx(Fi,{})]})}function I_({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"5",...e,children:t})}const d$=T.forwardRef(({loading:t=!1,children:e,...n},r)=>y.jsxs(y.Fragment,{children:[t&&y.jsx(hr,{w:"full",h:"100%"}),!t&&y.jsx(N.Container,{ref:r,center:!0,size:"x2",dflex:!0,flexCol:!0,gap:"8",...n,children:e})]}));function f$({children:t,...e}){return y.jsx("div",{trait:"typo.h6",mb:"3",...e,children:t})}const h$={draft:"Draft",published:"Published",pending:"Pending",approved:"Approved",partially_approved:"Partially Approved",rejected:"Rejected"},p$={draft:"warning",published:"success",pending:"secondary",approved:"success",partially_approved:"warning",rejected:"danger"};function g$({status:t,...e}){return y.jsx(N.Badge,{size:"sm",variant:"glass",whiteSpace:"nowrap",rounded:"full",px:"3",scheme:p$[t],...e,children:h$[t]})}function L_({path:t,...e}){const n=T.useCallback(r=>{r==null||r.preventDefault(),r==null||r.stopPropagation(),window.open(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${t}`,"_blank")},[t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"dark",onClick:n,...e,children:y.jsx(N.Icon,{path:ru})})}function D_({path:t,...e}){const n=Qt.useNavigate(),r=T.useCallback(o=>{o==null||o.preventDefault(),o==null||o.stopPropagation(),n(`${t}`)},[n,t]);return y.jsx(N.Button,{scheme:"secondary",w:"10",h:"10",variant:"borderless",corners:"pill",onClick:r,...e,children:y.jsx(N.Icon,{path:nu})})}function N_({children:t,...e}){return y.jsx(ia,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"warning",...e,children:t??y.jsx(N.Icon,{path:Ug})})}function R_({children:t,...e}){return y.jsx(ia,{w:"10",h:"10",scheme:"danger",variant:"borderless",corners:"pill",...e,children:t??y.jsx(N.Icon,{path:tu})})}function m$({publishId:t,viewPath:e,navigatePath:n,editDialog:r,deleteDialog:o,children:i,...s}){return y.jsxs("div",{dflex:!0,spaceX:"1",placeContent:"end",...s,children:[e&&y.jsx(L_,{path:e}),n&&y.jsx(D_,{path:n}),r&&y.jsx(N_,{buildDialog:r}),o&&y.jsx(R_,{buildDialog:o}),i]})}function y$({id:t,api:e,status:n,invalidateQueryKey:r,...o}){const i=n=="draft",s=Re.useInvalidateParentMutation(i?e.publish:e.unpublish,r??e.queryKey,{networkMode:"always"}),a=T.useCallback(l=>{l==null||l.preventDefault(),l==null||l.stopPropagation(),s.reset(),s.mutateAsync(t).then(()=>He.success(i?"Published!":"Unpublished!")).catch(c=>He.error(`Error: ${c}`))},[s,t]);return y.jsx(N.Button,{w:"10",h:"10",variant:"borderless",corners:"pill",scheme:"default",onClick:a,...o,children:y.jsx(N.Icon,{path:i?qg:Wg})})}Ae.AttachDialog=a$,Ae.Breadcrumbs=Fu,Ae.DialogButton=ia,Ae.FormActionDialog=c$,Ae.IconButton=jx,Ae.InvalidateButton=Zu,Ae.ItemEditDialog=u$,Ae.NavigateButton=ZA,Ae.OrderCell=iM,Ae.PageContainer=Fa,Ae.PageContentEditor=qE,Ae.PageMain=UE,Ae.PageQueryStateContainer=lg,Ae.PageSectionTitle=I_,Ae.PageSidebar=WE,Ae.PageSidebarSection=KE,Ae.PageStateContainer=d$,Ae.PageSubSectionTitle=f$,Ae.PageTabbedTopBar=XE,Ae.PageTabbedTopBarProvider=JE,Ae.PageTitle=cg,Ae.PageTopBar=ug,Ae.PageTopBarToolbar=YE,Ae.PublishButton=Ly,Ae.ScreenRenderer=Zc,Ae.SectionTitle=K_,Ae.StatusBadge=g$,Ae.TableContainer=S_,Ae.TableCreateButton=C_,Ae.TableFilterButton=E_,Ae.TableRowActionBar=m$,Ae.TableRowDeleteButton=R_,Ae.TableRowEditButton=N_,Ae.TableRowNavigateButton=D_,Ae.TableRowPublishPostButton=y$,Ae.TableRowViewButton=L_,Ae.TableTopBar=__,Ae.UpdateButton=W0,Ae.ViewButton=K0,Object.defineProperty(Ae,Symbol.toStringTag,{value:"Module"})});
@@ -78,7 +78,7 @@ type TableFilters = {
78
78
  form: FormRendererConfig;
79
79
  initialValues: any | ((data: any) => any);
80
80
  schema?: Yup.AnySchema;
81
- processInput: (input: any) => any;
81
+ processInput?: (input: any) => any;
82
82
  };
83
83
  type TableMassActions = {
84
84
  items: MassAction[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compill/admin",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {