import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-DE3RlOCf.js";import{r}from"./apiClient-JXzuem8t.js";import{t as i}from"./SimpleSelectField-l7FTdbHV.js";var a=e(t(),1);function o(e,t){let[n,r]=(0,a.useState)(t),[i,o]=(0,a.useState)(!1),[s,c]=(0,a.useState)(null),[l,u]=(0,a.useState)({}),[d,f]=(0,a.useState)(1),[p,m]=(0,a.useState)(25),h=(0,a.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:i,error:s,filters:l,page:d,pageSize:p,applyFilters:(0,a.useCallback)(e=>{u(e),f(1),h(e,1,p)},[h,p]),goToPage:(0,a.useCallback)(e=>{f(e),h(l,e,p)},[h,l,p]),changePageSize:(0,a.useCallback)(e=>{m(e),f(1),h(l,1,e)},[h,l]),refetch:(0,a.useCallback)(()=>h(l,d,p),[h,l,d,p])}}var s=e(n(),1);function c({value:e,onChange:t}){let[n,o]=(0,a.useState)([]);return(0,a.useEffect)(()=>{r.get(`/api/v1/auth/users/`,{params:{page_size:200}}).then(e=>o(e.results??[])).catch(()=>{})},[]),(0,s.jsx)(i,{name:`user`,label:``,value:e||void 0,onValueChange:e=>t(e||``),options:n.map(e=>({id:e.username,name:e.username})),showCustomize:!1})}function l({value:e,onChange:t}){let[n,o]=(0,a.useState)([]);return(0,a.useEffect)(()=>{r.get(`/api/v1/audit/reports/content-types/`).then(e=>o(Array.isArray(e)?e:[])).catch(()=>{})},[]),(0,s.jsx)(i,{name:`content_type`,label:``,value:e||void 0,onValueChange:e=>t(e||``),options:n.map(e=>({id:e,name:e})),showCustomize:!1})}function u({filters:e,onApply:t,onExport:n,loading:r}){let[o,u]=(0,a.useState)({}),d=(e,t)=>{u(n=>({...n,[e]:t}))};return(0,s.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3 p-4 bg-card border rounded-lg mb-4`,children:[e.map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-[140px]`,children:[(0,s.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:e.label}),e.type===`user_select`?(0,s.jsx)(c,{value:o[e.key]??``,onChange:t=>d(e.key,t)}):e.type===`content_type_select`?(0,s.jsx)(l,{value:o[e.key]??``,onChange:t=>d(e.key,t)}):e.type===`select`?(0,s.jsx)(i,{name:e.key,label:``,value:o[e.key]||void 0,onValueChange:t=>d(e.key,t||``),options:e.options?.map(e=>({id:e.value,name:e.label}))??[],showCustomize:!1}):(0,s.jsx)(`input`,{type:e.type,className:`h-8 rounded border border-input bg-background px-2 text-sm`,value:o[e.key]??``,onChange:t=>d(e.key,t.target.value)})]},e.key)),(0,s.jsxs)(`div`,{className:`flex gap-2 ml-auto mt-auto`,children:[(0,s.jsx)(`button`,{className:`h-8 px-4 rounded bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50`,onClick:()=>t(o),disabled:r,children:r?`Loading…`:`Apply`}),(0,s.jsx)(`button`,{className:`h-8 px-3 rounded border border-input bg-background text-sm`,onClick:()=>{u({}),t({})},children:`Clear`}),n&&(0,s.jsx)(`button`,{className:`h-8 px-3 rounded border border-input bg-background text-sm`,onClick:n,children:`Export XLSX`})]})]})}export{o as n,u as t};