import { defineComponent as j, computed as p, ref as m, watch as C, nextTick as y, onMounted as G, openBlock as a, createElementBlock as c, normalizeClass as s, unref as t, createVNode as S, withCtx as x, createElementVNode as $, normalizeStyle as h, renderSlot as z, toDisplayString as d, createBlock as E, resolveDynamicComponent as D, Fragment as A, renderList as J, createTextVNode as P, createCommentVNode as B } from "vue";
import { DownOutlined as Q } from "@ant-design/icons-vue";
import { Alert as U, Tooltip as X } from "@aplus-frontend/antdv";
import { isNil as Y, isString as N } from "lodash-unified";
import { ApActionItem as Z } from "../../ap-action/index.mjs";
import "../../config-provider/index.mjs";
import _ from "./style/index.mjs";
import { useLocale as ee } from "../../config-provider/hooks/use-locale.mjs";
import { useNamespace as te } from "../../config-provider/hooks/use-namespace.mjs";
const le = ["onClick"], pe = /* @__PURE__ */ j({
  __name: "ApExpandAlert",
  props: {
    type: { default: "warning" },
    data: { default: () => [] },
    prefix: { default: "" },
    tipTitle: { default: "" },
    mapLabel: {},
    separator: { default: "|" },
    separatorStyle: { default: () => ({}) },
    contentStyle: { default: () => ({}) },
    prefixStyle: { default: () => ({}) },
    rows: { default: 2 },
    defaultExpand: { type: Boolean, default: !0 },
    showIcon: { type: Boolean, default: !0 },
    closable: { type: Boolean },
    afterClose: {}
  },
  emits: ["choose", "expand", "close"],
  setup(e, { expose: V, emit: R }) {
    const v = R, u = e, { t: T } = ee(), q = p(() => {
      if (u.type != "card")
        return u.type;
    }), n = m(""), f = m(null), F = p(() => ({
      fontWeight: "400",
      wordBreak: "break-all",
      overflow: "hidden",
      display: "-webkit-box",
      webkitLineClamp: n.value,
      webkitBoxOrient: "vertical",
      lineHeight: "18px"
    }));
    function M() {
      n.value === "1" ? (n.value = "", v("expand", "expand")) : (n.value = "1", v("expand", "collapse"));
    }
    const O = p(() => n.value === "1" ? T("ap.apExpandAlert.expand") : T("ap.apExpandAlert.collapse")), k = m(!0), H = p(() => n.value !== "1");
    function w(l) {
      l ? n.value = "" : n.value = "1";
    }
    const I = m(!1);
    function K(l) {
      v("close", l), I.value = !0;
    }
    C(
      () => u.data,
      () => {
        n.value = "", y(() => {
          if (f.value) {
            const l = Number(f.value.clientHeight), r = Number(
              parseInt(f.value.style.lineHeight)
            );
            l < r * Number(u.rows) && H.value ? k.value = !1 : k.value = !0;
          }
        });
      },
      {
        immediate: !0
      }
    ), C(
      () => u.defaultExpand,
      (l) => {
        l ? y(() => {
          w(l);
        }) : y(() => {
          w(l);
        });
      },
      { immediate: !0 }
    ), G(() => {
      C(
        () => u.contentStyle,
        (l) => {
          Y(l.lineHeight) || y(() => {
            const r = document.querySelector(
              `#${b} .ant-alert-action`
            ), i = document.querySelector(
              `#${b} .ant-alert-icon`
            );
            r && r.setAttribute("style", `line-height: ${l.lineHeight}`), i && i.setAttribute("style", `line-height: ${l.lineHeight}`);
          });
        },
        {
          deep: !0,
          immediate: !0,
          flush: "post"
        }
      );
    });
    const { b: L, e: o } = te("ap-expand-alert"), W = _("ap-expand-alert"), b = `${L()}-key-${Date.now()}-${(Math.random() * 1e6).toFixed(0)}`;
    return V({
      setExpand: w
    }), (l, r) => I.value ? B("", !0) : (a(), c("div", {
      key: 0,
      id: b,
      class: s([t(L)(), t(W)])
    }, [
      S(t(U), {
        type: q.value,
        "show-icon": e.showIcon,
        closable: e.closable,
        class: s([t(o)("antAlert"), e.type == "card" ? "card-alert" : ""]),
        "after-close": e.afterClose,
        onClose: K
      }, {
        action: x(() => [
          k.value ? (a(), E(t(Z), {
            key: 0,
            size: "small",
            style: { "font-size": "12px", "padding-left": "16px" },
            onClick: r[0] || (r[0] = (i) => M())
          }, {
            default: x(() => [
              $("span", {
                class: s(t(o)("expandText"))
              }, d(O.value), 3),
              S(t(Q), {
                class: s(H.value ? t(o)("expandIcon") : t(o)("collapseIcon"))
              }, null, 8, ["class"])
            ]),
            _: 1
          })) : B("", !0)
        ]),
        message: x(() => [
          $("div", {
            ref_key: "ellipsisBoxRef",
            ref: f,
            style: h({ ...F.value, ...e.contentStyle }),
            class: s(t(o)("alertContent"))
          }, [
            z(l.$slots, "default", {}, () => [
              t(N)(e.prefix) ? (a(), c("span", {
                key: 0,
                class: s(t(o)("prefix")),
                style: h(e.prefixStyle)
              }, d(e.prefix), 7)) : (a(), E(D(e.prefix), {
                key: 1,
                style: h(e.prefixStyle)
              }, null, 8, ["style"])),
              t(N)(e.data) ? (a(), c("span", {
                key: 2,
                class: s(t(o)("text"))
              }, d(e.data), 3)) : (a(!0), c(A, { key: 3 }, J(e.data, (i, g) => (a(), c(A, { key: g }, [
                S(t(X), {
                  title: e.tipTitle ? e.tipTitle : null
                }, {
                  default: x(() => [
                    z(l.$slots, "item", {
                      record: i,
                      index: g
                    }, () => [
                      $("span", {
                        class: s(t(o)("showItem")),
                        onClick: (ae) => l.$emit("choose", i)
                      }, d(e.mapLabel ? i[e.mapLabel] : i), 11, le)
                    ])
                  ]),
                  _: 2
                }, 1032, ["title"]),
                g !== e.data.length - 1 ? (a(), c("span", {
                  key: 0,
                  class: s(t(o)("spliter")),
                  style: h(e.separatorStyle)
                }, [
                  t(N)(e.separator) ? (a(), c(A, { key: 0 }, [
                    P(d(e.separator), 1)
                  ], 64)) : (a(), E(D(e.separator), { key: 1 }))
                ], 6)) : B("", !0)
              ], 64))), 128))
            ])
          ], 6)
        ]),
        _: 3
      }, 8, ["type", "show-icon", "closable", "class", "after-close"])
    ], 2));
  }
});
export {
  pe as default
};
