import { op } from 'arquero';
import { useMemo } from 'react';
import { useSimpleDropdownOptions } from './useSimpleDropdownOptions.js';
export function useColumnValueOptions(column, table, values, filter) {
    const vals = useMemo(()=>{
        if (!column || !table || !column || column.trim().length === 0) {
            return [];
        }
        const getFallback = ()=>{
            const columnNamesArray = table.columnNames().filter((e)=>e === column);
            if (columnNamesArray.length !== 0) {
                const result = table.rollup({
                    [column]: op.array_agg_distinct(column)
                }).get(column, 0);
                return result ?? [];
            }
            return [];
        };
        const list = values ? values : getFallback();
        return filter ? list.filter(filter) : list;
    }, [
        column,
        table,
        values,
        filter
    ]);
    return useSimpleDropdownOptions(vals);
}
