(()=>{function e(n,o){var l,a,d,c,u,f;function i(e,t,n){e=e.deviceId;return t.detailCached(e).then(n.getResData).then(function(e){return t.supportsOperation(e,"c8y_LogfileRequest")})}function g(e){var t;return e&&e.c8y_LogfileRequest&&e.c8y_LogfileRequest.file?(e=e.c8y_LogfileRequest.file,u.isEventBinary(e)?(t=u.getEventIdFromUrl(e))?u.downloadAsText(t):l.get(e):(t=c.getIdFromUrl(e))?c.downloadAsText(t):l.get(e)):a.when({data:o("Loading logfiles…")})}function s(e){if(e.c8y_LogfileRequest.file){e=e.c8y_LogfileRequest.file;if(u.isEventBinary(e)){var t=u.getEventIdFromUrl(e);if(t)return u.detail(t).then(function(e){return f.downloadAndSaveAs(e.data)}).catch(function(){d.danger(o("Could not download the log file."))})}else{t=c.getIdFromUrl(e);if(t)return c.downloadAndSaveAs(t).catch(function(){d.danger(o("Could not download the log file."))})}}return!1}return{$get:["$http","$q","c8yAlert","c8yBinary","c8yEvents","eventsBinaryService",function(e,t,n,o,i,r){return l=e,a=t,d=n,c=o,u=i,f=r,{getLogfile:g,download:s}}],when:function(e,t){n.when(e,_.assign(t,{showIf:["$routeParams","c8yDevices","c8yBase",i]}))},showIf:i}}e.$inject=["c8yViewsProvider","gettext"],angular.module("c8y.logViewer").provider("logViewer",e)})();