import{r as c,j as s,bh as y,B as d,b1 as t}from"./index-BX768Frx.js";import{S as F}from"./select-fQyM9_P4.js";function v({items:p,defaultSelected:n,onApply:h}){const[f,x]=c.useState(!1),[a,r]=c.useState(n);c.useEffect(()=>{f&&r(n)},[f,n]);const b=(e,l)=>{r(o=>({...o,[e]:l}))},j=()=>{h(a)},g=()=>{const e=Object.fromEntries(p.map(l=>[l.id,null]));r(e)},i=Object.values(n).filter(Boolean).length,u=Object.values(a).filter(Boolean).length,S=i?`${i} applied ${i>1?"filters":"filter"}`:"No filters applied";return s.jsxs(y,{onOpenChange:x,children:[s.jsx(d,{"aria-label":"Open filters",leftIcon:"filter",size:"md",variant:"secondary",children:"Filter"}),s.jsx(t,{isDismissable:!0,"aria-label":"Filters",children:s.jsxs(t.Dialog,{children:[s.jsx(t.Header,{title:"Filters",description:S}),s.jsx(t.Content,{className:"flex flex-col gap-4",children:p.map(e=>{const l=`Filter by ${e.label?.toLowerCase()}`;return s.jsx(F,{...e,isInvalid:e.isInvalid&&!!a[String(e.id)],"aria-label":l,placeholder:l,className:"w-80",selectedKey:a[String(e.id)],onSelectionChange:o=>b(String(e.id),String(o))},e.id)})}),s.jsxs(t.Footer,{className:"flex justify-between",children:[s.jsx(d,{onPress:g,variant:"tertiary",isDisabled:!u,children:"Reset filters"}),s.jsx(d,{onPress:j,slot:"close",children:"Apply"})]})]})})]})}export{v as F};
