import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback } from 'react';
import { useVuiContext } from '../core';
import { Notification } from '../notification';
import { uid } from '../utils';
export const defaultDuration = 'fast';
export const fastToastDuration = 4000;
export const slowToastDuration = 8000;
const setup = {
    options: {
        duration: defaultDuration,
    },
    componentList: [],
};
const getDurationTime = (duration) => (duration === 'fast' ? fastToastDuration : slowToastDuration);
export const useToast = () => {
    const { addToast, removeToast } = useVuiContext();
    const showToast = useCallback((options) => {
        const id = options?.id ? options.id : uid('toast');
        const { duration = setup.options.duration, status = 'info', action, icon, text, title } = options || {};
        const toast = {
            id,
            component: (_jsx(Notification, { action: action, animation: "fadeDown", elevation: 3, icon: icon, mt: { md: 1, sm: '4px', xs: '4px' }, onClose: () => removeToast(id), status: status, text: text, title: title, verticalAlign: "center", w: 1 })),
        };
        addToast(toast);
        if (duration && duration !== 'sticky') {
            window.setTimeout(() => removeToast(id), getDurationTime(duration));
        }
    }, []);
    const showInfo = useCallback((text, duration = defaultDuration) => showToast({ text, status: 'info', duration }), [showToast]);
    const showSuccess = useCallback((text, duration = defaultDuration) => showToast({ text, status: 'success', duration }), [showToast]);
    const showWarning = useCallback((text, duration = defaultDuration) => showToast({ text, status: 'warning', duration }), [showToast]);
    const showError = useCallback((text, duration = defaultDuration) => showToast({ text, status: 'error', duration }), [showToast]);
    const showLoading = useCallback((text, duration = defaultDuration) => showToast({ text, status: 'loading', duration }), [showToast]);
    return {
        showToast,
        hideToast: removeToast,
        showInfo,
        showSuccess,
        showWarning,
        showError,
        showLoading,
    };
};
//# sourceMappingURL=useToast.js.map