var _a;
import { __awaiter, __generator } from "tslib";
import { IGXA } from "@intelligentgraphics/igd.core";
import { CatalogViewContentFilter } from "./Types";
var filterFunctions = (_a = {},
    _a[CatalogViewContentFilter.onlyFolderLike] = function (items) {
        return items.filter(function (item) {
            return item.Type === IGXA.EItemType.MultiArticle ||
                item.Type === IGXA.EItemType.Folder;
        });
    },
    _a[CatalogViewContentFilter.onlyArticleLike] = function (items) {
        return items.filter(function (item) {
            return item.Type === IGXA.EItemType.ArticleCom ||
                item.Type === IGXA.EItemType.ArticleGfx ||
                item.Type === IGXA.EItemType.Impression ||
                item.Type === IGXA.EItemType.Set;
        });
    },
    _a[CatalogViewContentFilter.onlyArticle] = function (items) {
        return items.filter(function (item) {
            return item.Type === IGXA.EItemType.ArticleGfx ||
                item.Type === IGXA.EItemType.ArticleCom;
        });
    },
    _a);
export var defaultFetchContent = function (params, catalogFetcher) { return __awaiter(void 0, void 0, void 0, function () {
    var content, filter;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                if (params.addableTargetId !== undefined) {
                    return [2 /*return*/, catalogFetcher.getAddables(params.path, params.addableTargetId)];
                }
                return [4 /*yield*/, catalogFetcher.getPathContent(params.path, {
                        flat: params.flat,
                    })];
            case 1:
                content = _a.sent();
                if (params.filterContent !== undefined) {
                    filter = typeof params.filterContent === "function"
                        ? params.filterContent
                        : filterFunctions[params.filterContent];
                    return [2 /*return*/, filter(content)];
                }
                return [2 /*return*/, content];
        }
    });
}); };
