"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildUiSchema = void 0;
const getCOrgOrEOrgId_1 = require("../../../../search/getCOrgOrEOrgId");
/**
 * Builds the UI Schema for the "settings => discussions" workspace pane
 * @param i18nScope the i18n scope for translations
 * @param options an EntityEditorOptions object
 * @param context an IArcGISContext object
 * @returns a promise that resolves a UI Schema object
 */
const buildUiSchema = (i18nScope, options, context, variant = "default") => {
    const uiSchema = {
        type: "Layout",
        elements: [
            {
                type: "Section",
                labelKey: "shared.sections.discussionSettings.moderation.label",
                elements: [
                    {
                        labelKey: "shared.fields.discussable.label",
                        scope: "/properties/isDiscussable",
                        type: "Control",
                        options: {
                            control: "hub-field-input-tile-select",
                            labels: [
                                "{{shared.fields.discussable.enabled.label:translate}}",
                                `{{${i18nScope}.fields.discussable.disabled.label:translate}}`,
                            ],
                            descriptions: [
                                "{{shared.fields.discussable.disabled.label:translate}}",
                                `{{${i18nScope}.fields.discussable.disabled.description:translate}}`,
                            ],
                            icons: ["speech-bubbles", "circle-disallowed"],
                            layout: variant === "compact" ? "vertical" : "horizontal",
                            styles: { "max-width": "45rem" },
                            type: "radio",
                        },
                    },
                ],
            },
        ],
    };
    if (context.hubLicense === "hub-premium" &&
        options.type !== "Hub Site Application") {
        const orgFacets = {
            label: "{{shared.fields.allowedChannelIds.facets.organization.label:translate}}",
            key: "organization",
            display: "single-select",
            operation: "OR",
            options: [
                {
                    label: "{{shared.fields.allowedChannelIds.facets.organization.options.organization.label:translate}}",
                    key: "organization",
                    predicates: [
                        {
                            orgId: [context.currentUser.orgId],
                        },
                    ],
                },
                {
                    label: "{{shared.fields.allowedChannelIds.facets.organization.options.world.label:translate}}",
                    key: "world",
                    predicates: [
                        {
                            orgId: [null],
                        },
                    ],
                },
            ],
        };
        if (context.communityOrgId) {
            orgFacets.options.splice(1, 0, {
                label: "{{shared.fields.allowedChannelIds.facets.organization.options.community.label:translate}}",
                key: "community",
                predicates: [
                    {
                        orgId: [context.communityOrgId],
                    },
                ],
            });
        }
        const cOrgOrEOrgId = (0, getCOrgOrEOrgId_1.getCOrgOrEOrgId)(context);
        const partnerOrgIds = context.trustedOrgIds.filter((orgId) => {
            return orgId !== context.currentUser.orgId && orgId !== cOrgOrEOrgId;
        });
        if (partnerOrgIds.length) {
            orgFacets.options.splice(orgFacets.options.length - 1, 0, {
                label: "{{shared.fields.allowedChannelIds.facets.organization.options.partner.label:translate}}",
                key: "partner",
                predicates: [
                    {
                        orgId: partnerOrgIds,
                    },
                ],
            });
        }
        uiSchema.elements[0].elements.push({
            labelKey: "shared.fields.allowedChannelIds.label",
            scope: "/properties/discussionSettings/properties/allowedChannelIds",
            type: "Control",
            options: {
                control: "hub-field-input-gallery-picker",
                targetEntity: "channel",
                showAddContent: true,
                allowGroupSelection: false,
                showSelection: false,
                showAllCollectionFacet: false,
                canReorder: false,
                linkTarget: "event",
                catalogs: [
                    {
                        schemaVersion: 1,
                        title: "{{shared.fields.allowedChannelIds.catalog.title:translate}}",
                        scopes: {
                            channel: {
                                targetEntity: "channel",
                                filters: [
                                    {
                                        predicates: [],
                                    },
                                ],
                            },
                        },
                        collections: [
                            {
                                label: "{{shared.fields.allowedChannelIds.catalog.title:translate}}",
                                key: "channels",
                                targetEntity: "channel",
                                scope: {
                                    targetEntity: "channel",
                                    filters: [],
                                },
                                include: ["groups"],
                            },
                        ],
                    },
                ],
                facets: [
                    {
                        label: "{{shared.fields.allowedChannelIds.facets.access.label:translate}}",
                        key: "access",
                        display: "multi-select",
                        operation: "OR",
                        options: [
                            {
                                label: "{{shared.fields.allowedChannelIds.facets.access.options.public.label:translate}}",
                                key: "public",
                                selected: false,
                                predicates: [
                                    {
                                        access: "public",
                                    },
                                ],
                            },
                            {
                                label: "{{shared.fields.allowedChannelIds.facets.access.options.org.label:translate}}",
                                key: "organization",
                                selected: false,
                                predicates: [
                                    {
                                        access: "org",
                                    },
                                ],
                            },
                            {
                                label: "{{shared.fields.allowedChannelIds.facets.access.options.private.label:translate}}",
                                key: "private",
                                selected: false,
                                predicates: [
                                    {
                                        access: "private",
                                    },
                                ],
                            },
                        ],
                    },
                    orgFacets,
                    {
                        label: "{{shared.fields.allowedChannelIds.facets.groups.label:translate}}",
                        key: "groups",
                        display: "multi-select",
                        operation: "OR",
                        options: context.currentUser.groups.map((group) => ({
                            label: group.title,
                            key: group.title,
                            selected: false,
                            predicates: [
                                {
                                    group: group.id,
                                },
                            ],
                        })),
                    },
                ],
                include: "groups",
            },
        });
    }
    return Promise.resolve(uiSchema);
};
exports.buildUiSchema = buildUiSchema;
//# sourceMappingURL=EntityUiSchemaDiscussionsSettings.js.map