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_use_merged_state = __toESM(require("../hooks/use-merged-state"));
var import_CheckboxContext = __toESM(require("./CheckboxContext"));
var import_use_refs = __toESM(require("../hooks/use-refs"));
var import_ConfigProviderContext = __toESM(require("../config-provider/ConfigProviderContext"));
const CheckBoxGroup = /* @__PURE__ */ (0, import_react.forwardRef)((props, ref) => {
  const {
    prefixCls,
    createNamespace
  } = (0, import_react.useContext)(import_ConfigProviderContext.default);
  const [bem] = createNamespace("checkbox-group", prefixCls);
  const [childrenRefs, setChildrenRefs] = (0, import_use_refs.default)();
  const [checked, setChecked] = (0, import_use_merged_state.default)({
    value: props.value,
    defaultValue: props.defaultValue
  });
  const toggleAll = (options = {}) => {
    if (typeof options === "boolean") {
      options = {
        checked: options
      };
    }
    const {
      checked: isChecked,
      skipDisabled
    } = options;
    const checkedChildren = childrenRefs.filter((item) => {
      if (!item.props.bindGroup) {
        return false;
      }
      if (item.props.disabled && skipDisabled) {
        return item.checked;
      }
      return isChecked != null ? isChecked : !item.checked;
    });
    const names = checkedChildren.map((item) => item.props.name);
    setChecked(names);
    props.onChange(names);
  };
  const toggle = (name) => {
    var _a;
    setChecked(name);
    (_a = props.onChange) == null ? void 0 : _a.call(props, name);
  };
  (0, import_react.useImperativeHandle)(ref, () => ({
    toggleAll
  }));
  return /* @__PURE__ */ import_react.default.createElement(import_CheckboxContext.default.Provider, {
    value: {
      parent: {
        props
      },
      toggle,
      checked
    }
  }, /* @__PURE__ */ import_react.default.createElement("div", {
    className: (0, import_classnames.default)(bem([props.direction]))
  }, import_react.default.Children.toArray(props.children).filter(Boolean).map((child, index) => {
    var _a;
    if (((_a = child.type) == null ? void 0 : _a.displayName) !== "Checkbox")
      return child;
    return /* @__PURE__ */ import_react.default.cloneElement(child, {
      ref: setChildrenRefs(index)
    });
  })));
});
CheckBoxGroup.defaultProps = {
  defaultValue: []
};
var stdin_default = CheckBoxGroup;
