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

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

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

const background = (props) => {
  if (props.background) {
    return css`
      background: ${props.background};
    `;
  }

  return css`
    background: transparent;
  `;
};

const image = (props) => {
  if (props.image) {
    return css`
      background-image: url("${props.image}");
      background-size: cover;
      background-repeat: no-repeat;
    `;
  }
  return css``;
};

const border = (props) => {
  if (props.border) {
    return css`
      border: ${getBorder(props, "wrap", "default")}
        ${getColor(props, "wrap", "color")};
      border-radius: ${getBorderRadius(props, "wrap", "default")};
    `;
  }
  return css`
    border: none;
  `;
};

const fluidHeight = (props) => {
  if (props.fluidHeight) {
    return css`
      min-height: 100vh;
    `;
  }

  return css`
    height: auto;
  `;
};

const Wrap = styled(Div)`
  width: auto;
  ${(props) => background(props)}
  ${(props) => image(props)}
  ${(props) => fluidHeight(props)}
  ${(props) => border(props)}
`;

Wrap.defaultProps = {
  theme,
};

export { Wrap };
