"use strict";
/* TODO auto-generated eslint ignore, please fix! */
/* eslint @typescript-eslint/no-inferrable-types: "off" */
/**
 * Liza Field Context Factory
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework
 *
 *  Liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldContextFactory = void 0;
var FieldContext_1 = require("./FieldContext");
var FieldContextStore_1 = require("./FieldContextStore");
var SubFieldContext_1 = require("./SubFieldContext");
var TableCellFieldContext_1 = require("./TableCellFieldContext");
var FieldContextFactory = /** @class */ (function () {
    /**
     * Initialize FieldContextFactory
     *
     * @param _document - DOM
     */
    function FieldContextFactory(_document, _styler_factory) {
        this._document = _document;
        this._styler_factory = _styler_factory;
        /**
         * Field element ID prefix
         */
        this._field_id_prefix = 'q_';
    }
    /**
     * Creates a new FieldContext
     *
     * @param name - field name
     * @param index - field index
     * @param content - field HTML content
     * @param is_subfield - field represents a subfield
     * @param sibling - field HTML sibling content
     */
    FieldContextFactory.prototype.create = function (name, index, content, is_subfield, sibling) {
        if (sibling === void 0) { sibling = null; }
        var element_id = this._field_id_prefix + name + '_' + index;
        var obj = FieldContext_1.FieldContext;
        if (is_subfield) {
            obj = SubFieldContext_1.SubFieldContext;
        }
        else if (content.tagName === 'TD') {
            obj = TableCellFieldContext_1.TableCellFieldContext;
        }
        return new obj(this._document, this._styler_factory.create(name, index), element_id, content, sibling);
    };
    /**
     * Creates a new FieldContextStore
     *
     * @param name - field name
     * @param content - field HTML content
     * @param sibling - field HTML sibling content
     * @param is_internal - if user is internal
     */
    FieldContextFactory.prototype.createStore = function (name, content, sibling, is_internal) {
        if (sibling === void 0) { sibling = null; }
        if (is_internal === void 0) { is_internal = false; }
        var element_id = this._field_id_prefix + name + '_0';
        return new FieldContextStore_1.FieldContextStore(element_id, content, sibling, is_internal);
    };
    return FieldContextFactory;
}());
exports.FieldContextFactory = FieldContextFactory;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRmllbGRDb250ZXh0RmFjdG9yeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIkZpZWxkQ29udGV4dEZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLG9EQUFvRDtBQUNwRCwwREFBMEQ7QUFDMUQ7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7OztBQUVILCtDQUl3QjtBQUN4Qix5REFBc0Q7QUFFdEQscURBQWtEO0FBQ2xELGlFQUE4RDtBQUc5RDtJQU1FOzs7O09BSUc7SUFDSCw2QkFDbUIsU0FBbUIsRUFDbkIsZUFBbUM7UUFEbkMsY0FBUyxHQUFULFNBQVMsQ0FBVTtRQUNuQixvQkFBZSxHQUFmLGVBQWUsQ0FBb0I7UUFadEQ7O1dBRUc7UUFDSyxxQkFBZ0IsR0FBVyxJQUFJLENBQUM7SUFVckMsQ0FBQztJQUVKOzs7Ozs7OztPQVFHO0lBQ0gsb0NBQU0sR0FBTixVQUNFLElBQVksRUFDWixLQUFzQixFQUN0QixPQUF1QixFQUN2QixXQUFvQixFQUNwQixPQUFzQztRQUF0Qyx3QkFBQSxFQUFBLGNBQXNDO1FBRXRDLElBQU0sVUFBVSxHQUFHLElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxJQUFJLEdBQUcsR0FBRyxHQUFHLEtBQUssQ0FBQztRQUU5RCxJQUFJLEdBQUcsR0FBRywyQkFBWSxDQUFDO1FBQ3ZCLElBQUksV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