import { colorToString } from "../../../../../utils/colorToString";
import {
  Shapes,
  Sizes,
  Contrasts
} from "../../../context/FormContext";
import { useResponsiveStyle } from "../../../../../utils/responsive-style";
function getSizeHeight(size) {
  switch (size) {
    case Sizes.SMALL:
      return 30;
    case Sizes.MEDIUM:
      return 38;
    case Sizes.LARGE:
      return 48;
    default:
      throw new Error(`Invalid form size "${size}"`);
  }
}
function getSizeHorizontalPadding(size) {
  switch (size) {
    case Sizes.SMALL:
      return 8;
    case Sizes.MEDIUM:
      return 12;
    case Sizes.LARGE:
      return 16;
    default:
      throw new Error(`Invalid form size "${size}"`);
  }
}
function getSizeVerticalPadding(size) {
  switch (size) {
    case Sizes.SMALL:
      return 3;
    case Sizes.MEDIUM:
      return 7;
    case Sizes.LARGE:
      return 11;
    default:
      throw new Error(`Invalid form size "${size}"`);
  }
}
function getShapeBorderRadius(shape) {
  switch (shape) {
    case Shapes.SQUARE:
      return 0;
    case Shapes.ROUNDED:
      return 4;
    case Shapes.PILL:
      return 500;
    default:
      throw new Error(`Invalid form shape "${shape}"`);
  }
}
function getContrastBorderColor(contrast, error) {
  switch (contrast) {
    case Contrasts.LIGHT:
      return error ? "rgba(255, 0, 0, 0.7)" : "rgba(0, 0, 0, 0.25)";
    case Contrasts.DARK:
      return error ? "rgba(255, 0, 0, 0.7)" : "rgba(255, 255, 255, 0.6)";
    default:
      throw new Error(`Invalid form contrast "${contrast}"`);
  }
}
function getContrastBackgroundColor(contrast) {
  switch (contrast) {
    case Contrasts.LIGHT:
      return "white";
    case Contrasts.DARK:
      return "rgba(0, 0, 0, 0.7)";
    default:
      throw new Error(`Invalid form contrast "${contrast}"`);
  }
}
function getContrastColor(contrast) {
  switch (contrast) {
    case Contrasts.LIGHT:
      return "rgba(0, 0, 0, 0.95)";
    case Contrasts.DARK:
      return "white";
    default:
      throw new Error(`Invalid form contrast "${contrast}"`);
  }
}
function getContrastPlaceholderColor(contrast) {
  switch (contrast) {
    case Contrasts.LIGHT:
      return "rgba(0, 0, 0, 0.3)";
    case Contrasts.DARK:
      return "rgba(255,255,255,0.3)";
    default:
      throw new Error(`Invalid form contrast "${contrast}"`);
  }
}
function responsiveField(props) {
  return {
    display: "block",
    width: "100%",
    outline: "none",
    borderWidth: 1,
    borderStyle: "solid",
    transition: "border-color 200ms",
    ...useResponsiveStyle(
      [props.shape, props.size, props.contrast, props.brandColor],
      ([
        shape = Shapes.ROUNDED,
        size = Sizes.MEDIUM,
        contrast = Contrasts.LIGHT,
        brandColor = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 }
      ]) => ({
        padding: `${getSizeVerticalPadding(size)}px ${getSizeHorizontalPadding(size)}px`,
        borderRadius: getShapeBorderRadius(shape),
        borderColor: getContrastBorderColor(contrast, props.error),
        color: getContrastColor(contrast),
        backgroundColor: getContrastBackgroundColor(contrast),
        ":focus, :focus-within": {
          borderColor: colorToString(brandColor)
        },
        "::placeholder": {
          color: getContrastPlaceholderColor(contrast)
        }
      })
    )
  };
}
export {
  responsiveField as default,
  getContrastBackgroundColor,
  getContrastBorderColor,
  getContrastColor,
  getShapeBorderRadius,
  getSizeHeight,
  getSizeHorizontalPadding
};
//# sourceMappingURL=responsiveField.js.map