import axios from "axios";
import { create } from "zustand";

interface SettingState {
	settings: any[];
	fetchSettings: () => Promise<void>;
	setSettings: (settings: any[]) => void;
}
interface FetchModulesResponse {
	data: any[];
}

export const useSettingStore = create<SettingState>()((set) => ({
	settings: [],
	setSettings: (settings) => set({ settings }),
	fetchSettings: async () => {
		try {
			//const response = await axios.get<{data: Setting[]}>(`${process.env.NEXT_PUBLIC_URL}/api/settings/client`);
			const response = await axios.get(`/lst/api/system/settings`, {});
			const data: FetchModulesResponse = response.data; //await response.json();
			//console.log(data);
			set({ settings: data.data });
		} catch (error) {
			console.error("Failed to fetch settings:", error);
			set({ settings: [] });
		}
	},
}));
