import { defineComponent as te, useCssModule as le, inject as $, computed as l, useTemplateRef as I, ref as x, watch as ae, nextTick as se, provide as oe, watchEffect as re, openBlock as u, createElementBlock as m, createElementVNode as h, normalizeStyle as r, normalizeClass as i, unref as b, renderSlot as E, createBlock as N, withCtx as f, createVNode as n, Fragment as z, createCommentVNode as L } from "vue";
import { d as ie, e as A, f as ne } from "./index-CLv1CFWG.js";
import D from "./Button.js";
import "es-toolkit";
import { M } from "./Module.keys-DcqBbvvT.js";
import "es-toolkit/compat";
import P from "./Icon.js";
import { D as j } from "./DataView.keys-aSOnA4AD.js";
import de from "./EmptyState.js";
import ce from "./Loading.js";
import J from "./TableCell.js";
import V from "./TableRow.js";
import { T as ue } from "./Table.keys-LHQf6FEH.js";
import { S as he } from "./misc-CHQs-G03.js";
import { _ as fe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
var be = /* @__PURE__ */ ((o) => (o.Scroll = "scroll", o.Stack = "stack", o))(be || {}), pe = /* @__PURE__ */ ((o) => (o.None = "none", o.Rounded = "rounded", o.RoundedBottom = "rounded-bottom", o))(pe || {});
const ve = { class: "stash-table-wrapper relative" }, me = ["aria-busy"], ye = /* @__PURE__ */ te({
  __name: "Table",
  props: {
    density: { default: void 0 },
    emptyStateText: { default: "" },
    hasActions: { type: Boolean, default: !1 },
    hasCustomExpandToggle: { type: Boolean, default: !1 },
    isEmpty: { type: Boolean, default: !1 },
    isSchemaDriven: { type: Boolean, default: !1 },
    isLoading: { type: Boolean, default: !1 },
    isExpandable: { type: Boolean, default: !1 },
    isSelectable: { type: Boolean, default: !1 },
    layout: { default: "scroll" },
    radius: { default: "rounded" },
    stickyHeader: { default: void 0 },
    pinnedLeftWidth: { default: 0 },
    pinnedRightWidth: { default: 0 },
    tableMinWidth: { default: void 0 }
  },
  setup(o) {
    const e = o, y = le(), {
      density: X,
      variant: g,
      isEmpty: p,
      isLoading: d,
      isSelectable: C
    } = $(j.key, j.defaults), { variant: w } = $(M.key, M.defaults), W = l(() => (w == null ? void 0 : w.value) === "table" || g.value === "table" ? "rounded-bottom" : e.radius), s = l(() => e.stickyHeader ? "scroll" : e.layout), U = l(() => s.value === "scroll" && g.value === "table"), R = l(() => {
      var t, a;
      return !!((t = e.stickyHeader) != null && t.maxHeight && ((a = e.stickyHeader) == null ? void 0 : a.listLength) > 3);
    }), F = l(() => {
      var t;
      return {
        maxHeight: R.value ? (t = e.stickyHeader) == null ? void 0 : t.maxHeight : ""
      };
    }), S = l(() => !!(e.isLoading || d != null && d.value)), c = I("scrollContainerRef"), T = I("tableRef"), B = x(!1), _ = x(0), k = x(0), { arrivedState: H, measure: q } = ie(c, { behavior: "smooth" });
    function v() {
      const t = c.value;
      !t || s.value !== "scroll" || (B.value = t.scrollWidth > t.clientWidth, _.value = t.offsetWidth - t.clientWidth, k.value = t.offsetHeight - t.clientHeight, q());
    }
    A(c, v), A(T, v), ne(
      c,
      (t) => {
        var a;
        (a = t[0]) != null && a.isIntersecting && v();
      },
      { threshold: 0.01 }
    ), ae(
      () => [e.pinnedLeftWidth, e.pinnedRightWidth, e.tableMinWidth],
      () => {
        se(() => v());
      }
    );
    const G = l(() => !H.left), K = l(() => !H.right), Q = l(() => s.value === "scroll" && B.value);
    function O(t) {
      var a;
      (a = c.value) == null || a.scrollBy({ left: t, behavior: "smooth" });
    }
    const Y = l(() => (e.pinnedLeftWidth ?? 0) > 0 || (e.pinnedRightWidth ?? 0) > 0), Z = l(() => {
      const t = {};
      return e.tableMinWidth != null && (t.minWidth = `${e.tableMinWidth}px`), Object.keys(t).length ? t : void 0;
    });
    return oe(ue.key, {
      density: l(() => e.density || X.value || he.Comfortable),
      hasCustomExpandToggle: l(() => e.hasCustomExpandToggle),
      hasActions: l(() => e.hasActions),
      isSchemaDriven: l(() => e.isSchemaDriven),
      isExpandable: l(() => e.isExpandable),
      isSelectable: l(
        () => e.isSelectable && !e.isLoading && !(d != null && d.value) && !e.isEmpty && !(p != null && p.value)
      ),
      isLoading: S,
      layout: s
    }), re(() => {
      C && (C.value = e.isSelectable);
    }), (t, a) => (u(), m("div", ve, [
      h("div", {
        ref_key: "scrollContainerRef",
        ref: c,
        class: i(["stash-table relative", [
          { rounded: W.value === "rounded" },
          { "rounded-b": W.value === "rounded-bottom" },
          { "border-t border-ice-200": b(g) === "table" },
          { "overflow-auto scroll-smooth": s.value === "scroll" },
          { shadow: U.value },
          {
            "overflow-visible lg:overflow-auto lg:shadow": s.value === "stack"
          }
        ]]),
        "data-test": "stash-table",
        "aria-busy": S.value,
        style: r(F.value)
      }, [
        h("table", {
          ref_key: "tableRef",
          ref: T,
          class: i(["relative w-full", { "border-separate border-spacing-0": R.value || Y.value }]),
          style: r(Z.value)
        }, [
          h("thead", {
            class: i(["border-b border-ice-200", { "hidden lg:table-header-group": s.value === "stack" }])
          }, [
            E(t.$slots, "head")
          ], 2),
          h("tbody", null, [
            S.value ? (u(), N(V, { key: 0 }, {
              default: f(() => [
                n(J, {
                  colspan: "100%",
                  class: i({ "relative! col-span-12": s.value === "stack" })
                }, {
                  default: f(() => [
                    n(ce, {
                      style: r([s.value === "scroll" ? { "max-width": "100vw" } : {}])
                    }, null, 8, ["style"])
                  ]),
                  _: 1
                }, 8, ["class"])
              ]),
              _: 1
            })) : e.isEmpty || b(p) ? (u(), N(V, { key: 1 }, {
              default: f(() => [
                n(J, {
                  colspan: "100%",
                  class: i({ "relative! col-span-12": s.value === "stack" })
                }, {
                  default: f(() => [
                    E(t.$slots, "empty", {}, () => [
                      n(de, {
                        class: "w-full bg-white",
                        text: e.emptyStateText,
                        style: r([s.value === "scroll" ? { "max-width": "100vw" } : {}])
                      }, null, 8, ["text", "style"])
                    ])
                  ]),
                  _: 3
                }, 8, ["class"])
              ]),
              _: 3
            })) : E(t.$slots, "body", { key: 2 })
          ])
        ], 6)
      ], 14, me),
      Q.value ? (u(), m("div", {
        key: 0,
        class: i([b(y)["stash-table-scroll-overlay"], "pointer-events-none absolute inset-0 flex items-center justify-between z-2"])
      }, [
        G.value ? (u(), m(z, { key: 0 }, [
          h("div", {
            class: i([b(y)["stash-table-scroll-shadow-left"], "stash-table-scroll-shadow border-l border-ice-100 absolute top-0 w-4"]),
            style: r({ left: `${e.pinnedLeftWidth}px`, bottom: `${k.value}px` }),
            "data-test": "stash-table|scroll-shadow-left"
          }, null, 6),
          n(D, {
            class: "pointer-events-auto absolute top-[7px] border border-ice-100 bg-white rounded-full shadow size-6 p-0 min-w-auto",
            style: r({ left: `${(e.pinnedLeftWidth ?? 0) + 12}px` }),
            secondary: "",
            icon: "",
            "aria-label": "Scroll table left",
            "data-test": "stash-table|scroll-left",
            onClick: a[0] || (a[0] = (ee) => O(-200))
          }, {
            default: f(() => [
              n(P, { name: "chevron-left" })
            ]),
            _: 1
          }, 8, ["style"])
        ], 64)) : L("", !0),
        K.value ? (u(), m(z, { key: 1 }, [
          h("div", {
            class: i([b(y)["stash-table-scroll-shadow-right"], "stash-table-scroll-shadow border-r border-ice-100 absolute top-0 w-4"]),
            style: r({
              right: `${_.value + (e.pinnedRightWidth ?? 0)}px`,
              bottom: `${k.value}px`
            }),
            "data-test": "stash-table|scroll-shadow-right"
          }, null, 6),
          n(D, {
            class: "pointer-events-auto absolute top-[7px] border border-ice-100 bg-white rounded-full shadow size-6 p-0 min-w-auto",
            style: r({ right: `${_.value + (e.pinnedRightWidth ?? 0) + 12}px` }),
            secondary: "",
            icon: "",
            "aria-label": "Scroll table right",
            "data-test": "stash-table|scroll-right",
            onClick: a[1] || (a[1] = (ee) => O(200))
          }, {
            default: f(() => [
              n(P, {
                name: "chevron-right",
                class: "text-ice-900"
              })
            ]),
            _: 1
          }, 8, ["style"])
        ], 64)) : L("", !0)
      ], 2)) : L("", !0)
    ]));
  }
}), ge = {
  "stash-table-scroll-shadow-left": "_stash-table-scroll-shadow-left_Dg4aP",
  "stash-table-scroll-shadow-right": "_stash-table-scroll-shadow-right_j3L98",
  "stash-table-scroll-overlay": "_stash-table-scroll-overlay_tzUO1"
}, we = {
  $style: ge
}, ze = /* @__PURE__ */ fe(ye, [["__cssModules", we]]);
export {
  be as Layout,
  ue as TABLE_INJECTION,
  pe as TableRadius,
  ze as default
};
//# sourceMappingURL=Table.js.map
