"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.REQUIRED_PRIVS = void 0;
exports.canEditSiteContent = canEditSiteContent;
const includes_1 = require("../utils/includes");
const get_prop_1 = require("../objects/get-prop");
const has_base_priv_1 = require("./has-base-priv");
const can_edit_item_1 = require("./can-edit-item");
exports.REQUIRED_PRIVS = [
    "portal:user:createGroup",
    "portal:user:createItem",
    "portal:user:shareToGroup",
    "portal:user:viewOrgGroups",
    "portal:user:viewOrgItems",
];
/**
 * Checks if user has access to content library in Hub
 * In Hub Home context, user access requires additional privileges
 * In initiative context, check is delegated to canEditItem for the initiative site item
 * @param {IItem} item
 * @param {IUser} user
 * @returns {boolean}
 */
function canEditSiteContent(item, user) {
    let res = false;
    const isDefaultHubHome = (0, get_prop_1.getProp)(item, "properties.isDefaultHubHome");
    const hasPriv = (0, has_base_priv_1.hasBasePriv)(user);
    if (!isDefaultHubHome && hasPriv) {
        res = (0, can_edit_item_1.canEditItem)(item, user);
    }
    else if (hasPriv) {
        const userOrgId = user.orgId;
        const itemOrgId = item.orgId;
        const sameOrg = !!userOrgId && userOrgId === itemOrgId;
        if (sameOrg) {
            const privileges = user.privileges || [];
            res = exports.REQUIRED_PRIVS.every((privilege) => (0, includes_1.includes)(privileges, privilege));
        }
    }
    return res;
}
//# sourceMappingURL=can-edit-site-content.js.map