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

export function getScanUsers() {
	return queryOptions({
		queryKey: ["getScanUsers"],
		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 axios.get("/lst/api/mobile/auth/user", {
		withCredentials: true,
		timeout: 5000,
	});

	return data.data;
};
