import React from "react";
import { RuntimeContext } from "../RuntimeContext";
export function useTableDetail(source) {
    const tables = RuntimeContext.useSelectState((state) => state.schema.tables);
    const views = RuntimeContext.useSelectState((state) => state.schema.views);
    const insights = RuntimeContext.useSelectState((state) => state.schema.insights);
    const table = React.useMemo(() => tables.find((table) => table.name === source.target), [tables, source]);
    const view = React.useMemo(() => views.find((view) => view.name === source.target), [views, source]);
    const insight = React.useMemo(() => insights.find((insight) => insight.name === source.target), [insights, source]);
    const data = React.useMemo(() => {
        if (insight) {
            return Object.assign(Object.assign({}, insight), { type: "insight" });
        }
        else if (view) {
            return Object.assign(Object.assign({}, view), { type: "view" });
        }
        else if (table) {
            return Object.assign(Object.assign({}, table), { type: "table" });
        }
        return undefined;
    }, [insight, view, table]);
    return data;
}
//# sourceMappingURL=useTableDetail.js.map