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

export function getSubModules(token: string) {
    return queryOptions({
        queryKey: ["submodules"],
        queryFn: () => fetchSettings(token),
        enabled: !!token,
        //staleTime: 1000,
        refetchOnWindowFocus: true,
    });
}

const fetchSettings = async (token: string) => {
    const { data } = await axios.get("/api/server/submodules", {
        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 settingsData;
};
