var L=Object.defineProperty,O=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var j=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var g=(r,t,a)=>t in r?L(r,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[t]=a,l=(r,t)=>{for(var a in t||(t={}))z.call(t,a)&&g(r,a,t[a]);if(j)for(var a of j(t))E.call(t,a)&&g(r,a,t[a]);return r},o=(r,t)=>O(r,P(t));import{j as s}from"./radixui-DBNNXUn7.js";import{r as u}from"./router-ZPDjRWWZ.js";import{B as p,q as v,I,T as S,r as A,s as B,v as G}from"./index-C1-9bQes.js";import{L as $}from"./label-wWBD5Ozj.js";import{P as q,a as C,b as R}from"./popover-D_hLgl2z.js";import{F as X,X as f,f as D}from"./icons-DvPHMWAM.js";function W({filtersConfig:r,onFilterApply:t,onFilterClear:a,initialFilters:x={}}){const[n,d]=u.useState(()=>{const e=r.reduce((c,i)=>o(l({},c),{[i.key]:""}),{});return l(l({},e),x)}),[N,h]=u.useState(!1);u.useEffect(()=>{d(e=>l(l({},e),x))},[x]);function b(e){const{id:c,value:i}=e.target;d(F=>o(l({},F),{[c]:i}))}function y(){t(n),h(!1)}function k(){const e=r.reduce((c,i)=>o(l({},c),{[i.key]:""}),{});d(e),a==null||a(),h(!1)}function w(){const e=r.reduce((c,i)=>o(l({},c),{[i.key]:""}),{});d(e),a==null||a()}const m=Object.values(n).some(e=>e!==""),T=Object.values(n).filter(e=>e!=="").length;return s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(q,{open:N,onOpenChange:h,children:[s.jsx(C,{asChild:!0,children:s.jsxs(p,{size:"sm",variant:"outline",className:`flex items-center gap-2 px-4 ${m?"border-primary text-primary":""}`,children:[s.jsx(X,{className:"h-4 w-4"}),m?"Filtros aplicados":"Filtros",m&&s.jsx("span",{className:"bg-primary text-primary-foreground ml-1 rounded-full px-2 py-0.5 text-xs",children:T})]})}),s.jsx(R,{className:"w-96",align:"start",side:"bottom",children:s.jsxs("div",{className:"grid gap-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsx("p",{className:"text-muted-foreground text-sm",children:"Selecciona la opción por la cual deseas filtrar"})}),s.jsx(v,{}),s.jsx("div",{className:"grid gap-4",children:r.map(e=>s.jsxs("div",{className:"grid gap-2",children:[s.jsx($,{htmlFor:e.key,children:e.label}),s.jsx(I,{id:e.key,value:n[e.key]||"",placeholder:`Filtrar por ${e.label.toLowerCase()}`,className:"h-8",onChange:b})]},e.key))}),s.jsx(v,{}),s.jsxs("div",{className:"flex justify-between",children:[s.jsxs(p,{size:"sm",variant:"ghost",className:"bg-neutral-100 hover:bg-neutral-200",onClick:k,children:[s.jsx(f,{className:"mr-2 h-4 w-4"}),"Limpiar filtros"]}),s.jsxs(p,{size:"sm",onClick:y,children:[s.jsx(D,{className:"mr-2 h-4 w-4"}),"Aplicar filtros"]})]})]})})]}),m&&s.jsx(S,{children:s.jsxs(A,{children:[s.jsx(B,{asChild:!0,children:s.jsx(p,{size:"sm",variant:"ghost",className:"h-6 w-6 rounded-full border border-neutral-200 bg-neutral-100 p-0 hover:bg-neutral-200",onClick:w,children:s.jsx(f,{className:"h-3 w-3 text-neutral-600"})})}),s.jsx(G,{children:s.jsx("p",{children:"Limpiar todos los filtros"})})]})})]})}export{W as G};
