import { defineComponent as $, ref as d, computed as r, unref as o, openBlock as b, createElementBlock as D, normalizeClass as A, createVNode as f, withCtx as I, createBlock as G, normalizeStyle as H, createCommentVNode as q, mergeProps as Y } from "vue";
import { Form as J, Space as Q } from "@aplus-frontend/antdv";
import { omit as W } from "lodash-unified";
import "../../ap-field/index.mjs";
import { useDefaultPlaceholder as X } from "../../ap-field/hooks/use-default-placeholder.mjs";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import { runEventHandler as V } from "../../utils/index.mjs";
import "./popover-input/index.vue.mjs";
import Z from "./style/index.mjs";
import { splitValue as ee } from "./utils.mjs";
import { useControllableValue as te } from "../../hooks/useControllableValue.mjs";
import { useLocale as oe } from "../../config-provider/hooks/use-locale.mjs";
import { useNamespace as ne } from "../../config-provider/hooks/use-namespace.mjs";
import { isDef as le } from "../../utils/is.mjs";
import ae from "../../ap-field/select/index.vue.mjs";
import { ApFieldText as ue } from "../../ap-field/text/index.mjs";
import re from "./popover-input/index.vue2.mjs";
const v = "GROUP_SEARCH_ALL", ke = /* @__PURE__ */ $({
  name: "BatchInputGroup",
  __name: "index",
  props: {
    style: { type: [Boolean, null, String, Object, Array] },
    inputStyle: { type: [Boolean, null, String, Object, Array] },
    options: {},
    hasAll: { type: Boolean, default: !0 },
    value: {},
    "onUpdate:value": {},
    popoverPlacement: { default: "left" },
    maxNum: { default: 200 },
    getPopupContainer: {},
    onComplete: {},
    mode: { default: "edit" },
    class: {},
    emptyText: { default: "--" },
    customReadMode: {},
    variant: {},
    size: {},
    name: {},
    type: { default: "text" },
    onCompositionend: {},
    onCompositionstart: {},
    onFocus: {},
    onBlur: {},
    onChange: {},
    onInput: {},
    onKeydown: {},
    onKeyup: {},
    onMousedown: {},
    focused: { type: Boolean },
    hidden: { type: Boolean },
    disabled: { type: Boolean },
    prefixCls: {},
    id: {},
    readonly: { type: Boolean },
    autofocus: { type: Boolean },
    autocomplete: {},
    placeholder: {},
    lazy: { type: Boolean, default: !0 },
    maxlength: {},
    loading: { type: Boolean },
    bordered: { type: Boolean, default: !0 },
    showCount: { type: [Boolean, Object] },
    htmlSize: {},
    onPressEnter: {},
    onMouseUp: {},
    onRawInput: {},
    valueModifiers: {},
    status: {},
    defaultValue: {},
    inputElement: {},
    triggerFocus: {},
    handleReset: {},
    addonBefore: {},
    addonAfter: {},
    prefix: {},
    suffix: {},
    clearIcon: {},
    allowClear: { type: Boolean, default: !0 },
    beforeInput: {}
  },
  emits: ["update:value"],
  setup(u, { emit: k }) {
    const t = u, S = X("Text", t), F = k, { value: n, updateValue: p } = te(
      t,
      F
    ), c = d(), h = d(), y = d(), { t: P } = oe(), { b: U } = ne("batch-input-group"), g = Z("batch-input-group"), i = J.useInjectFormItemContext(), w = r(() => t.options ? t.options.length > 1 && t.hasAll ? [
      { value: v, label: P("ap.common.all") },
      ...t.options
    ] : t.options : []), O = r(() => t.options ? t.options.map((e) => e.value) : []), R = r(() => o(n)?.value?.length ? o(n).value.join(",") : ""), j = r(() => o(n)?.value?.length ? o(n).value.join(`
`) : ""), E = r(() => {
      const e = o(n)?.key;
      if (e?.length)
        return e.length === 1 || !t.hasAll ? e[0] : v;
    }), L = r(() => {
      const e = o(n)?.key;
      return !e || e?.length <= 1 || t.hasAll === !1 ? o(S) : (t.options || []).filter((a) => e.includes(a.value)).map((a) => a.label).join("/");
    });
    function N(e) {
      const l = o(n) || {}, a = e === v ? o(O) : le(e) ? [e] : [];
      p({
        ...l,
        key: a
      }), i.onFieldChange();
    }
    function z(e) {
      const l = o(n) || {}, a = e.target.value || "";
      let m = ee(a, ",", ",", t.maxNum);
      if (a !== m) {
        const x = h.value?.$el?.querySelector("input");
        x && (x.value = m);
      }
      let s = m.split(",");
      s.length === 1 && s[0] === "" && (s = []), p({
        ...l,
        value: s
      }), i.onFieldChange();
    }
    function T(e) {
      const l = o(n) || {};
      let a = e.split(/,|\n/);
      p({
        ...l,
        value: a
      }), i.onFieldChange();
    }
    function C() {
      const e = o(n) || {}, l = e.value?.filter(Boolean);
      p({
        ...e,
        value: l
      }), i.onFieldChange();
    }
    function _() {
      C(), t.onComplete?.(n.value);
    }
    function M(e) {
      V(t.onFocus, e);
    }
    function B(e) {
      V(t.onBlur, e), !y.value?.getOpen() && t.onComplete?.(n.value);
    }
    function K(e) {
      C(), B(e);
    }
    return (e, l) => (b(), D("div", {
      ref_key: "containerRef",
      ref: c,
      class: A([o(U)(), o(g)]),
      onFocus: M,
      onBlur: B
    }, [
      f(o(Q).Compact, { block: "" }, {
        default: I(() => [
          u.options?.length ? (b(), G(o(ae), {
            key: 0,
            style: H(u.style),
            options: w.value,
            value: E.value,
            "allow-clear": !1,
            "dropdown-match-select-width": !1,
            disabled: u.disabled,
            "get-popup-container": () => c.value,
            "onUpdate:value": N
          }, null, 8, ["style", "options", "value", "disabled", "get-popup-container"])) : q("", !0),
          f(o(ue), Y(
            o(W)(t, [
              "style",
              "value",
              "onUpdate:value",
              "inputStyle",
              "hasAll",
              "options",
              "onBlur"
            ]),
            {
              ref_key: "inputRef",
              ref: h,
              style: u.inputStyle,
              value: R.value,
              placeholder: L.value,
              onInput: z,
              onBlur: K
            }
          ), {
            suffix: I(() => [
              f(re, {
                ref_key: "popoverInput",
                ref: y,
                parent: c.value,
                value: j.value,
                disabled: u.disabled,
                placement: t.popoverPlacement,
                "max-num": u.maxNum,
                class: A(o(g)),
                "get-popup-container": u.getPopupContainer,
                "onUpdate:value": T,
                onClose: _
              }, null, 8, ["parent", "value", "disabled", "placement", "max-num", "class", "get-popup-container"])
            ]),
            _: 1
          }, 16, ["style", "value", "placeholder"])
        ]),
        _: 1
      })
    ], 34));
  }
});
export {
  ke as default
};
