/** @license MIT | @cube-dev/ui-kit v0.135.1 | Cube Dev Team */
import { CheckIcon } from "../../../icons/CheckIcon.js";
import { DangerIcon } from "../../../icons/DangerIcon.js";
import { InfoCircleIcon } from "../../../icons/InfoCircleIcon.js";
import { WarningIcon } from "../../../icons/WarningIcon.js";
import { useToastContext } from "../Notifications/NotificationContext.js";
import { isValidElement, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
import { isFragment } from "react-is";

//#region src/components/overlays/Toast/useToast.tsx
const THEME_ICONS = {
	success: /* @__PURE__ */ jsx(CheckIcon, {}),
	danger: /* @__PURE__ */ jsx(DangerIcon, {}),
	warning: /* @__PURE__ */ jsx(WarningIcon, {}),
	note: /* @__PURE__ */ jsx(InfoCircleIcon, {})
};
/**
* Get the appropriate icon for a toast based on theme and loading state.
* - When loading, returns the provided icon as-is (loading indicator is separate)
* - When not loading, returns the provided icon or falls back to theme-based default
*/
function getThemeIcon(theme, icon, isLoading) {
	if (isLoading) return icon;
	if (icon !== void 0) return icon;
	return theme ? THEME_ICONS[theme] : void 0;
}
function isToastData(data) {
	return !(isValidElement(data) || isFragment(data) || typeof data === "string" || typeof data === "number" || typeof data === "boolean" || data === null || data === void 0 || Array.isArray(data));
}
function normalizeToastData(data, defaultTheme) {
	if (isToastData(data)) return {
		...data,
		theme: data.theme ?? defaultTheme
	};
	return {
		title: data,
		theme: defaultTheme
	};
}
/**
* Hook to display toast notifications.
*
* @example
* ```tsx
* const toast = useToast();
*
* // String shorthand
* toast.success('Copied to clipboard');
*
* // Object with options
* toast.success({
*   title: 'Success',
*   description: 'File copied to clipboard',
*   icon: <CustomIcon />,
*   duration: 3000,
* });
*
* // Methods: toast(), toast.success(), toast.danger(), toast.warning(), toast.note()
* ```
*/
function useToast() {
	const { addToast, removeToast } = useToastContext();
	return useMemo(() => {
		const toast = (data) => {
			return addToast(normalizeToastData(data));
		};
		toast.success = (data) => {
			return addToast(normalizeToastData(data, "success"));
		};
		toast.danger = (data) => {
			return addToast(normalizeToastData(data, "danger"));
		};
		toast.warning = (data) => {
			return addToast(normalizeToastData(data, "warning"));
		};
		toast.note = (data) => {
			return addToast(normalizeToastData(data, "note"));
		};
		toast.remove = (id) => {
			removeToast(id);
		};
		return toast;
	}, [addToast, removeToast]);
}

//#endregion
export { getThemeIcon, useToast };
//# sourceMappingURL=useToast.js.map