"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);

// packages/components/src/toggle-group-control/toggle-group-control/component.tsx
var component_exports = {};
__export(component_exports, {
  ToggleGroupControl: () => ToggleGroupControl,
  default: () => component_default
});
module.exports = __toCommonJS(component_exports);
var import_element = require("@wordpress/element");
var import_compose = require("@wordpress/compose");
var import_context = require("../../context/index.cjs");
var import_hooks = require("../../utils/hooks/index.cjs");
var import_base_control = __toESM(require("../../base-control/index.cjs"), 1);
var import_styles = require("./styles.cjs");
var styles = __toESM(require("./styles.cjs"), 1);
var import_as_radio_group = require("./as-radio-group.cjs");
var import_as_button_group = require("./as-button-group.cjs");
var import_element_rect = require("../../utils/element-rect.cjs");
var import_use_animated_offset_rect = require("../../utils/hooks/use-animated-offset-rect.cjs");
var import_deprecated_36px_size = require("../../utils/deprecated-36px-size.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function UnconnectedToggleGroupControl(props, forwardedRef) {
  const {
    __nextHasNoMarginBottom: _,
    // Prevent passing this to the internal component
    __next40pxDefaultSize = false,
    __shouldNotWarnDeprecated36pxSize,
    className,
    isAdaptiveWidth = false,
    isBlock = false,
    isDeselectable = false,
    label,
    hideLabelFromVision = false,
    help,
    onChange,
    size = "default",
    value,
    children,
    ...otherProps
  } = (0, import_context.useContextSystem)(props, "ToggleGroupControl");
  const normalizedSize = __next40pxDefaultSize && size === "default" ? "__unstable-large" : size;
  const [selectedElement, setSelectedElement] = (0, import_element.useState)();
  const [controlElement, setControlElement] = (0, import_element.useState)();
  const refs = (0, import_compose.useMergeRefs)([setControlElement, forwardedRef]);
  const selectedRect = (0, import_element_rect.useTrackElementOffsetRect)(value !== null && value !== void 0 ? selectedElement : void 0);
  (0, import_use_animated_offset_rect.useAnimatedOffsetRect)(controlElement, selectedRect, {
    prefix: "selected",
    dataAttribute: "indicator-animated",
    transitionEndFilter: (event) => event.pseudoElement === "::before",
    roundRect: true
  });
  const cx = (0, import_hooks.useCx)();
  const classes = (0, import_element.useMemo)(() => cx(styles.toggleGroupControl({
    isBlock,
    isDeselectable,
    size: normalizedSize
  }), isBlock && styles.block, className), [className, cx, isBlock, isDeselectable, normalizedSize]);
  const MainControl = isDeselectable ? import_as_button_group.ToggleGroupControlAsButtonGroup : import_as_radio_group.ToggleGroupControlAsRadioGroup;
  (0, import_deprecated_36px_size.maybeWarnDeprecated36pxSize)({
    componentName: "ToggleGroupControl",
    size,
    __next40pxDefaultSize,
    __shouldNotWarnDeprecated36pxSize
  });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_base_control.default, {
    help,
    children: [!hideLabelFromVision && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.VisualLabelWrapper, {
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base_control.default.VisualLabel, {
        children: label
      })
    }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MainControl, {
      ...otherProps,
      setSelectedElement,
      className: classes,
      isAdaptiveWidth,
      label,
      onChange,
      ref: refs,
      size: normalizedSize,
      value,
      children
    })]
  });
}
var ToggleGroupControl = (0, import_context.contextConnect)(UnconnectedToggleGroupControl, "ToggleGroupControl");
var component_default = ToggleGroupControl;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ToggleGroupControl
});
//# sourceMappingURL=component.cjs.map
