var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
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);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var stdin_exports = {};
__export(stdin_exports, {
  Highlight: () => Highlight,
  ProHelpSelect: () => ProHelpSelect
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_icons_vue = require("@ant-design/icons-vue");
var import_pro_provider = __toESM(require("@antdv/pro-provider"));
var import_pro_utils = require("@antdv/pro-utils");
var import_ant_design_vue = require("ant-design-vue");
var import_select = require("ant-design-vue/es/select");
var import_context = require("ant-design-vue/lib/config-provider/context");
var import_vue2 = require("vue");
var import_HelpProvide = require("./HelpProvide");
const Highlight = (0, import_vue2.defineComponent)({
  name: "Highlight",
  props: {
    label: (0, import_pro_utils.stringType)().isRequired,
    words: (0, import_pro_utils.arrayType)().isRequired
  },
  setup(props) {
    const {
      getPrefixCls
    } = (0, import_context.useConfigContextInject)();
    const lightCls = getPrefixCls("pro-help-search-list-item-content-light");
    const optionCls = getPrefixCls("pro-help-search-list-item-content");
    const {
      wrapSSR
    } = (0, import_pro_provider.useStyle)("Highlight", (token) => {
      return {
        [`.${lightCls}`]: {
          color: token.colorPrimary
        },
        [`.${optionCls}`]: {
          flex: "auto",
          overflow: "hidden",
          whiteSpace: "nowrap",
          textOverflow: "ellipsis"
        }
      };
    });
    return () => {
      const {
        words,
        label
      } = props;
      if (words.length === 0) return (0, import_vue.createVNode)(import_vue.Fragment, null, [label]);
      const matchKeywordsRE = new RegExp(words.map((word) => word.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&")).join("|"), "gi");
      let matchText = label;
      const elements = [];
      while (matchText.length) {
        const match = matchKeywordsRE.exec(matchText);
        if (!match) {
          elements.push(matchText);
          break;
        }
        const start = match.index;
        const matchLength = match[0].length + start;
        elements.push(matchText.slice(0, start), (0, import_vue2.h)("span", {
          className: lightCls
        }, matchText.slice(start, matchLength)));
        matchText = matchText.slice(matchLength);
      }
      return wrapSSR((0, import_vue2.h)("div", {
        title: label,
        className: optionCls
      }, elements));
    };
  }
});
const ProHelpSelect = (0, import_vue2.defineComponent)({
  name: "ProHelpSelect",
  props: __spreadProps(__spreadValues({}, (0, import_pro_utils.omit)((0, import_select.selectProps)(), ["onSearch", "optionFilterProp", "options", "filterOption"])), {
    className: (0, import_pro_utils.stringType)().isRequired,
    iconClassName: (0, import_pro_utils.stringType)()
  }),
  setup(props) {
    const {
      dataSource
    } = import_HelpProvide.ProHelpContext.useContext();
    const {
      hashId
    } = import_pro_provider.default.useContext();
    const [keyWord, setKeyWork] = (0, import_pro_utils.useState)("");
    const [open, setOpen] = (0, import_pro_utils.useState)(false);
    const debounceSetKeyWork = (0, import_pro_utils.useDebounceFn)((key) => __async(this, null, function* () {
      return setKeyWork(key);
    }), 20);
    return () => {
      return (0, import_vue.createVNode)(import_vue.Fragment, null, [!open.value ? (0, import_vue.createVNode)("div", {
        "class": (0, import_pro_utils.classNames)(props.iconClassName, hashId)
      }, [(0, import_vue.createVNode)(import_icons_vue.SearchOutlined, {
        "title": "search panel",
        "onClick": () => {
          setOpen(true);
        }
      }, null)]) : null, open.value ? (0, import_vue.createVNode)(import_ant_design_vue.Select, (0, import_vue.mergeProps)({
        "placeholder": "please input search text",
        "showSearch": true,
        "bordered": false,
        "onBlur": () => {
          setOpen(false);
        },
        "size": "small"
      }, (0, import_pro_utils.omit)(props, ["size", "showSearch", "bordered", "onBlur", "placeholder", "choiceTransitionName"]), {
        "choiceTransitionName": props.choiceTransitionName,
        "onSearch": (value) => {
          debounceSetKeyWork.cancel();
          debounceSetKeyWork.run(value);
        },
        "filterOption": (input, option) => {
          var _a;
          return ((_a = option == null ? void 0 : option.title) != null ? _a : "").toLowerCase().includes(input.toLowerCase());
        },
        "dropdownMatchSelectWidth": false,
        "options": dataSource == null ? void 0 : dataSource.map((item) => {
          var _a;
          return {
            label: (0, import_vue.createVNode)(Highlight, {
              "label": item.title,
              "words": [keyWord.value].filter(Boolean)
            }, null),
            title: item.title,
            value: item.key,
            options: (_a = item.children) == null ? void 0 : _a.map((sunItem) => {
              return {
                label: (0, import_vue.createVNode)(Highlight, {
                  "label": sunItem.title,
                  "words": [keyWord.value].filter(Boolean)
                }, null),
                title: sunItem.title,
                value: sunItem.key,
                dataItemKey: item.key
              };
            })
          };
        })
      }), null) : null]);
    };
  }
});
