import React, { createContext, useContext } from "react";

const Context = createContext(undefined);

export function CloudUiProvider({
	children,
	apiKey,
	user
}: {
	children: React.ReactNode;
	apiKey: string;
	user?: {
		name: string;
		email: string;
		id: string;
	};
}) {
	return (
		<Context.Provider value={{ apiKey, user }}>
			<>{children}</>
		</Context.Provider>
	);
}

export const useCloudUiProvider = () => {
	const context = useContext(Context);
	if (context === undefined) {
		throw new Error("useCloudUiProvider must be used inside CloudUiProvider");
	}
	return context;
};
