import assertUnreachable from '../utils/assertUnreachable';
export const isExploreSearchResult = (value) => 'explore' in value;
export const isFieldSearchResult = (value) => 'table' in value;
export const isTableErrorSearchResult = (value) => 'explore' in value && 'validationErrors' in value;
export const isSavedChartSearchResult = (value) => 'chartSource' in value && value.chartSource === 'saved';
export const isSqlChartSearchResult = (value) => 'chartSource' in value && value.chartSource === 'sql';
export const isDashboardSearchResult = (value) => 'charts' in value;
export const getSearchResultId = (meta) => {
    if (!meta || isTableErrorSearchResult(meta)) {
        return '';
    }
    if (isExploreSearchResult(meta)) {
        if (isFieldSearchResult(meta)) {
            return `${meta.explore}.${meta.table}.${meta.name}`;
        }
        return `${meta.explore}.${meta.name}`;
    }
    return meta.uuid;
};
export var SearchItemType;
(function (SearchItemType) {
    SearchItemType["DASHBOARD"] = "dashboard";
    SearchItemType["DASHBOARD_TAB"] = "dashboard_tab";
    SearchItemType["CHART"] = "saved_chart";
    SearchItemType["SQL_CHART"] = "sql_chart";
    SearchItemType["SPACE"] = "space";
    SearchItemType["TABLE"] = "table";
    SearchItemType["FIELD"] = "field";
    SearchItemType["PAGE"] = "page";
    SearchItemType["DATA_APP"] = "data_app";
})(SearchItemType || (SearchItemType = {}));
export function getSearchItemTypeFromResultKey(searchResultKey) {
    switch (searchResultKey) {
        case 'spaces':
            return SearchItemType.SPACE;
        case 'dashboards':
            return SearchItemType.DASHBOARD;
        case 'savedCharts':
            return SearchItemType.CHART;
        case 'tables':
            return SearchItemType.TABLE;
        case 'fields':
            return SearchItemType.FIELD;
        case 'pages':
            return SearchItemType.PAGE;
        case 'sqlCharts':
            return SearchItemType.SQL_CHART;
        case 'dashboardTabs':
            return SearchItemType.DASHBOARD_TAB;
        case 'dataApps':
            return SearchItemType.DATA_APP;
        default:
            return assertUnreachable(searchResultKey, `unexpected search result key: ${searchResultKey}`);
    }
}
//# sourceMappingURL=search.js.map