import { queryOptions } from "@tanstack/react-query";
import axios from "axios";

export function getMachineConnected(siloCon: any) {
	return queryOptions({
		queryKey: [`siloConnectionAttached-${siloCon.siloID}`],
		queryFn: () => fetchStockSilo(siloCon),
		//enabled:
		//staleTime: 1000,
		//refetchInterval: 60 * 1000,
		refetchOnWindowFocus: true,
	});
}

const fetchStockSilo = async (siloCon: any) => {
	const { data } = await axios.post(`/lst/old/api/logistics/siloconnection`, {
		siloID: siloCon.siloID,
		connectionType: siloCon.connectionType,
	});
	// if we are not localhost ignore the devDir setting.
	//const url: string = window.location.host.split(":")[0];
	return data.data ?? [];
};
