"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _Button = _interopRequireDefault(require("../Button"));
var _ButtonGroup = _interopRequireDefault(require("../ButtonGroup"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.

const ButtonGroupControl = _ref => {
  let {
    buttons,
    selectedValues,
    onClick,
    ghost,
    monospaced,
    isResponsive,
    baseClassName
  } = _ref;
  const buttonsRef = (0, _react.useRef)([]);
  const [monoWidth, setMonoWidth] = (0, _react.useState)(0);
  (0, _react.useLayoutEffect)(() => {
    if (!monospaced) return;
    const widths = buttonsRef.current.map(button => button.getBoundingClientRect().width);
    const maxWidth = Math.max(...widths);
    if (monoWidth !== maxWidth) {
      setMonoWidth(maxWidth);
    }
  }, [monospaced, monoWidth]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonGroup.default, {
    className: `${baseClassName}__button-group`,
    children: buttons.map((_ref2, index) => {
      let {
        value,
        title,
        style = {},
        ...buttonProps
      } = _ref2;
      const shouldApplyMonoWidth = !isResponsive && monospaced && monoWidth;
      const buttonStyle = {
        width: shouldApplyMonoWidth ? monoWidth : style.width,
        ...style
      };
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
        ref: node => {
          index === 0 && (buttonsRef.current = []);
          node && buttonsRef.current.push(node);
        },
        selected: selectedValues.includes(value),
        ghost: ghost,
        onClick: () => onClick(value),
        ...buttonProps,
        className: (0, _classnames.default)(buttonProps.className, `${baseClassName}__button`),
        style: buttonStyle,
        children: title
      }, `${value}`);
    })
  });
};
var _default = exports.default = ButtonGroupControl;