import { jsx as n } from "@emotion/react/jsx-runtime";
import { FactoryRender as d } from "./utils/FactoryRender/index.js";
import { PageRender as b } from "./utils/PageRender/index.js";
import { forwardRef as w, useRef as T, useImperativeHandle as D } from "react";
import { useTheme as E } from "@mui/material/styles";
import { PrintingSystemRootStyled as I } from "./slots/PrintingSystemSlots.js";
import { getComponentSlotRoot as x } from "../../utils/getComponentSlotRoot.js";
import { PRINTING_SYSTEM_KEY_COMPONENT as p } from "./constants.js";
import { PrintingSystemSlots as G } from "./slots/PrintingSystemEnum.js";
import { getPropDataTestId as _ } from "../../test/getNameDataTestId.js";
import z from "clsx";
import { printingSystemStyles as i } from "./PrintingSystem.styles.js";
const B = w((c, f) => {
  const { templateData: t, sourceData: y, size: u = "medium", variant: S = "bodyStandard", className: g, dataTestId: h } = c, P = E(), m = Array.isArray(t.pages) && t.pages.length > 0 ? t.pages : [], a = T(null);
  D(f, () => ({
    /**
     * Función para imprimir el contenido de la estructura raíz
     */
    GoPrint: async () => {
      if (a.current) {
        const r = a.current, e = window.open("", "_blank");
        if (e) {
          const o = e.document;
          o.write(
            "<html><head><title>Contenido a imprimir</title></head><body></body></html>"
          ), o.body.appendChild(r.cloneNode(!0));
          const s = o.createElement("style"), l = i.root && typeof i.root == "function" ? i.root({ theme: P }) : null;
          s.textContent = l ? String(l) : "", o.head.appendChild(s), o.close(), e.print();
        }
      }
    }
  }));
  const R = {
    size: u,
    variant: S
  }, C = () => /* @__PURE__ */ n(d, { data: t.header[0] }), N = () => /* @__PURE__ */ n(d, { data: t.footer[0] });
  return /* @__PURE__ */ n(
    I,
    {
      className: z(x(p), g),
      ..._(p, G.root, h),
      ownerState: R,
      ref: a,
      role: "region",
      "aria-label": "Printing System",
      children: m.map((r, e) => /* @__PURE__ */ n(
        b,
        {
          data: r,
          id: e + 1,
          unitSize: t.unitSizes,
          mainColor: t.mainColor,
          countPages: m.length,
          HeaderGeneral: C,
          FooterGeneral: N,
          sourceData: y,
          templateData: t
        },
        r.key
      ))
    }
  );
});
export {
  B as PrintingSystem
};
