import { defineComponent as ee, useSlots as te, useTemplateRef as oe, ref as H, computed as _, onMounted as le, onUnmounted as ae, resolveComponent as L, resolveDirective as re, createBlock as f, openBlock as c, createSlots as U, withCtx as i, createCommentVNode as b, createElementBlock as W, createVNode as V, withModifiers as ne, Fragment as se, renderList as de, createElementVNode as $, normalizeStyle as ie, renderSlot as h, createTextVNode as q, toDisplayString as K, withDirectives as ce, nextTick as ue } from "vue";
import { B as pe, F as fe, _ as me } from "./install-BuMO14Rb.js";
const ye = (r, E) => {
  let o = null, p = null, w = null, d = !1;
  const v = () => {
    if (!p || !d || w === null) return;
    const l = p.getBoundingClientRect(), s = 150, C = 1, I = 25, T = w - l.left, F = l.right - w, B = (y) => y < 0.5 ? 4 * y * y * y : 1 - (-2 * y + 2) ** 3 / 2;
    let S = 0, x = 0;
    if (T < s && p.scrollLeft > 0 ? (S = -1, x = T) : F < s && (S = 1, x = F), S !== 0) {
      const y = 1 - x / s, O = B(y), A = C + (I - C) * O;
      p.scrollLeft += A * S, o = requestAnimationFrame(v);
    } else
      o = null;
  }, k = (l) => {
    l.dataTransfer.effectAllowed = "move";
    const s = l.target.cloneNode(!0);
    s.style.position = "absolute", s.style.top = "-9999px", s.style.background = "var(--p-datatable-header-cell-drag-background)", s.style.width = `${l.target.offsetWidth}px`, document.body.appendChild(s), l.dataTransfer.setDragImage(s, l.offsetX, l.offsetY), setTimeout(() => {
      document.body.removeChild(s);
    }, 0), d = !0, p || (p = r.value?.$el?.querySelector(
      ".p-datatable-table-container"
    ));
  }, m = (l) => {
    w = l.clientX, !o && d && (o = requestAnimationFrame(v));
  }, R = () => {
    o && (cancelAnimationFrame(o), o = null), d = !1, w = null, p = null;
  };
  return {
    addTableDragListener: () => {
      if (!E) return;
      const l = r.value?.$el;
      l?.addEventListener("dragstart", k), l?.addEventListener("dragover", m), l?.addEventListener("dragend", R);
    },
    removeTableDragListener: () => {
      if (!E) return;
      const l = r.value?.$el;
      l?.removeEventListener("dragstart", k), l?.removeEventListener("dragover", m), l?.removeEventListener("dragend", R);
    }
  };
}, be = { class: "wt-table__th__content typo-body-1-bold" }, we = { class: "wt-table__td__actions" }, ve = 10, ge = 40, he = /* @__PURE__ */ ee({
  __name: "wt-table",
  props: {
    headers: { default: () => [] },
    data: { default: () => [] },
    sortable: { type: Boolean, default: !1 },
    selectable: { type: Boolean, default: !0 },
    selected: {},
    gridActions: { type: Boolean, default: !0 },
    fixedActions: { type: Boolean, default: !1 },
    headless: { type: Boolean, default: !1 },
    rowReorder: { type: Boolean, default: !1 },
    dataKey: { default: "" },
    isRowReorderDisabled: { type: Function, default: () => !1 },
    rowExpansion: { type: Boolean, default: !1 },
    rowClass: { type: Function, default: () => "" },
    rowStyle: { type: Function, default: () => ({}) },
    resizableColumns: { type: Boolean, default: !1 },
    reorderableColumns: { type: Boolean, default: !1 },
    rowExpansionDisabled: { type: Function, default: () => !1 },
    lazy: { type: Boolean, default: !1 },
    onLoading: {},
    loading: { type: Boolean },
    itemSize: { default: ge },
    value: {},
    rows: {},
    first: {},
    totalRecords: {},
    paginator: { type: Boolean },
    paginatorPosition: {},
    alwaysShowPaginator: { type: Boolean },
    paginatorTemplate: {},
    pageLinkSize: {},
    rowsPerPageOptions: {},
    currentPageReportTemplate: {},
    loadingIcon: {},
    sortField: {},
    sortOrder: {},
    nullSortOrder: {},
    defaultSortOrder: {},
    multiSortMeta: {},
    sortMode: {},
    removableSort: { type: Boolean },
    filters: {},
    filterDisplay: {},
    globalFilterFields: {},
    filterLocale: {},
    selection: {},
    selectionMode: {},
    compareSelectionBy: {},
    metaKeySelection: { type: Boolean },
    contextMenu: { type: Boolean },
    contextMenuSelection: {},
    selectAll: { type: [Boolean, null] },
    rowHover: { type: Boolean },
    csvSeparator: {},
    exportFilename: {},
    exportFunction: {},
    columnResizeMode: {},
    expandedRows: {},
    expandedRowIcon: {},
    collapsedRowIcon: {},
    rowGroupMode: {},
    groupRowsBy: {},
    expandableRowGroups: { type: Boolean },
    expandedRowGroups: {},
    stateStorage: {},
    stateKey: {},
    editMode: {},
    editingRows: {},
    scrollable: { type: Boolean },
    scrollHeight: {},
    virtualScrollerOptions: {},
    frozenValue: {},
    breakpoint: {},
    showHeaders: { type: Boolean },
    showGridlines: { type: Boolean },
    stripedRows: { type: Boolean },
    highlightOnSelect: { type: Boolean },
    size: {},
    tableStyle: {},
    tableClass: {},
    tableProps: {},
    filterInputProps: {},
    filterButtonProps: {},
    editButtonProps: {},
    dt: {},
    pt: {},
    ptOptions: {},
    unstyled: { type: Boolean }
  },
  emits: [
    "sort",
    "update:selected",
    "reorder:row",
    "column-resize",
    "column-reorder"
  ],
  setup(r, { emit: E }) {
    const o = r, { t: p } = pe(), w = te(), d = E, v = oe("table"), k = H(0), m = H([]), { addTableDragListener: R, removeTableDragListener: P } = ye(
      v,
      o.reorderableColumns
    ), N = [
      "row-select",
      "row-reorder",
      "row-actions",
      "row-expander"
    ], l = _(() => o.selectable ? o.selected || o.data.filter((e) => e._isSelected) : []), s = _(() => o.headers.map((e) => !e.text && e.locale ? {
      ...e,
      text: typeof e.locale == "string" ? p(e.locale) : p(...e.locale)
    } : e)), C = (e) => e.show === !1, I = (e) => {
      const n = e.width || "140px";
      return o.lazy ? {
        width: n
      } : {
        minWidth: n
      };
    }, T = _(() => Object.keys(w).some((e) => e.includes("-footer"))), F = _(() => Object.keys(w).some((e) => e === "footer")), B = _(() => l.value.length === o.data.length && o.data.length > 0), S = ({ sortField: e }) => {
      const a = s.value.find((u) => u.field === e);
      if (!x(a)) return;
      const n = fe(a.sort);
      d("sort", a, n);
    }, x = ({ sort: e }) => o.sortable && e !== void 0, y = () => {
      o.selected ? B.value ? d("update:selected", []) : d("update:selected", [
        ...o.data
      ]) : B.value ? o.data.forEach((e) => {
        e._isSelected = !1;
      }) : o.data.forEach((e) => {
        e._isSelected = !0;
      });
    }, O = (e, a) => {
      o.selected ? a ? d("update:selected", [
        ...l.value,
        e
      ]) : d(
        "update:selected",
        l.value.filter((n) => n !== e)
      ) : e._isSelected = !e._isSelected;
    }, A = ({ element: e }) => {
      const a = e.getAttribute("data-column-field"), n = getComputedStyle(e), u = Number.parseFloat(n.paddingLeft), z = Number.parseFloat(n.paddingRight), D = e.offsetWidth - u - z;
      d("column-resize", {
        columnName: a,
        columnWidth: `${D}px`
      });
    }, G = () => {
      const a = v.value.$el.querySelector(
        ".p-datatable-table-container"
      ).scrollLeft, n = v.value.d_columnOrder.filter(
        (u) => !N.includes(u)
      );
      k.value += 1, d("column-reorder", n), ue(() => {
        R(), v.value.$el.querySelector(".p-datatable-table-container").scrollLeft = a;
      });
    }, X = (e) => m.value.some((a) => a?.id === e?.id), j = (e) => {
      const a = m.value.findIndex((n) => n.id === e.id);
      a !== -1 ? m.value.splice(a, 1) : m.value.push(e);
    }, Z = _(() => {
      if (o.lazy)
        return {
          lazy: o.lazy,
          onLazyLoad: o.onLoading,
          itemSize: o.itemSize,
          // The height/width of item according to orientation
          numToleratedItems: ve,
          // Number of items to pre-render outside visible area
          totalRecords: o.data.length,
          autoSize: !0,
          // Enable auto height recalculation
          appendOnly: !0
          // Prevent scroll position jumps
        };
    });
    return le(() => {
      R();
    }), ae(() => {
      P();
    }), (e, a) => {
      const n = L("wt-icon-btn"), u = L("p-column"), z = L("wt-icon"), D = L("wt-checkbox"), Y = L("p-table"), J = re("tooltip");
      return c(), f(Y, {
        key: k.value,
        ref_key: "table",
        ref: v,
        "expanded-rows": m.value,
        "reorderable-columns": r.reorderableColumns,
        "resizable-columns": r.resizableColumns,
        "row-class": r.rowClass,
        "row-style": r.rowStyle,
        "show-headers": !r.headless,
        value: r.data,
        "data-key": o.dataKey,
        class: "wt-table",
        "column-resize-mode": "expand",
        lazy: "",
        "scroll-height": "flex",
        scrollable: "",
        "virtual-scroller-options": Z.value,
        pt: {
          tableContainer: "wt-scrollbar"
        },
        onSort: S,
        "onUpdate:expandedRows": a[0] || (a[0] = (t) => m.value = t),
        onColumnResizeEnd: A,
        onColumnReorder: G,
        onRowReorder: a[1] || (a[1] = ({ dragIndex: t, dropIndex: g }) => d("reorder:row", { oldIndex: t, newIndex: g }))
      }, U({
        expansion: i(({ data: t }) => [
          $("div", null, [
            h(e.$slots, "expansion", { item: t }, void 0, !0)
          ])
        ]),
        default: i(() => [
          r.rowExpansion ? (c(), f(u, {
            key: 0,
            pt: {
              columnresizer: {
                class: {
                  hidden: !0
                }
              }
            },
            "body-style": "width: 1%;",
            "column-key": "row-expander",
            "header-style": "width: 1%;"
          }, {
            body: i(({ data: t }) => [
              V(n, {
                disabled: o.rowExpansionDisabled(t),
                icon: X(t) ? "arrow-down" : "arrow-right",
                onClick: ne((g) => j(t), ["stop"])
              }, null, 8, ["disabled", "icon", "onClick"])
            ]),
            _: 1
          })) : b("", !0),
          r.rowReorder ? (c(), f(u, {
            key: 1,
            pt: {
              columnresizer: {
                class: {
                  hidden: !0
                }
              }
            },
            "reorderable-column": !1,
            "body-style": "width: 1%;",
            "column-key": "row-reorder",
            "header-style": "width: 1%;",
            "row-reorder": ""
          }, {
            body: i(({ data: t }) => [
              r.isRowReorderDisabled(t) ? b("", !0) : (c(), f(z, {
                key: 0,
                "data-pc-section": "reorderablerowhandle",
                icon: "move"
              }))
            ]),
            _: 1
          })) : b("", !0),
          r.selectable ? (c(), f(u, {
            key: 2,
            pt: {
              columnresizer: {
                class: {
                  hidden: !0
                }
              }
            },
            "reorderable-column": !1,
            "body-style": "width: 1%;",
            "column-key": "row-select",
            "header-style": "width: 1%;"
          }, {
            header: i(() => [
              V(D, {
                selected: B.value,
                "onUpdate:selected": y
              }, null, 8, ["selected"])
            ]),
            body: i(({ data: t }) => [
              t ? (c(), f(D, {
                key: 0,
                selected: l.value.includes(t),
                "onUpdate:selected": (g) => O(t, g)
              }, null, 8, ["selected", "onUpdate:selected"])) : b("", !0)
            ]),
            _: 1
          })) : b("", !0),
          (c(!0), W(se, null, de(s.value, (t, g) => (c(), f(u, {
            key: t.value,
            "column-key": t.field,
            field: t.field,
            hidden: C(t),
            pt: {
              root: {
                "data-column-field": t.field
                // required for column-resizer to get column field
              }
            },
            sortable: x(t)
          }, U({
            header: i(() => [
              h(e.$slots, `header-${t.value}`, {
                index: g,
                header: t
              }, () => [
                $("div", be, [
                  ce((c(), W("span", null, [
                    q(K(t.text), 1)
                  ])), [
                    [J, t.text]
                  ]),
                  t.sort === "asc" ? (c(), f(z, {
                    key: 0,
                    class: "wt-table__th__sort-arrow wt-table__th__sort-arrow--asc",
                    icon: "sort-arrow-up",
                    size: "sm"
                  })) : t.sort === "desc" ? (c(), f(z, {
                    key: 1,
                    class: "wt-table__th__sort-arrow wt-table__th__sort-arrow--desc",
                    icon: "sort-arrow-down",
                    size: "sm"
                  })) : b("", !0)
                ])
              ], !0)
            ]),
            body: i(({ data: M, index: Q }) => [
              $("div", {
                style: ie(I(t)),
                class: "wt-table__td__content typo-body-1"
              }, [
                M ? h(e.$slots, t.value, {
                  key: 0,
                  index: Q,
                  item: M
                }, () => [
                  q(K(M[t.value]), 1)
                ], !0) : b("", !0)
              ], 4)
            ]),
            sorticon: i(() => []),
            _: 2
          }, [
            T.value ? {
              name: "footer",
              fn: i(() => [
                h(e.$slots, `${t.value}-footer`, {}, void 0, !0)
              ]),
              key: "0"
            } : void 0
          ]), 1032, ["column-key", "field", "hidden", "pt", "sortable"]))), 128)),
          r.gridActions ? (c(), f(u, {
            key: 3,
            frozen: r.fixedActions,
            "align-frozen": "right",
            "column-key": "row-actions",
            style: { width: "112px" }
          }, {
            header: i(() => [
              h(e.$slots, "actions-header", {}, void 0, !0)
            ]),
            body: i(({ data: t, index: g }) => [
              $("div", we, [
                t ? h(e.$slots, "actions", {
                  key: 0,
                  index: g,
                  item: t
                }, void 0, !0) : b("", !0)
              ])
            ]),
            _: 3
          }, 8, ["frozen"])) : b("", !0)
        ], void 0, !0),
        _: 2
      }, [
        F.value ? {
          name: "footer",
          fn: i(() => [
            h(e.$slots, "footer", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0
      ]), 1032, ["expanded-rows", "reorderable-columns", "resizable-columns", "row-class", "row-style", "show-headers", "value", "data-key", "virtual-scroller-options"]);
    };
  }
}), _e = /* @__PURE__ */ me(he, [["__scopeId", "data-v-1d2d302d"]]);
export {
  _e as default
};
