"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 RadioElement_exports = {};
__export(RadioElement_exports, {
  default: () => RadioElement_default
});
module.exports = __toCommonJS(RadioElement_exports);
var import_react = __toESM(require("react"));
var import_styled_components = __toESM(require("styled-components"));
var import_helpers = require("../../../styles/helpers");
var import_Text = __toESM(require("../../asorted/Text"));
var import_index = require("./index");
const Label = (0, import_styled_components.default)(import_Text.default)`
  color: var(--ledger-ui-checkbox-color, ${(p) => p.theme.colors.neutral.c100});
  width: 266px;
`;
const Input = import_styled_components.default.input`
  --ledger-ui-checkbox-color: ${(p) => p.theme.colors.neutral.c50};
  --ledger-ui-checkbox-size: 1.25rem;

  position: relative;
  appearance: none;
  width: var(--ledger-ui-checkbox-size);
  height: var(--ledger-ui-checkbox-size);
  flex-shrink: 0;
  border-radius: ${(p) => `${p.theme.radii[1]}px`};
  border: 1px solid var(--ledger-ui-checkbox-color);
  cursor: pointer;

  &:checked::before {
    position: absolute;
    display: block;
    content: " ";
    background-color: var(--ledger-ui-checkbox-color);
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    border-radius: 2px;
    width: calc(var(--ledger-ui-checkbox-size) / 2);
    height: calc(var(--ledger-ui-checkbox-size) / 2);
  }

  &[data-variant="default"] {
    :hover {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.primary.c90};
    }
    :active {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.primary.c100};
    }
    :checked,
    :focus {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.primary.c80};
    }
    :focus {
      box-shadow: 0px 0px 0px 4px ${(p) => (0, import_helpers.rgba)(p.theme.colors.primary.c60, 0.48)};
    }
  }

  &[data-variant="main"] {
    :hover {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.neutral.c90};
    }
    :active,
    :checked,
    :focus {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.neutral.c100};
    }
    :focus {
      box-shadow: 0px 0px 0px 4px ${(p) => (0, import_helpers.rgba)(p.theme.colors.neutral.c60, 0.48)};
    }
  }

  &[data-variant="success"] {
    :hover,
    :checked:not([disabled]),
    :checked:not([disabled]) + ${Label}, :focus {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.success.c50};
    }
    :focus {
      box-shadow: 0px 0px 0px 4px ${(p) => (0, import_helpers.rgba)(p.theme.colors.success.c50, 0.48)};
    }
  }

  &[data-variant="error"] {
    :hover,
    :checked:not([disabled]),
    :checked:not([disabled]) + ${Label}, :focus {
      --ledger-ui-checkbox-color: ${(p) => p.theme.colors.error.c50};
    }
    :focus {
      box-shadow: 0px 0px 0px 4px ${(p) => (0, import_helpers.rgba)(p.theme.colors.error.c50, 0.48)};
    }
  }

  &[data-variant]:disabled {
    --ledger-ui-checkbox-color: ${(p) => p.theme.colors.neutral.c40};
    cursor: unset;
    background-color: ${(p) => p.theme.colors.neutral.c30};
  }
`;
const outlinedCSS = import_styled_components.css`
  padding: 20px;
  border: 1px solid ${(p) => p.theme.colors.neutral.c50};
  border-radius: ${(p) => p.theme.radii[2]}px;
  &[data-variant="default"] {
    :hover {
      border-color: ${(p) => p.theme.colors.primary.c90};
    }
    &[data-checked] :active {
      border-color: ${(p) => p.theme.colors.primary.c100};
    }
    :focus {
      border-color: ${(p) => p.theme.colors.primary.c80};
    }
  }

  &[data-variant="main"] {
    :hover {
      border-color: ${(p) => p.theme.colors.neutral.c90};
    }
    &[data-checked],
    :active :focus {
      border-color: ${(p) => p.theme.colors.neutral.c100};
    }
  }

  &[data-variant="success"] {
    &[data-checked]:not([disabled]) {
      border-color: ${(p) => p.theme.colors.success.c50};
    }
    :hover {
      border-color: ${(p) => p.theme.colors.success.c50};
    }
  }

  &[data-variant="error"] {
    &[data-checked]:not([disabled]) {
      border-color: ${(p) => p.theme.colors.error.c50};
    }
    :hover {
      border-color: ${(p) => p.theme.colors.error.c50};
    }
  }

  &[data-variant]:disabled {
    border-color: ${(p) => p.theme.colors.neutral.c40};
    cursor: unset;
  }
`;
const RadioElement = import_styled_components.default.label.attrs({ tabIndex: -1 })`
  display: inline-flex;
  column-gap: 0.75rem;
  align-items: center;
  cursor: pointer;
  &[data-variant]:disabled {
    cursor: unset;
  }
  ${(p) => p.outlined && outlinedCSS}
`;
const Element = ({
  label,
  value,
  disabled,
  outlined,
  variant = "default",
  ...props
}) => {
  const context = (0, import_react.useContext)(import_index.RadioContext);
  if (context === void 0)
    throw new Error("RadioElement must be used within a RadioProvider");
  const isChecked = (0, import_react.useMemo)(() => context.currentValue === value, [context.currentValue]);
  const handleChange = (event) => {
    context.onChange(event.target.value);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    RadioElement,
    {
      "data-variant": variant,
      ...isChecked ? { "data-checked": true } : {},
      outlined
    },
    /* @__PURE__ */ import_react.default.createElement(
      Input,
      {
        type: "radio",
        "data-variant": variant,
        checked: isChecked,
        disabled,
        onChange: handleChange,
        value,
        name: context.name,
        ...props
      }
    ),
    /* @__PURE__ */ import_react.default.createElement(Label, { variant: "paragraph" }, label)
  );
};
Element.displayName = "Radio.Element";
Element.Label = Label;
var RadioElement_default = Element;
//# sourceMappingURL=RadioElement.js.map
