import React from "react";
export class CodeEditor extends React.Component {
    constructor(props) {
        super(props);
        this.props = props;
        this.handleChange = this.handleChange.bind(this);
    }
    render() {
        const props = this.props;
        let value = '{}';
        try {
            value = JSON.stringify(props.formData, null, '    ');
        }
        catch (_a) {
            // N/A
        }
        return React.createElement('limel-code-editor', {
            value: value,
            language: 'json',
            lineNumbers: true,
            fold: true,
            lint: true,
            onChange: this.handleChange,
        });
    }
    handleChange(event) {
        const props = this.props;
        event.stopPropagation();
        if (!props.onChange) {
            return;
        }
        try {
            const value = JSON.parse(event.nativeEvent.detail);
            props.onChange(value);
            props.onValidate();
        }
        catch (_a) {
            props.onValidate('Should be a valid JSON document');
        }
    }
}
