import Popup from '@/views/Earth/components/Popup'

const popupMap: Map<string | number, any> = new Map()

export const useWeatherPopup = () => {
  return {
    popupMap,
    createPopup,
  }
}

function createPopup(id: string | number, position: Cesium.Cartesian3, data) {
  if (popupMap.has(id)) {
    return
  }
  const opts = {
    viewer,
    position,
    title: '天气信息',
    slotContent: generateContent(data),
    // slotFooter: generateFooter(data),
    closeEvent: function () {
      if (popupMap.has(id)) {
        popupMap.get(id).windowClose()
        popupMap.delete(id)
      }
    },
  }
  const popup = new Popup(opts)
  popupMap.set(id, popup)
}

function generateContent(data: TBaseNode) {
  return h(
    'div',
    {},
    Object.keys(data).map(key => h('div', {}, `${key}：${data[key]}`))
  )
}
