/**
 * 히트맵 레이어 (deck.gl HeatmapLayer)
 */
import { HeatmapLayer } from 'deck.gl';
import type { HeatPoint } from '../types';

interface HeatmapOptions {
  radiusPixels?: number;
  intensity?: number;
  threshold?: number;
}

/** HeatmapLayer 생성: points는 [lat, lng, intensity][] */
export function createHeatmapLayer(
  id: string,
  points: HeatPoint[],
  options: HeatmapOptions = {},
) {
  const { radiusPixels = 30, intensity = 1, threshold = 0.05 } = options;

  return new HeatmapLayer({
    id,
    data: points.map(([lat, lng, weight]) => ({ position: [lng, lat], weight })),
    getPosition: (d: { position: [number, number] }) => d.position,
    getWeight: (d: { weight: number }) => d.weight,
    radiusPixels,
    intensity,
    threshold,
    colorRange: [
      [30, 64, 175],   // #1e40af blue
      [59, 130, 246],   // #3b82f6
      [34, 197, 94],    // #22c55e green
      [234, 179, 8],    // #eab308 yellow
      [249, 115, 22],   // #f97316 orange
      [239, 68, 68],    // #ef4444 red
    ],
  });
}
