angular.module("c8y.core").factory("c8yDeviceStatus",["$rootScope","$filter","c8yBase","gettext","gettextCatalog",function(a,o,n,c,i){var N={sendData:{AVAILABLE:{icon:"long-arrow-right",class:"statusOk"},UNAVAILABLE:{icon:"long-arrow-right",class:"statusNok"},UNKNOWN:{icon:"long-arrow-right",class:"statusUnknown"},NOT_MONITORED:{icon:"long-arrow-right",class:"statusUnknown"}},push:{CONNECTED:{icon:"long-arrow-left",class:"statusOk"},DISCONNECTED:{icon:"long-arrow-left",class:"statusUnknown"},UNKNOWN:{icon:"long-arrow-left",class:"statusUnknown"}},device:{MAINTENANCE:{icon:"wrench",class:"statusAlert"}}},l={CONNECTED:c("Push connection: active"),DISCONNECTED:c("Push connection: inactive"),UNKNOWN:c("Push connection: inactive")},u={AVAILABLE:c("Send connection: online"),NOT_MONITORED:c("Send connection: not monitored"),UNAVAILABLE:c("Send connection: offline"),UNKNOWN:c("Send connection status unknown"),MAINTENANCE:c("Device is under maintenance")};function r(n){return n&&n.c8y_Availability&&n.c8y_Availability.status}return{status:function(n){var t=_.get(n,"c8y_RequiredAvailability"),t=(s=r(n))||(t?"UNKNOWN":"NOT_MONITORED"),e=_.get(n,"c8y_Connection.status")||"UNKNOWN",s="MAINTENANCE"===s||"MAINTENANCE"===e?{sendStatus:!1,pushStatus:!1,maintenanceStatus:{icon:N.device.MAINTENANCE.icon,class:N.device.MAINTENANCE.class,tooltip:c("Device is under maintenance")}}:{sendStatus:{icon:N.sendData[t].icon,class:N.sendData[t].class,status:t,label:u[t],tooltip:(n=>(n=(n=n&&n.c8y_Availability)&&n.lastMessage)?i.getString("Device last request:\n{{date}}",{date:o("absoluteDate")(n)}):c("Connection not monitored"))(n)},pushStatus:{icon:N.push[e].icon,class:N.push[e].class,status:e,label:l[e],tooltip:c("CONNECTED"===e?"Connection to device established":"Connection to device not established (not supported by device or no connectivity)")},maintenanceStatus:!1};return a.$emit("c8yDeviceStatus:update",n),s},isDeviceAvailable:function(n){return"AVAILABLE"===r(n)},isDeviceMaintenance:function(n){return"MAINTENANCE"===r(n)},canReceiveCommands:function(n){return"CONNECTED"===_.get(n,"c8y_Connection.status")}}}]);