import { getSecretsCacheKey as e } from "./query-keys.js";
import { useApiClient as t } from "./useApi.js";
import { useMutation as n, useQuery as r, useQueryClient as i } from "@tanstack/react-query";
//#region src/hooks/useSecrets.ts
function a(n) {
	let { envKey: i, api: a } = t();
	return r({
		queryKey: e(i, n),
		queryFn: () => a.secrets.getByWorkspaceId({ workspaceId: n }),
		enabled: !!n
	});
}
function o() {
	let { envKey: r, api: a } = t(), o = i();
	return n({
		mutationFn: (e) => a.secrets.create(e),
		onSuccess: (t, n) => {
			o.invalidateQueries({ queryKey: e(r, n.workspaceId) });
		}
	});
}
function s() {
	let { envKey: r, api: a } = t(), o = i();
	return n({
		mutationFn: (e) => a.secrets.update(e),
		onSuccess: (t, n) => {
			o.invalidateQueries({ queryKey: e(r, n.workspaceId) });
		}
	});
}
function c() {
	let { envKey: r, api: a } = t(), o = i();
	return n({
		mutationFn: (e) => a.secrets.upsert(e),
		onSuccess: (t, n) => {
			o.invalidateQueries({ queryKey: e(r, n.workspaceId) });
		}
	});
}
function l() {
	let { envKey: r, api: a } = t(), o = i();
	return n({
		mutationFn: (e) => a.secrets.delete(e),
		onSuccess: (t, n) => {
			o.invalidateQueries({ queryKey: e(r, n.workspaceId) });
		}
	});
}
//#endregion
export { o as useCreateSecret, l as useDeleteSecret, s as useUpdateSecret, c as useUpsertSecret, a as useWorkspaceSecrets };
