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