/* jscs:disable disallowDanglingUnderscores */

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

interface IconProps extends Partial<IconDefaultProps> {
    testAutomationId?: string;
    className?: string;
    name: string;
    ariaHidden?: boolean;
    onClick?: any;
}

interface IconDefaultProps {
    testAutomationId: string;
    ariaHidden: boolean;
}

export class Icon extends React.Component<IconProps> {
    static propTypes = {
        testAutomationId: PropTypes.string,
        className: PropTypes.string,
        name: PropTypes.string.isRequired,
        ariaHidden: PropTypes.string
    };

    static defaultProps = {
        className: null,
        testAutomationId: 'icon',
        ariaHidden: 'true'
    };

    render() {
        let {testAutomationId, className, name, ariaHidden, ...props} = this.props;

        let iconName = name;
        let iconClassName = classnames('rc-icon', 'rc-icon-' + name, className);
        if (iconName) {
            return (
                <span
                    data-test-automation-id={testAutomationId}
                    className={iconClassName}
                    aria-hidden={ariaHidden}
                    {...props}
                />
            );
        }
        return null;
    }
}
