'use client';


import { useAuth } from "./useAuth/useAuth.mjs";
import { useIntlayerAuth, useIntlayerOAuth } from "./useIntlayerAPI.mjs";
import { useConfiguration } from "@intlayer/editor-react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

//#region src/hooks/reactQuery.ts
/**
* Hook to enable authentication
*/
const useAuthEnable = ({ requireUser, requireProject, requireOrganization }) => {
	const { oAuth2AccessToken, session } = useAuth({ intlayerConfiguration: useConfiguration() });
	const user = session ? session.user : oAuth2AccessToken?.user;
	const organization = session ? session.organization : oAuth2AccessToken?.organization;
	const project = session ? session.project : oAuth2AccessToken?.project;
	return { enable: (requireUser ? Boolean(user) : true) && (requireProject ? Boolean(project) : true) && (requireOrganization ? Boolean(organization) : true) };
};
const useAppQuery = (options) => {
	const { requireUser, requireProject, requireOrganization,...rest } = options;
	const { enable } = useAuthEnable({
		requireUser,
		requireProject,
		requireOrganization
	});
	return useQuery({
		enabled: rest?.enabled === false ? false : enable,
		...rest
	});
};
/**
* Auth
*/
const useLogin = () => {
	const intlayerAuth = useIntlayerAuth();
	const queryClient = useQueryClient();
	return useMutation({
		mutationKey: ["login"],
		mutationFn: (args) => intlayerAuth.signInEmail(args),
		onSuccess: (data) => {
			const session = queryClient.getQueryData(["session"]);
			if (session && data.data?.user) queryClient.setQueryData(["session"], {
				...session,
				user: data.data.user
			});
		}
	});
};
const useGetVerifyEmailStatus = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["getVerifyEmailStatus"],
		mutationFn: (args) => intlayerAuth.verifyEmailSession(...args)
	});
};
const useRegister = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["register"],
		mutationFn: (args) => intlayerAuth.signUpEmail(args),
		meta: { resetQueries: [["session"]] }
	});
};
const useLogout = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["logout"],
		mutationFn: () => intlayerAuth.signOut(),
		meta: { resetQueries: [
			["session"],
			["users"],
			["organizations"],
			["projects"],
			["dictionaries"],
			["tags"]
		] }
	});
};
const useChangePassword = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["changePassword"],
		mutationFn: (args) => intlayerAuth.changePasswordSession(...args)
	});
};
const useAskResetPassword = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["askResetPassword"],
		mutationFn: (args) => intlayerAuth.requestPasswordResetSession(args)
	});
};
const useResetPassword = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["resetPassword"],
		mutationFn: (args) => intlayerAuth.resetPassword(args)
	});
};
const useVerifyEmail = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["verifyEmail"],
		mutationFn: (args) => intlayerAuth.verifyEmailSession(args)
	});
};
const useGetUserByAccount = () => {
	const intlayerAuth = useIntlayerAuth();
	return useMutation({
		mutationKey: ["user"],
		mutationFn: (args) => intlayerAuth.accountInfo(args)
	});
};
/**
* User
*/
const useGetUsers = (filters, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["users", filters],
		queryFn: () => intlayerOAuth.user.getUsers(filters),
		requireUser: true,
		...options
	});
};
const useGetUserById = (userId) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["users", userId],
		queryFn: () => intlayerOAuth.user.getUserById(userId),
		requireUser: true
	});
};
const useCreateUser = () => {
	const intlayerAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["users"],
		mutationFn: (args) => intlayerAuth.user.createUser(args)
	});
};
const useUpdateUser = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["users"],
		mutationFn: (args) => intlayerOAuth.user.updateUser(args)
	});
};
const useDeleteUser = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["users"],
		mutationFn: (args) => intlayerOAuth.user.deleteUser(args),
		meta: { invalidateQueries: [["users"]] }
	});
};
/**
* Organization
*/
const useGetOrganizations = (filters) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["organizations", filters],
		queryFn: ({ signal }) => intlayerOAuth.organization.getOrganizations(filters, { signal }),
		requireUser: true
	});
};
const useAddOrganization = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["organizations"],
		mutationFn: (args) => intlayerOAuth.organization.addOrganization(args)
	});
};
const useUpdateOrganization = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["organizations"],
		mutationFn: (args) => intlayerOAuth.organization.updateOrganization(args)
	});
};
const useUpdateOrganizationMembers = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["organizations"],
		mutationFn: (args) => intlayerOAuth.organization.updateOrganizationMembers(args),
		meta: { invalidateQueries: [["organizations"], ["users"]] }
	});
};
const useUpdateOrganizationMembersById = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["organizations"],
		mutationFn: ({ organizationId,...body }) => intlayerOAuth.organization.updateOrganizationMembersById(organizationId, body),
		meta: { invalidateQueries: [["organizations"], ["users"]] }
	});
};
const useAddOrganizationMember = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["organizations"],
		mutationFn: (args) => intlayerOAuth.organization.addOrganizationMember(args),
		meta: { invalidateQueries: [["organizations"]] }
	});
};
const useDeleteOrganization = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["organizations"],
		mutationFn: () => intlayerOAuth.organization.deleteOrganization(),
		meta: { invalidateQueries: [["organizations"]] }
	});
};
const useSelectOrganization = () => {
	const intlayerOAuth = useIntlayerOAuth();
	const queryClient = useQueryClient();
	return useMutation({
		mutationKey: ["session-organizations"],
		mutationFn: (args) => intlayerOAuth.organization.selectOrganization(args),
		meta: { invalidateQueries: [
			["organizations"],
			["projects"],
			["dictionaries"],
			["tags"],
			["subscription"],
			["users"]
		] },
		onSuccess: (data) => {
			const session = queryClient.getQueryData(["session"]);
			if (session) queryClient.setQueryData(["session"], {
				...session,
				organization: data.data
			});
		}
	});
};
const useUnselectOrganization = () => {
	const intlayerOAuth = useIntlayerOAuth();
	const queryClient = useQueryClient();
	return useMutation({
		mutationKey: ["session-organizations"],
		mutationFn: () => intlayerOAuth.organization.unselectOrganization(),
		meta: { resetQueries: [
			["organizations"],
			["projects"],
			["dictionaries"],
			["tags"],
			["subscription"],
			["users"]
		] },
		onSuccess: () => {
			const session = queryClient.getQueryData(["session"]);
			if (session) queryClient.setQueryData(["session"], {
				...session,
				organization: null,
				project: null
			});
		}
	});
};
/**
* Project
*/
const useGetProjects = (filters, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["projects", filters],
		queryFn: ({ signal }) => intlayerOAuth.project.getProjects(filters, { signal }),
		requireUser: true,
		requireOrganization: true,
		...options
	});
};
const useAddProject = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: (args) => intlayerOAuth.project.addProject(args),
		meta: { invalidateQueries: [["projects"]] }
	});
};
const useUpdateProject = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: (args) => intlayerOAuth.project.updateProject(args),
		meta: { invalidateQueries: [["projects"]] }
	});
};
const useUpdateProjectMembers = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: (args) => intlayerOAuth.project.updateProjectMembers(args),
		meta: { invalidateQueries: [["projects"]] }
	});
};
const useDeleteProject = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: () => intlayerOAuth.project.deleteProject(),
		meta: { invalidateQueries: [["projects"]] }
	});
};
const useSelectProject = () => {
	const intlayerOAuth = useIntlayerOAuth();
	const queryClient = useQueryClient();
	return useMutation({
		mutationKey: ["session-projects"],
		mutationFn: (args) => intlayerOAuth.project.selectProject(args),
		meta: { invalidateQueries: [
			["projects"],
			["dictionaries"],
			["tags"],
			["subscription"],
			["users"]
		] },
		onSuccess: (data) => {
			const session = queryClient.getQueryData(["session"]);
			if (session) queryClient.setQueryData(["session"], {
				...session,
				project: data.data
			});
		}
	});
};
const useUnselectProject = () => {
	const intlayerOAuth = useIntlayerOAuth();
	const queryClient = useQueryClient();
	return useMutation({
		mutationKey: ["session-projects"],
		mutationFn: () => intlayerOAuth.project.unselectProject(),
		meta: { resetQueries: [
			["projects"],
			["dictionaries"],
			["tags"],
			["subscription"],
			["users"]
		] },
		onSuccess: () => {
			const session = queryClient.getQueryData(["session"]);
			if (session) queryClient.setQueryData(["session"], {
				...session,
				project: null
			});
		}
	});
};
const useAddNewAccessKey = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: (args) => intlayerOAuth.project.addNewAccessKey(args),
		meta: { invalidateQueries: [["projects"]] }
	});
};
const useDeleteAccessKey = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: (args) => intlayerOAuth.project.deleteAccessKey(args),
		meta: { invalidateQueries: [["projects"]] }
	});
};
const useRefreshAccessKey = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["projects"],
		mutationFn: (args) => intlayerOAuth.project.refreshAccessKey(args),
		meta: { invalidateQueries: [["projects"]] }
	});
};
/**
* Dictionary
*/
const useGetDictionaries = (filters, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["dictionaries", filters],
		queryFn: ({ signal }) => intlayerOAuth.dictionary.getDictionaries(filters, { signal }),
		requireUser: true,
		requireOrganization: true,
		requireProject: true,
		...options
	});
};
const useGetDictionariesKeys = (options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["dictionariesKeys"],
		queryFn: () => intlayerOAuth.dictionary.getDictionariesKeys(),
		requireUser: true,
		requireOrganization: true,
		requireProject: true,
		...options
	});
};
const useGetDictionary = (dictionaryKey, version, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["dictionary", dictionaryKey],
		queryFn: ({ signal }) => intlayerOAuth.dictionary.getDictionary(dictionaryKey, version, { signal }),
		requireUser: true,
		requireOrganization: true,
		requireProject: true,
		...options
	});
};
const useAddDictionary = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["dictionaries"],
		mutationFn: (args) => intlayerOAuth.dictionary.addDictionary(args),
		meta: { invalidateQueries: [["dictionaries"], ["dictionariesKeys"]] }
	});
};
const usePushDictionaries = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["dictionaries"],
		mutationFn: (args) => intlayerOAuth.dictionary.pushDictionaries(args),
		meta: { invalidateQueries: [["dictionaries"], ["dictionariesKeys"]] }
	});
};
const useUpdateDictionary = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["dictionaries"],
		mutationFn: (args) => intlayerOAuth.dictionary.updateDictionary(args),
		meta: { invalidateQueries: [["dictionaries"], ["dictionariesKeys"]] }
	});
};
const useDeleteDictionary = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["dictionaries"],
		mutationFn: (args) => intlayerOAuth.dictionary.deleteDictionary(args),
		meta: { invalidateQueries: [["dictionaries"], ["dictionariesKeys"]] }
	});
};
/**
* Tag
*/
const useGetTags = (filters, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["tags", filters],
		queryFn: ({ signal }) => intlayerOAuth.tag.getTags(filters, { signal }),
		requireUser: true,
		requireOrganization: true,
		requireProject: true,
		...options
	});
};
const useAddTag = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["tags"],
		mutationFn: (args) => intlayerOAuth.tag.addTag(args),
		meta: { invalidateQueries: [["tags"]] }
	});
};
const useUpdateTag = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["tags"],
		mutationFn: (v) => intlayerOAuth.tag.updateTag(v.tagId, v.tag),
		meta: { invalidateQueries: [["tags"]] }
	});
};
const useDeleteTag = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["tags"],
		mutationFn: (args) => intlayerOAuth.tag.deleteTag(args),
		meta: { invalidateQueries: [["tags"]] }
	});
};
/**
* Stripe
*/
const useGetPricing = (body, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useQuery({
		queryKey: ["pricing", body],
		queryFn: ({ signal }) => intlayerOAuth.stripe.getPricing(body, { signal }),
		...options
	});
};
const useGetSubscription = (body, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["subscription", body],
		queryFn: ({ signal }) => intlayerOAuth.stripe.getSubscription(body, { signal }),
		requireUser: true,
		requireOrganization: true,
		...options
	});
};
const useCancelSubscription = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["subscription"],
		mutationFn: () => intlayerOAuth.stripe.cancelSubscription(),
		meta: { invalidateQueries: [["session"], ["subscription"]] }
	});
};
/**
* AI
*/
const useTranslateJSONDeclaration = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["ai-translateJSON"],
		mutationFn: (args) => intlayerOAuth.ai.translateJSON(args)
	});
};
const useAuditContentDeclaration = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["ai-auditContentDeclaration"],
		mutationFn: (args) => intlayerOAuth.ai.auditContentDeclaration(args)
	});
};
const useAuditContentDeclarationMetadata = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["ai-auditContentDeclarationMetadata"],
		mutationFn: (args) => intlayerOAuth.ai.auditContentDeclarationMetadata(args)
	});
};
const useAuditContentDeclarationField = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["ai-auditContentDeclarationField"],
		mutationFn: (args) => intlayerOAuth.ai.auditContentDeclarationField(args)
	});
};
const useAuditTag = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["ai-auditTag"],
		mutationFn: (args) => intlayerOAuth.ai.auditTag(args)
	});
};
const useAskDocQuestion = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: [],
		mutationFn: (args) => intlayerOAuth.ai.askDocQuestion(args)
	});
};
const useAutocomplete = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["ai-autocomplete"],
		mutationFn: (args) => intlayerOAuth.ai.autocomplete(args)
	});
};
/**
* Discussions
*/
const useGetDiscussions = (params, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["discussions", params],
		queryFn: ({ signal }) => intlayerOAuth.ai.getDiscussions(params, {
			signal,
			cache: "no-store"
		}),
		requireUser: true,
		...options
	});
};
const useGetDiscussionsData = (params, options) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useAppQuery({
		queryKey: ["discussions-data", params],
		queryFn: ({ signal }) => intlayerOAuth.ai.getDiscussions({
			includeMessages: "false",
			...params ?? {}
		}, {
			signal,
			cache: "no-store"
		}),
		requireUser: true,
		...options
	});
};
/**
* Search
*/
const useSearchDoc = (params) => {
	const intlayerOAuth = useIntlayerOAuth();
	return useQuery({
		queryKey: ["search", params],
		queryFn: () => intlayerOAuth.search.searchDoc(params),
		enabled: (params?.input?.length ?? 0) > 3
	});
};
/**
* Newsletter
*/
const useSubscribeToNewsletter = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["newsletter"],
		mutationFn: (args) => intlayerOAuth.newsletter.subscribeToNewsletter(args)
	});
};
const useUnsubscribeFromNewsletter = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["newsletter"],
		mutationFn: (args) => intlayerOAuth.newsletter.unsubscribeFromNewsletter(args)
	});
};
const useGetNewsletterStatus = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["newsletter"],
		mutationFn: () => intlayerOAuth.newsletter.getNewsletterStatus()
	});
};
/**
* Editor
*/
const useGetEditorDictionaries = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useQuery({
		queryKey: ["editor", "dictionaries"],
		queryFn: () => intlayerOAuth.editor.getDictionaries()
	});
};
const useWriteDictionary = () => {
	const intlayerOAuth = useIntlayerOAuth();
	return useMutation({
		mutationKey: ["editor", "dictionaries"],
		mutationFn: (args) => intlayerOAuth.editor.writeDictionary(args)
	});
};

//#endregion
export { useAddDictionary, useAddNewAccessKey, useAddOrganization, useAddOrganizationMember, useAddProject, useAddTag, useAppQuery, useAskDocQuestion, useAskResetPassword, useAuditContentDeclaration, useAuditContentDeclarationField, useAuditContentDeclarationMetadata, useAuditTag, useAutocomplete, useCancelSubscription, useChangePassword, useCreateUser, useDeleteAccessKey, useDeleteDictionary, useDeleteOrganization, useDeleteProject, useDeleteTag, useDeleteUser, useGetDictionaries, useGetDictionariesKeys, useGetDictionary, useGetDiscussions, useGetDiscussionsData, useGetEditorDictionaries, useGetNewsletterStatus, useGetOrganizations, useGetPricing, useGetProjects, useGetSubscription, useGetTags, useGetUserByAccount, useGetUserById, useGetUsers, useGetVerifyEmailStatus, useLogin, useLogout, usePushDictionaries, useQueryClient, useRefreshAccessKey, useRegister, useResetPassword, useSearchDoc, useSelectOrganization, useSelectProject, useSubscribeToNewsletter, useTranslateJSONDeclaration, useUnselectOrganization, useUnselectProject, useUnsubscribeFromNewsletter, useUpdateDictionary, useUpdateOrganization, useUpdateOrganizationMembers, useUpdateOrganizationMembersById, useUpdateProject, useUpdateProjectMembers, useUpdateTag, useUpdateUser, useVerifyEmail, useWriteDictionary };
//# sourceMappingURL=reactQuery.mjs.map