import { defineComponent, ref, createVNode, h, render, computed, nextTick, watch, onUnmounted, unref, mergeProps, reactive, getCurrentInstance, withDirectives, withModifiers, resolveComponent, Teleport, Transition, vShow, resolveDirective } from "vue";
import { offset, autoPlacement, arrow, shift, computePosition } from "@floating-ui/dom";
const editableSelectProps = {
  modelValue: {
    type: String,
    default: ""
  },
  options: {
    type: Array,
    default: () => []
  },
  allowClear: {
    type: Boolean,
    default: false
  },
  disabled: {
    type: Boolean
  },
  disabledKey: {
    type: String,
    default: ""
  },
  placeholder: {
    type: String,
    default: "Search"
  },
  width: {
    type: Number
  },
  maxHeight: {
    type: Number
  },
  loading: {
    type: Boolean
  },
  enableLazyLoad: {
    type: Boolean,
    default: false
  },
  searchFn: {
    type: Function
  },
  filterOption: {
    type: [Function, Boolean]
  }
};
const inBrowser = typeof window !== "undefined";
function on(element, eventName, handler) {
  if (document.addEventListener) {
    if (element && eventName && handler) {
      element.addEventListener(eventName, handler, false);
    }
  } else {
    if (element && eventName && handler) {
      element.attachEvent("on" + eventName, handler);
    }
  }
}
const ctx = Symbol("@@clickoutside");
const nodeList = /* @__PURE__ */ new Map();
let startClick;
let nid = 0;
let isFirst = true;
function createDocumentHandler(el, binding, vnode) {
  if (inBrowser && isFirst) {
    isFirst = false;
    on(document, "mousedown", (e) => {
      startClick = e;
    });
    on(document, "mouseup", (e) => {
      for (const [id, node] of nodeList) {
        node[ctx].documentHandler(e, startClick);
      }
    });
  }
  return function(mouseup, mousedown) {
    if (!vnode || !binding.instance || !mouseup.target || !mousedown.target || el.contains(mouseup.target) || el.contains(mousedown.target) || el === mouseup.target) {
      return;
    }
    el[ctx].bindingFn && el[ctx].bindingFn();
  };
}
const clickoutsideDirective = {
  beforeMount: function(el, binding, vnode) {
    nid++;
    nodeList.set(nid, el);
    el[ctx] = {
      nid,
      documentHandler: createDocumentHandler(el, binding, vnode),
      bindingFn: binding.value
    };
  },
  updated: function(el, binding, vnode) {
    el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
    el[ctx].bindingFn = binding.value;
  },
  unmounted: function(el) {
    nodeList.delete(el[ctx].nid);
    delete el[ctx];
  }
};
class View {
  constructor() {
    this.top = "50%";
    this.left = "50%";
  }
}
const loadingProps = {
  message: String,
  backdrop: Boolean,
  view: {
    type: Object,
    default: () => new View()
  },
  zIndex: Number,
  isFull: {
    type: Boolean,
    default: false
  }
};
class LoadingOptions {
  constructor() {
    this.backdrop = true;
    this.positionType = "relative";
    this.view = new View();
  }
}
function createBem(namespace, element, modifier) {
  let cls = namespace;
  if (element) {
    cls += `__${element}`;
  }
  if (modifier) {
    cls += `--${modifier}`;
  }
  return cls;
}
function useNamespace(block, needDot = false) {
  const namespace = needDot ? `.devui-${block}` : `devui-${block}`;
  const b = () => createBem(namespace);
  const e = (element) => element ? createBem(namespace, element) : "";
  const m = (modifier) => modifier ? createBem(namespace, "", modifier) : "";
  const em = (element, modifier) => element && modifier ? createBem(namespace, element, modifier) : "";
  return {
    b,
    e,
    m,
    em
  };
}
var loading = "";
var Loading = defineComponent({
  name: "DLoading",
  inheritAttrs: false,
  props: loadingProps,
  setup(props) {
    const style = {
      top: props.view.top,
      left: props.view.left,
      zIndex: props.zIndex
    };
    if (!props.message) {
      style.background = "none";
    }
    const isShow = ref(false);
    const open = () => {
      isShow.value = true;
    };
    const close = () => {
      isShow.value = false;
    };
    return {
      style,
      isShow,
      open,
      close
    };
  },
  render() {
    var _a;
    const {
      isShow,
      isFull,
      backdrop,
      style,
      message,
      $slots
    } = this;
    const ns = useNamespace("loading");
    return isShow && createVNode("div", {
      "class": [ns.b(), isFull ? ns.m("full") : ""]
    }, [((_a = $slots.default) == null ? void 0 : _a.call($slots)) || createVNode("div", {
      "class": ns.e("wrapper")
    }, [backdrop ? createVNode("div", {
      "class": ns.e("mask")
    }, null) : null, createVNode("div", {
      "style": style,
      "class": ns.e("area")
    }, [createVNode("div", {
      "class": ns.e("busy-default-spinner")
    }, [createVNode("div", {
      "class": ns.e("bar1")
    }, null), createVNode("div", {
      "class": ns.e("bar2")
    }, null), createVNode("div", {
      "class": ns.e("bar3")
    }, null), createVNode("div", {
      "class": ns.e("bar4")
    }, null)]), message ? createVNode("span", {
      "class": ns.e("text")
    }, [message]) : null])])]);
  }
});
const COMPONENT_CONTAINER_SYMBOL = Symbol("dev_component_container");
function createComponent(component, props, children = null) {
  const vnode = h(component, { ...props }, children);
  const container = document.createElement("div");
  vnode[COMPONENT_CONTAINER_SYMBOL] = container;
  render(vnode, container);
  return vnode.component;
}
function unmountComponent(ComponnetInstance) {
  render(null, ComponnetInstance == null ? void 0 : ComponnetInstance.vnode[COMPONENT_CONTAINER_SYMBOL]);
}
const loadingConstructor = defineComponent(Loading);
const cacheInstance = /* @__PURE__ */ new WeakSet();
const isEmpty = (val) => {
  if (!val) {
    return true;
  }
  if (Array.isArray(val)) {
    return val.length === 0;
  }
  if (val instanceof Set || val instanceof Map) {
    return val.size === 0;
  }
  if (val instanceof Promise) {
    return false;
  }
  if (typeof val === "object") {
    try {
      return Object.keys(val).length === 0;
    } catch (e) {
      return false;
    }
  }
  return false;
};
const getType = (vari) => {
  return Object.prototype.toString.call(vari).slice(8, -1).toLowerCase();
};
const isPromise = (value) => {
  const type = getType(value);
  switch (type) {
    case "promise":
      return [value];
    case "array":
      if (value.some((val) => getType(val) !== "promise")) {
        console.error(new TypeError("Binding values should all be of type Promise"));
        return "error";
      }
      return value;
    default:
      return false;
  }
};
const unmount = (el) => {
  cacheInstance.delete(el);
  el.instance.proxy.close();
  unmountComponent(el.instance);
};
const toggleLoading = (el, binding) => {
  var _a, _b, _c;
  if (binding.value) {
    const vals = isPromise(binding.value);
    if (vals === "error") {
      return;
    }
    (_c = (_b = (_a = el == null ? void 0 : el.instance) == null ? void 0 : _a.proxy) == null ? void 0 : _b.open) == null ? void 0 : _c.call(_b);
    el.appendChild(el.mask);
    cacheInstance.add(el);
    if (vals) {
      Promise.all(vals).catch((err) => {
        console.error(new Error("Promise handling errors"), err);
      }).finally(() => {
        unmount(el);
      });
    }
  } else {
    unmount(el);
  }
};
const removeAttribute = (el) => {
  el.removeAttribute("zindex");
  el.removeAttribute("positiontype");
  el.removeAttribute("backdrop");
  el.removeAttribute("message");
  el.removeAttribute("view");
  el.removeAttribute("loadingtemplateref");
};
const handleProps = (el, vprops) => {
  var _a;
  const props = {
    ...new LoadingOptions(),
    ...vprops
  };
  const loadingTemplateRef = props.loadingTemplateRef;
  const loadingInstance = createComponent(loadingConstructor, { ...props }, loadingTemplateRef ? () => loadingTemplateRef : null);
  el.style.position = props.positionType;
  el.options = props;
  el.instance = loadingInstance;
  el.mask = (_a = loadingInstance == null ? void 0 : loadingInstance.proxy) == null ? void 0 : _a.$el;
};
const loadingDirective = {
  mounted: function(el, binding, vnode) {
    handleProps(el, vnode.props);
    removeAttribute(el);
    !isEmpty(binding.value) && toggleLoading(el, binding);
  },
  updated: function(el, binding, vnode) {
    if (!isEmpty(binding.value) && cacheInstance.has(el) || isEmpty(binding.value) && !cacheInstance.has(el)) {
      return;
    }
    !cacheInstance.has(el) && handleProps(el, vnode.props);
    removeAttribute(el);
    toggleLoading(el, binding);
  }
};
function className(classStr, classOpt) {
  let classname = classStr;
  if (typeof classOpt === "object") {
    Object.keys(classOpt).forEach((key) => {
      classOpt[key] && (classname += ` ${key}`);
    });
  }
  return classname;
}
var editableSelect = "";
function useSelect(props) {
  const normalizeOptions = computed(() => {
    return props.options.map((option) => {
      let res;
      if (option !== "null" && typeof option === "object") {
        res = {
          ...option,
          label: option.label || "",
          value: option.value !== void 0 ? option.value : option.label || ""
        };
      } else {
        res = {
          label: String(option),
          value: option
        };
      }
      return res;
    });
  });
  return { normalizeOptions };
}
function useFilterOptions(enableLazyLoad, normalizeOptions, inputValue, searchFn) {
  const filteredOptions = computed(() => {
    if (!inputValue.value || enableLazyLoad) {
      return normalizeOptions.value;
    }
    return normalizeOptions.value.filter((option) => {
      return searchFn(option, inputValue.value);
    });
  });
  return { filteredOptions };
}
function useInput(inputValue, ctx2) {
  const onInputChange = (value) => {
    ctx2.emit("search", value);
  };
  const handleInput = (event) => {
    const value = event.target.value;
    inputValue.value = value;
    onInputChange(value);
  };
  return {
    handleInput
  };
}
function useLazyLoad(dropdownRef, enableLazyLoad, ctx2) {
  const loadMore = () => {
    const dropdownVal = dropdownRef.value;
    if (!enableLazyLoad) {
      return;
    }
    if (dropdownVal.clientHeight + dropdownVal.scrollTop >= dropdownVal.scrollHeight) {
      ctx2.emit("loadMore");
    }
  };
  return { loadMore };
}
function useKeyboardSelect(dropdownRef, visible, inputValue, cacheInput, filteredOptions, optionDisabledKey, filterOption, loading2, handleClick, closeMenu, toggleMenu) {
  const hoverIndex = ref(0);
  const selectedIndex = ref(0);
  const updateHoveringIndex = (index2) => {
    hoverIndex.value = index2;
  };
  const scrollToItem = (index2) => {
    const ul = dropdownRef.value;
    const li = ul.children[index2];
    nextTick(() => {
      if (li.scrollIntoViewIfNeeded) {
        li.scrollIntoViewIfNeeded(false);
      } else {
        const containerInfo = ul.getBoundingClientRect();
        const elementInfo = li.getBoundingClientRect();
        if (elementInfo.bottom > containerInfo.bottom || elementInfo.top < containerInfo.top) {
          li.scrollIntoView(false);
        }
      }
    });
  };
  const handleEscape = () => {
    inputValue.value = cacheInput.value;
    closeMenu();
  };
  const handleEnter = () => {
    const len = filteredOptions.value.length;
    if (!visible.value || !len) {
      return toggleMenu();
    }
    len && len === 1 ? handleClick(filteredOptions.value[0], 1) : handleClick(filteredOptions.value[hoverIndex.value], hoverIndex.value);
    return closeMenu();
  };
  const handleKeyboardNavigation = (direction) => {
    const len = filteredOptions.value.length;
    if (!len || len === 1) {
      return;
    }
    if (!["ArrowDown", "ArrowUp"].includes(direction)) {
      return;
    }
    if (filterOption === false && loading2.value) {
      return;
    }
    let newIndex = 0;
    newIndex = hoverIndex.value;
    if (direction === "ArrowUp") {
      newIndex -= 1;
      if (newIndex === -1) {
        newIndex = len - 1;
      }
    } else if (direction === "ArrowDown") {
      newIndex += 1;
      if (newIndex === len) {
        newIndex = 0;
      }
    }
    hoverIndex.value = newIndex;
    const option = filteredOptions.value[newIndex];
    if (option[optionDisabledKey]) {
      return handleKeyboardNavigation(direction);
    }
    updateHoveringIndex(newIndex);
    scrollToItem(newIndex);
  };
  const handleKeydown = (event) => {
    const keyCode = event.key || event.code;
    switch (keyCode) {
      case "Escape":
        handleEscape();
        break;
      case "Enter":
        handleEnter();
        break;
      default:
        handleKeyboardNavigation(keyCode);
    }
  };
  return { handleKeydown, hoverIndex, selectedIndex };
}
const flexibleOverlayProps = {
  modelValue: {
    type: Boolean,
    default: false
  },
  origin: {
    type: Object,
    require: true
  },
  position: {
    type: Array,
    default: ["bottom"]
  },
  offset: {
    type: [Number, Object],
    default: 8
  },
  shiftOffset: {
    type: Number
  },
  align: {
    type: String,
    default: null
  },
  showArrow: {
    type: Boolean,
    default: false
  },
  isArrowCenter: {
    type: Boolean,
    default: true
  }
};
function getScrollParent(element) {
  const overflowRegex = /(auto|scroll|hidden)/;
  for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
    const style = window.getComputedStyle(parent);
    if (overflowRegex.test(style.overflow + style.overflowX + style.overflowY)) {
      return parent;
    }
  }
  return window;
}
function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
  let { x, y } = point;
  if (!isArrowCenter) {
    const { width, height } = originRect;
    if (x && placement.includes("start")) {
      x = 12;
    }
    if (x && placement.includes("end")) {
      x = Math.round(width - 24);
    }
    if (y && placement.includes("start")) {
      y = 10;
    }
    if (y && placement.includes("end")) {
      y = height - 14;
    }
  }
  return { x, y };
}
function useOverlay(props, emit) {
  const overlayRef = ref();
  const arrowRef = ref();
  let originParent = null;
  const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
    const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
    const staticSide = {
      top: "bottom",
      right: "left",
      bottom: "top",
      left: "right"
    }[placement.split("-")[0]];
    Object.assign(arrowEl.style, {
      left: x ? `${x}px` : "",
      top: y ? `${y}px` : "",
      right: "",
      bottom: "",
      [staticSide]: "-4px"
    });
  };
  const updatePosition = async () => {
    const hostEl = props.origin;
    const overlayEl = unref(overlayRef.value);
    const arrowEl = unref(arrowRef.value);
    const middleware = [
      offset(props.offset),
      autoPlacement({
        alignment: props.align,
        allowedPlacements: props.position
      })
    ];
    props.showArrow && middleware.push(arrow({ element: arrowEl }));
    props.shiftOffset !== void 0 && middleware.push(shift());
    const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
      strategy: "fixed",
      middleware
    });
    let applyX = x;
    let applyY = y;
    if (props.shiftOffset !== void 0) {
      const { x: shiftX, y: shiftY } = middlewareData.shift;
      shiftX < 0 && (applyX -= props.shiftOffset);
      shiftX > 0 && (applyX += props.shiftOffset);
      shiftY < 0 && (applyY -= props.shiftOffset);
      shiftY > 0 && (applyY += props.shiftOffset);
    }
    emit("positionChange", placement);
    Object.assign(overlayEl.style, { top: `${applyY}px`, left: `${applyX}px` });
    props.showArrow && updateArrowPosition(arrowEl, placement, middlewareData.arrow, overlayEl);
  };
  watch(() => props.modelValue, () => {
    if (props.modelValue && props.origin) {
      originParent = getScrollParent(props.origin);
      nextTick(updatePosition);
      originParent == null ? void 0 : originParent.addEventListener("scroll", updatePosition);
      originParent !== window && window.addEventListener("scroll", updatePosition);
      window.addEventListener("resize", updatePosition);
    } else {
      originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
      originParent !== window && window.removeEventListener("scroll", updatePosition);
      window.removeEventListener("resize", updatePosition);
    }
  });
  onUnmounted(() => {
    originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
    originParent !== window && window.removeEventListener("scroll", updatePosition);
    window.removeEventListener("resize", updatePosition);
  });
  return { arrowRef, overlayRef, updatePosition };
}
var flexibleOverlay = "";
const FlexibleOverlay = defineComponent({
  name: "DFlexibleOverlay",
  inheritAttrs: false,
  props: flexibleOverlayProps,
  emits: ["update:modelValue", "positionChange"],
  setup(props, {
    slots,
    attrs,
    emit,
    expose
  }) {
    const ns = useNamespace("flexible-overlay");
    const {
      arrowRef,
      overlayRef,
      updatePosition
    } = useOverlay(props, emit);
    expose({
      updatePosition
    });
    return () => {
      var _a;
      return props.modelValue && createVNode("div", mergeProps({
        "ref": overlayRef,
        "class": ns.b()
      }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots), props.showArrow && createVNode("div", {
        "ref": arrowRef,
        "class": ns.e("arrow")
      }, null)]);
    };
  }
});
function useCacheFilteredOptions(filteredOptions) {
  const cacheFilteredOptions = computed(() => {
    const map = /* @__PURE__ */ new Map();
    filteredOptions.value.forEach((item) => {
      map.set(item, item.value);
    });
    return map;
  });
  const getOptionValue = (option) => cacheFilteredOptions.value.get(option);
  return {
    getOptionValue
  };
}
function deepAssign(...objects) {
  const isObject = (obj) => obj && typeof obj === "object";
  return objects.reduce((prev, from) => {
    Object.keys(from).forEach((key) => {
      const pVal = prev[key];
      const oVal = from[key];
      if (Array.isArray(pVal) && Array.isArray(oVal)) {
        prev[key] = Array.from(/* @__PURE__ */ new Set([...oVal, ...pVal]));
      } else if (isObject(pVal) && isObject(oVal)) {
        prev[key] = deepAssign(pVal, oVal);
      } else {
        prev[key] = oVal;
      }
    });
    return prev;
  }, {});
}
var zhCN = {
  pagination: {
    totalItemText: "\u6240\u6709\u6761\u76EE",
    goToText: "\u8DF3\u81F3"
  },
  accordion: {
    loading: "\u52A0\u8F7D\u4E2D",
    noData: "\u6CA1\u6709\u6570\u636E"
  },
  autoCompleteDropdown: {
    latestInput: "\u6700\u8FD1\u8F93\u5165"
  },
  cascaderList: {
    noData: "\u6CA1\u6709\u6570\u636E"
  },
  colorPicker: {
    foundationPanel: "\u57FA\u7840\u9762\u677F",
    advancedPanel: "\u9AD8\u7EA7\u9762\u677F"
  },
  datePickerPro: {
    ok: "\u786E\u5B9A",
    placeholder: "\u8BF7\u9009\u62E9\u65E5\u671F",
    month1: "1\u6708",
    month2: "2\u6708",
    month3: "3\u6708",
    month4: "4\u6708",
    month5: "5\u6708",
    month6: "6\u6708",
    month7: "7\u6708",
    month8: "8\u6708",
    month9: "9\u6708",
    month10: "10\u6708",
    month11: "11\u6708",
    month12: "12\u6708",
    year: "\u5E74",
    startPlaceholder: "\u8BF7\u9009\u62E9\u5F00\u59CB\u65E5\u671F",
    endPlaceholder: "\u8BF7\u9009\u62E9\u7ED3\u675F\u65E5\u671F",
    getWeekDays() {
      return ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"];
    },
    getTimeArr() {
      return ["\u65F6", "\u5206", "\u79D2"];
    },
    getYearMonthStr(year, month) {
      return `${year}\u5E74${month}\u6708`;
    }
  },
  editableSelect: {
    noRelatedRecords: "\u627E\u4E0D\u5230\u76F8\u5173\u8BB0\u5F55",
    noData: "\u6CA1\u6709\u6570\u636E"
  },
  input: {
    placeholder: "\u8BF7\u8F93\u5165"
  },
  splitterBar: {
    collapse: "\u6536\u8D77",
    expand: "\u5C55\u5F00"
  },
  stepsGuide: {
    previous: "\u4E0A\u4E00\u6B65",
    continue: "\u6211\u77E5\u9053\u5566\uFF0C\u7EE7\u7EED",
    ok: "\u6211\u77E5\u9053\u5566"
  },
  table: {
    selectAll: "\u5168\u9009",
    ok: "\u786E\u5B9A"
  },
  timePopup: {
    ok: "\u786E\u5B9A"
  },
  transfer: {
    unit: "\u9879",
    panelUnit: "\u9879",
    headerUnit: "\u9879",
    noData: "\u6682\u65E0\u6570\u636E",
    placeholder: "\u8BF7\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22"
  },
  tree: {
    loading: "\u52A0\u8F7D\u4E2D",
    newNode: "\u65B0\u8282\u70B9",
    selectPlaceholder: "\u8BF7\u9009\u62E9"
  },
  upload: {
    placeholder: "\u9009\u62E9\u6587\u4EF6",
    getExistSameNameFilesMsg(sameNames) {
      return `\u60A8\u4E0A\u4F20\u7684 "${sameNames}" \u5B58\u5728\u91CD\u540D\u6587\u4EF6, \u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6`;
    },
    getAllFilesBeyondMaximalFileSizeMsg(maximalSize) {
      return `\u6700\u5927\u652F\u6301\u4E0A\u4F20${maximalSize}MB\u7684\u6587\u4EF6, \u60A8\u672C\u6B21\u4E0A\u4F20\u7684\u6240\u6709\u6587\u4EF6\u8D85\u8FC7\u53EF\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F`;
    },
    getBeyondMaximalFileSizeMsg(filename, maximalSize) {
      return `\u6700\u5927\u652F\u6301\u4E0A\u4F20${maximalSize}MB\u7684\u6587\u4EF6, \u60A8\u4E0A\u4F20\u7684\u6587\u4EF6"${filename}"\u8D85\u8FC7\u53EF\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F`;
    },
    getNotAllowedFileTypeMsg(filename, scope) {
      return `\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B: "${scope}", \u60A8\u4E0A\u4F20\u7684\u6587\u4EF6"${filename}"\u4E0D\u5728\u5141\u8BB8\u8303\u56F4\u5185\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6`;
    }
  },
  search: {
    placeholder: "\u8BF7\u8F93\u5165\u5173\u952E\u5B57"
  },
  select: {
    placeholder: "\u8BF7\u9009\u62E9",
    noDataText: "\u65E0\u6570\u636E",
    noMatchText: "\u627E\u4E0D\u5230\u76F8\u5173\u8BB0\u5F55",
    loadingText: "\u52A0\u8F7D\u4E2D..."
  },
  tagInput: {
    maxTagsText: "\u5DF2\u8FBE\u5230\u6700\u5927\u4E2A\u6570\uFF1A"
  },
  timeSelect: {
    placeholder: "\u8BF7\u9009\u62E9\u65F6\u95F4"
  }
};
const lang = ref("zh-CN");
let langMessages = reactive({
  [lang.value]: zhCN
});
const Locale = {
  messages() {
    return langMessages[lang.value];
  },
  lang() {
    return lang.value;
  },
  use(newLang, newMessages) {
    lang.value = newLang;
    this.add({ [newLang]: newMessages });
  },
  add(newMessages = {}) {
    langMessages = deepAssign(langMessages, newMessages);
  }
};
const camelize = (name) => name.substring(1).replace(/^\S/, (s) => s.toLocaleLowerCase());
function get(object, path) {
  const keys = path.split(".");
  let result = object;
  keys.forEach((key) => {
    var _a;
    result = (_a = result[key]) != null ? _a : "";
  });
  return result;
}
function createI18nTranslate(name, app, newPrefix) {
  const prefix = newPrefix || camelize(name) + ".";
  return (path) => {
    var _a;
    const messages = ((_a = app == null ? void 0 : app.appContext.config.globalProperties.langMessages) == null ? void 0 : _a.value) || Locale.messages();
    const message = get(messages, prefix + path) || get(messages, path);
    return message;
  };
}
var EditableSelect = defineComponent({
  name: "DEditableSelect",
  directives: {
    clickOutside: clickoutsideDirective,
    dLoading: loadingDirective
  },
  props: editableSelectProps,
  emits: ["update:modelValue", "search", "loadMore"],
  setup(props, ctx2) {
    const app = getCurrentInstance();
    const t = createI18nTranslate("DEditableSelect", app);
    const ns = useNamespace("editable-select");
    const dropdownRef = ref();
    const origin = ref();
    const position = ref(["bottom"]);
    const visible = ref(false);
    const inputValue = ref(props.modelValue);
    const cacheInput = ref();
    const loading2 = ref(props.loading);
    const {
      normalizeOptions
    } = useSelect(props);
    const searchFn = props.searchFn || ((option, term) => option.label.toLocaleLowerCase().includes(term.trim().toLocaleLowerCase()));
    const {
      filteredOptions
    } = useFilterOptions(props.enableLazyLoad, normalizeOptions, inputValue, searchFn);
    const {
      getOptionValue
    } = useCacheFilteredOptions(filteredOptions);
    const emptyText = computed(() => {
      let text;
      if (props.enableLazyLoad) {
        text = t("noData");
      } else {
        text = t("noRelatedRecords");
      }
      return text;
    });
    watch(() => props.loading, (newVal) => {
      loading2.value = newVal;
    });
    const toggleMenu = () => {
      visible.value = !visible.value;
    };
    const closeMenu = () => {
      visible.value = false;
    };
    const {
      loadMore
    } = useLazyLoad(dropdownRef, props.enableLazyLoad, ctx2);
    const {
      handleInput
    } = useInput(inputValue, ctx2);
    const handleClick = (option, index2, curSelectedIndex) => {
      const {
        disabledKey
      } = props;
      if (disabledKey && !!option[disabledKey]) {
        return;
      }
      inputValue.value = option.label;
      cacheInput.value = option.label;
      curSelectedIndex.value = index2;
      const value = getOptionValue(option);
      ctx2.emit("update:modelValue", value + "");
      closeMenu();
    };
    const handleClear = () => {
      inputValue.value = "";
    };
    const {
      handleKeydown,
      hoverIndex,
      selectedIndex
    } = useKeyboardSelect(dropdownRef, visible, inputValue, cacheInput, filteredOptions, props.disabledKey, props.filterOption, loading2, (option, index2) => handleClick(option, index2, selectedIndex), closeMenu, toggleMenu);
    const getItemCls = (option, index2) => {
      const {
        disabledKey
      } = props;
      return className(`devui-dropdown-item`, {
        disabled: disabledKey ? !!option[disabledKey] : false,
        selected: index2 === selectedIndex.value,
        [`${ns.em("dropdown", "bg")}`]: index2 === hoverIndex.value
      });
    };
    return () => {
      const selectCls = className(`${ns.b()} devui-form-group devui-has-feedback ${inputValue.value && props.allowClear && "allow-clear"}`, {
        [`${ns.m("open")}`]: visible.value === true
      });
      const inputCls = className(`devui-form-control devui-dropdown-origin`, {
        "devui-dropdown-origin-open": visible.value === true
      });
      return withDirectives(createVNode("div", {
        "class": selectCls,
        "ref": origin,
        "style": {
          width: props.width + "px"
        }
      }, [createVNode("input", {
        "class": inputCls,
        "onClick": withModifiers(toggleMenu, ["self"]),
        "onInput": handleInput,
        "onKeydown": handleKeydown,
        "value": inputValue.value,
        "disabled": props.disabled,
        "placeholder": props.placeholder,
        "type": "text"
      }, null), createVNode("span", {
        "class": "devui-form-control-feedback"
      }, [createVNode("span", {
        "class": "devui-select-clear-icon",
        "onClick": handleClear
      }, [createVNode(resolveComponent("d-icon"), {
        "name": "icon-remove"
      }, null)]), createVNode("span", {
        "class": "devui-select-chevron-icon"
      }, [createVNode(resolveComponent("d-icon"), {
        "name": "select-arrow"
      }, null)])]), createVNode(Teleport, {
        "to": "body"
      }, {
        default: () => [createVNode(Transition, {
          "name": "fade"
        }, {
          default: () => [createVNode(FlexibleOverlay, {
            "origin": origin.value,
            "modelValue": visible.value,
            "onUpdate:modelValue": ($event) => visible.value = $event,
            "position": position.value
          }, {
            default: () => [createVNode("div", {
              "style": {
                width: props.width + "px"
              },
              "class": `${ns.e("menu")}`
            }, [withDirectives(createVNode("div", {
              "class": `devui-dropdown-menu`
            }, [createVNode("ul", {
              "ref": dropdownRef,
              "class": `${ns.em("list", "unstyled")} devui-scrollbar scroll-height`,
              "style": {
                maxHeight: props.maxHeight + "px"
              },
              "onScroll": loadMore
            }, [filteredOptions.value.map((option, index2) => {
              return createVNode("li", {
                "class": getItemCls(option, index2),
                "onClick": (e) => {
                  e.stopPropagation();
                  handleClick(option, index2, selectedIndex);
                }
              }, [ctx2.slots.item ? ctx2.slots.item(option) : option.label]);
            }), withDirectives(createVNode("div", {
              "class": "devui-no-data-tip"
            }, [ctx2.slots.noResultItem ? ctx2.slots.noResultItem(inputValue.value) : emptyText.value]), [[vShow, !filteredOptions.value.length]])])]), [[vShow, visible.value], [resolveDirective("d-loading"), props.loading]])])]
          })]
        })]
      })]), [[resolveDirective("click-outside"), closeMenu]]);
    };
  }
});
var index = {
  title: "EditableSelect \u53EF\u8F93\u5165\u4E0B\u62C9\u9009\u62E9\u6846",
  category: "\u6570\u636E\u5F55\u5165",
  status: "100%",
  install(app) {
    app.component(EditableSelect.name, EditableSelect);
  }
};
export { EditableSelect, index as default, editableSelectProps };
