import { isVNode as V, defineComponent as w, useSlots as B, reactive as E, computed as d, createVNode as l, createTextVNode as O, Fragment as _, shallowRef as F, watch as I, openBlock as R, createElementBlock as z, normalizeStyle as G, normalizeClass as $, unref as u, mergeProps as L } from "vue";
import { Descriptions as W } from "@aplus-frontend/antdv";
import { get as y } from "lodash-unified";
import "../../config-provider/index.mjs";
import "./components/help-message/index.vue.mjs";
import "./components/mask-wrapper/index.vue.mjs";
import { genDefaultMaskStatus as q, mixinsAttachmentExtraProps as H, transformValue as J, isEmptyWithType as Q, getSchemaKey as U, getMaskConfigBySchema as X } from "./helper.mjs";
import { useDescriptionsProvider as Y } from "./hooks/use-descriptions-context.mjs";
import Z from "./style/index.mjs";
import { useGlobalConfig as m } from "../../config-provider/hooks/use-global-config.mjs";
import { useNamespace as h } from "../../config-provider/hooks/use-namespace.mjs";
import tt from "./components/help-message/index.vue2.mjs";
import et from "./components/mask-wrapper/index.vue2.mjs";
function rt(o) {
  return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !V(o);
}
const gt = /* @__PURE__ */ w({
  name: "ApDescriptions",
  __name: "ap-descriptions",
  props: {
    descriptionsProps: {},
    schemas: {},
    dataSource: {},
    defaultMask: {},
    style: {
      type: [Boolean, null, String, Object, Array]
    },
    className: {}
  },
  setup(o, {
    expose: S
  }) {
    const s = o, g = m("apDescriptions"), b = m("downloadCenterTriggerConfig"), {
      b: v,
      be: c
    } = h("ap-descriptions"), k = Z("ap-descriptions"), x = B(), i = E({}), M = d((t) => q(s.schemas, t, s.defaultMask));
    Y({
      maskStatus: d(() => Object.assign({}, M.value, i)),
      setStatusByKey(t, e) {
        i[t] = e;
      }
    });
    const C = (t = {}) => {
      let e = "";
      return s.descriptionsProps?.layout === "vertical" && (e = "start"), {
        justifyContent: e,
        ...t
      };
    }, f = (t) => {
      const e = y(s.dataSource, t.field);
      if (t.customRender)
        return t.customRender(s.dataSource);
      t.valueType === "attachment" && (t.extraProps = H(t.extraProps, {
        fromConfig: g.value?.downloadFile,
        fromGlobal: b.value?.trigger
      }));
      const r = t.format ? t.format(e, s.dataSource || {}) : e;
      return J({
        value: r,
        record: s.dataSource
      }, t);
    }, P = (t) => t.valueType === "text" && !!t.extraProps?.ellipsis, N = (t, e) => {
      if (t.visible != null) {
        if (typeof t.visible == "boolean")
          return t.visible;
        if (typeof t.visible == "function")
          return t.visible({
            record: e || {},
            schema: t
          });
      }
      return !0;
    }, j = (t, e, r) => t.valueType === "empty" ? null : Q(y(r, t.field), t) ? l("span", null, [O("--")]) : t.contentSlotName ? x?.[t.contentSlotName]?.({
      index: e,
      record: r,
      item: f(t)
    }) : l(_, null, [t.prefix, f(t), t.suffix && l("span", {
      class: c("content", "suffix")
    }, [t.suffix])]), A = (t = [], e) => t.filter((r) => N(r, e)).map((r, a) => {
      let n;
      return {
        label: r.label && l(tt, {
          helpMessage: r.helpMessage,
          label: r.label
        }, null),
        span: r.span,
        style: r.style,
        contentStyle: r.contentStyle,
        labelStyle: r.labelStyle,
        key: r.field?.toString() || "empty" + a,
        class: P(r) ? c("item", "ellipsis") : "",
        children: l(et, {
          item: r,
          data: e,
          defaultMask: s.defaultMask
        }, rt(n = j(r, a, e)) ? n : {
          default: () => [n]
        })
      };
    }), p = F([]), D = (t) => {
      if (t != null)
        return typeof t == "string" ? [t] : t.some((e) => Array.isArray(e)) ? t.map((e) => Array.isArray(e) ? e.join(".") : e) : t;
    }, K = () => (s.schemas || []).map((t) => {
      const e = U(t), r = X(t, s.defaultMask);
      if (!(!e || !r))
        return e;
    }).filter((t) => !!t), T = (t, e) => {
      const r = D(e), a = r ? new Set(r) : void 0;
      K().forEach((n) => {
        (!a || a.has(n)) && (i[n] = t);
      });
    };
    return I([() => s.schemas, () => s.dataSource], () => {
      p.value = A(s.schemas, s.dataSource);
    }, {
      immediate: !0,
      deep: !0
    }), S({
      setMaskStatus: T
    }), (t, e) => (R(), z("div", {
      class: $([o.className, u(v)(), u(k)]),
      style: G(o.style)
    }, [l(u(W), L(o.descriptionsProps, {
      "label-style": C({
        ...o.descriptionsProps?.labelStyle || {}
      }),
      items: p.value
    }), null, 16, ["label-style", "items"])], 6));
  }
});
export {
  gt as default
};
