angular.module("mystrom.tiles.services",[]).factory("tileService",["$http","$filter","$interval","api","$q","$translate",function(e,t,n,i,a,c){function r(e){_.isUndefined(U)||angular.forEach(e.data.devices,function(e){var t=h(e.id);_.isNull(t)||(e.frontface=t.frontface)}),U=e,R=e.data.devices.length,k=0,c("EnergySwitch").then(function(e){for(var t=new RegExp("^"+e+"\\s?[0-9]*$"),n=0;n<U.data.devices.length;n++)if(t.test(U.data.devices[n].name)){var i=U.data.devices[n].name.split(" ");if(i.length===e.split(" ").length+1){var a=parseInt(i[e.split(" ").length]);k=a>k?a:k}else 0===k&&(k=1)}})}function d(){return i.get(i.baseURL+"devices",{params:{totalReport:!0,alert:!0,report:!0,checkFirmware:!0}})}function s(e){return i.get(i.baseURL+"device/switch",{params:e})}function o(e){return i.get(i.baseURL+"setDeviceProperties",{params:e})}function l(e){return i.get(i.baseURL+"device/register",{params:e})}function u(e){return i.get(i.baseURL+"device/remove",{params:e}).then(function(){var t=_.findIndex(U.data.devices,{id:e.id});-1!==t&&U.data.devices.splice(t,1)})}function v(e,t){var n=_.findIndex(U.data.devices,{id:t.id}),i=_.findLastIndex(U.data.devices,{name:e});return-1!==n&&-1!==i&&n!==i||-1===n&&-1!==i?!0:!1}function f(e,t){E.push({deviceTypeId:"new-adapter",name:"SwitchDetected",icons:[],ribbon:{color:"#dd1122",text:t,size:120},activationCode:e})}function m(e){var t=_.findIndex(E,{activationCode:e});-1!=t&&E.splice(t,1)}function g(e,t){console.log("Generate tiles for:"),console.log(e),E.splice(0,E.length);for(var n=0,i=e.length;i>n;n++)-1==_.findIndex(E,{activationCode:e[n]})&&f(e[n],t)}function p(){R=U.data.devices.length;var e=U.data.devices.concat(E);return e=e.concat(B),e[e.length-4].text=U.data.energyReport.power,e}function y(){return U}function h(e){for(var t=0;t<U.data.devices.length;t++)if(U.data.devices[t].id===e)return U.data.devices[t];return null}function T(){return R}function b(e){q=e}function S(e){z=e}function I(e,t,n){L.name=e,L.icon=t,L.blockSwitchingOff=n}function x(){return q}function w(){return z}function C(){return k}function D(){return L}var U,O,q,z,M=null,R=0,k=0,L={name:"",icon:""},B=[{tileType:!1,deviceTypeId:!1,name:"TotalConsumption",text:"1000",subindex:"W",icons:[]},{deviceTypeId:"add",name:"AddSwitch",icons:[]},{deviceTypeId:"mystromsettings",name:"MyStromSettings",icons:[]},{deviceTypeId:"buy",name:"BuySwitches",icons:[]}],E=[],N=[{deviceTypeId:"scheduler",name:"Scheduler"},{deviceTypeId:"graphs",name:"Graphs"},{deviceTypeId:"devicesettings",name:"DeviceSettings",ribbon:{color:"#dd1122",text:"",size:120}}],P=[{deviceTypeId:"priceplans",name:"PricePlans"},{deviceTypeId:"help",name:"Help"}],$=["tJF1WKsm0oPinYdj","mgcSLEtmj6kDNvb2","SDFbs6Ab0Ryd6mtq","mq6LmfsGtZqQlr85","DOTP26oEoY0bMRkq","qvjq297mYk21Mcic","h0Mb3IgcygBl1PzN","ykjY2LfG7Ks2Luxy","qCghXQ1SMW0tmVyS","KeCWzkm1Cmbpf7gM","9COiuwdkbGE6FpNy","M7t3UEfRyH8M3PGV","fCjSO3eK3bvViUft","a10z8IfmnXAUzlhT","OSUsUqPaXO96e4uS","9BdpBUB7MCoGIg1S","bHx7qxyms1WAybb1","MqFl6Dzd8CliKyjg","wElVDxalcBXzbQSZ","oxtVohvvzy9MrjVU"];return{getTiles:p,getDeviceTiles:y,setTiles:r,syncTiles:d,setState:s,setParams:o,registerDevice:l,removeDevice:u,addDynamicTile:f,removeDynamicTile:m,generateAddTiles:g,getTile:h,staticTiles:B,dynamicTiles:E,settingsTiles:N,mystromSettingsTiles:P,activeTile:O,allowedIcons:$,interval:M,getSwitchCount:T,checkDuplicateName:v,setOldName:b,setOldIcon:S,getOldName:x,getOldIcon:w,getEnergyNameCount:C,setOldTile:I,getOldTile:D}}]).factory("stateService",["$state","$ionicNavBarDelegate","$ionicHistory",function(e,t){function n(n,i,a){return t.showBackButton(a),e.go(n,i)}function i(e){r=e}function a(){return r}var c,r=!1;return{modal:c,goState:n,setWizardCompleted:i,getWizardCompleted:a}}]);