"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cannotCreatePostGroupsBlockedV2 = cannotCreatePostGroupsBlockedV2;
const aclCategory_1 = require("../../enums/aclCategory");
const role_1 = require("../../enums/role");
const can_create_post_v2_1 = require("./can-create-post-v2");
const utils_1 = require("../../../utils");
function cannotCreatePostGroupsBlockedV2(channel, user = {}) {
    if ((0, can_create_post_v2_1.canCreatePostV2)(channel, user)) {
        return false;
    }
    const userGroupsById = (user.groups || []).reduce((acc, group) => (Object.assign(Object.assign({}, acc), { [group.id]: group })), {});
    const channelUserGroups = channel.channelAcl.reduce((acc, permission) => permission.category === aclCategory_1.AclCategory.GROUP &&
        [
            role_1.Role.WRITE,
            role_1.Role.READWRITE,
            role_1.Role.OWNER,
            role_1.Role.MANAGE,
            role_1.Role.MODERATE,
        ].includes(permission.role) &&
        userGroupsById[permission.key]
        ? [...acc, userGroupsById[permission.key]]
        : acc, []);
    if (!channelUserGroups.length) {
        return false;
    }
    return channelUserGroups.every((group) => !(0, utils_1.isDiscussable)(group));
}
//# sourceMappingURL=cannot-create-post-groups-blocked-v2.js.map