import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import React from "react";
import styled from "styled-components";
import { FormContext } from "./Utilities/FormContext";
import { Button, TextField } from "@material-ui/core";
import { CloseIcon } from "../CommonUI/Icon/CloseIcon";
import { FormMode } from "./FormDesignConstants";
import { RegisterFormElements } from "./registerElements";
const Header = styled.div `
    display: flex;
    align-items: center;
    padding: 10px 15px;
    bottom: 100%;
    left: 0;
    width: 100%;
    position: absolute;

    .MuiButtonBase-root {
        margin-left: auto;
    }

`;
export class XUserForm extends React.Component {
    constructor(props) {
        super(props, {});
        this.hasHeader = () => {
            return !!this.props.formTitle || !!this.props.onFormClose;
        };
        // ensure controls are registered.
        RegisterFormElements.doRegistration();
        let fContext = new FormContext(props.form);
        fContext.mode = 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);
    }
    render() {
        return (_jsxs(_Fragment, { children: [this.hasHeader() &&
                    _jsxs(Header, { children: [this.props.formTitle && _jsx(TextField, { value: this.props.formTitle, "data-testid": "test-form-title" }, void 0),
                            this.props.onFormClose && _jsx(Button, Object.assign({ onClick: () => this.props.onFormClose(this.formContext.getFormData()), "data-testid": "btn-topbar-close" }, { children: _jsx(CloseIcon, {}, void 0) }), void 0)] }, void 0), this.props.form.render()] }, void 0));
    }
}
//# sourceMappingURL=XUserForm.js.map