import { IGXA } from "@intelligentgraphics/igd.core";
import { CatalogViewContentFilter } from "./Types";
const filterFunctions = {
    [CatalogViewContentFilter.onlyFolderLike]: (items) => items.filter(item => item.Type === IGXA.EItemType.MultiArticle ||
        item.Type === IGXA.EItemType.Folder),
    [CatalogViewContentFilter.onlyArticleLike]: (items) => items.filter(item => item.Type === IGXA.EItemType.ArticleCom ||
        item.Type === IGXA.EItemType.ArticleGfx ||
        item.Type === IGXA.EItemType.Impression ||
        item.Type === IGXA.EItemType.Set),
    [CatalogViewContentFilter.onlyArticle]: items => items.filter(item => item.Type === IGXA.EItemType.ArticleGfx ||
        item.Type === IGXA.EItemType.ArticleCom),
};
export const defaultFetchContent = async (params, catalogFetcher) => {
    if (params.addableTargetId !== undefined) {
        return catalogFetcher.getAddables(params.path, params.addableTargetId);
    }
    const content = await catalogFetcher.getPathContent(params.path, {
        flat: params.flat,
    });
    if (params.filterContent !== undefined) {
        const filter = typeof params.filterContent === "function"
            ? params.filterContent
            : filterFunctions[params.filterContent];
        return filter(content);
    }
    return content;
};
