import type { AisTarget } from '../../entities/aisTarget/model/types';
import type { LegacyVesselInfo } from '../../entities/legacyVessel/model/types';
import type { SubcableGeoJson } from '../../entities/subcable/model/types';
import type { ActiveTrack } from '../../entities/vesselTrack/model/types';
import type { ZonesGeoJson } from '../../entities/zone/api/useZones';
import type { MapToggleState } from '../../features/mapToggles/MapToggles';
import type { FcLink, FleetCircle, LegacyAlarmKind, PairLink } from '../../features/legacyDashboard/model/types';
import type { MapStyleSettings } from '../../features/mapSettings/types';
import type { OceanMapSettings } from '../../features/oceanMap/model/types';
import type { EncMapSettings } from '../../features/encMap/model/types';

export type Map3DSettings = {
  showSeamark: boolean;
  showShips: boolean;
  showDensity: boolean;
};

export type BaseMapId = 'enhanced' | 'enc' | 'ocean' | 'legacy';
export type MapProjectionId = 'mercator' | 'globe';

export interface MapViewState {
  center: [number, number]; // [lon, lat]
  zoom: number;
  bearing: number;
  pitch: number;
}

export interface Map3DProps {
  targets: AisTarget[];
  zones: ZonesGeoJson | null;
  selectedMmsi: number | null;
  hoveredMmsiSet?: number[];
  hoveredFleetMmsiSet?: number[];
  hoveredPairMmsiSet?: number[];
  hoveredFleetOwnerKey?: string | null;
  highlightedMmsiSet?: number[];
  settings: Map3DSettings;
  baseMap: BaseMapId;
  projection: MapProjectionId;
  overlays: MapToggleState;
  onSelectMmsi: (mmsi: number | null) => void;
  onToggleHighlightMmsi?: (mmsi: number) => void;
  onViewBboxChange?: (bbox: [number, number, number, number]) => void;
  legacyHits?: Map<number, LegacyVesselInfo> | null;
  pairLinks?: PairLink[];
  fcLinks?: FcLink[];
  fleetCircles?: FleetCircle[];
  onProjectionLoadingChange?: (loading: boolean) => void;
  fleetFocus?: {
    id: string | number;
    center: [number, number];
    zoom?: number;
  };
  onHoverFleet?: (ownerKey: string | null, fleetMmsiSet: number[]) => void;
  onClearFleetHover?: () => void;
  onHoverMmsi?: (mmsiList: number[]) => void;
  onClearMmsiHover?: () => void;
  onHoverPair?: (mmsiList: number[]) => void;
  onClearPairHover?: () => void;
  subcableGeo?: SubcableGeoJson | null;
  hoveredCableId?: string | null;
  onHoverCable?: (cableId: string | null) => void;
  onClickCable?: (cableId: string | null) => void;
  mapStyleSettings?: MapStyleSettings;
  onMapReady?: (map: import('maplibre-gl').Map) => void;
  initialView?: MapViewState | null;
  onViewStateChange?: (view: MapViewState) => void;
  onGlobeShipsReady?: (ready: boolean) => void;
  activeTrack?: ActiveTrack | null;
  trackContextMenu?: { x: number; y: number; mmsi: number; vesselName: string; isPermitted: boolean } | null;
  onRequestTrack?: (mmsi: number, minutes: number) => void;
  onCloseTrackMenu?: () => void;
  onOpenTrackMenu?: (info: { x: number; y: number; mmsi: number; vesselName: string; isPermitted: boolean }) => void;
  /** MMSI → 가장 높은 우선순위 경고 종류. filteredAlarms 기반. */
  alarmMmsiMap?: Map<number, LegacyAlarmKind>;
  /** 사진 있는 선박 클릭 시 콜백 (사진 표시자 or 선박 아이콘) */
  onClickShipPhoto?: (mmsi: number) => void;
  /** 자유 시점 모드 (회전/틸트 허용) */
  freeCamera?: boolean;
  /** Ocean 지도 전용 설정 */
  oceanMapSettings?: OceanMapSettings;
  /** ENC 전자해도 전용 설정 */
  encMapSettings?: EncMapSettings;
}

export type DashSeg = {
  from: [number, number];
  to: [number, number];
  suspicious: boolean;
  distanceNm?: number;
  fromMmsi?: number;
  toMmsi?: number;
};

export type PairRangeCircle = {
  center: [number, number]; // [lon, lat]
  radiusNm: number;
  warn: boolean;
  aMmsi: number;
  bMmsi: number;
  distanceNm: number;
};

export type BathyZoomRange = {
  id: string;
  mercator: [number, number];
  globe: [number, number];
};
