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

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

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

const content = (props) => {
  if (props.require) {
    return css`
      &::after {
        color: ${getColor(props, "formLabel", "require")};
        content: "*";
      }
    `;
  }
  return css``;
};

const color = (props) => {
  if (props.loading) {
    return css`
      color: transparent;
    `;
  }

  return css`
    color: ${(props) => getColor(props, "formLabel", "color")};
  `;
};

const FormLabel = styled(label)`
  display: block;
  font-family: Montserrat;
  background-color: ${(props) => getColor(props, "formLabel", "background")};
  margin-top: ${(props) => getMargin(props, "formLabel", "top")};
  margin-bottom: ${(props) => getMargin(props, "formLabel", "bottom")};
  box-sizing: border-box;
  border-radius: ${(props) => getBorderRadius(props, "formLabel", "default")};
  ${(props) => content(props)};
  ${(props) => color(props)};
`;

FormLabel.defaultProps = {
  theme,
};

export { FormLabel };
