"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCardEditorSchemas = getCardEditorSchemas;
const getCardType_1 = require("./getCardType");
const filterSchemaToUiSchema_1 = require("./filterSchemaToUiSchema");
const util_1 = require("../../../util");
const MetricSchema_1 = require("./metrics/MetricSchema");
const FollowSchema_1 = require("./follow/FollowSchema");
const EmbedSchema_1 = require("./embed/EmbedSchema");
const EventGalleryCardSchema_1 = require("./events/EventGalleryCardSchema");
const buildStatUiSchema = require("./metrics/StatCardUiSchema");
const buildFollowUiSchema = require("./follow/FollowCardUiSchema");
const buildEmbedSchema = require("./embed/EmbedUiSchema");
const buildEventGalleryCardSchema = require("./events/EventGalleryCardUiSchema");
/**
 * get the editor schema and uiSchema defined for a layout card.
 * The schema and uiSchema that are returned can be used to
 * render a form UI (using the configuration editor).
 *
 * @param i18nScope  translation scope to be interpolated into the uiSchema
 * @param type editor type - corresponds to the returned uiSchema
 * @param options optional hash of dynamic uiSchema element options
 * @param context
 * @returns
 */
async function getCardEditorSchemas(i18nScope, type, options, context) {
    const cardType = (0, getCardType_1.getCardType)(type);
    let schema;
    let uiSchema;
    let defaults;
    switch (cardType) {
        case "stat": {
            const MODULES = {
                "hub:card:stat": buildStatUiSchema,
            };
            const module = MODULES[type];
            schema = (0, util_1.cloneObject)(MetricSchema_1.MetricSchema);
            uiSchema = await module.buildUiSchema(i18nScope, options, context);
            // if we have buildDefaults, build the defaults
            // TODO: when first implementing buildDefaults for initiative templates, remove the ignore line
            /* istanbul ignore next */
            if (module.buildDefaults) {
                defaults = module.buildDefaults(i18nScope, options, context);
            }
            break;
        }
        case "follow": {
            const MODULES = {
                "hub:card:follow": buildFollowUiSchema,
            };
            const module = MODULES[type];
            schema = (0, util_1.cloneObject)(FollowSchema_1.FollowSchema);
            uiSchema = await module.buildUiSchema(i18nScope, options, context);
            break;
        }
        case "embed": {
            schema = (0, util_1.cloneObject)(EmbedSchema_1.EmbedCardSchema);
            uiSchema = buildEmbedSchema.buildUiSchema(i18nScope, options, context);
            defaults = { embeds: [] };
            break;
        }
        case "eventGallery": {
            schema = (0, util_1.cloneObject)(EventGalleryCardSchema_1.EventGalleryCardSchema);
            uiSchema = await buildEventGalleryCardSchema.buildUiSchema(i18nScope, options, context);
            break;
        }
    }
    // filter out properties not used in uiSchema
    schema = (0, filterSchemaToUiSchema_1.filterSchemaToUiSchema)(schema, uiSchema);
    return Promise.resolve({ schema, uiSchema, defaults });
}
//# sourceMappingURL=getCardEditorSchemas.js.map