import { ConfigService } from "../configService/index.mjs";
import { apiMutate } from "../utilities/useAxiosMutate.mjs";
import { c } from "react-compiler-runtime";
import "react";
//#region src/hooks/crudForeignKeyData.js
/**
* Pure data-fetching helper extracted from useCrudActions so ActionWrapper and
* other entry-chunk consumers can use it without statically pulling in the
* heavy form-rendering JSX (DateTimeField → @date-io/date-fns → date-fns,
* FluentColorPicker → react-color, etc.) that the rest of useCrudActions
* needs.
*/
function useCrudForeignKeyData() {
	const $ = c(1);
	const getFKData = _temp2;
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = { getFKData };
		$[0] = t0;
	} else t0 = $[0];
	return t0;
}
async function _temp2(fkMethods, setForeignKeyData, enqueueSnackbar, displayToasts) {
	const fkData = [];
	const promises = [];
	const promiseDetails = [];
	fkMethods.forEach((method) => {
		if (method && method?.entity?.unityBaseGetAllMethod) {
			promiseDetails.push({
				url: ConfigService.integrationV1ApiUrl + `/apimethod/executeQueryWithParameters/${method?.entity?.unityBaseGetAllMethod?.apiMethodId}`,
				fieldName: method.fkName,
				name: method.entity.entityName
			});
			promises.push(apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${method?.entity?.unityBaseGetAllMethod?.apiMethodId}`, { method: "post" }, { data: {} }));
		} else if (displayToasts) enqueueSnackbar(`${method.entity.entityName}'s Get-All method needs to be promoted`, {
			variant: "error",
			anchorOrigin: {
				vertical: "top",
				horizontal: "center"
			}
		});
		else console.warn(`${method.entity.entityName}'s Get-All method needs to be promoted`);
	});
	Promise.all(promises).then((resp) => {
		resp.forEach((response) => {
			if (response.status === 200 && response?.data) {
				const respData = response.data.map(_temp);
				const promiseDetail = promiseDetails.find((p) => p.url === response?.config?.url);
				fkData.push({
					fieldName: promiseDetail.fieldName,
					name: promiseDetail.fieldName,
					data: respData
				});
			}
		});
		setForeignKeyData(fkData);
	});
}
function _temp(d) {
	return {
		id: d.id,
		name: d.name ?? d.id
	};
}
//#endregion
export { useCrudForeignKeyData };

//# sourceMappingURL=crudForeignKeyData.mjs.map