"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormRuntime = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const styled_components_1 = tslib_1.__importDefault(require("styled-components"));
const FormContext_1 = require("./Utilities/FormContext");
const core_1 = require("@material-ui/core");
const CloseIcon_1 = require("../CommonUI/Icon/CloseIcon");
const FormDesignConstants_1 = require("./Utilities/FormDesignConstants");
const registerElements_1 = require("./registerElements");
const Header = styled_components_1.default.div `
    display: flex;
    align-items: center;
    padding: 10px 15px;
    bottom: 100%;
    left: 0;
    width: 100%;
    position: absolute;

    .MuiButtonBase-root {
        margin-left: auto;
    }
`;
class FormRuntime extends react_1.default.Component {
    name;
    formContext;
    constructor(props) {
        super(props, {});
        // ensure controls are registered.
        registerElements_1.RegisterFormElements.doRegistration();
        let fContext = props.form.getFormContext() ?? new FormContext_1.FormContext(props.form);
        fContext.mode = FormDesignConstants_1.FormMode.Runtime;
        if (this.props.formData)
            fContext.setFormData(this.props.formData);
        if (this.props.onFormDataChange)
            fContext.onFormDataChange = this.props.onFormDataChange;
        if (this.props.onFormButtonClick)
            fContext.onFormButtonClick = this.props.onFormButtonClick;
        if (this.props.onFormCancelButton)
            fContext.onFormCancelButton = this.props.onFormCancelButton;
        if (this.props.onFormClose)
            fContext.onFormClose = this.props.onFormClose;
        if (this.props.formTitle)
            fContext.formTitle = this.props.formTitle;
        this.formContext = fContext;
        this.props.form.setFormContext(fContext);
    }
    hasHeader = () => {
        return !!this.props.formTitle || !!this.props.onFormClose;
    };
    render() {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [this.hasHeader() && ((0, jsx_runtime_1.jsxs)(Header, { children: [this.props.formTitle && ((0, jsx_runtime_1.jsx)(core_1.TextField, { value: this.props.formTitle, "data-testid": "test-form-title" })), this.props.onFormClose && ((0, jsx_runtime_1.jsx)(core_1.Button, { onClick: () => this.props.onFormClose(this.formContext.getFormData()), "data-testid": "btn-topbar-close", children: (0, jsx_runtime_1.jsx)(CloseIcon_1.CloseIcon, {}) }))] })), this.props.form.render()] }));
    }
}
exports.FormRuntime = FormRuntime;
//# sourceMappingURL=FormRuntime.js.map