"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 Checkbox_exports = {};
__export(Checkbox_exports, {
  default: () => Checkbox_default
});
module.exports = __toCommonJS(Checkbox_exports);
var import_react = __toESM(require("react"));
var import_styled_components = __toESM(require("styled-components"));
var import_Text = __toESM(require("../../asorted/Text"));
var import_CheckAloneMedium = __toESM(require("@ledgerhq/icons-ui/reactLegacy/CheckAloneMedium"));
var import_server = require("react-dom/server");
const Icon = () => import_react.default.cloneElement((0, import_CheckAloneMedium.default)({ size: 13, color: "currentColor" }), {
  // the xmlns attribute is required to properly display the checkbox
  xmlns: "http://www.w3.org/2000/svg"
});
const CheckMarkIcon = encodeURIComponent((0, import_server.renderToStaticMarkup)(/* @__PURE__ */ import_react.default.createElement(Icon, null)));
const Input = import_styled_components.default.input`
  background-color: transparent;

  border-radius: ${(p) => `${p.theme.radii[1]}px`};
  position: relative;

  min-width: ${(p) => p.theme.space[7]}px;
  height: ${(p) => p.theme.space[7]}px;
  appearance: none;
  border: 1px solid ${(props) => props.theme.colors.neutral.c90};
  box-shadow: none;

  &:checked {
    background-color: currentColor;
    border-color: currentColor;
  }

  &:checked::after {
    content: " ";
    width: ${(p) => p.theme.space[7]}px;
    height: ${(p) => p.theme.space[7]}px;
    display: inline-block;
    color: ${(props) => props.theme.colors.neutral.c00};

    background-image: url("data:image/svg+xml,${CheckMarkIcon}");
    background-position: center;
    background-repeat: no-repeat;

    /* Trick to center the check mark by taking into account the border */
    position: absolute;
    top: -1px;
    left: -1px;
  }
`;
const Label = (0, import_styled_components.default)(import_Text.default).attrs({ type: "body", fontWeight: "500" })`
  color: ${(props) => props.theme.colors.neutral.c80};

  /* Version when the input is checked */
  ${Input}:checked + & {
    color: currentColor;
  }

  &:first-letter {
    text-transform: uppercase;
  }
`;
const Container = import_styled_components.default.div`
  --ll-checkbox-color: unset;
  color: var(--ll-checkbox-color, ${(props) => props.theme.colors.primary.c90});

  display: inline-flex;
  column-gap: ${(p) => p.theme.space[5]}px;
  align-items: center;
  cursor: pointer;

  &[data-variant="default"] {
    --ll-checkbox-color: ${(props) => props.theme.colors.primary.c90};
  }

  &[data-variant="success"] {
    --ll-checkbox-color: ${(props) => props.theme.colors.success.c50};
  }

  &[data-variant="error"] {
    --ll-checkbox-color: ${(props) => props.theme.colors.error.c50};
  }

  &[data-disabled="true"] {
    --ll-checkbox-color: ${(props) => props.theme.colors.neutral.c80};
    cursor: unset;
  }
`;
const Checkbox = ({
  isDisabled = false,
  variant = "default",
  label,
  isChecked,
  name,
  onChange
}) => /* @__PURE__ */ import_react.default.createElement(Container, { "data-variant": variant, "data-disabled": isDisabled }, /* @__PURE__ */ import_react.default.createElement(
  Input,
  {
    type: "checkbox",
    name,
    id: name,
    checked: isChecked,
    disabled: isDisabled,
    onChange: () => onChange(!isChecked)
  }
), label ? /* @__PURE__ */ import_react.default.createElement(Label, { as: "label", htmlFor: name }, label) : null);
var Checkbox_default = Checkbox;
//# sourceMappingURL=Checkbox.js.map
