/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { useCallback, useMemo, useRef, useState } from "react";
import { usePdfAnnotationPortals } from "./usePdfAnnotationPortals.js";
import { usePdfDocument } from "./usePdfDocument.js";
import { usePdfViewer } from "./usePdfViewer.js";
import { usePdfViewerSync } from "./usePdfViewerSync.js";
export function usePdfViewerCore({
  src,
  initialPage = 1,
  initialScale = 1.0,
  initialAutoSize = false
}) {
  const {
    document,
    numPages,
    loading,
    error
  } = usePdfDocument(src);
  const [scale, setScale] = useState(initialScale);
  const [currentPage, setCurrentPage] = useState(initialPage);
  const [autoSize, setAutoSize] = useState(initialAutoSize);
  const containerRef = useRef(null);
  const viewerRef = useRef(null);
  const {
    pdfViewerRef,
    eventBusRef,
    findControllerRef
  } = usePdfViewer(containerRef, viewerRef, document, initialScale, initialPage);
  const handleScaleChange = useCallback(newScale => {
    setScale(newScale);
  }, []);
  const handlePageChange = useCallback(page => {
    setCurrentPage(page);
  }, []);
  const {
    scrollToPage: syncScrollToPage
  } = usePdfViewerSync({
    pdfViewerRef,
    eventBusRef,
    containerRef,
    document,
    scale,
    autoSize,
    onScaleChange: handleScaleChange,
    onPageChange: handlePageChange
  });
  const scrollToPage = useCallback(page => {
    setCurrentPage(page);
    syncScrollToPage(page);
  }, [syncScrollToPage]);
  const portalTargets = usePdfAnnotationPortals(pdfViewerRef, eventBusRef, document);
  return useMemo(() => ({
    document,
    numPages,
    loading,
    error,
    containerRef,
    viewerRef,
    currentPage,
    scrollToPage,
    scale,
    setScale,
    autoSize,
    setAutoSize,
    portalTargets,
    pdfViewerRef,
    eventBusRef,
    findControllerRef
  }), [document, numPages, loading, error, currentPage, scrollToPage, scale, setScale, autoSize, setAutoSize, portalTargets]);
}
//# sourceMappingURL=usePdfViewerCore.js.map