import { useApiClient } from "./useApi.js";
import { c } from "react/compiler-runtime";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
function useWorkspace(n) {
	let i = c(10), { envKey: a, api: s } = useApiClient(), l;
	i[0] !== a || i[1] !== n ? (l = [
		"workspace",
		n,
		a
	], i[0] = a, i[1] = n, i[2] = l) : l = i[2];
	let u;
	i[3] !== s || i[4] !== n ? (u = () => {
		if (!s) throw Error("API not available");
		return s.ApiV1WorkspacesApi.workspaceControllerGetWorkspaceById({ id: n });
	}, i[3] = s, i[4] = n, i[5] = u) : u = i[5];
	let d = !!n, f;
	return i[6] !== l || i[7] !== u || i[8] !== d ? (f = {
		queryKey: l,
		queryFn: u,
		enabled: d,
		select: _temp
	}, i[6] = l, i[7] = u, i[8] = d, i[9] = f) : f = i[9], useQuery(f);
}
function _temp(e) {
	return e.data;
}
function useFilterWorkspaces(n, i, a, o, s, u) {
	let d = c(23), f = a === void 0 ? "id" : a, p = o === void 0 ? "DESC" : o, m = s === void 0 ? 0 : s, h = u === void 0 ? 10 : u, { envKey: g, api: _ } = useApiClient(), v = Object.keys(i).length > 0, y;
	d[0] !== i || d[1] !== v ? (y = v && { filter: JSON.stringify(i) }, d[0] = i, d[1] = v, d[2] = y) : y = d[2];
	let b;
	d[3] !== p || d[4] !== f ? (b = JSON.stringify([{
		field: f,
		order: p
	}]), d[3] = p, d[4] = f, d[5] = b) : b = d[5];
	let x;
	d[6] === n ? x = d[7] : (x = n && {
		search: n,
		searchColumns: JSON.stringify(["title"])
	}, d[6] = n, d[7] = x);
	let S;
	d[8] !== h || d[9] !== m || d[10] !== y || d[11] !== b || d[12] !== x ? (S = {
		...y,
		sortBy: b,
		page: m,
		limit: h,
		...x
	}, d[8] = h, d[9] = m, d[10] = y, d[11] = b, d[12] = x, d[13] = S) : S = d[13];
	let C = S, w;
	d[14] !== g || d[15] !== C ? (w = [
		"workspaces",
		g,
		C
	], d[14] = g, d[15] = C, d[16] = w) : w = d[16];
	let T;
	d[17] !== _ || d[18] !== C ? (T = () => {
		if (!_) throw Error("API not available");
		return _.ApiV1WorkspacesApi.workspaceControllerGetWorkspaces(C);
	}, d[17] = _, d[18] = C, d[19] = T) : T = d[19];
	let E;
	return d[20] !== w || d[21] !== T ? (E = {
		queryKey: w,
		queryFn: T,
		select: _temp2,
		enabled: !0
	}, d[20] = w, d[21] = T, d[22] = E) : E = d[22], useQuery(E);
}
function _temp2(e) {
	return e.data;
}
function useCreateWorkspace() {
	let r = c(8), { envKey: a, api: o } = useApiClient(), s = useQueryClient(), l;
	r[0] === o ? l = r[1] : (l = (e) => {
		if (!o) throw Error("API not available");
		return o.ApiV1WorkspacesApi.workspaceControllerCreateWorkspace(e);
	}, r[0] = o, r[1] = l);
	let u;
	r[2] !== a || r[3] !== s ? (u = () => {
		s.invalidateQueries({ queryKey: ["workspaces", a] });
	}, r[2] = a, r[3] = s, r[4] = u) : u = r[4];
	let d;
	return r[5] !== l || r[6] !== u ? (d = {
		mutationFn: l,
		onSuccess: u
	}, r[5] = l, r[6] = u, r[7] = d) : d = r[7], useMutation(d);
}
function useUpdateWorkspace() {
	let r = c(8), { envKey: a, api: o } = useApiClient(), s = useQueryClient(), l;
	r[0] === o ? l = r[1] : (l = (e) => {
		if (!o) throw Error("API not available");
		return o.ApiV1WorkspacesApi.workspaceControllerUpdateWorkspace(e);
	}, r[0] = o, r[1] = l);
	let u;
	r[2] !== a || r[3] !== s ? (u = (e, t) => {
		s.invalidateQueries({ queryKey: [
			"workspace",
			t.id,
			a
		] }), s.invalidateQueries({ queryKey: ["workspaces", a] });
	}, r[2] = a, r[3] = s, r[4] = u) : u = r[4];
	let d;
	return r[5] !== l || r[6] !== u ? (d = {
		mutationFn: l,
		onSuccess: u
	}, r[5] = l, r[6] = u, r[7] = d) : d = r[7], useMutation(d);
}
function useDeleteWorkspace() {
	let r = c(8), { envKey: a, api: o } = useApiClient(), s = useQueryClient(), l;
	r[0] === o ? l = r[1] : (l = (e) => {
		if (!o) throw Error("API not available");
		return o.ApiV1WorkspacesApi.workspaceControllerDeleteWorkspace({ id: e });
	}, r[0] = o, r[1] = l);
	let u;
	r[2] !== a || r[3] !== s ? (u = (e, t) => {
		s.removeQueries({ queryKey: [
			"workspace",
			t,
			a
		] }), s.invalidateQueries({ queryKey: ["workspaces", a] });
	}, r[2] = a, r[3] = s, r[4] = u) : u = r[4];
	let d;
	return r[5] !== l || r[6] !== u ? (d = {
		mutationFn: l,
		onSuccess: u
	}, r[5] = l, r[6] = u, r[7] = d) : d = r[7], useMutation(d);
}
function useSetFavouriteWorkspace() {
	let r = c(8), { envKey: a, api: o } = useApiClient(), s = useQueryClient(), l;
	r[0] === o ? l = r[1] : (l = (e) => {
		let { id: t, isFavourite: n } = e;
		if (!o) throw Error("API not available");
		return o.ApiV1WorkspacesApi.workspaceControllerSetFavourite({
			id: t,
			workspaceFavouriteDto: { isFavourite: n }
		});
	}, r[0] = o, r[1] = l);
	let u;
	r[2] !== a || r[3] !== s ? (u = () => {
		s.invalidateQueries({ queryKey: ["workspaces", a] });
	}, r[2] = a, r[3] = s, r[4] = u) : u = r[4];
	let d;
	return r[5] !== l || r[6] !== u ? (d = {
		mutationFn: l,
		onSuccess: u
	}, r[5] = l, r[6] = u, r[7] = d) : d = r[7], useMutation(d);
}
function useBatchDeleteWorkspaces() {
	let r = c(8), { envKey: a, api: o } = useApiClient(), s = useQueryClient(), l;
	r[0] === o ? l = r[1] : (l = (e) => {
		if (!o) throw Error("API not available");
		return o.ApiV1WorkspacesApi.workspaceControllerBatchDeleteWorkspaces({ workspaceControllerBatchDeleteWorkspacesRequest: { ids: e } });
	}, r[0] = o, r[1] = l);
	let u;
	r[2] !== a || r[3] !== s ? (u = () => {
		s.invalidateQueries({ queryKey: ["workspaces", a] });
	}, r[2] = a, r[3] = s, r[4] = u) : u = r[4];
	let d;
	return r[5] !== l || r[6] !== u ? (d = {
		mutationFn: l,
		onSuccess: u
	}, r[5] = l, r[6] = u, r[7] = d) : d = r[7], useMutation(d);
}
export { useBatchDeleteWorkspaces, useCreateWorkspace, useDeleteWorkspace, useFilterWorkspaces, useSetFavouriteWorkspace, useUpdateWorkspace, useWorkspace };
