import { inject } from "vue";
import { toastKey } from "./toast-context.js";

export function useToast() {
	const api = inject(toastKey, null);

	if(api) {
		return api;
	}

	const missingProvider = () => {
		throw new Error("GNexus UI Kit: useToast() requires <GnToastProvider> near the app root.");
	};

	return {
		show: missingProvider,
		info: missingProvider,
		success: missingProvider,
		warning: missingProvider,
		danger: missingProvider,
		error: missingProvider,
		close: missingProvider
	};
}

export default useToast;
