"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("lz-string"),r=require("lodash/debounce"),n=require("../cache-utils/formatBytes.js"),i=require("../cache-utils/idle-callback.js"),s=require("./constants.js"),a=require("./validateEnvelope.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=o(e),u=o(t),l=o(r);function f(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var p=function(e){var t={},r=Date.now();try{var n=sessionStorage.getItem(s.STORAGE_KEY);if(n){var i=JSON.parse(n),o=a.validateEnvelope(i);o&&(t=o.state,r=o.timestamp)}}catch(e){}var u=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){c.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},t),l=r;return e.forEach((function(e,t){u[t]=e.wellIds,e.timestamp>l&&(l=e.timestamp)})),{mergedState:u,latestTimestamp:l}};exports.createTileCacheFlusher=function(e){return l.default((function(){var t=e.pendingWritesRef.current;if(0!==t.size){var r=new Map(t),a=i.scheduleIdleWork((function(){e.idleHandlesRef.current.delete(a);try{var t=p(r),i=t.mergedState,o=t.latestTimestamp,c=JSON.stringify(i),l={version:s.CACHE_VERSION,timestamp:o,schema:s.CACHE_SCHEMA,compression:"lz-utf16",count:Object.keys(i).length,sizeKB:n.formatBytesToKB(c.length),state:u.default.compressToUTF16(c)};sessionStorage.setItem(s.STORAGE_KEY,JSON.stringify(l))}finally{r.forEach((function(t,r){e.pendingWritesRef.current.delete(r)}))}}),{timeout:5e3});e.idleHandlesRef.current.add(a)}}),s.DEBOUNCE_DELAY)};
//# sourceMappingURL=createTileCacheFlusher.js.map
