"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeProps = computeProps;
const utils_1 = require("../../search/utils");
const computeLinks_1 = require("./computeLinks");
const getDefaultEntitySettings_1 = require("../../discussions/api/settings/getDefaultEntitySettings");
const utils_2 = require("../../discussions/utils");
/**
 * Given a model and a group, set various computed properties that can't be directly mapped
 * @private
 * @param group
 * @param hubGroup
 * @param requestOptions
 * @returns
 */
function computeProps(group, hubGroup, entitySettings, requestOptions) {
    var _a, _b, _c, _d;
    let token;
    if (requestOptions.authentication) {
        const session = requestOptions.authentication;
        token = session.token;
    }
    // thumbnail url
    hubGroup.thumbnailUrl = (0, utils_1.getGroupThumbnailUrl)(requestOptions.portal, group, token);
    // Handle Dates
    hubGroup.createdDate = new Date(group.created);
    hubGroup.createdDateSource = "group.created";
    hubGroup.updatedDate = new Date(group.modified);
    hubGroup.updatedDateSource = "group.modified";
    hubGroup.type = "Group";
    hubGroup.isDiscussable = (0, utils_2.isDiscussable)(group);
    // This tells us on if the group is an edit/view group.
    // If it has the `updateitemcontrol` capability, it is an edit group
    hubGroup.isSharedUpdate = (group.capabilities || []).includes("updateitemcontrol");
    hubGroup.memberType = (_a = group.userMembership) === null || _a === void 0 ? void 0 : _a.memberType;
    hubGroup.membershipAccess = "anyone";
    if (group.membershipAccess === "org") {
        hubGroup.membershipAccess = "organization";
    }
    if (group.membershipAccess === "collaboration") {
        hubGroup.membershipAccess = "collaborators";
    }
    hubGroup.canEdit =
        ((_b = group.userMembership) === null || _b === void 0 ? void 0 : _b.memberType) === "owner" ||
            ((_c = group.userMembership) === null || _c === void 0 ? void 0 : _c.memberType) === "admin";
    hubGroup.canDelete = hubGroup.canEdit;
    hubGroup.links = (0, computeLinks_1.computeLinks)(group, requestOptions);
    const settings = entitySettings || (0, getDefaultEntitySettings_1.getDefaultEntitySettings)("group");
    hubGroup.entitySettingsId = (_d = settings.id) !== null && _d !== void 0 ? _d : null;
    hubGroup.discussionSettings = settings.settings.discussions;
    // cast b/c this takes a partial but returns a full group
    return hubGroup;
}
//# sourceMappingURL=computeProps.js.map