"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var RadioButton_exports = {};
__export(RadioButton_exports, {
  default: () => RadioButton_default
});
module.exports = __toCommonJS(RadioButton_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_color = __toESM(require("color"));
var import_Label = require("../Label");
var import_FormContext = require("../../../../context/FormContext");
var import_responsiveField = require("../../services/responsiveField");
var import_colorToString = require("../../../../../../utils/colorToString");
var import_css = require("@emotion/css");
var import_responsive_style = require("../../../../../../utils/responsive-style");
var import_use_style = require("../../../../../../../runtimes/react/use-style");
function getCheckmarkColor({
  swatch: { hue: h, saturation: s, lightness: l } = { hue: 0, saturation: 0, lightness: 0 },
  alpha: a = 1
}) {
  return (0, import_color.default)({ h, s, l }).alpha(a).isLight() ? "rgba(0, 0, 0, 0.7)" : "rgba(255, 255, 255, 0.95)";
}
function Container({ size, className, ...restOfProps }) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "div",
    {
      ...restOfProps,
      className: (0, import_css.cx)(
        (0, import_use_style.useStyle)({ position: "relative" }),
        (0, import_use_style.useStyle)(
          (0, import_responsive_style.useResponsiveStyle)([size], ([size2 = import_FormContext.Sizes.MEDIUM]) => ({
            height: (0, import_Label.getSizeHeight)(size2),
            width: (0, import_Label.getSizeHeight)(size2)
          }))
        ),
        className
      )
    }
  );
}
const FAKE_RADIO_BUTTON_CLASS_NAME = "fake-radio-button";
function FakeRadioButton({ className, contrast, error, ...restOfProps }) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "div",
    {
      ...restOfProps,
      className: (0, import_css.cx)(
        FAKE_RADIO_BUTTON_CLASS_NAME,
        (0, import_use_style.useStyle)({
          position: "absolute",
          width: "100%",
          height: "100%",
          borderStyle: "solid",
          borderRadius: "50%",
          pointerEvents: "none",
          borderWidth: 1
        }),
        (0, import_use_style.useStyle)(
          (0, import_responsive_style.useResponsiveStyle)([contrast], ([contrast2 = import_FormContext.Contrasts.LIGHT]) => ({
            borderColor: (0, import_responsiveField.getContrastBorderColor)(contrast2, error),
            backgroundColor: (0, import_responsiveField.getContrastBackgroundColor)(contrast2)
          }))
        ),
        className
      )
    }
  );
}
const HiddenRadioButton = (0, import_react.forwardRef)(function HiddenRadioButton2({ className, brandColor, contrast, error, ...restOfProps }, ref) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "input",
    {
      ...restOfProps,
      type: "radio",
      className: (0, import_css.cx)(
        (0, import_use_style.useStyle)({
          position: "absolute",
          opacity: 0,
          width: "100%",
          height: "100%",
          cursor: "pointer",
          "&:disabled": {
            cursor: "no-drop",
            [`& ~ .${FAKE_RADIO_BUTTON_CLASS_NAME}`]: {
              opacity: 0.5
            }
          },
          [`&:checked ~ .${FAKE_RADIO_BUTTON_CLASS_NAME}`]: {
            ...(0, import_responsive_style.useResponsiveStyle)(
              [brandColor],
              ([brandColor2 = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 }]) => ({
                backgroundColor: (0, import_colorToString.colorToString)(brandColor2)
              })
            ),
            borderColor: "transparent",
            "&::after": {
              content: '""',
              position: "absolute",
              boxSizing: "content-box",
              top: "50%",
              left: "50%",
              width: "50%",
              height: "50%",
              borderRadius: "50%",
              transform: "translate(-50%, -50%)",
              ...(0, import_responsive_style.useResponsiveStyle)(
                [brandColor],
                ([brandColor2 = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 }]) => ({
                  backgroundColor: getCheckmarkColor(brandColor2)
                })
              )
            }
          },
          "&:not(:disabled)": {
            [`&:focus ~ .${FAKE_RADIO_BUTTON_CLASS_NAME}`]: (0, import_responsive_style.useResponsiveStyle)(
              [brandColor],
              ([brandColor2 = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 }]) => ({
                borderColor: (0, import_colorToString.colorToString)(brandColor2)
              })
            )
          },
          "&:not(:disabled):checked": {
            [`&:focus ~ .${FAKE_RADIO_BUTTON_CLASS_NAME}`]: (0, import_responsive_style.useResponsiveStyle)(
              [contrast],
              ([contrast2 = import_FormContext.Contrasts.LIGHT]) => ({
                borderColor: (0, import_responsiveField.getContrastBorderColor)(contrast2, error)
              })
            )
          }
        }),
        className
      ),
      ref
    }
  );
});
var RadioButton_default = (0, import_react.forwardRef)(function RadioButton({ error, className, style, form, ...restOfProps }, ref) {
  const { size, contrast, brandColor } = (0, import_FormContext.useFormContext)();
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Container, { size, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      HiddenRadioButton,
      {
        ...restOfProps,
        ref,
        error,
        contrast,
        brandColor
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FakeRadioButton, { className, error, contrast, style })
  ] });
});
//# sourceMappingURL=index.js.map