"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildUiSchema = void 0;
const getLocationExtent_1 = require("../../core/schemas/internal/getLocationExtent");
const getLocationOptions_1 = require("../../core/schemas/internal/getLocationOptions");
const getTagItems_1 = require("../../core/schemas/internal/getTagItems");
const getThumbnailUiSchemaElement_1 = require("../../core/schemas/internal/getThumbnailUiSchemaElement");
const getAuthedImageUrl_1 = require("../../core/_internal/getAuthedImageUrl");
const fetchCategoriesUiSchemaElement_1 = require("../../core/schemas/internal/fetchCategoriesUiSchemaElement");
const getFeaturedContentCatalogs_1 = require("../../core/schemas/internal/getFeaturedContentCatalogs");
const checkPermission_1 = require("../../permissions/checkPermission");
const uiSchemaRuleEffects_1 = require("../../core/enums/uiSchemaRuleEffects");
/**
 * @private
 * constructs the complete edit uiSchema for Hub Projects.
 * This defines how the schema properties should be
 * rendered in the project editing experience
 */
const buildUiSchema = async (i18nScope, options, context) => {
    var _a;
    return {
        type: "Layout",
        elements: [
            {
                type: "Section",
                labelKey: `${i18nScope}.sections.basicInfo.label`,
                options: {
                    helperText: {
                        labelKey: `${i18nScope}.sections.basicInfo.helperText`,
                    },
                },
                elements: [
                    {
                        labelKey: `${i18nScope}.fields.name.label`,
                        scope: "/properties/name",
                        type: "Control",
                        options: {
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "required",
                                    icon: true,
                                    labelKey: `${i18nScope}.fields.name.requiredError`,
                                },
                                {
                                    type: "ERROR",
                                    keyword: "maxLength",
                                    icon: true,
                                    labelKey: `${i18nScope}.fields.name.maxLengthError`,
                                },
                                {
                                    type: "ERROR",
                                    keyword: "format",
                                    icon: true,
                                    labelKey: `${i18nScope}.fields.name.entityTitleValidatorError`,
                                },
                            ],
                        },
                    },
                    // getSlugSchemaElement(i18nScope),
                    {
                        labelKey: `${i18nScope}.fields.summary.label`,
                        scope: "/properties/summary",
                        type: "Control",
                        options: {
                            control: "hub-field-input-input",
                            type: "textarea",
                            rows: 4,
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "maxLength",
                                    icon: true,
                                    labelKey: `shared.fields.purpose.maxLengthError`,
                                },
                            ],
                        },
                    },
                    ...(0, getThumbnailUiSchemaElement_1.getThumbnailUiSchemaElement)(i18nScope, options.thumbnail, options.thumbnailUrl, "project", context.requestOptions),
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.description.label`,
                        options: {
                            section: "block",
                        },
                        elements: [
                            {
                                labelKey: `${i18nScope}.fields.description.label`,
                                scope: "/properties/description",
                                type: "Control",
                                options: {
                                    control: "hub-field-input-rich-text",
                                    type: "textarea",
                                },
                            },
                        ],
                    },
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.discoverability.label`,
                        options: {
                            section: "block",
                            helperText: {
                                labelKey: `${i18nScope}.sections.discoverability.helperText`,
                            },
                        },
                        elements: [
                            {
                                labelKey: `${i18nScope}.fields.tags.label`,
                                scope: "/properties/tags",
                                type: "Control",
                                options: {
                                    control: "hub-field-input-combobox",
                                    items: await (0, getTagItems_1.getTagItems)(options.tags, context.portal.id, context.hubRequestOptions),
                                    allowCustomValues: true,
                                    selectionMode: "multiple",
                                    placeholderIcon: "label",
                                },
                            },
                            ...(await (0, fetchCategoriesUiSchemaElement_1.fetchCategoriesUiSchemaElement)({
                                source: "org",
                                currentValues: options.categories,
                                context,
                            })),
                        ],
                    },
                ],
            },
            {
                type: "Section",
                labelKey: `${i18nScope}.sections.location.label`,
                elements: [
                    {
                        scope: "/properties/location",
                        type: "Control",
                        options: {
                            control: "hub-field-input-location-picker",
                            extent: await (0, getLocationExtent_1.getLocationExtent)(options.location, context.hubRequestOptions),
                            options: await (0, getLocationOptions_1.getLocationOptions)(options.id, options.type, options.location, context.portal.name, context.hubRequestOptions),
                            noticeTitleElementAriaLevel: 3,
                        },
                    },
                ],
            },
            {
                type: "Section",
                labelKey: `${i18nScope}.sections.status.label`,
                elements: [
                    {
                        scope: "/properties/status",
                        type: "Control",
                        labelKey: `${i18nScope}.fields.status.label`,
                        options: {
                            control: "hub-field-input-select",
                            enum: {
                                i18nScope: `${i18nScope}.fields.status.enum`,
                            },
                        },
                    },
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.timeline.label`,
                        options: {
                            section: "block",
                            helperText: {
                                labelKey: `${i18nScope}.sections.timeline.helperText`,
                            },
                        },
                        elements: [
                            {
                                scope: "/properties/view/properties/timeline",
                                type: "Control",
                                options: {
                                    control: "arcgis-hub-timeline-editor",
                                    showTitleAndDescription: false,
                                },
                            },
                        ],
                    },
                ],
            },
            {
                type: "Section",
                labelKey: "shared.sections.heroBanner.label",
                elements: [
                    // {
                    //   type: "Section",
                    //   labelKey: 'shared.sections.heroBannerAppearance.label',
                    //   options: {
                    //     section: "block",
                    //     helperText: {
                    //       labelKey: 'shared.sections.heroBannerAppearance.helperText',
                    //     },
                    //   },
                    //   elements: [
                    //     {
                    //       labelKey: 'shared.fields.hero.label',
                    //       scope: "/properties/view/properties/hero",
                    //       type: "Control",
                    //       options: {
                    //         control: "hub-field-input-tile-select",
                    //         layout: "horizontal",
                    //         labels: [
                    //           '{{shared.fields.hero.map.label:translate}}',
                    //           '{{shared.fields.hero.image.label:translate}}',
                    //         ],
                    //         descriptions: [
                    //           '{{shared.fields.hero.map.description:translate}}',
                    //           '{{shared.fields.hero.image.description:translate}}',
                    //         ],
                    //         icons: ["map-pin", "image"],
                    //       },
                    //     },
                    //     {
                    //       labelKey: 'shared.fields.featuredImage.altText.label',
                    //       scope: "/properties/view/properties/featuredImageAltText",
                    //       type: "Control",
                    //       rule: {
                    //         effect: UiSchemaRuleEffects.HIDE,
                    //         condition: {
                    //           scope: "/properties/view/properties/hero",
                    //           schema: { const: "map" },
                    //         },
                    //       },
                    //     },
                    //   ]
                    // },
                    {
                        type: "Section",
                        labelKey: "shared.sections.heroActions.label",
                        options: {
                            section: "block",
                            helperText: {
                                labelKey: "shared.sections.heroActions.helperText",
                            },
                        },
                        elements: [
                            {
                                scope: "/properties/view/properties/heroActions",
                                type: "Control",
                                options: {
                                    control: "hub-composite-input-action-links",
                                    type: "button",
                                    catalogs: (0, getFeaturedContentCatalogs_1.getFeaturedContentCatalogs)(context.currentUser), // for now we'll just re-use this util to get the catalogs
                                    facets: [
                                        {
                                            label: `{{${i18nScope}.fields.callToAction.facets.type:translate}}`,
                                            key: "type",
                                            display: "multi-select",
                                            field: "type",
                                            options: [],
                                            operation: "OR",
                                            aggLimit: 100,
                                        },
                                        {
                                            label: `{{${i18nScope}.fields.callToAction.facets.sharing:translate}}`,
                                            key: "access",
                                            display: "multi-select",
                                            field: "access",
                                            options: [],
                                            operation: "OR",
                                        },
                                    ],
                                    showAllCollectionFacet: true,
                                },
                            },
                        ],
                    },
                ],
            },
            // Note: Upon the release of configurable views, we will show a
            // deprecation notice and disallow the configuration of the
            // featured image, embed, and content from the workspace because
            // these will become editiable (as cards) directly from the view.
            // 90 days post release, we will hide/retire this entire section.
            {
                type: "Section",
                labelKey: `${i18nScope}.sections.view.label`,
                rules: [
                    {
                        effect: uiSchemaRuleEffects_1.UiSchemaRuleEffects.SHOW,
                        conditions: [
                            // NOTE: The "hub:project:workspace:edit:cardProps"
                            // permission will deny access on PROD starting 90 days
                            // after the configurable views release, thereby resulting
                            // in this entire section being hidden.
                            (0, checkPermission_1.checkPermission)("hub:project:workspace:edit:cardProps", context)
                                .access,
                        ],
                    },
                ],
                elements: [
                    {
                        type: "Notice",
                        options: {
                            notice: {
                                configuration: {
                                    id: "deprecated-workspace-features-notice",
                                    noticeType: "notice",
                                    closable: false,
                                    kind: "info",
                                    icon: "information",
                                    scale: "m",
                                },
                                title: `{{${i18nScope}.sections.view.deprecatedNotice.title:translate}}`,
                                message: `{{${i18nScope}.sections.view.deprecatedNotice.message:translate}}`,
                                autoShow: true,
                            },
                        },
                        rules: [
                            // only show the deprecation notice once configurable views
                            // are released
                            {
                                effect: uiSchemaRuleEffects_1.UiSchemaRuleEffects.SHOW,
                                conditions: [
                                    (0, checkPermission_1.checkPermission)("hub:feature:configurableViews", context)
                                        .access,
                                ],
                            },
                        ],
                    },
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.view.image.label`,
                        options: {
                            section: "block",
                            helperText: {
                                labelKey: `${i18nScope}.sections.view.image.helperText`,
                            },
                        },
                        rules: [
                            // disable the featured image section once configurable
                            // views are released - at this point, the featured image
                            // will be editable directly from the view.
                            {
                                effect: uiSchemaRuleEffects_1.UiSchemaRuleEffects.DISABLE,
                                conditions: [
                                    (0, checkPermission_1.checkPermission)("hub:feature:configurableViews", context)
                                        .access,
                                ],
                            },
                        ],
                        elements: [
                            {
                                labelKey: "shared.fields.featuredImage.label",
                                scope: "/properties/view/properties/featuredImage",
                                type: "Control",
                                options: {
                                    control: "hub-field-input-image-picker",
                                    imgSrc: (0, getAuthedImageUrl_1.getAuthedImageUrl)((_a = options.view) === null || _a === void 0 ? void 0 : _a.featuredImageUrl, context.requestOptions),
                                    maxWidth: 727,
                                    maxHeight: 484,
                                    aspectRatio: 1.5,
                                    sizeDescription: {
                                        labelKey: "shared.fields.featuredImage.sizeDescription",
                                    },
                                },
                            },
                            {
                                labelKey: "shared.fields.featuredImage.altText.label",
                                scope: "/properties/view/properties/featuredImageAltText",
                                type: "Control",
                            },
                        ],
                    },
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.view.embed.label`,
                        options: {
                            section: "block",
                            helperText: {
                                labelKey: `${i18nScope}.sections.view.embed.helperText`,
                            },
                        },
                        rules: [
                            // disable the featured embed section once configurable
                            // views are released - at this point, the featured embed
                            // will be editable directly from the view.
                            {
                                effect: uiSchemaRuleEffects_1.UiSchemaRuleEffects.DISABLE,
                                conditions: [
                                    (0, checkPermission_1.checkPermission)("hub:feature:configurableViews", context)
                                        .access,
                                ],
                            },
                        ],
                        elements: [
                            {
                                scope: "/properties/view/properties/embeds",
                                type: "Control",
                                options: {
                                    control: "hub-composite-input-embeds",
                                },
                            },
                        ],
                    },
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.view.content.label`,
                        options: {
                            section: "block",
                            helperText: {
                                labelKey: `${i18nScope}.sections.view.content.helperText`,
                            },
                        },
                        rules: [
                            // disable the featured content section once configurable
                            // views are released - at this point, the featured content
                            // will be editable directly from the view.
                            {
                                effect: uiSchemaRuleEffects_1.UiSchemaRuleEffects.DISABLE,
                                conditions: [
                                    (0, checkPermission_1.checkPermission)("hub:feature:configurableViews", context)
                                        .access,
                                ],
                            },
                        ],
                        elements: [
                            {
                                scope: "/properties/view/properties/featuredContentIds",
                                type: "Control",
                                options: {
                                    control: "hub-field-input-gallery-picker",
                                    targetEntity: "item",
                                    catalogs: (0, getFeaturedContentCatalogs_1.getFeaturedContentCatalogs)(context.currentUser),
                                    facets: [
                                        {
                                            label: `{{${i18nScope}.fields.featuredContent.facets.type:translate}}`,
                                            key: "type",
                                            display: "multi-select",
                                            field: "type",
                                            options: [],
                                            operation: "OR",
                                            aggLimit: 100,
                                        },
                                        {
                                            label: `{{${i18nScope}.fields.featuredContent.facets.sharing:translate}}`,
                                            key: "access",
                                            display: "multi-select",
                                            field: "access",
                                            options: [],
                                            operation: "OR",
                                        },
                                    ],
                                    showAllCollectionFacet: true,
                                    showAddContent: true,
                                },
                            },
                        ],
                    },
                ],
            },
        ],
    };
};
exports.buildUiSchema = buildUiSchema;
//# sourceMappingURL=ProjectUiSchemaEdit.js.map