import { forwardRef, useContext } from "react";
import Button$2 from "../Button/index.js";
import Dropdown from "./index.js";
import IconMore from "../../icon/react-icon/IconMore/index.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { pickDataAttributes } from "../_util/pick.js";
import { jsx, jsxs } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var defaultProps = {
  position: "br",
  trigger: "hover",
  type: "default",
  icon: /* @__PURE__ */ jsx(IconMore, {}),
  unmountOnExit: true
};
function Button(baseProps, ref) {
  var _a;
  var componentConfig = useContext(ConfigContext).componentConfig;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig["Dropdown.Button"]);
  var className = props.className, style = props.style, children = props.children, disabled = props.disabled, droplist = props.droplist, _b = props.position, position = _b === void 0 ? "br" : _b, _c = props.trigger, trigger = _c === void 0 ? "hover" : _c, _d = props.type, type = _d === void 0 ? "default" : _d, size = props.size, _e = props.icon, icon = _e === void 0 ? /* @__PURE__ */ jsx(IconMore, {}) : _e, _f = props.unmountOnExit, unmountOnExit = _f === void 0 ? true : _f, onClick = props.onClick, onVisibleChange = props.onVisibleChange, buttonProps = props.buttonProps, buttonsRender = props.buttonsRender;
  var leftButton = /* @__PURE__ */ jsx(Button$2, {
    ...__assign({
      disabled,
      type,
      size,
      onClick
    }, buttonProps),
    children
  });
  var rightButton = /* @__PURE__ */ jsx(Button$2, {
    disabled,
    type,
    size,
    icon
  });
  if (buttonsRender) {
    _a = __read(buttonsRender([leftButton, rightButton]), 2), leftButton = _a[0], rightButton = _a[1];
  }
  var disableTrigger = disabled || !rightButton || rightButton.props && rightButton.props.loading;
  return /* @__PURE__ */ jsxs(Button$2.Group, {
    ...__assign({
      className,
      style,
      ref
    }, pickDataAttributes(props)),
    children: [leftButton, /* @__PURE__ */ jsx(Dropdown, {
      disabled,
      droplist,
      position,
      trigger,
      unmountOnExit,
      onVisibleChange,
      triggerProps: {
        disabled: disableTrigger
      },
      children: rightButton
    })]
  });
}
var ButtonComponent = forwardRef(Button);
ButtonComponent.displayName = "DropdownButton";
const Button$1 = ButtonComponent;
export {
  Button$1 as default
};
//# sourceMappingURL=button.js.map
