import { jsx as w } from "react/jsx-runtime";
import { createContext as L, useState as P, useCallback as u, useContext as h, useRef as g, useMemo as A } from "react";
import { LicenseType as R } from "../utils/types.js";
import { useDimensionPagesContext as y } from "./DimensionPagesContext.js";
import { usePagesRotateContext as S } from "./PagesRotateContext.js";
import { useLicenseContext as T } from "./LicenseContext.js";
import { useZoomContext as _ } from "./ZoomContext.js";
import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as E } from "../utils/const.js";
const d = L(void 0), U = ({ children: c }) => {
  const [i, o] = P({}), { widths: t, heights: l } = y(), { pageRotate: m } = S(), { currentZoom: f } = _(), x = u(
    (e, r) => {
      o((n) => {
        const s = { width: t[e], height: l[e] };
        return {
          ...n,
          [e]: r(
            n[e],
            s,
            m[e],
            f * 100
          )
        };
      });
    },
    [t, l, f, m]
  ), p = u((e) => {
    o((r) => {
      const n = { ...r };
      return delete n[e], n;
    });
  }, []), C = u((e, r) => {
    o((n) => {
      const s = { ...n };
      return s[e] = s[e].filter((D, v) => v !== r), s;
    });
  }, []);
  return /* @__PURE__ */ w(
    d.Provider,
    {
      value: { updateElement: x, clearElements: p, removeElement: C, elementList: i },
      children: c
    }
  );
}, a = () => {
}, W = () => {
  const c = h(d), { type: i, validating: o } = T(), t = g(0), l = A(() => {
    if (o !== !1)
      return {
        updateElement: a,
        clearElements: a,
        removeElement: a,
        elementList: {}
      };
    if (!(i !== R.Developer))
      return {
        updateElement: () => {
          t.current === 0 && (console.error(E), t.current++);
        },
        clearElements: () => {
          t.current === 0 && (console.error(E), t.current++);
        },
        removeElement: () => {
          t.current === 0 && (console.error(E), t.current++);
        },
        elementList: {}
      };
  }, [i, o]);
  if (!c)
    throw new Error("useElementPageContext must be used within a ElementPageProvider");
  return l || c;
};
export {
  d as ElementPageContext,
  U as ElementPageProvider,
  W as useElementPageContext
};
