"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.projectResultToCardModel = exports.projectToCardModel = void 0;
const get_family_1 = require("../content/get-family");
const internalContentUtils_1 = require("../content/_internal/internalContentUtils");
const getCardModelUrl_1 = require("../urls/getCardModelUrl");
/**
 * Convert a project entity into a card view model that can
 * be consumed by the suite of hub gallery components
 *
 * @param project project entity
 * @param context auth & portal information
 * @param opts view model options
 */
const projectToCardModel = (project, context, opts) => {
    const { actionLinks = [], baseUrl = "", locale = "en-US", target = "self", } = opts || {};
    const titleUrl = (0, getCardModelUrl_1.getCardModelUrlFromEntity)(project, context, target, baseUrl);
    return Object.assign(Object.assign(Object.assign({}, getSharedProjectCardModel(project, locale)), { actionLinks,
        titleUrl }), (project.thumbnailUrl && { thumbnailUrl: project.thumbnailUrl }));
};
exports.projectToCardModel = projectToCardModel;
/**
 * Convert a project hub search result into a card view model that
 * can be consumed by the suite of hub gallery components
 *
 * @param searchResult hub project search result
 * @param opts view model options
 */
const projectResultToCardModel = (searchResult, opts) => {
    const { actionLinks = [], baseUrl = "", locale = "en-US", target = "self", } = opts || {};
    const titleUrl = (0, getCardModelUrl_1.getCardModelUrlFromResult)(searchResult, target, baseUrl);
    return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, getSharedProjectCardModel(searchResult, locale)), { actionLinks }), (!isNaN(searchResult.index) && { index: searchResult.index })), { titleUrl }), (searchResult.links.thumbnail && {
        thumbnailUrl: searchResult.links.thumbnail,
    }));
};
exports.projectResultToCardModel = projectResultToCardModel;
/**
 * Given a project entity OR hub serach result, construct the
 * project's shared card view model properties
 *
 * @param entityOrSearchResult project entity or hub search result
 * @param locale internationalization locale
 */
const getSharedProjectCardModel = (entityOrSearchResult, locale) => {
    var _a, _b;
    const additionalInfo = [
        {
            i18nKey: "type",
            value: entityOrSearchResult.type,
        },
        {
            i18nKey: "dateUpdated",
            value: entityOrSearchResult.updatedDate.toLocaleDateString(locale),
        },
        ...(((_a = entityOrSearchResult.tags) === null || _a === void 0 ? void 0 : _a.length)
            ? [
                {
                    i18nKey: "tags",
                    value: entityOrSearchResult.tags.join(", "),
                },
            ]
            : []),
        ...(((_b = entityOrSearchResult.categories) === null || _b === void 0 ? void 0 : _b.length)
            ? [
                {
                    i18nKey: "categories",
                    value: (0, internalContentUtils_1.getShortenedCategories)(entityOrSearchResult.categories).join(", "),
                },
            ]
            : []),
        {
            i18nKey: "dateCreated",
            value: entityOrSearchResult.createdDate.toLocaleDateString(locale),
        },
    ];
    return {
        access: entityOrSearchResult.access,
        badges: [],
        id: entityOrSearchResult.id,
        family: (0, get_family_1.getFamily)(entityOrSearchResult.type),
        source: entityOrSearchResult.owner,
        summary: entityOrSearchResult.summary,
        title: entityOrSearchResult.name,
        type: entityOrSearchResult.type,
        additionalInfo,
    };
};
//# sourceMappingURL=view.js.map