'use client';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useToast = exports.useToastStore = void 0;
var react_1 = __importDefault(require("react"));
var dayjs_1 = __importDefault(require("@qaing/utils/dayjs"));
var stores_1 = require("../../utils/stores");
var toastDuration = 3000;
exports.useToastStore = (0, stores_1.create)(function (set) { return ({
    toast: null,
    setToast: function (toast) { return set({ toast: toast }); },
    removeToast: function (createdAt) {
        return set(function (_a) {
            var toast = _a.toast;
            return ({
                toast: (toast === null || toast === void 0 ? void 0 : toast.createdAt) === createdAt ? null : toast,
            });
        });
    },
}); });
var useToast = function () {
    var _a = (0, exports.useToastStore)(), setToast = _a.setToast, removeToast = _a.removeToast;
    return react_1.default.useCallback(function (content) {
        var createdAt = (0, dayjs_1.default)().valueOf();
        setToast({ content: content, createdAt: createdAt });
        setTimeout(function () { return removeToast(createdAt); }, toastDuration);
    }, []);
};
exports.useToast = useToast;
//# sourceMappingURL=toast.js.map