import { useMemo } from 'react';
import type { Layer } from '@deck.gl/core';
import type { PowerFacility } from '../services/infra';
import type { HazardType } from '../data/hazardFacilities';
import { useFontScale } from './useFontScale';

// Re-export types for consumers
export type { StaticPickedObject, StaticLayerKind, StaticPickInfo } from './layers/types';

import { createPortLayers } from './layers/createPortLayers';
import { createNavigationLayers } from './layers/createNavigationLayers';
import { createMilitaryLayers } from './layers/createMilitaryLayers';
import { createFacilityLayers } from './layers/createFacilityLayers';

interface StaticLayerConfig {
  ports: boolean;
  coastGuard: boolean;
  windFarm: boolean;
  militaryBases: boolean;
  govBuildings: boolean;
  airports: boolean;
  navWarning: boolean;
  nkLaunch: boolean;
  nkMissile: boolean;
  piracy: boolean;
  infra: boolean;
  infraFacilities: PowerFacility[];
  hazardTypes: HazardType[];
  cnPower: boolean;
  cnMilitary: boolean;
  jpPower: boolean;
  jpMilitary: boolean;
  onPick: (info: import('./layers/types').StaticPickInfo) => void;
  sizeScale?: number;
}

export function useStaticDeckLayers(config: StaticLayerConfig): Layer[] {
  const { fontScale } = useFontScale();
  return useMemo(() => {
    const fc = { sc: config.sizeScale ?? 1.0, fs: fontScale.facility, onPick: config.onPick };

    return [
      ...createPortLayers({ ports: config.ports, windFarm: config.windFarm }, fc),
      ...createNavigationLayers({
        coastGuard: config.coastGuard,
        airports: config.airports,
        navWarning: config.navWarning,
        piracy: config.piracy,
      }, fc),
      ...createMilitaryLayers({
        militaryBases: config.militaryBases,
        govBuildings: config.govBuildings,
        nkLaunch: config.nkLaunch,
        nkMissile: config.nkMissile,
      }, fc),
      ...createFacilityLayers({
        infra: config.infra,
        infraFacilities: config.infraFacilities,
        hazardTypes: config.hazardTypes,
        cnPower: config.cnPower,
        cnMilitary: config.cnMilitary,
        jpPower: config.jpPower,
        jpMilitary: config.jpMilitary,
      }, fc),
    ];
  }, [
    config.ports,
    config.windFarm,
    config.coastGuard,
    config.airports,
    config.navWarning,
    config.piracy,
    config.militaryBases,
    config.govBuildings,
    config.nkLaunch,
    config.nkMissile,
    config.infra,
    config.infraFacilities,
    config.hazardTypes,
    config.cnPower,
    config.cnMilitary,
    config.jpPower,
    config.jpMilitary,
    config.onPick,
    config.sizeScale,
    fontScale.facility,
  ]);
}
