import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-CIxEorsV.js";import{r}from"./apiClient-CHudnEwS.js";var i=e(t(),1);function a(e,t){let[n,r]=(0,i.useState)(t),[a,o]=(0,i.useState)(!1),[s,c]=(0,i.useState)(null),[l,u]=(0,i.useState)({}),[d,f]=(0,i.useState)(1),[p,m]=(0,i.useState)(25),h=(0,i.useCallback)(async(t,n,i)=>{o(!0),c(null);try{let a=await e({...t,page:n,page_size:i});r(a)}catch(e){c(e instanceof Error?e.message:`Failed to load`)}finally{o(!1)}},[e]);return{data:n,loading:a,error:s,filters:l,page:d,pageSize:p,applyFilters:(0,i.useCallback)(e=>{u(e),f(1),h(e,1,p)},[h,p]),goToPage:(0,i.useCallback)(e=>{f(e),h(l,e,p)},[h,l,p]),changePageSize:(0,i.useCallback)(e=>{m(e),f(1),h(l,1,e)},[h,l]),refetch:(0,i.useCallback)(()=>h(l,d,p),[h,l,d,p])}}var o=e(n(),1);function s({value:e,onChange:t}){let[n,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{r.get(`/api/v1/auth/users/`,{params:{page_size:200}}).then(e=>a(e.results??[])).catch(()=>{})},[]),(0,o.jsxs)(`select`,{className:`h-8 rounded border border-input bg-background px-2 text-sm`,value:e,onChange:e=>t(e.target.value),children:[(0,o.jsx)(`option`,{value:``,children:`All Users`}),n.map(e=>(0,o.jsx)(`option`,{value:e.username,children:e.username},e.username))]})}function c({value:e,onChange:t}){let[n,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{r.get(`/api/v1/audit/reports/content-types/`).then(e=>a(Array.isArray(e)?e:[])).catch(()=>{})},[]),(0,o.jsxs)(`select`,{className:`h-8 rounded border border-input bg-background px-2 text-sm min-w-[160px]`,value:e,onChange:e=>t(e.target.value),children:[(0,o.jsx)(`option`,{value:``,children:`All Modules`}),n.map(e=>(0,o.jsx)(`option`,{value:e,children:e},e))]})}function l({filters:e,onApply:t,onExport:n,loading:r}){let[a,l]=(0,i.useState)({}),u=(e,t)=>{l(n=>({...n,[e]:t}))};return(0,o.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3 p-4 bg-card border rounded-lg mb-4`,children:[e.map(e=>(0,o.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-[140px]`,children:[(0,o.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:e.label}),e.type===`user_select`?(0,o.jsx)(s,{value:a[e.key]??``,onChange:t=>u(e.key,t)}):e.type===`content_type_select`?(0,o.jsx)(c,{value:a[e.key]??``,onChange:t=>u(e.key,t)}):e.type===`select`?(0,o.jsxs)(`select`,{className:`h-8 rounded border border-input bg-background px-2 text-sm`,value:a[e.key]??``,onChange:t=>u(e.key,t.target.value),children:[(0,o.jsx)(`option`,{value:``,children:`All`}),e.options?.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,o.jsx)(`input`,{type:e.type,className:`h-8 rounded border border-input bg-background px-2 text-sm`,value:a[e.key]??``,onChange:t=>u(e.key,t.target.value)})]},e.key)),(0,o.jsxs)(`div`,{className:`flex gap-2 ml-auto mt-auto`,children:[(0,o.jsx)(`button`,{className:`h-8 px-4 rounded bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50`,onClick:()=>t(a),disabled:r,children:r?`Loading…`:`Apply`}),(0,o.jsx)(`button`,{className:`h-8 px-3 rounded border border-input bg-background text-sm`,onClick:()=>{l({}),t({})},children:`Clear`}),n&&(0,o.jsx)(`button`,{className:`h-8 px-3 rounded border border-input bg-background text-sm`,onClick:n,children:`Export XLSX`})]})]})}export{a as n,l as t};