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

export function getSettings(token: string) {
    return queryOptions({
        queryKey: ["settings"],
        queryFn: () => fetch(token),
        enabled: !!token,
        staleTime: 1000,
        refetchOnWindowFocus: true,
    });
}

const fetch = async (token: string) => {
    const { data } = await axios.get("/api/server/settings", {
        headers: { Authorization: `Bearer ${token}` },
    });
    // if we are not localhost ignore the devDir setting.
    // const url: string = window.location.host.split(":")[0];
    // let settingsData = data.data;
    // if (url != "localhost") {
    //     settingsData.filter((n: any) => n.name === "devDir");
    // }
    return data.data;
};
