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
}

// Local-only orthophoto entry for the GPS-Denied upload list. There is no
// backend endpoint for orthophoto upload yet, so this lives entirely in
// component state (see GpsDeniedPanel / FlightsPage).
export interface OrthoPhoto {
  id: string
  name: string
  lat: number
  lon: 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

// AZ-498 — single self-hosted satellite tile URL. The previous classic/satellite
// pair (OSM + Esri) was retired so the SPA only consumes the suite's own
// satellite-provider service. Production builds MUST set VITE_SATELLITE_TILE_URL
// to the same-origin nginx path (e.g. `/tiles/{z}/{x}/{y}`); the dev default
// targets the satellite-provider container on its conventional dev port.
//
// Read via a function (mirrors `getOwmBaseUrl` in flightPlanUtils.ts) so tests
// can stub `import.meta.env` per-case without module-reload tricks.
export const DEFAULT_SATELLITE_TILE_URL = 'http://localhost:5100/tiles/{z}/{x}/{y}'

export function getTileUrl(): string {
  const raw = import.meta.env.VITE_SATELLITE_TILE_URL
  if (!raw) return DEFAULT_SATELLITE_TILE_URL
  return raw.replace(/\/+$/, '')
}
