import type { BasemapKey, BasemapType } from './types'

/**
 * Google Maps basemap types.
 */
export const GmapsBasemap = {
  roadmap: 'roadmap',
  satellite: 'satellite',
  hybrid: 'hybrid',
} as const

/**
 * CARTO basemap names.
 */
export const CartoBasemaps = {
  darkMatter: 'darkMatter',
  positron: 'positron',
  voyager: 'voyager',
} as const

export const CartoBasemapURL = {
  [CartoBasemaps.positron]:
    'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json',
  [CartoBasemaps.voyager]:
    'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json',
  [CartoBasemaps.darkMatter]:
    'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json',
}

export const MapsTypes = {
  maplibre: 'maplibre',
  googleMaps: 'google-maps',
}

/**
 * Human-readable labels for every basemap key. Useful for building basemap
 * pickers without re-declaring labels per consumer.
 */
export const BASEMAP_LABELS: Record<BasemapKey, string> = {
  [CartoBasemaps.positron]: 'Positron',
  [CartoBasemaps.voyager]: 'Voyager',
  [CartoBasemaps.darkMatter]: 'Dark Matter',
  [GmapsBasemap.roadmap]: 'Roadmap',
  [GmapsBasemap.satellite]: 'Satellite',
  [GmapsBasemap.hybrid]: 'Hybrid',
}

export const MAPS_BASEMAP: Record<
  BasemapKey,
  {
    url?: string
    dark?: boolean
    type: BasemapType
  }
> = {
  [CartoBasemaps.positron]: {
    url: CartoBasemapURL[CartoBasemaps.positron],
    type: MapsTypes.maplibre,
  },
  [CartoBasemaps.voyager]: {
    url: CartoBasemapURL[CartoBasemaps.voyager],
    type: MapsTypes.maplibre,
  },
  [CartoBasemaps.darkMatter]: {
    url: CartoBasemapURL[CartoBasemaps.darkMatter],
    type: MapsTypes.maplibre,
    dark: true,
  },
  [GmapsBasemap.roadmap]: {
    type: MapsTypes.googleMaps,
  },
  [GmapsBasemap.satellite]: {
    type: MapsTypes.googleMaps,
  },
  [GmapsBasemap.hybrid]: {
    type: MapsTypes.googleMaps,
  },
}
