import { jsx as C } from "react/jsx-runtime";
import { createContext as h, useState as m, useEffect as v, useMemo as S, useContext as D } from "react";
import { useLoadPdf as F } from "../utils/hooks/useLoadPdf.js";
import { usePdfProperties as M } from "../utils/hooks/usePdfProperties.js";
import { appConsole as j } from "../utils/appConsole.js";
const u = h({
  pdf: void 0,
  pages: /* @__PURE__ */ new Map(),
  setPdfSrc: () => {
  },
  setFilename: () => {
  },
  loading: !1,
  loaderProgress: 0,
  error: void 0
}), b = ({
  children: t,
  src: e,
  characterMap: c,
  onLoadError: P,
  onLoaded: g
}) => {
  const [o, n] = m(e), [s, i] = m(), { pdf: r, pages: d, loading: p, loadingProgress: f, error: a } = F(o, c, {
    onLoadError: P,
    onLoaded: g
  }), l = M(o, r, s);
  v(() => {
    i(e == null ? void 0 : e.split("/").pop()), n(e);
  }, [e]);
  const x = S(() => ({
    pdf: r,
    pages: d,
    pdfSrc: o,
    setPdfSrc: n,
    pdfProperties: l,
    setFilename: i,
    filename: s,
    loading: p,
    loaderProgress: f,
    error: a
  }), [r, d, o, l, p, f, a]);
  return /* @__PURE__ */ C(u.Provider, { value: x, children: o ? t : null });
}, q = () => {
  const t = D(u);
  return t.pdfSrc || j.error("Please use this hooks inside children component of RPDocument"), t;
};
export {
  b as DocumentProvider,
  u as default,
  q as useDocumentContext
};
