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

import { api } from "../apiHelper";

export function servers() {
	return queryOptions({
		queryKey: ["servers"],
		queryFn: () => fetch(),
		staleTime: 5000,
		refetchOnWindowFocus: true,
		placeholderData: keepPreviousData,
	});
}

const fetch = async () => {
	if (window.location.hostname === "localhost") {
		await new Promise((res) => setTimeout(res, 1500));
	}

	const { data } = await api.get("/servers");

	return data.data;
};
