!function(e,t){"use strict";var r=e.EasyChatRequest,a="easychat.admin.chatListCache.",n=null,s=0;if(r&&!e.EasyChatUnreadPrefetchConfigured){e.EasyChatUnreadPrefetchConfigured=!0;var o={prefix:a,key:i,read:function(t,r){r=r||{};try{var a=e.sessionStorage?e.sessionStorage.getItem(t):"",n=a?JSON.parse(a):null;if(!n||!n.data||!n.savedAt)return null;var s=r.allowStale?18e5:12e4;return Date.now()-parseInt(n.savedAt||0,10)<=s?n.data:null}catch(e){return null}},write:u,clear:function(){try{if(!e.sessionStorage)return;for(var t=[],r=0;r<e.sessionStorage.length;r+=1){var n=e.sessionStorage.key(r);n&&0===n.indexOf(a)&&t.push(n)}t.forEach(function(t){e.sessionStorage.removeItem(t)})}catch(e){}}};e.EasyChatChatListCache=o,e.EasyChatUnreadPrefetch={warm:function(e){if(!(e=Math.max(0,parseInt(e||0,10)))||"index"===((a=t.getElementById("easychat-main-shell"))?String(a.getAttribute("data-easychat-active-route")||""):""))return Promise.resolve({warmed:!1,reason:"not-needed"});var a;if(n)return n.promise;if(Date.now()-s<2e3)return Promise.resolve({warmed:!1,reason:"coalesced"});s=Date.now();var o=r.abortableJson("index.php?route=index/getChats",{data:{scope:"unassigned",source_provider:"all"},headers:{"X-EasyChat-Unread-Prefetch":"1"},timeoutMs:8e3}),l=o.promise.then(function(e){var t=u(i("unassigned","all",1,0),e);return{warmed:t,reason:t?"stored":"invalid-response"}}).catch(function(){return{warmed:!1,reason:"request-failed"}}),d=Promise.all([l,c().catch(function(){return null})]).then(function(e){return e[0]}).then(function(e){return n=null,e});return n={abort:o.abort,promise:d},d},isPending:function(){return!!n}}}function i(e,t,r,n){return"unassigned"!==(e=String(e||"").toLowerCase())&&"mine"!==e&&"all"!==e&&"archive"!==e&&(e=1===parseInt(e||0,10)?"archive":"all"),a+e+"."+function(e){var t=String(e||"all").toLowerCase().replace(/[^a-z0-9_-]/g,"");return t&&"widget_all"!==t?t:"all"}(t)+".operator-"+Math.max(0,parseInt(n||0,10))+"."+Math.max(1,parseInt(r||1,10))}function u(t,r){if(!r||!0!==r.success||!Array.isArray(r.chats))return!1;try{return!!e.sessionStorage&&(e.sessionStorage.setItem(t,JSON.stringify({savedAt:Date.now(),data:r})),!0)}catch(e){return!1}}function c(){if(!e.EasyChatAdminInstant||"function"!=typeof e.EasyChatAdminInstant.prefetch)return Promise.resolve(null);var r=t.querySelector('[data-easychat-shell-route="index"]');return r?e.EasyChatAdminInstant.prefetch(r):Promise.resolve(null)}}(window,document);