import { j as t } from "../../../_virtual/jsx-runtime.js";
import { useState as m, useEffect as p } from "react";
import { Checkbox as j } from "../../Field/checkbox/Checkbox.js";
import { CheckboxCell as g, Th as k, ThContainer as C } from "../styles.js";
import { getRowIdByIdentifier as u } from "../utils.js";
const E = ({
  columns: c,
  selectAllRows: i,
  rows: l,
  selectedRows: r,
  rowIdentifier: n,
  "data-testid": s,
  "data-trackid": f
}) => {
  const [d, h] = m(!1);
  return p(() => {
    r && (r.length === 0 || r.length < l.length) && h(!1);
  }, [r]), /* @__PURE__ */ t.jsx("thead", { "data-testid": s, "data-trackid": f, children: /* @__PURE__ */ t.jsxs("tr", { role: "row", children: [
    r && typeof i == "function" && /* @__PURE__ */ t.jsx(g, { as: "th", role: "columnheader", children: /* @__PURE__ */ t.jsx(
      j,
      {
        onChange: () => {
          h((e) => {
            const a = !e;
            let o = [];
            return n && (o = l.map(
              (x) => u(x, n)
            )), i(o, a), a;
          });
        },
        checked: d,
        name: "select-all",
        value: 0,
        indeterminate: r.length > 0 && !d
      }
    ) }),
    c.map(
      (e, a) => !e.hideHeader && /* @__PURE__ */ t.jsx(
        k,
        {
          textAlign: e.textAlign,
          onClick: e.onClick,
          columnWidth: e.width,
          role: "columnheader",
          children: /* @__PURE__ */ t.jsxs(C, { children: [
            /* @__PURE__ */ t.jsx("span", { children: e.header.title }),
            e.header.icon
          ] })
        },
        `${a}_${e.header.title}`
      )
    )
  ] }) });
};
export {
  E as default
};
