import React from 'react';
import PropTypes from 'prop-types';
import Icon from '../icon/Icon';
import { createNamespace } from '../../tools/namingTools';
// IMPORTANT: (s)css should be imported after other atoms/components
import './styles/Error.scss';

const n = createNamespace('Error');

const Error = ({
    title, errorText, links, errorIcon, ...otherProps
}) => (
    <div {...n('wrapper').props} {...otherProps}>
        <Icon type={errorIcon} {...n('icon').props} />
        <h1 {...n('title').props}>
            {title}
        </h1>
        <div {...n('textDiv').props}>
            {errorText}
        </div>
        {links.map((link, index) => (
            // eslint-disable-next-line react/no-array-index-key
            <div {...n('linkItem').props} key={`linkItem-${index}`}>
                {link}
            </div>
        ))}
    </div>
);

const propTypes = {
    title: PropTypes.string.isRequired,
    errorText: PropTypes.node.isRequired,
    links: PropTypes.arrayOf(PropTypes.object),
    errorIcon: PropTypes.string
};

const defaultProps = {
    links: [],
    errorIcon: 'alert'
};

Error.propTypes = propTypes;
Error.defaultProps = defaultProps;

export default Error;
