require("./chunk-9hOWP6kD.cjs");
const require_mysite_api_context = require("./mysite-api-context-SWweFE49.cjs");
let _tanstack_react_query = require("@tanstack/react-query");
//#region ../../mysite/ui/src/portal/hooks/use-mysite-portal.ts
const PORTAL_MYSITE_KEYS = {
	profile: () => ["portal-mysite", "profile"],
	links: () => ["portal-mysite", "links"],
	favorites: () => ["portal-mysite", "favorites"],
	themes: () => ["portal-mysite", "themes"]
};
function usePortalMySiteProfile() {
	const api = require_mysite_api_context.useMySiteApi();
	return (0, _tanstack_react_query.useQuery)({
		queryKey: PORTAL_MYSITE_KEYS.profile(),
		queryFn: () => api.fetchProfile()
	});
}
function usePortalUpdateSettings(options) {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: (body) => api.updateSettings(body),
		onSuccess: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.profile() });
			options?.onSuccess?.();
		}
	});
}
function usePortalLinks() {
	const api = require_mysite_api_context.useMySiteApi();
	return (0, _tanstack_react_query.useQuery)({
		queryKey: PORTAL_MYSITE_KEYS.links(),
		queryFn: () => api.listLinks()
	});
}
function usePortalCreateLink() {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: (body) => api.createLink(body),
		onSuccess: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.links() });
		}
	});
}
function usePortalUpdateLink() {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: ({ linkId, body }) => api.updateLink(linkId, body),
		onSuccess: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.links() });
		}
	});
}
function usePortalDeleteLink() {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: (linkId) => api.deleteLink(linkId),
		onSuccess: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.links() });
		}
	});
}
function usePortalReorderLinks() {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: ({ orderedIds }) => api.reorderLinks(orderedIds),
		onMutate: async ({ optimisticItems }) => {
			await queryClient.cancelQueries({ queryKey: PORTAL_MYSITE_KEYS.links() });
			const previousData = queryClient.getQueryData(PORTAL_MYSITE_KEYS.links());
			queryClient.setQueryData(PORTAL_MYSITE_KEYS.links(), optimisticItems);
			return { previousData };
		},
		onError: (_err, _vars, context) => {
			if (context?.previousData) queryClient.setQueryData(PORTAL_MYSITE_KEYS.links(), context.previousData);
		},
		onSettled: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.links() });
		}
	});
}
function usePortalFavorites() {
	const api = require_mysite_api_context.useMySiteApi();
	return (0, _tanstack_react_query.useQuery)({
		queryKey: PORTAL_MYSITE_KEYS.favorites(),
		queryFn: () => api.listFavorites()
	});
}
function usePortalDeleteFavorite() {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: (favoriteId) => api.deleteFavorite(favoriteId),
		onSuccess: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.favorites() });
		}
	});
}
function usePortalReorderFavorites() {
	const api = require_mysite_api_context.useMySiteApi();
	const queryClient = (0, _tanstack_react_query.useQueryClient)();
	return (0, _tanstack_react_query.useMutation)({
		mutationFn: ({ orderedIds }) => api.reorderFavorites(orderedIds),
		onMutate: async ({ optimisticItems }) => {
			await queryClient.cancelQueries({ queryKey: PORTAL_MYSITE_KEYS.favorites() });
			const previousData = queryClient.getQueryData(PORTAL_MYSITE_KEYS.favorites());
			queryClient.setQueryData(PORTAL_MYSITE_KEYS.favorites(), optimisticItems);
			return { previousData };
		},
		onError: (_err, _vars, context) => {
			if (context?.previousData) queryClient.setQueryData(PORTAL_MYSITE_KEYS.favorites(), context.previousData);
		},
		onSettled: () => {
			queryClient.invalidateQueries({ queryKey: PORTAL_MYSITE_KEYS.favorites() });
		}
	});
}
function usePortalMySiteThemes() {
	const api = require_mysite_api_context.useMySiteApi();
	return (0, _tanstack_react_query.useQuery)({
		queryKey: PORTAL_MYSITE_KEYS.themes(),
		queryFn: () => api.listThemes()
	});
}
//#endregion
Object.defineProperty(exports, "PORTAL_MYSITE_KEYS", {
	enumerable: true,
	get: function() {
		return PORTAL_MYSITE_KEYS;
	}
});
Object.defineProperty(exports, "usePortalCreateLink", {
	enumerable: true,
	get: function() {
		return usePortalCreateLink;
	}
});
Object.defineProperty(exports, "usePortalDeleteFavorite", {
	enumerable: true,
	get: function() {
		return usePortalDeleteFavorite;
	}
});
Object.defineProperty(exports, "usePortalDeleteLink", {
	enumerable: true,
	get: function() {
		return usePortalDeleteLink;
	}
});
Object.defineProperty(exports, "usePortalFavorites", {
	enumerable: true,
	get: function() {
		return usePortalFavorites;
	}
});
Object.defineProperty(exports, "usePortalLinks", {
	enumerable: true,
	get: function() {
		return usePortalLinks;
	}
});
Object.defineProperty(exports, "usePortalMySiteProfile", {
	enumerable: true,
	get: function() {
		return usePortalMySiteProfile;
	}
});
Object.defineProperty(exports, "usePortalMySiteThemes", {
	enumerable: true,
	get: function() {
		return usePortalMySiteThemes;
	}
});
Object.defineProperty(exports, "usePortalReorderFavorites", {
	enumerable: true,
	get: function() {
		return usePortalReorderFavorites;
	}
});
Object.defineProperty(exports, "usePortalReorderLinks", {
	enumerable: true,
	get: function() {
		return usePortalReorderLinks;
	}
});
Object.defineProperty(exports, "usePortalUpdateLink", {
	enumerable: true,
	get: function() {
		return usePortalUpdateLink;
	}
});
Object.defineProperty(exports, "usePortalUpdateSettings", {
	enumerable: true,
	get: function() {
		return usePortalUpdateSettings;
	}
});

//# sourceMappingURL=use-mysite-portal-DtJ9elyn.cjs.map