!function(t){"use strict";function e(t){t=t||{},this.maxEntries=Math.max(2,parseInt(t.maxEntries||4,10)),this.ttlMs=Math.max(6e4,parseInt(t.ttlMs||6e5,10)),this.entries=new Map,this.onEvict="function"==typeof t.onEvict?t.onEvict:function(){},this.canEvict="function"==typeof t.canEvict?t.canEvict:function(){return!0}}e.prototype.normalizeId=function(t){var e=parseInt(t||0,10);return isNaN(e)||e<=0?0:e},e.prototype.isFresh=function(t,e){return!!t&&e-parseInt(t.savedAt||0,10)<=this.ttlMs},e.prototype.remove=function(t,e){if(!(t=this.normalizeId(t))||!this.entries.has(t))return null;var i=this.entries.get(t);return this.entries.delete(t),e&&this.onEvict(i,e),i},e.prototype.prune=function(){var t=Date.now(),e=this;for(this.entries.forEach(function(i,n){!e.isFresh(i,t)&&e.canEvict(i)&&e.remove(n,"expired")});this.entries.size>this.maxEntries;){var i=0;if(this.entries.forEach(function(t,n){!i&&e.canEvict(t)&&(i=n)}),!i)break;this.remove(i,"capacity")}},e.prototype.put=function(t,e){return!(!(t=this.normalizeId(t))||!e)&&(this.entries.has(t)&&this.entries.delete(t),e.chatId=t,e.savedAt=Date.now(),this.entries.set(t,e),this.prune(),!0)},e.prototype.take=function(t){if(!(t=this.normalizeId(t))||!this.entries.has(t))return null;var e=this.entries.get(t);return this.entries.delete(t),!this.isFresh(e,Date.now())&&this.canEvict(e)?(this.onEvict(e,"expired"),null):e},e.prototype.peek=function(t){if(!(t=this.normalizeId(t))||!this.entries.has(t))return null;var e=this.entries.get(t);return!this.isFresh(e,Date.now())&&this.canEvict(e)?(this.remove(t,"expired"),null):e},e.prototype.clear=function(t){var e=this;Array.from(this.entries.keys()).forEach(function(i){e.remove(i,t||"clear")})},t.EasyChatConversationStateStore=e}(window);