"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormFrameShim = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
/**
 * The FormFrameShim component provides a compatibility shim for the AJAX viewer form frame
 *
 * @export
 * @class FormFrameShim
 * @extends {React.Component<FormFrameShimProps, any>}
 */
var FormFrameShim = /** @class */ (function (_super) {
    tslib_1.__extends(FormFrameShim, _super);
    function FormFrameShim(props) {
        var _this = _super.call(this, props) || this;
        _this.onFormMounted = function (form) {
            _this._form = form;
        };
        _this.state = {
            target: "",
            action: "",
            params: []
        };
        return _this;
    }
    FormFrameShim.prototype.submit = function (url, params, target) {
        var _this = this;
        //TODO: Can't convert this to functional component with hooks, until this type
        //of pattern is possible
        this.setState({
            action: url,
            params: params,
            target: target
        }, function () {
            //The form will have the updated content at this point
            _this._form.submit();
        });
    };
    FormFrameShim.prototype.render = function () {
        var _a = this.state, target = _a.target, action = _a.action, params = _a.params;
        return React.createElement("form", { style: { visibility: "hidden", width: 0, height: 0 }, ref: this.onFormMounted, method: "post", id: "Frm", target: target, action: action, encType: "application/x-www-form-urlencoded" }, (function () {
            var fields = [];
            for (var i = 0; i < params.length; i += 2) {
                fields.push(React.createElement("input", { id: "f".concat(i), key: "f".concat(i), type: "hidden", name: params[i], value: params[i + 1] }));
            }
            return fields;
        })());
    };
    return FormFrameShim;
}(React.Component));
exports.FormFrameShim = FormFrameShim;
//# sourceMappingURL=form-frame-shim.js.map