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

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

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

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

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

const overlay = (props) => {
  if (props.disabled) {
    return css`
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: ${getColor(props, "cardImageHeader", "color")};
      opacity: 0.5;
    `;
  }

  return css``;
};

const loading = (props) =>
    props.loading &&
    css`
    opacity: 0;
    cursor: progress;
    `;

const CardImageHeader = styled(Img)`
  width: 100%;
  display: flex;
  ${(props) => borderRadius(props)}
  ${(props) => overlay(props)}
  ${(props) => loading(props)}
`;

CardImageHeader.defaultProps = {
  theme,
};


export { CardImageHeader };
