"use strict";const t=require("../../../utils/env.js"),e=require("../../../../common/vendor.js"),a=class a{constructor(){this.chatStorage=null}static getInstance(){return a.instance||(a.instance=new a),a.instance}getChatStorage(t){if(this.chatStorage||(this.chatStorage=this.getChatStorageFromLocalStorage()),t)return this.chatStorage[t];throw new Error("No key provided")}setChatStorage(r,o){this.chatStorage||(this.chatStorage=this.getChatStorageFromLocalStorage()),this.chatStorage[r]=o;try{t.isUniFrameWork?e.i.setStorageSync(a.CHAT_STORAGE_KEY,JSON.stringify(this.chatStorage)):localStorage.setItem(a.CHAT_STORAGE_KEY,JSON.stringify(this.chatStorage))}catch(s){throw new Error("Fail to set chat storage")}}getChatStorageFromLocalStorage(){let r="";if(r=t.isUniFrameWork?e.i.getStorageSync(a.CHAT_STORAGE_KEY)||"":localStorage.getItem(a.CHAT_STORAGE_KEY)||"",!r)return{};try{this.chatStorage=JSON.parse(r)}catch(o){this.chatStorage={}}return this.chatStorage}};a.instance=null,a.CHAT_STORAGE_KEY="TUI_CHAT_STORAGE";const r=a.getInstance();exports.chatStorage=r;
