import type { LayerProps } from 'react-map-gl/maplibre'
import type { PolygonLayerOptions } from '../types'

export function createPolygonLayer(
  id: string,
  sourceId: string,
  options: PolygonLayerOptions = {}
): LayerProps {
  const {
    fillColor = '#3b82f6',
    fillOpacity = 0.3,
    strokeColor = '#1d4ed8',
    strokeWidth = 2,
  } = options

  return {
    id,
    type: 'fill',
    source: sourceId,
    paint: {
      'fill-color': fillColor,
      'fill-opacity': fillOpacity,
      'fill-outline-color': strokeColor,
    },
  }
}

export function createPolygonOutlineLayer(
  id: string,
  sourceId: string,
  options: {
    color?: string
    width?: number
  } = {}
): LayerProps {
  const { color = '#1d4ed8', width = 2 } = options

  return {
    id,
    type: 'line',
    source: sourceId,
    paint: {
      'line-color': color,
      'line-width': width,
    },
  }
}

export function createHighlightLayer(
  id: string,
  sourceId: string,
  options: {
    fillColor?: string
    fillOpacity?: number
    strokeColor?: string
    strokeWidth?: number
  } = {}
): LayerProps {
  const {
    fillColor = '#fbbf24',
    fillOpacity = 0.5,
  } = options

  return {
    id,
    type: 'fill',
    source: sourceId,
    paint: {
      'fill-color': fillColor,
      'fill-opacity': fillOpacity,
    },
  }
}
