import { defineComponent as O, ref as u, computed as d, openBlock as _, createElementBlock as F, normalizeClass as m, unref as n, createVNode as f, withCtx as g, createElementVNode as L } from "vue";
import { Popover as z, Textarea as G } from "@aplus-frontend/antdv";
import { IconApAdLineScreen as S } from "@aplus-frontend/icon";
import { isNumber as W } from "lodash-unified";
import "../../../config-provider/index.mjs";
import "../../../hooks/index.mjs";
import { splitValue as j } from "../utils.mjs";
import { useControllableValue as T } from "../../../hooks/useControllableValue.mjs";
import { useLocale as U } from "../../../config-provider/hooks/use-locale.mjs";
import { useNamespace as h } from "../../../config-provider/hooks/use-namespace.mjs";
const ee = /* @__PURE__ */ O({
  name: "BatchInputGroupPopoverInput",
  inheritAttrs: !1,
  __name: "index",
  props: {
    _parent: {},
    onClose: { type: Function },
    disabled: { type: Boolean },
    maxNum: {},
    getPopupContainer: { type: Function },
    placement: {},
    value: {},
    "onUpdate:value": { type: Function }
  },
  emits: ["update:value"],
  setup(r, { emit: C }) {
    const o = r, x = C, { value: b, updateValue: y } = T(o, x), c = u(!1), s = u(), i = u(), p = u({
      left: 0,
      right: 0
    }), P = (e) => o._parent || e, { t: V } = U();
    function I(e) {
      const a = e.target.value || "";
      let t = j(a, `
,`, `
`, o.maxNum);
      if (t = t.replace(/\\n/g, `
`), t !== a) {
        const l = s.value?.$el || s.value;
        l && (l.value = t);
      }
      y(t);
    }
    const N = () => {
      if (o.getPopupContainer) {
        const e = o._parent, a = o.getPopupContainer(), t = e?.getBoundingClientRect(), l = a?.getBoundingClientRect();
        i.value = e?.offsetWidth, p.value.left = (t?.left || 0) - (l.left || 0), p.value.right = (t?.right || 0) - (l.right || 0);
      }
    };
    function $(e) {
      N(), o.disabled ? c.value = !1 : c.value = e, !e && o.onClose?.();
    }
    const { b: v, e: R, em: B, bm: A } = h("batch-input-group-popover-input"), { cssVar: k } = h("batch-input-group-popover"), w = d(() => {
      const e = o.placement, a = W(e) ? `${e}px` : e === "left" ? `${p.value.left}px` : "unset", t = e === "right" ? `${-p.value.right}px` : "unset";
      return {
        left: a,
        right: t
      };
    }), E = d(() => k({
      ...w.value,
      width: i.value ? `${i.value}px` : "100%"
    }));
    return (e, a) => (_(), F("div", {
      class: m(n(v)())
    }, [
      f(n(z), {
        "overlay-class-name": `${n(R)("popover")} ${e.$attrs.class}`,
        "get-popup-container": r.getPopupContainer ?? P,
        trigger: "click",
        placement: "bottomLeft",
        open: c.value,
        "overlay-style": E.value,
        onOpenChange: $
      }, {
        content: g(() => [
          L("div", {
            class: m(n(B)("popover", "content"))
          }, [
            f(n(G), {
              ref_key: "textAreaRef",
              ref: s,
              placeholder: n(V)("ap.batchInputGroup.popoverInputPlaceholder", {
                maxNum: r.maxNum + ""
              }),
              bordered: !1,
              rows: 10,
              value: n(b),
              "allow-clear": !1,
              "auto-size": !1,
              onInput: I
            }, null, 8, ["placeholder", "value"])
          ], 2)
        ]),
        default: g(() => [
          f(n(S), {
            class: m([
              n(v)("trigger-icon"),
              r.disabled ? n(A)("trigger-icon", "disabled") : null
            ])
          }, null, 8, ["class"])
        ]),
        _: 1
      }, 8, ["overlay-class-name", "get-popup-container", "open", "overlay-style"])
    ], 2));
  }
});
export {
  ee as default
};
