function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { createContext, useContext } from "react";
import Stack from "../../atoms/stack/stack";
const checkboxGroupContext = /*#__PURE__*/createContext({});

/**
 * Hook to get access to the state of a Checkbox group
 */
export const useCheckBoxGroup = () => useContext(checkboxGroupContext);
/**
 * CheckBoxGroup is a component that groups together multiple CheckBox components.
 */
const CheckBoxGroup = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(({
  children,
  isDisabled = false,
  shape = "square",
  value = undefined,
  defaultValue = [],
  spacing = "2",
  size = "m",
  variant = "filled",
  colorScheme = "primary",
  onChange = () => {},
  ...rest
}, ref) => {
  const currentValue = value ?? defaultValue ?? [];
  const addCheckBoxGroupValue = valueToAdd => {
    onChange([...currentValue, valueToAdd]);
  };
  const deleteCheckBoxGroupValue = valueToDelete => {
    onChange(currentValue.filter(value => value !== valueToDelete));
  };
  return /*#__PURE__*/React.createElement(checkboxGroupContext.Provider, {
    value: {
      size: size,
      shape: shape,
      variant: variant,
      isDisabled: isDisabled,
      colorScheme: colorScheme,
      checkboxGroupValue: currentValue,
      addCheckBoxGroupValue: addCheckBoxGroupValue,
      deleteCheckBoxGroupValue: deleteCheckBoxGroupValue
    }
  }, /*#__PURE__*/React.createElement(Stack, _extends({
    direction: "vertical",
    spacing: spacing
  }, rest, {
    ref: ref
  }), children));
}));
CheckBoxGroup.displayName = "CheckBoxGroup";
export default CheckBoxGroup;
//# sourceMappingURL=checkbox-group.js.map