"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Formio_1 = require("./Formio");
const builders_1 = __importDefault(require("./builders"));
const Form_1 = __importDefault(require("./Form"));
class FormBuilder extends Form_1.default {
    /**
     * Creates a new form builder.
     * @param {HTMLElement} element - The HTML element to place the form builder.
     * @param {string | object | undefined} form - The form to pass to the builder
     * @param {FormBuilderOptions} options - The options to create this builder.
     * @returns {FormBuilder} - The form builder instance.
     */
    constructor(element, form, options) {
        form = form || {};
        options = options || {};
        super(element, form, Object.assign(options, FormBuilder.options, Formio_1.Formio.options && Formio_1.Formio.options.builder ? Formio_1.Formio.options.builder : {}));
    }
    create(display) {
        if (builders_1.default.builders[display]) {
            return new builders_1.default.builders[display](this.element, this.options);
        }
        else {
            return new builders_1.default.builders['webform'](this.element, this.options);
        }
    }
}
/**
 * @typedef FormBuilderOptions
 * @property {string[]} [disabled] - An array of "keys" of components that should be disabled within the form builder. Example: ['firstName', 'lastName']
 * @property {boolean} [noNewEdit] - When set to TRUE no modal is shown when a component is dragged onto the form.
 * @property {boolean} [noDefaultSubmitButton] - Set to TRUE to not include the default submit button in Webforms.
 * @property {boolean} [alwaysConfirmComponentRemoval] - Set to TRUE to always require confirmation before removing a component.
 * @property {object} [formConfig] - Form configurations to apply to forms being created. These configurations are added to the "config" property of the form object.
 * @property {string} [resourceTag] - The tag to use to query for the "Existing Resource Fields" section of the builder.
 * @property {import('./Form').FormOptions} [editForm] - The options to apply to the Edit Form (the form that shows inside the modal when you edit a component).
 * @property {string} [language] - The language to load into the form builder.
 * @property {object} [builder] - The builder options to pass to the builder.
 * @property {'form'|'wizard'|'pdf'} [display] - The display mode of the builder.
 * @property {string} [resourceFilter] - Filter applied to the resources that appear in the builder's Existing Resource Fields.
 * @property {boolean} [noSource] - When set to TRUE, the resource ID in the builder's Existing Resource Fields will not be linked.
 * @property {boolean} [showFullJsonSchema] - When set to TRUE, the full JSON schema will be displayed in the JSON edit menu.
 */
/** @type {FormBuilderOptions} */
FormBuilder.options = {};
exports.default = FormBuilder;
/**
 * Factory that creates a new form builder based on the form parameter.
 * @param {HTMLElement} element - The HTML Element to add this form to.
 * @param {string|object} form - The src of the form, or a form object.
 * @param {object} options - The options to create this form.
 * @returns {Promise} - When the form is instance is ready.
 */
Formio_1.Formio.builder = (element, form, options) => {
    return new FormBuilder(element, form, options).ready;
};
Formio_1.Formio.FormBuilder = FormBuilder;
