import * as React from 'react';
import {isEmpty} from 'lodash';
import classNames from 'classnames';
import RenderHtml from '../renderFunction';
import PropsTypes from './types';
import FormComponent from '../FormComponent';

export default class ElementContainer extends FormComponent<PropsTypes, {}> {

    constructor(props: PropsTypes, {}) {
        super(props);
    }

    componentDidMount() {
        this.validate('true')
    }

    render(): JSX.Element {

        const {errorMessage, caption} = this.props;
        const uiClass = classNames(`jump-ui-container jump-ui-element-container`, {
                'error': !isEmpty(errorMessage),
            });

        return (
            <div className={`${uiClass}`}>
                <div className="ui-caption">
                    {caption}
                </div>
                <div>
                    {this.props.children}
                </div>
                {RenderHtml.renderError(this.error())}
            </div>
        );
    }
}
