interface TBase {
  name: string
  position: number[]
  icon?: string
}

const base = [
  {
    name: 'base-1',
    position: [92.0, 35.0, 0.0],
  },
  { name: 'base-2', position: [114.0, 30.0, 0.0] },
  { name: 'base-3', position: [104.0, 40.0, 0.0] },
  { name: 'base-4', position: [104.0, 30.0, 0.0] },
  { name: 'base-5', position: [114.0, 40.0, 0.0] },
]

const airport = [
  { name: 'airport-1', position: [104.0, 30.0, 0.0] },
  { name: 'airport-2', position: [114.0, 24.0, 0.0] },
  { name: 'airport-3', position: [114.0, 34.0, 0.0] },
]

const port = [
  { name: 'port-1', position: [119.0, 24.43, 0.0] },
  { name: 'port-2', position: [120.9, 27.02, 0.0] },
  { name: 'port-3', position: [120.18, 25.68, 0.0] },
]

const station = [
  { name: 'station-1', position: [119.18, 26.11, 0.0] },
  { name: 'station-2', position: [117.02, 24.11, 0.0] },
  { name: 'station-3', position: [114.26, 23.14, 0.0] },
]

const baseMap = new Map()
const airportMap = new Map()
const portMap = new Map()
const stationMap = new Map()

const dict = [
  {
    name: 'base',
    data: base,
    map: baseMap,
    icon: '/images/icons/base/base1.png',
  },
  {
    name: 'airport',
    data: airport,
    map: airportMap,
    icon: '/images/icons/base/airport1.png',
  },
  {
    name: 'port',
    data: port,
    map: portMap,
    icon: '/images/icons/base/port1.png',
  },
  {
    name: 'station',
    data: station,
    map: stationMap,
    icon: '/images/icons/base/station1.png',
  },
]
export const useBase = () => {
  const addBaseFacilities = () => {
    dict.forEach(({ map, data, icon }) => {
      data.forEach(item => {
        const entity = addEntity({ icon: icon, ...item })
        map.set(item.name, entity)
      })
    })
  }

  return {
    addBaseFacilities,
  }
}

function addEntity({ name, position, icon }: TBase) {
  const entity = viewer.entities.add({
    name: name,
    position: Cesium.Cartesian3.fromDegrees(...position),

    billboard: {
      image: icon,
      width: 30,
      height: 30,
      verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    },
  })
  return entity
}
