import { getShortenedCategories } from "../content/_internal/internalContentUtils";
import { getCardModelUrlFromEntity, getCardModelUrlFromResult, } from "../urls/getCardModelUrl";
import { getFamily } from "../content/get-family";
/**
 * Convert an initiative entity in a card view model
 * that can be consumed by the suite of hub gallery components
 *
 * @param initiative initiative entity
 * @param context auth & portal information
 * @param opts view model options
 */
export const initiativeToCardModel = (initiative, context, opts) => {
    const { actionLinks = [], baseUrl = "", locale = "en-US", target = "self", } = opts || {};
    const titleUrl = getCardModelUrlFromEntity(initiative, context, target, baseUrl);
    return Object.assign(Object.assign(Object.assign({}, getSharedInitiativeCardModel(initiative, locale)), { actionLinks,
        titleUrl }), (initiative.thumbnailUrl && { thumbnailUrl: initiative.thumbnailUrl }));
};
/**
 * Conver an initiative search result into a card view model
 * that can be consumed by the suite of hub gallery components
 *
 * @param searchResult hub initiative search result
 * @param opts view model options
 */
export const initiativeResultToCardModel = (searchResult, opts) => {
    const { actionLinks = [], baseUrl = "", locale = "en-US", target = "self", } = opts || {};
    const titleUrl = getCardModelUrlFromResult(searchResult, target, baseUrl);
    return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, getSharedInitiativeCardModel(searchResult, locale)), { actionLinks }), (!isNaN(searchResult.index) && { index: searchResult.index })), { titleUrl }), (searchResult.links.thumbnail && {
        thumbnailUrl: searchResult.links.thumbnail,
    }));
};
/**
 * Given an initiative entiy OR hub search result, construct the
 * initiative's shared card view model properties
 *
 * @param entityOrSearchResult intiative entity or hub search result
 * @param locale internationalization locale
 */
const getSharedInitiativeCardModel = (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: getShortenedCategories(entityOrSearchResult.categories).join(", "),
                },
            ]
            : []),
        {
            i18nKey: "dateCreated",
            value: entityOrSearchResult.createdDate.toLocaleDateString(locale),
        },
    ];
    return {
        access: entityOrSearchResult.access,
        badges: [],
        id: entityOrSearchResult.id,
        family: getFamily(entityOrSearchResult.type),
        source: entityOrSearchResult.owner,
        summary: entityOrSearchResult.summary,
        title: entityOrSearchResult.name,
        type: entityOrSearchResult.type,
        additionalInfo,
    };
};
//# sourceMappingURL=view.js.map