(()=>{function e(c,u,n){var a="userPreferences";function r(e,r){e=t(e,r);return o(r,e).then(_.partial(i,e))}function t(e,r){return e+r.userName.replace(/\./g,"__")}function o(e,r){var n;return s(e)?u.list({fragmentType:r}).then(function(e){return e.length?e[0]:{type:"c8y_UserPreference"}}):(e=h(),(n={})[r]=e[r],c.when(n))}function i(e,r){return r[e]}function f(e,r,n){e=t(e,n);return o(n,e).then(_.partial(l,e,r,n))}function l(e,r,n,t){return s(n)?(t[e]=r,u.save(t)):((n=h())[e]=r,window.localStorage.setItem(a,JSON.stringify(n)),c.resolve())}function s(e){return n.hasRole(e,"ROLE_INVENTORY_READ")&&n.hasRole(e,"ROLE_INVENTORY_ADMIN")||n.hasRole(e,"ROLE_MANAGED_OBJECT_READ")&&n.hasRole(e,"ROLE_MANAGED_OBJECT_ADMIN")}function h(){var r=window.localStorage.getItem(a);try{r=JSON.parse(r)}catch(e){r={}}return r||{}}return{get:function(e){return n.current().then(_.partial(r,e))},set:function(e,r){return n.current().then(_.partial(f,e,r))}}}e.$inject=["$q","c8yInventory","c8yUser"],angular.module("c8y.core").factory("c8yUserPreferences",e)})();