"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildDefaults = exports.buildUiSchema = void 0;
const uiSchemaRuleEffects_1 = require("../../../enums/uiSchemaRuleEffects");
const rules_1 = require("./rules");
/**
 * @private
 * Exports the uiSchema of metrics for projects
 * @param i18nScope
 * @param config
 * @param context
 * @returns
 */
const buildUiSchema = (_i18nScope, _config, _context) => {
    return Promise.resolve({
        type: "Layout",
        elements: [
            {
                type: "Notice",
                options: {
                    notice: {
                        id: "metric-editor-preview-notice",
                        title: "{{shared.notices.metrics.preview.label:translate}}",
                        message: "{{shared.notices.metrics.preview.message:translate}}",
                        configuration: {
                            noticeType: "notice",
                            icon: true,
                            kind: "info",
                            closable: false,
                            scale: "s",
                        },
                    },
                },
            },
            {
                type: "Section",
                labelKey: "shared.sections.metrics.basic.label",
                elements: [
                    {
                        labelKey: "shared.fields.metrics.cardTitle.label",
                        scope: "/properties/_metric/properties/cardTitle",
                        type: "Control",
                        options: {
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "required",
                                    labelKey: "shared.fields.metrics.cardTitle.message.required",
                                    icon: true,
                                },
                            ],
                        },
                    },
                ],
            },
            {
                type: "Section",
                labelKey: "shared.sections.metrics.source.label",
                elements: [
                    {
                        labelKey: "shared.fields.metrics.type.label",
                        scope: "/properties/_metric/properties/type",
                        type: "Control",
                        options: {
                            control: "hub-field-input-tile-select",
                            rules: [
                                [],
                                [],
                                [
                                    {
                                        effect: uiSchemaRuleEffects_1.UiSchemaRuleEffects.SHOW,
                                        conditions: [
                                            // commented out for now, as itemQuery was a prototyped fearure that was not implemented.
                                            // will be replaced with requestings metrics in the near future
                                            // checkPermission("hub:availability:alpha", context).access,
                                            false,
                                        ],
                                    },
                                ],
                            ],
                            enum: {
                                i18nScope: "shared.fields.metrics.type.enum",
                            },
                        },
                    },
                    {
                        scope: "/properties/_metric/properties/valueType",
                        type: "Control",
                        labelKey: "shared.fields.metrics.valueType.label",
                        rule: rules_1.SHOW_FOR_STATIC_RULE_ENTITY,
                        options: {
                            control: "hub-field-input-tile-select",
                            layout: "horizontal",
                            helperText: {
                                labelKey: "shared.fields.metrics.valueType.helperText",
                                placement: "top",
                            },
                            enum: {
                                i18nScope: "shared.fields.metrics.valueType.enum",
                            },
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.value.label",
                        scope: "/properties/_metric/properties/value",
                        type: "Control",
                        rules: [rules_1.SHOW_FOR_STATIC_AND_STRING_RULE_ENTITY],
                        options: {
                            control: "hub-field-input-input",
                            clearOnHidden: true,
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "required",
                                    labelKey: "shared.fields.metrics.value.message.required",
                                    icon: true,
                                },
                            ],
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.value.label",
                        scope: "/properties/_metric/properties/value",
                        type: "Control",
                        rules: [rules_1.SHOW_FOR_STATIC_AND_NUMBER_RULE_ENTITY],
                        options: {
                            control: "hub-field-input-input",
                            clearOnHidden: true,
                            type: "number",
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "required",
                                    labelKey: "shared.fields.metrics.value.message.required",
                                    icon: true,
                                },
                            ],
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.value.label",
                        scope: "/properties/_metric/properties/value",
                        type: "Control",
                        rules: [rules_1.SHOW_FOR_STATIC_AND_DATE_RULE_ENTITY],
                        options: {
                            control: "hub-field-input-date",
                            clearOnHidden: true,
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "required",
                                    labelKey: "shared.fields.metrics.value.message.required",
                                    icon: true,
                                },
                            ],
                        },
                    },
                    {
                        scope: "/properties/_metric/properties/dynamicMetric",
                        type: "Control",
                        labelKey: "shared.fields.metrics.dynamicMetric.label",
                        rule: rules_1.SHOW_FOR_DYNAMIC_RULE_ENTITY,
                        options: {
                            control: "hub-composite-input-service-query-metric",
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.unit.label",
                        scope: "/properties/_metric/properties/unit",
                        type: "Control",
                        options: {
                            helperText: {
                                labelKey: "shared.fields.metrics.unit.helperText",
                                placement: "top",
                            },
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.unitPosition.label",
                        scope: "/properties/_metric/properties/unitPosition",
                        type: "Control",
                        options: {
                            helperText: {
                                labelKey: "shared.fields.metrics.unitPosition.helperText",
                                placement: "bottom",
                            },
                            control: "hub-field-input-select",
                            enum: {
                                i18nScope: "shared.fields.metrics.unitPosition.enum",
                            },
                        },
                    },
                ],
            },
            {
                type: "Section",
                labelKey: "shared.sections.metrics.formatting.label",
                elements: [
                    {
                        labelKey: "shared.fields.metrics.trailingText.label",
                        scope: "/properties/_metric/properties/trailingText",
                        type: "Control",
                        options: {
                            helperText: {
                                labelKey: "shared.fields.metrics.trailingText.helperText",
                                placement: "bottom",
                            },
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.sourceLink.label",
                        scope: "/properties/_metric/properties/sourceLink",
                        type: "Control",
                        rule: rules_1.SHOW_FOR_STATIC_RULE_ENTITY,
                        options: {
                            placeholder: "https://esri.com",
                            messages: [
                                {
                                    type: "ERROR",
                                    keyword: "required",
                                    icon: true,
                                    labelKey: "shared.fields.metrics.sourceLink.message.required",
                                    allowShowBeforeInteract: true,
                                },
                                {
                                    type: "ERROR",
                                    keyword: "format",
                                    icon: true,
                                    labelKey: "shared.errors.urlFormat",
                                },
                                {
                                    type: "ERROR",
                                    keyword: "if",
                                    hidden: true,
                                },
                            ],
                        },
                    },
                    {
                        labelKey: "shared.fields.metrics.sourceTitle.label",
                        scope: "/properties/_metric/properties/sourceTitle",
                        type: "Control",
                        rule: rules_1.SHOW_FOR_STATIC_RULE_ENTITY,
                    },
                    {
                        type: "Control",
                        scope: "/properties/_metric/properties/allowDynamicLink",
                        labelKey: "shared.fields.metrics.allowDynamicLink.label",
                        rule: rules_1.SHOW_FOR_DYNAMIC_RULE_ENTITY,
                        options: {
                            layout: "inline-space-between",
                            control: "hub-field-input-switch",
                        },
                    },
                ],
            },
        ],
    });
};
exports.buildUiSchema = buildUiSchema;
/**
 * @private
 * constructs the default values for the project metrics editor.
 * This is used to pre-populate the metrics editor with specific default values
 * that are different from the Schema default values, or contain translated
 * values.
 * @param i18nScope
 * @param options
 * @param context
 * @returns
 */
const buildDefaults = (_i18nScope, _options, _context) => {
    return Promise.resolve({
        _metric: {
            cardTitle: `{{shared.fields.metrics.cardTitle.label:translate}}`,
        },
    });
};
exports.buildDefaults = buildDefaults;
//# sourceMappingURL=ProjectUiSchemaMetrics.js.map