import { jsxs as w, jsx as r } from "@emotion/react/jsx-runtime";
import { useBase as x, getPropertyByString as b, evaluateWithContext as y } from "@m4l/core";
import { getSize as h } from "../../utils/getSize/index.js";
import { GridNodeRootStyled as N, GridNodeTrStyled as l, GridNodeThStyled as j, GridNodeTdStyled as G } from "../../slots/PrintingSystemSlots.js";
const X = (u) => {
  const { style: c = {}, rows: e, columns: n } = u, m = typeof e == "string" && /\$\{([^{}]+)\}/g.exec(e) || "", i = Array.isArray(n) && n.length > 0 ? n : [], {
    unitSize: s,
    sourceData: g
    /* templateData */
  } = x(), o = b(g, typeof e == "string" ? m[1] : ""), p = Array.isArray(o) ? o : typeof o == "object" ? [{ ...o }] : [], f = typeof e == "string" ? p : e;
  return i.length > 0 ? /* @__PURE__ */ w(
    N,
    {
      style: {
        ...c
      },
      children: [
        /* @__PURE__ */ r("thead", { children: /* @__PURE__ */ r(
          l,
          {
            children: n.map((t) => /* @__PURE__ */ r(
              j,
              {
                style: {
                  minWidth: t.width ? h(t.width, s) : "auto",
                  maxWidth: t.width ? h(t.width, s) : "auto",
                  justifyContent: t.alignX ? t.alignX : "center"
                },
                children: y(g, t.title)
              },
              `th-${Math.random().toString(36).substring(7)}`
            ))
          },
          `tr-${Math.random().toString(36).substring(7)}`
        ) }),
        /* @__PURE__ */ r("tbody", { children: f.map((t) => /* @__PURE__ */ r(
          l,
          {
            children: n.map((d, a) => {
              const S = !!d.nestedValue;
              return /* @__PURE__ */ r(
                G,
                {
                  style: {
                    minWidth: h(i[a].width || "auto", s),
                    justifyContent: d.alignX ? d.alignX : "center"
                  },
                  children: S ? y({ row: t }, i[a].nestedValue || "") : t[i[a].key]
                },
                `td-${Math.random().toString(36).substring(7)}`
              );
            })
          },
          `tr-${Math.random().toString(36).substring(7)}`
        )) })
      ]
    }
  ) : null;
};
export {
  X as GridNode
};
