import React from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
import space from 'Components/utils/styles/space';
import statusTypes from 'Components/utils/types/statusTypes';
import { notificationColor, whiteColor } from 'Themes/utils/colorPickers';
import { textSize } from 'Themes/utils/fontPickers';

const colors = ({ type }) => css`
  color: ${notificationColor(type)};
  border-color: ${notificationColor(type)};
  background-color: ${notificationColor(type)[0.2]};
`;

const iconColor = ({ type }) => css`
  ${notificationColor(type)};
`;

const CloseIcon = styled.span`
  position: absolute;
  top: 20px;
  right: 20px;
  font-weight: bold;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  background-color: ${iconColor};
`;

const Cross = styled.span`
  position: absolute;
  top: 3px;
  left: 7px;
  width: 2px;
  height: 10px;
  transform: rotate(-225deg);
  border-radius: 2.9px;
  background-color: ${whiteColor};
`;

const Cross1 = styled(Cross)`
  transform: rotate(-225deg);
`;

const Cross2 = styled(Cross)`
  transform: rotate(225deg);
`;

const StyledNotification = styled.div`
  position: relative;
  font-weight: bold;
  border: 1px solid;
  border-radius: 5px;
  padding: 16px 20px;
  margin: 8px;
  font-size: ${textSize('M')};
  ${colors}
  ${space}
`;

const Notification = ({ children, type, theme, onClose }) => {
  return (
    <StyledNotification type={type} theme={theme}>
      {children}
      <CloseIcon onClick={onClose} type={type} theme={theme}>
        <Cross1 />
        <Cross2 />
      </CloseIcon>
    </StyledNotification>
  );
};

Notification.propTypes = {
  type: PropTypes.oneOf(statusTypes),
  onClose: PropTypes.func,
};

Notification.defaultProps = {
  type: 'success',
};

export default Notification;
