/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

import { useReactFlow } from '@xyflow/react';
import { useCallback } from 'react';
/**
 * Custom hook for managing celestial view controls
 * Provides zoom and fit view functionality for the celestial map
 * @returns Object containing zoom and fit view control functions
 */
export const useCelestialControls = () => {
  // Extract zoom and fit view controls from ReactFlow
  const {
    zoomIn,
    zoomOut,
    fitView
  } = useReactFlow();

  /**
   * Handler for zooming in the view
   * @param e Mouse event from zoom button click
   */
  const onZoomIn = useCallback(e => {
    e.stopPropagation();
    zoomIn === null || zoomIn === void 0 || zoomIn({
      duration: 300
    });
  }, [zoomIn]);

  /**
   * Handler for zooming out the view
   * @param e Mouse event from zoom button click
   */
  const onZoomOut = useCallback(e => {
    e.stopPropagation();
    zoomOut === null || zoomOut === void 0 || zoomOut({
      duration: 300
    });
  }, [zoomOut]);

  /**
   * Handler for fitting all elements in view
   * @param e Mouse event from fit view button click
   */
  const onFitView = useCallback(e => {
    e.stopPropagation();
    fitView === null || fitView === void 0 || fitView({
      duration: 300
    }); // Animate transition over 300ms
  }, [fitView]);
  return {
    onZoomIn,
    onZoomOut,
    onFitView
  };
};