/*! For license information please see timemanager.js.LICENSE.txt */
(()=>{"use strict";lizMap.events.on({uicreated:function(e){var t,a=lizMap.config,i=(lizMap.layers,!1),n=0;if(!("timemanagerLayers"in a))return-1;t=Object.keys(lizMap.config.timemanagerLayers).length,$("#timemanager-menu button.btn-timemanager-clear").click((function(){$("#button-timemanager").click()})),lizMap.events.on({minidockopened:function(e){"timemanager"==e.id&&(i||($("#timemanager-menu").show(),function(){var e=1/0,i=-1/0;for(var r in a.timemanagerLayers)d(a.timemanagerLayers[r],(function(l,o){a.timemanagerLayers[r].min=l,a.timemanagerLayers[r].max=o;var f=moment(l).startOf(c.slice(0,-1)),d=moment(o).endOf(c.slice(0,-1));f&&f<e&&(e=f),d&&d>i&&(i=d),u=moment(e),s=moment(i),m=moment(u),$("#tmCurrentValue").html(x(u,c)),$("#tmNextValue").html(x(s,c)),Y(),$("#tmSlider").slider({min:u.valueOf(),max:s.startOf(c.slice(0,-1)).valueOf(),value:u.valueOf()}),v((n+=1)==t)}));b()}(),i=!0))},minidockclosed:function(e){"timemanager"==e.id&&i&&(h(!0),$("#timemanager-menu").hide(),i=!1,function(){for(var e in lizMap.config.timemanagerLayers)lizMap.deactivateMaplayerFilter(e),lizMap.config.layers[e].request_params.filtertoken=null,lizMap.events.triggerEvent("layerFilterParamChanged",{featureType:e,filter:null,updateDrawing:!1})}())}}),$("#tmSlider").slider();var r,m,l=null,u=-1/0,s=1/0,o=a.options.tmTimeFrameSize,c=a.options.tmTimeFrameType,f=a.options.tmAnimationFrameLength;function d(e,t){var a=e.startAttribute;if(e.endAttribute&&""!=e.endAttribute&&e.endAttribute!=e.startAttribute&&(a+=","+e.endAttribute),"min_timestamp"in e&&e.min_timestamp&&""!=e.min_timestamp&&"max_timestamp"in e&&e.max_timestamp&&""!=e.max_timestamp){var i=e.min_timestamp,n=e.max_timestamp;return t(i,n),!0}var r={request:"getMinAndMaxValues",layerId:e.layerId,fieldname:a,filter:""};$.get(filterConfigData.url,r,(function(e){if(!e)return!1;if("status"in e&&"error"==e.status)return console.log(e.title+": "+e.detail),!1;var a=null,i=null;for(var n in e){var r=e[n];a=r.min,i=r.max}t(a,i)}),"json")}function g(e,t,a,i,n){var r=moment(e).startOf(a),m=i*o*n;return r.add(m,a),r}function v(e){if(!e)return!0;b()}function p(e,t,a){var i=[];if(t==e.min&&a==e.max)return e.data={min_date:null,max_date:null},e.filter=null,null;var n=e.startAttribute,r=e.endAttribute,m=e.attributeResolution;if(t&&Date.parse(t)){var l='( "'+n+"\" >= '"+x(t,m)+"'";r&&""!=r&&r!=n&&(l+=' OR  "'+r+"\" >= '"+x(t,m)+"'"),l+=" )",i.push(l)}else t=null;if(a&&Date.parse(a)){var u='( "'+n+"\" <= '"+x(a,m)+"'";r&&""!=r&&r!=n&&(u+=' OR  "'+r+"\" <= '"+x(a,m)+"'"),u+=" )",i.push(u)}else a=null;var s=null;return i.length&&(s=" ( ",s+=i.join(" AND "),s+=" ) "),e.data={min_date:t,max_date:a},e.filter=s,s}function y(){var e=g(m,0,c,1,1);e.startOf(c.slice(0,-1))<=s.startOf(c.slice(0,-1))?M(e,g(m,0,c,2,1)):(h(!0),b())}function Y(){var e=$("#tmCurrentValue").text()==$("#tmNextValue").text();$("#tmNextValue").toggle(!e),$("#tmNextValue").prev("span").toggle(!e)}function M(e,t){!function(e,t){for(var i in t.subtract(1,"milliseconds"),a.timemanagerLayers)l=p(a.timemanagerLayers[i],e,t),lizMap.triggerLayerFilter(i,l)}(e,t),m=moment(e),$("#tmCurrentValue").html(x(m,c)),$("#tmNextValue").html(x(moment(t),c)),Y(),$("#tmSlider").slider("option","value",m.valueOf())}function b(){var e=$("#tmSlider").slider("option","value"),t=moment(e);M(t=t.startOf(c.slice(0,-1)),g(t,0,c,1,1))}function h(e){if(window.clearInterval(r),r=null,$("#tmTogglePlay").html(lizDict["timemanager.toolbar.play"]),!0===e){m=moment(u),$("#tmCurrentValue").html(x(m,c)),$("#tmSlider").slider("option","value",m.valueOf());var t=g(m,0,c,1,1);$("#tmNextValue").html(x(t,c)),Y()}}function x(e,t){var a=moment(e),i=null;switch(t){case"milliseconds":case"seconds":i="YYYY-MM-DD HH:mm:ss";break;case"minutes":i="YYYY-MM-DD HH:mm:00";break;case"hours":i="YYYY-MM-DD HH:00";break;case"days":case"weeks":i="YYYY-MM-DD";break;case"months":i="YYYY-MM";break;case"years":i="YYYY"}return a.format(i)}f<1e3&&(f=1e3),$("#tmSlider").on("slide",(function(e,t){$("#tmSlider").slider("option","value")})),$("#tmSlider").on("slidestop",(function(e,t){b()})),$("#tmTogglePlay").click((function(){$(this).html()==lizDict["timemanager.toolbar.play"]?function(){r&&h(!0),$("#tmTogglePlay").html(lizDict["timemanager.toolbar.pause"]),m||(m=u);r=window.setInterval((function(){y()}),f)}():h()})),$("#tmPrev").click((function(){var e;h(!1),(e=g(m,0,c,1,-1)).startOf(c.slice(0,-1))>=u.startOf(c.slice(0,-1))?M(e,moment(m)):(h(!0),b())})),$("#tmNext").click((function(){h(!1),y()}))}})})();
//# sourceMappingURL=timemanager.js.map