define(["browser","appSettings","events"],function(browser,appSettings,events){"use strict";function setLayout(instance,layout,selectedLayout){layout===selectedLayout?(instance[layout]=!0,document.documentElement.classList.add("layout-"+layout)):(instance[layout]=!1,document.documentElement.classList.remove("layout-"+layout))}function LayoutManager(){}return LayoutManager.prototype.setLayout=function(layout,save){layout&&"auto"!==layout?(setLayout(this,"mobile",layout),setLayout(this,"tv",layout),setLayout(this,"desktop",layout),!1!==save&&appSettings.set("layout",layout)):(this.autoLayout(),!1!==save&&appSettings.set("layout","")),events.trigger(this,"modechange")},LayoutManager.prototype.getSavedLayout=function(layout){return appSettings.get("layout")},LayoutManager.prototype.autoLayout=function(){this.setLayout(this.getDefaultLayout(),!1)},LayoutManager.prototype.getDefaultLayout=function(){if(this.getPlatformDefaultLayout){var result=this.getPlatformDefaultLayout();if(result)return result}return browser.xboxOne||browser.ps4||browser.chromecast||browser.netcast||browser.operaTv?"tv":function(){for(var terms=["mobi","ipad","iphone","ipod","silk","gt-p1000","nexus 7","kindle fire","opera mini"],lower=navigator.userAgent.toLowerCase(),i=0,length=terms.length;i<length;i++)if(-1!==lower.indexOf(terms[i]))return!0;return!1}()?"mobile":browser.tv?"tv":function(){try{if(window.matchMedia("(pointer: coarse)").matches)return!0;if(window.matchMedia("(pointer: fine)").matches)return!1;if(window.matchMedia("(pointer: none)").matches)return!1}catch(err){console.log("error using window.matchMedia")}return"ontouchstart"in document.documentElement}()?"mobile":self.Dashboard?"desktop":"tv"},LayoutManager.prototype.init=function(){var saved=this.getSavedLayout();saved?this.setLayout(saved,!1):this.autoLayout()},new LayoutManager});