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

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

const dataFetch = async () => {
	const { data } = await api.get("/dockDoor/scanners");
	if (!data.success) {
		throw new Error(data.message ?? "Failed to load articles");
	}

	return data.data ?? [];
};
