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

// Declarative Toast component
import { useEffect, useRef } from 'react';
import { useToastContext } from './ToastProvider.js';
import { useProgressToast } from './useProgressToast.js';
import { getThemeIcon } from './useToast.js';
export { ToastProvider, useToastContext } from './ToastProvider.js';
export { ToastItem } from './ToastItem.js';
export { useToast, getThemeIcon } from './useToast.js';
export { useProgressToast } from './useProgressToast.js';
/**
 * Declarative Toast component that shows a toast while mounted.
 *
 * @example
 * ```tsx
 * // Simple toast (visible while mounted)
 * <Toast theme="success">Saved successfully</Toast>
 *
 * // With description
 * <Toast title="Success" description="Changes saved" theme="success" />
 * ```
 */
export function Toast(props) {
    const { children, ...toastData } = props;
    const { addToast, removeToast, updateToast } = useToastContext();
    const toastIdRef = useRef(null);
    // Apply theme-based icon if not loading and no icon provided
    const icon = getThemeIcon(toastData.theme, toastData.icon, toastData.isLoading);
    useEffect(() => {
        // Add toast on mount
        toastIdRef.current = addToast({
            ...toastData,
            title: toastData.title ?? children,
            icon,
            duration: null, // Persistent while mounted
        }, true);
        return () => {
            // Remove toast on unmount
            if (toastIdRef.current != null) {
                removeToast(toastIdRef.current);
                toastIdRef.current = null;
            }
        };
    }, []);
    // Update toast when props change
    useEffect(() => {
        if (toastIdRef.current != null) {
            updateToast(toastIdRef.current, {
                ...toastData,
                title: toastData.title ?? children,
                icon,
            });
        }
    }, [
        children,
        toastData.title,
        toastData.description,
        toastData.theme,
        toastData.icon,
        toastData.isLoading,
        toastData.id,
        icon,
        // Note: itemProps is intentionally excluded - it's an object that would cause
        // unnecessary re-runs. Users needing dynamic itemProps should remount the component.
        updateToast,
    ]);
    return null;
}
/**
 * Declarative Progress Toast component.
 *
 * @example
 * ```tsx
 * <Toast.Progress
 *   {...(isLoading
 *     ? { isLoading: true, title: 'Saving...' }
 *     : { isLoading: false, title: 'Saved!', theme: 'success' }
 *   )}
 * />
 * ```
 */
function ToastProgress(props) {
    const { children, ...progressOptions } = props;
    useProgressToast({
        ...progressOptions,
        title: progressOptions.title ?? children,
    });
    return null;
}
Toast.Progress = ToastProgress;

        