/** @jsx jsx */
import { jsx } from '@emotion/core';
import styled from '@emotion/styled';
import { createPortal } from 'react-dom';
import { blue500, gray300, gray800 } from './styles/colors_v2';
import { MajorButton } from './styles/elements';

const Modal = styled.div`
  box-sizing: border-box;
  background-color: ${gray300};
  border-radius: 8px;
  padding: 40px;
  width: 100%;
  max-height: 100%;
  overflow: scroll;
  ::-webkit-scrollbar {
    display: none;
  }
  color: ${gray800};
  @media screen and (max-width: 720px) {
    padding: 20px;
  }
`;

const ModalWrap = styled.div`
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.75);
  padding: 5px;
  z-index: 5;
  display: flex;
  justify-content: center;
  align-items: center;
`;

export const ModalButton = styled(MajorButton)`
  padding: 10px 20px;
  margin: 30px auto 0 auto;
  width: 300px;
  &+button {
    margin-top: 15px;
  }
`;



export const ModalTitle = styled.h3`
  text-align: center;
  font-family: 'Lexend Peta', 'Helvetica Neue', 'Helvetica', Arial, sans-serif;
  margin-bottom: 30px;
  font-size: 30px;
  @media screen and (max-width: 720px) {
    font-size: 20px;
    margin-bottom: 20px;
  }
`;

export const ModalBody = styled.p<{ centered?: boolean }>`
  text-align: ${({ centered }) => centered ? 'center' : 'left'};
  font-size: 18px;
  line-height: 24px;
  margin-top: 24px;
  a {
    color: ${blue500}
  }
  @media screen and (max-width: 720px) {
    font-size: 14px;
    line-height: 18px;
    margin-top: 18px;
  }
`;


export default ({ children, maxWidth = 640 }: { children: React.ReactNode[] | React.ReactNode, maxWidth?: number }) => {
  return createPortal(
    <ModalWrap>
      <Modal style={{ maxWidth }}>
        {children}
      </Modal>
    </ModalWrap>,
    document.body
  );
}
