import { jsx as C } from "react/jsx-runtime";
import { createContext as x, useContext as P, useState as F, useCallback as r } from "react";
import { useDocumentContext as h } from "./RPDocumentContext.js";
import { useToolbarComponentContext as T } from "./ToolbarComponentContext.js";
import { useDocumentPasswordContext as v } from "./DocumentPasswordContext.js";
import { useToolComponentContext as L } from "./ToolComponentContext.js";
const i = x({
  dragging: !1,
  handleDragLeave: () => {
  },
  handleDragEnter: () => {
  },
  handleDrop: () => {
  }
}), R = () => P(i), S = ({ children: c }) => {
  const [f, t] = F(!1), { setFilename: n, setPdfSrc: a } = h(), { openFileTool: s } = T(), { openFileTool: l } = L(), { setPassword: u } = v(), m = r(
    (e) => {
      var p;
      e.preventDefault(), e.stopPropagation(), t(!1);
      const o = (p = e.dataTransfer) == null ? void 0 : p.files[0];
      if (!o || o.type !== "application/pdf")
        return;
      const D = URL.createObjectURL(o);
      n(o.name), a(D), u("");
    },
    [n, a]
  ), d = r(
    (e) => {
      e.preventDefault(), e.stopPropagation(), !(!s || !l) && t(!0);
    },
    [s, l]
  ), g = r((e) => {
    e.preventDefault(), e.stopPropagation(), t(!1);
  }, []);
  return /* @__PURE__ */ C(
    i.Provider,
    {
      value: {
        dragging: f,
        handleDragLeave: g,
        handleDragEnter: d,
        handleDrop: m
      },
      children: c
    }
  );
};
export {
  i as DropFileZoneContext,
  S as DropFileZoneProvider,
  R as useDropFileZoneContext
};
