import type { MutableRefObject } from 'react';
import type maplibregl from 'maplibre-gl';
import type { FcLink, FleetCircle, PairLink } from '../../../features/legacyDashboard/model/types';
import type { MapToggleState } from '../../../features/mapToggles/MapToggles';
import type { MapProjectionId } from '../types';
import { useGlobePairOverlay } from './useGlobePairOverlay';
import { useGlobeFcFleetOverlay } from './useGlobeFcFleetOverlay';

export function useGlobeOverlays(
  mapRef: MutableRefObject<maplibregl.Map | null>,
  projectionBusyRef: MutableRefObject<boolean>,
  reorderGlobeFeatureLayers: () => void,
  opts: {
    overlays: MapToggleState;
    pairLinks: PairLink[] | undefined;
    fcLinks: FcLink[] | undefined;
    fleetCircles: FleetCircle[] | undefined;
    projection: MapProjectionId;
    mapSyncEpoch: number;
    hoveredFleetMmsiList: number[];
    hoveredFleetOwnerKeyList: string[];
    hoveredPairMmsiList: number[];
  },
) {
  // Pair lines + pair range
  useGlobePairOverlay(mapRef, projectionBusyRef, reorderGlobeFeatureLayers, {
    overlays: opts.overlays,
    pairLinks: opts.pairLinks,
    projection: opts.projection,
    mapSyncEpoch: opts.mapSyncEpoch,
    hoveredPairMmsiList: opts.hoveredPairMmsiList,
  });

  // FC lines + fleet circles
  useGlobeFcFleetOverlay(mapRef, projectionBusyRef, reorderGlobeFeatureLayers, {
    overlays: opts.overlays,
    fcLinks: opts.fcLinks,
    fleetCircles: opts.fleetCircles,
    projection: opts.projection,
    mapSyncEpoch: opts.mapSyncEpoch,
    hoveredFleetMmsiList: opts.hoveredFleetMmsiList,
    hoveredFleetOwnerKeyList: opts.hoveredFleetOwnerKeyList,
    hoveredPairMmsiList: opts.hoveredPairMmsiList,
  });
}
