import styled, { css } from "styled-components";

import { Utilities, Button as BaseButton, A } from "../../base";

import {
  theme,
  getColor,
  getBorderRadius,
  getPadding,
  getFontSize,
} from "../../styled-config";


const padding = (props) => {
  return css`
    width: 40px;
    padding: ${getPadding(props, "pagination", "default")};
  `;
};


const fontSize = (props) => {
  return css`
    font-size: ${getFontSize(props, "button", "default")};
  `;
};


const border = (props) => {
  if (props.active) {
    return css`
    border: 1px solid ${getColor(props, "pagination", "primary")};
    border-radius: ${getBorderRadius(props, "button", "pill")};
    `;
  }  else if (props.loading) {
    return css`
      border: none;
    `;
  }
  return css`
    border: none;
  `;
};

const color = (props) => {
  if (props.active) {
    return css`
      color: ${getColor(props, "pagination", "white")};
      background-color: ${getColor(props, "pagination", "primary")};
      &:hover {
        color: ${getColor(props, "pagination", "white")};
        background-color: ${getColor(props, "pagination", "primary")};
      }
    `;
  } else if (props.loading) {
    return css`
      color: transparent;
    `;
  }

  return css`
    color: ${getColor(props, "button", "primary")};
  `;
};



const linkStyle = (props) => css`
  font-weight: 600;
  line-height: 0.875rem;
  text-align: center;
  font-family: Montserrat;
  text-transform: uppercase;
  white-space: wrap;
  vertical-align: middle;
  user-select: none;
  background-color: transparent;
  cursor: pointer;
  text-decoration: none;
  ${fontSize(props)};
  ${padding(props)};
  ${border(props)};
  ${color(props)};
`;

const PaginationItem = styled(A)`
  ${Utilities};
  ${(props) => linkStyle(props)};
`;

PaginationItem.defaultProps = {
  theme,
};

export { PaginationItem };
