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/comment-editor/at/index.tsx
var at_exports = {};
__export(at_exports, {
  default: () => at_default
});
module.exports = __toCommonJS(at_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_iconfont = __toESM(require("../../iconfont"));
var import_ahooks = require("ahooks");
var import_axios = require("../../_util/axios");
var import_util = require("../../_util/index");
var import_context = require("../../config-provider/context");
var import_constants = require("../../_util/constants");
var import_index = require("./index.less");
var { Option } = import_antd.Select;
var CommentAt = (props) => {
  const { uiLocale } = (0, import_react.useContext)(import_context.ConfigContext);
  const [visible, setVisible] = (0, import_react.useState)(false);
  const [key, setKey] = (0, import_react.useState)(Date.now());
  const [list, setList] = (0, import_react.useState)([]);
  const { run } = (0, import_ahooks.useDebounceFn)(
    async (value) => {
      value = (0, import_util.includeEn)(value) ? (0, import_util.empty)(value) : (0, import_util.emptyAll)(value);
      if (!value)
        return;
      const data = await (0, import_axios.get)({ url: `${import_constants.EHR_SERVICE}/api/auth4web/employee/list/${value}` });
      let newList = data == null ? void 0 : data.map(({ jobNumber, name, ...rest }) => ({
        id: jobNumber,
        name,
        other: rest
      }));
      setList(newList);
    },
    { wait: 200 }
  );
  const onChange = (id) => {
    var _a;
    const { insertHtml } = props;
    const selectItem = (_a = list.filter((item) => item.id === id)) == null ? void 0 : _a[0];
    insertHtml(`<a data-id=${selectItem.id} data-name=${selectItem.name}>@${selectItem.name}</a>`, { className: "at" });
    setVisible(false);
    setKey(Date.now());
    setList([]);
  };
  return /* @__PURE__ */ import_react.default.createElement("span", { className: "u-comment-controller-item u-comment-controller-at" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Popover,
    {
      open: visible,
      overlayClassName: "comment-at-popover",
      onOpenChange: (visible2) => setVisible(visible2),
      placement: "bottom",
      content: /* @__PURE__ */ import_react.default.createElement(
        import_antd.Select,
        {
          key,
          filterOption: false,
          placeholder: uiLocale.Comment.placeholderAt,
          showSearch: true,
          onSearch: run,
          onChange,
          style: { width: 335 },
          notFoundContent: null
        },
        list.map((item) => {
          var _a;
          return /* @__PURE__ */ import_react.default.createElement(Option, { key: item.id, value: item.id }, item.name, " | ", item.id, " | ", (_a = item.other) == null ? void 0 : _a.popo);
        })
      ),
      trigger: "click"
    },
    /* @__PURE__ */ import_react.default.createElement(import_iconfont.default, { type: "icon-ehr-ui-aite" })
  ));
};
var at_default = CommentAt;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
