"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildUiSchema = void 0;
const getThumbnailUiSchemaElement_1 = require("../../core/schemas/internal/getThumbnailUiSchemaElement");
const getEntityThumbnailUrl_1 = require("../../core/getEntityThumbnailUrl");
const getTagItems_1 = require("../../core/schemas/internal/getTagItems");
const fetchCategoriesUiSchemaElement_1 = require("../../core/schemas/internal/fetchCategoriesUiSchemaElement");
const uiSchemaMessageTypes_1 = require("../../core/enums/uiSchemaMessageTypes");
/**
 * @private
 * constructs the complete edit uiSchema for Hub Templates.
 * This defines how the schema properties should be rendered
 * in the template editing experience.
 *
 * @param i18nScope
 * @param entity
 * @param context
 * @returns
 */
const buildUiSchema = async (i18nScope, options, context) => {
    return {
        type: "Layout",
        elements: [
            {
                type: "Section",
                labelKey: `${i18nScope}.sections.basicInfo.label`,
                options: {
                    helperText: {
                        labelKey: `${i18nScope}.sections.basicInfo.helperText`,
                    },
                },
                elements: [
                    {
                        type: "Control",
                        scope: "/properties/name",
                        labelKey: `${i18nScope}.fields.name.label`,
                        options: {
                            messages: [
                                {
                                    type: uiSchemaMessageTypes_1.UiSchemaMessageTypes.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),
                    {
                        type: "Control",
                        scope: "/properties/summary",
                        labelKey: `${i18nScope}.fields.summary.label`,
                        options: {
                            control: "hub-field-input-input",
                            type: "textarea",
                            rows: 4,
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "maxLength",
                                    icon: true,
                                    labelKey: `shared.fields.summary.maxLengthError`,
                                },
                            ],
                        },
                    },
                    ...(0, getThumbnailUiSchemaElement_1.getThumbnailUiSchemaElement)(i18nScope, options.thumbnail, (0, getEntityThumbnailUrl_1.getEntityThumbnailUrl)(options), "template", context.requestOptions),
                    {
                        type: "Section",
                        labelKey: `${i18nScope}.sections.description.label`,
                        options: {
                            section: "block",
                        },
                        elements: [
                            // description
                            {
                                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: [
                            // tags
                            {
                                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",
                                },
                            },
                            // categories
                            ...(await (0, fetchCategoriesUiSchemaElement_1.fetchCategoriesUiSchemaElement)({
                                source: "org",
                                currentValues: options.categories,
                                context,
                            })),
                        ],
                    },
                ],
            },
            {
                type: "Section",
                labelKey: `${i18nScope}.sections.templateDetails.label`,
                elements: [
                    {
                        type: "Control",
                        scope: "/properties/previewUrl",
                        labelKey: `${i18nScope}.fields.previewUrl.label`,
                        options: {
                            helperText: {
                                labelKey: `${i18nScope}.fields.previewUrl.helperText`,
                            },
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "format",
                                    icon: true,
                                    labelKey: `shared.errors.urlFormat`,
                                },
                                {
                                    type: "ERROR",
                                    keyword: "if",
                                    hidden: true,
                                },
                            ],
                        },
                    },
                ],
            },
        ],
    };
};
exports.buildUiSchema = buildUiSchema;
//# sourceMappingURL=TemplateUiSchemaEdit.js.map