import React from 'react';
import Alert from 'antd/es/alert';

import { ConfigConsumer } from '../config-provider';
import Icons from '../icons';
import './index.less';

const {
  CheckCircleIcon,
  CloseCircleIcon,
  InfoCircleIcon,
  WarningCircleIcon,
  CloseIcon,
} = Icons;

const iconMap = {
  success: <CheckCircleIcon fill="currentColor" />,
  error: <CloseCircleIcon fill="currentColor" />,
  info: <InfoCircleIcon fill="currentColor" />,
  warning: <WarningCircleIcon fill="currentColor" />,
};

export default props => (
  <ConfigConsumer>
    {({ getPrefixCls }) => {
      const {
        prefixCls: customizePrefixCls,
        type,
        closable,
        ...restProps
      } = props;
      const prefixCls = getPrefixCls('alert', customizePrefixCls);
      return (
        <Alert
          prefixCls={prefixCls}
          type={type}
          icon={iconMap[type]}
          closeText={closable ? <CloseIcon /> : null}
          {...restProps}
        />
      );
    }}
  </ConfigConsumer>
);
