!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("rxjs"),require("underscore"),require("guid-typescript"),require("ngx-cookie-service"),require("@angular/common/http"),require("@angular/core"),require("@microsoft/signalr")):"function"==typeof define&&define.amd?define("@snovasys/snova-shared-components",["exports","rxjs","underscore","guid-typescript","ngx-cookie-service","@angular/common/http","@angular/core","@microsoft/signalr"],n):n((e.snovasys=e.snovasys||{},e.snovasys["snova-shared-components"]={}),e.rxjs,e._,e.guidTypescript,e.ngxCookieService,e.ng.common.http,e.ng.core,e.signalR)}(this,function(e,t,o,n,i,s,r,a){"use strict";var c="CurrentCulture",u="Environment",l="CompanySettings",h="UserModel",d="IsSignalREnabled",g="SignalRBasePath",f="HydaSignalRBasePath",p=(Object.defineProperty(I.prototype,"isSidenavHovered",{get:function(){return this._isSidenavHovered},set:function(e){this._isSidenavHovered=e,this.sidenavChange.next({isSidenavExpanded:this.isSidenavExpanded,isSidenavHovered:this.isSidenavHovered})},enumerable:!0,configurable:!0}),Object.defineProperty(I.prototype,"isSidenavExpanded",{get:function(){return this._isSidenavExpanded},set:function(e){this._isSidenavExpanded=e,this.sidenavChange.next({isSidenavExpanded:this.isSidenavExpanded,isSidenavHovered:this.isSidenavHovered})},enumerable:!0,configurable:!0}),I.prototype.toggleSidenav=function(){var e=this;this.resetMenusState(),this.isSidenavExpanded=!this.isSidenavExpanded,this.removeHoverSidenav(),setTimeout(function(){document.querySelector("nav.side-navigation");e.positionHeader(0),e.positionPageContent(0)},100)},I.prototype.resetMenusState=function(){var e=document.querySelectorAll(".menu-title"),n=document.querySelectorAll(".menu-panel");e.forEach(function(e){return e.classList.remove("menu-active")}),n.forEach(function(e){return e.style.maxHeight=null})},I.prototype.positionHeader=function(e){var n=document.querySelector("header.header"),t=document.querySelector("nav.side-navigation"),o=(document.querySelector(".snova-treeview-main-wrapper"),1);t&&(o+=t.offsetWidth),e&&this.isSidenavExpanded&&(o-=e),n.style.marginLeft=o+"px"},I.prototype.positionPageContent=function(e){var n=document.querySelector("nav.side-navigation"),t=document.querySelector(".mat-sidenav-content"),o=(document.querySelector(".snova-treeview-main-wrapper"),1);n&&(o+=n.offsetWidth),e&&this.isSidenavExpanded&&(o-=e),t.style.marginLeft=o+"px"},I.prototype.getFavouriteCount=function(){return this.favouriteCount.asObservable()},I.prototype.updateFavouriteCount=function(e){return this.favouriteCount.next(e)},I.prototype.hoverSidenav=function(){this.isSidenavExpanded||(this.isSidenavHovered=!0)},I.prototype.removeHoverSidenav=function(){this.isSidenavExpanded||(this.isSidenavHovered=!1)},I.prototype.updateKeystrokestab=function(e){return this.canTrackKeyStrokesAndMouseMovements.next(e)},I.prototype.updateSetupPage=function(e){return this.isSetupPage.next(e)},I);function I(){var n=this;this._isSidenavExpanded=!1,this.favouriteCount=new t.BehaviorSubject(0),this._isSidenavHovered=!1,this.sidenavChange=new t.BehaviorSubject({isSidenavExpanded:!1,isSidenavHovered:!1}),this.canTrackKeyStrokesAndMouseMovements=new t.BehaviorSubject(!1),this.isSetupPage=new t.BehaviorSubject(!1),window.innerWidth<1500?this.isUiExpanded=!1:this.isUiExpanded=!0,this._isSidenavExpanded=this.isUiExpanded,this._isSidenavHovered=this.isUiExpanded,this.sidenavChange.next({isSidenavExpanded:this.isSidenavExpanded,isSidenavHovered:this.isSidenavHovered}),setTimeout(function(){var e=JSON.parse(localStorage.getItem(l));n.keyStrokesTabEnable="0"!=o.find(e,function(e){return"CanTrackKeyStrokesAndMouseMovements"==e.key}).value,n.canTrackKeyStrokesAndMouseMovements.next(n.keyStrokesTabEnable)},500)}function S(e,n,a,c){return new(a=a||Promise)(function(t,o){function i(e){try{r(c.next(e))}catch(n){o(n)}}function s(e){try{r(c["throw"](e))}catch(n){o(n)}}function r(e){var n;e.done?t(e.value):((n=e.value)instanceof a?n:new a(function(e){e(n)})).then(i,s)}r((c=c.apply(e,n||[])).next())})}function v(t,o){var i,s,r,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},e={next:n(0),"throw":n(1),"return":n(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function n(n){return function(e){return c([n,e])}}function c(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,s&&(r=2&e[0]?s["return"]:e[0]?s["throw"]||((r=s["return"])&&r.call(s),0):s.next)&&!(r=r.call(s,e[1])).done)return r;switch(s=0,(e=r?[2&e[0],r.value]:e)[0]){case 0:case 1:r=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,s=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(r=0<(r=a.trys).length&&r[r.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!r||e[1]>r[0]&&e[1]<r[3]))a.label=e[1];else if(6===e[0]&&a.label<r[1])a.label=r[1],r=e;else{if(!(r&&a.label<r[2])){r[2]&&a.ops.pop(),a.trys.pop();continue}a.label=r[2],a.ops.push(e)}}e=o.call(t,a)}catch(n){e=[6,n],s=0}finally{i=r=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}var C={Connecting:0,Connected:1,Reconnecting:2,Disconnected:4},m=C[C.Connecting]="Connecting",y=C[C.Connected]="Connected",b=C[C.Reconnecting]="Reconnecting",R=C[C.Disconnected]="Disconnected",T=(k.prototype.add=function(e,n){this.items.hasOwnProperty(e)||this.count++,this.items[e]=n},k.prototype.containsKey=function(e){return this.items.hasOwnProperty(e)},k.prototype.size=function(){return this.count},k.prototype.getItem=function(e){return this.items[e]},k.prototype.removeItem=function(e){var n=this.items[e];return delete this.items[e],this.count--,n},k.prototype.getKeys=function(){var e,n=[];for(e in this.items)this.items.hasOwnProperty(e)&&n.push(e);return n},k.prototype.values=function(){var e,n=[];for(e in this.items)this.items.hasOwnProperty(e)&&n.push(this.items[e]);return n},k);function k(){this.items={},this.count=0}U.prototype.establishConnectionWithRealTimeHub=function(){return S(this,void 0,void 0,function(){return v(this,function(e){switch(e.label){case 0:console.log("[SIGNALR] establishConnectionWithRealTimeHub called!"),e.label=1;case 1:return null!=localStorage.getItem(d)&&localStorage.getItem(d)!=undefined?this.canViewLiveStatus="true"==localStorage.getItem(d):this.canViewLiveStatus=!1,JSON.parse(localStorage.getItem(g))!=undefined&&null!=JSON.parse(localStorage.getItem(g))&&(this.apiURL=JSON.parse(localStorage.getItem(g)),console.log("[SIGNALR] Setting API URL: "+this.apiURL)),this.canViewLiveStatus?this.checkConnectionWithActivityTrackerHub(!1):(console.log("live status feature was disabled"),this.clearRealTimeStatusDictionary(),this.disconnect()),[4,this.delay(6e4)];case 2:return e.sent(),[3,1];case 3:return[2]}})})},U.prototype.delay=function(n){return new Promise(function(e){return setTimeout(e,n)})},U.prototype.checkConnectionWithActivityTrackerHub=function(e){e||3<this.retryConnecting||0==this.connectionInProgress&&(null==this.hubConnection||this.hubConnection==undefined||this.hubConnection.state==C.Disconnected)?(this.retryConnecting=0,this.establishSignalrConnection()):this.hubConnection.state==C.Reconnecting||this.hubConnection.state==C.Connecting?(console.log("connection is in connecting state on retry "+this.retryConnecting),this.retryConnecting=this.retryConnecting+1):(this.retryConnecting=0,console.log("stable connection already exist"))},U.prototype.establishSignalrConnection=function(){var n,t,o=this,i=this;1!=i.connectionInProgress?(i.connectionInProgress=!0,i.signalRconnectionInProgress.next(!0),i.signalRHubConnectionError.next(!1),n=this.loggedInUserId+"-"+this.randomId+"-web-main",t=this.companyId,i.hubConnection?this.isSignalRConnected()?console.log("[SIGNALR] establishSignalrConnection already connected so doing nothing"):(console.log("restarting the already existing connection 1"),i.hubConnection.start().done(function(){console.log("[SIGNALR] hubConnection.Start().Done - hub already existed")}).fail(function(){i.connectionInProgress=!1,i.signalRconnectionInProgress.next(!1),i.signalRHubConnectionError.next(!0),console.log("connection failed")})):(console.log("[SIGNALR] no available hub so creating and connecting"),i.hubConnection=$_tracker.hubConnection(i.apiURL+"signalr",{useDefaultPath:!1}),i.hubConnection.stateChanged(function(e){i.getConnectionState(e)==C.Connected&&(console.log("SIGNALR] (On)stateChange(Connected) called UpdateClientCredData  with :",JSON.stringify({ClientUserId:n,CompanyId:t})),i.trackerHub.invoke("UpdateClientCredData",JSON.stringify({ClientUserId:n,CompanyId:t})),i.connectionInProgress=!1,i.signalRconnectionInProgress.next(!1),i.signalRHubConnectionError.next(!1),i.invokeStatusChanges(),i.subScribeForRecordChanges([o.loggedInUserId]),i.getTestAutomationForUsers([o.loggedInUserId]))}),i.trackerHub=i.hubConnection.createHubProxy("ActivityTrackerHub"),i.trackerHub.on("autoUserCreationDetectedFromTracker",function(e){i.autoUserCreatedDetection.next(e)}),i.trackerHub.on("testAutomation",function(e){i.testAutomationChanged.next(e),console.log(e,"testautomationdatastatus")}),i.trackerHub.on("statusChangeNotified",function(e){null==e.DesktopDeviceId?console.log("[SIGNALR] [ERROR] (on)statusChangeNotified - UserRealTimeData has NULL DesktopID. Not updating state! UserID: "+e.UserId+" DesktopID: "+e.DesktopDeviceId+" Status: "+e.CurrentStatusEnum):(i.saveInDictionaryForFurtherUse(e),i.userStateChanged.next(e))}),i.trackerHub.on("someThingWentWrong",function(e){console.log(e)}),i.trackerHub.on("getUserLiveLocation",function(e){null==e.UserId?console.log("[SIGNALR] [ERROR] (on)getUserLiveLocation - UserRealTimeLocationData has NULL DesktopID. Not updating state! UserID: "+e.UserId+" DesktopID: "+e.MobileDeviceId+" Status: "+e.Latitude):(i.saveUserLocationInDictionaryForFurtherUse(e),i.userLocationChanged.next(e))}),i.trackerHub.on("getRunningRecordDetails",function(e){null==e.UserId?console.log("[SIGNALR] [ERROR] (on)getRunningRecordDetails has NULL UserId. Not updating state! UserID: "+e.UserId):i.getRunningRecord.next(e)}),i.hubConnection.start().done(function(){console.log("[SIGNALR] connectionEstablished.hubConnection.start() on hubConnection Done - Actual status is "+i.hubConnection.state)}).fail(function(){i.connectionInProgress=!1,i.signalRconnectionInProgress.next(!1),i.signalRHubConnectionError.next(!0),console.log("connection failed")}))):console.log("[SIGNALR] establishSignalrConnection skipped as connectionInProgress = true")},U.prototype.getConnectionState=function(e){switch(console.log("HubConnectionState changed from "+e.oldState+" to "+e.newState),e.newState){case C.Connecting:return C.Connecting;case C.Connected:return C.Connected;case C.Reconnecting:return C.Reconnecting;case C.Disconnected:return C.Disconnected;default:return C.Connecting}},U.prototype.isSignalRConnected=function(){return null!=this.hubConnection&&this.hubConnection.state==C.Connected},U.prototype.ngOnDestroy=function(){this.userStateChanged.complete(),this.signalRconnectionInProgress.complete(),this.signalRHubConnectionError.complete(),this.officeTvFilter.complete(),this.autoUserCreatedDetection.complete(),this.adminSettingsChanged.complete(),this.testAutomationChanged.complete(),this.clearRealTimeStatusDictionary(),this.disconnect()},U.prototype.clearRealTimeStatusDictionary=function(){this.userRealTimeStatusDictionary=new T,this.allreferenceIds=[]},U.prototype.disconnect=function(){if(this.hubConnection&&this.hubConnection.state!==C.Disconnected)try{this.hubConnection.stop(!0,!0)}catch(e){console.log(e)}},U.prototype.saveInDictionaryForFurtherUse=function(e){e&&e.DesktopDeviceId&&(console.log("saving "+e.DesktopDeviceId+" into dictionary for further use"),this.userRealTimeStatusDictionary.add(e.DesktopDeviceId,e))},U.prototype.saveUserLocationInDictionaryForFurtherUse=function(e){e&&e.UserId&&(console.log("saving "+e.UserId+" into dictionary for further use"),this.userRealTimeLocationDictionary.add(e.UserId,e))},U.prototype.getCurrentUserStatusFromDictionary=function(e){return this.userRealTimeStatusDictionary.getItem(e)},U.prototype.getStatusChangesForUsers=function(e){var t=this,o=!1;e.forEach(function(n){null!=n&&""!=n&&t.checkIfValidGUID(n)&&-1==t.allreferenceIds.findIndex(function(e){return e==n})&&null==t.userRealTimeStatusDictionary.getItem(n)&&(t.allreferenceIds.push(n),o=!0),t.userRealTimeStatusDictionary.getItem(n)&&t.userStateChanged.next(t.userRealTimeStatusDictionary.getItem(n))}),this.canViewLiveStatus&&o&&(this.newIdsToPushWhenConnected=!0,this.invokeStatusChanges(e))},U.prototype.invokeStatusChanges=function(e){var n=this;if(this.isSignalRConnected()&&this.newIdsToPushWhenConnected){if(0<this.allreferenceIds.length)try{var t=this.allreferenceIds.join(";");null!=e&&(t=e.join(";")),console.log("referenceIds - "+t),this.trackerHub.invoke("GetMeStatusChangesForUsers",t,n.companyId).done(function(){console.log("sent GetMeStatusChangesForUsers request with userIds and siteaddress- "+t+"companyId"+n.companyId),this.newIdsToPushWhenConnected=!1}).fail(function(){console.log("GetMeStatusChangesForUsers request failed")})}catch(o){console.log(o)}}else console.log("[SIGNALR] invokeStatusChange skipped as not connected")},U.prototype.initialise=function(){console.log("[SIGNALR] Initalise Called"),this.userStateChanged=new r.EventEmitter,this.officeTvFilter=new r.EventEmitter,this.autoUserCreatedDetection=new r.EventEmitter,this.adminSettingsChanged=new r.EventEmitter,this.loggedInUserId=JSON.parse(localStorage.getItem(h)).id,this.companyId=JSON.parse(localStorage.getItem(h)).companyId,this.environment=JSON.parse(localStorage.getItem(u)),this.connectionInProgress=!1,this.canViewLiveStatus=!1,this.retryConnecting=0,this.allreferenceIds=[],(JSON.parse(localStorage.getItem(g))!=undefined&&null!=JSON.parse(localStorage.getItem(g))?JSON.parse(localStorage.getItem(g)):this.environment.apiURL)!=this.apiURL?this.restartSignalRConnection():this.establishConnectionWithRealTimeHub(),console.log("[SIGNALR] Initalise Finished")},U.prototype.restartSignalRConnection=function(){this.hubConnection=null,this.trackerHub=null,this.apiURL=JSON.parse(localStorage.getItem(g))!=undefined&&null!=JSON.parse(localStorage.getItem(g))?JSON.parse(localStorage.getItem(g)):this.environment.apiURL,this.userRealTimeStatusDictionary=new T,this.userRealTimeLocationDictionary=new T,this.establishConnectionWithRealTimeHub()},U.prototype.checkIfValidGUID=function(e){return/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi.test(e)},U.prototype.getUserIdsFromOfficeTvFilters=function(e){var n=this;console.log("restarting the already existing connection 1"),n.hubConnection.start().done(function(){console.log("[SIGNALR] hubConnection.Start().Done - hub already existed"),n.trackerHub.invoke("StatusFilterForOfficeTv",e,n.companyId).done(function(e){n.officeTvFilter.next(e)})}).fail(function(){n.connectionInProgress=!1,n.signalRconnectionInProgress.next(!1),n.signalRHubConnectionError.next(!0),console.log("connection failed")})},U.prototype.getLocationChangeForUsers=function(e){var t=this,o=!1,i=!1;e.forEach(function(n){null!=n&&""!=n&&t.checkIfValidGUID(n)&&-1==t.referenceIdsForLocation.findIndex(function(e){return e==n})&&null==t.userRealTimeLocationDictionary.getItem(n)&&(t.referenceIdsForLocation.push(n),o=!0),t.userRealTimeLocationDictionary.getItem(n)&&(t.userLocationChanged.next(t.userRealTimeLocationDictionary.getItem(n)),i=!0)}),!o&&i||(this.newIdsToPushWhenConnected=!0,this.invokeLocationChanges(e))},U.prototype.invokeLocationChanges=function(e){var n=this;if(this.isSignalRConnected()&&this.newIdsToPushWhenConnected){if(0<this.referenceIdsForLocation.length)try{var t=(null!=e?e:this.referenceIdsForLocation).join(";");console.log("referenceIds - "+t),console.log("The Reference Id's Count",this.referenceIdsForLocation.length),this.trackerHub.invoke("GetUserLiveLocation",t,n.companyId).done(function(){console.log("sent GetUserLiveLocation request with userIds and siteaddress- "+t+"companyId"+n.companyId),this.newIdsToPushWhenConnected=!1}).fail(function(){console.log("GetUserLiveLocation request failed")})}catch(o){console.log(o)}}else console.log("[SIGNALR] invokeStatusChange skipped as not connected")},U.prototype.getTestAutomationForUsers=function(e){var t=this,o=!1;e.forEach(function(n){null!=n&&""!=n&&t.checkIfValidGUID(n)&&-1==t.referenceIdsForTestAutomation.findIndex(function(e){return e==n})&&(t.referenceIdsForTestAutomation.push(n),o=!0)}),o&&(this.newIdsToPushWhenConnected=!0,this.invokeTestAutomationSubscription(e))},U.prototype.invokeTestAutomationSubscription=function(e){var n=this;if(this.isSignalRConnected()&&this.newIdsToPushWhenConnected){if(0<this.referenceIdsForTestAutomation.length)try{var t=(null!=e?e:this.referenceIdsForTestAutomation).join(";");console.log("TestAutomation referenceIds - "+t),this.trackerHub.invoke("SubscribeToTestAutomation",t,n.companyId).done(function(){console.log("sent SubscribeToTestAutomation request with userIds - "+t+" companyId "+n.companyId),this.newIdsToPushWhenConnected=!1}).fail(function(){console.log("SubscribeToTestAutomation request failed")})}catch(o){console.log(o)}}else console.log("[SIGNALR] invokeTestAutomationSubscription skipped as not connected")},U.prototype.invokeTaskSelectionChanged=function(e){if(this.isSignalRConnected())try{console.log("The Selected User Id : ",e),this.trackerHub.invoke("TaskSelectionChanged",JSON.stringify(e)).done(function(){console.log("sent invokeTaskSelectionChanged request with required hub data"+JSON.stringify(e))}).fail(function(){console.log("invokeTaskSelectionChanged request failed")})}catch(n){console.log(n)}else console.log("[SIGNALR] invokeTaskSelectionChanged skipped as not connected")},U.prototype.sendUserConfiguration=function(e){var t=this,o=!1;e.forEach(function(n){null!=n&&""!=n&&t.checkIfValidGUID(n)&&-1==t.referenceIdsForLocation.findIndex(function(e){return e==n})&&(t.referenceIdsForUserConfiguration.push(n),o=!0)}),o&&(this.newIdsToPushWhenConnected=!0,this.invokeUserConfiguration())},U.prototype.invokeUserConfiguration=function(){var e=this;if(this.isSignalRConnected()&&this.newIdsToPushWhenConnected){if(0<this.referenceIdsForUserConfiguration.length)try{var n=this.referenceIdsForUserConfiguration.join(";");console.log("referenceIds - "+n),console.log("The Reference Id's Count",this.referenceIdsForUserConfiguration.length),this.trackerHub.invoke("UpdateUserConfigurationInJobSite",n,e.companyId).done(function(){console.log("sent UpdateUserConfigurationInJobSite request with userIds and siteaddress- "+n+"companyId"+e.companyId),this.newIdsToPushWhenConnected=!1,this.referenceIdsForUserConfiguration=[]}).fail(function(){console.log("UpdateUserConfigurationInJobSite request failed")})}catch(t){console.log(t)}}else console.log("[SIGNALR] invokeStatusChange skipped as not connected")},U.prototype.getRunningRecordData=function(e){var t=this;e.forEach(function(n){null!=n&&""!=n&&t.checkIfValidGUID(n)&&-1==t.referenceIdForTaskTimer.findIndex(function(e){return e==n})&&(n+="-signalr",t.referenceIdForTaskTimer.push(n))}),0<this.referenceIdForTaskTimer.length&&(this.newIdsToPushWhenConnected=!0,this.subScribeForRecordChanges(e))},U.prototype.invokeGetRunningRecordMethod=function(e){var n=this;if(this.isSignalRConnected()&&this.newIdsToPushWhenConnected){if(null!=e.UserId)try{var t=e.UserId;this.trackerHub.invoke("GetRunningRecordDetails",e).done(function(){console.log("sent GetRunningRecordDetails request with userIds and siteaddress- "+t+"companyId"+n.companyId),this.newIdsToPushWhenConnected=!1,this.referenceIdForTaskTimer=[]}).fail(function(){console.log("GetRunningRecordDetails request failed")})}catch(o){console.log(o)}}else console.log("[SIGNALR] invokeStatusChange skipped as not connected"),this.RetryUntilConnectedToGetRunningRecordDetails(e)},U.prototype.subScribeForRecordChanges=function(e){var n=this;if(this.isSignalRConnected()&&this.newIdsToPushWhenConnected){if(0<this.referenceIdForTaskTimer.length)try{var t=(null!=e?e:this.referenceIdForTaskTimer).join(";");this.trackerHub.invoke("SubScribeForRecordChanges",t).done(function(){console.log("sent SubScribeForRecordChanges request with userIds and siteaddress- "+t+"companyId"+n.companyId),this.newIdsToPushWhenConnected=!1,this.referenceIdForTaskTimer=[]}).fail(function(){console.log("SubScribeForRecordChanges request failed")})}catch(o){console.log(o)}}else console.log("[SIGNALR] invokeStatusChange skipped as not connected")},U.prototype.RetryUntilConnectedToGetRunningRecordDetails=function(i){return S(this,void 0,void 0,function(){var n,t,o;return v(this,function(e){switch(e.label){case 0:n=10,t=0,o=500,e.label=1;case 1:if(t<n){if(!this.isSignalRConnected())return[3,2];console.log("[SIGNALR] Connection established"),this.invokeGetRunningRecordMethod(i)}return[3,5];case 2:return console.log("[SIGNALR] Waiting for connection... Attempt "+(t+1)),t++,[4,this.delay(o)];case 3:e.sent(),o*=2,e.label=4;case 4:return[3,1];case 5:return t===n&&console.log("[SIGNALR] Max retries reached. Exiting..."),[2]}})})};var L=U;function U(){this.userStateChanged=new r.EventEmitter,this.userLocationChanged=new r.EventEmitter,this.signalRconnectionInProgress=new r.EventEmitter,this.signalRHubConnectionError=new r.EventEmitter,this.officeTvFilter=new r.EventEmitter,this.autoUserCreatedDetection=new r.EventEmitter,this.adminSettingsChanged=new r.EventEmitter,this.getRunningRecord=new r.EventEmitter,this.testAutomationChanged=new r.EventEmitter,this.referenceIdsForTestAutomation=[],this.hubConnection=null,this.connectionInProgress=!1,this.canViewLiveStatus=!1,this.newIdsToPushWhenConnected=!1,this.trackerHub=null,this.retryConnecting=0,this.environment=JSON.parse(localStorage.getItem(u)),this.apiURL=JSON.parse(localStorage.getItem(g))!=undefined&&null!=JSON.parse(localStorage.getItem(g))?JSON.parse(localStorage.getItem(g)):this.environment.apiURL,this.allreferenceIds=[],this.referenceIdsForLocation=[],this.referenceIdsForUserConfiguration=[],this.referenceIdForTaskTimer=[],this.userRealTimeStatusDictionary=new T,this.userRealTimeLocationDictionary=new T,this.userRealTimeStatusDictionary=new T,this.allreferenceIds=[],this.randomId=n.Guid.create().toString()}w.prototype.intercept=function(e,n){var t=JSON.parse(localStorage.getItem(u)),o=localStorage.getItem("CurrentUser"),i=this.cookieService.get(c);return"null"!==i&&"undefined"!==i||(i="en"),o&&(e=e.clone({setHeaders:{Authorization:"Bearer "+o,CurrentCulture:null!=i&&""!=i?i:"en"}})),!t.production&&t.useTestAuthenticator&&(e=e.clone({setHeaders:{Authorization:"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1laWQiOiIxMjcxMzNmMS00NDI3LTQxNDktOWRkNi1iMDJlMGUwMzY5NzEiLCJDb21wYW55IjoiNGFmZWI0NDQtZTgyNi00Zjk1LWFjNDEtMjE3NWUzNmEwYzE2IiwiaXNzIjoiaHR0cDovL215LnRva2VuaXNzdWVyLmNvbSIsImF1ZCI6Imh0dHA6Ly9teS53ZWJzaXRlLmNvbSIsImV4cCI6MTk4MjA4MTI0NywibmJmIjoxNTUwMDg0ODQ3fQ.yUHRfy1aCW9F_CvbBZmuK-mOWf5YrftathYJ0HYjd6Q"}})),n.handle(e)},w.decorators=[{type:r.Injectable}],w.ctorParameters=function(){return[{type:i.CookieService}]};var D=w;function w(e){this.cookieService=e}E.prototype.establishConnectionWithHYDAHub=function(){return S(this,void 0,void 0,function(){return v(this,function(e){switch(e.label){case 0:console.log("[HYDA SignalR] Connection method called"),e.label=1;case 1:return null!=localStorage.getItem(d)&&localStorage.getItem(d)!=undefined?this.canViewLiveStatus="true"==localStorage.getItem(d):this.canViewLiveStatus=!1,null!=localStorage.getItem(f)&&localStorage.getItem(f)!=undefined&&(this.apiURL=localStorage.getItem(f),console.log("[SIGNALR] Setting API URL: "+this.apiURL)),console.log("Hyda SignalRBasePath",localStorage.getItem(f)),this.canViewLiveStatus?this.checkConnectionWithHYDAHub(!1):this.disconnect(),[4,this.delay(6e3)];case 2:return e.sent(),[3,1];case 3:return[2]}})})},E.prototype.checkConnectionWithHYDAHub=function(e){e||3<this.retryConnecting||0==this.connectionInProgress&&(null==this.hubConnection||this.hubConnection==undefined||this.hubConnection.state==R)?(this.retryConnecting=0,this.establishSignalrConnection()):this.hubConnection.state==b||this.hubConnection.state==m?(console.log("connection is in connecting state on retry "+this.retryConnecting),this.retryConnecting=this.retryConnecting+1):(this.retryConnecting=0,console.log("stable connection already exist"))},E.prototype.establishSignalrConnection=function(){return S(this,void 0,void 0,function(){var n,t=this;return v(this,function(e){switch(e.label){case 0:return this.hubConnection?this.isSignalRConnected()?[3,2]:[4,this.hubConnection.start().then(function(){console.log("Connection Established successfully"),t.checkIfValidGUID(t.loggedInUserId)&&t.invokeTestAutomationSubscription(t.loggedInUserId),t.connectionInProgress=!1})["catch"](function(){console.log("Connection Disconnected"),t.hubConnection=null})]:[3,2];case 1:e.sent(),e.label=2;case 2:if(this.connectionInProgress)return console.log("[SIGNALR CORE] Connection already in progress, skipping."),[2];if(this.connectionInProgress=!0,this.hubConnection&&this.hubConnection.state===y)return console.log("[SIGNALR CORE] Already connected, skipping connection."),this.connectionInProgress=!1,[2];console.log("[SIGNALR CORE] Creating and starting new hub connection..."),this.hubConnection=(new a.HubConnectionBuilder).withUrl(this.apiURL+"HYDA").configureLogging(a.LogLevel.Trace).build(),this.hubConnection.on("TestAutomation",function(e){t.testAutomationChanged.next(e),console.log(e,"testautomationdatastatus")}),this.hubConnection.on("someThingWentWrong",function(e){console.error("[SIGNALR CORE]",e)}),e.label=3;case 3:return e.trys.push([3,5,,6]),[4,this.hubConnection.start().then(function(){return console.log("Connected via LongPolling")})["catch"](function(e){return console.error("Connection failed: ",e)})];case 4:return e.sent(),console.log("[HYDA SignalR] Connection established successfully"),this.checkIfValidGUID(this.loggedInUserId)&&this.invokeTestAutomationSubscription(this.loggedInUserId),this.connectionInProgress=!1,[3,6];case 5:return n=e.sent(),console.error("[HYDA SignalR] Connection failed",n),this.connectionInProgress=!1,[3,6];case 6:return this.hubConnection.onclose(function(e){console.log("Connection closed:",e)}),[2]}})})},E.prototype.initialize=function(){console.log("[HYDA SIGNALR] Initalise Called"),this.loggedInUserId=JSON.parse(localStorage.getItem(h)).id,this.companyId=JSON.parse(localStorage.getItem(h)).companyId,this.environment=JSON.parse(localStorage.getItem(u)),this.connectionInProgress=!1,this.canViewLiveStatus=!1,this.retryConnecting=0,(localStorage.getItem(f)||this.environment.apiURL)!=this.apiURL?this.restartSignalRConnection():this.establishConnectionWithHYDAHub(),console.log("[SIGNALR] Initalise Finished")},E.prototype.restartSignalRConnection=function(){this.hubConnection=null,this.apiURL=localStorage.getItem(f)||this.environment.apiURL,this.establishConnectionWithHYDAHub()},E.prototype.checkIfValidGUID=function(e){return/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi.test(e)},E.prototype.invokeTestAutomationSubscription=function(t){return S(this,void 0,void 0,function(){var n;return v(this,function(e){switch(e.label){case 0:if(!this.isSignalRConnected())return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.hubConnection.invoke("SubscribeToTestAutomation",t)];case 2:return e.sent(),console.log("[HYDA SignalR] Sent SubscribeToTestAutomation request: "+t),[3,4];case 3:return n=e.sent(),console.error("[HYDA SignalR] SubscribeToTestAutomation failed",n),[3,4];case 4:return[3,6];case 5:console.log("[HYDA SignalR] invokeTestAutomationSubscription skipped as SignalR not connected"),e.label=6;case 6:return[2]}})})},E.prototype.delay=function(n){return new Promise(function(e){return setTimeout(e,n)})},E.prototype.isSignalRConnected=function(){return null!=this.hubConnection&&this.hubConnection.state==a.HubConnectionState.Connected},E.prototype.disconnect=function(){return S(this,void 0,void 0,function(){var n;return v(this,function(e){switch(e.label){case 0:if(!this.hubConnection||this.hubConnection.state===a.HubConnectionState.Disconnected)return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.hubConnection.stop()];case 2:return e.sent(),console.log("[HYDA SignalR] Disconnected successfully"),[3,4];case 3:return n=e.sent(),console.error(n),[3,4];case 4:return[2]}})})},E.prototype.ngOnDestroy=function(){this.testAutomationChanged.complete(),this.disconnect()},E.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],E.ctorParameters=function(){return[]},E.ngInjectableDef=r.defineInjectable({factory:function(){return new E},token:E,providedIn:"root"});var A=E;function E(){this.testAutomationChanged=new r.EventEmitter,this.hubConnection=null,this.connectionInProgress=!1,this.canViewLiveStatus=!1,this.retryConnecting=0,this.environment=JSON.parse(localStorage.getItem(u)),this.apiURL=localStorage.getItem(f)||this.environment.apiURL}function H(){}H.forRoot=function(){return{ngModule:H,providers:[L,A,p,{provide:s.HTTP_INTERCEPTORS,useClass:D,multi:!0}]}},H.decorators=[{type:r.NgModule,args:[{}]}],e.SnovaSharedModule=H,e.RealTimeSignalRHub=L,e.SidenavUiService=p,e.RealTimeSignalRCoreHub=A,e.ɵa=D,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=snovasys-snova-shared-components.umd.min.js.map