import styled, { css } from 'styled-components';
import { color } from '../../constants/style';

const align: { [index: string]: string } = {
  left: 'flex-start',
  center: 'center',
  right: 'flex-end',
};

const staticStyles = css`
  border-width: 0;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 16px;
  font-style: normal;
  transition: all 0.3s linear;
  cursor: pointer;
  outline: none;
  padding: 5px 20px;
  min-width: 80px;
`;

const theme: { [index: string]: any } = {
  default: css`
    color: black;
    background-color: transparent;
    border: 1.5px solid transparent;

    &:hover {
      background-color: ${color['soft-blue']};
    }
  `,
  primary: css`
    color: white;
    background-color: ${color.primary};
    border: 1.5px solid ${color.primary};

    &:hover {
      background-color: ${color['french-blue']};
      border: 1.5px solid ${color['french-blue']};
    }
  `,
  'primary-hollow': css`
    color: black;
    background-color: white;
    border: 1.5px solid ${color.primary};

    &:hover {
      background-color: ${color['primary-light']};
    }
  `,
  'danger-hollow': css`
    color: ${color.danger};
    background-color: white;
    border: 1.5px solid ${color.danger};

    &:hover {
      background-color: white;
    }
  `,
  'default-hollow': css`
    color: black;
    background-color: white;
    border: 1.5px solid ${color.black56};

    &:hover {
      color: white;
      background-color: ${color.black38};
    }
  `,
  link: css`
    color: ${color.primary};
    background-color: transparent;
    border: none;
    text-decoration: underline;
    padding: 5px 0;
  `,
  'danger-link': css`
    color: ${color.error};
    background-color: transparent;
    border: none;
    text-decoration: underline;
    padding: 5px 0;
  `,
  dark: css`
    color: #ffffff;
    background-color: #000000;
    border: 1.5px solid #000000;

    &:hover {
      background-color: #333333;
      border: 1.5px solid #333333;
    }
  `,
};

const activeTheme: { [index: string]: any } = {
  default: css`
    background-color: ${color['soft-blue']};
  `,
  primary: css`
    background-color: ${color['french-blue']};
    border: 1.5px solid ${color['french-blue']};
  `,
  'primary-hollow': css`
    background-color: ${color['primary-light']};
  `,
  'default-hollow': css`
    background-color: ${color.black38};
  `,
};

export const NormalButton = styled('div')<{
  appearance?: string;
  shouldFitContainer?: boolean;
  align?: string;
  isActive?: boolean;
}>`
  ${staticStyles}
  ${props => theme[props.appearance || 'default']};
  ${props =>
    props.shouldFitContainer
      ? css`
          width: 100%;
        `
      : null}
  ${props =>
    props.isActive
      ? activeTheme[props.appearance || 'default']
      : null}

  display: inline-flex;
  justify-content: ${props => align[props.align || 'center']};
  align-items: center;
`;

export const DisableButton = styled.button`
  ${staticStyles}

  color: ${color.black38};
  background-color: #eeeff3;
  cursor: not-allowed;
`;
