import useSelectedFloor from "@/hooks/useSelectedFloor";
import { computed, inject, watch } from "vue";

function useSystemShowData() {
  const { data } = inject("system_deviceList");
  const { selectedFloor } = useSelectedFloor();

  const showData = computed(() =>
    selectedFloor.value?.key === "main"
      ? data.value
      : data.value.filter(
          ({ floor_guid }) => floor_guid === selectedFloor.value?.key
        ) || []
  );

  const flatSubData = computed(() => {
    let items = [];
    showData.value.forEach((device) => {
      items = [...items, ...device.device_list];
    });
    return items;
  });

  return { showData, flatSubData };
}

export default useSystemShowData;
