import { defineComponent as P, useAttrs as z, useCssModule as L, useSlots as q, inject as F, computed as m, ref as G, watch as J, openBlock as i, createElementBlock as f, Fragment as B, createElementVNode as Q, mergeProps as U, unref as e, createBlock as T, normalizeClass as c, withCtx as h, createVNode as _, createCommentVNode as w, renderSlot as A } from "vue";
import { uniqueId as W } from "es-toolkit/compat";
import { t as v } from "./locale.js";
import X from "./Checkbox.js";
import { _ as Y } from "./ChevronToggle.vue_vue_type_script_setup_true_lang-DuvluoTi.js";
import { _ as H } from "./Expand.vue_vue_type_script_setup_true_lang-CSzt6UW3.js";
import "es-toolkit";
import "./Module.keys-DcqBbvvT.js";
import "./DataView.keys-aSOnA4AD.js";
import "./Illustration.vue_vue_type_script_setup_true_lang-Bs1KwoBm.js";
import R from "./TableCell.js";
import { T as K } from "./Table.keys-LHQf6FEH.js";
import { _ as Z } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const ee = /* @__PURE__ */ P({
  inheritAttrs: !1,
  __name: "TableRow",
  props: {
    hideExpansionDivider: { type: Boolean, default: !1 },
    isExpanded: { type: Boolean, default: !1 },
    isSelected: { type: Boolean, default: !1 },
    isSelectDisabled: { type: Boolean, default: !1 },
    accentColor: { default: void 0 }
  },
  emits: ["update:isSelected", "update:isExpanded"],
  setup(y, { emit: N }) {
    const o = y, C = N, $ = z(), l = L(), d = q(), k = F(K.key);
    if (!k)
      throw new Error("TableRow must be used within a Table component");
    const { hasActions: I, hasCustomExpandToggle: E, isSchemaDriven: x, isExpandable: D, isSelectable: M, layout: p, isLoading: V } = k, b = m(() => M.value && !(x != null && x.value)), s = G(o.isExpanded), r = m(() => D.value && !!d.expansion);
    function j(a) {
      return Array.isArray(a) && a.every((t) => t != null && typeof t == "object" && "type" in t);
    }
    function g(a) {
      return a.reduce((t, n) => n.type === B && j(n.children) ? t + g(n.children) : t + 1, 0);
    }
    const O = m(() => {
      var n;
      const a = ((n = d.default) == null ? void 0 : n.call(d, { toggleExpand: u })) ?? [];
      let t = g(a);
      return b.value && (t += 1), r.value && !E.value && (t += 1), t;
    }), S = W("table-row-");
    function u(a) {
      if (!r.value)
        throw new Error("Cannot call `toggleExpand` on a non-expandable row. Provide an `expansion` slot.");
      const t = typeof a == "boolean" ? a : !s.value;
      s.value = t, C("update:isExpanded", t);
    }
    return J(
      () => o.isExpanded,
      () => u(o.isExpanded)
    ), (a, t) => (i(), f(B, null, [
      Q("tr", U({
        class: ["stash-table-row", [
          e(l).root,
          e(l)[`layout--${e(p)}`],
          {
            [e(l)["is-expandable"]]: r.value,
            [e(l)["is-expanded"]]: s.value,
            [e(l)["root--hidden-divider"]]: y.hideExpansionDivider,
            "p-gutter": e(p) === "stack",
            "mb-6 shadow lg:mb-0 lg:shadow-none": e(p) === "stack" && !r.value,
            "pt-[60px]": e(I) && e(p) === "stack" && !b.value && !e(V),
            "stash-table-row--accent": o.accentColor,
            relative: o.accentColor
          }
        ]],
        "data-test": "stash-table-row"
      }, e($)), [
        b.value ? (i(), T(R, {
          key: 0,
          "is-control": "",
          class: c(["stash-table-row__selection-cell min-w-12 lg:pl-3", e(l)["row-control-cell"]]),
          "data-test": "stash-table-row|selection-cell"
        }, {
          default: h(() => [
            _(X, {
              class: c(e(l)["row-selection-checkbox"]),
              checked: o.isSelected,
              disabled: o.isSelectDisabled,
              title: e(v)("ll.select.self"),
              "onUpdate:checked": t[0] || (t[0] = (n) => C("update:isSelected", n))
            }, null, 8, ["class", "checked", "disabled", "title"])
          ]),
          _: 1
        }, 8, ["class"])) : w("", !0),
        r.value && !e(E) ? (i(), T(R, {
          key: 1,
          class: c(["stash-table-row__toggle-expansion-cell px-0", e(l)["row-control-cell"]]),
          "data-test": "stash-table-row|custom-expansion-cell",
          "is-control": ""
        }, {
          default: h(() => [
            _(Y, {
              "aria-controls": e(S),
              "aria-label": s.value ? e(v)("ll.table.collapseRow") : e(v)("ll.table.expandRow"),
              direction: s.value ? "up" : "down",
              "is-expanded": s.value,
              onClick: u
            }, null, 8, ["aria-controls", "aria-label", "direction", "is-expanded"])
          ]),
          _: 1
        }, 8, ["class"])) : w("", !0),
        A(a.$slots, "default", {
          isRowExpanded: s.value,
          toggleExpand: u
        }),
        o.accentColor ? (i(), f("div", {
          key: 2,
          "data-test": "stash-table-row|accent",
          class: c({
            absolute: o.accentColor,
            [`bg-${o.accentColor}`]: o.accentColor,
            block: o.accentColor,
            "h-full": o.accentColor,
            "w-1": o.accentColor,
            "top-0": o.accentColor,
            "left-0": o.accentColor
          })
        }, null, 2)) : w("", !0)
      ], 16),
      r.value ? (i(), f("tr", {
        key: 0,
        class: c(["stash-table-row stash-table-row--expandable", e(l)["row-expansion"]]),
        "data-test": "stash-table-row|expansion-row"
      }, [
        _(H, {
          is: "td",
          id: e(S),
          class: c(["border-none bg-white px-3 py-0", e(l)["row-expansion-content"]]),
          "data-test": "stash-table-row|expansion-cell",
          colspan: O.value,
          "is-expanded": s.value
        }, {
          default: h(() => [
            A(a.$slots, "expansion")
          ]),
          _: 3
        }, 8, ["id", "class", "colspan", "is-expanded"])
      ], 2)) : w("", !0)
    ], 64));
  }
}), oe = "_root_O73SC", te = {
  root: oe,
  "is-expandable": "_is-expandable_ez9BI",
  "root--hidden-divider": "_root--hidden-divider_NtG22",
  "is-expanded": "_is-expanded_b2EYE",
  "layout--scroll": "_layout--scroll_nQum2",
  "layout--stack": "_layout--stack_Mhht4",
  "row-selection-checkbox": "_row-selection-checkbox_P35yd",
  "row-control-cell": "_row-control-cell_3yOgm",
  "row-expansion-content": "_row-expansion-content_kuohW",
  "row-expansion": "_row-expansion_krAXD"
}, ae = {
  $style: te
}, fe = /* @__PURE__ */ Z(ee, [["__cssModules", ae]]);
export {
  fe as default
};
//# sourceMappingURL=TableRow.js.map
