import { defineComponent as oe, useSlots as le, useTemplateRef as ae, ref as H, computed as h, onMounted as re, onUnmounted as ne, resolveComponent as L, resolveDirective as se, createBlock as m, openBlock as c, createSlots as U, withCtx as i, createCommentVNode as b, createElementBlock as W, createVNode as V, withModifiers as de, Fragment as ie, renderList as ce, createElementVNode as $, normalizeStyle as ue, renderSlot as S, createTextVNode as q, toDisplayString as K, withDirectives as pe, nextTick as fe } from "vue";
import { B as me, S as G, F as ye, _ as be } from "./install-DJFUeaKV.js";
const we = (r, C) => {
  let o = null, p = null, w = null, d = !1;
  const v = () => {
    if (!p || !d || w === null) return;
    const l = p.getBoundingClientRect(), s = 150, E = 1, I = 25, F = w - l.left, T = l.right - w, R = (f) => f < 0.5 ? 4 * f * f * f : 1 - (-2 * f + 2) ** 3 / 2;
    let x = 0, B = 0;
    if (F < s && p.scrollLeft > 0 ? (x = -1, B = F) : T < s && (x = 1, B = T), x !== 0) {
      const f = 1 - B / s, O = R(f), A = E + (I - E) * O;
      p.scrollLeft += A * x, o = requestAnimationFrame(v);
    } else
      o = null;
  }, _ = (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"
    ));
  }, y = (l) => {
    w = l.clientX, !o && d && (o = requestAnimationFrame(v));
  }, k = () => {
    o && (cancelAnimationFrame(o), o = null), d = !1, w = null, p = null;
  };
  return {
    addTableDragListener: () => {
      if (!C) return;
      const l = r.value?.$el;
      l?.addEventListener("dragstart", _), l?.addEventListener("dragover", y), l?.addEventListener("dragend", k);
    },
    removeTableDragListener: () => {
      if (!C) return;
      const l = r.value?.$el;
      l?.removeEventListener("dragstart", _), l?.removeEventListener("dragover", y), l?.removeEventListener("dragend", k);
    }
  };
}, ve = { class: "wt-table__th__content typo-body-1-bold" }, ge = { class: "wt-table__td__actions" }, he = 10, Se = 40, xe = /* @__PURE__ */ oe({
  __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: Se },
    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: C }) {
    const o = r, { t: p } = me(), w = le(), d = C, v = ae("table"), _ = H(0), y = H([]), { addTableDragListener: k, removeTableDragListener: P } = we(
      v,
      o.reorderableColumns
    ), N = [
      "row-select",
      "row-reorder",
      "row-actions",
      "row-expander"
    ], l = h(() => o.selectable ? o.selected || o.data.filter((e) => e._isSelected) : []), s = h(() => o.headers.map((e) => !e.text && e.locale ? {
      ...e,
      text: typeof e.locale == "string" ? p(e.locale) : p(...e.locale)
    } : e)), E = (e) => e.show === !1, I = (e) => {
      const n = e.width || "140px";
      return o.lazy ? {
        width: n
      } : {
        minWidth: n
      };
    }, F = h(() => Object.keys(w).some((e) => e.includes("-footer"))), T = h(() => Object.keys(w).some((e) => e === "footer")), R = h(() => l.value.length === o.data.length && o.data.length > 0), x = h(() => o.headers.find(
      (a) => a.sort === G.ASC || a.sort === G.DESC
    )?.field ?? null), B = ({ sortField: e }) => {
      const a = s.value.find((u) => u.field === e);
      if (!f(a)) return;
      const n = ye(a.sort);
      d("sort", a, n);
    }, f = ({ sort: e }) => o.sortable && e !== void 0, O = () => {
      o.selected ? R.value ? d("update:selected", []) : d("update:selected", [
        ...o.data
      ]) : R.value ? o.data.forEach((e) => {
        e._isSelected = !1;
      }) : o.data.forEach((e) => {
        e._isSelected = !0;
      });
    }, A = (e, a) => {
      o.selected ? a ? d("update:selected", [
        ...l.value,
        e
      ]) : d(
        "update:selected",
        l.value.filter((n) => n !== e)
      ) : e._isSelected = !e._isSelected;
    }, X = ({ 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`
      });
    }, j = () => {
      const a = v.value.$el.querySelector(
        ".p-datatable-table-container"
      ).scrollLeft, n = v.value.d_columnOrder.filter(
        (u) => !N.includes(u)
      );
      _.value += 1, d("column-reorder", n), fe(() => {
        k(), v.value.$el.querySelector(".p-datatable-table-container").scrollLeft = a;
      });
    }, Z = (e) => y.value.some((a) => a?.id === e?.id), Y = (e) => {
      const a = y.value.findIndex((n) => n.id === e.id);
      a !== -1 ? y.value.splice(a, 1) : y.value.push(e);
    }, J = h(() => {
      if (o.lazy)
        return {
          lazy: o.lazy,
          onLazyLoad: o.onLoading,
          itemSize: o.itemSize,
          // The height/width of item according to orientation
          numToleratedItems: he,
          // 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 re(() => {
      k();
    }), ne(() => {
      P();
    }), (e, a) => {
      const n = L("wt-icon-btn"), u = L("p-column"), z = L("wt-icon"), D = L("wt-checkbox"), Q = L("p-table"), ee = se("tooltip");
      return c(), m(Q, {
        key: _.value,
        ref_key: "table",
        ref: v,
        "expanded-rows": y.value,
        "reorderable-columns": r.reorderableColumns,
        "resizable-columns": r.resizableColumns,
        "row-class": r.rowClass,
        "row-style": r.rowStyle,
        "show-headers": !r.headless,
        value: r.data,
        "sort-field": x.value,
        "data-key": o.dataKey,
        class: "wt-table",
        "column-resize-mode": "expand",
        lazy: "",
        "scroll-height": "flex",
        scrollable: "",
        "virtual-scroller-options": J.value,
        pt: {
          tableContainer: "wt-scrollbar"
        },
        onSort: B,
        "onUpdate:expandedRows": a[0] || (a[0] = (t) => y.value = t),
        onColumnResizeEnd: X,
        onColumnReorder: j,
        onRowReorder: a[1] || (a[1] = ({ dragIndex: t, dropIndex: g }) => d("reorder:row", { oldIndex: t, newIndex: g }))
      }, U({
        expansion: i(({ data: t }) => [
          $("div", null, [
            S(e.$slots, "expansion", { item: t }, void 0, !0)
          ])
        ]),
        default: i(() => [
          r.rowExpansion ? (c(), m(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: Z(t) ? "arrow-down" : "arrow-right",
                onClick: de((g) => Y(t), ["stop"])
              }, null, 8, ["disabled", "icon", "onClick"])
            ]),
            _: 1
          })) : b("", !0),
          r.rowReorder ? (c(), m(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(), m(z, {
                key: 0,
                "data-pc-section": "reorderablerowhandle",
                icon: "move"
              }))
            ]),
            _: 1
          })) : b("", !0),
          r.selectable ? (c(), m(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: R.value,
                "onUpdate:selected": O
              }, null, 8, ["selected"])
            ]),
            body: i(({ data: t }) => [
              t ? (c(), m(D, {
                key: 0,
                selected: l.value.includes(t),
                "onUpdate:selected": (g) => A(t, g)
              }, null, 8, ["selected", "onUpdate:selected"])) : b("", !0)
            ]),
            _: 1
          })) : b("", !0),
          (c(!0), W(ie, null, ce(s.value, (t, g) => (c(), m(u, {
            key: t.value,
            "column-key": t.field,
            field: t.field,
            hidden: E(t),
            pt: {
              root: {
                "data-column-field": t.field
                // required for column-resizer to get column field
              }
            },
            sortable: f(t)
          }, U({
            header: i(() => [
              S(e.$slots, `header-${t.value}`, {
                index: g,
                header: t
              }, () => [
                $("div", ve, [
                  pe((c(), W("span", null, [
                    q(K(t.text), 1)
                  ])), [
                    [ee, t.text]
                  ]),
                  t.sort === "asc" ? (c(), m(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(), m(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: te }) => [
              $("div", {
                style: ue(I(t)),
                class: "wt-table__td__content typo-body-1"
              }, [
                M ? S(e.$slots, t.value, {
                  key: 0,
                  index: te,
                  item: M
                }, () => [
                  q(K(M[t.value]), 1)
                ], !0) : b("", !0)
              ], 4)
            ]),
            sorticon: i(() => []),
            _: 2
          }, [
            F.value ? {
              name: "footer",
              fn: i(() => [
                S(e.$slots, `${t.value}-footer`, {}, void 0, !0)
              ]),
              key: "0"
            } : void 0
          ]), 1032, ["column-key", "field", "hidden", "pt", "sortable"]))), 128)),
          r.gridActions ? (c(), m(u, {
            key: 3,
            frozen: r.fixedActions,
            "align-frozen": "right",
            "column-key": "row-actions",
            style: { width: "112px" }
          }, {
            header: i(() => [
              S(e.$slots, "actions-header", {}, void 0, !0)
            ]),
            body: i(({ data: t, index: g }) => [
              $("div", ge, [
                t ? S(e.$slots, "actions", {
                  key: 0,
                  index: g,
                  item: t
                }, void 0, !0) : b("", !0)
              ])
            ]),
            _: 3
          }, 8, ["frozen"])) : b("", !0)
        ], void 0, !0),
        _: 2
      }, [
        T.value ? {
          name: "footer",
          fn: i(() => [
            S(e.$slots, "footer", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0
      ]), 1032, ["expanded-rows", "reorderable-columns", "resizable-columns", "row-class", "row-style", "show-headers", "value", "sort-field", "data-key", "virtual-scroller-options"]);
    };
  }
}), Re = /* @__PURE__ */ be(xe, [["__scopeId", "data-v-7cd9cee7"]]);
export {
  Re as default
};
