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

const Icon = ({
    type,
    fill,
    ...otherProps
}) => {
    if (!types || !types[type]) {
        return null;
    }

    const { getContent, viewBox } = types[type];

    return (
        <svg fill={fill} {...otherProps} viewBox={viewBox} xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
            {getContent()}
        </svg>
    );
};


export const allowedTypes = Object.keys(types);

Icon.propTypes = {
    type: PropTypes.oneOf(allowedTypes).isRequired,
    fill: PropTypes.string
};

Icon.defaultProps = {
    fill: 'black'
};

export default Icon;
