import JSONObjectField from "@rjsf/core/lib/components/fields/ObjectField";
import React from "react";
import { CodeEditor } from "../widgets/code-editor";
import { renderDescription, renderTitle } from "../templates/common";
import { isCustomObjectSchema } from "./field-helpers";
export class ObjectField extends React.Component {
    constructor(props) {
        super(props);
        this.handleValidation = (error) => {
            this.setState({
                error: error,
            });
        };
        this.state = {
            error: null,
        };
    }
    render() {
        if (!isCustomObjectSchema(this.props.schema)) {
            return React.createElement(JSONObjectField, this.props);
        }
        return React.createElement(React.Fragment, {}, renderTitle(this.props.schema.title), renderDescription(this.props.schema.description), React.createElement(CodeEditor, Object.assign(Object.assign({}, this.props), { onValidate: this.handleValidation })), this.renderErrors());
    }
    renderErrors() {
        if (!this.state.error) {
            return;
        }
        return React.createElement('div', {
            role: 'alert',
            className: 'form-error',
        }, this.state.error);
    }
}
