import { computed } from "vue"

export function useClassPolygon(allPolygon) {
  const classPoiList = computed(() => {
    return allPolygon.value.filter(i => i?.class?.length).reduce((result, item) => {
      item.class.forEach((classId) => {
        if (!result?.[classId]) {
          result[classId] = []
        }
        result[classId].push(item)
      })
      return result
    }, {})
  })
  const classDict = {
    "327": {
      "parentId": 0,
      "name": "摄像头",
      "sortNo": 0,
      "customerUserId": 0,
      "id": 327
    },
    "328": {
      "parentId": 0,
      "name": "烟感器",
      "sortNo": 0,
      "customerUserId": 0,
      "id": 328
    },
    "329": {
      "parentId": 0,
      "name": "温湿度感应器",
      "sortNo": 0,
      "customerUserId": 0,
      "id": 329
    },
    "330": {
      "parentId": 0,
      "name": "立式空调",
      "sortNo": 0,
      "customerUserId": 0,
      "id": 330
    },
    "331": {
      "parentId": 0,
      "name": "除湿机",
      "sortNo": 0,
      "customerUserId": 0,
      "id": 331
    }
  }

  return {
    classPoiList,
    classDict,
  }
}
