import { useMemo } from "react";
import { useEditorContext } from "../context/editor-context.js";
import { makeTableData } from "../utils/table.js";
import { useSortTableItems } from "./useSortTableItems.js";
export function useTableData(tableName) {
    const inputs = useEditorContext();
    // type inference is going wrong because some of the table data types have a "type" field.
    // even though this "type" field is not relevant to the table data type, typescript insists on including it in its type narrowing logic.
    const tableData = useMemo(() => {
        return makeTableData(tableName, inputs);
    }, [inputs, tableName]);
    const { sortedItems, sortHandler } = useSortTableItems(tableData);
    return useMemo(() => ({
        tableData: sortedItems ?? [],
        sortHandler,
    }), [sortedItems, sortHandler]);
}
//# sourceMappingURL=useTableData.js.map