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

import { Div } from "../../base";

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


const vertical = (props) => {
  return css`
    & > a {
      &:last-child {
        border: 1px solid ${getColor(props, "pagination", "primary")};
        border-radius: ${getBorderRadius(props, "button", "pill")};
      }
      &:first-child {
        border: 1px solid ${getColor(props, "pagination", "primary")};
        border-radius: ${getBorderRadius(props, "button", "pill")};
      }
    }
  `;
};


const cursorLoading = (props) =>
  props.loading &&
  css`
    cursor: progress;
    & > a {
      pointer-events: none;
      cursor: progress;   
    }
  `;

const loading = (props) =>
  props.loading &&
  css`
    opacity: 0.5;
  `;

const Pagination = styled(Div)`
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  & > a {
    line-height: 1.5;
    position: relative;
    flex: 0 1 auto;
    &:hover {
      z-index: 1;
    }
  }
  ${(props) => vertical(props)};
  ${(props) => cursorLoading(props)};
  ${(props) => loading(props)};
`;

Pagination.defaultProps = {
  theme,
};

export { Pagination };
