import { ref, computed } from "vue";
import instance from "@/util/request";
import { GET_DEVICELIST_API } from "@/constant";

export default function useGetDevice() {
  const deviceList = ref(null);
  //取得設備列表
  const getDeviceList = async ({
    building_tag,
    main_system_tag,
    sub_system_tag,
    floor_tag,
  }) => {
    const res = await instance.post(GET_DEVICELIST_API, {
      building_tag,
      floor_tag,
      sub_system_tag,
    });

    let devices = []
    res.data.data.forEach(({device_list})=>{
      devices = [...devices, ...device_list]
    })
    deviceList.value = devices;
  };

  return {
    deviceList,
    getDeviceList,
  };
}
