"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    NoticeType: ()=>NoticesManager_rslib_entry_NoticeType,
    NoticeDuration: ()=>NoticesManager_rslib_entry_NoticeDuration,
    useNoticeManager: ()=>useNoticeManager,
    NoticeManagerContext: ()=>NoticeManagerContext,
    NoticeLevel: ()=>NoticesManager_rslib_entry_NoticeLevel,
    NoticeManager: ()=>NoticeManager,
    useNoticeSub: ()=>useNoticeSub,
    NoticeManagerProvider: ()=>NoticeManagerProvider
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_mitt_namespaceObject = require("mitt");
var external_mitt_default = /*#__PURE__*/ __webpack_require__.n(external_mitt_namespaceObject);
const index_js_namespaceObject = require("./hooks/index.js");
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
var NoticesManager_rslib_entry_NoticeLevel = /*#__PURE__*/ function(NoticeLevel) {
    NoticeLevel["INFO"] = "info";
    NoticeLevel["WARNING"] = "warning";
    NoticeLevel["SUCCESS"] = "success";
    NoticeLevel["ERROR"] = "error";
    return NoticeLevel;
}({});
var NoticesManager_rslib_entry_NoticeType = /*#__PURE__*/ function(NoticeType) {
    NoticeType["STATUS"] = "status";
    NoticeType["TOAST"] = "toast";
    NoticeType["NOTIFICATION"] = "notification";
    NoticeType["CUSTOM"] = "custom";
    return NoticeType;
}({});
var NoticesManager_rslib_entry_NoticeDuration = /*#__PURE__*/ function(NoticeDuration) {
    NoticeDuration["Short"] = "SHORT";
    return NoticeDuration;
}({});
const NoticeManagerContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
const NoticeManagerProvider = (param)=>{
    let { children } = param;
    const app = (0, index_js_namespaceObject.useApp)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NoticeManagerContext.Provider, {
        value: {
            manager: app.noticeManager
        },
        children: children
    });
};
const useNoticeManager = ()=>(0, external_react_namespaceObject.useContext)(NoticeManagerContext);
const useNoticeSub = (name, handler)=>{
    const { manager } = useNoticeManager();
    (0, external_react_namespaceObject.useEffect)(()=>{
        manager.emitter.on(name, handler);
        return ()=>{
            manager.emitter.off(name, handler);
        };
    }, [
        manager.emitter,
        name,
        handler
    ]);
};
class NoticeManager {
    on(data) {
        if ("notification" === data.type) this[data.type](data.title, data.content, data.level);
        else if ("custom" === data.type) this.emitter.emit(data.eventType, data.event);
        else this[data.type](data.content, data.level);
    }
    status(content, level, duration) {
        this.currentStatus = content;
        this.currentStatusUpdatedAt = Date.now();
    }
    toast(content, level) {
        external_antd_namespaceObject.message[level](content);
    }
    notification(title, content, level) {
        external_antd_namespaceObject.notification[level]({
            message: title,
            description: content
        });
    }
    constructor(app){
        _define_property(this, "app", void 0);
        _define_property(this, "ws", void 0);
        _define_property(this, "emitter", void 0);
        _define_property(this, "currentStatus", void 0);
        _define_property(this, "currentStatusUpdatedAt", void 0);
        this.app = app;
        this.currentStatus = '';
        this.currentStatusUpdatedAt = Date.now();
        this.ws = app.ws;
        this.emitter = external_mitt_default()();
        (0, schema_namespaceObject.define)(this, {
            currentStatus: schema_namespaceObject.observable.ref
        });
        setInterval(()=>{
            const now = Date.now();
            if (now - this.currentStatusUpdatedAt > 30000) this.currentStatus = '';
        }, 1000);
    }
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
