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

export function getOcpLogs(hours: string) {
	return queryOptions({
		queryKey: ["ocpLogs"],
		queryFn: () => fetchSettings(hours),

		staleTime: 1000,
		refetchInterval: 2 * 1000,
		refetchOnWindowFocus: true,
	});
}

const fetchSettings = async (hours: string) => {
	const { data } = await axios.get(
		`/lst/old/api/logger/logs?service=ocp&service=rfid&service=dyco&level=error&level=warn&hours=${hours}`,
	);
	// if we are not localhost ignore the devDir setting.
	//const url: string = window.location.host.split(":")[0];
	return data.data ?? [];
};
