import { defineComponent as ee, useSlots as te, ref as G, useModel as le, watch as oe, computed as s, createVNode as a, Fragment as p, Comment as ne, openBlock as n, createElementBlock as B, mergeProps as re, normalizeStyle as z, normalizeClass as x, unref as h, createBlock as f, resolveDynamicComponent as y, createCommentVNode as v, renderSlot as P, withCtx as D, createElementVNode as ae, mergeModels as se } from "vue";
import { QuestionCircleOutlined as ie } from "@ant-design/icons-vue";
import { Spin as de, Tooltip as ue } from "@aplus-frontend/antdv";
import ce from "@aplus-frontend/antdv/es/_util/hooks/useBreakpoint";
import { IconApAdFillDown as pe } from "@aplus-frontend/icon";
import { clsx as C } from "clsx";
import "../../../config-provider/index.mjs";
import fe from "../../style/index.mjs";
import { useNamespace as ye } from "../../../config-provider/hooks/use-namespace.mjs";
const Ce = /* @__PURE__ */ ee({
  name: "ApProCard",
  __name: "index",
  props: /* @__PURE__ */ se({
    headStyle: {},
    bodyStyle: {},
    actionsStyle: {},
    headerBordered: {
      type: Boolean,
      default: !1
    },
    title: {
      type: [Object, String, Number, Boolean, null, Array]
    },
    tooltip: {
      type: [Object, String, Number, Boolean, null, Array]
    },
    extra: {
      type: [Object, String, Number, Boolean, null, Array]
    },
    layout: {},
    type: {},
    direction: {},
    wrap: {
      type: Boolean,
      default: !1
    },
    loading: {
      type: [Boolean, Object, String, Number, null, Array]
    },
    colSpan: {},
    colStyle: {},
    gutter: {
      default: 0
    },
    actions: {
      type: [Object, String, Number, Boolean, null, Array]
    },
    split: {},
    bordered: {
      type: Boolean,
      default: !1
    },
    hoverable: {
      type: Boolean,
      default: !1
    },
    ghost: {
      type: Boolean,
      default: !1
    },
    collapsible: {
      type: Boolean,
      default: !1
    },
    defaultCollapsed: {
      type: Boolean,
      default: !1
    },
    collapsed: {
      type: Boolean
    },
    collapsibleIconRender: {},
    boxShadow: {
      type: Boolean,
      default: !1
    }
  }, {
    collapsed: {
      type: Boolean,
      default: void 0
    },
    collapsedModifiers: {}
  }),
  emits: ["update:collapsed"],
  setup(j) {
    const t = j, i = te(), m = G(t.defaultCollapsed), M = le(j, "collapsed");
    oe(() => M.value, (e) => {
      e !== void 0 && (m.value = e);
    }, {
      immediate: !0
    });
    const R = () => {
      m.value = !m.value;
    }, {
      b: d
    } = ye("pro-card"), V = fe("pro-card"), $ = ["xxxl", "xxl", "xl", "lg", "md", "sm", "xs"], I = ce(), k = (e, l) => e ? l : {}, F = (e) => {
      const l = [0, 0];
      return (Array.isArray(e) ? e : [e, 0]).forEach((o, c) => {
        if (typeof o == "object")
          for (let u = 0; u < $.length; u += 1) {
            const g = $[u];
            if ({
              lg: !0,
              md: !0,
              sm: !0,
              xl: !1,
              xs: !1,
              xxl: !1,
              xxxl: !1,
              ...I?.value
            }[g] && o[g] !== void 0) {
              l[c] = o[g];
              break;
            }
          }
        else
          l[c] = o || 0;
      }), l;
    }, H = (e) => {
      let l = e;
      if (typeof e == "object")
        for (let o = 0; o < $.length; o += 1) {
          const c = $[o];
          if ({
            lg: !0,
            md: !0,
            sm: !0,
            xl: !1,
            xs: !1,
            xxl: !1,
            xxxl: !1,
            ...I?.value
          }?.[c] && e?.[c] !== void 0) {
            l = e[c];
            break;
          }
        }
      const r = k(typeof l == "string" && /\d%|\dpx/i.test(l), {
        width: l,
        flexShrink: 0
      });
      return {
        span: l,
        colSpanStyle: r
      };
    }, Q = s(() => F(t.gutter)), A = G(!1), E = (e) => {
      A.value = e;
    }, T = s(() => a(p, null, [t.title || i.title?.()])), q = s(() => a(p, null, [t.tooltip])), J = s(() => a(p, null, [t.extra || i.extra?.()])), K = s(() => a(p, null, [t.actions || i.actions?.()])), L = s(() => t.loading === !0 ? a(de, {
      style: {
        width: "100%",
        height: "100%",
        display: "flex",
        alignItems: "center",
        justifyContent: "center"
      }
    }, null) : a(p, null, [t.loading])), b = s(() => t.collapsible && M.value === void 0), U = () => t.collapsibleIconRender ? t.collapsibleIconRender?.({
      collapsed: m.value
    }) : a(p, null, [a(pe, {
      class: d("collapsible-icon"),
      style: {
        transform: m.value ? "rotate(-90deg)" : "rotate(0deg)"
      }
    }, null)]), O = (e, l = []) => {
      if (e?.type === p) {
        const r = Array.isArray(e?.children) ? e?.children : [e?.children];
        if (r?.length)
          for (let o = 0; o < r.length; o++)
            r?.[o] && O(r?.[o], l);
      } else
        e && l.push(e);
      return l;
    }, W = () => {
      const e = i.default?.();
      return E(!1), a(p, null, [e?.reduce((l, r) => {
        const o = O(r);
        return [...l, ...o];
      }, [])?.filter((l) => l.type !== ne)?.map((l, r, o) => {
        if (l && typeof l == "object" && "type" in l && l.type?.isProCard === !0) {
          E(!0);
          const c = l?.props?.colSpan || l?.props?.["col-span"] || {}, {
            span: u,
            colSpanStyle: g
          } = H(c), S = d("col"), _ = C(`${S}`, [typeof u == "number" && u >= 0 && u <= 24 ? `${S}-span-${u}` : void 0, t.split === "horizontal" && r !== o.length - 1 ? `${S}-split-horizontal` : void 0, t.split === "vertical" && r !== o.length - 1 ? `${S}-split-vertical` : void 0].filter(Boolean)), [w, N] = Q.value;
          return a("div", {
            class: _,
            style: {
              ...g,
              ...k(w > 0, {
                paddingInlineStart: `${w / 2}px`,
                paddingInlineEnd: `${w / 2}px`
              }),
              ...k(N > 0, {
                paddingBlockStart: `${N / 2}px`,
                paddingBlockEnd: `${N / 2}px`
              }),
              ...t.colStyle
            }
          }, [l]);
        }
        return l;
      })]);
    }, X = s(() => {
      const e = d();
      return C(`${e}`, [t.bordered ? `${e}-border` : void 0, t.boxShadow ? `${e}-box-shadow` : void 0, A.value ? `${e}-contain-card` : void 0, t.loading ? `${e}-loading` : void 0, t.split === "vertical" || t.split === "horizontal" ? `${e}-split` : void 0, t.ghost ? `${e}-ghost` : void 0, t.hoverable ? `${e}-hoverable` : void 0, t.type ? `${e}-type-${t.type}` : void 0, m.value ? `${e}-collapsed` : void 0, V.value].filter(Boolean));
    }), Y = s(() => {
      const e = d("header");
      return C(`${e}`, [t.headerBordered || t.type === "inner" ? `${e}-border` : void 0, b.value ? `${e}-collapsible` : void 0].filter(Boolean));
    }), Z = s(() => {
      const e = d("body");
      return C(`${e}`, [t.layout === "center" ? `${e}-center` : void 0, t.split === "horizontal" || t.direction === "column" ? `${e}-direction-column` : void 0, t.wrap && A.value ? `${e}-wrap` : void 0].filter(Boolean));
    });
    return (e, l) => (n(), B("div", re({
      class: X.value
    }, {
      ...e.$attrs
    }), [t.title || i.title || t.extra || i.extra || b.value ? (n(), B("div", {
      key: 0,
      class: x(Y.value),
      style: z({
        ...t.headStyle
      }),
      onClick: l[0] || (l[0] = () => {
        b.value && R();
      })
    }, [t.title || i.title || b.value ? (n(), B("div", {
      key: 0,
      class: x(h(d)("header-title"))
    }, [b.value ? (n(), f(y(U()), {
      key: 0
    })) : v("", !0), P(e.$slots, "title", {}, () => [(n(), f(y(T.value)))]), t.tooltip ? (n(), f(h(ue), {
      key: 1
    }, {
      title: D(() => [(n(), f(y(q.value)))]),
      default: D(() => [a(h(ie), {
        class: x(h(d)("header-title-tooltip"))
      }, null, 8, ["class"])]),
      _: 1
    })) : v("", !0)], 2)) : v("", !0), t.extra || i.extra ? (n(), B("div", {
      key: 1,
      class: x(h(d)("header-extra"))
    }, [P(e.$slots, "extra", {}, () => [(n(), f(y(J.value)))])], 2)) : v("", !0)], 6)) : v("", !0), ae("div", {
      class: x(Z.value),
      style: z({
        ...t.bodyStyle
      })
    }, [t.loading ? (n(), f(y(L.value), {
      key: 0
    })) : (n(), f(y(W()), {
      key: 1
    }))], 6), t.actions || i.actions ? (n(), B("div", {
      key: 1,
      class: x(h(d)("actions")),
      style: z({
        ...t.actionsStyle
      })
    }, [(n(), f(y(K.value)))], 6)) : v("", !0)], 16));
  }
});
export {
  Ce as default
};
