import { useEffect, useRef, useState } from 'react';
import { Viewer, DocumentGate, usePageList } from '@embedpdf/react/runtime';
import type { OpenInput, PageRef } from '@embedpdf/react/runtime';
import { Stage, stagePlugin, useStage, useStageState } from '@embedpdf/react/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/react/render';
import { pageEditPlugin, usePageEdit } from '@embedpdf/react/page-edit';
import { cloudEngine } from '@cloudpdf/engine';
import './insert.css';
const engine = cloudEngine();
const plugins = [stagePlugin(), renderPlugin(), pageEditPlugin()];
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
/** Another PDF's bytes, to insert pages from. */
const otherPdf = async () =>
(await fetch('https://www.cloudpdf.com/pdfs/welcome.pdf')).arrayBuffer();
// Inserts next to the page you're on, then goes to the first new page.
function InsertToolbar() {
const pageEdit = usePageEdit();
const stage = useStage();
const pages = usePageList();
const currentPageIndex = useStageState((state) => state.currentPageIndex);
const page = pages[currentPageIndex];
const [added, setAdded] = useState