import { h } from 'vue'
import { NButton } from 'naive-ui'
import Popup from '@/views/Earth/components/Popup'

const popupMap: Map<string | number, any> = new Map()
export const useHangjingPopup = () => {
  return {
    popupMap,
    createPopup,
  }
}

function createPopup(
  id: string | number,
  position: Cesium.Cartesian3,
  hjData: Record<string, any>
) {
  if (popupMap.has(id)) {
    return
  }
  const opts = {
    viewer,
    position,
    title: hjData.title,
    // content: 'ceshi',
    slotContent: h(
      'div',
      { class: '' },
      Object.keys(hjData).map(key => {
        return h('div', { class: 'truncate' }, `${key}: ${hjData[key]}`)
      })
    ),
    closeEvent: function () {
      if (popupMap.has(id)) {
        popupMap.get(id).windowClose()
        popupMap.delete(id)
      }
    },
  }
  const popup = new Popup(opts)
  popupMap.set(id, popup)
}
