@starasia/admin 12.14.0 → 12.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(g,tr){typeof exports=="object"&&typeof module<"u"?tr(exports,require("@starasia/alert"),require("@starasia/badges"),require("@starasia/box"),require("@starasia/breadcrumb"),require("@starasia/button"),require("@starasia/card"),require("@starasia/date"),require("@starasia/dialog"),require("@starasia/drawer"),require("@starasia/dropdown"),require("@starasia/hooks"),require("@starasia/http"),require("@starasia/input"),require("@starasia/menu"),require("@starasia/pagination"),require("@starasia/storage"),require("@starasia/table"),require("@starasia/tabs"),require("@starasia/textarea"),require("@starasia/theme"),require("@starasia/toast"),require("@starasia/toggle"),require("@starasia/tooltip"),require("@starasia/checkbox"),require("@starasia/radio"),require("@starasia/text"),require("@starasia/icon"),require("@starasia/flex"),require("@starasia/grid"),require("@starasia/progress"),require("@starasia/stepper"),require("@starasia/accordion"),require("@starasia/story-record"),require("@starasia/skeleton"),require("@starasia/progress-stepper"),require("react/jsx-runtime"),require("react"),require("react-dom"),require("react-easy-crop")):typeof define=="function"&&define.amd?define(["exports","@starasia/alert","@starasia/badges","@starasia/box","@starasia/breadcrumb","@starasia/button","@starasia/card","@starasia/date","@starasia/dialog","@starasia/drawer","@starasia/dropdown","@starasia/hooks","@starasia/http","@starasia/input","@starasia/menu","@starasia/pagination","@starasia/storage","@starasia/table","@starasia/tabs","@starasia/textarea","@starasia/theme","@starasia/toast","@starasia/toggle","@starasia/tooltip","@starasia/checkbox","@starasia/radio","@starasia/text","@starasia/icon","@starasia/flex","@starasia/grid","@starasia/progress","@starasia/stepper","@starasia/accordion","@starasia/story-record","@starasia/skeleton","@starasia/progress-stepper","react/jsx-runtime","react","react-dom","react-easy-crop"],tr):(g=typeof globalThis<"u"?globalThis:g||self,tr(g["@starasia/admin"]={},g.alert,g.badges,g.box,g.breadcrumb,g.button,g.card,g.date,g.dialog,g.drawer,g.dropdown,g.hooks,g.http,g.input,g.menu,g.pagination,g.storage,g.table,g.tabs,g.textarea,g.theme,g.toast,g.toggle,g.tooltip,g.checkbox,g.radio,g.text,g.icon,g.flex,g.grid,g.progress,g.stepper,g.accordion,g.storyRecord,g.skeleton,g.progressStepper,g.jsxRuntime,g.React,g.ReactDOM,g.ReactEasyCrop))})(this,function(g,tr,Ye,u,or,N,It,er,Ae,kr,lr,be,nr,Xe,W,gr,ur,Q,Ot,Jr,cr,Wt,sr,Be,Ze,Yr,k,T,ne,At,zt,Ht,Vt,Pt,ze,jt,e,h,Br,bl){"use strict";const Cl={menus:[],menuBottom:void 0,logo:"",appName:"Workspace",userData:null,setUserData:()=>{}},Xr=h.createContext(Cl),$r=()=>h.useContext(Xr),Nt=r=>{const[t,o]=h.useState((r==null?void 0:r.initialUserData)||null);return{userData:t,setUserData:o}},_t=h.createContext({badges:{},setBadge:()=>{},setBadges:()=>{},clearBadge:()=>{}}),qt=({children:r})=>{const[t,o]=h.useState({}),n=h.useCallback(i=>{o(a=>typeof i=="function"?i(a):i)},[]),l=h.useCallback((i,a)=>{o(d=>{const y=typeof a=="function"?a(d[i]):a;return{...d,[i]:y}})},[]),c=h.useCallback(i=>{o(a=>{if(!(i in a))return a;const d={...a};return delete d[i],d})},[]),s=h.useMemo(()=>({badges:t,setBadge:l,setBadges:n,clearBadge:c}),[t,l,n,c]);return e.jsx(_t.Provider,{value:s,children:r})},Zt=()=>h.useContext(_t),mr=(r,t)=>{const o=t!==void 0?t:r;return o==null?null:typeof o=="string"||typeof o=="number"?{value:o}:o},Gt=h.createContext({collapsed:!1,setCollapsed:()=>{},toggle:()=>{},collapse:()=>{},expand:()=>{},mobileOpen:!1,setMobileOpen:()=>{},openMobile:()=>{},closeMobile:()=>{},toggleMobile:()=>{}}),Qt=({children:r,defaultCollapsed:t=!1})=>{const[o,n]=h.useState(t),[l,c]=h.useState(!1),s=h.useCallback(x=>{n(L=>typeof x=="function"?x(L):x)},[]),i=h.useCallback(()=>n(x=>!x),[]),a=h.useCallback(()=>n(!0),[]),d=h.useCallback(()=>n(!1),[]),y=h.useCallback(x=>{c(L=>typeof x=="function"?x(L):x)},[]),b=h.useCallback(()=>c(!0),[]),p=h.useCallback(()=>c(!1),[]),v=h.useCallback(()=>c(x=>!x),[]),B=h.useMemo(()=>({collapsed:o,setCollapsed:s,toggle:i,collapse:a,expand:d,mobileOpen:l,setMobileOpen:y,openMobile:b,closeMobile:p,toggleMobile:v}),[o,s,i,a,d,l,y,b,p,v]);return e.jsx(Gt.Provider,{value:B,children:r})},Ut=()=>h.useContext(Gt),Jt=h.createContext(null),Yt=({adapter:r,children:t})=>e.jsx(Jt.Provider,{value:r,children:t}),Ge=()=>{const r=h.useContext(Jt);if(!r)throw new Error("[@starasia/admin] Router adapter belum dipasang. Bungkus aplikasi dengan <App routerAdapter={...} /> atau <StarasiaRouterProvider adapter={...}>. Import adapter dari '@starasia/admin/adapters/react-router' atau '@starasia/admin/adapters/tanstack'.");return r},Xt=({router:r,routerAdapter:t,menus:o=[],menuBottom:n,logo:l,appName:c="Workspace",initialUserData:s,theme:i})=>{const a=Nt({initialUserData:s}),{theme:d}=cr.useTheme();return e.jsx(Yt,{adapter:t,children:e.jsx(Xr.Provider,{value:{logo:l,appName:c,menus:o,userData:a.userData,setUserData:a.setUserData,menuBottom:n},children:e.jsx(qt,{children:e.jsx(Qt,{children:i?e.jsx(cr.ThemeProvider,{value:i,children:r}):d?e.jsx(cr.ThemeProvider,{value:d,children:r}):r})})})})},vl=h.memo(Xt);function $t({collapsed:r=!1,children:t}){if(!t)return null;const o=typeof t=="function",n=o?t({collapsed:r}):t;return n==null||n===!1?null:e.jsx("div",{style:{position:"sticky",top:"4rem",zIndex:1,borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",paddingLeft:"0.5rem",paddingRight:"0.5rem",paddingTop:"0.5rem",paddingBottom:"0.5rem",boxSizing:"border-box"},children:o?n:e.jsx("div",{style:{opacity:r?0:1,transition:"opacity 0.3s",visibility:r?"hidden":"visible"},children:n})})}const Kr=h.createContext(null);function Kt({children:r}){const[t,o]=h.useState(null),[n,l]=h.useState(null),[c,s]=h.useState(null),[i,a]=h.useState(0),d=h.useCallback(()=>(a(y=>y+1),()=>a(y=>y-1)),[]);return e.jsx(Kr.Provider,{value:{prependNode:t,appendNode:n,replaceNode:c,setPrependNode:o,setAppendNode:l,setReplaceNode:s,replaceCount:i,registerReplace:d},children:r})}function Rt({children:r}){const t=h.useContext(Kr);return t?e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:t.setPrependNode,style:{display:"contents"}}),t.replaceCount>0?e.jsx("div",{ref:t.setReplaceNode,style:{display:"contents"}}):r,e.jsx("div",{ref:t.setAppendNode,style:{display:"contents"}})]}):e.jsx(e.Fragment,{children:r})}function xl({children:r,mode:t="append"}){const o=h.useContext(Kr);if(h.useEffect(()=>{if(!(t!=="replace"||!o))return o.registerReplace()},[t,o]),!o)return process.env.NODE_ENV!=="production"&&console.warn("[HeaderLeftSlot] used outside AppLayout — content not rendered"),null;const n=t==="prepend"?o.prependNode:t==="replace"?o.replaceNode:o.appendNode;return n?Br.createPortal(r,n):null}const Rr=h.createContext(null);function eo({children:r}){const[t,o]=h.useState({}),[n,l]=h.useState({}),c=h.useCallback((a,d)=>{o(y=>y[a]===d?y:{...y,[a]:d})},[]),s=h.useCallback(a=>(l(d=>({...d,[a]:(d[a]??0)+1})),()=>l(d=>({...d,[a]:Math.max(0,(d[a]??0)-1)}))),[]),i=h.useMemo(()=>({outletNodes:t,setOutletNode:c,slotCounts:n,registerSlot:s}),[t,c,n,s]);return e.jsx(Rr.Provider,{value:i,children:r})}function ro({slotKey:r,fallback:t}){const o=h.useContext(Rr),n=o?(o.slotCounts[r]??0)>0:!1,l=h.useRef(o==null?void 0:o.setOutletNode);l.current=o==null?void 0:o.setOutletNode;const c=h.useCallback(s=>{var i;return(i=l.current)==null?void 0:i.call(l,r,s)},[r]);return e.jsx(e.Fragment,{children:n?e.jsx("div",{ref:c,style:{display:"contents"}}):t})}function wl({slotKey:r,children:t}){const o=h.useContext(Rr),n=h.useRef(o==null?void 0:o.registerSlot);if(n.current=o==null?void 0:o.registerSlot,h.useEffect(()=>{var c;return(c=n.current)==null?void 0:c.call(n,r)},[r]),!o)return process.env.NODE_ENV!=="production"&&console.warn("[SidebarGroupSlot] used outside AppLayout — content not rendered"),null;const l=o.outletNodes[r];return l?Br.createPortal(t,l):null}const Fr="moduleSwitcherGroupId",et="sa-module-switcher-change";function to(){if(typeof window>"u")return null;const r=window.localStorage.getItem(Fr);if(r===null)return null;const t=Number(r);return Number.isFinite(t)?t:null}function oo(r){typeof window>"u"||(r===null?window.localStorage.removeItem(Fr):window.localStorage.setItem(Fr,String(r)),window.dispatchEvent(new CustomEvent(et,{detail:r})))}function Dl(){oo(null)}function rt(){const[r,t]=h.useState(()=>to());return h.useEffect(()=>{const n=()=>{t(to())},l=c=>{c.key===Fr&&n()};return window.addEventListener(et,n),window.addEventListener("storage",l),()=>{window.removeEventListener(et,n),window.removeEventListener("storage",l)}},[]),{selectedGroupId:r,setSelectedGroupId:n=>{oo(n),t(n)}}}let Er=0,rr=!1,lo=new Set;const no=()=>e.jsxs("svg",{width:"100%",height:"100%",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"1.667",y:"1.667",width:"12.667",height:"12.667",rx:"2"}),e.jsx("line",{x1:"6",y1:"1.667",x2:"6",y2:"14.333"})]});function Sl(r){const[t,o]=h.useState(!1),n=h.useRef(null),l=h.useRef(null);return h.useLayoutEffect(()=>{const c=n.current;if(!c)return;let s=0;const i=()=>{s=0;const d=l.current;if(!d)return;const y=d.scrollWidth>c.clientWidth;o(b=>b===y?b:y)},a=new ResizeObserver(()=>{s||(s=requestAnimationFrame(i))});return a.observe(c),i(),()=>{s&&cancelAnimationFrame(s),a.disconnect()}},[r]),{containerRef:n,textRef:l,truncated:t}}function co({text:r,textStyle:t}){const{containerRef:o,textRef:n,truncated:l}=Sl(r),c=e.jsx("span",{ref:n,style:{display:"block",fontSize:"0.875rem",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",...t},children:r});return e.jsx("div",{ref:o,style:{flex:1,minWidth:0},children:l?e.jsx(Be.Tooltip,{fluid:!0,label:r,position:"top",children:c}):c})}const so={width:"100%",display:"flex",alignItems:"center",gap:"0.75rem",paddingLeft:"0.75rem",paddingRight:"0.75rem",paddingTop:"0.5rem",paddingBottom:"0.5rem",fontSize:"0.875rem",color:"var(--sa-text-subtle, #8c8f97)",background:"transparent",border:"none",borderRadius:"0.375rem",cursor:"pointer",textAlign:"left"};function kl({children:r,headerLeftSlot:t,profile:o,isLoadingProfile:n,onLogout:l,isLoggingOut:c,loadingComponent:s,sidebarHeaderContent:i,headerActions:a,profileRole:d,profileMenuButtons:y,profileMenuItems:b,logoutButton:p}){var dr,P;const{useSearchParams:v,useNavigate:B,useLocation:x,Outlet:L}=Ge(),[F]=v(),A=F.get("embed")==="true",D=$r(),{badges:m}=Zt(),H=B(),z=x(),E=!be.useMediaQuery("md"),[U,X]=h.useState(!1),{collapsed:G,setCollapsed:R,mobileOpen:_,setMobileOpen:K}=Ut(),[te,q]=h.useState(!1),[j,Z]=h.useState(()=>new Set(lo)),[le,Ce]=h.useState(null),{selectedGroupId:ve,setSelectedGroupId:he}=rt();h.useEffect(()=>{lo=j},[j]);const ge=h.useRef(null),xe=h.useRef(null);h.useEffect(()=>{const S=ge.current;if(!S)return;const O=()=>{rr||(Er=S.scrollTop)};return S.addEventListener("scroll",O),()=>S.removeEventListener("scroll",O)},[]);const Ee=()=>{const S=ge.current;S&&Er>0&&(rr=!0,S.scrollTop=Er,requestAnimationFrame(()=>{rr=!1}))};h.useLayoutEffect(()=>{rr=!0,Ee();const S=setTimeout(()=>{rr=!1},300);return()=>clearTimeout(S)},[]),h.useLayoutEffect(()=>{D.menus.length>0&&(Er>0?Ee():requestAnimationFrame(()=>{var O;const S=(O=ge.current)==null?void 0:O.querySelector("[data-menu-active='true']");S&&S.scrollIntoView({block:"center",behavior:"instant"})}))},[D.menus]),h.useEffect(()=>{rr=!0,Ee();const S=setTimeout(Ee,0),O=setTimeout(Ee,50),V=setTimeout(Ee,100),J=setTimeout(Ee,200),de=setTimeout(()=>{rr=!1},300),Me=setTimeout(()=>{const fe=ge.current,oe=fe==null?void 0:fe.querySelector("[data-menu-active='true']");if(fe&&oe){const pe=fe.getBoundingClientRect(),Le=oe.getBoundingClientRect();Le.top>=pe.top&&Le.bottom<=pe.bottom||oe.scrollIntoView({block:"center",behavior:"smooth"})}},250);return()=>{clearTimeout(S),clearTimeout(O),clearTimeout(V),clearTimeout(J),clearTimeout(de),clearTimeout(Me)}},[z.pathname]),h.useEffect(()=>{xe.current&&(xe.current.scrollTop=0)},[z.pathname]),h.useEffect(()=>{E&&K(!1)},[z.pathname,E]),h.useEffect(()=>{E&&R(!0)},[E]);const Oe=()=>{X(!0)},Ve=()=>{X(!1)},Pe=()=>{X(!1),l()},ke=S=>{const O=[S.to];return S.children&&O.push(...S.children.map(V=>V.to)),O},je=[...D.menus.flatMap(S=>S.items.flatMap(ke)),...((dr=D.menuBottom)==null?void 0:dr.flatMap(ke))??[]],we=S=>{if(!z.pathname.startsWith(S))return!1;const O=je.filter(V=>z.pathname.startsWith(V)).sort((V,J)=>J.length-V.length)[0];return S===O};h.useEffect(()=>{var O;const S=V=>{var J;(J=V.children)!=null&&J.some(de=>z.pathname.startsWith(de.to))&&Z(de=>{const Me=new Set(de);return Me.add(V.id),Me})};D.menus.forEach(V=>{V.items.forEach(S)}),(O=D.menuBottom)==null||O.forEach(S)},[z.pathname,D.menus,D.menuBottom]);const $e=S=>{Z(O=>{const V=new Set(O);return V.has(S)?V.delete(S):V.add(S),V})};h.useEffect(()=>{D.menus.length!==0&&ve!==null&&!D.menus.some(S=>S.id===ve)&&he(null)},[D.menus,ve,he]);const De=h.useMemo(()=>{if(ve!==null)return D.menus.filter(V=>V.id===ve||V.parentGroupId===ve);const S=D.menus.filter(V=>V.parentGroupId===void 0),O=D.menus.filter(V=>V.parentGroupId!==void 0).flatMap(V=>V.items);return O.length===0?S:[...S,{id:18,name:"Pengaturan",items:O,parentGroupId:void 0}]},[D.menus,ve]);if(A)return e.jsx("main",{style:{height:"100vh",overflowY:"auto",backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)"},children:r||e.jsx(L,{})});const Ne=S=>{const O=S.children&&S.children.length>0,V=j.has(S.id),J=O?S.children.some(fe=>we(fe.to)):we(S.to),de=mr(S.badge,m[S.id]),Me=!!de&&G&&!E;return e.jsxs("div",{"data-menu-active":J||void 0,children:[e.jsxs("button",{onClick:fe=>{if(O)if(G&&!E){const oe=fe.currentTarget.getBoundingClientRect();Ce({item:S,top:oe.top,left:oe.right+8})}else $e(S.id);else H(S.to)},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:G&&!E?"center":void 0,gap:"0.5rem",paddingLeft:G&&!E?"0":"0.5rem",paddingRight:G&&!E?"0":"0.5rem",paddingTop:"0.25rem",paddingBottom:"0.25rem",height:"2rem",borderRadius:J?"var(--sa-radii-sm, 0.375rem)":"var(--sa-radii-md, 0.5rem)",textAlign:"left",border:J?"1px solid var(--sa-border-subtle, #0b120e24)":"1px solid transparent",backgroundColor:J?"var(--sa-background-primary, #ffffff)":"transparent",color:"var(--sa-text-primary, #292a2e)",cursor:"pointer"},title:G&&!E?S.title:void 0,onMouseEnter:fe=>{J||(fe.currentTarget.style.backgroundColor="var(--sa-background-neutral, #f0f1f2)")},onMouseLeave:fe=>{J||(fe.currentTarget.style.backgroundColor="transparent")},children:[e.jsxs("span",{style:{position:"relative",display:"inline-flex",flexShrink:0},children:[e.jsx(T.Icon,{name:S.icon,size:"sm",style:{flexShrink:0}}),Me&&e.jsx("span",{"aria-hidden":"true",style:{position:"absolute",top:"-2px",right:"-2px",width:"0.5rem",height:"0.5rem",borderRadius:"9999px",backgroundColor:"var(--sa-color-error-500, #ff4d6d)",border:"1px solid var(--sa-background-primary, #ffffff)"}})]}),(!G||E)&&e.jsxs(e.Fragment,{children:[e.jsx(co,{text:S.title,textStyle:{transition:"opacity 0.3s"}}),de&&e.jsx(Ye.Badges,{text:String(de.value),variant:de.variant??"info",size:"xs",border:!0}),O&&e.jsx("svg",{style:{width:"1rem",height:"1rem",flexShrink:0,transition:"transform 0.2s",transform:V?"rotate(180deg)":"rotate(0deg)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]}),O&&(!G||E)&&(()=>{const fe=S.children.findIndex(oe=>we(oe.to));return e.jsxs("div",{style:{position:"relative",marginLeft:"0.9375rem",paddingLeft:"1.125rem",overflow:"hidden",transition:"all 0.3s ease-in-out",maxHeight:V?`${S.children.length*36}px`:"0px",opacity:V?1:0,marginTop:V?"0.25rem":"0px"},children:[e.jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:0,top:0,width:"1.5px",height:"100%",backgroundColor:"var(--sa-border-subtle, #0b120e24)",pointerEvents:"none"}}),fe>=0&&e.jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:0,top:`${fe*32}px`,width:"1.5px",height:"32px",backgroundColor:"var(--sa-text-primary, #292a2e)",transition:"top 0.2s ease-in-out",pointerEvents:"none",zIndex:1}}),S.children.map(oe=>{const pe=mr(oe.badge,m[oe.id]);return e.jsxs("button",{onClick:()=>H(oe.to),style:{width:"100%",display:"flex",alignItems:"center",gap:"0.5rem",paddingLeft:"0.75rem",paddingRight:"0.5rem",paddingTop:"0.25rem",paddingBottom:"0.25rem",height:"2rem",borderRadius:we(oe.to)?"var(--sa-radii-sm, 0.375rem)":"var(--sa-radii-md, 0.5rem)",textAlign:"left",backgroundColor:we(oe.to)?"var(--sa-background-primary, #ffffff)":"transparent",color:we(oe.to)?"var(--sa-text-primary, #292a2e)":"var(--sa-text-subtle, #505258)",cursor:"pointer",border:we(oe.to)?"1px solid var(--sa-border-subtle, #0b120e24)":"1px solid transparent"},onMouseEnter:Le=>{we(oe.to)||(Le.currentTarget.style.backgroundColor="var(--sa-background-neutral, #f0f1f2)")},onMouseLeave:Le=>{we(oe.to)||(Le.currentTarget.style.backgroundColor="transparent")},children:[e.jsx(T.Icon,{name:oe.icon,size:"sm",style:{flexShrink:0}}),e.jsx(co,{text:oe.title}),pe&&e.jsx(Ye.Badges,{text:String(pe.value),variant:pe.variant??"info",size:"xs",border:!0})]},oe.id)})]})})()]},S.id)};return e.jsx(eo,{children:e.jsxs(Kt,{children:[e.jsxs("div",{style:{display:"flex",height:"100vh",position:"relative","--app-sidebar-width":E?"0px":G?"4.375rem":"16.375rem","--app-footer-zindex":E&&_?"40":"998"},children:[E&&e.jsx("div",{style:{position:"fixed",inset:0,backgroundColor:"var(--sa-color-black-alpha-a50, #181a198f)",zIndex:40,opacity:_?.5:0,pointerEvents:_?"auto":"none",transition:"opacity 0.3s"},onClick:()=>K(!1)}),e.jsxs("aside",{style:{width:E?"16.375rem":G?"4.375rem":"16.375rem",position:E?"fixed":"relative",...E&&{inset:0,zIndex:50,transform:_?"translateX(0)":"translateX(-100%)"},backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",borderRight:"1px solid var(--sa-border-subtle, #0b120e24)",display:"flex",flexDirection:"column",transition:"all 0.3s ease-in-out",flexShrink:E?void 0:0},children:[e.jsx("div",{onMouseEnter:()=>q(!0),onMouseLeave:()=>q(!1),style:{height:"4rem",display:"flex",alignItems:"center",justifyContent:"space-between",paddingLeft:"1rem",paddingRight:"1rem",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",position:"relative"},children:(()=>{const S=!E&&G&&!_,O=S&&te;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",flex:S?1:void 0,justifyContent:S?"center":void 0,transition:"opacity 0.2s",opacity:O?0:1,pointerEvents:O?"none":"auto"},children:[e.jsx("img",{src:D.logo,alt:"Logo",style:{width:"2rem",height:"2rem",flexShrink:0}}),(!G||_)&&e.jsx("span",{style:{fontWeight:"600",color:"var(--sa-text-primary, #292a2e)",whiteSpace:"nowrap",transition:"opacity 0.3s"},children:D.appName})]}),!E&&!G&&e.jsx("button",{type:"button",onClick:()=>R(!0),"aria-label":"Collapse sidebar",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1rem",height:"1rem",padding:0,background:"transparent",border:"none",color:"var(--sa-text-subtle, #8c8f97)",cursor:"pointer",flexShrink:0},children:e.jsx(no,{})}),S&&e.jsx("button",{type:"button",onClick:()=>R(!1),"aria-label":"Expand sidebar",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"2rem",height:"2rem",padding:0,background:"var(--sa-background-primary, #ffffff)",border:"1px solid var(--sa-border-subtle, #0b120e24)",borderRadius:"var(--sa-radii-sm, 0.375rem)",color:"var(--sa-text-primary, #292a2e)",cursor:"pointer",opacity:O?1:0,pointerEvents:O?"auto":"none",transition:"opacity 0.2s"},children:e.jsx("span",{style:{width:"1rem",height:"1rem",display:"inline-flex"},children:e.jsx(no,{})})}),E&&e.jsx("button",{onClick:()=>K(!1),"aria-label":"Close menu",style:{padding:"0.375rem",borderRadius:"0.5rem",backgroundColor:"transparent",border:"none",color:"var(--sa-text-subtle, #8c8f97)",cursor:"pointer"},children:e.jsx("svg",{style:{width:"1.25rem",height:"1.25rem"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})})()}),i&&e.jsx($t,{collapsed:E?!1:G,children:i}),e.jsx("div",{ref:ge,style:{flex:1,overflowY:"auto",paddingTop:"1rem",paddingBottom:"1rem"},children:De.map(S=>e.jsxs("div",{style:{marginBottom:"1rem"},children:[!G||E?S.name&&e.jsx("div",{style:{paddingLeft:"1.5rem",paddingRight:"1rem",paddingTop:"0rem",paddingBottom:"0.25rem",fontSize:"0.875rem",fontWeight:"400",color:"var(--sa-text-subtlest, #6b6e76)",transition:"opacity 0.3s",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:S.name}):S.name&&e.jsx("div",{"aria-label":S.name,style:{display:"flex",alignItems:"center",justifyContent:"center",paddingTop:"0.75rem",paddingBottom:"0.75rem"},children:e.jsx("span",{style:{display:"block",width:"1rem",height:"2px",borderRadius:"1px",backgroundColor:S.color??"var(--sa-background-brand, #04254f)"}})}),e.jsx("div",{style:{paddingLeft:"1rem",paddingRight:"1rem",display:"flex",flexDirection:"column",gap:"var(--sa-spacing-xs, 0.25rem)"},children:S.slotKey?e.jsx(ro,{slotKey:S.slotKey,fallback:S.items.map(O=>Ne(O))}):S.items.map(O=>Ne(O))})]},S.id))}),D.menuBottom&&D.menuBottom.length>0&&e.jsx("div",{style:{borderTop:"1px solid var(--sa-border-subtle, #0b120e24)",paddingTop:"0.75rem",paddingBottom:"0.75rem",paddingLeft:"1rem",paddingRight:"1rem",backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",display:"flex",flexDirection:"column",gap:"var(--sa-spacing-xs, 0.25rem)",flexShrink:0},children:D.menuBottom.map(S=>Ne(S))})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsxs("header",{style:{height:"4rem",backgroundColor:"var(--sa-background-primary, #ffffff)",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",display:"flex",alignItems:"center",justifyContent:"space-between",paddingLeft:"1rem",paddingRight:"1rem",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:E?"1rem":void 0},children:[E&&e.jsx("button",{onClick:()=>K(!0),style:{padding:"0.375rem",borderRadius:"0.5rem",backgroundColor:"transparent",border:"none",color:"var(--sa-text-subtle, #8c8f97)",cursor:"pointer"},children:e.jsx("svg",{style:{width:"1.5rem",height:"1.5rem"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),e.jsx(Rt,{children:t})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[a,e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[e.jsxs("div",{style:{textAlign:"right",maxWidth:"12.5rem"},children:[e.jsx("p",{style:{margin:0,fontSize:"0.875rem",fontWeight:500,color:"var(--sa-text-subtle, #8c8f97)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n?"Loading...":(o==null?void 0:o.name)||"unknown"}),e.jsx("p",{style:{margin:0,fontSize:"0.75rem",color:"var(--sa-text-subtle, #8c8f97)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n?"":(o==null?void 0:o.email)||"unknown"})]}),e.jsx("div",{style:{width:"2.5rem",height:"2.5rem",borderRadius:"9999px",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--sa-background-primary, #ffffff)",fontWeight:600,fontSize:"0.875rem",boxShadow:"var(--sa-shadow-sm, 0 1px 2px 0 #0000000d)",flexShrink:0,backgroundColor:"var(--sa-background-brand, #04254f)"},children:((o==null?void 0:o.name)||"U")[0].toUpperCase()}),e.jsx(T.Icon,{name:"ChevronDown",size:"sm",style:{color:"var(--sa-text-subtle, #8c8f97)"}})]})}),e.jsxs(W.MenuLists,{style:{width:"280px",paddingBlock:"12px",paddingInline:"12px",gap:"8px",marginTop:"16px"},children:[e.jsx(W.MenuHeading,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",paddingBlock:"0.5rem"},children:[e.jsx("div",{style:{width:"4rem",height:"4rem",borderRadius:"9999px",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--sa-background-primary, #ffffff)",fontWeight:600,fontSize:"1.25rem",boxShadow:"var(--sa-shadow-sm, 0 1px 2px 0 #0000000d)",marginBottom:"0.75rem",backgroundColor:"var(--sa-background-brand, #04254f)"},children:((o==null?void 0:o.name)||"U")[0].toUpperCase()}),e.jsx("p",{style:{margin:0,fontSize:"0.875rem",fontWeight:600,color:"var(--sa-text-primary, #292a2e)",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(o==null?void 0:o.name)||"unknown"}),e.jsx("p",{style:{margin:0,fontSize:"0.75rem",color:"var(--sa-text-subtle, #8c8f97)",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(o==null?void 0:o.email)||"unknown"}),d&&e.jsx("p",{style:{margin:0,fontSize:"0.75rem",color:"var(--sa-text-subtle, #8c8f97)",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d})]})}),(y&&y.length>0||b)&&e.jsxs(W.MenuBody,{children:[y==null?void 0:y.map((S,O)=>e.jsx(W.MenuButton,{children:e.jsxs("button",{type:"button",onClick:S.onClick,style:so,onMouseEnter:V=>{V.currentTarget.style.backgroundColor="var(--sa-background-neutral, #f0f1f2)"},onMouseLeave:V=>{V.currentTarget.style.backgroundColor="transparent"},children:[e.jsx(T.Icon,{name:S.icon,size:"md"}),e.jsx("span",{children:S.label})]})},`${S.label}-${O}`)),b]}),p??e.jsx(W.MenuFooter,{children:e.jsx(W.MenuButton,{children:e.jsxs("button",{type:"button",onClick:Oe,style:{...so,color:"var(--sa-background-error, #c9184a)",fontWeight:500},onMouseEnter:S=>{S.currentTarget.style.backgroundColor="var(--sa-color-error-50, #fff0f3)"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="transparent"},children:[e.jsx(T.Icon,{name:"Logout",size:"md",style:{color:"var(--sa-background-error, #c9184a)"}}),e.jsx("span",{children:"Logout"})]})})})]})]})]})]}),e.jsx("main",{ref:xe,style:{flex:1,overflowY:"auto"},children:r||e.jsx(L,{})})]})]}),c&&s&&e.jsx("div",{style:{position:"fixed",inset:0,background:"var(--sa-color-black-alpha-a70, #181a19b8)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},children:s}),e.jsxs(Ae.Dialog,{isShow:U,onHide:Ve,children:[e.jsx(Ae.DialogTitle,{children:"Confirmation Logout"}),e.jsx(Ae.DialogBody,{children:"Are you sure you want to end the session and exit the page?"}),e.jsx(Ae.DialogFooter,{children:e.jsx(u.Box,{direction:"column",display:"flex",align:"flex-end",justify:"center",children:e.jsxs(ne.Flex,{direction:"row",gap:"sm",align:"center",children:[e.jsx(u.Box,{direction:"column",children:e.jsx(N.Button,{secondary:!0,onClick:Ve,children:"Cancel"})}),e.jsx(u.Box,{direction:"column",children:e.jsx(N.Button,{primary:!0,onClick:Pe,children:"Yes, Sure"})})]})})})]}),le&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>Ce(null),style:{position:"fixed",inset:0,zIndex:60,backgroundColor:"transparent"}}),e.jsxs("div",{role:"dialog","aria-label":le.item.title,style:{position:"fixed",top:le.top,left:le.left,zIndex:61,minWidth:"13rem",maxWidth:"16rem",backgroundColor:"var(--sa-background-primary, #ffffff)",border:"1px solid var(--sa-border-subtle, #0b120e24)",borderRadius:"var(--sa-radii-md, 0.5rem)",boxShadow:"var(--sa-shadow-lg, 0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a)",padding:"0.5rem",display:"flex",flexDirection:"column",gap:"0.125rem"},children:[e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--sa-color-gray-500, #8c8f97)",padding:"0.25rem 0.5rem 0.5rem",textTransform:"uppercase",letterSpacing:"0.05em"},children:le.item.title}),(P=le.item.children)==null?void 0:P.map(S=>{const O=we(S.to),V=mr(S.badge,m[S.id]);return e.jsxs("button",{onClick:()=>{H(S.to),Ce(null)},style:{width:"100%",display:"flex",alignItems:"center",gap:"0.75rem",padding:"0.5rem 0.75rem",borderRadius:"var(--sa-radii-md, 0.5rem)",textAlign:"left",backgroundColor:O?"var(--sa-color-gray-100, #f8f8f8)":"transparent",color:O?"var(--sa-text-primary, #292a2e)":"var(--sa-color-gray-800, #505258)",border:"1px solid transparent",cursor:"pointer",fontSize:"0.875rem",fontWeight:500},onMouseEnter:J=>{O||(J.currentTarget.style.backgroundColor="var(--sa-color-gray-100, #f8f8f8)")},onMouseLeave:J=>{O||(J.currentTarget.style.backgroundColor="transparent")},children:[S.icon&&e.jsx(T.Icon,{name:S.icon,size:"sm",style:{flexShrink:0}}),e.jsx("span",{style:{flex:1,whiteSpace:"nowrap"},children:S.title}),V&&e.jsx(Ye.Badges,{text:String(V.value),variant:V.variant??"info",size:"xs",border:!0})]},S.id)})]})]})]})})}const yr=h.forwardRef(({children:r,...t},o)=>e.jsx(u.Box,{ref:o,role:"button",cursor:"pointer","aria-pressed":"true",display:"inline-block",tabIndex:0,...t,children:r})),io=({title:r,iconName:t,textColor:o,iconColor:n,hoverTextColor:l,hoverIconColor:c})=>{const[s,i]=h.useState(!1),a=n??"var(--sa-text-subtle, #8c8f97)",d=o??"var(--sa-text-subtle, #8c8f97)",y=c??"var(--sa-text-subtle, #8c8f97)",b=l??"var(--sa-text-primary, #292a2e)";return e.jsxs(u.Box,{direction:"row",gap:"xs",align:"center",onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{cursor:"pointer"},children:[e.jsx(T.Icon,{name:t||"ChevronLeft",size:"xs",style:{color:s?y:a,transition:"color 0.15s ease"}}),e.jsx(k.Text,{variant:"sub-h3",style:{color:s?b:d,transition:"color 0.15s ease"},children:r||"Back"})]})},Bl=({items:r,separator:t="/",iconName:o,iconColor:n,hoverIconColor:l})=>{const{Link:c}=Ge(),[s,i]=h.useState(!1),a=n??"var(--sa-text-subtle, #8c8f97)",d=l??"var(--sa-text-subtle, #8c8f97)",y=r.length>1?r[0]:void 0,b=!!(y!=null&&y.to||y!=null&&y.onClick),p=e.jsx(T.Icon,{name:o||"ChevronLeft",size:"xs",onMouseEnter:b?()=>i(!0):void 0,onMouseLeave:b?()=>i(!1):void 0,style:{color:b&&s?d:a,transition:"color 0.15s ease",cursor:b?"pointer":void 0}}),v=y!=null&&y.to?e.jsx(c,{to:y.to,replace:!0,style:{textDecoration:"none"},children:p}):y!=null&&y.onClick?e.jsx(yr,{onClick:y.onClick,children:p}):p;return e.jsxs(u.Box,{direction:"row",gap:"xs",align:"center",children:[v,e.jsx(or.Breadcrumb,{separator:t,size:"md",children:r.map((B,x)=>{const L=x===r.length-1;return B.to&&!L?e.jsx(or.BreadcrumbItem,{children:e.jsx(c,{to:B.to,children:B.label})},x):e.jsx(or.BreadcrumbItem,{currentPage:L,children:e.jsx(or.BreadcrumbLink,{onClick:L?void 0:B.onClick,children:B.label})},x)})})]})},ml=r=>{const{Link:t}=Ge(),{items:o,separator:n,onClick:l,navigateTo:c,...s}=r;return o&&o.length>0?e.jsx(Bl,{items:o,separator:n,iconName:s.iconName,iconColor:s.iconColor,hoverIconColor:s.hoverIconColor}):c?e.jsx(u.Box,{direction:"row",children:e.jsx(t,{to:c,replace:!0,style:{textDecoration:"none"},children:e.jsx(io,{...s})})}):e.jsx(u.Box,{direction:"row",children:e.jsx(yr,{onClick:l,children:e.jsx(io,{...s})})})},tt=[{icon:"var(--sa-color-brand-400, #3366b7)",activeBg:"var(--sa-color-brand-50, #e6edf6)",activeBorder:"var(--sa-color-brand-300, #668cc9)",activeShadow:"rgba(51, 102, 183, 0.25)"},{icon:"var(--sa-color-warning-400, #ed9f30)",activeBg:"var(--sa-color-warning-50, #fef2e6)",activeBorder:"var(--sa-color-warning-300, #f1b259)",activeShadow:"rgba(237, 159, 48, 0.25)"},{icon:"var(--sa-color-secondary-300, #5468e1)",activeBg:"var(--sa-color-secondary-50, #e6e9fb)",activeBorder:"var(--sa-color-secondary-200, #8a98ea)",activeShadow:"rgba(84, 104, 225, 0.25)"},{icon:"var(--sa-color-info-500, #00abeb)",activeBg:"var(--sa-color-info-50, #effaff)",activeBorder:"var(--sa-color-info-300, #75dbff)",activeShadow:"rgba(0, 171, 235, 0.25)"},{icon:"var(--sa-color-success-500, #30ce84)",activeBg:"var(--sa-color-success-50, #ecfff6)",activeBorder:"var(--sa-color-success-300, #75dead)",activeShadow:"rgba(48, 206, 132, 0.25)"},{icon:"var(--sa-color-error-400, #ff758f)",activeBg:"var(--sa-color-error-50, #fff0f3)",activeBorder:"var(--sa-color-error-300, #ff8fa3)",activeShadow:"rgba(255, 117, 143, 0.25)"}];function ao(r,t,o){return{display:"flex",alignItems:"center",justifyContent:"center",width:"64px",height:"64px",borderRadius:"var(--sa-radii-sm, 6px)",border:r?`2px solid ${o.activeBorder}`:"2px solid var(--sa-color-gray-200, #f0f1f2)",backgroundColor:r?o.activeBg:"var(--sa-color-gray-50, #ffffff)",boxShadow:r?t?`0 8px 20px ${o.activeShadow.replace("0.25","0.35")}`:`0 2px 8px ${o.activeShadow}`:t?"0 8px 20px rgba(0, 0, 0, 0.14)":"0 1px 4px rgba(0, 0, 0, 0.08)",transform:t?"translateY(-3px) scale(1.05)":"translateY(0) scale(1)",transition:"box-shadow 0.2s ease, transform 0.2s ease, background-color 0.15s ease, border-color 0.15s ease"}}const ho={fontSize:"11px",fontWeight:500,textAlign:"center",overflowWrap:"normal",wordBreak:"normal",color:"var(--sa-background-primary, #ffffff)",lineHeight:"1.3",maxWidth:"80px"},fo={display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",background:"none",border:"none",cursor:"pointer",padding:0};function go({isShow:r,onHide:t,menus:o,selectedGroupId:n,onSelect:l}){const[c,s]=h.useState(void 0),i=d=>{l(d),t()},a=tt[0];return e.jsx(Ae.Dialog,{isShow:r,onHide:t,style:{width:560,background:"transparent",boxShadow:"none",border:"none"},children:e.jsx(Ae.DialogBody,{children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"16px"},children:[e.jsxs("button",{onClick:()=>i(null),onMouseEnter:()=>s("all"),onMouseLeave:()=>s(void 0),style:fo,children:[e.jsx("div",{style:ao(n===null,c==="all",a),children:e.jsx("div",{style:{color:a.icon,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(T.Icon,{name:"Grid",size:"lg",style:{width:32,height:32}})})}),e.jsx("span",{style:ho,children:"Semua"})]}),o.map((d,y)=>{var x;const b=n===d.id,p=c===d.id,v=((x=d.items[0])==null?void 0:x.icon)??"Grid",B=tt[(y+1)%tt.length];return e.jsxs("button",{onClick:()=>i(d.id),onMouseEnter:()=>s(d.id),onMouseLeave:()=>s(void 0),style:fo,children:[e.jsx("div",{style:ao(b,p,B),children:e.jsx("div",{style:{color:B.icon,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(T.Icon,{name:v,size:"lg",style:{width:32,height:32}})})}),e.jsx("span",{style:ho,children:d.name})]},d.id)})]})})})}function Fl({onSelect:r,"aria-label":t="Pilih module"}={}){const o=$r(),{useNavigate:n}=Ge(),l=n(),{selectedGroupId:c,setSelectedGroupId:s}=rt(),[i,a]=h.useState(!1),d=y=>{var b;if(s(y),y!==null){const p=o.menus.find(B=>B.id===y),v=(b=p==null?void 0:p.items[0])==null?void 0:b.to;v&&l(v)}r==null||r(y)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx("button",{onClick:()=>a(!0),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"2.25rem",height:"2.25rem",borderRadius:"var(--sa-radii-sm, 0.25rem)",border:"1px solid var(--sa-border-subtle, #0b120e24)",color:"var(--sa-text-subtle, #8c8f97)",backgroundColor:"transparent",cursor:"pointer"},"aria-label":t,onMouseEnter:y=>{y.currentTarget.style.backgroundColor="var(--sa-background-primary-inverse, #f8f8f8)"},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent"},children:e.jsx(T.Icon,{name:"GridApplication",size:"sm"})}),c!==null&&e.jsx("span",{style:{position:"absolute",top:"0.25rem",right:"0.25rem",width:"0.5rem",height:"0.5rem",borderRadius:"9999px",backgroundColor:"var(--sa-color-brand-500, #1a4fa0)"},"aria-hidden":"true"})]}),e.jsx(go,{isShow:i,onHide:()=>a(!1),menus:o.menus.filter(y=>y.parentGroupId===void 0),selectedGroupId:c,onSelect:d})]})}const El=(r,t)=>{const o=[];if(t===0)return o.push(r),o;for(let n=0;n<r.length;n+=t){const l=r.slice(n,n+t);o.push(l)}return o},Ml=h.memo(({value:r,label:t,separator:o,labelWidth:n,lastIndex:l,labelAlign:c="top"})=>{const s=h.useMemo(()=>({padding:0,paddingBottom:l?0:12,verticalAlign:c}),[l,c]),i=h.useMemo(()=>({padding:0,paddingRight:12,paddingLeft:12,paddingBottom:l?0:12,verticalAlign:c}),[l,c]),a=()=>typeof t=="string"?e.jsx(k.Text,{fontWeight:"medium",color:"subtlest",children:t}):t,d=()=>typeof r=="string"||typeof r=="number"?e.jsx(k.Text,{color:"primary",fontWeight:"medium",children:r}):r,y=()=>typeof o=="string"||typeof o=="number"?e.jsx(k.Text,{fontWeight:"medium",color:"subtlest",children:o}):o;return e.jsxs(Q.Tr,{children:[e.jsx(Q.Td,{style:s,width:n,children:a()}),o?e.jsx(Q.Td,{style:i,width:24,children:y()}):null,e.jsx(Q.Td,{style:s,children:d()})]})}),Ll=h.memo(({fields:r,separator:t,labelWidth:o})=>e.jsx(Q.Table,{withColumnBorder:!1,withRowBorder:!1,children:r.map((n,l)=>e.jsx(Ml,{separator:t,labelWidth:o,lastIndex:l===r.length-1,...n},`field-group-field-${l}`))})),Tl=h.memo(({maxRow:r=0,maxColumn:t=2,separator:o=":",fields:n=[],labelWidth:l=150,bordered:c=!1})=>{const s=h.useMemo(()=>El(n,r),[n,r]),i=s.length>2,a=()=>{switch(t){case 1:return"width-full";case 2:return"width-1-2";case 3:return"width-1-3";case 4:return"width-1-4";default:return"width-1-2"}};return e.jsx(u.Box,{gap:i?void 0:"lg",direction:"row",flexWrap:"wrap",borderRadius:"rounded-sm",padding:"lg",paddingBottom:i?"xs":"lg",bg:"accent-dark-tertiary",borderWidth:c?"border":void 0,borderStyle:c?"border-solid":void 0,borderColor:c?"border-subtle":void 0,children:s.map((d,y)=>e.jsx(u.Box,{direction:"column",flex:i?void 0:"1",width:i?a():void 0,marginBottom:i?"lg":void 0,children:e.jsx(Ll,{labelWidth:l,fields:d,separator:o})},y))})}),Il=({backButton:r})=>{const[t,o]=h.useState(!1),n=(r==null?void 0:r.iconColor)??"var(--sa-text-subtle, #8c8f97)",l=(r==null?void 0:r.textColor)??"var(--sa-text-subtle, #8c8f97)",c=(r==null?void 0:r.hoverIconColor)??"var(--sa-text-subtle, #8c8f97)",s=(r==null?void 0:r.hoverTextColor)??"var(--sa-text-primary, #292a2e)";return e.jsxs(u.Box,{direction:"row",gap:"xs",align:"center",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{cursor:"pointer"},children:[e.jsx(T.Icon,{name:(r==null?void 0:r.iconName)||"ChevronLeft",size:"xs",style:{color:t?c:n,transition:"color 0.15s ease"}}),e.jsx(k.Text,{variant:"sub-h3",style:{color:t?s:l,textDecoration:t?"underline":"none",transition:"color 0.15s ease"},children:(r==null?void 0:r.title)||"Back"})]})},Ol=({backButton:r,title:t,titleIcon:o,titleTag:n,children:l,header:c=!0,headerBorder:s=!1,disableAnimation:i=!1,scrollable:a=!1,stickyHeader:d=!1,subHeaders:y,action:b,titleTagProps:p,containerProps:v,headerProps:B})=>{const x=be.useMediaQuery("md"),{Link:L,useNavigate:F,useLocation:A}=Ge(),D=F(),m=A(),H=r==null?void 0:r.show,z=()=>{if(typeof(r==null?void 0:r.onClick)=="function"){r.onClick();return}D(-1,{replace:!0})},I=()=>{if(!b)return null;if(h.isValidElement(b))return b;const _=b.filter(K=>K&&(K.title||K.icon));return _.length===0?null:x?e.jsx(u.Box,{direction:"row",gap:"md",children:_.map(({title:K,icon:te,buttonProps:q,onClick:j},Z)=>e.jsx(N.Button,{iconLeft:te?e.jsx(T.Icon,{name:te,size:"md"}):void 0,onClick:j,...q,children:K},`action-${Z}`))}):e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"tertiary",size:"sm",iconLeft:e.jsx(T.Icon,{name:"MenuBurger"}),"aria-label":"Actions"})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{minWidth:200},children:_.map(({title:K,icon:te,buttonProps:q,onClick:j},Z)=>{const le=(q==null?void 0:q.tone)==="error"||(q==null?void 0:q.danger)===!0;return e.jsx(W.MenuItem,{intent:le?"danger":void 0,disabled:q==null?void 0:q.disabled,startIcon:te?e.jsx(T.Icon,{name:te}):void 0,onClick:j,children:K},`action-${Z}`)})})})]})},E=()=>{const _=e.jsx(Il,{backButton:r});return r!=null&&r.navigateTo?e.jsx(u.Box,{direction:"row",children:e.jsx(L,{to:r.navigateTo,replace:!0,style:{textDecoration:"none"},children:_})}):e.jsx(u.Box,{direction:"row",children:e.jsx(yr,{onClick:z,children:_})})},U=()=>{const _=!!t,K=Array.isArray(b)&&b.length>0,te=h.isValidElement(b)?!0:K;if(!_&&!te&&!H)return null;const j=x||!x&&K;return e.jsxs(u.Box,{direction:"column",gap:"xs",paddingBlock:(B==null?void 0:B.paddingBlock)??"sm",paddingInline:(B==null?void 0:B.paddingInline)??"md",...B,style:{...s?{boxShadow:"inset 0 -1px 0 0 var(--sa-border-subtle, #0b120e24)"}:{},...B==null?void 0:B.style},children:[H&&E(),(_||te)&&e.jsxs(u.Box,{direction:j?"row":"column",gap:"sm",justify:"space-between",align:j?"center":"flex-start",children:[_?typeof t=="string"?e.jsxs(u.Box,{direction:"row",gap:"lg",align:"center",children:[e.jsxs(u.Box,{direction:"row",gap:"sm",align:"center",children:[o&&e.jsx(T.Icon,{name:o,size:"md",color:"primary"}),e.jsx(k.Text,{variant:"h3",fontWeight:"semibold",fontFamily:"Poppins",children:t})]}),n&&e.jsx(Ye.Badge,{border:!0,size:"lg",text:n,...p})]}):t:null,I()]})]})},X=()=>{if(!y||y.length===0)return null;const _=y.filter(q=>q.show!==!1);if(_.length===0)return null;let K=0,te=-1/0;return _.forEach((q,j)=>{const Z=q.order??0;Z>=te&&(te=Z,K=j)}),_.map(({content:q,order:j,borderBottom:Z=!0,keepBottomPadding:le=!1,paddingInline:Ce=!0,paddingBlock:ve=!0},he)=>e.jsx(u.Box,{direction:"column",paddingTop:ve?"sm":"spacing-0",paddingBottom:ve&&(Z||le||he===K)?"sm":"spacing-0",paddingInline:Ce?"md":"spacing-0",style:{...Z?{boxShadow:"inset 0 -1px 0 0 var(--sa-border-subtle, #0b120e24)"}:{},...j!==void 0?{order:j}:{}},children:q},`sub-header-${he}`))},G=()=>{const _=c?U():null,K=X();return!_&&!K?null:e.jsxs(u.Box,{direction:"column",style:{...a?{position:"sticky",left:0,...d?{top:0}:{},zIndex:2,background:"var(--sa-background-primary, #ffffff)"}:{},marginBottom:K?"var(--sa-spacing-0)":"var(--sa-spacing-md)"},children:[_,K]})},R=()=>l;return e.jsxs(u.Box,{direction:"column",as:"main",...v,style:{...a?{height:"100%",minHeight:0,overflow:"auto"}:{},...(v==null?void 0:v.style)??{},...i?{}:{animation:"pageLayoutEnter 320ms cubic-bezier(0.16, 1, 0.3, 1) backwards"}},children:[G(),R()]},m.pathname)},Wl=h.memo(Ol),Al={icon:"Cross",title:""},uo=h.forwardRef(({onHide:r,show:t,withBlur:o=!1,style:n,children:l,closeButton:c=Al,width:s,minWidth:i,maxWidth:a},d)=>{const y=s??a??i??"357px";return e.jsx(kr.Drawer,{blur:o,isShow:t,position:"right",onHide:r,ref:d,size:y,style:n,children:e.jsxs(u.Box,{direction:"column",padding:"lg",children:[c?e.jsxs(u.Box,{direction:"row",align:"center",gap:"sm",onClick:r,marginBottom:"lg",cursor:"pointer",children:[e.jsx(T.Icon,{name:c.icon,size:"md",color:"subtle",cursor:"pointer"}),c.title?e.jsx(k.Text,{fontFamily:"Poppins",fontSize:"md",color:"subtlest",children:c.title}):null]}):null,l]})})}),ot=h.memo(({children:r,borderBottom:t=!0,padding:o=!0})=>{const n=be.useMediaQuery("lg");return e.jsx(u.Box,{direction:"column",padding:o?"md":"spacing-0",paddingLeft:o?"md":"spacing-0",paddingRight:o?"md":"spacing-0",style:t?{borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)"}:void 0,children:r})}),lt=h.memo(({children:r,borderTop:t=!0,padding:o=!0})=>{const n=be.useMediaQuery("lg");return e.jsx(u.Box,{direction:"column",padding:o?"md":"spacing-0",paddingLeft:o?"md":"spacing-0",paddingRight:o?"md":"spacing-0",style:t?{borderTop:"1px solid var(--sa-border-subtle, #0b120e24)"}:void 0,children:r})}),zl=h.memo(({children:r,...t})=>e.jsx(u.Box,{direction:"column",padding:"md",paddingLeft:"md",paddingRight:"md",gap:"md",...t,children:r})),Hl=h.memo(({children:r,title:t,titleTag:o,action:n,header:l,footer:c,actionContainer:s,containerProps:i,bodyProps:a,headerProps:d={borderBottom:!0},footerProps:y={borderTop:!0},variantTag:b="info"})=>{const p=be.useMediaQuery("lg"),v=()=>o?e.jsxs(u.Box,{direction:"row",gap:"sm",align:"center",children:[e.jsx(k.Text,{fontWeight:"medium",children:t}),e.jsx(Ye.Badges,{border:!0,text:o,variant:b})]}):e.jsx(k.Text,{fontWeight:"medium",children:t}),B=()=>l||e.jsxs(u.Box,{direction:"row",justify:"space-between",align:"flex-start",gap:"md",children:[e.jsx(u.Box,{direction:"column",children:t?v():null}),e.jsx(u.Box,{direction:"column",style:p?{width:"100%",maxWidth:"19.313rem"}:{flex:1},...s,children:n??null})]}),x=!!(l||t||n);return e.jsxs(u.Box,{direction:"column",bg:"white",borderRadius:"rounded-xs",as:"section",borderWidth:"border",borderStyle:"border-solid",borderColor:"border-base",...i,style:{backgroundColor:"var(--sa-background-primary, #ffffff)",...(i==null?void 0:i.style)??{}},children:[l!==null&&x?e.jsx(ot,{...d,children:B()}):null,e.jsx(zl,{...a,children:r}),c?e.jsx(lt,{...y,children:c}):null]})}),He={H1:r=>e.jsx(k.Text,{variant:"h1",children:r.children,...r.props}),H2:r=>e.jsx(k.Text,{variant:"h2",children:r.children,...r.props}),H3:r=>e.jsx(k.Text,{variant:"h3",children:r.children,...r.props}),H4:r=>e.jsx(k.Text,{variant:"h4",children:r.children,...r.props}),H5:r=>e.jsx(k.Text,{variant:"h5",children:r.children,...r.props}),H6:r=>e.jsx(k.Text,{variant:"h6",children:r.children,...r.props}),SubH1:r=>e.jsx(k.Text,{variant:"sub-h1",children:r.children,...r.props}),SubH2:r=>e.jsx(k.Text,{variant:"sub-h2",children:r.children,...r.props}),SubH3:r=>e.jsx(k.Text,{variant:"sub-h3",children:r.children,...r.props}),Body1:r=>e.jsx(k.Text,{variant:"body-1",children:r.children,...r.props}),Body2:r=>e.jsx(k.Text,{variant:"body-2",children:r.children,...r.props}),Body3:r=>e.jsx(k.Text,{variant:"body-3",children:r.children,...r.props})},Te=()=>{const{useSearchParams:r,useParams:t,useLocation:o}=Ge(),[n,l]=r(),c=nr.searchParamsToObject(n.toString()),s=t(),i=o(),a=s.id;return{setSearchParams:l,searchParams:n,searchQueries:c,isHasQuery:(v,B)=>n.has(v)&&n.get(v)===B,getQueryParam:v=>n.get(v),getRouteParam:v=>s[v],params:s,location:i,id:a,hasId:!!a}},yo=r=>JSON.stringify(r),po=r=>JSON.stringify(r),bo=r=>JSON.stringify(r),Co=r=>JSON.stringify(r),Vl=r=>r,Pl=r=>JSON.stringify(r),pr=({value:r,name:t,type:o,withSearchParam:n=!0,setSearchParams:l,searchQueries:c,dropdownSearchKey:s,filterKey:i="filter",pageKey:a="page"})=>{if(n){let d;switch(o){case"search":d=Vl(r);break;case"dropdown":case"dropdown-multiple":d=yo(r);break;case"radio":d=po(r);break;case"date-range":d=bo(r);break;case"advanced-date-range":d=Pl(r);break;case"date":d=Co(r);break;default:d=r;break}if(typeof d<"u"){const b={...c[i]&&typeof c[i]=="string"?JSON.parse(c[i]):void 0,[t]:d},p={...c};s&&typeof s=="string"&&delete p[s],delete p[a];const v={...p,[i]:JSON.stringify(b)},B=new URLSearchParams(c).toString(),x=new URLSearchParams(v).toString();if(B===x)return;l(v)}}},Mr=({name:r,filterKey:t="filter",searchParams:o,get:n})=>{const l=o.get(t)||void 0,c=l&&typeof l=="string"?JSON.parse(l):void 0,s=c?c[r]:void 0;return n==="label"&&s?JSON.parse(s)[0].label:n==="value"&&s?JSON.parse(s)[0].value:s},vo=({name:r,filterKey:t="filter",searchParams:o,get:n})=>{const l=o.get(t)||void 0,c=l&&typeof l=="string"?JSON.parse(l):void 0,s=c?c[r]:void 0;return n==="label"&&s?JSON.parse(s).map(i=>i.label):n==="value"&&s?JSON.parse(s).map(i=>i.value):n==="array"&&s?JSON.parse(s):s},jl=({name:r,filterKey:t="filter",searchParams:o,get:n})=>{const l=o.get(t)||void 0,c=l&&typeof l=="string"?JSON.parse(l):void 0,s=c?c[r]:void 0;return n==="id"&&s?JSON.parse(s).id:n==="label"&&s?JSON.parse(s).label:n==="value"&&s?JSON.parse(s).value:s},Lr=(r,t,o)=>{const n=t.get(o||"filter")||void 0,l=n&&typeof n=="string"?JSON.parse(n):void 0;return l?l[r]:void 0},Nl=({name:r,filterKey:t="filter",searchParams:o})=>{const n=o.get(t||"filter")||void 0,l=n&&typeof n=="string"?JSON.parse(n):void 0,c=l?l[r]:void 0;return{start:c?JSON.parse(c).from:void 0,end:c?JSON.parse(c).to:void 0}},xo=({name:r,filterKey:t="filter",searchParams:o})=>{const n=o.get(t||"filter")||void 0,l=n&&typeof n=="string"?JSON.parse(n):void 0,c=l?l[r]:void 0;return c?JSON.parse(c):void 0},_l=(r,{filterKey:t="filter",perPageKey:o="perPage",pageKey:n="page"})=>{const l=r.get(t)||void 0,c=r.get(o)||void 0,s=r.get(n)||void 0;return!!l||!!c||!!s},wo=({isOpen:r,onClose:t,filterKey:o,pageKey:n,filters:l})=>{const{searchParams:c,setSearchParams:s,searchQueries:i}=Te(),[a,d]=h.useState({}),y=()=>{c.delete(o||"filter"),s(c)},b=(p,v)=>{switch(p.type){case"radio":{const{show:B=!0}=p;return B&&e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v)}case"dropdown":{const{show:B=!0}=p;return B&&e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v)}case"date-range":return e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v);case"date":return e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v);case"dropdown-multiple":{const{show:B=!0}=p;return B&&e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v)}default:return null}};return e.jsx(uo,{onHide:t,show:r||!1,children:e.jsxs(u.Box,{direction:"column",gap:"md",children:[e.jsxs(ne.Flex,{direction:"row",justify:"space-between",align:"center",children:[e.jsx(u.Box,{direction:"column",children:"Filter"}),e.jsx(u.Box,{direction:"column",style:{cursor:"pointer"},onClick:y,children:"Reset"})]}),l==null?void 0:l.map((p,v)=>b(p,v))]})})},Do=({searchKey:r="q",statusKey:t="status",searchPlaceholder:o="Search",searchHighlightPlaceholder:n,extendedFilter:l,showSearchFilter:c=!0,showStatusFilter:s=!0,filterKey:i="filter",pageKey:a="page",customWidthSearch:d,handleOnReset:y,filterConfigs:b,buttonToggleProps:p,position:v="right",titleSearchLabel:B="Work Order",withTitleLabels:x=!1})=>{const F=(p==null?void 0:p.isShowLabel)??!0,[A,D]=h.useState(!1),[m,H]=h.useState(0),z=()=>{H(Z=>Z+1)},{searchParams:I,setSearchParams:E,getQueryParam:U}=Te(),X=nr.searchParamsToObject(I.toString()),G=Lr(r,I,i)||"",[R,_]=h.useState(G),K=U(i),q=!!(K&&!(()=>{if(K)try{const Z=JSON.parse(K);return Object.keys(Z).length===1&&Z[r]===""}catch(Z){console.error("Filter parameter is not a valid JSON:",Z)}return!1})()),j=be.useMediaQuery("md");return h.useEffect(()=>{_(G)},[G]),h.useEffect(()=>{if(R===G)return;const Z=window.setTimeout(()=>{pr({value:R,name:r,type:"search",searchQueries:X,setSearchParams:E,filterKey:i,pageKey:a})},350);return()=>{window.clearTimeout(Z)}},[R,G,r,X,E,i,a]),e.jsxs(ne.Flex,{gap:"md",style:{flexDirection:j&&v==="left"?"row":j&&v==="right"?"row-reverse":"column"},align:"flex-end",children:[q&&e.jsx(u.Box,{direction:"column",justify:"flex-end",children:e.jsx(N.Button,{onClick:()=>{const Z=new URLSearchParams(I);Z.delete(i),E(Z),_(""),z(),y&&y()},variant:"outline",tone:"neutral",children:e.jsx(k.Text,{color:"error",fontWeight:"semibold",children:"Reset"})})}),l==null?void 0:l.map(({minWidth:Z,content:le,title:Ce,onClickContainer:ve},he)=>e.jsxs(u.Box,{direction:"column",gap:"sm",onClick:ve,style:{minWidth:Z},children:[Ce&&e.jsx(He.SubH3,{children:Ce}),le]},`extended-filter-${he}-${m}`)),!!(b!=null&&b.length)&&e.jsx(N.Button,{primary:q,secondary:!q,iconLeft:e.jsx(T.Icon,{size:"sm",name:(p==null?void 0:p.icon)||"FilterHorizontal",style:{color:K?"var(--sa-background-brand, #04254f)":"var(--sa-text-primary, #292a2e)"}}),fullWidth:!j,onClick:()=>D(!0),children:F?"Filter":void 0}),s&&e.jsxs(u.Box,{direction:"column",gap:"sm",style:{minWidth:"126px"},children:[x&&e.jsx(He.SubH3,{children:"Status"}),e.jsx(lr.Dropdown,{dropdownLists:[{label:"Active",value:"active"},{label:"InActive",value:"inactive"}],defaultValue:Mr({get:"value",name:t,searchParams:I,filterKey:i})?[{label:Mr({get:"value",name:t,searchParams:I,filterKey:i})==="active"?"Active":"InActive",value:Mr({get:"value",name:t,searchParams:I,filterKey:i})}]:[],onChange:Z=>pr({value:Z,name:t,type:"dropdown",searchQueries:X,setSearchParams:E,filterKey:i}),placeholder:x?"All":"All Status"},m)]}),c&&e.jsxs(u.Box,{direction:"column",gap:"sm",style:{width:d&&j?d:j?"310px":""},children:[x&&e.jsxs(He.SubH3,{children:["Search for ",B]}),e.jsx(Xe.Input,{placeholder:o,leftIcon:e.jsx(T.Icon,{name:"Search",width:20,height:20}),onChange:Z=>_(Z.target.value),value:R,fullWidth:!0},m+1+i)]}),e.jsx(wo,{isOpen:A,onClose:()=>D(!1),filterKey:i,filters:b,pageKey:a})]})},ql=r=>r==="checkbox-multiple"?"dropdown-multiple":r==="radio"?"dropdown":r==="date-compact"?"date":r;function nt({configs:r,filterKey:t="filter",activeFilterKey:o="filters",pageKey:n="page",searchKey:l="q"}){const{searchParams:c,setSearchParams:s,searchQueries:i}=Te(),a=h.useMemo(()=>Object.fromEntries(r.map(m=>[m.key,m])),[r]),d=h.useMemo(()=>{const m=(c.get(o)||"").split(",").map(z=>z.trim()).filter(Boolean);let H=[];try{const z=c.get(t);z&&(H=Object.keys(JSON.parse(z)).filter(I=>I!==l))}catch{}return r.map(z=>z.key).filter(z=>{const I=a[z];return(I==null?void 0:I.locked)||m.includes(z)||H.includes(z)})},[c,o,t,l,r,a]),y=h.useCallback(m=>{try{return m[t]?JSON.parse(m[t]):{}}catch{return{}}},[t]),b=h.useCallback(m=>{const H={...i};m.length?H[o]=m.join(","):delete H[o],s(H)},[i,o,s]),p=h.useCallback(m=>{d.includes(m)||b([...d,m])},[d,b]),v=h.useCallback(m=>{var E;if((E=a[m])!=null&&E.locked)return;const H={...i},z=d.filter(U=>U!==m);z.length?H[o]=z.join(","):delete H[o];const I=y(H);m in I&&(delete I[m],Object.keys(I).length?H[t]=JSON.stringify(I):delete H[t]),delete H[n],s(H)},[i,d,o,t,n,y,s,a]),B=h.useCallback(m=>d.includes(m)?v(m):p(m),[d,p,v]),x=h.useCallback(m=>{switch(m.type){case"dropdown":case"dropdown-multiple":case"checkbox-multiple":case"radio":return vo({name:m.key,get:"array",searchParams:c,filterKey:t})||[];case"date":{const H=xo({name:m.key,searchParams:c,filterKey:t});return H?new Date(H):void 0}case"date-compact":{const z=y(Object.fromEntries(c.entries()))[m.key];return z&&typeof z=="object"?z:void 0}default:return}},[c,t,y]),L=h.useCallback((m,H)=>{if(m.type==="date-compact"){const z={...i},I=y(z);H==null?delete I[m.key]:I[m.key]=H,Object.keys(I).length?z[t]=JSON.stringify(I):delete z[t],delete z[n],s(z);return}pr({value:H,name:m.key,type:ql(m.type),searchQueries:i,setSearchParams:s,filterKey:t,pageKey:n})},[i,s,t,n,y]),F=h.useCallback(m=>{const H={...i},z=y(H);m in z&&(delete z[m],Object.keys(z).length?H[t]=JSON.stringify(z):delete H[t]),delete H[n],s(H)},[i,t,n,y,s]),A=h.useCallback(()=>{const m={...i};delete m[t],delete m[o],delete m[n],s(m)},[i,t,o,n,s]),D=d.length>0;return{activeKeys:d,configByKey:a,hasActiveFilter:D,addFilter:p,removeFilter:v,toggleFilter:B,getValue:x,setValue:L,clearValue:F,clearAll:A}}const ct={get(r){return ur.storage.get(r)??null},set(r,t){ur.storage.save(r,t)},remove(r){ur.storage.delete(r)}},ir={columns:r=>`filterbar:colprefs:${r}`,savedViews:r=>`filterbar:views:${r}`,lastState:r=>`filterbar:last:${r}`,perPage:r=>`filterbar:perpage:${r}`,tableSort:r=>`tablelayout:sort:${r}`},Tr=(r,t)=>{const o=new Set(t.map(c=>c.key)),n=r.order.filter(c=>o.has(c));for(const c of t)n.includes(c.key)||n.push(c.key);const l=r.hidden.filter(c=>o.has(c));return{order:n,hidden:l}};function Zl({columns:r,scopeId:t,storage:o,onColumnsChange:n,value:l}){const c=h.useMemo(()=>({order:r.map(I=>I.key),hidden:[]}),[r]),s=t?ir.columns(t):void 0,i=(I,E)=>Tr({order:I.order??E,hidden:I.hidden??[]},r),[a,d]=h.useState(()=>{if(l&&(l.order||l.hidden))return i(l,r.map(I=>I.key));if(s){const I=o.get(s);if(I&&Array.isArray(I.order))return Tr(I,r)}return c}),y=r.map(I=>I.key).join("|");h.useEffect(()=>d(I=>Tr(I,r)),[y]);const b=h.useRef(a);b.current=a;const p=l?`${(l.order??[]).join("|")}~${(l.hidden??[]).join("|")}`:null,v=h.useRef(p);h.useEffect(()=>{if(p==null||v.current===p)return;v.current=p;const I=b.current,E=i(l,I.order);E.order.join("|")===I.order.join("|")&&E.hidden.join("|")===I.hidden.join("|")||(d(E),s&&o.set(s,E))},[p,y]);const B=h.useRef(!1);h.useEffect(()=>{B.current||(B.current=!0,n==null||n(a))},[]);const x=h.useCallback(I=>{d(I),s&&o.set(s,I),n==null||n(I)},[s,o,n]),L=h.useMemo(()=>{const I=new Map(r.map(E=>[E.key,E]));return a.order.filter(E=>I.has(E)).map(E=>({...I.get(E),visible:!a.hidden.includes(E)}))},[a,r]),F=h.useCallback(I=>{const E=a.hidden.includes(I)?a.hidden.filter(U=>U!==I):[...a.hidden,I];x({...a,hidden:E})},[a,x]),A=h.useCallback((I,E)=>{if(I===E)return;const U=[...a.order],[X]=U.splice(I,1);U.splice(E,0,X),x({...a,order:U})},[a,x]),D=h.useCallback(I=>{x({...a,hidden:I?r.filter(E=>!E.locked).map(E=>E.key):[]})},[a,r,x]),m=h.useCallback(()=>x(c),[x,c]),H=h.useCallback(I=>x(Tr(I,r)),[x,r]),z=a.hidden.length===0;return{state:a,orderedColumns:L,allVisible:z,toggleVisibility:F,reorder:A,setAllHidden:D,reset:m,applyState:H}}function Gl({scopeId:r,storage:t,snapshotKeys:o,pageKey:n="page",getColumns:l,applyColumns:c}){const{searchParams:s,setSearchParams:i}=Te(),a=r?ir.savedViews(r):void 0,[d,y]=h.useState(()=>a?t.get(a)||[]:[]),b=h.useCallback(x=>{y(x),a&&t.set(a,x)},[a]),p=h.useCallback(x=>{const L=x.trim();if(!L)return;const F={};o.forEach(D=>{const m=s.get(D);m!=null&&(F[D]=m)});const A={id:`${Date.now()}`,name:L,query:F,columns:l==null?void 0:l(),createdAt:Date.now()};b([...d,A])},[o,s,l,b,d]),v=h.useCallback(x=>b(d.filter(L=>L.id!==x)),[b,d]),B=h.useCallback(x=>{const L=Object.fromEntries(s.entries());o.forEach(F=>delete L[F]),Object.assign(L,x.query),delete L[n],i(L),x.columns&&(c==null||c(x.columns))},[s,o,n,i,c]);return{enabled:!!a,views:d,saveView:p,deleteView:v,applyView:B}}function Ql(r,t){let o;try{o=JSON.parse(r)}catch{return r}return!o||typeof o!="object"?r:(delete o[t],Object.keys(o).length>0?JSON.stringify(o):void 0)}function So(r,t,o){const n=r[t];if(n==null)return;const l=Ql(n,o);l===void 0?delete r[t]:r[t]=l}function Ul({scopeId:r,storage:t,snapshotKeys:o,enabled:n=!0,filterKey:l="filter",searchKey:c="q",persistSearch:s=!0}){const{searchParams:i}=Te(),a=r&&n?ir.lastState(r):void 0,d=h.useRef(a),y=h.useRef(!1);h.useEffect(()=>{if(!a){d.current=a;return}if(d.current!==a){d.current=a,y.current=!1;return}const v={};if(o.forEach(B=>{const x=i.get(B);x!=null&&(v[B]=x)}),s||So(v,l,c),Object.keys(v).length===0){y.current&&t.remove(a);return}y.current=!0,t.set(a,v)},[i,a,o,t,s,l,c]);const b=h.useCallback(()=>{if(!a)return null;const v=t.get(a);return!v||Object.keys(v).length===0||!s&&(So(v,l,c),Object.keys(v).length===0)?null:v},[a,t,s,l,c]),p=h.useCallback(()=>{a&&t.remove(a)},[a,t]);return{enabled:!!a,read:b,clear:p}}function Jl({scopeId:r,storage:t,perPageKey:o,pageSizeOptions:n,enabled:l=!0}){const{searchParams:c}=Te(),s=r&&l?ir.perPage(r):void 0,i=c.toString(),a=h.useRef(s);h.useEffect(()=>{if(!s){a.current=s;return}if(a.current!==s){a.current=s;return}const b=c.get(o);if(!b)return;const p=Number(b);!Number.isFinite(p)||p<=0||t.set(s,p)},[i,s,o,t]);const d=h.useCallback(()=>{if(!s)return null;const b=t.get(s);if(b==null)return null;const p=Number(b);return!Number.isFinite(p)||p<=0||n&&!n.includes(p)?null:String(p)},[s,t,n]),y=h.useCallback(()=>{s&&t.remove(s)},[s,t]);return{enabled:!!s,read:d,clear:y}}let st={},it=!1,at=null;const Yl=(r,t)=>{Object.assign(st,r),at=t,!it&&(it=!0,queueMicrotask(()=>{const o=st,n=at;st={},it=!1,at=null,!(!n||Object.keys(o).length===0)&&n(l=>{const c=new URLSearchParams(l);return Object.entries(o).forEach(([s,i])=>c.set(s,i)),c})}))};function Xl({enabled:r,snapshotKeys:t,perPageKey:o,readSnapshot:n,readPerPage:l}){const{searchParams:c,setSearchParams:s,location:i}=Te(),a=h.useRef(null);h.useEffect(()=>{if(!r||a.current===i.pathname)return;a.current=i.pathname;const d={};if(!c.has(o)){const y=l();y&&(d[o]=y)}if(!t.some(y=>c.has(y))){const y=n();y&&Object.assign(d,y)}Object.keys(d).length!==0&&Yl(d,s)},[i.pathname,r])}const $l=({configs:r,activeKeys:t,onToggle:o,hasActiveFilter:n,onReset:l})=>r.length?e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:n?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"FilterHorizontal"}),"aria-label":"Add filter"})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{minWidth:260},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:"Add Filter"}),n&&l&&e.jsx(N.Button,{variant:"link",tone:"brand",size:"xs",onClick:l,children:"Reset"})]}),children:r.map(c=>e.jsx(W.MenuItem,{selected:c.locked||t.includes(c.key),disabled:c.locked,closeOnSelect:!1,startIcon:c.icon??void 0,onClick:()=>{c.locked||o(c.key)},children:c.label},c.key))})})]}):null,Ir=({onClear:r,onRemove:t})=>e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"link",tone:"neutral",size:"xs",iconLeft:e.jsx(T.Icon,{name:"MenuHorizontal"}),"aria-label":"Filter actions"})}),e.jsx(W.MenuLists,{children:e.jsxs(W.MenuBody,{style:{width:180},children:[e.jsx(W.MenuItem,{startIcon:e.jsx(T.Icon,{name:"CrossCircle"}),onClick:r,children:"Clear value"}),t&&e.jsx(W.MenuItem,{intent:"danger",startIcon:e.jsx(T.Icon,{name:"Trash1"}),onClick:t,children:"Remove filter"})]})})]}),Kl=r=>{const t=new Date(r);return t.setHours(0,0,0,0),t},ko=(r,t,o)=>{const n=new Date(r);return o==="day"?n.setDate(n.getDate()+t):o==="week"?n.setDate(n.getDate()+t*7):o==="month"?n.setMonth(n.getMonth()+t):n.setFullYear(n.getFullYear()+t),n},Bo=r=>{const t=Kl(new Date);if(r.direction==="this"){const n=new Date(t),l=new Date(t);return r.period==="week"?(n.setDate(t.getDate()-t.getDay()),l.setDate(n.getDate()+6)):r.period==="month"?(n.setDate(1),l.setMonth(l.getMonth()+1,0)):r.period==="year"&&(n.setMonth(0,1),l.setMonth(11,31)),{from:n,to:l}}const o=r.count??1;return r.direction==="past"?{from:ko(t,-o,r.period),to:t}:{from:t,to:ko(t,o,r.period)}},mo=24,Fo=r=>r.length>mo?`${r.slice(0,mo)}...`:r,Or=r=>r.toLocaleDateString(void 0,{day:"2-digit",month:"short",year:"numeric"}),Wr={is:"Is","is-before":"Is before","is-after":"Is after","is-on-or-before":"Is on or before","is-on-or-after":"Is on or after","is-between":"Is between","is-relative-to-today":"Is relative to today","is-empty":"Is empty","is-not-empty":"Is not empty"},Rl=["is","is-before","is-after","is-on-or-before","is-on-or-after","is-between","is-relative-to-today","is-empty","is-not-empty"],dt={past:"Past",next:"Next",this:"This"},en=["day","week","month","year"],rn=["past","next","this"],tn=r=>r.field.type==="date-compact"?e.jsx(nn,{field:r.field,value:r.value,onChange:r.onChange,onClear:r.onClear,onRemove:r.onRemove}):e.jsx(on,{field:r.field,value:r.value,onChange:r.onChange,onClear:r.onClear,onRemove:r.onRemove}),on=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=t?Or(new Date(t)):null,s=!!c,i=s?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:500},children:[r.label,":"]})," ",e.jsx("span",{style:{fontWeight:400},children:Fo(c)})]}):r.label;return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:s?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:s?e.jsx(T.Icon,{name:"Calendar",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:i})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:260},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:e.jsx(er.StarasiaDate,{size:"sm",input:!1,clearable:!0,filter:r.mode,value:t,onChange:a=>a==null?n():o(a),withPadding:!1})})})]})},ln=r=>{switch(r.op){case"is":case"is-before":case"is-after":case"is-on-or-before":case"is-on-or-after":return r.date?`${Wr[r.op]} ${Or(new Date(r.date))}`:null;case"is-between":return r.from&&r.to?`${Or(new Date(r.from))} - ${Or(new Date(r.to))}`:null;case"is-relative-to-today":{const t=r.relative;if(!t)return null;if(t.direction==="this")return`This ${t.period}`;const o=t.count??1,n=o===1?t.period:`${t.period}s`;return`${dt[t.direction]} ${o} ${n}`}case"is-empty":case"is-not-empty":return Wr[r.op];default:return null}},nn=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=r.ops&&r.ops.length>0?r.ops:Rl,s=r.defaultOp&&c.includes(r.defaultOp)?r.defaultOp:c[0],i=(t==null?void 0:t.op)??s,a=t?ln(t):null,d=!!a,y=d?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:500},children:[r.label,":"]})," ",e.jsx("span",{style:{fontWeight:400},children:Fo(a)})]}):r.label,b=p=>{if(p!==i){if(p==="is-empty"||p==="is-not-empty"){o({op:p});return}if(p==="is-relative-to-today"){o({op:p,relative:(t==null?void 0:t.relative)??{direction:"past",count:1,period:"week"}});return}if(p==="is-between"){o({op:p,from:t==null?void 0:t.from,to:t==null?void 0:t.to});return}o({op:p,date:t==null?void 0:t.date})}};return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:d?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:d?e.jsx(T.Icon,{name:"Calendar",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:y})}),e.jsxs(W.MenuLists,{children:[e.jsx(W.MenuBody,{style:{width:320},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",gap:"xs",fullWidth:!0,children:[e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",gap:"xs",style:{minWidth:0},children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(cn,{op:i,ops:c,onChange:b})]}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:e.jsx(sn,{value:t,op:i,onChange:o})}),i==="is-relative-to-today"&&e.jsx(W.MenuFooter,{children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"Filter will update with the current date"})})]})]})},cn=({op:r,ops:t,onChange:o})=>e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"link",tone:"neutral",size:"xs",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:Wr[r]})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:200},children:t.map(n=>e.jsx(W.MenuItem,{selected:r===n,onClick:()=>o(n),endIcon:r===n?e.jsx(T.Icon,{name:"Check"}):void 0,children:Wr[n]},n))})})]}),sn=({value:r,op:t,onChange:o})=>{if(t==="is-empty"||t==="is-not-empty")return e.jsx(u.Box,{paddingBlock:"sm",paddingInline:"sm",children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"No further input required."})});if(t==="is-between"){const n=r!=null&&r.from||r!=null&&r.to?{from:r!=null&&r.from?new Date(r.from):null,to:r!=null&&r.to?new Date(r.to):null}:void 0;return e.jsx(er.StarasiaDate,{size:"sm",input:!1,clearable:!0,rangedDate:!0,value:n,onChange:l=>{if(l==null){o({op:t});return}if(typeof l=="object"&&l!==null&&"from"in l&&"to"in l){let{from:c,to:s}=l;if(!c&&s&&(c=s,s=null),!c&&!s){o({op:t});return}o({op:t,from:c?c.toISOString():void 0,to:s?s.toISOString():void 0})}},withPadding:!1},"range")}return t==="is-relative-to-today"?e.jsx(an,{value:r==null?void 0:r.relative,onChange:n=>o({op:t,relative:n})}):e.jsx(er.StarasiaDate,{size:"sm",input:!1,clearable:!0,value:r!=null&&r.date?new Date(r.date):void 0,onChange:n=>{if(n==null){o({op:t});return}n instanceof Date&&o({op:t,date:n.toISOString()})},withPadding:!1},"single")},an=({value:r,onChange:t})=>{const o=(r==null?void 0:r.direction)??"past",n=(r==null?void 0:r.count)??1,l=(r==null?void 0:r.period)??"week",c=o!=="this",s=Bo({direction:o,count:n,period:l});return e.jsxs(u.Box,{direction:"column",display:"flex",gap:"sm",children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"xs",children:[e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:dt[o]})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:140},children:rn.map(i=>e.jsx(W.MenuItem,{selected:o===i,endIcon:o===i?e.jsx(T.Icon,{name:"Check"}):void 0,onClick:()=>t(i==="this"?{direction:i,period:l}:{direction:i,count:n,period:l}),children:dt[i]},i))})})]}),c&&e.jsx(Xe.Input,{type:"number",size:"sm",min:1,clearable:!1,value:n,onChange:i=>{const a=Number(i.target.value);t({direction:o,count:Number.isFinite(a)&&a>0?a:1,period:l})},style:{width:72}}),e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:l})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:140},children:en.map(i=>e.jsx(W.MenuItem,{selected:l===i,endIcon:l===i?e.jsx(T.Icon,{name:"Check"}):void 0,onClick:()=>t(o==="this"?{direction:o,period:i}:{direction:o,count:n,period:i}),children:i},i))})})]})]}),e.jsx(er.StarasiaDate,{size:"sm",input:!1,disabled:!0,rangedDate:!0,value:s,onChange:()=>{},withPadding:!1},"relative-preview")]})},Eo=18,dn=r=>r.length>Eo?`${r.slice(0,Eo)}...`:r,hn=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=r.type==="dropdown-multiple",s=t.length,i=r.searchable!==!1,[a,d]=h.useState(""),y=r.options,b=typeof r.onSearch=="function",p=(()=>{if(b)return y;const F=a.trim().toLowerCase();return F?y.filter(A=>A.label.toLowerCase().includes(F)):y})(),v=F=>t.some(A=>A.value===F.value),B=F=>{if(!c){o([{label:F.label,value:F.value}]),d("");return}o(v(F)?t.filter(A=>A.value!==F.value):[...t,{label:F.label,value:F.value}])},x=F=>{var A;d(F),(A=r.onSearch)==null||A.call(r,F)},L=s===0?r.label:e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:500},children:[r.label,":"]})," ",e.jsx("span",{style:{fontWeight:400},children:s===1?dn(t[0].label):`${s} Selected`})]});return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:s>0?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:s>0?e.jsx(T.Icon,{name:"Tag",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:L})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:260},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:e.jsxs(u.Box,{direction:"column",gap:"sm",children:[i&&e.jsx(lr.Dropdown,{size:"sm",triggerInput:!0,fullWidth:!0,hideChevronIcon:!0,clearable:!0,multiSelect:c,searchAble:!0,searchValue:a,onSearch:x,value:t,onChange:o,placeholder:`Search ${r.label.toLowerCase()}…`}),e.jsx(u.Box,{direction:"column",overflow:"overflow-y-auto",customMaxHeight:"240px",children:r.isLoading?e.jsx(u.Box,{paddingBlock:"sm",paddingInline:"sm",children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"Loading…"})}):p.length===0?e.jsx(u.Box,{paddingBlock:"sm",paddingInline:"sm",children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"No results"})}):p.map(F=>e.jsx(W.MenuItem,{closeOnSelect:!c,selected:v(F),startIcon:F.avatar,endIcon:v(F)?e.jsx(T.Icon,{name:"Check"}):void 0,description:F.description,onClick:()=>B(F),children:F.label},F.value))})]})})})]})},Mo=18,fn=r=>r.length>Mo?`${r.slice(0,Mo)}...`:r,Lo=({checked:r,indeterminate:t})=>e.jsx("span",{style:{pointerEvents:"none",display:"inline-flex"},children:e.jsx(Ze.Checkbox,{size:"sm",checked:r,readOnly:!0,onChange:()=>{},variant:t?"indeterminate":"select"})}),gn=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=new Set(t.map(p=>p.value)),s=t.length,i=r.options.length>0&&r.options.every(p=>c.has(p.value)),a=s>0&&!i,d=p=>{o(c.has(p.value)?t.filter(v=>v.value!==p.value):[...t,{label:p.label,value:p.value}])},y=()=>{o(i?[]:r.options.map(p=>({label:p.label,value:p.value})))},b=s===0?r.label:e.jsxs(e.Fragment,{children:[e.jsxs(k.Text,{as:"span",fontWeight:"semibold",children:[r.label,":"]})," ",e.jsx(k.Text,{as:"span",children:s===1?fn(t[0].label):`${s} Selected`})]});return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:s>0?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:s>0?e.jsx(T.Icon,{name:"Tag",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:b})}),e.jsx(W.MenuLists,{children:e.jsxs(W.MenuBody,{style:{width:240},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:[e.jsx(W.MenuItem,{closeOnSelect:!1,selected:i,onClick:y,startIcon:e.jsx(Lo,{checked:i||a,indeterminate:a}),children:"Select All"}),r.options.map(p=>e.jsx(W.MenuItem,{closeOnSelect:!1,selected:c.has(p.value),onClick:()=>d(p),startIcon:e.jsx(Lo,{checked:c.has(p.value)}),children:p.label},p.value))]})})]})},To=({activeKeys:r,configByKey:t,getValue:o,setValue:n,clearValue:l,removeFilter:c})=>e.jsx(e.Fragment,{children:r.map(s=>{const i=t[s];if(!i)return null;const a=o(i),d=i.locked?void 0:()=>c(s);return i.type==="date"||i.type==="date-compact"?e.jsx(tn,{field:i,value:a,onChange:y=>n(i,y),onClear:()=>l(s),onRemove:d},s):i.type==="checkbox-multiple"?e.jsx(gn,{field:i,value:a||[],onChange:y=>n(i,y),onClear:()=>l(s),onRemove:d},s):e.jsx(hn,{field:i,value:a||[],onChange:y=>n(i,y),onClear:()=>l(s),onRemove:d},s)})}),Io=r=>`${r} Rows`,un=({pagination:r,pageKey:t="page",perPageKey:o="perPage",pageSizeOptions:n=[10,25,50,100],defaultPerPage:l=10,showResultCount:c=!0,showPageSize:s=!0,showPagination:i=!0})=>{var F;const{searchQueries:a,setSearchParams:d,searchParams:y}=Te(),b=y.get(o),p=b?Number(b):l,v=A=>{d({...a,[t]:String(A)})},B=A=>{d({...a,[o]:A,[t]:"1"})},x=(r==null?void 0:r.rangeStart)??(((r==null?void 0:r.currentPage)||0)>1?(((r==null?void 0:r.currentPage)||0)-1)*((r==null?void 0:r.perPage)||0)+1:0),L=(r==null?void 0:r.rangeEnd)??((r==null?void 0:r.totalCurrentPage)!==(r==null?void 0:r.perPage)?r==null?void 0:r.totalData:((r==null?void 0:r.currentPage)||1)*((r==null?void 0:r.totalCurrentPage)||0));return e.jsxs(e.Fragment,{children:[c&&e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"primary",truncate:!0,children:`${x}-${L} of ${((F=r==null?void 0:r.totalData)==null?void 0:F.toLocaleString())||0}`}),s&&e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),"aria-label":"Rows per page",children:Io(p)})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{children:n.map(A=>e.jsx(W.MenuItem,{selected:A===p,onClick:()=>B(String(A)),children:Io(A)},A))})})]}),i&&((r==null?void 0:r.totalPage)??0)>1&&e.jsx(u.Box,{direction:"column",display:"flex",align:"center",gap:"sm",paddingRight:"sm",style:{borderRight:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.14))"},children:e.jsx(gr.Pagination,{size:"sm",variant:"neutral",siblingCount:0,currentPage:r!=null&&r.currentPage?Number(r.currentPage):1,totalPages:Number(r==null?void 0:r.totalPage),onPageChange:v})})]})};function yn(r,t,o=!0){h.useEffect(()=>{if(!o)return;const n=l=>{var i;if(l.metaKey||l.ctrlKey||l.altKey||l.key!==r)return;const c=l.target,s=(i=c==null?void 0:c.tagName)==null?void 0:i.toLowerCase();s==="input"||s==="textarea"||c!=null&&c.isContentEditable||(l.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[r,t,o])}const pn=240,Oo=({searchKey:r="q",filterKey:t="filter",pageKey:o="page",placeholder:n="Search",shortcut:l="/",collapsible:c=!0})=>{const{searchParams:s,setSearchParams:i,searchQueries:a}=Te(),d=Lr(r,s,t)||"",[y,b]=h.useState(!c||!!d),[p,v]=h.useState(c&&!d),[B,x]=h.useState(d),L=be.useDebounce(B,350),F=h.useRef(null);h.useEffect(()=>{x(d),d&&b(!0)},[d]),h.useEffect(()=>{y&&v(!1)},[y]),h.useEffect(()=>{L!==d&&pr({value:L,name:r,type:"search",searchQueries:a,setSearchParams:i,filterKey:t,pageKey:o})},[L]);const A=h.useCallback(()=>{b(!0),requestAnimationFrame(()=>{var z;return(z=F.current)==null?void 0:z.focus()})},[]);yn(l,A);const D=()=>{c&&!B&&b(!1)},m=z=>{var I;c&&z.key==="Escape"&&!B&&(b(!1),(I=F.current)==null||I.blur())},H=()=>{y||v(!0)};return e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",gap:"spacing-0",children:[p&&e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Search",size:"sm"}),"aria-label":"Search","aria-expanded":!1,onClick:A}),e.jsxs(u.Box,{onTransitionEnd:H,style:{position:"relative",width:y?pn:0,overflow:"hidden",transition:"width 220ms ease"},children:[e.jsx(Xe.Input,{ref:F,size:"sm",fullWidth:!0,value:B,placeholder:n,leftIcon:e.jsx(T.Icon,{name:"Search",width:16,height:16}),onChange:z=>x(z.target.value),onKeyDown:m,onBlur:D,tabIndex:y?0:-1}),y&&!B&&e.jsx(u.Box,{align:"center",justify:"center",borderColor:"border-subtle",borderWidth:"border",borderStyle:"border-solid",borderRadius:"rounded-xs",paddingInline:"spacing-1",customBackgroundColor:"var(--sa-background-surface-hover, #f1f2f4)",style:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",pointerEvents:"none",minWidth:18,height:18,display:"inline-flex"},children:e.jsx(k.Text,{fontSize:"xs",color:"subtle",children:l})})]})]})},Wo=({columns:r,allVisible:t,onToggle:o,onReorder:n,onSetAllHidden:l})=>{const[c,s]=h.useState(null),[i,a]=h.useState(null),d=()=>{c!==null&&i!==null&&c!==i&&n(c,i),s(null),a(null)},y=(b,p)=>{const v=b+p;v<0||v>=r.length||n(b,v)};return e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:t?"outline":"secondary",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Grid",size:"sm"}),"aria-label":"Customize columns"})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{children:e.jsxs(u.Box,{padding:"sm",direction:"column",customWidth:"296px",customMaxHeight:"60vh",overflow:"overflow-hidden",children:[e.jsx(k.Text,{fontWeight:"semibold",color:"primary",children:"Customize Column Table"}),e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",paddingBlock:"md",children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtle",children:"Show in table"}),e.jsx(N.Button,{variant:"link",tone:"info",size:"xs",onClick:()=>l(t),children:t?"Hide All":"Show All"})]}),e.jsx(u.Box,{direction:"column",overflow:"overflow-y-auto",children:r.map((b,p)=>{const v=!b.locked,B=i===p&&c!==null&&c!==p;return e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",paddingBlock:"xs",draggable:v,onDragStart:()=>v&&s(p),onDragOver:x=>{x.preventDefault(),a(p)},onDrop:d,onDragEnd:d,style:{minHeight:32,boxShadow:B?"inset 0 2px 0 0 var(--sa-background-brand, #04254f)":void 0},children:[e.jsx(u.Box,{direction:"column",as:"div",align:"center",justify:"center",role:"button",tabIndex:v?0:-1,"aria-label":`Reorder ${b.title}`,"aria-disabled":!v||void 0,color:"icon-subtlest",onKeyDown:x=>{v&&(x.key==="ArrowUp"?(x.preventDefault(),y(p,-1)):x.key==="ArrowDown"&&(x.preventDefault(),y(p,1)))},style:{display:"inline-flex",cursor:v?"grab":"default",opacity:v?1:.4},children:e.jsx(T.Icon,{name:"DragVertical",width:16,height:16})}),b.icon&&e.jsx(u.Box,{direction:"column",align:"center",color:"icon-subtle",style:{display:"inline-flex"},children:b.icon}),e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"primary",truncate:!0,children:b.title}),e.jsx(u.Box,{direction:"column",style:{marginLeft:"auto"},children:e.jsx(sr.Toggle,{size:"sm",checked:b.visible,disabled:b.locked,onChange:()=>o(b.key),"aria-label":`Toggle ${b.title} column`})})]},b.key)})})]})})})]})},Ao=({views:r,onApply:t,onDelete:o,onSave:n})=>{const[l,c]=h.useState(""),s=()=>{const i=l.trim();i&&(n(i),c(""))};return e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:r.length>0?"secondary":"outline",tone:(r.length>0,"neutral"),size:"sm",iconLeft:e.jsx(T.Icon,{name:"Bookmark",size:"sm"}),"aria-label":"Saved views"})}),e.jsxs(W.MenuLists,{style:{width:"260px"},children:[e.jsx(W.MenuBody,{children:e.jsxs(u.Box,{direction:"column",padding:"xs",gap:"sm",children:[e.jsx(k.Text,{fontWeight:"semibold",color:"primary",children:"Saved Views"}),e.jsx(u.Box,{direction:"column",overflow:"overflow-y-auto",children:r.length===0?e.jsx(u.Box,{direction:"column",paddingBlock:"sm",children:e.jsx(k.Text,{fontSize:"sm",color:"subtlest",children:"No saved views yet"})}):r.map(i=>e.jsx(W.MenuItem,{startIcon:e.jsx(T.Icon,{name:"Bookmark"}),onClick:()=>t(i),endIcon:e.jsx(N.Button,{variant:"link",tone:"error",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Trash2"}),"aria-label":`Delete ${i.name}`,onClick:a=>{a.stopPropagation(),o(i.id)}}),children:i.name},i.id))})]})}),e.jsx(W.MenuFooter,{children:e.jsxs(u.Box,{direction:"row",gap:"xs",children:[e.jsx(u.Box,{direction:"column",style:{flex:"1 0 0",minWidth:0},children:e.jsx(Xe.Input,{size:"sm",fullWidth:!0,placeholder:"Save current view as…",value:l,onChange:i=>c(i.target.value),onKeyDown:i=>{i.key==="Enter"&&s()}})}),e.jsx(N.Button,{variant:"primary",tone:"brand",size:"sm",disabled:!l.trim(),onClick:s,children:"Save"})]})})]})]})},bn=({isOpen:r,onClose:t,configs:o,activeKeys:n,configByKey:l,hasActiveFilter:c,onToggle:s,onReset:i,getValue:a,setValue:d,clearValue:y,removeFilter:b})=>{const p=n.length;return e.jsx(kr.Drawer,{position:"bottom",isShow:r,onHide:t,children:e.jsxs(u.Box,{direction:"column",customMaxHeight:"85vh",style:{minHeight:280},children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",paddingInline:"md",paddingBlock:"sm",style:{borderBottom:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.14))"},children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"xs",children:[e.jsx(k.Text,{fontWeight:"semibold",color:"primary",children:"Filter"}),p>0&&e.jsxs(k.Text,{fontSize:"sm",color:"subtle",children:["(",p,")"]})]}),e.jsx(N.Button,{variant:"link",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Cross"}),"aria-label":"Close filter",onClick:t})]}),e.jsxs(u.Box,{direction:"column",gap:"lg",padding:"md",overflow:"overflow-y-auto",style:{flex:"1 1 auto",minHeight:0},children:[p>0&&e.jsxs(u.Box,{direction:"column",gap:"sm",children:[e.jsx(k.Text,{fontSize:"xs",fontWeight:"medium",color:"subtlest",children:"Filter aktif"}),e.jsx(u.Box,{direction:"row",display:"flex",wrap:"wrap",gap:"sm",align:"center",children:e.jsx(To,{activeKeys:n,configByKey:l,getValue:a,setValue:d,clearValue:y,removeFilter:b})})]}),o.length>0&&e.jsxs(u.Box,{direction:"column",gap:"sm",children:[e.jsx(k.Text,{fontSize:"xs",fontWeight:"medium",color:"subtlest",children:"Tambah filter"}),e.jsx(u.Box,{direction:"column",children:o.map(v=>{const B=n.includes(v.key),x=!!v.locked;return e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",gap:"sm",paddingBlock:"sm",style:{opacity:x?.5:1,borderTop:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.08))"},children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",style:{minWidth:0},children:[v.icon&&e.jsx(u.Box,{direction:"column",align:"center",color:"icon-subtle",style:{display:"inline-flex"},children:v.icon}),e.jsx(k.Text,{fontSize:"sm",color:"primary",truncate:!0,children:v.label})]}),e.jsx(sr.Toggle,{size:"sm",checked:B||x,disabled:x,onChange:()=>s(v.key),"aria-label":`Toggle ${v.label}`})]},v.key)})})]})]}),e.jsxs(u.Box,{direction:"row",display:"flex",gap:"sm",paddingInline:"md",paddingBlock:"sm",style:{borderTop:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.14))"},children:[e.jsx(u.Box,{direction:"column",style:{flex:"1 1 0"},children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"md",fullWidth:!0,disabled:!c,onClick:i,children:"Reset"})}),e.jsx(u.Box,{direction:"column",style:{flex:"1 1 0"},children:e.jsx(N.Button,{variant:"primary",tone:"brand",size:"md",fullWidth:!0,onClick:t,children:"Selesai"})})]})]})})},Cn=r=>`${r} Rows`,vn=({perPageKey:r,pageKey:t,pageSizeOptions:o,defaultPerPage:n=10,showPageSize:l})=>{const{searchQueries:c,setSearchParams:s,searchParams:i}=Te(),a=i.get(r),d=a?Number(a):n,y=b=>{s({...c,[r]:b,[t]:"1"})};return l?e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"MenuVertical",size:"sm"}),"aria-label":"More options"})}),e.jsx(W.MenuLists,{children:e.jsxs(W.MenuBody,{style:{minWidth:200},children:[e.jsx(u.Box,{paddingInline:"sm",paddingBlock:"xs",children:e.jsx(k.Text,{fontSize:"xs",fontWeight:"medium",color:"subtlest",children:"Rows per page"})}),o.map(b=>e.jsx(W.MenuItem,{selected:b===d,endIcon:b===d?e.jsx(T.Icon,{name:"Check"}):void 0,onClick:()=>y(String(b)),children:Cn(b)},b))]})})]}):null},xn=r=>{var we;const{withPadding:t,configs:o,activeKeys:n,configByKey:l,hasActiveFilter:c,toggleFilter:s,removeFilter:i,getValue:a,setValue:d,clearValue:y,onReset:b,searchable:p,searchKey:v,filterKey:B,pageKey:x,searchPlaceholder:L,searchShortcut:F,searchCollapsible:A,pagination:D,perPageKey:m,pageSizeOptions:H,defaultPerPage:z,showPagination:I,showResultCount:E,showPageSize:U,hasColumns:X,orderedColumns:G,allVisible:R,onToggleVisibility:_,onReorder:K,onSetAllHidden:te,showSavedViews:q,savedViews:j,onApplyView:Z,onDeleteView:le,onSaveView:Ce,leadingActions:ve}=r,[he,ge]=h.useState(!1),{searchQueries:xe,setSearchParams:Ee}=Te(),Oe=(D==null?void 0:D.rangeStart)??(((D==null?void 0:D.currentPage)||0)>1?(((D==null?void 0:D.currentPage)||0)-1)*((D==null?void 0:D.perPage)||0)+1:1),Ve=(D==null?void 0:D.rangeEnd)??((D==null?void 0:D.totalCurrentPage)!==(D==null?void 0:D.perPage)?D==null?void 0:D.totalData:((D==null?void 0:D.currentPage)||1)*((D==null?void 0:D.totalCurrentPage)||0)),Pe=$e=>{Ee({...xe,[x]:String($e)})},ke=E||I&&!!(D!=null&&D.totalPage),je=()=>{b(),ge(!1)};return e.jsxs(u.Box,{direction:"column",gap:"sm",fullWidth:!0,paddingTop:t?"sm":void 0,paddingBottom:t?"sm":void 0,paddingLeft:t?"md":void 0,paddingRight:t?"md":void 0,role:"toolbar","aria-label":"Filter bar",children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",wrap:"wrap",gap:"sm",fullWidth:!0,overflow:"overflow-auto",children:[p&&e.jsx(Oo,{searchKey:v,filterKey:B,pageKey:x,placeholder:L,shortcut:F,collapsible:A}),e.jsx(N.Button,{variant:c?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"FilterHorizontal"}),onClick:()=>ge(!0),"aria-label":"Open filters",children:c?`Filter: ${n.length}`:null}),e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",style:{marginLeft:"auto"},children:[ve,q&&e.jsx(Ao,{views:j,onApply:Z,onDelete:le,onSave:Ce}),X&&e.jsx(Wo,{columns:G,allVisible:R,onToggle:_,onReorder:K,onSetAllHidden:te}),e.jsx(vn,{perPageKey:m,pageKey:x,pageSizeOptions:H,defaultPerPage:z,showPageSize:U})]})]}),ke&&e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",gap:"sm",fullWidth:!0,children:[E?e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"primary",truncate:!0,children:`${Oe}-${Ve} of ${((we=D==null?void 0:D.totalData)==null?void 0:we.toLocaleString())||0}`}):e.jsx(u.Box,{direction:"column"}),I&&!!(D!=null&&D.totalPage)&&e.jsx(gr.Pagination,{size:"xs",variant:"neutral",siblingCount:0,currentPage:D!=null&&D.currentPage?Number(D.currentPage):1,totalPages:Number(D.totalPage),onPageChange:Pe})]}),e.jsx(bn,{isOpen:he,onClose:()=>ge(!1),configs:o,activeKeys:n,configByKey:l,hasActiveFilter:c,onToggle:s,onReset:je,getValue:a,setValue:d,clearValue:y,removeFilter:i})]})},wn=({withPadding:r=!1,filterConfigs:t=[],filterKey:o="filter",activeFilterKey:n="filters",pageKey:l="page",perPageKey:c="perPage",pageSizeOptions:s=[25,50,100],defaultPerPage:i,showPagination:a=!0,showResultCount:d=!0,showPageSize:y=!0,searchable:b=!1,searchKey:p="q",searchPlaceholder:v="Search",searchShortcut:B="/",searchPosition:x="right",searchCollapsible:L=!0,pagination:F,columns:A=[],onColumnsChange:D,columnsState:m,scopeId:H,savedViews:z,persistLastState:I=!0,persistSearch:E=!0,storage:U=ct,onReset:X,leadingActions:G})=>{const R=H??(z==null?void 0:z.scopeId),{activeKeys:_,configByKey:K,hasActiveFilter:te,toggleFilter:q,removeFilter:j,getValue:Z,setValue:le,clearValue:Ce,clearAll:ve}=nt({configs:t,filterKey:o,activeFilterKey:n,pageKey:l,searchKey:p}),he=Zl({columns:A,scopeId:R,storage:U,onColumnsChange:D,value:m}),ge=Gl({scopeId:R,storage:U,snapshotKeys:[n,o,c],pageKey:l,getColumns:()=>he.state,applyColumns:he.applyState}),xe=Ul({scopeId:R,storage:U,snapshotKeys:[n,o,l],enabled:I,filterKey:o,searchKey:p,persistSearch:E}),Ee=Jl({scopeId:R,storage:U,perPageKey:c,pageSizeOptions:s,enabled:I});Xl({enabled:I&&!!R,snapshotKeys:[n,o,l],perPageKey:c,readSnapshot:xe.read,readPerPage:Ee.read});const Oe=i??s[0]??25,Ve=!!(z!=null&&z.enabled)&&ge.enabled,Pe=()=>{ve(),xe.clear(),X==null||X()},ke=be.useMediaQuery("md"),je=b?e.jsx(Oo,{searchKey:p,filterKey:o,pageKey:l,placeholder:v,shortcut:B,collapsible:L}):null;return ke?e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",gap:"sm",wrap:"wrap",fullWidth:!0,paddingTop:r?"sm":void 0,paddingBottom:r?"sm":void 0,paddingLeft:r?"md":void 0,paddingRight:r?"md":void 0,role:"toolbar","aria-label":"Filter bar",children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",style:{flex:"1 1 0",minWidth:0},children:[e.jsx($l,{configs:t,activeKeys:_,onToggle:q,hasActiveFilter:te,onReset:Pe}),x==="left"&&je,e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",overflow:"overflow-x-auto",style:{flex:"1 1 0",minWidth:0},children:[e.jsx(To,{activeKeys:_,configByKey:K,getValue:Z,setValue:le,clearValue:Ce,removeFilter:j}),te&&e.jsx(N.Button,{variant:"link",tone:"brand",size:"sm",onClick:Pe,children:"Reset"})]})]}),e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",children:[G,e.jsx(un,{pagination:F,pageKey:l,perPageKey:c,pageSizeOptions:s,defaultPerPage:Oe,showPagination:a,showResultCount:d,showPageSize:y}),x==="right"&&je,Ve&&e.jsx(Ao,{views:ge.views,onApply:ge.applyView,onDelete:ge.deleteView,onSave:ge.saveView}),A.length>0&&e.jsx(Wo,{columns:he.orderedColumns,allVisible:he.allVisible,onToggle:he.toggleVisibility,onReorder:he.reorder,onSetAllHidden:he.setAllHidden})]})]}):e.jsx(xn,{withPadding:r,configs:t,activeKeys:_,configByKey:K,hasActiveFilter:te,toggleFilter:q,removeFilter:j,getValue:Z,setValue:le,clearValue:Ce,onReset:Pe,searchable:b,searchKey:p,filterKey:o,pageKey:l,searchPlaceholder:v,searchShortcut:B,searchCollapsible:L,pagination:F,perPageKey:c,pageSizeOptions:s,defaultPerPage:Oe,showPagination:a,showResultCount:d,showPageSize:y,hasColumns:A.length>0,orderedColumns:he.orderedColumns,allVisible:he.allVisible,onToggleVisibility:he.toggleVisibility,onReorder:he.reorder,onSetAllHidden:he.setAllHidden,showSavedViews:Ve,savedViews:ge.views,onApplyView:ge.applyView,onDeleteView:ge.deleteView,onSaveView:ge.saveView,leadingActions:G})},Dn=r=>{if(!Array.isArray(r)||r.length===0)return;const t=r[0];return(t==null?void 0:t.value)!=null?String(t.value):void 0},Sn=r=>{if(!Array.isArray(r)||r.length===0)return;const t=r.map(o=>(o==null?void 0:o.value)!=null?String(o.value):null).filter(o=>o!=null);return t.length?t:void 0},kn=(r,t)=>{switch(r.type){case"dropdown":case"radio":return Dn(t);case"dropdown-multiple":case"checkbox-multiple":return Sn(t);case"date":return t instanceof Date?t.toISOString():void 0;case"date-compact":return t;default:return}},zo=(r,t)=>{if(r==null||r==="")return t;const o=Number(r);return Number.isFinite(o)&&o>0?o:t},Bn=r=>{const{filterConfigs:t,filterKey:o="filter",activeFilterKey:n="filters",pageKey:l="page",perPageKey:c="perPage",searchKey:s="q",defaultPage:i=1,defaultPerPage:a=10,paramKeys:d,serialize:y}=r,{activeKeys:b,configByKey:p,hasActiveFilter:v,getValue:B}=nt({configs:t,filterKey:o,activeFilterKey:n,pageKey:l,searchKey:s}),{searchParams:x}=Te(),L=x.toString();return h.useMemo(()=>{const A={},D={},m=zo(x.get(l),i),H=zo(x.get(c),a);A[(d==null?void 0:d.page)??"page"]=m,A[(d==null?void 0:d.perPage)??"perPage"]=H;const z=Lr(s,x,o)||"";z&&(A[(d==null?void 0:d.search)??"search"]=z);let I=!1;for(const E of b){const U=p[E];if(!U)continue;const X=B(U);D[E]=X;const G=y==null?void 0:y[E],R=G?G(X):kn(U,X);if(R==null||Array.isArray(R)&&R.length===0)continue;const _=(d==null?void 0:d[E])??E;A[_]=R,I=!0}return{params:A,raw:D,hasActiveFilter:v||!!z||I}},[L,b.join("|"),o,n,l,c,s,i,a,d,y,p])},mn=["dropdown","dropdown-multiple","checkbox-multiple","radio"],Fn=({filterConfigs:r,filterKey:t,activeFilterKey:o,pageKey:n,searchKey:l})=>{const{configByKey:c,getValue:s,setValue:i,removeFilter:a,clearAll:d,hasActiveFilter:y}=nt({configs:r,filterKey:t,activeFilterKey:o,pageKey:n,searchKey:l}),b=(F,A)=>{var m;const D=F.options;return((m=D==null?void 0:D.find(H=>H.value===A))==null?void 0:m.label)??A},p=h.useCallback(F=>{const A=c[F];if(!A)return[];const D=s(A);return Array.isArray(D)?D.map(m=>String(m.value)):[]},[c,s]),v=h.useCallback((F,A)=>{const D=c[F];if(!D||!mn.includes(D.type))return;const m=Array.isArray(A)?A:[A];if(m.length===0){a(F);return}i(D,m.map(H=>({label:b(D,H),value:H})))},[c,i,a]),B=h.useCallback((F,A)=>{const D=p(F);v(F,D.includes(A)?D.filter(m=>m!==A):[...D,A])},[p,v]),x=h.useCallback((F,A)=>p(F).includes(A),[p]),L=h.useCallback(F=>a(F),[a]);return{set:v,toggle:B,clear:L,clearAll:d,isActive:x,values:p,hasActiveFilter:y}},En=(r,t)=>{if(!r)return{};const{fromKey:o,toKey:n,opKey:l}=t,c={};switch(r.op){case"is":case"is-before":case"is-after":case"is-on-or-before":case"is-on-or-after":return r.date&&(c[o]=new Date(r.date).toISOString()),l&&(c[l]=r.op),c;case"is-between":return r.from&&(c[o]=new Date(r.from).toISOString()),r.to&&(c[n]=new Date(r.to).toISOString()),c;case"is-relative-to-today":{if(!r.relative)return c;const{from:s,to:i}=Bo(r.relative);return c[o]=s.toISOString(),c[n]=i.toISOString(),c}case"is-empty":case"is-not-empty":return l&&(c[l]=r.op==="is-empty"?"empty":"not-empty"),c;default:return c}},Ho=({children:r,borderRadius:t,height:o})=>{const n=h.useRef(null),[l,c]=h.useState("100vh");return h.useEffect(()=>{if(o)return;const s=()=>{if(n.current){const i=n.current.getBoundingClientRect().top;c(`calc(100vh - ${i}px)`)}};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[o]),e.jsx(u.Box,{ref:n,fullWidth:!0,borderStyle:"border-solid",borderWidth:"border",borderColor:"border-base",borderRadius:t||"rounded-xs",style:{height:o??l,display:"flex",flexDirection:"column"},children:r})},Vo=({action:r,rightContent:t,leftContent:o,headerSlot:n,advanceFilter:l,showFilter:c=!0})=>{const s=be.useMediaQuery("md"),i=c?e.jsx(Do,{...l}):null,a=()=>r?h.isValidElement(r)?r:e.jsx(u.Box,{style:{display:"flex",flexDirection:s?"row":"column",gap:"8px",width:s?"auto":"100%",textWrap:"nowrap"},children:r.map(({title:d,icon:y,buttonProps:b,onClick:p},v)=>!d&&!y?null:e.jsx(N.Button,{fullWidth:!s,iconLeft:y?e.jsx(T.Icon,{name:y}):void 0,onClick:p,...b,children:d},`action-${v}`))}):null;return e.jsx(u.Box,{style:{display:"flex",width:"100%",justifyContent:"space-between",alignItems:"center",paddingLeft:"8px",paddingRight:"8px",paddingTop:"8px",paddingBottom:"8px",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",flexShrink:0,position:"relative",zIndex:10,flexDirection:s?"row":"column-reverse",gap:"16px"},children:n?n({filter:i}):e.jsxs(e.Fragment,{children:[e.jsxs(u.Box,{style:{display:"flex",gap:"8px",flexDirection:"row",alignItems:"center",flex:1,minWidth:0},children:[i,o]}),e.jsxs(u.Box,{style:{display:"flex",gap:"8px",flexDirection:"row",alignItems:"center",flexShrink:0},children:[t,a()]})]})})},Mn=({totalData:r,withMarginBottom:t=!0,withMarginTop:o=!0})=>e.jsxs(u.Box,{style:{display:"flex",gap:"4px",flexDirection:"row",alignItems:"center",marginBottom:t?"16px":void 0,marginTop:o?"16px":void 0},children:[e.jsxs(He.Body1,{props:{color:"gray-500"},children:["Total data:"," "]}),e.jsx(He.Body1,{children:r||0})]}),Po=({pagination:r,pageKey:t="page",perPageKey:o="perPage",defaultPerPage:n=10,showPagination:l=!0,totalData:c})=>{const{searchQueries:s,setSearchParams:i,searchParams:a}=Te(),d=a.get(o),y=B=>{i({...s,[t]:String(B)})},b=B=>{i({...s,[o]:B,[t]:"1"})},p=(r==null?void 0:r.rangeStart)??(((r==null?void 0:r.currentPage)||0)>1?(((r==null?void 0:r.currentPage)||0)-1)*((r==null?void 0:r.perPage)||0)+1:1),v=(r==null?void 0:r.rangeEnd)??((r==null?void 0:r.totalCurrentPage)!==(r==null?void 0:r.perPage)?r==null?void 0:r.totalData:((r==null?void 0:r.currentPage)||1)*((r==null?void 0:r.totalCurrentPage)||0));return e.jsx(u.Box,{style:{display:"flex",width:"100%",flexDirection:"row",justifyContent:"space-between",alignItems:"center",paddingLeft:"16px",paddingRight:"16px",paddingTop:"8px",paddingBottom:"8px",borderTop:"1px solid var(--sa-border-subtle, #0b120e24)",flexShrink:0},children:l?e.jsxs(e.Fragment,{children:[e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",gap:"8px",alignItems:"center",textWrap:"nowrap"},children:[e.jsx(k.Text,{children:"Rows Per Page: "}),e.jsx(lr.Dropdown,{dropdownLists:[{label:"5",value:"5"},{label:"10",value:"10"},{label:"25",value:"25"},{label:"50",value:"50"},{label:"100",value:"100"}],onChange:B=>{b(B[0].value)},value:d?[{label:`${d} per row`,value:d}]:[{label:`${n} per row`,value:`${n}`}],defaultValue:d?[{label:`${d} per row`,value:d}]:[{label:`${n} per row`,value:`${n}`}]}),e.jsx(k.Text,{children:`${p}-${v} of ${(r==null?void 0:r.totalData)||0}`})]}),e.jsx(gr.Pagination,{currentPage:r!=null&&r.currentPage?Number(r==null?void 0:r.currentPage):1,totalPages:r!=null&&r.totalPage?Number(r==null?void 0:r.totalPage):1,onPageChange:y})]}):e.jsx(Mn,{totalData:c,withMarginBottom:!1,withMarginTop:!1})})},jo=({filter:r,columnTitle:t})=>{const[o,n]=h.useState(!1),l=h.useRef(null),c=h.useRef(null),s=h.useRef(null),[i,a]=h.useState(""),[d,y]=h.useState({top:0,left:0}),b=r.selectedValues,p=h.useMemo(()=>i?r.options.filter(x=>x.label.toLowerCase().includes(i.toLowerCase())):r.options,[r.options,i]);h.useEffect(()=>{if(o&&c.current){const x=c.current.getBoundingClientRect(),L=280,F={top:x.bottom+8};r.position==="left"||x.left+L>window.innerWidth?F.right=window.innerWidth-x.right:F.left=x.left,y(F)}},[o,r.position]),h.useEffect(()=>{o&&s.current?setTimeout(()=>{var x;return(x=s.current)==null?void 0:x.focus()},50):a("")},[o]),h.useEffect(()=>{const x=L=>{l.current&&!l.current.contains(L.target)&&c.current&&!c.current.contains(L.target)&&n(!1)};return o&&document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[o]);const v=x=>{const L=b.includes(x)?b.filter(F=>F!==x):[...b,x];r.onFilterChange(L)},B=()=>r.onFilterChange([]);return e.jsxs(u.Box,{direction:"column",style:{position:"relative"},children:[e.jsx(u.Box,{ref:c,style:{display:"flex",flexDirection:"row",alignItems:"center",cursor:"pointer"},onClick:x=>{var L;x.stopPropagation(),o||(L=r.onOpen)==null||L.call(r),n(F=>!F)},children:e.jsx(T.Icon,{name:o?"ChevronUp":"ChevronDown",size:"sm",style:{color:b.length>0?"var(--sa-color-brand-500, #1a4fa0)":"var(--sa-text-subtle, #8c8f97)"}})}),o&&e.jsxs(u.Box,{ref:l,style:{position:"fixed",top:`${d.top}px`,...d.left!==void 0?{left:`${d.left}px`}:{right:`${d.right}px`},backgroundColor:"white",borderRadius:"4px",minWidth:"280px",maxHeight:"400px",display:"flex",flexDirection:"column",zIndex:9999,animation:"fadeInDropdown 0.15s ease-out",border:"1px solid var(--sa-border-subtle, #0b120e24)"},children:[e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",paddingTop:"12px",paddingBottom:"12px",paddingLeft:"16px",paddingRight:"16px",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)"},children:[e.jsxs(k.Text,{fontSize:"sm",fontWeight:"semibold",color:"gray-700",children:["Filter ",t]}),b.length>0&&e.jsx(u.Box,{direction:"column",style:{cursor:"pointer"},children:e.jsx(k.Text,{fontSize:"xs",color:"primary",fontWeight:"semibold",onClick:x=>{x.stopPropagation(),B()},children:"CLEAR"})})]}),!r.hideSearch&&e.jsx(u.Box,{direction:"column",style:{paddingLeft:"16px",paddingRight:"16px",paddingTop:"8px",paddingBottom:"8px"},children:e.jsx(Xe.Input,{ref:s,placeholder:`Search ${t.toLowerCase()}...`,leftIcon:e.jsx(T.Icon,{name:"Search",size:"sm"}),value:i,onChange:x=>a(x.target.value),style:{fontSize:"14px"}})}),e.jsx(u.Box,{direction:"column",className:"ts-filter-dropdown-options",style:{overflowY:"auto",maxHeight:"250px",paddingLeft:"8px",paddingRight:"8px"},children:r.isLoadingOptions?e.jsxs(u.Box,{style:{paddingTop:"40px",paddingBottom:"40px",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column"},children:[e.jsx(T.Icon,{name:"Loading",size:"lg",style:{color:"var(--sa-background-brand, #04254f)",animation:"spin 1s linear infinite"}}),e.jsx(k.Text,{fontSize:"sm",color:"gray-500",style:{textAlign:"center",marginTop:"8px"},children:"Loading options..."})]}):p.length>0?e.jsx(u.Box,{direction:"column",style:{gap:"2px",paddingTop:"4px",paddingBottom:"4px"},children:p.map(x=>e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"8px",paddingTop:"8px",paddingBottom:"8px",paddingLeft:"8px",paddingRight:"8px",cursor:"pointer",borderRadius:"8px",transition:"all 0.2s ease",backgroundColor:b.includes(x.value)?"var(--sa-color-brand-50, #e6edf6)":"transparent"},onClick:L=>{L.stopPropagation(),v(x.value)},onMouseEnter:L=>{b.includes(x.value)||(L.currentTarget.style.backgroundColor="var(--sa-background-primary, #ffffff)"),L.currentTarget.style.transform="translateX(2px)"},onMouseLeave:L=>{L.currentTarget.style.backgroundColor=b.includes(x.value)?"var(--sa-color-brand-50, #e6edf6)":"transparent",L.currentTarget.style.transform="translateX(0)"},children:[e.jsx(Ze.Checkbox,{checked:b.includes(x.value),onChange:()=>{}}),e.jsx(k.Text,{fontSize:"sm",fontWeight:b.includes(x.value)?"medium":"normal",color:b.includes(x.value)?"primary":"gray-700",children:x.label})]},x.value))}):e.jsxs(u.Box,{style:{paddingTop:"40px",paddingBottom:"40px",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column"},children:[e.jsx(T.Icon,{name:"Search",size:"lg",style:{color:"var(--sa-text-subtle, #8c8f97)"}}),e.jsx(k.Text,{fontSize:"sm",color:"gray-500",style:{textAlign:"center",marginTop:"8px"},children:"No results found"})]})}),b.length>0&&e.jsx(u.Box,{direction:"column",style:{paddingTop:"8px",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"16px",borderTop:"1px solid var(--sa-border-subtle, #0b120e24)",backgroundColor:"var(--sa-color-brand-50, #e6edf6)",marginTop:"auto"},children:e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"4px"},children:[e.jsx(u.Box,{direction:"column",style:{backgroundColor:"var(--sa-background-brand, #04254f)",borderRadius:"12px",padding:"2px 8px",fontSize:"11px",fontWeight:600,color:"white"},children:b.length}),e.jsxs(k.Text,{fontSize:"xs",color:"primary",fontWeight:"medium",children:["item",b.length>1?"s":""," selected"]})]})})]})]})},Ln=({direction:r})=>{const t="var(--sa-text-primary, #292a2e)",o="var(--sa-text-subtle, #8c8f97)",n=r==="asc"?t:o,l=r==="desc"?t:o,c=r==="asc"?1:.45,s=r==="desc"?1:.45;return e.jsxs("span",{style:{display:"inline-flex",flexDirection:"column",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:0},"aria-hidden":!0,children:[e.jsx("svg",{width:"8",height:"5",viewBox:"0 0 8 5",style:{color:n,opacity:c,marginBottom:1},children:e.jsx("path",{d:"M4 0 L8 5 L0 5 Z",fill:"currentColor"})}),e.jsx("svg",{width:"8",height:"5",viewBox:"0 0 8 5",style:{color:l,opacity:s},children:e.jsx("path",{d:"M0 0 L8 0 L4 5 Z",fill:"currentColor"})})]})},Tn=({frozen:r})=>e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:r?"currentColor":"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:r?"M7 11V7a5 5 0 0 1 10 0v4":"M7 11V7a5 5 0 0 1 9.9-1"})]}),ht="var(--sa-background-primary, #ffffff)",No="var(--sa-background-primary-inverse, #f8f8f8)",_o=({columns:r,records:t,handleDetail:o,handleUpdate:n,handleDelete:l,isLoading:c,visibleHandleDelete:s,visibleHandleUpdate:i,visibleHandleDetail:a,showHeadBorder:d=!1,scrollParentRef:y,frozenCount:b=0,onFrozenCountChange:p,customActions:v,actionsOrder:B=["detail","update","delete","custom"],customEmptyState:x,enableColumnResize:L=!1,defaultColumnWidths:F,onColumnWidthsChange:A,defaultMinColumnWidth:D=60,sort:m,defaultSort:H,onSortChange:z,showActionDivider:I=!1})=>{const E=m!==void 0,[U,X]=h.useState(H??null),G=E?m??null:U,R=P=>{if(P.sortKey)return P.sortKey;if(typeof P.accessor=="string")return P.accessor},_=P=>{const S=R(P);if(!S)return;let O;!G||G.key!==S?O={key:S,direction:"asc"}:G.direction==="asc"?O={key:S,direction:"desc"}:O=null,E||X(O),z==null||z(O)},te=[o,n,l].filter(P=>P!==void 0).length,q=!!v,j=!!o||!!n||!!l||q,Z="var(--sa-border-subtle, #0b120e24)",le=`1px solid ${Z}`,Ce=`inset 1px 0 0 ${Z}`,ve=`inset -1px 0 0 ${Z}`,he=te===3?q?"178px":"140px":te===2?q?"140px":"102px":te===1?q?"112px":"74px":q?"74px":"",ge=(P,S)=>{if(!S)return P;if(typeof S=="function")return S(P);if(typeof S=="string")return P[S]},[xe,Ee]=h.useState(!1);h.useEffect(()=>{if(!(y!=null&&y.current))return;const P=y.current;Ee(P.scrollHeight>P.clientHeight)},[t,y]);const Oe=h.useRef(null),[Ve,Pe]=h.useState([]),[ke,je]=h.useState(()=>F??{}),we=h.useRef(null);h.useLayoutEffect(()=>{if(!b||!Oe.current){Pe([]);return}const P=Array.from(Oe.current.querySelectorAll("thead tr th")),S=[];let O=0;P.forEach((V,J)=>{S[J]=O,J<b&&(O+=V.offsetWidth)}),Pe(S)},[b,r,t,ke]);const $e=P=>{p&&p(P<b?P:P+1)},De=(P,S)=>{const O=ke[P];if(O!==void 0){const V=`${O}px`;return{width:V,minWidth:V,maxWidth:V}}return S?{width:S}:{}},Ne=P=>L&&(P.resizable??!0),dr=(P,S)=>{P.preventDefault(),P.stopPropagation();const O=P.currentTarget.closest("th");if(!O)return;const V=Math.round(O.getBoundingClientRect().width);we.current={colIndex:S,startX:P.clientX,startWidth:V};const J=document.body.style.userSelect,de=document.body.style.cursor;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const Me=oe=>{var Ke;const pe=we.current;if(!pe)return;const Le=((Ke=r[pe.colIndex])==null?void 0:Ke.minWidth)??D,Se=Math.max(Le,pe.startWidth+(oe.clientX-pe.startX));je(Re=>Re[pe.colIndex]===Se?Re:{...Re,[pe.colIndex]:Se})},fe=()=>{document.removeEventListener("mousemove",Me),document.removeEventListener("mouseup",fe),document.body.style.userSelect=J,document.body.style.cursor=de,we.current=null,A&&je(oe=>(A(oe),oe))};document.addEventListener("mousemove",Me),document.addEventListener("mouseup",fe)};return e.jsx("div",{ref:Oe,children:e.jsxs(Q.Table,{fullWidth:!0,children:[e.jsx(Q.Thead,{style:{height:"40px",whiteSpace:"nowrap"},children:e.jsxs(Q.Tr,{children:[r.map((P,S)=>{var Zr,hr;const O=b>0&&S<b,V=Ve[S]??0,J=Ne(P),Me=S===r.length-1&&j&&I,fe=R(P),oe=!!P.sortable&&!!fe,pe=oe&&(G==null?void 0:G.key)===fe?G.direction:null,Le=P.title||((Zr=P.accessor)==null?void 0:Zr.toString())||"",Se=(hr=P.headerTooltip)!=null&&hr.showIcon?e.jsx(T.Icon,{name:"InfoCircle",size:"xs",style:{flexShrink:0,color:"var(--sa-icon-subtle, #8c8f97)",opacity:.75}}):null,Ke=e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Le}),Re=oe?e.jsxs("button",{type:"button",onClick:()=>_(P),title:pe==="asc"?"Sorted ascending — click to sort descending":pe==="desc"?"Sorted descending — click to clear":"Click to sort ascending",style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:4,background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",cursor:"pointer",textAlign:P.textAlign==="text-right"?"right":P.textAlign==="text-center"?"center":"left"},children:[Ke,Se,e.jsx(Ln,{direction:pe})]}):e.jsxs("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:4},children:[Ke,Se]});return e.jsxs(Q.Th,{style:{position:"sticky",top:0,left:O?V:void 0,zIndex:O?4:2,paddingLeft:S===0?"12px":"",borderRight:d&&!Me&&!O?le:void 0,borderBottom:d?le:void 0,boxShadow:d&&O?ve:void 0,backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",textAlign:P.textAlign==="text-right"?"right":P.textAlign==="text-center"?"center":"left",...De(S,P.width)},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",justifyContent:"space-between",minWidth:0},children:[P.headerTooltip?e.jsx(Be.Tooltip,{label:P.headerTooltip.content,position:"bottom",children:Re}):Re,P.filter&&e.jsx(jo,{filter:P.filter,columnTitle:P.title}),p&&e.jsx("button",{onClick:()=>$e(S),title:O?"Unfreeze column":"Freeze column",style:{background:"none",border:"none",cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",flexShrink:0,color:O?"var(--sa-background-brand, #04254f)":"var(--sa-text-subtle, #8c8f97)",opacity:O?1:.45,transition:"opacity 0.15s"},children:e.jsx(Tn,{frozen:O})})]}),J&&e.jsx("div",{onMouseDown:wr=>dr(wr,S),onClick:wr=>wr.stopPropagation(),role:"separator","aria-orientation":"vertical",title:"Drag to resize",style:{position:"absolute",top:0,right:-3,width:6,height:"100%",cursor:"col-resize",userSelect:"none",zIndex:5,touchAction:"none"}})]},`table-head-${S}`)}),j?e.jsx(Q.Th,{style:{backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",position:"sticky",top:0,right:0,zIndex:3,borderBottom:d?le:void 0,boxShadow:d&&I?Ce:void 0}}):null]})}),e.jsx(Q.Tbody,{children:c?e.jsx(Q.Tr,{children:e.jsx(Q.Td,{colSpan:r.length+1,children:e.jsxs(u.Box,{direction:"column",style:{gap:"16px"},children:[e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"})]})})}):!(t!=null&&t.length)&&x?e.jsx(Q.Tr,{children:e.jsx(Q.Td,{colSpan:r.length+1,children:x})}):t==null?void 0:t.map((P,S)=>e.jsxs(Q.Tr,{style:{transition:"background-color 0.3s ease",padding:0,borderBottom:S===t.length-1&&xe?void 0:"1px solid var(--sa-border-subtle, #0b120e24)"},onMouseEnter:O=>{const V=O.currentTarget;V.style.backgroundColor=No,Array.from(V.querySelectorAll("td")).forEach(J=>{J.style.position==="sticky"&&(J.style.backgroundColor=No)})},onMouseLeave:O=>{const V=O.currentTarget;V.style.backgroundColor="",Array.from(V.querySelectorAll("td")).forEach(J=>{J.style.position==="sticky"&&(J.style.backgroundColor=ht)})},children:[r.map((O,V)=>{const J=O.render?O.render(P,S,t):ge(P,O.accessor),de=b>0&&V<b,Me=Ve[V]??0,fe=ke[V]!==void 0,oe=de&&V===b-1;return e.jsx(Q.Td,{style:{position:de?"sticky":void 0,left:de?Me:void 0,zIndex:de?1:void 0,backgroundColor:de?ht:void 0,transition:de?"background-color 0.3s ease":void 0,paddingLeft:V===0?"12px":"",whiteSpace:"nowrap",overflow:fe?"hidden":void 0,borderLeft:O.showBorderLeft?le:void 0,borderRight:O.showBorderRight?le:void 0,boxShadow:oe?ve:void 0,textAlign:O.textAlign==="text-right"?"right":O.textAlign==="text-center"?"center":"left",...De(V,O.width)},children:typeof J=="string"?e.jsx(k.Text,{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",textAlign:O.textAlign==="text-right"?"right":O.textAlign==="text-center"?"center":"left"},children:J}):J},`row-${S}-col-${V}`)}),j?e.jsx(Q.Td,{style:{width:he,position:"sticky",right:0,zIndex:1,backgroundColor:ht,boxShadow:I?Ce:void 0,transition:"background-color 0.3s ease"},children:e.jsx(ne.Flex,{direction:"row",align:"center",justify:"center",gap:"sm",children:B.map(O=>{const V=S===t.length-1?"top":"bottom";return O==="detail"&&o&&(a==null?void 0:a(P))!==!1?e.jsx(Be.Tooltip,{label:"Detail",position:V,children:e.jsx(N.Button,{size:"xs",variant:"outline",tone:"neutral",onClick:()=>o(P.id,P),iconLeft:e.jsx(T.Icon,{name:"DocumentClean",size:"sm",style:{color:"var(--sa-text-subtle, #8c8f97)"}})})},"detail"):O==="update"&&n&&(i==null?void 0:i(P))!==!1?e.jsx(Be.Tooltip,{label:"Update",position:V,children:e.jsx(N.Button,{size:"xs",variant:"outline",tone:"neutral",onClick:()=>n(P),iconLeft:e.jsx(T.Icon,{name:"Edit1",size:"sm",style:{color:"var(--sa-text-subtle, #8c8f97)"}})})},"update"):O==="delete"&&l&&(s==null?void 0:s(P))!==!1?e.jsx(Be.Tooltip,{label:"Delete",position:V,children:e.jsx(N.Button,{size:"xs",variant:"outline",tone:"neutral",onClick:()=>l(P.id,P),iconLeft:e.jsx(T.Icon,{name:"Trash1",size:"sm",style:{color:"var(--sa-color-error-600, #c9184a)"}})})},"delete"):O==="custom"?e.jsx(h.Fragment,{children:v==null?void 0:v(P)},"custom"):null})})}):null]},`${P}${S}`))})]})})},In=({wrapperProps:r,dataTableProps:t,headerProps:o,footerProps:n})=>{var b;const l=h.useRef(null),[c,s]=h.useState((t==null?void 0:t.defaultFrozenCount)??0),i=(o==null?void 0:o.show)??!0,a=h.useRef(null),d=(b=t==null?void 0:t.pagination)==null?void 0:b.totalData;typeof d=="number"&&(a.current=d);const y=(n==null?void 0:n.showFooter)??(d===void 0?a.current!==0:d!==0);return e.jsxs(Ho,{...r,children:[i&&e.jsx(Vo,{...o}),e.jsx(u.Box,{direction:"column",ref:l,style:{flex:1,overflowY:"auto",overflowX:"auto"},children:t?e.jsx(_o,{...t,scrollParentRef:l,frozenCount:t!=null&&t.enableFreezeColumns?c:0,onFrozenCountChange:t!=null&&t.enableFreezeColumns?s:void 0}):null}),y&&e.jsx(Po,{pagination:t==null?void 0:t.pagination,pageKey:t==null?void 0:t.pageKey,perPageKey:t==null?void 0:t.perPageKey,defaultPerPage:t==null?void 0:t.defaultPerPage,showPagination:t==null?void 0:t.showPagination,totalData:n==null?void 0:n.totalData})]})};function On(r){return h.memo(r)}const Wn=On(In),qo=200,ft="1px solid var(--sa-border-subtle, #0b120e24)",An=({sortDir:r,frozen:t})=>r==="asc"?e.jsx(T.Icon,{name:"ChevronSmallUp"}):r==="desc"?e.jsx(T.Icon,{name:"ChevronSmallDown"}):t?e.jsx(T.Icon,{name:"LockOn",size:"xs"}):e.jsx(T.Icon,{name:"Filter",size:"xs"}),Ar=({icon:r,label:t,active:o,danger:n,onClick:l})=>{const c=n?"var(--sa-text-error, #a4133c)":"var(--sa-text-primary, #292a2e)";return e.jsxs("button",{type:"button",onClick:l,style:{display:"flex",alignItems:"center",gap:12,width:"100%",padding:"8px 12px",background:o?"var(--sa-background-brand-subtlest, #e6edf6)":"none",border:"none",cursor:"pointer",font:"inherit",color:c,textAlign:"left"},onMouseEnter:s=>{o||(s.currentTarget.style.background="var(--sa-background-primary-inverse, #f8f8f8)")},onMouseLeave:s=>{s.currentTarget.style.background=o?"var(--sa-background-brand-subtlest, #e6edf6)":"none"},children:[e.jsx(T.Icon,{name:r,size:"sm",style:{color:c,flexShrink:0}}),e.jsx(k.Text,{as:"span",style:{color:c},children:t})]})},Zo=({active:r,canSort:t,canHide:o,sortDir:n,frozen:l,onSort:c,onClearSort:s,onToggleFreeze:i,onHide:a})=>{const[d,y]=h.useState(!1),b=h.useRef(null),p=h.useRef(null),[v,B]=h.useState({top:0,left:0});h.useEffect(()=>{if(d&&b.current){const L=b.current.getBoundingClientRect(),F=L.left+qo>window.innerWidth;B({top:L.bottom+6,...F?{right:window.innerWidth-L.right}:{left:L.left}})}},[d]),h.useEffect(()=>{if(!d)return;const L=F=>{p.current&&!p.current.contains(F.target)&&b.current&&!b.current.contains(F.target)&&y(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[d]);const x=L=>{L(),y(!1)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:b,type:"button",className:"sa-tl-menu-trigger","data-active":r||d?"true":"false",onClick:L=>{L.stopPropagation(),y(F=>!F)},title:"Column options",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,borderRadius:"var(--sa-radii-sm, 6px)",border:ft,background:"var(--sa-background-primary, #ffffff)",cursor:"pointer",color:"var(--sa-text-subtle, #8c8f97)",flexShrink:0},children:e.jsx(An,{sortDir:n,frozen:l})}),d&&e.jsxs(u.Box,{ref:p,onClick:L=>L.stopPropagation(),style:{position:"fixed",top:`${v.top}px`,...v.left!==void 0?{left:`${v.left}px`}:{right:`${v.right}px`},minWidth:qo,backgroundColor:"var(--sa-background-primary, #ffffff)",border:ft,borderRadius:"var(--sa-radii-sm, 6px)",boxShadow:"var(--sa-shadow-xl, 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a)",zIndex:9999,padding:"4px",display:"flex",flexDirection:"column"},children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(Ar,{icon:"ChevronUp",label:"Ascending",active:n==="asc",onClick:()=>x(()=>n==="asc"?s():c("asc"))}),e.jsx(Ar,{icon:"ChevronDown",label:"Descending",active:n==="desc",onClick:()=>x(()=>n==="desc"?s():c("desc"))}),e.jsx("div",{style:{borderTop:ft,margin:"4px 0"}})]}),e.jsx(Ar,{icon:"Pin1",label:l?"Unfreeze":"Freeze",active:l,onClick:()=>x(i)}),o&&e.jsx(Ar,{icon:"EyeClosed",label:"Hide column",danger:!0,onClick:()=>x(a)})]})]})},br="1px solid var(--sa-border-subtle, #0b120e24)",zn="var(--sa-text-subtle, #8c8f97)",ar="var(--sa-background-neutral, #f0f1f2)",Go="2px 0 4px -2px var(--sa-border-subtle, #0b120e24)",Cr=40,gt="var(--sa-background-brand-subtlest)",zr={display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Qo="sa-table-layout-styles",Hn=()=>{if(typeof document>"u"||document.getElementById(Qo))return;const r=document.createElement("style");r.id=Qo,r.textContent=`
|
|
1
|
+
(function(g,tr){typeof exports=="object"&&typeof module<"u"?tr(exports,require("@starasia/alert"),require("@starasia/badges"),require("@starasia/box"),require("@starasia/breadcrumb"),require("@starasia/button"),require("@starasia/card"),require("@starasia/date"),require("@starasia/dialog"),require("@starasia/drawer"),require("@starasia/dropdown"),require("@starasia/hooks"),require("@starasia/http"),require("@starasia/input"),require("@starasia/menu"),require("@starasia/pagination"),require("@starasia/storage"),require("@starasia/table"),require("@starasia/tabs"),require("@starasia/textarea"),require("@starasia/theme"),require("@starasia/toast"),require("@starasia/toggle"),require("@starasia/tooltip"),require("@starasia/checkbox"),require("@starasia/radio"),require("@starasia/text"),require("@starasia/icon"),require("@starasia/flex"),require("@starasia/grid"),require("@starasia/progress"),require("@starasia/stepper"),require("@starasia/accordion"),require("@starasia/story-record"),require("@starasia/skeleton"),require("@starasia/progress-stepper"),require("react/jsx-runtime"),require("react"),require("react-dom"),require("react-easy-crop")):typeof define=="function"&&define.amd?define(["exports","@starasia/alert","@starasia/badges","@starasia/box","@starasia/breadcrumb","@starasia/button","@starasia/card","@starasia/date","@starasia/dialog","@starasia/drawer","@starasia/dropdown","@starasia/hooks","@starasia/http","@starasia/input","@starasia/menu","@starasia/pagination","@starasia/storage","@starasia/table","@starasia/tabs","@starasia/textarea","@starasia/theme","@starasia/toast","@starasia/toggle","@starasia/tooltip","@starasia/checkbox","@starasia/radio","@starasia/text","@starasia/icon","@starasia/flex","@starasia/grid","@starasia/progress","@starasia/stepper","@starasia/accordion","@starasia/story-record","@starasia/skeleton","@starasia/progress-stepper","react/jsx-runtime","react","react-dom","react-easy-crop"],tr):(g=typeof globalThis<"u"?globalThis:g||self,tr(g["@starasia/admin"]={},g.alert,g.badges,g.box,g.breadcrumb,g.button,g.card,g.date,g.dialog,g.drawer,g.dropdown,g.hooks,g.http,g.input,g.menu,g.pagination,g.storage,g.table,g.tabs,g.textarea,g.theme,g.toast,g.toggle,g.tooltip,g.checkbox,g.radio,g.text,g.icon,g.flex,g.grid,g.progress,g.stepper,g.accordion,g.storyRecord,g.skeleton,g.progressStepper,g.jsxRuntime,g.React,g.ReactDOM,g.ReactEasyCrop))})(this,function(g,tr,Ye,u,or,N,It,er,Ae,kr,lr,be,nr,Xe,W,gr,ur,Q,Ot,Jr,cr,Wt,sr,Be,Ze,Yr,k,T,ne,At,zt,Ht,Vt,Pt,ze,jt,e,h,Br,bl){"use strict";const Cl={menus:[],menuBottom:void 0,logo:"",appName:"Workspace",userData:null,setUserData:()=>{}},Xr=h.createContext(Cl),$r=()=>h.useContext(Xr),Nt=r=>{const[t,o]=h.useState((r==null?void 0:r.initialUserData)||null);return{userData:t,setUserData:o}},_t=h.createContext({badges:{},setBadge:()=>{},setBadges:()=>{},clearBadge:()=>{}}),qt=({children:r})=>{const[t,o]=h.useState({}),n=h.useCallback(i=>{o(a=>typeof i=="function"?i(a):i)},[]),l=h.useCallback((i,a)=>{o(d=>{const y=typeof a=="function"?a(d[i]):a;return{...d,[i]:y}})},[]),c=h.useCallback(i=>{o(a=>{if(!(i in a))return a;const d={...a};return delete d[i],d})},[]),s=h.useMemo(()=>({badges:t,setBadge:l,setBadges:n,clearBadge:c}),[t,l,n,c]);return e.jsx(_t.Provider,{value:s,children:r})},Zt=()=>h.useContext(_t),mr=(r,t)=>{const o=t!==void 0?t:r;return o==null?null:typeof o=="string"||typeof o=="number"?{value:o}:o},Gt=h.createContext({collapsed:!1,setCollapsed:()=>{},toggle:()=>{},collapse:()=>{},expand:()=>{},mobileOpen:!1,setMobileOpen:()=>{},openMobile:()=>{},closeMobile:()=>{},toggleMobile:()=>{}}),Qt=({children:r,defaultCollapsed:t=!1})=>{const[o,n]=h.useState(t),[l,c]=h.useState(!1),s=h.useCallback(x=>{n(L=>typeof x=="function"?x(L):x)},[]),i=h.useCallback(()=>n(x=>!x),[]),a=h.useCallback(()=>n(!0),[]),d=h.useCallback(()=>n(!1),[]),y=h.useCallback(x=>{c(L=>typeof x=="function"?x(L):x)},[]),b=h.useCallback(()=>c(!0),[]),p=h.useCallback(()=>c(!1),[]),v=h.useCallback(()=>c(x=>!x),[]),B=h.useMemo(()=>({collapsed:o,setCollapsed:s,toggle:i,collapse:a,expand:d,mobileOpen:l,setMobileOpen:y,openMobile:b,closeMobile:p,toggleMobile:v}),[o,s,i,a,d,l,y,b,p,v]);return e.jsx(Gt.Provider,{value:B,children:r})},Ut=()=>h.useContext(Gt),Jt=h.createContext(null),Yt=({adapter:r,children:t})=>e.jsx(Jt.Provider,{value:r,children:t}),Ge=()=>{const r=h.useContext(Jt);if(!r)throw new Error("[@starasia/admin] Router adapter belum dipasang. Bungkus aplikasi dengan <App routerAdapter={...} /> atau <StarasiaRouterProvider adapter={...}>. Import adapter dari '@starasia/admin/adapters/react-router' atau '@starasia/admin/adapters/tanstack'.");return r},Xt=({router:r,routerAdapter:t,menus:o=[],menuBottom:n,logo:l,appName:c="Workspace",initialUserData:s,theme:i})=>{const a=Nt({initialUserData:s}),{theme:d}=cr.useTheme();return e.jsx(Yt,{adapter:t,children:e.jsx(Xr.Provider,{value:{logo:l,appName:c,menus:o,userData:a.userData,setUserData:a.setUserData,menuBottom:n},children:e.jsx(qt,{children:e.jsx(Qt,{children:i?e.jsx(cr.ThemeProvider,{value:i,children:r}):d?e.jsx(cr.ThemeProvider,{value:d,children:r}):r})})})})},vl=h.memo(Xt);function $t({collapsed:r=!1,children:t}){if(!t)return null;const o=typeof t=="function",n=o?t({collapsed:r}):t;return n==null||n===!1?null:e.jsx("div",{style:{position:"sticky",top:"4rem",zIndex:1,borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",paddingLeft:"0.5rem",paddingRight:"0.5rem",paddingTop:"0.5rem",paddingBottom:"0.5rem",boxSizing:"border-box"},children:o?n:e.jsx("div",{style:{opacity:r?0:1,transition:"opacity 0.3s",visibility:r?"hidden":"visible"},children:n})})}const Kr=h.createContext(null);function Kt({children:r}){const[t,o]=h.useState(null),[n,l]=h.useState(null),[c,s]=h.useState(null),[i,a]=h.useState(0),d=h.useCallback(()=>(a(y=>y+1),()=>a(y=>y-1)),[]);return e.jsx(Kr.Provider,{value:{prependNode:t,appendNode:n,replaceNode:c,setPrependNode:o,setAppendNode:l,setReplaceNode:s,replaceCount:i,registerReplace:d},children:r})}function Rt({children:r}){const t=h.useContext(Kr);return t?e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:t.setPrependNode,style:{display:"contents"}}),t.replaceCount>0?e.jsx("div",{ref:t.setReplaceNode,style:{display:"contents"}}):r,e.jsx("div",{ref:t.setAppendNode,style:{display:"contents"}})]}):e.jsx(e.Fragment,{children:r})}function xl({children:r,mode:t="append"}){const o=h.useContext(Kr);if(h.useEffect(()=>{if(!(t!=="replace"||!o))return o.registerReplace()},[t,o]),!o)return process.env.NODE_ENV!=="production"&&console.warn("[HeaderLeftSlot] used outside AppLayout — content not rendered"),null;const n=t==="prepend"?o.prependNode:t==="replace"?o.replaceNode:o.appendNode;return n?Br.createPortal(r,n):null}const Rr=h.createContext(null);function eo({children:r}){const[t,o]=h.useState({}),[n,l]=h.useState({}),c=h.useCallback((a,d)=>{o(y=>y[a]===d?y:{...y,[a]:d})},[]),s=h.useCallback(a=>(l(d=>({...d,[a]:(d[a]??0)+1})),()=>l(d=>({...d,[a]:Math.max(0,(d[a]??0)-1)}))),[]),i=h.useMemo(()=>({outletNodes:t,setOutletNode:c,slotCounts:n,registerSlot:s}),[t,c,n,s]);return e.jsx(Rr.Provider,{value:i,children:r})}function ro({slotKey:r,fallback:t}){const o=h.useContext(Rr),n=o?(o.slotCounts[r]??0)>0:!1,l=h.useRef(o==null?void 0:o.setOutletNode);l.current=o==null?void 0:o.setOutletNode;const c=h.useCallback(s=>{var i;return(i=l.current)==null?void 0:i.call(l,r,s)},[r]);return e.jsx(e.Fragment,{children:n?e.jsx("div",{ref:c,style:{display:"contents"}}):t})}function wl({slotKey:r,children:t}){const o=h.useContext(Rr),n=h.useRef(o==null?void 0:o.registerSlot);if(n.current=o==null?void 0:o.registerSlot,h.useEffect(()=>{var c;return(c=n.current)==null?void 0:c.call(n,r)},[r]),!o)return process.env.NODE_ENV!=="production"&&console.warn("[SidebarGroupSlot] used outside AppLayout — content not rendered"),null;const l=o.outletNodes[r];return l?Br.createPortal(t,l):null}const Fr="moduleSwitcherGroupId",et="sa-module-switcher-change";function to(){if(typeof window>"u")return null;const r=window.localStorage.getItem(Fr);if(r===null)return null;const t=Number(r);return Number.isFinite(t)?t:null}function oo(r){typeof window>"u"||(r===null?window.localStorage.removeItem(Fr):window.localStorage.setItem(Fr,String(r)),window.dispatchEvent(new CustomEvent(et,{detail:r})))}function Dl(){oo(null)}function rt(){const[r,t]=h.useState(()=>to());return h.useEffect(()=>{const n=()=>{t(to())},l=c=>{c.key===Fr&&n()};return window.addEventListener(et,n),window.addEventListener("storage",l),()=>{window.removeEventListener(et,n),window.removeEventListener("storage",l)}},[]),{selectedGroupId:r,setSelectedGroupId:n=>{oo(n),t(n)}}}let Er=0,rr=!1,lo=new Set;const no=()=>e.jsxs("svg",{width:"100%",height:"100%",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"1.667",y:"1.667",width:"12.667",height:"12.667",rx:"2"}),e.jsx("line",{x1:"6",y1:"1.667",x2:"6",y2:"14.333"})]});function Sl(r){const[t,o]=h.useState(!1),n=h.useRef(null),l=h.useRef(null);return h.useLayoutEffect(()=>{const c=n.current;if(!c)return;let s=0;const i=()=>{s=0;const d=l.current;if(!d)return;const y=d.scrollWidth>c.clientWidth;o(b=>b===y?b:y)},a=new ResizeObserver(()=>{s||(s=requestAnimationFrame(i))});return a.observe(c),i(),()=>{s&&cancelAnimationFrame(s),a.disconnect()}},[r]),{containerRef:n,textRef:l,truncated:t}}function co({text:r,textStyle:t}){const{containerRef:o,textRef:n,truncated:l}=Sl(r),c=e.jsx("span",{ref:n,style:{display:"block",fontSize:"0.875rem",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",...t},children:r});return e.jsx("div",{ref:o,style:{flex:1,minWidth:0},children:l?e.jsx(Be.Tooltip,{fluid:!0,label:r,position:"top",children:c}):c})}const so={width:"100%",display:"flex",alignItems:"center",gap:"0.75rem",paddingLeft:"0.75rem",paddingRight:"0.75rem",paddingTop:"0.5rem",paddingBottom:"0.5rem",fontSize:"0.875rem",color:"var(--sa-text-subtle, #8c8f97)",background:"transparent",border:"none",borderRadius:"0.375rem",cursor:"pointer",textAlign:"left"};function kl({children:r,headerLeftSlot:t,profile:o,isLoadingProfile:n,onLogout:l,isLoggingOut:c,loadingComponent:s,sidebarHeaderContent:i,headerActions:a,profileRole:d,profileMenuButtons:y,profileMenuItems:b,logoutButton:p}){var dr,P;const{useSearchParams:v,useNavigate:B,useLocation:x,Outlet:L}=Ge(),[F]=v(),A=F.get("embed")==="true",D=$r(),{badges:m}=Zt(),H=B(),z=x(),E=!be.useMediaQuery("md"),[U,X]=h.useState(!1),{collapsed:G,setCollapsed:R,mobileOpen:_,setMobileOpen:K}=Ut(),[te,q]=h.useState(!1),[j,Z]=h.useState(()=>new Set(lo)),[le,Ce]=h.useState(null),{selectedGroupId:ve,setSelectedGroupId:he}=rt();h.useEffect(()=>{lo=j},[j]);const ge=h.useRef(null),xe=h.useRef(null);h.useEffect(()=>{const S=ge.current;if(!S)return;const O=()=>{rr||(Er=S.scrollTop)};return S.addEventListener("scroll",O),()=>S.removeEventListener("scroll",O)},[]);const Ee=()=>{const S=ge.current;S&&Er>0&&(rr=!0,S.scrollTop=Er,requestAnimationFrame(()=>{rr=!1}))};h.useLayoutEffect(()=>{rr=!0,Ee();const S=setTimeout(()=>{rr=!1},300);return()=>clearTimeout(S)},[]),h.useLayoutEffect(()=>{D.menus.length>0&&(Er>0?Ee():requestAnimationFrame(()=>{var O;const S=(O=ge.current)==null?void 0:O.querySelector("[data-menu-active='true']");S&&S.scrollIntoView({block:"center",behavior:"instant"})}))},[D.menus]),h.useEffect(()=>{rr=!0,Ee();const S=setTimeout(Ee,0),O=setTimeout(Ee,50),V=setTimeout(Ee,100),J=setTimeout(Ee,200),de=setTimeout(()=>{rr=!1},300),Me=setTimeout(()=>{const fe=ge.current,oe=fe==null?void 0:fe.querySelector("[data-menu-active='true']");if(fe&&oe){const pe=fe.getBoundingClientRect(),Le=oe.getBoundingClientRect();Le.top>=pe.top&&Le.bottom<=pe.bottom||oe.scrollIntoView({block:"center",behavior:"smooth"})}},250);return()=>{clearTimeout(S),clearTimeout(O),clearTimeout(V),clearTimeout(J),clearTimeout(de),clearTimeout(Me)}},[z.pathname]),h.useEffect(()=>{xe.current&&(xe.current.scrollTop=0)},[z.pathname]),h.useEffect(()=>{E&&K(!1)},[z.pathname,E]),h.useEffect(()=>{E&&R(!0)},[E]);const Oe=()=>{X(!0)},Ve=()=>{X(!1)},Pe=()=>{X(!1),l()},ke=S=>{const O=[S.to];return S.children&&O.push(...S.children.map(V=>V.to)),O},je=[...D.menus.flatMap(S=>S.items.flatMap(ke)),...((dr=D.menuBottom)==null?void 0:dr.flatMap(ke))??[]],we=S=>{if(!z.pathname.startsWith(S))return!1;const O=je.filter(V=>z.pathname.startsWith(V)).sort((V,J)=>J.length-V.length)[0];return S===O};h.useEffect(()=>{var O;const S=V=>{var J;(J=V.children)!=null&&J.some(de=>z.pathname.startsWith(de.to))&&Z(de=>{const Me=new Set(de);return Me.add(V.id),Me})};D.menus.forEach(V=>{V.items.forEach(S)}),(O=D.menuBottom)==null||O.forEach(S)},[z.pathname,D.menus,D.menuBottom]);const $e=S=>{Z(O=>{const V=new Set(O);return V.has(S)?V.delete(S):V.add(S),V})};h.useEffect(()=>{D.menus.length!==0&&ve!==null&&!D.menus.some(S=>S.id===ve)&&he(null)},[D.menus,ve,he]);const De=h.useMemo(()=>{if(ve!==null)return D.menus.filter(V=>V.id===ve||V.parentGroupId===ve);const S=D.menus.filter(V=>V.parentGroupId===void 0),O=D.menus.filter(V=>V.parentGroupId!==void 0).flatMap(V=>V.items);return O.length===0?S:[...S,{id:18,name:"Pengaturan",items:O,parentGroupId:void 0}]},[D.menus,ve]);if(A)return e.jsx("main",{style:{height:"100vh",overflowY:"auto",backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)"},children:r||e.jsx(L,{})});const Ne=S=>{const O=S.children&&S.children.length>0,V=j.has(S.id),J=O?S.children.some(fe=>we(fe.to)):we(S.to),de=mr(S.badge,m[S.id]),Me=!!de&&G&&!E;return e.jsxs("div",{"data-menu-active":J||void 0,children:[e.jsxs("button",{onClick:fe=>{if(O)if(G&&!E){const oe=fe.currentTarget.getBoundingClientRect();Ce({item:S,top:oe.top,left:oe.right+8})}else $e(S.id);else H(S.to)},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:G&&!E?"center":void 0,gap:"0.5rem",paddingLeft:G&&!E?"0":"0.5rem",paddingRight:G&&!E?"0":"0.5rem",paddingTop:"0.25rem",paddingBottom:"0.25rem",height:"2rem",borderRadius:J?"var(--sa-radii-sm, 0.375rem)":"var(--sa-radii-md, 0.5rem)",textAlign:"left",border:J?"1px solid var(--sa-border-subtle, #0b120e24)":"1px solid transparent",backgroundColor:J?"var(--sa-background-primary, #ffffff)":"transparent",color:"var(--sa-text-primary, #292a2e)",cursor:"pointer"},title:G&&!E?S.title:void 0,onMouseEnter:fe=>{J||(fe.currentTarget.style.backgroundColor="var(--sa-background-neutral, #f0f1f2)")},onMouseLeave:fe=>{J||(fe.currentTarget.style.backgroundColor="transparent")},children:[e.jsxs("span",{style:{position:"relative",display:"inline-flex",flexShrink:0},children:[e.jsx(T.Icon,{name:S.icon,size:"sm",style:{flexShrink:0}}),Me&&e.jsx("span",{"aria-hidden":"true",style:{position:"absolute",top:"-2px",right:"-2px",width:"0.5rem",height:"0.5rem",borderRadius:"9999px",backgroundColor:"var(--sa-color-error-500, #ff4d6d)",border:"1px solid var(--sa-background-primary, #ffffff)"}})]}),(!G||E)&&e.jsxs(e.Fragment,{children:[e.jsx(co,{text:S.title,textStyle:{transition:"opacity 0.3s"}}),de&&e.jsx(Ye.Badges,{text:String(de.value),variant:de.variant??"info",size:"xs",border:!0}),O&&e.jsx("svg",{style:{width:"1rem",height:"1rem",flexShrink:0,transition:"transform 0.2s",transform:V?"rotate(180deg)":"rotate(0deg)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]}),O&&(!G||E)&&(()=>{const fe=S.children.findIndex(oe=>we(oe.to));return e.jsxs("div",{style:{position:"relative",marginLeft:"0.9375rem",paddingLeft:"1.125rem",overflow:"hidden",transition:"all 0.3s ease-in-out",maxHeight:V?`${S.children.length*36}px`:"0px",opacity:V?1:0,marginTop:V?"0.25rem":"0px"},children:[e.jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:0,top:0,width:"1.5px",height:"100%",backgroundColor:"var(--sa-border-subtle, #0b120e24)",pointerEvents:"none"}}),fe>=0&&e.jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:0,top:`${fe*32}px`,width:"1.5px",height:"32px",backgroundColor:"var(--sa-text-primary, #292a2e)",transition:"top 0.2s ease-in-out",pointerEvents:"none",zIndex:1}}),S.children.map(oe=>{const pe=mr(oe.badge,m[oe.id]);return e.jsxs("button",{onClick:()=>H(oe.to),style:{width:"100%",display:"flex",alignItems:"center",gap:"0.5rem",paddingLeft:"0.75rem",paddingRight:"0.5rem",paddingTop:"0.25rem",paddingBottom:"0.25rem",height:"2rem",borderRadius:we(oe.to)?"var(--sa-radii-sm, 0.375rem)":"var(--sa-radii-md, 0.5rem)",textAlign:"left",backgroundColor:we(oe.to)?"var(--sa-background-primary, #ffffff)":"transparent",color:we(oe.to)?"var(--sa-text-primary, #292a2e)":"var(--sa-text-subtle, #505258)",cursor:"pointer",border:we(oe.to)?"1px solid var(--sa-border-subtle, #0b120e24)":"1px solid transparent"},onMouseEnter:Le=>{we(oe.to)||(Le.currentTarget.style.backgroundColor="var(--sa-background-neutral, #f0f1f2)")},onMouseLeave:Le=>{we(oe.to)||(Le.currentTarget.style.backgroundColor="transparent")},children:[e.jsx(T.Icon,{name:oe.icon,size:"sm",style:{flexShrink:0}}),e.jsx(co,{text:oe.title}),pe&&e.jsx(Ye.Badges,{text:String(pe.value),variant:pe.variant??"info",size:"xs",border:!0})]},oe.id)})]})})()]},S.id)};return e.jsx(eo,{children:e.jsxs(Kt,{children:[e.jsxs("div",{style:{display:"flex",height:"100vh",position:"relative","--app-sidebar-width":E?"0px":G?"4.375rem":"16.375rem","--app-footer-zindex":E&&_?"40":"998"},children:[E&&e.jsx("div",{style:{position:"fixed",inset:0,backgroundColor:"var(--sa-color-black-alpha-a50, #181a198f)",zIndex:40,opacity:_?.5:0,pointerEvents:_?"auto":"none",transition:"opacity 0.3s"},onClick:()=>K(!1)}),e.jsxs("aside",{style:{width:E?"16.375rem":G?"4.375rem":"16.375rem",position:E?"fixed":"relative",...E&&{inset:0,zIndex:50,transform:_?"translateX(0)":"translateX(-100%)"},backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",borderRight:"1px solid var(--sa-border-subtle, #0b120e24)",display:"flex",flexDirection:"column",transition:"all 0.3s ease-in-out",flexShrink:E?void 0:0},children:[e.jsx("div",{onMouseEnter:()=>q(!0),onMouseLeave:()=>q(!1),style:{height:"4rem",display:"flex",alignItems:"center",justifyContent:"space-between",paddingLeft:"1rem",paddingRight:"1rem",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",position:"relative"},children:(()=>{const S=!E&&G&&!_,O=S&&te;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",flex:S?1:void 0,justifyContent:S?"center":void 0,transition:"opacity 0.2s",opacity:O?0:1,pointerEvents:O?"none":"auto"},children:[e.jsx("img",{src:D.logo,alt:"Logo",style:{width:"2rem",height:"2rem",flexShrink:0}}),(!G||_)&&e.jsx("span",{style:{fontWeight:"600",color:"var(--sa-text-primary, #292a2e)",whiteSpace:"nowrap",transition:"opacity 0.3s"},children:D.appName})]}),!E&&!G&&e.jsx("button",{type:"button",onClick:()=>R(!0),"aria-label":"Collapse sidebar",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1rem",height:"1rem",padding:0,background:"transparent",border:"none",color:"var(--sa-text-subtle, #8c8f97)",cursor:"pointer",flexShrink:0},children:e.jsx(no,{})}),S&&e.jsx("button",{type:"button",onClick:()=>R(!1),"aria-label":"Expand sidebar",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"2rem",height:"2rem",padding:0,background:"var(--sa-background-primary, #ffffff)",border:"1px solid var(--sa-border-subtle, #0b120e24)",borderRadius:"var(--sa-radii-sm, 0.375rem)",color:"var(--sa-text-primary, #292a2e)",cursor:"pointer",opacity:O?1:0,pointerEvents:O?"auto":"none",transition:"opacity 0.2s"},children:e.jsx("span",{style:{width:"1rem",height:"1rem",display:"inline-flex"},children:e.jsx(no,{})})}),E&&e.jsx("button",{onClick:()=>K(!1),"aria-label":"Close menu",style:{padding:"0.375rem",borderRadius:"0.5rem",backgroundColor:"transparent",border:"none",color:"var(--sa-text-subtle, #8c8f97)",cursor:"pointer"},children:e.jsx("svg",{style:{width:"1.25rem",height:"1.25rem"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})})()}),i&&e.jsx($t,{collapsed:E?!1:G,children:i}),e.jsx("div",{ref:ge,style:{flex:1,overflowY:"auto",paddingTop:"1rem",paddingBottom:"1rem"},children:De.map(S=>e.jsxs("div",{style:{marginBottom:"1rem"},children:[!G||E?S.name&&e.jsx("div",{style:{paddingLeft:"1.5rem",paddingRight:"1rem",paddingTop:"0rem",paddingBottom:"0.25rem",fontSize:"0.875rem",fontWeight:"400",color:"var(--sa-text-subtlest, #6b6e76)",transition:"opacity 0.3s",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:S.name}):S.name&&e.jsx("div",{"aria-label":S.name,style:{display:"flex",alignItems:"center",justifyContent:"center",paddingTop:"0.75rem",paddingBottom:"0.75rem"},children:e.jsx("span",{style:{display:"block",width:"1rem",height:"2px",borderRadius:"1px",backgroundColor:S.color??"var(--sa-background-brand, #04254f)"}})}),e.jsx("div",{style:{paddingLeft:"1rem",paddingRight:"1rem",display:"flex",flexDirection:"column",gap:"var(--sa-spacing-xs, 0.25rem)"},children:S.slotKey?e.jsx(ro,{slotKey:S.slotKey,fallback:S.items.map(O=>Ne(O))}):S.items.map(O=>Ne(O))})]},S.id))}),D.menuBottom&&D.menuBottom.length>0&&e.jsx("div",{style:{borderTop:"1px solid var(--sa-border-subtle, #0b120e24)",paddingTop:"0.75rem",paddingBottom:"0.75rem",paddingLeft:"1rem",paddingRight:"1rem",backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",display:"flex",flexDirection:"column",gap:"var(--sa-spacing-xs, 0.25rem)",flexShrink:0},children:D.menuBottom.map(S=>Ne(S))})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsxs("header",{style:{height:"4rem",backgroundColor:"var(--sa-background-primary, #ffffff)",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",display:"flex",alignItems:"center",justifyContent:"space-between",paddingLeft:"1rem",paddingRight:"1rem",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:E?"1rem":void 0},children:[E&&e.jsx("button",{onClick:()=>K(!0),style:{padding:"0.375rem",borderRadius:"0.5rem",backgroundColor:"transparent",border:"none",color:"var(--sa-text-subtle, #8c8f97)",cursor:"pointer"},children:e.jsx("svg",{style:{width:"1.5rem",height:"1.5rem"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),e.jsx(Rt,{children:t})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[a,e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[e.jsxs("div",{style:{textAlign:"right",maxWidth:"12.5rem"},children:[e.jsx("p",{style:{margin:0,fontSize:"0.875rem",fontWeight:500,color:"var(--sa-text-subtle, #8c8f97)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n?"Loading...":(o==null?void 0:o.name)||"unknown"}),e.jsx("p",{style:{margin:0,fontSize:"0.75rem",color:"var(--sa-text-subtle, #8c8f97)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n?"":(o==null?void 0:o.email)||"unknown"})]}),e.jsx("div",{style:{width:"2.5rem",height:"2.5rem",borderRadius:"9999px",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--sa-background-primary, #ffffff)",fontWeight:600,fontSize:"0.875rem",boxShadow:"var(--sa-shadow-sm, 0 1px 2px 0 #0000000d)",flexShrink:0,backgroundColor:"var(--sa-background-brand, #04254f)"},children:((o==null?void 0:o.name)||"U")[0].toUpperCase()}),e.jsx(T.Icon,{name:"ChevronDown",size:"sm",style:{color:"var(--sa-text-subtle, #8c8f97)"}})]})}),e.jsxs(W.MenuLists,{width:280,style:{paddingBlock:"12px",paddingInline:"12px",gap:"8px",marginTop:"16px"},children:[e.jsx(W.MenuHeading,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",paddingBlock:"0.5rem"},children:[e.jsx("div",{style:{width:"4rem",height:"4rem",borderRadius:"9999px",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--sa-background-primary, #ffffff)",fontWeight:600,fontSize:"1.25rem",boxShadow:"var(--sa-shadow-sm, 0 1px 2px 0 #0000000d)",marginBottom:"0.75rem",backgroundColor:"var(--sa-background-brand, #04254f)"},children:((o==null?void 0:o.name)||"U")[0].toUpperCase()}),e.jsx("p",{style:{margin:0,fontSize:"0.875rem",fontWeight:600,color:"var(--sa-text-primary, #292a2e)",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(o==null?void 0:o.name)||"unknown"}),e.jsx("p",{style:{margin:0,fontSize:"0.75rem",color:"var(--sa-text-subtle, #8c8f97)",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(o==null?void 0:o.email)||"unknown"}),d&&e.jsx("p",{style:{margin:0,fontSize:"0.75rem",color:"var(--sa-text-subtle, #8c8f97)",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d})]})}),(y&&y.length>0||b)&&e.jsxs(W.MenuBody,{children:[y==null?void 0:y.map((S,O)=>e.jsx(W.MenuButton,{children:e.jsxs("button",{type:"button",onClick:S.onClick,style:so,onMouseEnter:V=>{V.currentTarget.style.backgroundColor="var(--sa-background-neutral, #f0f1f2)"},onMouseLeave:V=>{V.currentTarget.style.backgroundColor="transparent"},children:[e.jsx(T.Icon,{name:S.icon,size:"md"}),e.jsx("span",{children:S.label})]})},`${S.label}-${O}`)),b]}),p??e.jsx(W.MenuFooter,{children:e.jsx(W.MenuButton,{children:e.jsxs("button",{type:"button",onClick:Oe,style:{...so,color:"var(--sa-background-error, #c9184a)",fontWeight:500},onMouseEnter:S=>{S.currentTarget.style.backgroundColor="var(--sa-color-error-50, #fff0f3)"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="transparent"},children:[e.jsx(T.Icon,{name:"Logout",size:"md",style:{color:"var(--sa-background-error, #c9184a)"}}),e.jsx("span",{children:"Logout"})]})})})]})]})]})]}),e.jsx("main",{ref:xe,style:{flex:1,overflowY:"auto"},children:r||e.jsx(L,{})})]})]}),c&&s&&e.jsx("div",{style:{position:"fixed",inset:0,background:"var(--sa-color-black-alpha-a70, #181a19b8)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},children:s}),e.jsxs(Ae.Dialog,{isShow:U,onHide:Ve,children:[e.jsx(Ae.DialogTitle,{children:"Confirmation Logout"}),e.jsx(Ae.DialogBody,{children:"Are you sure you want to end the session and exit the page?"}),e.jsx(Ae.DialogFooter,{children:e.jsx(u.Box,{direction:"column",display:"flex",align:"flex-end",justify:"center",children:e.jsxs(ne.Flex,{direction:"row",gap:"sm",align:"center",children:[e.jsx(u.Box,{direction:"column",children:e.jsx(N.Button,{secondary:!0,onClick:Ve,children:"Cancel"})}),e.jsx(u.Box,{direction:"column",children:e.jsx(N.Button,{primary:!0,onClick:Pe,children:"Yes, Sure"})})]})})})]}),le&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>Ce(null),style:{position:"fixed",inset:0,zIndex:60,backgroundColor:"transparent"}}),e.jsxs("div",{role:"dialog","aria-label":le.item.title,style:{position:"fixed",top:le.top,left:le.left,zIndex:61,minWidth:"13rem",maxWidth:"16rem",backgroundColor:"var(--sa-background-primary, #ffffff)",border:"1px solid var(--sa-border-subtle, #0b120e24)",borderRadius:"var(--sa-radii-md, 0.5rem)",boxShadow:"var(--sa-shadow-lg, 0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a)",padding:"0.5rem",display:"flex",flexDirection:"column",gap:"0.125rem"},children:[e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--sa-color-gray-500, #8c8f97)",padding:"0.25rem 0.5rem 0.5rem",textTransform:"uppercase",letterSpacing:"0.05em"},children:le.item.title}),(P=le.item.children)==null?void 0:P.map(S=>{const O=we(S.to),V=mr(S.badge,m[S.id]);return e.jsxs("button",{onClick:()=>{H(S.to),Ce(null)},style:{width:"100%",display:"flex",alignItems:"center",gap:"0.75rem",padding:"0.5rem 0.75rem",borderRadius:"var(--sa-radii-md, 0.5rem)",textAlign:"left",backgroundColor:O?"var(--sa-color-gray-100, #f8f8f8)":"transparent",color:O?"var(--sa-text-primary, #292a2e)":"var(--sa-color-gray-800, #505258)",border:"1px solid transparent",cursor:"pointer",fontSize:"0.875rem",fontWeight:500},onMouseEnter:J=>{O||(J.currentTarget.style.backgroundColor="var(--sa-color-gray-100, #f8f8f8)")},onMouseLeave:J=>{O||(J.currentTarget.style.backgroundColor="transparent")},children:[S.icon&&e.jsx(T.Icon,{name:S.icon,size:"sm",style:{flexShrink:0}}),e.jsx("span",{style:{flex:1,whiteSpace:"nowrap"},children:S.title}),V&&e.jsx(Ye.Badges,{text:String(V.value),variant:V.variant??"info",size:"xs",border:!0})]},S.id)})]})]})]})})}const yr=h.forwardRef(({children:r,...t},o)=>e.jsx(u.Box,{ref:o,role:"button",cursor:"pointer","aria-pressed":"true",display:"inline-block",tabIndex:0,...t,children:r})),io=({title:r,iconName:t,textColor:o,iconColor:n,hoverTextColor:l,hoverIconColor:c})=>{const[s,i]=h.useState(!1),a=n??"var(--sa-text-subtle, #8c8f97)",d=o??"var(--sa-text-subtle, #8c8f97)",y=c??"var(--sa-text-subtle, #8c8f97)",b=l??"var(--sa-text-primary, #292a2e)";return e.jsxs(u.Box,{direction:"row",gap:"xs",align:"center",onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{cursor:"pointer"},children:[e.jsx(T.Icon,{name:t||"ChevronLeft",size:"xs",style:{color:s?y:a,transition:"color 0.15s ease"}}),e.jsx(k.Text,{variant:"sub-h3",style:{color:s?b:d,transition:"color 0.15s ease"},children:r||"Back"})]})},Bl=({items:r,separator:t="/",iconName:o,iconColor:n,hoverIconColor:l})=>{const{Link:c}=Ge(),[s,i]=h.useState(!1),a=n??"var(--sa-text-subtle, #8c8f97)",d=l??"var(--sa-text-subtle, #8c8f97)",y=r.length>1?r[0]:void 0,b=!!(y!=null&&y.to||y!=null&&y.onClick),p=e.jsx(T.Icon,{name:o||"ChevronLeft",size:"xs",onMouseEnter:b?()=>i(!0):void 0,onMouseLeave:b?()=>i(!1):void 0,style:{color:b&&s?d:a,transition:"color 0.15s ease",cursor:b?"pointer":void 0}}),v=y!=null&&y.to?e.jsx(c,{to:y.to,replace:!0,style:{textDecoration:"none"},children:p}):y!=null&&y.onClick?e.jsx(yr,{onClick:y.onClick,children:p}):p;return e.jsxs(u.Box,{direction:"row",gap:"xs",align:"center",children:[v,e.jsx(or.Breadcrumb,{separator:t,size:"md",children:r.map((B,x)=>{const L=x===r.length-1;return B.to&&!L?e.jsx(or.BreadcrumbItem,{children:e.jsx(c,{to:B.to,children:B.label})},x):e.jsx(or.BreadcrumbItem,{currentPage:L,children:e.jsx(or.BreadcrumbLink,{onClick:L?void 0:B.onClick,children:B.label})},x)})})]})},ml=r=>{const{Link:t}=Ge(),{items:o,separator:n,onClick:l,navigateTo:c,...s}=r;return o&&o.length>0?e.jsx(Bl,{items:o,separator:n,iconName:s.iconName,iconColor:s.iconColor,hoverIconColor:s.hoverIconColor}):c?e.jsx(u.Box,{direction:"row",children:e.jsx(t,{to:c,replace:!0,style:{textDecoration:"none"},children:e.jsx(io,{...s})})}):e.jsx(u.Box,{direction:"row",children:e.jsx(yr,{onClick:l,children:e.jsx(io,{...s})})})},tt=[{icon:"var(--sa-color-brand-400, #3366b7)",activeBg:"var(--sa-color-brand-50, #e6edf6)",activeBorder:"var(--sa-color-brand-300, #668cc9)",activeShadow:"rgba(51, 102, 183, 0.25)"},{icon:"var(--sa-color-warning-400, #ed9f30)",activeBg:"var(--sa-color-warning-50, #fef2e6)",activeBorder:"var(--sa-color-warning-300, #f1b259)",activeShadow:"rgba(237, 159, 48, 0.25)"},{icon:"var(--sa-color-secondary-300, #5468e1)",activeBg:"var(--sa-color-secondary-50, #e6e9fb)",activeBorder:"var(--sa-color-secondary-200, #8a98ea)",activeShadow:"rgba(84, 104, 225, 0.25)"},{icon:"var(--sa-color-info-500, #00abeb)",activeBg:"var(--sa-color-info-50, #effaff)",activeBorder:"var(--sa-color-info-300, #75dbff)",activeShadow:"rgba(0, 171, 235, 0.25)"},{icon:"var(--sa-color-success-500, #30ce84)",activeBg:"var(--sa-color-success-50, #ecfff6)",activeBorder:"var(--sa-color-success-300, #75dead)",activeShadow:"rgba(48, 206, 132, 0.25)"},{icon:"var(--sa-color-error-400, #ff758f)",activeBg:"var(--sa-color-error-50, #fff0f3)",activeBorder:"var(--sa-color-error-300, #ff8fa3)",activeShadow:"rgba(255, 117, 143, 0.25)"}];function ao(r,t,o){return{display:"flex",alignItems:"center",justifyContent:"center",width:"64px",height:"64px",borderRadius:"var(--sa-radii-sm, 6px)",border:r?`2px solid ${o.activeBorder}`:"2px solid var(--sa-color-gray-200, #f0f1f2)",backgroundColor:r?o.activeBg:"var(--sa-color-gray-50, #ffffff)",boxShadow:r?t?`0 8px 20px ${o.activeShadow.replace("0.25","0.35")}`:`0 2px 8px ${o.activeShadow}`:t?"0 8px 20px rgba(0, 0, 0, 0.14)":"0 1px 4px rgba(0, 0, 0, 0.08)",transform:t?"translateY(-3px) scale(1.05)":"translateY(0) scale(1)",transition:"box-shadow 0.2s ease, transform 0.2s ease, background-color 0.15s ease, border-color 0.15s ease"}}const ho={fontSize:"11px",fontWeight:500,textAlign:"center",overflowWrap:"normal",wordBreak:"normal",color:"var(--sa-background-primary, #ffffff)",lineHeight:"1.3",maxWidth:"80px"},fo={display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",background:"none",border:"none",cursor:"pointer",padding:0};function go({isShow:r,onHide:t,menus:o,selectedGroupId:n,onSelect:l}){const[c,s]=h.useState(void 0),i=d=>{l(d),t()},a=tt[0];return e.jsx(Ae.Dialog,{isShow:r,onHide:t,style:{width:560,background:"transparent",boxShadow:"none",border:"none"},children:e.jsx(Ae.DialogBody,{children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"16px"},children:[e.jsxs("button",{onClick:()=>i(null),onMouseEnter:()=>s("all"),onMouseLeave:()=>s(void 0),style:fo,children:[e.jsx("div",{style:ao(n===null,c==="all",a),children:e.jsx("div",{style:{color:a.icon,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(T.Icon,{name:"Grid",size:"lg",style:{width:32,height:32}})})}),e.jsx("span",{style:ho,children:"Semua"})]}),o.map((d,y)=>{var x;const b=n===d.id,p=c===d.id,v=((x=d.items[0])==null?void 0:x.icon)??"Grid",B=tt[(y+1)%tt.length];return e.jsxs("button",{onClick:()=>i(d.id),onMouseEnter:()=>s(d.id),onMouseLeave:()=>s(void 0),style:fo,children:[e.jsx("div",{style:ao(b,p,B),children:e.jsx("div",{style:{color:B.icon,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(T.Icon,{name:v,size:"lg",style:{width:32,height:32}})})}),e.jsx("span",{style:ho,children:d.name})]},d.id)})]})})})}function Fl({onSelect:r,"aria-label":t="Pilih module"}={}){const o=$r(),{useNavigate:n}=Ge(),l=n(),{selectedGroupId:c,setSelectedGroupId:s}=rt(),[i,a]=h.useState(!1),d=y=>{var b;if(s(y),y!==null){const p=o.menus.find(B=>B.id===y),v=(b=p==null?void 0:p.items[0])==null?void 0:b.to;v&&l(v)}r==null||r(y)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx("button",{onClick:()=>a(!0),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"2.25rem",height:"2.25rem",borderRadius:"var(--sa-radii-sm, 0.25rem)",border:"1px solid var(--sa-border-subtle, #0b120e24)",color:"var(--sa-text-subtle, #8c8f97)",backgroundColor:"transparent",cursor:"pointer"},"aria-label":t,onMouseEnter:y=>{y.currentTarget.style.backgroundColor="var(--sa-background-primary-inverse, #f8f8f8)"},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent"},children:e.jsx(T.Icon,{name:"GridApplication",size:"sm"})}),c!==null&&e.jsx("span",{style:{position:"absolute",top:"0.25rem",right:"0.25rem",width:"0.5rem",height:"0.5rem",borderRadius:"9999px",backgroundColor:"var(--sa-color-brand-500, #1a4fa0)"},"aria-hidden":"true"})]}),e.jsx(go,{isShow:i,onHide:()=>a(!1),menus:o.menus.filter(y=>y.parentGroupId===void 0),selectedGroupId:c,onSelect:d})]})}const El=(r,t)=>{const o=[];if(t===0)return o.push(r),o;for(let n=0;n<r.length;n+=t){const l=r.slice(n,n+t);o.push(l)}return o},Ml=h.memo(({value:r,label:t,separator:o,labelWidth:n,lastIndex:l,labelAlign:c="top"})=>{const s=h.useMemo(()=>({padding:0,paddingBottom:l?0:12,verticalAlign:c}),[l,c]),i=h.useMemo(()=>({padding:0,paddingRight:12,paddingLeft:12,paddingBottom:l?0:12,verticalAlign:c}),[l,c]),a=()=>typeof t=="string"?e.jsx(k.Text,{fontWeight:"medium",color:"subtlest",children:t}):t,d=()=>typeof r=="string"||typeof r=="number"?e.jsx(k.Text,{color:"primary",fontWeight:"medium",children:r}):r,y=()=>typeof o=="string"||typeof o=="number"?e.jsx(k.Text,{fontWeight:"medium",color:"subtlest",children:o}):o;return e.jsxs(Q.Tr,{children:[e.jsx(Q.Td,{style:s,width:n,children:a()}),o?e.jsx(Q.Td,{style:i,width:24,children:y()}):null,e.jsx(Q.Td,{style:s,children:d()})]})}),Ll=h.memo(({fields:r,separator:t,labelWidth:o})=>e.jsx(Q.Table,{withColumnBorder:!1,withRowBorder:!1,children:r.map((n,l)=>e.jsx(Ml,{separator:t,labelWidth:o,lastIndex:l===r.length-1,...n},`field-group-field-${l}`))})),Tl=h.memo(({maxRow:r=0,maxColumn:t=2,separator:o=":",fields:n=[],labelWidth:l=150,bordered:c=!1})=>{const s=h.useMemo(()=>El(n,r),[n,r]),i=s.length>2,a=()=>{switch(t){case 1:return"width-full";case 2:return"width-1-2";case 3:return"width-1-3";case 4:return"width-1-4";default:return"width-1-2"}};return e.jsx(u.Box,{gap:i?void 0:"lg",direction:"row",flexWrap:"wrap",borderRadius:"rounded-sm",padding:"lg",paddingBottom:i?"xs":"lg",bg:"accent-dark-tertiary",borderWidth:c?"border":void 0,borderStyle:c?"border-solid":void 0,borderColor:c?"border-subtle":void 0,children:s.map((d,y)=>e.jsx(u.Box,{direction:"column",flex:i?void 0:"1",width:i?a():void 0,marginBottom:i?"lg":void 0,children:e.jsx(Ll,{labelWidth:l,fields:d,separator:o})},y))})}),Il=({backButton:r})=>{const[t,o]=h.useState(!1),n=(r==null?void 0:r.iconColor)??"var(--sa-text-subtle, #8c8f97)",l=(r==null?void 0:r.textColor)??"var(--sa-text-subtle, #8c8f97)",c=(r==null?void 0:r.hoverIconColor)??"var(--sa-text-subtle, #8c8f97)",s=(r==null?void 0:r.hoverTextColor)??"var(--sa-text-primary, #292a2e)";return e.jsxs(u.Box,{direction:"row",gap:"xs",align:"center",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{cursor:"pointer"},children:[e.jsx(T.Icon,{name:(r==null?void 0:r.iconName)||"ChevronLeft",size:"xs",style:{color:t?c:n,transition:"color 0.15s ease"}}),e.jsx(k.Text,{variant:"sub-h3",style:{color:t?s:l,textDecoration:t?"underline":"none",transition:"color 0.15s ease"},children:(r==null?void 0:r.title)||"Back"})]})},Ol=({backButton:r,title:t,titleIcon:o,titleTag:n,children:l,header:c=!0,headerBorder:s=!1,disableAnimation:i=!1,scrollable:a=!1,stickyHeader:d=!1,subHeaders:y,action:b,titleTagProps:p,containerProps:v,headerProps:B})=>{const x=be.useMediaQuery("md"),{Link:L,useNavigate:F,useLocation:A}=Ge(),D=F(),m=A(),H=r==null?void 0:r.show,z=()=>{if(typeof(r==null?void 0:r.onClick)=="function"){r.onClick();return}D(-1,{replace:!0})},I=()=>{if(!b)return null;if(h.isValidElement(b))return b;const _=b.filter(K=>K&&(K.title||K.icon));return _.length===0?null:x?e.jsx(u.Box,{direction:"row",gap:"md",children:_.map(({title:K,icon:te,buttonProps:q,onClick:j},Z)=>e.jsx(N.Button,{iconLeft:te?e.jsx(T.Icon,{name:te,size:"md"}):void 0,onClick:j,...q,children:K},`action-${Z}`))}):e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"tertiary",size:"sm",iconLeft:e.jsx(T.Icon,{name:"MenuBurger"}),"aria-label":"Actions"})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{minWidth:200},children:_.map(({title:K,icon:te,buttonProps:q,onClick:j},Z)=>{const le=(q==null?void 0:q.tone)==="error"||(q==null?void 0:q.danger)===!0;return e.jsx(W.MenuItem,{intent:le?"danger":void 0,disabled:q==null?void 0:q.disabled,startIcon:te?e.jsx(T.Icon,{name:te}):void 0,onClick:j,children:K},`action-${Z}`)})})})]})},E=()=>{const _=e.jsx(Il,{backButton:r});return r!=null&&r.navigateTo?e.jsx(u.Box,{direction:"row",children:e.jsx(L,{to:r.navigateTo,replace:!0,style:{textDecoration:"none"},children:_})}):e.jsx(u.Box,{direction:"row",children:e.jsx(yr,{onClick:z,children:_})})},U=()=>{const _=!!t,K=Array.isArray(b)&&b.length>0,te=h.isValidElement(b)?!0:K;if(!_&&!te&&!H)return null;const j=x||!x&&K;return e.jsxs(u.Box,{direction:"column",gap:"xs",paddingBlock:(B==null?void 0:B.paddingBlock)??"sm",paddingInline:(B==null?void 0:B.paddingInline)??"md",...B,style:{...s?{boxShadow:"inset 0 -1px 0 0 var(--sa-border-subtle, #0b120e24)"}:{},...B==null?void 0:B.style},children:[H&&E(),(_||te)&&e.jsxs(u.Box,{direction:j?"row":"column",gap:"sm",justify:"space-between",align:j?"center":"flex-start",children:[_?typeof t=="string"?e.jsxs(u.Box,{direction:"row",gap:"lg",align:"center",children:[e.jsxs(u.Box,{direction:"row",gap:"sm",align:"center",children:[o&&e.jsx(T.Icon,{name:o,size:"md",color:"primary"}),e.jsx(k.Text,{variant:"h3",fontWeight:"semibold",fontFamily:"Poppins",children:t})]}),n&&e.jsx(Ye.Badge,{border:!0,size:"lg",text:n,...p})]}):t:null,I()]})]})},X=()=>{if(!y||y.length===0)return null;const _=y.filter(q=>q.show!==!1);if(_.length===0)return null;let K=0,te=-1/0;return _.forEach((q,j)=>{const Z=q.order??0;Z>=te&&(te=Z,K=j)}),_.map(({content:q,order:j,borderBottom:Z=!0,keepBottomPadding:le=!1,paddingInline:Ce=!0,paddingBlock:ve=!0},he)=>e.jsx(u.Box,{direction:"column",paddingTop:ve?"sm":"spacing-0",paddingBottom:ve&&(Z||le||he===K)?"sm":"spacing-0",paddingInline:Ce?"md":"spacing-0",style:{...Z?{boxShadow:"inset 0 -1px 0 0 var(--sa-border-subtle, #0b120e24)"}:{},...j!==void 0?{order:j}:{}},children:q},`sub-header-${he}`))},G=()=>{const _=c?U():null,K=X();return!_&&!K?null:e.jsxs(u.Box,{direction:"column",style:{...a?{position:"sticky",left:0,...d?{top:0}:{},zIndex:2,background:"var(--sa-background-primary, #ffffff)"}:{},marginBottom:K?"var(--sa-spacing-0)":"var(--sa-spacing-md)"},children:[_,K]})},R=()=>l;return e.jsxs(u.Box,{direction:"column",as:"main",...v,style:{...a?{height:"100%",minHeight:0,overflow:"auto"}:{},...(v==null?void 0:v.style)??{},...i?{}:{animation:"pageLayoutEnter 320ms cubic-bezier(0.16, 1, 0.3, 1) backwards"}},children:[G(),R()]},m.pathname)},Wl=h.memo(Ol),Al={icon:"Cross",title:""},uo=h.forwardRef(({onHide:r,show:t,withBlur:o=!1,style:n,children:l,closeButton:c=Al,width:s,minWidth:i,maxWidth:a},d)=>{const y=s??a??i??"357px";return e.jsx(kr.Drawer,{blur:o,isShow:t,position:"right",onHide:r,ref:d,size:y,style:n,children:e.jsxs(u.Box,{direction:"column",padding:"lg",children:[c?e.jsxs(u.Box,{direction:"row",align:"center",gap:"sm",onClick:r,marginBottom:"lg",cursor:"pointer",children:[e.jsx(T.Icon,{name:c.icon,size:"md",color:"subtle",cursor:"pointer"}),c.title?e.jsx(k.Text,{fontFamily:"Poppins",fontSize:"md",color:"subtlest",children:c.title}):null]}):null,l]})})}),ot=h.memo(({children:r,borderBottom:t=!0,padding:o=!0})=>{const n=be.useMediaQuery("lg");return e.jsx(u.Box,{direction:"column",padding:o?"md":"spacing-0",paddingLeft:o?"md":"spacing-0",paddingRight:o?"md":"spacing-0",style:t?{borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)"}:void 0,children:r})}),lt=h.memo(({children:r,borderTop:t=!0,padding:o=!0})=>{const n=be.useMediaQuery("lg");return e.jsx(u.Box,{direction:"column",padding:o?"md":"spacing-0",paddingLeft:o?"md":"spacing-0",paddingRight:o?"md":"spacing-0",style:t?{borderTop:"1px solid var(--sa-border-subtle, #0b120e24)"}:void 0,children:r})}),zl=h.memo(({children:r,...t})=>e.jsx(u.Box,{direction:"column",padding:"md",paddingLeft:"md",paddingRight:"md",gap:"md",...t,children:r})),Hl=h.memo(({children:r,title:t,titleTag:o,action:n,header:l,footer:c,actionContainer:s,containerProps:i,bodyProps:a,headerProps:d={borderBottom:!0},footerProps:y={borderTop:!0},variantTag:b="info"})=>{const p=be.useMediaQuery("lg"),v=()=>o?e.jsxs(u.Box,{direction:"row",gap:"sm",align:"center",children:[e.jsx(k.Text,{fontWeight:"medium",children:t}),e.jsx(Ye.Badges,{border:!0,text:o,variant:b})]}):e.jsx(k.Text,{fontWeight:"medium",children:t}),B=()=>l||e.jsxs(u.Box,{direction:"row",justify:"space-between",align:"flex-start",gap:"md",children:[e.jsx(u.Box,{direction:"column",children:t?v():null}),e.jsx(u.Box,{direction:"column",style:p?{width:"100%",maxWidth:"19.313rem"}:{flex:1},...s,children:n??null})]}),x=!!(l||t||n);return e.jsxs(u.Box,{direction:"column",bg:"white",borderRadius:"rounded-xs",as:"section",borderWidth:"border",borderStyle:"border-solid",borderColor:"border-base",...i,style:{backgroundColor:"var(--sa-background-primary, #ffffff)",...(i==null?void 0:i.style)??{}},children:[l!==null&&x?e.jsx(ot,{...d,children:B()}):null,e.jsx(zl,{...a,children:r}),c?e.jsx(lt,{...y,children:c}):null]})}),He={H1:r=>e.jsx(k.Text,{variant:"h1",children:r.children,...r.props}),H2:r=>e.jsx(k.Text,{variant:"h2",children:r.children,...r.props}),H3:r=>e.jsx(k.Text,{variant:"h3",children:r.children,...r.props}),H4:r=>e.jsx(k.Text,{variant:"h4",children:r.children,...r.props}),H5:r=>e.jsx(k.Text,{variant:"h5",children:r.children,...r.props}),H6:r=>e.jsx(k.Text,{variant:"h6",children:r.children,...r.props}),SubH1:r=>e.jsx(k.Text,{variant:"sub-h1",children:r.children,...r.props}),SubH2:r=>e.jsx(k.Text,{variant:"sub-h2",children:r.children,...r.props}),SubH3:r=>e.jsx(k.Text,{variant:"sub-h3",children:r.children,...r.props}),Body1:r=>e.jsx(k.Text,{variant:"body-1",children:r.children,...r.props}),Body2:r=>e.jsx(k.Text,{variant:"body-2",children:r.children,...r.props}),Body3:r=>e.jsx(k.Text,{variant:"body-3",children:r.children,...r.props})},Te=()=>{const{useSearchParams:r,useParams:t,useLocation:o}=Ge(),[n,l]=r(),c=nr.searchParamsToObject(n.toString()),s=t(),i=o(),a=s.id;return{setSearchParams:l,searchParams:n,searchQueries:c,isHasQuery:(v,B)=>n.has(v)&&n.get(v)===B,getQueryParam:v=>n.get(v),getRouteParam:v=>s[v],params:s,location:i,id:a,hasId:!!a}},yo=r=>JSON.stringify(r),po=r=>JSON.stringify(r),bo=r=>JSON.stringify(r),Co=r=>JSON.stringify(r),Vl=r=>r,Pl=r=>JSON.stringify(r),pr=({value:r,name:t,type:o,withSearchParam:n=!0,setSearchParams:l,searchQueries:c,dropdownSearchKey:s,filterKey:i="filter",pageKey:a="page"})=>{if(n){let d;switch(o){case"search":d=Vl(r);break;case"dropdown":case"dropdown-multiple":d=yo(r);break;case"radio":d=po(r);break;case"date-range":d=bo(r);break;case"advanced-date-range":d=Pl(r);break;case"date":d=Co(r);break;default:d=r;break}if(typeof d<"u"){const b={...c[i]&&typeof c[i]=="string"?JSON.parse(c[i]):void 0,[t]:d},p={...c};s&&typeof s=="string"&&delete p[s],delete p[a];const v={...p,[i]:JSON.stringify(b)},B=new URLSearchParams(c).toString(),x=new URLSearchParams(v).toString();if(B===x)return;l(v)}}},Mr=({name:r,filterKey:t="filter",searchParams:o,get:n})=>{const l=o.get(t)||void 0,c=l&&typeof l=="string"?JSON.parse(l):void 0,s=c?c[r]:void 0;return n==="label"&&s?JSON.parse(s)[0].label:n==="value"&&s?JSON.parse(s)[0].value:s},vo=({name:r,filterKey:t="filter",searchParams:o,get:n})=>{const l=o.get(t)||void 0,c=l&&typeof l=="string"?JSON.parse(l):void 0,s=c?c[r]:void 0;return n==="label"&&s?JSON.parse(s).map(i=>i.label):n==="value"&&s?JSON.parse(s).map(i=>i.value):n==="array"&&s?JSON.parse(s):s},jl=({name:r,filterKey:t="filter",searchParams:o,get:n})=>{const l=o.get(t)||void 0,c=l&&typeof l=="string"?JSON.parse(l):void 0,s=c?c[r]:void 0;return n==="id"&&s?JSON.parse(s).id:n==="label"&&s?JSON.parse(s).label:n==="value"&&s?JSON.parse(s).value:s},Lr=(r,t,o)=>{const n=t.get(o||"filter")||void 0,l=n&&typeof n=="string"?JSON.parse(n):void 0;return l?l[r]:void 0},Nl=({name:r,filterKey:t="filter",searchParams:o})=>{const n=o.get(t||"filter")||void 0,l=n&&typeof n=="string"?JSON.parse(n):void 0,c=l?l[r]:void 0;return{start:c?JSON.parse(c).from:void 0,end:c?JSON.parse(c).to:void 0}},xo=({name:r,filterKey:t="filter",searchParams:o})=>{const n=o.get(t||"filter")||void 0,l=n&&typeof n=="string"?JSON.parse(n):void 0,c=l?l[r]:void 0;return c?JSON.parse(c):void 0},_l=(r,{filterKey:t="filter",perPageKey:o="perPage",pageKey:n="page"})=>{const l=r.get(t)||void 0,c=r.get(o)||void 0,s=r.get(n)||void 0;return!!l||!!c||!!s},wo=({isOpen:r,onClose:t,filterKey:o,pageKey:n,filters:l})=>{const{searchParams:c,setSearchParams:s,searchQueries:i}=Te(),[a,d]=h.useState({}),y=()=>{c.delete(o||"filter"),s(c)},b=(p,v)=>{switch(p.type){case"radio":{const{show:B=!0}=p;return B&&e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v)}case"dropdown":{const{show:B=!0}=p;return B&&e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v)}case"date-range":return e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v);case"date":return e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v);case"dropdown-multiple":{const{show:B=!0}=p;return B&&e.jsx(u.Box,{direction:"column",children:e.jsx(u.Box,{direction:"column",children:p.title})},v)}default:return null}};return e.jsx(uo,{onHide:t,show:r||!1,children:e.jsxs(u.Box,{direction:"column",gap:"md",children:[e.jsxs(ne.Flex,{direction:"row",justify:"space-between",align:"center",children:[e.jsx(u.Box,{direction:"column",children:"Filter"}),e.jsx(u.Box,{direction:"column",style:{cursor:"pointer"},onClick:y,children:"Reset"})]}),l==null?void 0:l.map((p,v)=>b(p,v))]})})},Do=({searchKey:r="q",statusKey:t="status",searchPlaceholder:o="Search",searchHighlightPlaceholder:n,extendedFilter:l,showSearchFilter:c=!0,showStatusFilter:s=!0,filterKey:i="filter",pageKey:a="page",customWidthSearch:d,handleOnReset:y,filterConfigs:b,buttonToggleProps:p,position:v="right",titleSearchLabel:B="Work Order",withTitleLabels:x=!1})=>{const F=(p==null?void 0:p.isShowLabel)??!0,[A,D]=h.useState(!1),[m,H]=h.useState(0),z=()=>{H(Z=>Z+1)},{searchParams:I,setSearchParams:E,getQueryParam:U}=Te(),X=nr.searchParamsToObject(I.toString()),G=Lr(r,I,i)||"",[R,_]=h.useState(G),K=U(i),q=!!(K&&!(()=>{if(K)try{const Z=JSON.parse(K);return Object.keys(Z).length===1&&Z[r]===""}catch(Z){console.error("Filter parameter is not a valid JSON:",Z)}return!1})()),j=be.useMediaQuery("md");return h.useEffect(()=>{_(G)},[G]),h.useEffect(()=>{if(R===G)return;const Z=window.setTimeout(()=>{pr({value:R,name:r,type:"search",searchQueries:X,setSearchParams:E,filterKey:i,pageKey:a})},350);return()=>{window.clearTimeout(Z)}},[R,G,r,X,E,i,a]),e.jsxs(ne.Flex,{gap:"md",style:{flexDirection:j&&v==="left"?"row":j&&v==="right"?"row-reverse":"column"},align:"flex-end",children:[q&&e.jsx(u.Box,{direction:"column",justify:"flex-end",children:e.jsx(N.Button,{onClick:()=>{const Z=new URLSearchParams(I);Z.delete(i),E(Z),_(""),z(),y&&y()},variant:"outline",tone:"neutral",children:e.jsx(k.Text,{color:"error",fontWeight:"semibold",children:"Reset"})})}),l==null?void 0:l.map(({minWidth:Z,content:le,title:Ce,onClickContainer:ve},he)=>e.jsxs(u.Box,{direction:"column",gap:"sm",onClick:ve,style:{minWidth:Z},children:[Ce&&e.jsx(He.SubH3,{children:Ce}),le]},`extended-filter-${he}-${m}`)),!!(b!=null&&b.length)&&e.jsx(N.Button,{primary:q,secondary:!q,iconLeft:e.jsx(T.Icon,{size:"sm",name:(p==null?void 0:p.icon)||"FilterHorizontal",style:{color:K?"var(--sa-background-brand, #04254f)":"var(--sa-text-primary, #292a2e)"}}),fullWidth:!j,onClick:()=>D(!0),children:F?"Filter":void 0}),s&&e.jsxs(u.Box,{direction:"column",gap:"sm",style:{minWidth:"126px"},children:[x&&e.jsx(He.SubH3,{children:"Status"}),e.jsx(lr.Dropdown,{dropdownLists:[{label:"Active",value:"active"},{label:"InActive",value:"inactive"}],defaultValue:Mr({get:"value",name:t,searchParams:I,filterKey:i})?[{label:Mr({get:"value",name:t,searchParams:I,filterKey:i})==="active"?"Active":"InActive",value:Mr({get:"value",name:t,searchParams:I,filterKey:i})}]:[],onChange:Z=>pr({value:Z,name:t,type:"dropdown",searchQueries:X,setSearchParams:E,filterKey:i}),placeholder:x?"All":"All Status"},m)]}),c&&e.jsxs(u.Box,{direction:"column",gap:"sm",style:{width:d&&j?d:j?"310px":""},children:[x&&e.jsxs(He.SubH3,{children:["Search for ",B]}),e.jsx(Xe.Input,{placeholder:o,leftIcon:e.jsx(T.Icon,{name:"Search",width:20,height:20}),onChange:Z=>_(Z.target.value),value:R,fullWidth:!0},m+1+i)]}),e.jsx(wo,{isOpen:A,onClose:()=>D(!1),filterKey:i,filters:b,pageKey:a})]})},ql=r=>r==="checkbox-multiple"?"dropdown-multiple":r==="radio"?"dropdown":r==="date-compact"?"date":r;function nt({configs:r,filterKey:t="filter",activeFilterKey:o="filters",pageKey:n="page",searchKey:l="q"}){const{searchParams:c,setSearchParams:s,searchQueries:i}=Te(),a=h.useMemo(()=>Object.fromEntries(r.map(m=>[m.key,m])),[r]),d=h.useMemo(()=>{const m=(c.get(o)||"").split(",").map(z=>z.trim()).filter(Boolean);let H=[];try{const z=c.get(t);z&&(H=Object.keys(JSON.parse(z)).filter(I=>I!==l))}catch{}return r.map(z=>z.key).filter(z=>{const I=a[z];return(I==null?void 0:I.locked)||m.includes(z)||H.includes(z)})},[c,o,t,l,r,a]),y=h.useCallback(m=>{try{return m[t]?JSON.parse(m[t]):{}}catch{return{}}},[t]),b=h.useCallback(m=>{const H={...i};m.length?H[o]=m.join(","):delete H[o],s(H)},[i,o,s]),p=h.useCallback(m=>{d.includes(m)||b([...d,m])},[d,b]),v=h.useCallback(m=>{var E;if((E=a[m])!=null&&E.locked)return;const H={...i},z=d.filter(U=>U!==m);z.length?H[o]=z.join(","):delete H[o];const I=y(H);m in I&&(delete I[m],Object.keys(I).length?H[t]=JSON.stringify(I):delete H[t]),delete H[n],s(H)},[i,d,o,t,n,y,s,a]),B=h.useCallback(m=>d.includes(m)?v(m):p(m),[d,p,v]),x=h.useCallback(m=>{switch(m.type){case"dropdown":case"dropdown-multiple":case"checkbox-multiple":case"radio":return vo({name:m.key,get:"array",searchParams:c,filterKey:t})||[];case"date":{const H=xo({name:m.key,searchParams:c,filterKey:t});return H?new Date(H):void 0}case"date-compact":{const z=y(Object.fromEntries(c.entries()))[m.key];return z&&typeof z=="object"?z:void 0}default:return}},[c,t,y]),L=h.useCallback((m,H)=>{if(m.type==="date-compact"){const z={...i},I=y(z);H==null?delete I[m.key]:I[m.key]=H,Object.keys(I).length?z[t]=JSON.stringify(I):delete z[t],delete z[n],s(z);return}pr({value:H,name:m.key,type:ql(m.type),searchQueries:i,setSearchParams:s,filterKey:t,pageKey:n})},[i,s,t,n,y]),F=h.useCallback(m=>{const H={...i},z=y(H);m in z&&(delete z[m],Object.keys(z).length?H[t]=JSON.stringify(z):delete H[t]),delete H[n],s(H)},[i,t,n,y,s]),A=h.useCallback(()=>{const m={...i};delete m[t],delete m[o],delete m[n],s(m)},[i,t,o,n,s]),D=d.length>0;return{activeKeys:d,configByKey:a,hasActiveFilter:D,addFilter:p,removeFilter:v,toggleFilter:B,getValue:x,setValue:L,clearValue:F,clearAll:A}}const ct={get(r){return ur.storage.get(r)??null},set(r,t){ur.storage.save(r,t)},remove(r){ur.storage.delete(r)}},ir={columns:r=>`filterbar:colprefs:${r}`,savedViews:r=>`filterbar:views:${r}`,lastState:r=>`filterbar:last:${r}`,perPage:r=>`filterbar:perpage:${r}`,tableSort:r=>`tablelayout:sort:${r}`},Tr=(r,t)=>{const o=new Set(t.map(c=>c.key)),n=r.order.filter(c=>o.has(c));for(const c of t)n.includes(c.key)||n.push(c.key);const l=r.hidden.filter(c=>o.has(c));return{order:n,hidden:l}};function Zl({columns:r,scopeId:t,storage:o,onColumnsChange:n,value:l}){const c=h.useMemo(()=>({order:r.map(I=>I.key),hidden:[]}),[r]),s=t?ir.columns(t):void 0,i=(I,E)=>Tr({order:I.order??E,hidden:I.hidden??[]},r),[a,d]=h.useState(()=>{if(l&&(l.order||l.hidden))return i(l,r.map(I=>I.key));if(s){const I=o.get(s);if(I&&Array.isArray(I.order))return Tr(I,r)}return c}),y=r.map(I=>I.key).join("|");h.useEffect(()=>d(I=>Tr(I,r)),[y]);const b=h.useRef(a);b.current=a;const p=l?`${(l.order??[]).join("|")}~${(l.hidden??[]).join("|")}`:null,v=h.useRef(p);h.useEffect(()=>{if(p==null||v.current===p)return;v.current=p;const I=b.current,E=i(l,I.order);E.order.join("|")===I.order.join("|")&&E.hidden.join("|")===I.hidden.join("|")||(d(E),s&&o.set(s,E))},[p,y]);const B=h.useRef(!1);h.useEffect(()=>{B.current||(B.current=!0,n==null||n(a))},[]);const x=h.useCallback(I=>{d(I),s&&o.set(s,I),n==null||n(I)},[s,o,n]),L=h.useMemo(()=>{const I=new Map(r.map(E=>[E.key,E]));return a.order.filter(E=>I.has(E)).map(E=>({...I.get(E),visible:!a.hidden.includes(E)}))},[a,r]),F=h.useCallback(I=>{const E=a.hidden.includes(I)?a.hidden.filter(U=>U!==I):[...a.hidden,I];x({...a,hidden:E})},[a,x]),A=h.useCallback((I,E)=>{if(I===E)return;const U=[...a.order],[X]=U.splice(I,1);U.splice(E,0,X),x({...a,order:U})},[a,x]),D=h.useCallback(I=>{x({...a,hidden:I?r.filter(E=>!E.locked).map(E=>E.key):[]})},[a,r,x]),m=h.useCallback(()=>x(c),[x,c]),H=h.useCallback(I=>x(Tr(I,r)),[x,r]),z=a.hidden.length===0;return{state:a,orderedColumns:L,allVisible:z,toggleVisibility:F,reorder:A,setAllHidden:D,reset:m,applyState:H}}function Gl({scopeId:r,storage:t,snapshotKeys:o,pageKey:n="page",getColumns:l,applyColumns:c}){const{searchParams:s,setSearchParams:i}=Te(),a=r?ir.savedViews(r):void 0,[d,y]=h.useState(()=>a?t.get(a)||[]:[]),b=h.useCallback(x=>{y(x),a&&t.set(a,x)},[a]),p=h.useCallback(x=>{const L=x.trim();if(!L)return;const F={};o.forEach(D=>{const m=s.get(D);m!=null&&(F[D]=m)});const A={id:`${Date.now()}`,name:L,query:F,columns:l==null?void 0:l(),createdAt:Date.now()};b([...d,A])},[o,s,l,b,d]),v=h.useCallback(x=>b(d.filter(L=>L.id!==x)),[b,d]),B=h.useCallback(x=>{const L=Object.fromEntries(s.entries());o.forEach(F=>delete L[F]),Object.assign(L,x.query),delete L[n],i(L),x.columns&&(c==null||c(x.columns))},[s,o,n,i,c]);return{enabled:!!a,views:d,saveView:p,deleteView:v,applyView:B}}function Ql(r,t){let o;try{o=JSON.parse(r)}catch{return r}return!o||typeof o!="object"?r:(delete o[t],Object.keys(o).length>0?JSON.stringify(o):void 0)}function So(r,t,o){const n=r[t];if(n==null)return;const l=Ql(n,o);l===void 0?delete r[t]:r[t]=l}function Ul({scopeId:r,storage:t,snapshotKeys:o,enabled:n=!0,filterKey:l="filter",searchKey:c="q",persistSearch:s=!0}){const{searchParams:i}=Te(),a=r&&n?ir.lastState(r):void 0,d=h.useRef(a),y=h.useRef(!1);h.useEffect(()=>{if(!a){d.current=a;return}if(d.current!==a){d.current=a,y.current=!1;return}const v={};if(o.forEach(B=>{const x=i.get(B);x!=null&&(v[B]=x)}),s||So(v,l,c),Object.keys(v).length===0){y.current&&t.remove(a);return}y.current=!0,t.set(a,v)},[i,a,o,t,s,l,c]);const b=h.useCallback(()=>{if(!a)return null;const v=t.get(a);return!v||Object.keys(v).length===0||!s&&(So(v,l,c),Object.keys(v).length===0)?null:v},[a,t,s,l,c]),p=h.useCallback(()=>{a&&t.remove(a)},[a,t]);return{enabled:!!a,read:b,clear:p}}function Jl({scopeId:r,storage:t,perPageKey:o,pageSizeOptions:n,enabled:l=!0}){const{searchParams:c}=Te(),s=r&&l?ir.perPage(r):void 0,i=c.toString(),a=h.useRef(s);h.useEffect(()=>{if(!s){a.current=s;return}if(a.current!==s){a.current=s;return}const b=c.get(o);if(!b)return;const p=Number(b);!Number.isFinite(p)||p<=0||t.set(s,p)},[i,s,o,t]);const d=h.useCallback(()=>{if(!s)return null;const b=t.get(s);if(b==null)return null;const p=Number(b);return!Number.isFinite(p)||p<=0||n&&!n.includes(p)?null:String(p)},[s,t,n]),y=h.useCallback(()=>{s&&t.remove(s)},[s,t]);return{enabled:!!s,read:d,clear:y}}let st={},it=!1,at=null;const Yl=(r,t)=>{Object.assign(st,r),at=t,!it&&(it=!0,queueMicrotask(()=>{const o=st,n=at;st={},it=!1,at=null,!(!n||Object.keys(o).length===0)&&n(l=>{const c=new URLSearchParams(l);return Object.entries(o).forEach(([s,i])=>c.set(s,i)),c})}))};function Xl({enabled:r,snapshotKeys:t,perPageKey:o,readSnapshot:n,readPerPage:l}){const{searchParams:c,setSearchParams:s,location:i}=Te(),a=h.useRef(null);h.useEffect(()=>{if(!r||a.current===i.pathname)return;a.current=i.pathname;const d={};if(!c.has(o)){const y=l();y&&(d[o]=y)}if(!t.some(y=>c.has(y))){const y=n();y&&Object.assign(d,y)}Object.keys(d).length!==0&&Yl(d,s)},[i.pathname,r])}const $l=({configs:r,activeKeys:t,onToggle:o,hasActiveFilter:n,onReset:l})=>r.length?e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:n?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"FilterHorizontal"}),"aria-label":"Add filter"})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{minWidth:260},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:"Add Filter"}),n&&l&&e.jsx(N.Button,{variant:"link",tone:"brand",size:"xs",onClick:l,children:"Reset"})]}),children:r.map(c=>e.jsx(W.MenuItem,{selected:c.locked||t.includes(c.key),disabled:c.locked,closeOnSelect:!1,startIcon:c.icon??void 0,onClick:()=>{c.locked||o(c.key)},children:c.label},c.key))})})]}):null,Ir=({onClear:r,onRemove:t})=>e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"link",tone:"neutral",size:"xs",iconLeft:e.jsx(T.Icon,{name:"MenuHorizontal"}),"aria-label":"Filter actions"})}),e.jsx(W.MenuLists,{children:e.jsxs(W.MenuBody,{style:{width:180},children:[e.jsx(W.MenuItem,{startIcon:e.jsx(T.Icon,{name:"CrossCircle"}),onClick:r,children:"Clear value"}),t&&e.jsx(W.MenuItem,{intent:"danger",startIcon:e.jsx(T.Icon,{name:"Trash1"}),onClick:t,children:"Remove filter"})]})})]}),Kl=r=>{const t=new Date(r);return t.setHours(0,0,0,0),t},ko=(r,t,o)=>{const n=new Date(r);return o==="day"?n.setDate(n.getDate()+t):o==="week"?n.setDate(n.getDate()+t*7):o==="month"?n.setMonth(n.getMonth()+t):n.setFullYear(n.getFullYear()+t),n},Bo=r=>{const t=Kl(new Date);if(r.direction==="this"){const n=new Date(t),l=new Date(t);return r.period==="week"?(n.setDate(t.getDate()-t.getDay()),l.setDate(n.getDate()+6)):r.period==="month"?(n.setDate(1),l.setMonth(l.getMonth()+1,0)):r.period==="year"&&(n.setMonth(0,1),l.setMonth(11,31)),{from:n,to:l}}const o=r.count??1;return r.direction==="past"?{from:ko(t,-o,r.period),to:t}:{from:t,to:ko(t,o,r.period)}},mo=24,Fo=r=>r.length>mo?`${r.slice(0,mo)}...`:r,Or=r=>r.toLocaleDateString(void 0,{day:"2-digit",month:"short",year:"numeric"}),Wr={is:"Is","is-before":"Is before","is-after":"Is after","is-on-or-before":"Is on or before","is-on-or-after":"Is on or after","is-between":"Is between","is-relative-to-today":"Is relative to today","is-empty":"Is empty","is-not-empty":"Is not empty"},Rl=["is","is-before","is-after","is-on-or-before","is-on-or-after","is-between","is-relative-to-today","is-empty","is-not-empty"],dt={past:"Past",next:"Next",this:"This"},en=["day","week","month","year"],rn=["past","next","this"],tn=r=>r.field.type==="date-compact"?e.jsx(nn,{field:r.field,value:r.value,onChange:r.onChange,onClear:r.onClear,onRemove:r.onRemove}):e.jsx(on,{field:r.field,value:r.value,onChange:r.onChange,onClear:r.onClear,onRemove:r.onRemove}),on=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=t?Or(new Date(t)):null,s=!!c,i=s?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:500},children:[r.label,":"]})," ",e.jsx("span",{style:{fontWeight:400},children:Fo(c)})]}):r.label;return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:s?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:s?e.jsx(T.Icon,{name:"Calendar",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:i})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:260},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:e.jsx(er.StarasiaDate,{size:"sm",input:!1,clearable:!0,filter:r.mode,value:t,onChange:a=>a==null?n():o(a),withPadding:!1})})})]})},ln=r=>{switch(r.op){case"is":case"is-before":case"is-after":case"is-on-or-before":case"is-on-or-after":return r.date?`${Wr[r.op]} ${Or(new Date(r.date))}`:null;case"is-between":return r.from&&r.to?`${Or(new Date(r.from))} - ${Or(new Date(r.to))}`:null;case"is-relative-to-today":{const t=r.relative;if(!t)return null;if(t.direction==="this")return`This ${t.period}`;const o=t.count??1,n=o===1?t.period:`${t.period}s`;return`${dt[t.direction]} ${o} ${n}`}case"is-empty":case"is-not-empty":return Wr[r.op];default:return null}},nn=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=r.ops&&r.ops.length>0?r.ops:Rl,s=r.defaultOp&&c.includes(r.defaultOp)?r.defaultOp:c[0],i=(t==null?void 0:t.op)??s,a=t?ln(t):null,d=!!a,y=d?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:500},children:[r.label,":"]})," ",e.jsx("span",{style:{fontWeight:400},children:Fo(a)})]}):r.label,b=p=>{if(p!==i){if(p==="is-empty"||p==="is-not-empty"){o({op:p});return}if(p==="is-relative-to-today"){o({op:p,relative:(t==null?void 0:t.relative)??{direction:"past",count:1,period:"week"}});return}if(p==="is-between"){o({op:p,from:t==null?void 0:t.from,to:t==null?void 0:t.to});return}o({op:p,date:t==null?void 0:t.date})}};return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:d?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:d?e.jsx(T.Icon,{name:"Calendar",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:y})}),e.jsxs(W.MenuLists,{children:[e.jsx(W.MenuBody,{style:{width:320},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",gap:"xs",fullWidth:!0,children:[e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",gap:"xs",style:{minWidth:0},children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(cn,{op:i,ops:c,onChange:b})]}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:e.jsx(sn,{value:t,op:i,onChange:o})}),i==="is-relative-to-today"&&e.jsx(W.MenuFooter,{children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"Filter will update with the current date"})})]})]})},cn=({op:r,ops:t,onChange:o})=>e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"link",tone:"neutral",size:"xs",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:Wr[r]})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:200},children:t.map(n=>e.jsx(W.MenuItem,{selected:r===n,onClick:()=>o(n),endIcon:r===n?e.jsx(T.Icon,{name:"Check"}):void 0,children:Wr[n]},n))})})]}),sn=({value:r,op:t,onChange:o})=>{if(t==="is-empty"||t==="is-not-empty")return e.jsx(u.Box,{paddingBlock:"sm",paddingInline:"sm",children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"No further input required."})});if(t==="is-between"){const n=r!=null&&r.from||r!=null&&r.to?{from:r!=null&&r.from?new Date(r.from):null,to:r!=null&&r.to?new Date(r.to):null}:void 0;return e.jsx(er.StarasiaDate,{size:"sm",input:!1,clearable:!0,rangedDate:!0,value:n,onChange:l=>{if(l==null){o({op:t});return}if(typeof l=="object"&&l!==null&&"from"in l&&"to"in l){let{from:c,to:s}=l;if(!c&&s&&(c=s,s=null),!c&&!s){o({op:t});return}o({op:t,from:c?c.toISOString():void 0,to:s?s.toISOString():void 0})}},withPadding:!1},"range")}return t==="is-relative-to-today"?e.jsx(an,{value:r==null?void 0:r.relative,onChange:n=>o({op:t,relative:n})}):e.jsx(er.StarasiaDate,{size:"sm",input:!1,clearable:!0,value:r!=null&&r.date?new Date(r.date):void 0,onChange:n=>{if(n==null){o({op:t});return}n instanceof Date&&o({op:t,date:n.toISOString()})},withPadding:!1},"single")},an=({value:r,onChange:t})=>{const o=(r==null?void 0:r.direction)??"past",n=(r==null?void 0:r.count)??1,l=(r==null?void 0:r.period)??"week",c=o!=="this",s=Bo({direction:o,count:n,period:l});return e.jsxs(u.Box,{direction:"column",display:"flex",gap:"sm",children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"xs",children:[e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:dt[o]})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:140},children:rn.map(i=>e.jsx(W.MenuItem,{selected:o===i,endIcon:o===i?e.jsx(T.Icon,{name:"Check"}):void 0,onClick:()=>t(i==="this"?{direction:i,period:l}:{direction:i,count:n,period:l}),children:dt[i]},i))})})]}),c&&e.jsx(Xe.Input,{type:"number",size:"sm",min:1,clearable:!1,value:n,onChange:i=>{const a=Number(i.target.value);t({direction:o,count:Number.isFinite(a)&&a>0?a:1,period:l})},style:{width:72}}),e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:l})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:140},children:en.map(i=>e.jsx(W.MenuItem,{selected:l===i,endIcon:l===i?e.jsx(T.Icon,{name:"Check"}):void 0,onClick:()=>t(o==="this"?{direction:o,period:i}:{direction:o,count:n,period:i}),children:i},i))})})]})]}),e.jsx(er.StarasiaDate,{size:"sm",input:!1,disabled:!0,rangedDate:!0,value:s,onChange:()=>{},withPadding:!1},"relative-preview")]})},Eo=18,dn=r=>r.length>Eo?`${r.slice(0,Eo)}...`:r,hn=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=r.type==="dropdown-multiple",s=t.length,i=r.searchable!==!1,[a,d]=h.useState(""),y=r.options,b=typeof r.onSearch=="function",p=(()=>{if(b)return y;const F=a.trim().toLowerCase();return F?y.filter(A=>A.label.toLowerCase().includes(F)):y})(),v=F=>t.some(A=>A.value===F.value),B=F=>{if(!c){o([{label:F.label,value:F.value}]),d("");return}o(v(F)?t.filter(A=>A.value!==F.value):[...t,{label:F.label,value:F.value}])},x=F=>{var A;d(F),(A=r.onSearch)==null||A.call(r,F)},L=s===0?r.label:e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:500},children:[r.label,":"]})," ",e.jsx("span",{style:{fontWeight:400},children:s===1?dn(t[0].label):`${s} Selected`})]});return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:s>0?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:s>0?e.jsx(T.Icon,{name:"Tag",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:L})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{style:{width:260},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:e.jsxs(u.Box,{direction:"column",gap:"sm",children:[i&&e.jsx(lr.Dropdown,{size:"sm",triggerInput:!0,fullWidth:!0,hideChevronIcon:!0,clearable:!0,multiSelect:c,searchAble:!0,searchValue:a,onSearch:x,value:t,onChange:o,placeholder:`Search ${r.label.toLowerCase()}…`}),e.jsx(u.Box,{direction:"column",overflow:"overflow-y-auto",customMaxHeight:"240px",children:r.isLoading?e.jsx(u.Box,{paddingBlock:"sm",paddingInline:"sm",children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"Loading…"})}):p.length===0?e.jsx(u.Box,{paddingBlock:"sm",paddingInline:"sm",children:e.jsx(k.Text,{fontSize:"xs",color:"subtlest",children:"No results"})}):p.map(F=>e.jsx(W.MenuItem,{closeOnSelect:!c,selected:v(F),startIcon:F.avatar,endIcon:v(F)?e.jsx(T.Icon,{name:"Check"}):void 0,description:F.description,onClick:()=>B(F),children:F.label},F.value))})]})})})]})},Mo=18,fn=r=>r.length>Mo?`${r.slice(0,Mo)}...`:r,Lo=({checked:r,indeterminate:t})=>e.jsx("span",{style:{pointerEvents:"none",display:"inline-flex"},children:e.jsx(Ze.Checkbox,{size:"sm",checked:r,readOnly:!0,onChange:()=>{},variant:t?"indeterminate":"select"})}),gn=({field:r,value:t,onChange:o,onClear:n,onRemove:l})=>{const c=new Set(t.map(p=>p.value)),s=t.length,i=r.options.length>0&&r.options.every(p=>c.has(p.value)),a=s>0&&!i,d=p=>{o(c.has(p.value)?t.filter(v=>v.value!==p.value):[...t,{label:p.label,value:p.value}])},y=()=>{o(i?[]:r.options.map(p=>({label:p.label,value:p.value})))},b=s===0?r.label:e.jsxs(e.Fragment,{children:[e.jsxs(k.Text,{as:"span",fontWeight:"semibold",children:[r.label,":"]})," ",e.jsx(k.Text,{as:"span",children:s===1?fn(t[0].label):`${s} Selected`})]});return e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:s>0?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:s>0?e.jsx(T.Icon,{name:"Tag",size:"sm"}):void 0,iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),children:b})}),e.jsx(W.MenuLists,{children:e.jsxs(W.MenuBody,{style:{width:240},title:e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",justify:"space-between",fullWidth:!0,children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtlest",children:r.label}),e.jsx(Ir,{onClear:n,onRemove:l})]}),children:[e.jsx(W.MenuItem,{closeOnSelect:!1,selected:i,onClick:y,startIcon:e.jsx(Lo,{checked:i||a,indeterminate:a}),children:"Select All"}),r.options.map(p=>e.jsx(W.MenuItem,{closeOnSelect:!1,selected:c.has(p.value),onClick:()=>d(p),startIcon:e.jsx(Lo,{checked:c.has(p.value)}),children:p.label},p.value))]})})]})},To=({activeKeys:r,configByKey:t,getValue:o,setValue:n,clearValue:l,removeFilter:c})=>e.jsx(e.Fragment,{children:r.map(s=>{const i=t[s];if(!i)return null;const a=o(i),d=i.locked?void 0:()=>c(s);return i.type==="date"||i.type==="date-compact"?e.jsx(tn,{field:i,value:a,onChange:y=>n(i,y),onClear:()=>l(s),onRemove:d},s):i.type==="checkbox-multiple"?e.jsx(gn,{field:i,value:a||[],onChange:y=>n(i,y),onClear:()=>l(s),onRemove:d},s):e.jsx(hn,{field:i,value:a||[],onChange:y=>n(i,y),onClear:()=>l(s),onRemove:d},s)})}),Io=r=>`${r} Rows`,un=({pagination:r,pageKey:t="page",perPageKey:o="perPage",pageSizeOptions:n=[10,25,50,100],defaultPerPage:l=10,showResultCount:c=!0,showPageSize:s=!0,showPagination:i=!0})=>{var F;const{searchQueries:a,setSearchParams:d,searchParams:y}=Te(),b=y.get(o),p=b?Number(b):l,v=A=>{d({...a,[t]:String(A)})},B=A=>{d({...a,[o]:A,[t]:"1"})},x=(r==null?void 0:r.rangeStart)??(((r==null?void 0:r.currentPage)||0)>1?(((r==null?void 0:r.currentPage)||0)-1)*((r==null?void 0:r.perPage)||0)+1:0),L=(r==null?void 0:r.rangeEnd)??((r==null?void 0:r.totalCurrentPage)!==(r==null?void 0:r.perPage)?r==null?void 0:r.totalData:((r==null?void 0:r.currentPage)||1)*((r==null?void 0:r.totalCurrentPage)||0));return e.jsxs(e.Fragment,{children:[c&&e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"primary",truncate:!0,children:`${x}-${L} of ${((F=r==null?void 0:r.totalData)==null?void 0:F.toLocaleString())||0}`}),s&&e.jsxs(W.Menu,{position:"bottom-left",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconRight:e.jsx(T.Icon,{name:"ChevronSmallDown"}),"aria-label":"Rows per page",children:Io(p)})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{children:n.map(A=>e.jsx(W.MenuItem,{selected:A===p,onClick:()=>B(String(A)),children:Io(A)},A))})})]}),i&&((r==null?void 0:r.totalPage)??0)>1&&e.jsx(u.Box,{direction:"column",display:"flex",align:"center",gap:"sm",paddingRight:"sm",style:{borderRight:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.14))"},children:e.jsx(gr.Pagination,{size:"sm",variant:"neutral",siblingCount:0,currentPage:r!=null&&r.currentPage?Number(r.currentPage):1,totalPages:Number(r==null?void 0:r.totalPage),onPageChange:v})})]})};function yn(r,t,o=!0){h.useEffect(()=>{if(!o)return;const n=l=>{var i;if(l.metaKey||l.ctrlKey||l.altKey||l.key!==r)return;const c=l.target,s=(i=c==null?void 0:c.tagName)==null?void 0:i.toLowerCase();s==="input"||s==="textarea"||c!=null&&c.isContentEditable||(l.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[r,t,o])}const pn=240,Oo=({searchKey:r="q",filterKey:t="filter",pageKey:o="page",placeholder:n="Search",shortcut:l="/",collapsible:c=!0})=>{const{searchParams:s,setSearchParams:i,searchQueries:a}=Te(),d=Lr(r,s,t)||"",[y,b]=h.useState(!c||!!d),[p,v]=h.useState(c&&!d),[B,x]=h.useState(d),L=be.useDebounce(B,350),F=h.useRef(null);h.useEffect(()=>{x(d),d&&b(!0)},[d]),h.useEffect(()=>{y&&v(!1)},[y]),h.useEffect(()=>{L!==d&&pr({value:L,name:r,type:"search",searchQueries:a,setSearchParams:i,filterKey:t,pageKey:o})},[L]);const A=h.useCallback(()=>{b(!0),requestAnimationFrame(()=>{var z;return(z=F.current)==null?void 0:z.focus()})},[]);yn(l,A);const D=()=>{c&&!B&&b(!1)},m=z=>{var I;c&&z.key==="Escape"&&!B&&(b(!1),(I=F.current)==null||I.blur())},H=()=>{y||v(!0)};return e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",gap:"spacing-0",children:[p&&e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Search",size:"sm"}),"aria-label":"Search","aria-expanded":!1,onClick:A}),e.jsxs(u.Box,{onTransitionEnd:H,style:{position:"relative",width:y?pn:0,overflow:"hidden",transition:"width 220ms ease"},children:[e.jsx(Xe.Input,{ref:F,size:"sm",fullWidth:!0,value:B,placeholder:n,leftIcon:e.jsx(T.Icon,{name:"Search",width:16,height:16}),onChange:z=>x(z.target.value),onKeyDown:m,onBlur:D,tabIndex:y?0:-1}),y&&!B&&e.jsx(u.Box,{align:"center",justify:"center",borderColor:"border-subtle",borderWidth:"border",borderStyle:"border-solid",borderRadius:"rounded-xs",paddingInline:"spacing-1",customBackgroundColor:"var(--sa-background-surface-hover, #f1f2f4)",style:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",pointerEvents:"none",minWidth:18,height:18,display:"inline-flex"},children:e.jsx(k.Text,{fontSize:"xs",color:"subtle",children:l})})]})]})},Wo=({columns:r,allVisible:t,onToggle:o,onReorder:n,onSetAllHidden:l})=>{const[c,s]=h.useState(null),[i,a]=h.useState(null),d=()=>{c!==null&&i!==null&&c!==i&&n(c,i),s(null),a(null)},y=(b,p)=>{const v=b+p;v<0||v>=r.length||n(b,v)};return e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:t?"outline":"secondary",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Grid",size:"sm"}),"aria-label":"Customize columns"})}),e.jsx(W.MenuLists,{children:e.jsx(W.MenuBody,{children:e.jsxs(u.Box,{padding:"sm",direction:"column",customWidth:"296px",customMaxHeight:"60vh",overflow:"overflow-hidden",children:[e.jsx(k.Text,{fontWeight:"semibold",color:"primary",children:"Customize Column Table"}),e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",paddingBlock:"md",children:[e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"subtle",children:"Show in table"}),e.jsx(N.Button,{variant:"link",tone:"info",size:"xs",onClick:()=>l(t),children:t?"Hide All":"Show All"})]}),e.jsx(u.Box,{direction:"column",overflow:"overflow-y-auto",children:r.map((b,p)=>{const v=!b.locked,B=i===p&&c!==null&&c!==p;return e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",paddingBlock:"xs",draggable:v,onDragStart:()=>v&&s(p),onDragOver:x=>{x.preventDefault(),a(p)},onDrop:d,onDragEnd:d,style:{minHeight:32,boxShadow:B?"inset 0 2px 0 0 var(--sa-background-brand, #04254f)":void 0},children:[e.jsx(u.Box,{direction:"column",as:"div",align:"center",justify:"center",role:"button",tabIndex:v?0:-1,"aria-label":`Reorder ${b.title}`,"aria-disabled":!v||void 0,color:"icon-subtlest",onKeyDown:x=>{v&&(x.key==="ArrowUp"?(x.preventDefault(),y(p,-1)):x.key==="ArrowDown"&&(x.preventDefault(),y(p,1)))},style:{display:"inline-flex",cursor:v?"grab":"default",opacity:v?1:.4},children:e.jsx(T.Icon,{name:"DragVertical",width:16,height:16})}),b.icon&&e.jsx(u.Box,{direction:"column",align:"center",color:"icon-subtle",style:{display:"inline-flex"},children:b.icon}),e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"primary",truncate:!0,children:b.title}),e.jsx(u.Box,{direction:"column",style:{marginLeft:"auto"},children:e.jsx(sr.Toggle,{size:"sm",checked:b.visible,disabled:b.locked,onChange:()=>o(b.key),"aria-label":`Toggle ${b.title} column`})})]},b.key)})})]})})})]})},Ao=({views:r,onApply:t,onDelete:o,onSave:n})=>{const[l,c]=h.useState(""),s=()=>{const i=l.trim();i&&(n(i),c(""))};return e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:r.length>0?"secondary":"outline",tone:(r.length>0,"neutral"),size:"sm",iconLeft:e.jsx(T.Icon,{name:"Bookmark",size:"sm"}),"aria-label":"Saved views"})}),e.jsxs(W.MenuLists,{style:{width:"260px"},children:[e.jsx(W.MenuBody,{children:e.jsxs(u.Box,{direction:"column",padding:"xs",gap:"sm",children:[e.jsx(k.Text,{fontWeight:"semibold",color:"primary",children:"Saved Views"}),e.jsx(u.Box,{direction:"column",overflow:"overflow-y-auto",children:r.length===0?e.jsx(u.Box,{direction:"column",paddingBlock:"sm",children:e.jsx(k.Text,{fontSize:"sm",color:"subtlest",children:"No saved views yet"})}):r.map(i=>e.jsx(W.MenuItem,{startIcon:e.jsx(T.Icon,{name:"Bookmark"}),onClick:()=>t(i),endIcon:e.jsx(N.Button,{variant:"link",tone:"error",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Trash2"}),"aria-label":`Delete ${i.name}`,onClick:a=>{a.stopPropagation(),o(i.id)}}),children:i.name},i.id))})]})}),e.jsx(W.MenuFooter,{children:e.jsxs(u.Box,{direction:"row",gap:"xs",children:[e.jsx(u.Box,{direction:"column",style:{flex:"1 0 0",minWidth:0},children:e.jsx(Xe.Input,{size:"sm",fullWidth:!0,placeholder:"Save current view as…",value:l,onChange:i=>c(i.target.value),onKeyDown:i=>{i.key==="Enter"&&s()}})}),e.jsx(N.Button,{variant:"primary",tone:"brand",size:"sm",disabled:!l.trim(),onClick:s,children:"Save"})]})})]})]})},bn=({isOpen:r,onClose:t,configs:o,activeKeys:n,configByKey:l,hasActiveFilter:c,onToggle:s,onReset:i,getValue:a,setValue:d,clearValue:y,removeFilter:b})=>{const p=n.length;return e.jsx(kr.Drawer,{position:"bottom",isShow:r,onHide:t,children:e.jsxs(u.Box,{direction:"column",customMaxHeight:"85vh",style:{minHeight:280},children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",paddingInline:"md",paddingBlock:"sm",style:{borderBottom:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.14))"},children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"xs",children:[e.jsx(k.Text,{fontWeight:"semibold",color:"primary",children:"Filter"}),p>0&&e.jsxs(k.Text,{fontSize:"sm",color:"subtle",children:["(",p,")"]})]}),e.jsx(N.Button,{variant:"link",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"Cross"}),"aria-label":"Close filter",onClick:t})]}),e.jsxs(u.Box,{direction:"column",gap:"lg",padding:"md",overflow:"overflow-y-auto",style:{flex:"1 1 auto",minHeight:0},children:[p>0&&e.jsxs(u.Box,{direction:"column",gap:"sm",children:[e.jsx(k.Text,{fontSize:"xs",fontWeight:"medium",color:"subtlest",children:"Filter aktif"}),e.jsx(u.Box,{direction:"row",display:"flex",wrap:"wrap",gap:"sm",align:"center",children:e.jsx(To,{activeKeys:n,configByKey:l,getValue:a,setValue:d,clearValue:y,removeFilter:b})})]}),o.length>0&&e.jsxs(u.Box,{direction:"column",gap:"sm",children:[e.jsx(k.Text,{fontSize:"xs",fontWeight:"medium",color:"subtlest",children:"Tambah filter"}),e.jsx(u.Box,{direction:"column",children:o.map(v=>{const B=n.includes(v.key),x=!!v.locked;return e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",gap:"sm",paddingBlock:"sm",style:{opacity:x?.5:1,borderTop:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.08))"},children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",style:{minWidth:0},children:[v.icon&&e.jsx(u.Box,{direction:"column",align:"center",color:"icon-subtle",style:{display:"inline-flex"},children:v.icon}),e.jsx(k.Text,{fontSize:"sm",color:"primary",truncate:!0,children:v.label})]}),e.jsx(sr.Toggle,{size:"sm",checked:B||x,disabled:x,onChange:()=>s(v.key),"aria-label":`Toggle ${v.label}`})]},v.key)})})]})]}),e.jsxs(u.Box,{direction:"row",display:"flex",gap:"sm",paddingInline:"md",paddingBlock:"sm",style:{borderTop:"1px solid var(--sa-border-subtle, rgba(11, 18, 14, 0.14))"},children:[e.jsx(u.Box,{direction:"column",style:{flex:"1 1 0"},children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"md",fullWidth:!0,disabled:!c,onClick:i,children:"Reset"})}),e.jsx(u.Box,{direction:"column",style:{flex:"1 1 0"},children:e.jsx(N.Button,{variant:"primary",tone:"brand",size:"md",fullWidth:!0,onClick:t,children:"Selesai"})})]})]})})},Cn=r=>`${r} Rows`,vn=({perPageKey:r,pageKey:t,pageSizeOptions:o,defaultPerPage:n=10,showPageSize:l})=>{const{searchQueries:c,setSearchParams:s,searchParams:i}=Te(),a=i.get(r),d=a?Number(a):n,y=b=>{s({...c,[r]:b,[t]:"1"})};return l?e.jsxs(W.Menu,{position:"bottom-right",children:[e.jsx(W.MenuButton,{children:e.jsx(N.Button,{variant:"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"MenuVertical",size:"sm"}),"aria-label":"More options"})}),e.jsx(W.MenuLists,{children:e.jsxs(W.MenuBody,{style:{minWidth:200},children:[e.jsx(u.Box,{paddingInline:"sm",paddingBlock:"xs",children:e.jsx(k.Text,{fontSize:"xs",fontWeight:"medium",color:"subtlest",children:"Rows per page"})}),o.map(b=>e.jsx(W.MenuItem,{selected:b===d,endIcon:b===d?e.jsx(T.Icon,{name:"Check"}):void 0,onClick:()=>y(String(b)),children:Cn(b)},b))]})})]}):null},xn=r=>{var we;const{withPadding:t,configs:o,activeKeys:n,configByKey:l,hasActiveFilter:c,toggleFilter:s,removeFilter:i,getValue:a,setValue:d,clearValue:y,onReset:b,searchable:p,searchKey:v,filterKey:B,pageKey:x,searchPlaceholder:L,searchShortcut:F,searchCollapsible:A,pagination:D,perPageKey:m,pageSizeOptions:H,defaultPerPage:z,showPagination:I,showResultCount:E,showPageSize:U,hasColumns:X,orderedColumns:G,allVisible:R,onToggleVisibility:_,onReorder:K,onSetAllHidden:te,showSavedViews:q,savedViews:j,onApplyView:Z,onDeleteView:le,onSaveView:Ce,leadingActions:ve}=r,[he,ge]=h.useState(!1),{searchQueries:xe,setSearchParams:Ee}=Te(),Oe=(D==null?void 0:D.rangeStart)??(((D==null?void 0:D.currentPage)||0)>1?(((D==null?void 0:D.currentPage)||0)-1)*((D==null?void 0:D.perPage)||0)+1:1),Ve=(D==null?void 0:D.rangeEnd)??((D==null?void 0:D.totalCurrentPage)!==(D==null?void 0:D.perPage)?D==null?void 0:D.totalData:((D==null?void 0:D.currentPage)||1)*((D==null?void 0:D.totalCurrentPage)||0)),Pe=$e=>{Ee({...xe,[x]:String($e)})},ke=E||I&&!!(D!=null&&D.totalPage),je=()=>{b(),ge(!1)};return e.jsxs(u.Box,{direction:"column",gap:"sm",fullWidth:!0,paddingTop:t?"sm":void 0,paddingBottom:t?"sm":void 0,paddingLeft:t?"md":void 0,paddingRight:t?"md":void 0,role:"toolbar","aria-label":"Filter bar",children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",wrap:"wrap",gap:"sm",fullWidth:!0,overflow:"overflow-auto",children:[p&&e.jsx(Oo,{searchKey:v,filterKey:B,pageKey:x,placeholder:L,shortcut:F,collapsible:A}),e.jsx(N.Button,{variant:c?"secondary":"outline",tone:"neutral",size:"sm",iconLeft:e.jsx(T.Icon,{name:"FilterHorizontal"}),onClick:()=>ge(!0),"aria-label":"Open filters",children:c?`Filter: ${n.length}`:null}),e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",style:{marginLeft:"auto"},children:[ve,q&&e.jsx(Ao,{views:j,onApply:Z,onDelete:le,onSave:Ce}),X&&e.jsx(Wo,{columns:G,allVisible:R,onToggle:_,onReorder:K,onSetAllHidden:te}),e.jsx(vn,{perPageKey:m,pageKey:x,pageSizeOptions:H,defaultPerPage:z,showPageSize:U})]})]}),ke&&e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",justify:"space-between",gap:"sm",fullWidth:!0,children:[E?e.jsx(k.Text,{fontSize:"sm",fontWeight:"medium",color:"primary",truncate:!0,children:`${Oe}-${Ve} of ${((we=D==null?void 0:D.totalData)==null?void 0:we.toLocaleString())||0}`}):e.jsx(u.Box,{direction:"column"}),I&&!!(D!=null&&D.totalPage)&&e.jsx(gr.Pagination,{size:"xs",variant:"neutral",siblingCount:0,currentPage:D!=null&&D.currentPage?Number(D.currentPage):1,totalPages:Number(D.totalPage),onPageChange:Pe})]}),e.jsx(bn,{isOpen:he,onClose:()=>ge(!1),configs:o,activeKeys:n,configByKey:l,hasActiveFilter:c,onToggle:s,onReset:je,getValue:a,setValue:d,clearValue:y,removeFilter:i})]})},wn=({withPadding:r=!1,filterConfigs:t=[],filterKey:o="filter",activeFilterKey:n="filters",pageKey:l="page",perPageKey:c="perPage",pageSizeOptions:s=[25,50,100],defaultPerPage:i,showPagination:a=!0,showResultCount:d=!0,showPageSize:y=!0,searchable:b=!1,searchKey:p="q",searchPlaceholder:v="Search",searchShortcut:B="/",searchPosition:x="right",searchCollapsible:L=!0,pagination:F,columns:A=[],onColumnsChange:D,columnsState:m,scopeId:H,savedViews:z,persistLastState:I=!0,persistSearch:E=!0,storage:U=ct,onReset:X,leadingActions:G})=>{const R=H??(z==null?void 0:z.scopeId),{activeKeys:_,configByKey:K,hasActiveFilter:te,toggleFilter:q,removeFilter:j,getValue:Z,setValue:le,clearValue:Ce,clearAll:ve}=nt({configs:t,filterKey:o,activeFilterKey:n,pageKey:l,searchKey:p}),he=Zl({columns:A,scopeId:R,storage:U,onColumnsChange:D,value:m}),ge=Gl({scopeId:R,storage:U,snapshotKeys:[n,o,c],pageKey:l,getColumns:()=>he.state,applyColumns:he.applyState}),xe=Ul({scopeId:R,storage:U,snapshotKeys:[n,o,l],enabled:I,filterKey:o,searchKey:p,persistSearch:E}),Ee=Jl({scopeId:R,storage:U,perPageKey:c,pageSizeOptions:s,enabled:I});Xl({enabled:I&&!!R,snapshotKeys:[n,o,l],perPageKey:c,readSnapshot:xe.read,readPerPage:Ee.read});const Oe=i??s[0]??25,Ve=!!(z!=null&&z.enabled)&&ge.enabled,Pe=()=>{ve(),xe.clear(),X==null||X()},ke=be.useMediaQuery("md"),je=b?e.jsx(Oo,{searchKey:p,filterKey:o,pageKey:l,placeholder:v,shortcut:B,collapsible:L}):null;return ke?e.jsxs(u.Box,{display:"flex",direction:"row",align:"center",gap:"sm",wrap:"wrap",fullWidth:!0,paddingTop:r?"sm":void 0,paddingBottom:r?"sm":void 0,paddingLeft:r?"md":void 0,paddingRight:r?"md":void 0,role:"toolbar","aria-label":"Filter bar",children:[e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",style:{flex:"1 1 0",minWidth:0},children:[e.jsx($l,{configs:t,activeKeys:_,onToggle:q,hasActiveFilter:te,onReset:Pe}),x==="left"&&je,e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",overflow:"overflow-x-auto",style:{flex:"1 1 0",minWidth:0},children:[e.jsx(To,{activeKeys:_,configByKey:K,getValue:Z,setValue:le,clearValue:Ce,removeFilter:j}),te&&e.jsx(N.Button,{variant:"link",tone:"brand",size:"sm",onClick:Pe,children:"Reset"})]})]}),e.jsxs(u.Box,{direction:"row",display:"flex",align:"center",gap:"sm",children:[G,e.jsx(un,{pagination:F,pageKey:l,perPageKey:c,pageSizeOptions:s,defaultPerPage:Oe,showPagination:a,showResultCount:d,showPageSize:y}),x==="right"&&je,Ve&&e.jsx(Ao,{views:ge.views,onApply:ge.applyView,onDelete:ge.deleteView,onSave:ge.saveView}),A.length>0&&e.jsx(Wo,{columns:he.orderedColumns,allVisible:he.allVisible,onToggle:he.toggleVisibility,onReorder:he.reorder,onSetAllHidden:he.setAllHidden})]})]}):e.jsx(xn,{withPadding:r,configs:t,activeKeys:_,configByKey:K,hasActiveFilter:te,toggleFilter:q,removeFilter:j,getValue:Z,setValue:le,clearValue:Ce,onReset:Pe,searchable:b,searchKey:p,filterKey:o,pageKey:l,searchPlaceholder:v,searchShortcut:B,searchCollapsible:L,pagination:F,perPageKey:c,pageSizeOptions:s,defaultPerPage:Oe,showPagination:a,showResultCount:d,showPageSize:y,hasColumns:A.length>0,orderedColumns:he.orderedColumns,allVisible:he.allVisible,onToggleVisibility:he.toggleVisibility,onReorder:he.reorder,onSetAllHidden:he.setAllHidden,showSavedViews:Ve,savedViews:ge.views,onApplyView:ge.applyView,onDeleteView:ge.deleteView,onSaveView:ge.saveView,leadingActions:G})},Dn=r=>{if(!Array.isArray(r)||r.length===0)return;const t=r[0];return(t==null?void 0:t.value)!=null?String(t.value):void 0},Sn=r=>{if(!Array.isArray(r)||r.length===0)return;const t=r.map(o=>(o==null?void 0:o.value)!=null?String(o.value):null).filter(o=>o!=null);return t.length?t:void 0},kn=(r,t)=>{switch(r.type){case"dropdown":case"radio":return Dn(t);case"dropdown-multiple":case"checkbox-multiple":return Sn(t);case"date":return t instanceof Date?t.toISOString():void 0;case"date-compact":return t;default:return}},zo=(r,t)=>{if(r==null||r==="")return t;const o=Number(r);return Number.isFinite(o)&&o>0?o:t},Bn=r=>{const{filterConfigs:t,filterKey:o="filter",activeFilterKey:n="filters",pageKey:l="page",perPageKey:c="perPage",searchKey:s="q",defaultPage:i=1,defaultPerPage:a=10,paramKeys:d,serialize:y}=r,{activeKeys:b,configByKey:p,hasActiveFilter:v,getValue:B}=nt({configs:t,filterKey:o,activeFilterKey:n,pageKey:l,searchKey:s}),{searchParams:x}=Te(),L=x.toString();return h.useMemo(()=>{const A={},D={},m=zo(x.get(l),i),H=zo(x.get(c),a);A[(d==null?void 0:d.page)??"page"]=m,A[(d==null?void 0:d.perPage)??"perPage"]=H;const z=Lr(s,x,o)||"";z&&(A[(d==null?void 0:d.search)??"search"]=z);let I=!1;for(const E of b){const U=p[E];if(!U)continue;const X=B(U);D[E]=X;const G=y==null?void 0:y[E],R=G?G(X):kn(U,X);if(R==null||Array.isArray(R)&&R.length===0)continue;const _=(d==null?void 0:d[E])??E;A[_]=R,I=!0}return{params:A,raw:D,hasActiveFilter:v||!!z||I}},[L,b.join("|"),o,n,l,c,s,i,a,d,y,p])},mn=["dropdown","dropdown-multiple","checkbox-multiple","radio"],Fn=({filterConfigs:r,filterKey:t,activeFilterKey:o,pageKey:n,searchKey:l})=>{const{configByKey:c,getValue:s,setValue:i,removeFilter:a,clearAll:d,hasActiveFilter:y}=nt({configs:r,filterKey:t,activeFilterKey:o,pageKey:n,searchKey:l}),b=(F,A)=>{var m;const D=F.options;return((m=D==null?void 0:D.find(H=>H.value===A))==null?void 0:m.label)??A},p=h.useCallback(F=>{const A=c[F];if(!A)return[];const D=s(A);return Array.isArray(D)?D.map(m=>String(m.value)):[]},[c,s]),v=h.useCallback((F,A)=>{const D=c[F];if(!D||!mn.includes(D.type))return;const m=Array.isArray(A)?A:[A];if(m.length===0){a(F);return}i(D,m.map(H=>({label:b(D,H),value:H})))},[c,i,a]),B=h.useCallback((F,A)=>{const D=p(F);v(F,D.includes(A)?D.filter(m=>m!==A):[...D,A])},[p,v]),x=h.useCallback((F,A)=>p(F).includes(A),[p]),L=h.useCallback(F=>a(F),[a]);return{set:v,toggle:B,clear:L,clearAll:d,isActive:x,values:p,hasActiveFilter:y}},En=(r,t)=>{if(!r)return{};const{fromKey:o,toKey:n,opKey:l}=t,c={};switch(r.op){case"is":case"is-before":case"is-after":case"is-on-or-before":case"is-on-or-after":return r.date&&(c[o]=new Date(r.date).toISOString()),l&&(c[l]=r.op),c;case"is-between":return r.from&&(c[o]=new Date(r.from).toISOString()),r.to&&(c[n]=new Date(r.to).toISOString()),c;case"is-relative-to-today":{if(!r.relative)return c;const{from:s,to:i}=Bo(r.relative);return c[o]=s.toISOString(),c[n]=i.toISOString(),c}case"is-empty":case"is-not-empty":return l&&(c[l]=r.op==="is-empty"?"empty":"not-empty"),c;default:return c}},Ho=({children:r,borderRadius:t,height:o})=>{const n=h.useRef(null),[l,c]=h.useState("100vh");return h.useEffect(()=>{if(o)return;const s=()=>{if(n.current){const i=n.current.getBoundingClientRect().top;c(`calc(100vh - ${i}px)`)}};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[o]),e.jsx(u.Box,{ref:n,fullWidth:!0,borderStyle:"border-solid",borderWidth:"border",borderColor:"border-base",borderRadius:t||"rounded-xs",style:{height:o??l,display:"flex",flexDirection:"column"},children:r})},Vo=({action:r,rightContent:t,leftContent:o,headerSlot:n,advanceFilter:l,showFilter:c=!0})=>{const s=be.useMediaQuery("md"),i=c?e.jsx(Do,{...l}):null,a=()=>r?h.isValidElement(r)?r:e.jsx(u.Box,{style:{display:"flex",flexDirection:s?"row":"column",gap:"8px",width:s?"auto":"100%",textWrap:"nowrap"},children:r.map(({title:d,icon:y,buttonProps:b,onClick:p},v)=>!d&&!y?null:e.jsx(N.Button,{fullWidth:!s,iconLeft:y?e.jsx(T.Icon,{name:y}):void 0,onClick:p,...b,children:d},`action-${v}`))}):null;return e.jsx(u.Box,{style:{display:"flex",width:"100%",justifyContent:"space-between",alignItems:"center",paddingLeft:"8px",paddingRight:"8px",paddingTop:"8px",paddingBottom:"8px",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)",flexShrink:0,position:"relative",zIndex:10,flexDirection:s?"row":"column-reverse",gap:"16px"},children:n?n({filter:i}):e.jsxs(e.Fragment,{children:[e.jsxs(u.Box,{style:{display:"flex",gap:"8px",flexDirection:"row",alignItems:"center",flex:1,minWidth:0},children:[i,o]}),e.jsxs(u.Box,{style:{display:"flex",gap:"8px",flexDirection:"row",alignItems:"center",flexShrink:0},children:[t,a()]})]})})},Mn=({totalData:r,withMarginBottom:t=!0,withMarginTop:o=!0})=>e.jsxs(u.Box,{style:{display:"flex",gap:"4px",flexDirection:"row",alignItems:"center",marginBottom:t?"16px":void 0,marginTop:o?"16px":void 0},children:[e.jsxs(He.Body1,{props:{color:"gray-500"},children:["Total data:"," "]}),e.jsx(He.Body1,{children:r||0})]}),Po=({pagination:r,pageKey:t="page",perPageKey:o="perPage",defaultPerPage:n=10,showPagination:l=!0,totalData:c})=>{const{searchQueries:s,setSearchParams:i,searchParams:a}=Te(),d=a.get(o),y=B=>{i({...s,[t]:String(B)})},b=B=>{i({...s,[o]:B,[t]:"1"})},p=(r==null?void 0:r.rangeStart)??(((r==null?void 0:r.currentPage)||0)>1?(((r==null?void 0:r.currentPage)||0)-1)*((r==null?void 0:r.perPage)||0)+1:1),v=(r==null?void 0:r.rangeEnd)??((r==null?void 0:r.totalCurrentPage)!==(r==null?void 0:r.perPage)?r==null?void 0:r.totalData:((r==null?void 0:r.currentPage)||1)*((r==null?void 0:r.totalCurrentPage)||0));return e.jsx(u.Box,{style:{display:"flex",width:"100%",flexDirection:"row",justifyContent:"space-between",alignItems:"center",paddingLeft:"16px",paddingRight:"16px",paddingTop:"8px",paddingBottom:"8px",borderTop:"1px solid var(--sa-border-subtle, #0b120e24)",flexShrink:0},children:l?e.jsxs(e.Fragment,{children:[e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",gap:"8px",alignItems:"center",textWrap:"nowrap"},children:[e.jsx(k.Text,{children:"Rows Per Page: "}),e.jsx(lr.Dropdown,{dropdownLists:[{label:"5",value:"5"},{label:"10",value:"10"},{label:"25",value:"25"},{label:"50",value:"50"},{label:"100",value:"100"}],onChange:B=>{b(B[0].value)},value:d?[{label:`${d} per row`,value:d}]:[{label:`${n} per row`,value:`${n}`}],defaultValue:d?[{label:`${d} per row`,value:d}]:[{label:`${n} per row`,value:`${n}`}]}),e.jsx(k.Text,{children:`${p}-${v} of ${(r==null?void 0:r.totalData)||0}`})]}),e.jsx(gr.Pagination,{currentPage:r!=null&&r.currentPage?Number(r==null?void 0:r.currentPage):1,totalPages:r!=null&&r.totalPage?Number(r==null?void 0:r.totalPage):1,onPageChange:y})]}):e.jsx(Mn,{totalData:c,withMarginBottom:!1,withMarginTop:!1})})},jo=({filter:r,columnTitle:t})=>{const[o,n]=h.useState(!1),l=h.useRef(null),c=h.useRef(null),s=h.useRef(null),[i,a]=h.useState(""),[d,y]=h.useState({top:0,left:0}),b=r.selectedValues,p=h.useMemo(()=>i?r.options.filter(x=>x.label.toLowerCase().includes(i.toLowerCase())):r.options,[r.options,i]);h.useEffect(()=>{if(o&&c.current){const x=c.current.getBoundingClientRect(),L=280,F={top:x.bottom+8};r.position==="left"||x.left+L>window.innerWidth?F.right=window.innerWidth-x.right:F.left=x.left,y(F)}},[o,r.position]),h.useEffect(()=>{o&&s.current?setTimeout(()=>{var x;return(x=s.current)==null?void 0:x.focus()},50):a("")},[o]),h.useEffect(()=>{const x=L=>{l.current&&!l.current.contains(L.target)&&c.current&&!c.current.contains(L.target)&&n(!1)};return o&&document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[o]);const v=x=>{const L=b.includes(x)?b.filter(F=>F!==x):[...b,x];r.onFilterChange(L)},B=()=>r.onFilterChange([]);return e.jsxs(u.Box,{direction:"column",style:{position:"relative"},children:[e.jsx(u.Box,{ref:c,style:{display:"flex",flexDirection:"row",alignItems:"center",cursor:"pointer"},onClick:x=>{var L;x.stopPropagation(),o||(L=r.onOpen)==null||L.call(r),n(F=>!F)},children:e.jsx(T.Icon,{name:o?"ChevronUp":"ChevronDown",size:"sm",style:{color:b.length>0?"var(--sa-color-brand-500, #1a4fa0)":"var(--sa-text-subtle, #8c8f97)"}})}),o&&e.jsxs(u.Box,{ref:l,style:{position:"fixed",top:`${d.top}px`,...d.left!==void 0?{left:`${d.left}px`}:{right:`${d.right}px`},backgroundColor:"white",borderRadius:"4px",minWidth:"280px",maxHeight:"400px",display:"flex",flexDirection:"column",zIndex:9999,animation:"fadeInDropdown 0.15s ease-out",border:"1px solid var(--sa-border-subtle, #0b120e24)"},children:[e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",paddingTop:"12px",paddingBottom:"12px",paddingLeft:"16px",paddingRight:"16px",borderBottom:"1px solid var(--sa-border-subtle, #0b120e24)"},children:[e.jsxs(k.Text,{fontSize:"sm",fontWeight:"semibold",color:"gray-700",children:["Filter ",t]}),b.length>0&&e.jsx(u.Box,{direction:"column",style:{cursor:"pointer"},children:e.jsx(k.Text,{fontSize:"xs",color:"primary",fontWeight:"semibold",onClick:x=>{x.stopPropagation(),B()},children:"CLEAR"})})]}),!r.hideSearch&&e.jsx(u.Box,{direction:"column",style:{paddingLeft:"16px",paddingRight:"16px",paddingTop:"8px",paddingBottom:"8px"},children:e.jsx(Xe.Input,{ref:s,placeholder:`Search ${t.toLowerCase()}...`,leftIcon:e.jsx(T.Icon,{name:"Search",size:"sm"}),value:i,onChange:x=>a(x.target.value),style:{fontSize:"14px"}})}),e.jsx(u.Box,{direction:"column",className:"ts-filter-dropdown-options",style:{overflowY:"auto",maxHeight:"250px",paddingLeft:"8px",paddingRight:"8px"},children:r.isLoadingOptions?e.jsxs(u.Box,{style:{paddingTop:"40px",paddingBottom:"40px",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column"},children:[e.jsx(T.Icon,{name:"Loading",size:"lg",style:{color:"var(--sa-background-brand, #04254f)",animation:"spin 1s linear infinite"}}),e.jsx(k.Text,{fontSize:"sm",color:"gray-500",style:{textAlign:"center",marginTop:"8px"},children:"Loading options..."})]}):p.length>0?e.jsx(u.Box,{direction:"column",style:{gap:"2px",paddingTop:"4px",paddingBottom:"4px"},children:p.map(x=>e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"8px",paddingTop:"8px",paddingBottom:"8px",paddingLeft:"8px",paddingRight:"8px",cursor:"pointer",borderRadius:"8px",transition:"all 0.2s ease",backgroundColor:b.includes(x.value)?"var(--sa-color-brand-50, #e6edf6)":"transparent"},onClick:L=>{L.stopPropagation(),v(x.value)},onMouseEnter:L=>{b.includes(x.value)||(L.currentTarget.style.backgroundColor="var(--sa-background-primary, #ffffff)"),L.currentTarget.style.transform="translateX(2px)"},onMouseLeave:L=>{L.currentTarget.style.backgroundColor=b.includes(x.value)?"var(--sa-color-brand-50, #e6edf6)":"transparent",L.currentTarget.style.transform="translateX(0)"},children:[e.jsx(Ze.Checkbox,{checked:b.includes(x.value),onChange:()=>{}}),e.jsx(k.Text,{fontSize:"sm",fontWeight:b.includes(x.value)?"medium":"normal",color:b.includes(x.value)?"primary":"gray-700",children:x.label})]},x.value))}):e.jsxs(u.Box,{style:{paddingTop:"40px",paddingBottom:"40px",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column"},children:[e.jsx(T.Icon,{name:"Search",size:"lg",style:{color:"var(--sa-text-subtle, #8c8f97)"}}),e.jsx(k.Text,{fontSize:"sm",color:"gray-500",style:{textAlign:"center",marginTop:"8px"},children:"No results found"})]})}),b.length>0&&e.jsx(u.Box,{direction:"column",style:{paddingTop:"8px",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"16px",borderTop:"1px solid var(--sa-border-subtle, #0b120e24)",backgroundColor:"var(--sa-color-brand-50, #e6edf6)",marginTop:"auto"},children:e.jsxs(u.Box,{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"4px"},children:[e.jsx(u.Box,{direction:"column",style:{backgroundColor:"var(--sa-background-brand, #04254f)",borderRadius:"12px",padding:"2px 8px",fontSize:"11px",fontWeight:600,color:"white"},children:b.length}),e.jsxs(k.Text,{fontSize:"xs",color:"primary",fontWeight:"medium",children:["item",b.length>1?"s":""," selected"]})]})})]})]})},Ln=({direction:r})=>{const t="var(--sa-text-primary, #292a2e)",o="var(--sa-text-subtle, #8c8f97)",n=r==="asc"?t:o,l=r==="desc"?t:o,c=r==="asc"?1:.45,s=r==="desc"?1:.45;return e.jsxs("span",{style:{display:"inline-flex",flexDirection:"column",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:0},"aria-hidden":!0,children:[e.jsx("svg",{width:"8",height:"5",viewBox:"0 0 8 5",style:{color:n,opacity:c,marginBottom:1},children:e.jsx("path",{d:"M4 0 L8 5 L0 5 Z",fill:"currentColor"})}),e.jsx("svg",{width:"8",height:"5",viewBox:"0 0 8 5",style:{color:l,opacity:s},children:e.jsx("path",{d:"M0 0 L8 0 L4 5 Z",fill:"currentColor"})})]})},Tn=({frozen:r})=>e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:r?"currentColor":"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:r?"M7 11V7a5 5 0 0 1 10 0v4":"M7 11V7a5 5 0 0 1 9.9-1"})]}),ht="var(--sa-background-primary, #ffffff)",No="var(--sa-background-primary-inverse, #f8f8f8)",_o=({columns:r,records:t,handleDetail:o,handleUpdate:n,handleDelete:l,isLoading:c,visibleHandleDelete:s,visibleHandleUpdate:i,visibleHandleDetail:a,showHeadBorder:d=!1,scrollParentRef:y,frozenCount:b=0,onFrozenCountChange:p,customActions:v,actionsOrder:B=["detail","update","delete","custom"],customEmptyState:x,enableColumnResize:L=!1,defaultColumnWidths:F,onColumnWidthsChange:A,defaultMinColumnWidth:D=60,sort:m,defaultSort:H,onSortChange:z,showActionDivider:I=!1})=>{const E=m!==void 0,[U,X]=h.useState(H??null),G=E?m??null:U,R=P=>{if(P.sortKey)return P.sortKey;if(typeof P.accessor=="string")return P.accessor},_=P=>{const S=R(P);if(!S)return;let O;!G||G.key!==S?O={key:S,direction:"asc"}:G.direction==="asc"?O={key:S,direction:"desc"}:O=null,E||X(O),z==null||z(O)},te=[o,n,l].filter(P=>P!==void 0).length,q=!!v,j=!!o||!!n||!!l||q,Z="var(--sa-border-subtle, #0b120e24)",le=`1px solid ${Z}`,Ce=`inset 1px 0 0 ${Z}`,ve=`inset -1px 0 0 ${Z}`,he=te===3?q?"178px":"140px":te===2?q?"140px":"102px":te===1?q?"112px":"74px":q?"74px":"",ge=(P,S)=>{if(!S)return P;if(typeof S=="function")return S(P);if(typeof S=="string")return P[S]},[xe,Ee]=h.useState(!1);h.useEffect(()=>{if(!(y!=null&&y.current))return;const P=y.current;Ee(P.scrollHeight>P.clientHeight)},[t,y]);const Oe=h.useRef(null),[Ve,Pe]=h.useState([]),[ke,je]=h.useState(()=>F??{}),we=h.useRef(null);h.useLayoutEffect(()=>{if(!b||!Oe.current){Pe([]);return}const P=Array.from(Oe.current.querySelectorAll("thead tr th")),S=[];let O=0;P.forEach((V,J)=>{S[J]=O,J<b&&(O+=V.offsetWidth)}),Pe(S)},[b,r,t,ke]);const $e=P=>{p&&p(P<b?P:P+1)},De=(P,S)=>{const O=ke[P];if(O!==void 0){const V=`${O}px`;return{width:V,minWidth:V,maxWidth:V}}return S?{width:S}:{}},Ne=P=>L&&(P.resizable??!0),dr=(P,S)=>{P.preventDefault(),P.stopPropagation();const O=P.currentTarget.closest("th");if(!O)return;const V=Math.round(O.getBoundingClientRect().width);we.current={colIndex:S,startX:P.clientX,startWidth:V};const J=document.body.style.userSelect,de=document.body.style.cursor;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const Me=oe=>{var Ke;const pe=we.current;if(!pe)return;const Le=((Ke=r[pe.colIndex])==null?void 0:Ke.minWidth)??D,Se=Math.max(Le,pe.startWidth+(oe.clientX-pe.startX));je(Re=>Re[pe.colIndex]===Se?Re:{...Re,[pe.colIndex]:Se})},fe=()=>{document.removeEventListener("mousemove",Me),document.removeEventListener("mouseup",fe),document.body.style.userSelect=J,document.body.style.cursor=de,we.current=null,A&&je(oe=>(A(oe),oe))};document.addEventListener("mousemove",Me),document.addEventListener("mouseup",fe)};return e.jsx("div",{ref:Oe,children:e.jsxs(Q.Table,{fullWidth:!0,children:[e.jsx(Q.Thead,{style:{height:"40px",whiteSpace:"nowrap"},children:e.jsxs(Q.Tr,{children:[r.map((P,S)=>{var Zr,hr;const O=b>0&&S<b,V=Ve[S]??0,J=Ne(P),Me=S===r.length-1&&j&&I,fe=R(P),oe=!!P.sortable&&!!fe,pe=oe&&(G==null?void 0:G.key)===fe?G.direction:null,Le=P.title||((Zr=P.accessor)==null?void 0:Zr.toString())||"",Se=(hr=P.headerTooltip)!=null&&hr.showIcon?e.jsx(T.Icon,{name:"InfoCircle",size:"xs",style:{flexShrink:0,color:"var(--sa-icon-subtle, #8c8f97)",opacity:.75}}):null,Ke=e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Le}),Re=oe?e.jsxs("button",{type:"button",onClick:()=>_(P),title:pe==="asc"?"Sorted ascending — click to sort descending":pe==="desc"?"Sorted descending — click to clear":"Click to sort ascending",style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:4,background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",cursor:"pointer",textAlign:P.textAlign==="text-right"?"right":P.textAlign==="text-center"?"center":"left"},children:[Ke,Se,e.jsx(Ln,{direction:pe})]}):e.jsxs("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:4},children:[Ke,Se]});return e.jsxs(Q.Th,{style:{position:"sticky",top:0,left:O?V:void 0,zIndex:O?4:2,paddingLeft:S===0?"12px":"",borderRight:d&&!Me&&!O?le:void 0,borderBottom:d?le:void 0,boxShadow:d&&O?ve:void 0,backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",textAlign:P.textAlign==="text-right"?"right":P.textAlign==="text-center"?"center":"left",...De(S,P.width)},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",justifyContent:"space-between",minWidth:0},children:[P.headerTooltip?e.jsx(Be.Tooltip,{label:P.headerTooltip.content,position:"bottom",children:Re}):Re,P.filter&&e.jsx(jo,{filter:P.filter,columnTitle:P.title}),p&&e.jsx("button",{onClick:()=>$e(S),title:O?"Unfreeze column":"Freeze column",style:{background:"none",border:"none",cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",flexShrink:0,color:O?"var(--sa-background-brand, #04254f)":"var(--sa-text-subtle, #8c8f97)",opacity:O?1:.45,transition:"opacity 0.15s"},children:e.jsx(Tn,{frozen:O})})]}),J&&e.jsx("div",{onMouseDown:wr=>dr(wr,S),onClick:wr=>wr.stopPropagation(),role:"separator","aria-orientation":"vertical",title:"Drag to resize",style:{position:"absolute",top:0,right:-3,width:6,height:"100%",cursor:"col-resize",userSelect:"none",zIndex:5,touchAction:"none"}})]},`table-head-${S}`)}),j?e.jsx(Q.Th,{style:{backgroundColor:"var(--sa-background-primary-inverse, #f8f8f8)",position:"sticky",top:0,right:0,zIndex:3,borderBottom:d?le:void 0,boxShadow:d&&I?Ce:void 0}}):null]})}),e.jsx(Q.Tbody,{children:c?e.jsx(Q.Tr,{children:e.jsx(Q.Td,{colSpan:r.length+1,children:e.jsxs(u.Box,{direction:"column",style:{gap:"16px"},children:[e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"}),e.jsx(ze.Skeleton,{variant:"list"})]})})}):!(t!=null&&t.length)&&x?e.jsx(Q.Tr,{children:e.jsx(Q.Td,{colSpan:r.length+1,children:x})}):t==null?void 0:t.map((P,S)=>e.jsxs(Q.Tr,{style:{transition:"background-color 0.3s ease",padding:0,borderBottom:S===t.length-1&&xe?void 0:"1px solid var(--sa-border-subtle, #0b120e24)"},onMouseEnter:O=>{const V=O.currentTarget;V.style.backgroundColor=No,Array.from(V.querySelectorAll("td")).forEach(J=>{J.style.position==="sticky"&&(J.style.backgroundColor=No)})},onMouseLeave:O=>{const V=O.currentTarget;V.style.backgroundColor="",Array.from(V.querySelectorAll("td")).forEach(J=>{J.style.position==="sticky"&&(J.style.backgroundColor=ht)})},children:[r.map((O,V)=>{const J=O.render?O.render(P,S,t):ge(P,O.accessor),de=b>0&&V<b,Me=Ve[V]??0,fe=ke[V]!==void 0,oe=de&&V===b-1;return e.jsx(Q.Td,{style:{position:de?"sticky":void 0,left:de?Me:void 0,zIndex:de?1:void 0,backgroundColor:de?ht:void 0,transition:de?"background-color 0.3s ease":void 0,paddingLeft:V===0?"12px":"",whiteSpace:"nowrap",overflow:fe?"hidden":void 0,borderLeft:O.showBorderLeft?le:void 0,borderRight:O.showBorderRight?le:void 0,boxShadow:oe?ve:void 0,textAlign:O.textAlign==="text-right"?"right":O.textAlign==="text-center"?"center":"left",...De(V,O.width)},children:typeof J=="string"?e.jsx(k.Text,{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",textAlign:O.textAlign==="text-right"?"right":O.textAlign==="text-center"?"center":"left"},children:J}):J},`row-${S}-col-${V}`)}),j?e.jsx(Q.Td,{style:{width:he,position:"sticky",right:0,zIndex:1,backgroundColor:ht,boxShadow:I?Ce:void 0,transition:"background-color 0.3s ease"},children:e.jsx(ne.Flex,{direction:"row",align:"center",justify:"center",gap:"sm",children:B.map(O=>{const V=S===t.length-1?"top":"bottom";return O==="detail"&&o&&(a==null?void 0:a(P))!==!1?e.jsx(Be.Tooltip,{label:"Detail",position:V,children:e.jsx(N.Button,{size:"xs",variant:"outline",tone:"neutral",onClick:()=>o(P.id,P),iconLeft:e.jsx(T.Icon,{name:"DocumentClean",size:"sm",style:{color:"var(--sa-text-subtle, #8c8f97)"}})})},"detail"):O==="update"&&n&&(i==null?void 0:i(P))!==!1?e.jsx(Be.Tooltip,{label:"Update",position:V,children:e.jsx(N.Button,{size:"xs",variant:"outline",tone:"neutral",onClick:()=>n(P),iconLeft:e.jsx(T.Icon,{name:"Edit1",size:"sm",style:{color:"var(--sa-text-subtle, #8c8f97)"}})})},"update"):O==="delete"&&l&&(s==null?void 0:s(P))!==!1?e.jsx(Be.Tooltip,{label:"Delete",position:V,children:e.jsx(N.Button,{size:"xs",variant:"outline",tone:"neutral",onClick:()=>l(P.id,P),iconLeft:e.jsx(T.Icon,{name:"Trash1",size:"sm",style:{color:"var(--sa-color-error-600, #c9184a)"}})})},"delete"):O==="custom"?e.jsx(h.Fragment,{children:v==null?void 0:v(P)},"custom"):null})})}):null]},`${P}${S}`))})]})})},In=({wrapperProps:r,dataTableProps:t,headerProps:o,footerProps:n})=>{var b;const l=h.useRef(null),[c,s]=h.useState((t==null?void 0:t.defaultFrozenCount)??0),i=(o==null?void 0:o.show)??!0,a=h.useRef(null),d=(b=t==null?void 0:t.pagination)==null?void 0:b.totalData;typeof d=="number"&&(a.current=d);const y=(n==null?void 0:n.showFooter)??(d===void 0?a.current!==0:d!==0);return e.jsxs(Ho,{...r,children:[i&&e.jsx(Vo,{...o}),e.jsx(u.Box,{direction:"column",ref:l,style:{flex:1,overflowY:"auto",overflowX:"auto"},children:t?e.jsx(_o,{...t,scrollParentRef:l,frozenCount:t!=null&&t.enableFreezeColumns?c:0,onFrozenCountChange:t!=null&&t.enableFreezeColumns?s:void 0}):null}),y&&e.jsx(Po,{pagination:t==null?void 0:t.pagination,pageKey:t==null?void 0:t.pageKey,perPageKey:t==null?void 0:t.perPageKey,defaultPerPage:t==null?void 0:t.defaultPerPage,showPagination:t==null?void 0:t.showPagination,totalData:n==null?void 0:n.totalData})]})};function On(r){return h.memo(r)}const Wn=On(In),qo=200,ft="1px solid var(--sa-border-subtle, #0b120e24)",An=({sortDir:r,frozen:t})=>r==="asc"?e.jsx(T.Icon,{name:"ChevronSmallUp"}):r==="desc"?e.jsx(T.Icon,{name:"ChevronSmallDown"}):t?e.jsx(T.Icon,{name:"LockOn",size:"xs"}):e.jsx(T.Icon,{name:"Filter",size:"xs"}),Ar=({icon:r,label:t,active:o,danger:n,onClick:l})=>{const c=n?"var(--sa-text-error, #a4133c)":"var(--sa-text-primary, #292a2e)";return e.jsxs("button",{type:"button",onClick:l,style:{display:"flex",alignItems:"center",gap:12,width:"100%",padding:"8px 12px",background:o?"var(--sa-background-brand-subtlest, #e6edf6)":"none",border:"none",cursor:"pointer",font:"inherit",color:c,textAlign:"left"},onMouseEnter:s=>{o||(s.currentTarget.style.background="var(--sa-background-primary-inverse, #f8f8f8)")},onMouseLeave:s=>{s.currentTarget.style.background=o?"var(--sa-background-brand-subtlest, #e6edf6)":"none"},children:[e.jsx(T.Icon,{name:r,size:"sm",style:{color:c,flexShrink:0}}),e.jsx(k.Text,{as:"span",style:{color:c},children:t})]})},Zo=({active:r,canSort:t,canHide:o,sortDir:n,frozen:l,onSort:c,onClearSort:s,onToggleFreeze:i,onHide:a})=>{const[d,y]=h.useState(!1),b=h.useRef(null),p=h.useRef(null),[v,B]=h.useState({top:0,left:0});h.useEffect(()=>{if(d&&b.current){const L=b.current.getBoundingClientRect(),F=L.left+qo>window.innerWidth;B({top:L.bottom+6,...F?{right:window.innerWidth-L.right}:{left:L.left}})}},[d]),h.useEffect(()=>{if(!d)return;const L=F=>{p.current&&!p.current.contains(F.target)&&b.current&&!b.current.contains(F.target)&&y(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[d]);const x=L=>{L(),y(!1)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:b,type:"button",className:"sa-tl-menu-trigger","data-active":r||d?"true":"false",onClick:L=>{L.stopPropagation(),y(F=>!F)},title:"Column options",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,borderRadius:"var(--sa-radii-sm, 6px)",border:ft,background:"var(--sa-background-primary, #ffffff)",cursor:"pointer",color:"var(--sa-text-subtle, #8c8f97)",flexShrink:0},children:e.jsx(An,{sortDir:n,frozen:l})}),d&&e.jsxs(u.Box,{ref:p,onClick:L=>L.stopPropagation(),style:{position:"fixed",top:`${v.top}px`,...v.left!==void 0?{left:`${v.left}px`}:{right:`${v.right}px`},minWidth:qo,backgroundColor:"var(--sa-background-primary, #ffffff)",border:ft,borderRadius:"var(--sa-radii-sm, 6px)",boxShadow:"var(--sa-shadow-xl, 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a)",zIndex:9999,padding:"4px",display:"flex",flexDirection:"column"},children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(Ar,{icon:"ChevronUp",label:"Ascending",active:n==="asc",onClick:()=>x(()=>n==="asc"?s():c("asc"))}),e.jsx(Ar,{icon:"ChevronDown",label:"Descending",active:n==="desc",onClick:()=>x(()=>n==="desc"?s():c("desc"))}),e.jsx("div",{style:{borderTop:ft,margin:"4px 0"}})]}),e.jsx(Ar,{icon:"Pin1",label:l?"Unfreeze":"Freeze",active:l,onClick:()=>x(i)}),o&&e.jsx(Ar,{icon:"EyeClosed",label:"Hide column",danger:!0,onClick:()=>x(a)})]})]})},br="1px solid var(--sa-border-subtle, #0b120e24)",zn="var(--sa-text-subtle, #8c8f97)",ar="var(--sa-background-neutral, #f0f1f2)",Go="2px 0 4px -2px var(--sa-border-subtle, #0b120e24)",Cr=40,gt="var(--sa-background-brand-subtlest)",zr={display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Qo="sa-table-layout-styles",Hn=()=>{if(typeof document>"u"||document.getElementById(Qo))return;const r=document.createElement("style");r.id=Qo,r.textContent=`
|
|
2
2
|
.sa-table-layout tbody td {
|
|
3
3
|
transition: background-color 0.15s ease;
|
|
4
4
|
background-color: var(--sa-tl-bg, transparent);
|