/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-6b06f3c
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { isValidElement, useMemo } from 'react';
import { isFragment } from 'react-is';
import { CheckIcon, DangerIcon, InfoCircleIcon, WarningIcon, } from '../../../icons/index.js';
import { useToastContext } from './ToastProvider.js';
// Default icons for each theme
const THEME_ICONS = {
    success: _jsx(CheckIcon, {}),
    danger: _jsx(DangerIcon, {}),
    warning: _jsx(WarningIcon, {}),
    note: _jsx(InfoCircleIcon, {}),
};
function isToastData(data) {
    const isReactNode = isValidElement(data) ||
        isFragment(data) ||
        typeof data === 'string' ||
        typeof data === 'number';
    return !isReactNode;
}
function normalizeToastData(data, defaultTheme) {
    const theme = isToastData(data) ? data.theme ?? defaultTheme : defaultTheme;
    const defaultIcon = theme ? THEME_ICONS[theme] : undefined;
    if (isToastData(data)) {
        return {
            icon: defaultIcon,
            theme: defaultTheme,
            ...data,
        };
    }
    // String or ReactNode passed directly - use as title
    return {
        title: data,
        theme: defaultTheme,
        icon: defaultIcon,
    };
}
/**
 * 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()
 * ```
 */
export function useToast() {
    const { addToast, removeToast } = useToastContext();
    const api = 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]);
    return api;
}

        