import type L from 'leaflet'

export interface FlightPoint {
  id: string
  position: { lat: number; lng: number }
  altitude: number
  meta: string[]
}

export interface CalculatedPointInfo {
  bat: number
  time: number
}

export interface MapRectangle {
  id: string
  layer?: L.Layer
  bounds: L.LatLngBounds
  color: 'red' | 'green'
}

export interface AircraftParams {
  type: string
  downang: number
  upang: number
  weight: number
  speed: number
  frontalArea: number
  dragCoefficient: number
  batteryCapacity: number
  thrustWatts: { thrust: number; watts: number }[]
  propellerEfficiency: number
}

export interface WindParams {
  direction: number
  speed: number
}

export interface MovingPointInfo {
  x: number
  y: number
  latlng: L.LatLng
}

export type ActionMode = 'points' | 'workArea' | 'prohibitedArea'

export const PURPOSES = [
  { value: 'tank', label: 'options.tank' },
  { value: 'artillery', label: 'options.artillery' },
] as const

export const COORDINATE_PRECISION = 8

const trimTrailingSlash = (s: string) => s.replace(/\/+$/, '')

export const TILE_URLS = {
  classic:
    trimTrailingSlash(import.meta.env.VITE_OSM_TILE_URL ?? '') ||
    'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  satellite:
    trimTrailingSlash(import.meta.env.VITE_ESRI_TILE_URL ?? '') ||
    'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
} as const
