import { useContext } from "react";
import cs from "../_util/classNames.js";
import ResizeObserver from "../_util/resizeObserver.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import IconDragDotVertical from "../../icon/react-icon/IconDragDotVertical/index.js";
import IconDragDot from "../../icon/react-icon/IconDragDot/index.js";
import IconCaretRight from "../../icon/react-icon/IconCaretRight/index.js";
import IconCaretLeft from "../../icon/react-icon/IconCaretLeft/index.js";
import IconCaretDown from "../../icon/react-icon/IconCaretDown/index.js";
import IconCaretUp from "../../icon/react-icon/IconCaretUp/index.js";
import { isObject, isFunction } from "../_util/is.js";
import omit from "../_util/omit.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 __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
function ResizeTrigger(props) {
  var _a, _b;
  var className = props.className, direction = props.direction, icon = props.icon, onMouseDown = props.onMouseDown, onResize = props.onResize, children = props.children, _c = props.collapsible, collapsible = _c === void 0 ? {} : _c, _d = props.resizable, resizable = _d === void 0 ? true : _d, renderChildren = props.renderChildren, rest = __rest(props, ["className", "direction", "icon", "onMouseDown", "onResize", "children", "collapsible", "resizable", "renderChildren"]);
  var _e = useContext(ConfigContext), getPrefixCls = _e.getPrefixCls, rtl = _e.rtl;
  var prefixCls = getPrefixCls("resizebox-trigger");
  var isHorizontal = direction === "horizontal";
  var rtlReverse = rtl && !isHorizontal;
  var classNames = cs(prefixCls, prefixCls + "-" + (isHorizontal ? "horizontal" : "vertical"), (_a = {}, _a[prefixCls + "-not-resizable"] = !resizable, _a), (_b = {}, _b[prefixCls + "-rtl"] = rtl, _b), className);
  var verticalTriggerIcon = rtlReverse ? [/* @__PURE__ */ jsx(IconCaretRight, {}, "prev"), /* @__PURE__ */ jsx(IconCaretLeft, {}, "next")] : [/* @__PURE__ */ jsx(IconCaretLeft, {}, "prev"), /* @__PURE__ */ jsx(IconCaretRight, {}, "next")];
  var prevCollapsedConfig = isObject(collapsible.prev) ? __assign(__assign({}, collapsible.prev), {
    icon: collapsible.prev.icon || (isHorizontal ? /* @__PURE__ */ jsx(IconCaretUp, {}) : verticalTriggerIcon[0])
  }) : {};
  var nextCollapsedConfig = isObject(collapsible.next) ? __assign(__assign({}, collapsible.next), {
    icon: collapsible.next.icon || (isHorizontal ? /* @__PURE__ */ jsx(IconCaretDown, {}) : verticalTriggerIcon[1])
  }) : {};
  var renderPrevCollapsedTrigger = function() {
    if (prevCollapsedConfig.icon && !prevCollapsedConfig.collapsed || nextCollapsedConfig.collapsed) {
      return /* @__PURE__ */ jsx("span", {
        className: cs(prefixCls + "-icon", cs(prefixCls + "-prev")),
        onClick: prevCollapsedConfig.onClick,
        children: prevCollapsedConfig.icon
      });
    }
    return /* @__PURE__ */ jsx("span", {
      className: cs(prefixCls + "-icon-empty")
    });
  };
  var renderNextCollapsedTrigger = function() {
    if (nextCollapsedConfig.icon && !nextCollapsedConfig.collapsed || prevCollapsedConfig.collapsed) {
      return /* @__PURE__ */ jsx("span", {
        className: cs(prefixCls + "-icon", cs(prefixCls + "-next")),
        onClick: nextCollapsedConfig.onClick,
        children: nextCollapsedConfig.icon
      });
    }
    return /* @__PURE__ */ jsx("span", {
      className: cs(prefixCls + "-icon-empty")
    });
  };
  var renderResizeTrigger = function() {
    if (resizable) {
      return /* @__PURE__ */ jsx("span", {
        className: prefixCls + "-icon",
        children: icon || (isHorizontal ? /* @__PURE__ */ jsx(IconDragDot, {}) : /* @__PURE__ */ jsx(IconDragDotVertical, {}))
      });
    }
    return /* @__PURE__ */ jsx("span", {
      className: cs(prefixCls + "-icon-empty")
    });
  };
  var prev = renderPrevCollapsedTrigger();
  var trigger = renderResizeTrigger();
  var next = renderNextCollapsedTrigger();
  var renderIcon = function() {
    return /* @__PURE__ */ jsxs("div", {
      className: prefixCls + "-icon-wrapper",
      children: [prev, trigger, next]
    });
  };
  if (!resizable) {
    return /* @__PURE__ */ jsx("div", {
      className: classNames,
      children: isFunction(renderChildren) ? renderChildren(prev, trigger, next) : children || renderIcon()
    });
  }
  return /* @__PURE__ */ jsx(ResizeObserver, {
    onResize,
    children: /* @__PURE__ */ jsx("div", {
      ...__assign({}, omit(rest, ["style"]), {
        className: classNames,
        onMouseDown
      }),
      children: isFunction(renderChildren) ? renderChildren(prev, trigger, next) : children || renderIcon()
    })
  });
}
export {
  ResizeTrigger as default
};
//# sourceMappingURL=resize-trigger.js.map
