"use client";
'use strict';

var jsxRuntime = require('react/jsx-runtime');
var filter = require('../../../icons/assets/filter.svg.cjs');
var filters = require('../../../types/filters.cjs');
var button = require('../../button/button.cjs');
var dropdownMenu = require('../../dropdown-menu/dropdown-menu.cjs');
var filterChip = require('../../filter-chip/filter-chip.cjs');
var flex = require('../../flex/flex.cjs');
var iconButton = require('../../icon-button/icon-button.cjs');
var useDataTable = require('../hooks/useDataTable.cjs');
var useFilters = require('../hooks/useFilters.cjs');

function AddFilter({ columnList = [], appliedFiltersSet, onAddFilter }) {
    const availableFilters = columnList?.filter(col => !appliedFiltersSet.has(col.id));
    return availableFilters.length > 0 ? (jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(dropdownMenu.DropdownMenu.Trigger, { asChild: true, children: appliedFiltersSet.size > 0 ? (jsxRuntime.jsx(iconButton.IconButton, { size: 4, children: jsxRuntime.jsx(filter.ReactComponent, {}) })) : (jsxRuntime.jsx(button.Button, { variant: 'text', size: 'small', leadingIcon: jsxRuntime.jsx(filter.ReactComponent, {}), color: 'neutral', children: "Filter" })) }), jsxRuntime.jsx(dropdownMenu.DropdownMenu.Content, { children: availableFilters?.map(column => {
                    const columnDef = column.columnDef;
                    const id = columnDef.accessorKey || column.id;
                    return (jsxRuntime.jsx(dropdownMenu.DropdownMenu.Item, { onClick: () => onAddFilter(column), children: columnDef.header || id }, id));
                }) })] })) : null;
}
function Filters() {
    const { table, tableQuery } = useDataTable.useDataTable();
    const columns = table?.getAllColumns();
    const { onAddFilter, handleRemoveFilter, handleFilterValueChange, handleFilterOperationChange } = useFilters.useFilters();
    const columnList = columns?.filter(column => column.columnDef.enableColumnFilter);
    const appliedFiltersSet = new Set(tableQuery?.filters?.map(filter => filter.name));
    const appliedFilters = tableQuery?.filters?.map(filter => {
        const columnDef = columns?.find(col => {
            const columnDef = col.columnDef;
            const id = columnDef.accessorKey || col.id;
            return id === filter.name;
        })?.columnDef;
        return {
            filterType: columnDef?.filterType || filters.FilterType.string,
            label: columnDef?.header || '',
            options: columnDef?.filterOptions || [],
            ...filter
        };
    }) || [];
    return (jsxRuntime.jsxs(flex.Flex, { gap: 3, children: [jsxRuntime.jsx(flex.Flex, { gap: 3, children: appliedFilters.map(filter => (jsxRuntime.jsx(filterChip.FilterChip, { label: filter.label, value: filter.value, onRemove: () => handleRemoveFilter(filter.name), onValueChange: value => handleFilterValueChange(filter.name, value), onOperationChange: operator => handleFilterOperationChange(filter.name, operator), columnType: filter.filterType, options: filter.options }, filter.name))) }), jsxRuntime.jsx(AddFilter, { columnList: columnList, appliedFiltersSet: appliedFiltersSet, onAddFilter: onAddFilter })] }));
}

exports.Filters = Filters;
//# sourceMappingURL=filters.cjs.map
