"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useToast = exports.slowToastDuration = exports.fastToastDuration = exports.defaultDuration = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const core_1 = require("../core");
const notification_1 = require("../notification");
const utils_1 = require("../utils");
exports.defaultDuration = 'fast';
exports.fastToastDuration = 4000;
exports.slowToastDuration = 8000;
const setup = {
    options: {
        duration: exports.defaultDuration,
    },
    componentList: [],
};
const getDurationTime = (duration) => (duration === 'fast' ? exports.fastToastDuration : exports.slowToastDuration);
const useToast = () => {
    const { addToast, removeToast } = (0, core_1.useVuiContext)();
    const showToast = (0, react_1.useCallback)((options) => {
        const id = (options === null || options === void 0 ? void 0 : options.id) ? options.id : (0, utils_1.uid)('toast');
        const { duration = setup.options.duration, status = 'info', action, icon, text, title } = options || {};
        const toast = {
            id,
            component: ((0, jsx_runtime_1.jsx)(notification_1.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 = (0, react_1.useCallback)((text, duration = exports.defaultDuration) => showToast({ text, status: 'info', duration }), [showToast]);
    const showSuccess = (0, react_1.useCallback)((text, duration = exports.defaultDuration) => showToast({ text, status: 'success', duration }), [showToast]);
    const showWarning = (0, react_1.useCallback)((text, duration = exports.defaultDuration) => showToast({ text, status: 'warning', duration }), [showToast]);
    const showError = (0, react_1.useCallback)((text, duration = exports.defaultDuration) => showToast({ text, status: 'error', duration }), [showToast]);
    const showLoading = (0, react_1.useCallback)((text, duration = exports.defaultDuration) => showToast({ text, status: 'loading', duration }), [showToast]);
    return {
        showToast,
        hideToast: removeToast,
        showInfo,
        showSuccess,
        showWarning,
        showError,
        showLoading,
    };
};
exports.useToast = useToast;
//# sourceMappingURL=useToast.js.map