import React from 'react';
import PropTypes from 'prop-types';

export class DangerousHTML extends React.Component<any> {
    static propTypes = {
        children: PropTypes.node.isRequired,
        testAutomationId: PropTypes.string
    };

    static defaultProps = {
        testAutomationId: null
    };

    render() {
        let {children, testAutomationId, ...props} = this.props;

        let propsClone = {...props};

        if (testAutomationId) {
            propsClone['data-test-automation-id'] = testAutomationId;
        }

        if (typeof children === 'string') {
            propsClone.dangerouslySetInnerHTML = {__html: children};
        } else {
            propsClone.children = children;
        }

        return <div className="inline-block" {...propsClone} />;
    }
}
