import { fetcher } from "../fetcher.mjs";
import { built_default } from "../config/dist/esm/built.mjs";

//#region ../chokidar/dist/esm/api/dist/esm/getIntlayerAPI/dictionary.mjs
const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
	const backendURL = intlayerConfig?.editor?.backendURL ?? built_default?.editor?.backendURL;
	if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
	const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;
	/**
	* Retrieves a list of dictionaries based on filters and pagination.
	* @param filters - Filters and pagination options.
	*/
	const getDictionaries = async (filters, otherOptions = {}) => await fetcher(PROJECT_API_ROUTE, authAPIOptions, otherOptions, {
		cache: "no-store",
		params: filters
	});
	/**
	* Retrieves a list of dictionary keys related to the project.
	*/
	const getDictionariesKeys = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/keys`, authAPIOptions, otherOptions, { cache: "no-store" });
	/**
	* Retrieves a list of dictionary keys related to the project.
	*/
	const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/update`, authAPIOptions, otherOptions, { cache: "no-store" });
	/**
	* Retrieves a dictionary by its key and version.
	* @param dictionaryKey - Dictionary key.
	* @param version - Dictionary version of content.
	*/
	const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${dictionaryKey}`, authAPIOptions, otherOptions, { params: version ? { version: version.toString() } : void 0 });
	/**
	* Adds a new dictionary to the database.
	* @param dictionary - Dictionary data.
	*/
	const addDictionary = async (body, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
		method: "POST",
		body
	});
	const pushDictionaries = async (dictionaries, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
		method: "PATCH",
		body: { dictionaries }
	});
	/**
	* Updates an existing dictionary in the database.
	* @param dictionary - Updated dictionary data.
	*/
	const updateDictionary = async (dictionary, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${dictionary.id}`, authAPIOptions, otherOptions, {
		method: "PUT",
		body: dictionary
	});
	/**
	* Deletes a dictionary from the database by its ID.
	* @param id - Dictionary ID.
	*/
	const deleteDictionary = async (id, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${id}`, authAPIOptions, otherOptions, { method: "DELETE" });
	return {
		getDictionaries,
		getDictionariesKeys,
		getDictionariesUpdateTimestamp,
		getDictionary,
		pushDictionaries,
		addDictionary,
		updateDictionary,
		deleteDictionary
	};
};

//#endregion
export { getDictionaryAPI };
//# sourceMappingURL=dictionary.mjs.map