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

// src/components/sort/components/InlineMenu/index.tsx
var InlineMenu_exports = {};
__export(InlineMenu_exports, {
  default: () => InlineMenu_default
});
module.exports = __toCommonJS(InlineMenu_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_ahooks = require("ahooks");
var import_index = require("./index.less");
var prefix = "pisell-lowcode-";
var InlineMenu = (props) => {
  const { items } = props;
  const [state, setState] = (0, import_ahooks.useControllableValue)(props);
  const value = (0, import_react.useMemo)(() => {
    return (state || "").split(":");
  }, [state]);
  const childItems = (0, import_react.useMemo)(() => {
    var _a;
    return ((_a = items.find((item) => {
      var _a2;
      return ((_a2 = item.key) == null ? void 0 : _a2.toString()) === (value == null ? void 0 : value[0]);
    })) == null ? void 0 : _a.children) || items[0].children;
  }, [value, items]);
  const handleParentClick = (detail) => {
    var _a;
    const children = items.find((item) => {
      var _a2, _b;
      return ((_a2 = item.key) == null ? void 0 : _a2.toString()) === ((_b = detail.key) == null ? void 0 : _b.toString());
    });
    const defaultKey = children.children[0].key;
    setState(((_a = detail.key) == null ? void 0 : _a.toString()) === value[0] ? "" : defaultKey, {
      key: defaultKey,
      item: children.children[0],
      keyPath: [defaultKey, detail.key]
    });
  };
  const handleChildrenClick = (detail) => {
    var _a;
    const parent = items.find(
      (item) => item.children.some((c) => c.key === detail.key)
    );
    setState((_a = detail.key) == null ? void 0 : _a.toString(), {
      key: detail.key,
      item: detail.item,
      keyPath: [detail.key, parent.key]
    });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}inline-menu-wrap` }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Menu,
    {
      items: items.map((item) => ({
        key: item.key,
        label: /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefix}menu-item-label-wrap` }, /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefix}menu-item-label` }, item.label), item.key === (value == null ? void 0 : value[0]) && /* @__PURE__ */ import_react.default.createElement(import_icons.CheckOutlined, null))
      })),
      onClick: handleParentClick,
      selectedKeys: [value == null ? void 0 : value[0]]
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_antd.Divider, { style: { margin: "6px 0" } }), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Menu,
    {
      className: `${prefix}sort-sub-menu-popup-wrap`,
      items: childItems,
      onClick: handleChildrenClick,
      selectedKeys: [state]
    }
  ));
};
var InlineMenu_default = InlineMenu;
