import Drawer from '@cesium-extends/drawer'

export type TType = 'RECTANGLE' | 'POLYGON' | 'POLYLINE' | 'POINT' | 'CIRCLE'

export const useDrawer = () => {
  const drawer = new Drawer(viewer, {
    tips: { init: '点击开始绘制', start: '左键点击添加点，双击结束', end: '' },
  })
  // 开始绘制
  const drawRectangle = (
    fn: (
      entity: typeof Cesium.Entity,
      positions: (typeof Cesium.Cartesian3)[]
    ) => void
  ) => {
    drawer.start({
      once: true,
      type: 'RECTANGLE',
      finalOptions: {
        material: new Cesium.ColorMaterialProperty(
          new Cesium.Color.fromCssColorString('#0f02')
        ),
      },
      onEnd: fn,
    })
  }

  const drawAreaFromType = (
    type: TType,
    fn: (
      entity: typeof Cesium.Entity,
      positions: (typeof Cesium.Cartesian3)[]
    ) => void
  ) => {
    drawer.start({
      once: true,
      type,
      finalOptions: {
        material: new Cesium.ColorMaterialProperty(
          new Cesium.Color.fromCssColorString('#0f02')
        ),
      },
      onEnd: fn,
    })
  }

  return {
    drawRectangle,
    drawAreaFromType,
  }
}
