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

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

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

const borderRadius = (props) => {
  if (props.noRadius) {
    return css`
      border-radius: ${getBorderRadius(props, "cardHeader", "noRadius")};
    `;
  }

  return css`
    border-top-left-radius: ${getBorderRadius(
      props,
      "cardHeader",
      "topLeftRight"
    )};
    border-top-right-radius: ${getBorderRadius(
      props,
      "cardHeader",
      "topLeftRight"
    )};
  `;
};

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

  return css``;
};

const padding = (props) => {
  if (props.disabled) {
    return css`
    padding: ${(props) => getPadding(props, "cardHeader", "disabled")};
    `;
  }

  return css`
  padding: ${(props) => getPadding(props, "cardHeader", "default")};
  `;
};

const CardHeader = styled(Div)`
  background-color: ${(props) => getColor(props, "cardHeader", "background")};
  border-bottom: 1px solid
    ${(props) => getColor(props, "cardHeader", "borderBottom")};
  width: 100%;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  ${(props) => borderRadius(props)}
  ${(props) => src(props)}
  ${(props) => padding(props)}
`;

CardHeader.defaultProps = {
  theme,
};

export { CardHeader };
