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(
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_icon = __toESM(require("../icon"));
var import_utils = require("../utils");
const Checker = (props) => {
  const iconRef = (0, import_react.useRef)(null);
  const getParentProp = (name) => {
    if (props.parent && props.bindGroup) {
      return props.parent.props[name];
    }
    return null;
  };
  const disabled = (0, import_react.useMemo)(() => getParentProp("disabled") || props.disabled, [props.parent, props.disabled]);
  const direction = (0, import_react.useMemo)(() => getParentProp("direction") || null, [props.parent]);
  const iconStyle = (0, import_react.useMemo)(() => {
    const checkedColor = props.checkedColor || getParentProp("checkedColor");
    if (checkedColor && props.checked && !disabled) {
      return {
        borderColor: checkedColor,
        backgroundColor: checkedColor
      };
    }
    return {};
  }, [props.checkedColor, props.checked, disabled]);
  const onClick = (event) => {
    const {
      target
    } = event;
    const icon = iconRef.current;
    const iconClicked = icon === target || icon.contains(target);
    if (!disabled && (iconClicked || !props.labelDisabled)) {
      if (props.onToggle) {
        props.onToggle();
      }
    }
    if (props.onClick) {
      props.onClick(event);
    }
  };
  const renderIcon = () => {
    const {
      bem,
      shape,
      checked
    } = props;
    const iconSize = props.iconSize || getParentProp("iconSize");
    return /* @__PURE__ */ import_react.default.createElement("div", {
      ref: iconRef,
      className: (0, import_classnames.default)(bem("icon", [shape, {
        disabled,
        checked
      }])),
      style: {
        fontSize: (0, import_utils.addUnit)(iconSize)
      }
    }, props.iconRender ? props.iconRender({
      checked,
      disabled
    }) : /* @__PURE__ */ import_react.default.createElement(import_icon.default, {
      name: "success",
      style: iconStyle
    }));
  };
  const renderLabel = () => {
    if (props.children) {
      return /* @__PURE__ */ import_react.default.createElement("span", {
        className: props.bem("label", [props.labelPosition, {
          disabled
        }])
      }, props.children);
    }
    return null;
  };
  return /* @__PURE__ */ import_react.default.createElement("div", {
    role: props.role,
    className: (0, import_classnames.default)(props.bem([{
      disabled,
      "label-disabled": props.labelDisabled
    }, direction]), props.className),
    tabIndex: disabled ? -1 : 0,
    "aria-checked": props.checked,
    onClick
  }, props.labelPosition === "left" && renderLabel(), renderIcon(), props.labelPosition !== "left" && renderLabel());
};
Checker.defaultProps = {
  shape: "round",
  bindGroup: true
};
var stdin_default = Checker;
