import { defineComponent as z, ref as B, computed as r, unref as t, openBlock as x, createElementBlock as T, normalizeClass as C, createVNode as d, withCtx as b, createBlock as M, normalizeStyle as K, createCommentVNode as $, mergeProps as D } from "vue";
import { Form as G, Space as q } from "@aplus-frontend/antdv";
import { omit as H } from "lodash-unified";
import "../../ap-field/index.mjs";
import { useDefaultPlaceholder as Y } from "../../ap-field/hooks/use-default-placeholder.mjs";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import "../../utils/index.mjs";
import "./popover-input/index.vue.mjs";
import J from "./style/index.mjs";
import { splitValue as Q } from "./utils.mjs";
import { useControllableValue as W } from "../../hooks/useControllableValue.mjs";
import { useLocale as X } from "../../config-provider/hooks/use-locale.mjs";
import { useNamespace as Z } from "../../config-provider/hooks/use-namespace.mjs";
import { isDef as _ } from "../../utils/is.mjs";
import ee from "../../ap-field/select/index.vue.mjs";
import { ApFieldText as te } from "../../ap-field/text/index.mjs";
import oe from "./popover-input/index.vue2.mjs";
const f = "GROUP_SEARCH_ALL", Ce = /* @__PURE__ */ z({
  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: {},
    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(a, { emit: A }) {
    const o = a, I = Y("Text", o), V = A, { value: u, updateValue: i } = W(
      o,
      V
    ), c = B(), v = B(), { t: S } = X(), { b: k } = Z("batch-input-group"), y = J("batch-input-group"), p = G.useInjectFormItemContext(), F = r(() => o.options ? o.options.length > 1 && o.hasAll ? [
      { value: f, label: S("ap.common.all") },
      ...o.options
    ] : o.options : []), U = r(() => o.options ? o.options.map((e) => e.value) : []), w = r(() => t(u)?.value?.length ? t(u).value.join(",") : ""), P = r(() => t(u)?.value?.length ? t(u).value.join(`
`) : ""), R = r(() => {
      const e = t(u)?.key;
      if (e?.length)
        return e.length === 1 || !o.hasAll ? e[0] : f;
    }), j = r(() => {
      const e = t(u)?.key;
      return !e || e?.length <= 1 || o.hasAll === !1 ? t(I) : (o.options || []).filter((n) => e.includes(n.value)).map((n) => n.label).join("/");
    });
    function E(e) {
      const l = t(u) || {}, n = e === f ? t(U) : _(e) ? [e] : [];
      i({
        ...l,
        key: n
      }), p.onFieldChange();
    }
    function L(e) {
      const l = t(u) || {}, n = e.target.value || "";
      let m = Q(n, ",", ",", o.maxNum);
      if (n !== m) {
        const g = v.value?.$el?.querySelector("input");
        g && (g.value = m);
      }
      let s = m.split(",");
      s.length === 1 && s[0] === "" && (s = []), i({
        ...l,
        value: s
      }), p.onFieldChange();
    }
    function N(e) {
      const l = t(u) || {};
      let n = e.split(/,|\n/);
      i({
        ...l,
        value: n
      }), p.onFieldChange();
    }
    function h() {
      const e = t(u) || {}, l = e.value?.filter(Boolean);
      i({
        ...e,
        value: l
      }), p.onFieldChange();
    }
    function O(e) {
      h(), o.onBlur?.(e);
    }
    return (e, l) => (x(), T("div", {
      ref_key: "containerRef",
      ref: c,
      class: C([t(k)(), t(y)]),
      onFocus: l[0] || (l[0] = //@ts-ignore
      (...n) => a.onFocus && a.onFocus(...n)),
      onBlur: l[1] || (l[1] = //@ts-ignore
      (...n) => a.onBlur && a.onBlur(...n))
    }, [
      d(t(q).Compact, { block: "" }, {
        default: b(() => [
          a.options?.length ? (x(), M(t(ee), {
            key: 0,
            style: K(a.style),
            options: F.value,
            value: R.value,
            "allow-clear": !1,
            "dropdown-match-select-width": !1,
            disabled: a.disabled,
            "get-popup-container": () => c.value,
            "onUpdate:value": E
          }, null, 8, ["style", "options", "value", "disabled", "get-popup-container"])) : $("", !0),
          d(t(te), D(
            t(H)(o, [
              "style",
              "value",
              "onUpdate:value",
              "inputStyle",
              "hasAll",
              "options",
              "onBlur"
            ]),
            {
              ref_key: "inputRef",
              ref: v,
              style: a.inputStyle,
              value: w.value,
              placeholder: j.value,
              onInput: L,
              onBlur: O
            }
          ), {
            suffix: b(() => [
              d(oe, {
                _parent: c.value,
                value: P.value,
                disabled: a.disabled,
                placement: o.popoverPlacement,
                "max-num": a.maxNum,
                class: C(t(y)),
                "get-popup-container": a.getPopupContainer,
                "onUpdate:value": N,
                onClose: h
              }, null, 8, ["_parent", "value", "disabled", "placement", "max-num", "class", "get-popup-container"])
            ]),
            _: 1
          }, 16, ["style", "value", "placeholder"])
        ]),
        _: 1
      })
    ], 34));
  }
});
export {
  Ce as default
};
