// utils/setupDevices.js
import { setSelectedDevice, clearSelectedDevice } from "../redux/slices/selectedDeviceSlice";

export const setupDevices = async (map, deviceMarkers, dispatch) => {
  for (const marker of deviceMarkers) {
    marker.on("mouseover", function () {
      console.log("✅ Gerät ausgewählt:", marker);
      dispatch(setSelectedDevice(marker.options)); // Gerät in Redux speichern
    });

    marker.on("mouseout", function () {
      console.log("❌ Gerät abgewählt");
      dispatch(clearSelectedDevice()); // Gerät aus Redux entfernen
    });

    marker.addTo(map);
  }
};
