import { computed as C, unref as B, defineComponent as z, ref as M, onMounted as D, resolveComponent as L, createElementBlock as d, openBlock as l, Fragment as $, createElementVNode as u, createCommentVNode as b, normalizeClass as T, renderList as m, renderSlot as p, createBlock as x, createTextVNode as U, toDisplayString as H, createSlots as W, withCtx as I, toRef as O, normalizeStyle as Q, withModifiers as j, createVNode as q } from "vue";
import { B as G, P as R, Q as J, _ as F, F as X } from "./install-BuMO14Rb.js";
const Y = ({ headers: e }) => {
  const { t: y } = G();
  return {
    tableHeaders: C(() => (B(e) ?? []).filter(
      (r) => r.show === void 0 || r.show
    ).map((r) => !r.text && r.locale ? {
      ...r,
      text: typeof r.locale == "string" ? y(r.locale) : y(...r.locale)
    } : r))
  };
}, Z = { class: "wt-tree-table-td__content" }, K = {
  key: 0,
  class: "wt-tree-table-td__icon-wrapper"
}, _ = {
  key: 0,
  class: "wt-tree-table-td__actions typo-body-1"
}, ee = { class: "wt-tree-table-td__content" }, te = /* @__PURE__ */ z({
  __name: "wt-tree-table-row",
  props: {
    data: {},
    rowPosition: {},
    childrenProp: {},
    selectable: { type: Boolean, default: !1 },
    selectedElements: {},
    dataHeaders: {},
    gridActions: { type: Boolean, default: !0 },
    nestingLevel: { default: 0 },
    searchedProp: { default: "searched" }
  },
  emits: [
    "update:selected",
    "expanded-collapse"
  ],
  setup(e, { emit: y }) {
    const a = e, r = y, h = M(!0), N = C(() => a.nestingLevel), A = C(() => a.nestingLevel + 1), P = C(() => a.selectedElements.includes(a.data)), k = () => {
      h.value = !1, r("expanded-collapse");
    }, g = (c, i = 0) => {
      if (c[a.searchedProp] && i) return !0;
      if (Array.isArray(c[a.childrenProp])) {
        for (const f of c[a.childrenProp])
          if (g(f, i + 1))
            return !0;
      }
      return !1;
    };
    return D(() => {
      a.searchedProp && g(a.data) && k();
    }), (c, i) => {
      const f = L("wt-tree-table-row", !0);
      return l(), d($, null, [
        u("tr", {
          class: T([[{ "wt-tree-table-row--alternate": e.rowPosition % 2 }], "wt-tree-table-row"])
        }, [
          (l(!0), d($, null, m(e.dataHeaders, (S, E) => (l(), d("td", {
            key: E,
            class: "wt-tree-table-td typo-body-1"
          }, [
            u("div", Z, [
              E ? b("", !0) : (l(), d("div", K, [
                (l(!0), d($, null, m(N.value, (t) => (l(), d("div", {
                  key: t,
                  class: "wt-tree-table-row__tree-space"
                }))), 128)),
                e.selectable ? (l(), x(R, {
                  key: 0,
                  selected: P.value,
                  "onUpdate:selected": i[0] || (i[0] = (t) => c.$emit("update:selected", {
                    data: e.data,
                    select: t
                  }))
                }, null, 8, ["selected"])) : b("", !0),
                e.data[e.childrenProp] ? (l(), x(J, {
                  key: 1,
                  icon: h.value ? "tree-expand" : "tree-collapse",
                  onClick: i[1] || (i[1] = (t) => h.value = !h.value)
                }, null, 8, ["icon"])) : b("", !0)
              ])),
              p(c.$slots, S.value, {
                index: e.rowPosition,
                item: e.data
              }, () => [
                U(H(e.data[S.value]), 1)
              ], !0)
            ])
          ]))), 128)),
          e.gridActions ? (l(), d("td", _, [
            u("div", ee, [
              p(c.$slots, "actions", {
                index: e.rowPosition,
                item: e.data
              }, void 0, !0)
            ])
          ])) : b("", !0)
        ], 2),
        h.value ? b("", !0) : (l(!0), d($, { key: 0 }, m(e.data[e.childrenProp], (S, E) => (l(), x(f, {
          key: E,
          "children-prop": e.childrenProp,
          data: S,
          "data-headers": e.dataHeaders,
          "nesting-level": A.value,
          "row-position": e.rowPosition,
          "searched-prop": e.searchedProp,
          selectable: e.selectable,
          "selected-elements": e.selectedElements,
          onExpandedCollapse: k,
          "onUpdate:selected": i[2] || (i[2] = (t) => c.$emit("update:selected", {
            data: t.data,
            select: t.select
          }))
        }, W({
          actions: I(({ item: t }) => [
            p(c.$slots, "actions", {
              index: e.rowPosition,
              item: t
            }, void 0, !0)
          ]),
          _: 2
        }, [
          m(e.dataHeaders, (t, o) => ({
            name: t.value,
            fn: I(({ item: n }) => [
              p(c.$slots, t.value, {
                index: e.rowPosition,
                item: n
              }, () => [
                u("div", null, H(n[t.value]), 1)
              ], !0)
            ])
          }))
        ]), 1032, ["children-prop", "data", "data-headers", "nesting-level", "row-position", "searched-prop", "selectable", "selected-elements"]))), 128))
      ], 64);
    };
  }
}), ae = /* @__PURE__ */ F(te, [["__scopeId", "data-v-8381ad70"]]), le = { class: "wt-tree-table wt-scrollbar" }, se = { class: "wt-tree-table-wrapper" }, re = { class: "wt-tree-table-head" }, oe = { class: "wt-tree-table-tr wt-tree-table-tr-head" }, ne = ["onClick"], de = { class: "wt-tree-table-th__text" }, ce = {
  key: 0,
  class: "wt-tree-table-th__actions"
}, ie = { class: "wt-tree-table-th__content" }, ue = { class: "wt-tree-table-body" }, he = /* @__PURE__ */ z({
  __name: "wt-tree-table",
  props: {
    headers: {},
    data: {},
    sortable: { type: Boolean, default: !1 },
    selectable: { type: Boolean, default: !0 },
    selected: {},
    gridActions: { type: Boolean, default: !0 },
    childrenProp: {},
    searchedProp: { default: "searched" }
  },
  emits: [
    "sort",
    "update:selected"
  ],
  setup(e, { emit: y }) {
    const a = e, r = y, h = (t) => t[a.childrenProp] && Array.isArray(t[a.childrenProp]), N = (t) => {
      const o = [], n = (s) => {
        if (s._isSelected)
          return [
            s
          ];
        h(s) && s[a.childrenProp].forEach(n);
      };
      return t.forEach(n), o;
    }, A = (t) => {
      const o = [], n = (s) => {
        o.push(s), h(s) && s[a.childrenProp].forEach(n);
      };
      return t.forEach(n), o;
    }, P = C(() => a.selected || N(a.data)), k = C(() => P.value.length === A(a.data).length && A(a.data).length > 0), { tableHeaders: g } = Y({
      headers: O(a, "headers")
    }), c = ({ sort: t }) => a.sortable && t !== void 0, i = (t) => {
      if (!c(t)) return;
      const o = X(t.sort);
      r("sort", t, o);
    }, f = (t, o) => {
      t.forEach((n) => {
        n._isSelected = o, h(n) && f(n[a.childrenProp], o);
      });
    }, S = () => {
      a.selected ? r(
        "update:selected",
        k.value ? [] : [
          ...A(a.data)
        ]
      ) : k.value ? f(a.data, !1) : f(a.data, !0);
    }, E = (t, o) => {
      a.selected ? o ? r("update:selected", [
        ...P.value,
        t
      ]) : r(
        "update:selected",
        P.value.filter((n) => n !== t)
      ) : t._isSelected = !t._isSelected;
    };
    return (t, o) => {
      const n = L("wt-icon");
      return l(), d("div", le, [
        u("table", se, [
          u("thead", re, [
            u("tr", oe, [
              (l(!0), d($, null, m(B(g), (s, v) => (l(), d("th", {
                key: String(v) + s?.sort,
                class: T([[
                  {
                    "wt-tree-table-th--sortable": c(s)
                  },
                  `wt-tree-table-th--sort-${s.sort}`
                ], "wt-tree-table-th typo-body-1"]),
                style: Q(s.width ? `min-width:${s.width}` : ""),
                onClick: (w) => i(s)
              }, [
                u("div", {
                  class: T(["wt-tree-table-th__content", { "wt-tree-table-th__content--selectable": v === 0 && e.selectable }])
                }, [
                  v === 0 && e.selectable ? (l(), d("div", {
                    key: 0,
                    onClick: o[0] || (o[0] = j(() => {
                    }, ["stop"]))
                  }, [
                    q(R, {
                      selected: k.value,
                      "onUpdate:selected": S
                    }, null, 8, ["selected"])
                  ])) : b("", !0),
                  u("div", de, H(s.text), 1),
                  e.sortable ? (l(), x(n, {
                    key: 1,
                    class: "wt-tree-table-th-sort-arrow wt-tree-table-th-sort-arrow--asc",
                    icon: "sort-arrow-up",
                    size: "sm"
                  })) : b("", !0),
                  e.sortable ? (l(), x(n, {
                    key: 2,
                    class: "wt-tree-table-th-sort-arrow wt-tree-table-th-sort-arrow--desc",
                    icon: "sort-arrow-down",
                    size: "sm"
                  })) : b("", !0)
                ], 2)
              ], 14, ne))), 128)),
              e.gridActions ? (l(), d("th", ce, [
                u("div", ie, [
                  p(t.$slots, "actions-header", {}, void 0, !0)
                ])
              ])) : b("", !0)
            ])
          ]),
          u("tbody", ue, [
            (l(!0), d($, null, m(e.data, (s, v) => (l(), x(ae, {
              key: v,
              "row-position": v,
              "data-headers": B(g),
              data: s,
              selectable: e.selectable,
              "children-prop": e.childrenProp,
              "selected-elements": P.value,
              "searched-prop": e.searchedProp,
              "onUpdate:selected": o[1] || (o[1] = (w) => E(w.data, w.select))
            }, W({
              actions: I(({ item: w }) => [
                p(t.$slots, "actions", { item: w }, void 0, !0)
              ]),
              _: 2
            }, [
              m(B(g), (w, we) => ({
                name: w.value,
                fn: I(({ item: V }) => [
                  p(t.$slots, w.value, {
                    index: v,
                    item: V
                  }, () => [
                    U(H(V[w.value]), 1)
                  ], !0)
                ])
              }))
            ]), 1032, ["row-position", "data-headers", "data", "selectable", "children-prop", "selected-elements", "searched-prop"]))), 128))
          ])
        ])
      ]);
    };
  }
}), ve = /* @__PURE__ */ F(he, [["__scopeId", "data-v-721c9bc6"]]);
export {
  ve as default
};
