(function(b,d){var a={};if("object"==typeof b&&(a=b,b=a.mode,!b))throw Error("Missing mode in setUI({...})");var f=!0;global.WIDGETS&&WIDGETS.back&&(f=!1,WIDGETS.back.remove(b&&a.back));Bangle.btnWatches&&(Bangle.btnWatches.forEach(clearWatch),delete Bangle.btnWatches);Bangle.swipeHandler&&(Bangle.removeListener("swipe",Bangle.swipeHandler),delete Bangle.swipeHandler);Bangle.touchHandler&&(Bangle.removeListener("touch",Bangle.touchHandler),delete Bangle.touchHandler);delete Bangle.uiRedraw; delete Bangle.CLOCK;if(Bangle.uiRemove){let c=Bangle.uiRemove;delete Bangle.uiRemove;c()}g.reset();if(b){if("updown"==b)Bangle.btnWatches=[setWatch(function(){d(-1)},BTN1,{repeat:1,edge:"falling"}),setWatch(function(){d(1)},BTN3,{repeat:1,edge:"falling"}),setWatch(function(){d()},BTN2,{repeat:1,edge:"falling"})];else if("leftright"==b)Bangle.btnWatches=[setWatch(function(){d(-1)},BTN1,{repeat:1,edge:"falling"}),setWatch(function(){d(1)},BTN3,{repeat:1,edge:"falling"}),setWatch(function(){d()},BTN2, {repeat:1,edge:"falling"})],Bangle.swipeHandler=c=>{d(c)},Bangle.on("swipe",Bangle.swipeHandler),Bangle.touchHandler=c=>{d()},Bangle.on("touch",Bangle.touchHandler);else if("clock"==b)Bangle.CLOCK=1,Bangle.btnWatches=[setWatch(Bangle.showLauncher,BTN2,{repeat:1,edge:"falling"})];else if("clockupdown"==b)Bangle.CLOCK=1,Bangle.btnWatches=[setWatch(function(){d(-1)},BTN1,{repeat:1,edge:"falling"}),setWatch(function(){d(1)},BTN3,{repeat:1,edge:"falling"}),setWatch(Bangle.showLauncher,BTN2,{repeat:1,edge:"falling"})]; else if("custom"==b)a.clock&&(Bangle.CLOCK=1),a.touch&&(Bangle.touchHandler=a.touch,Bangle.on("touch",Bangle.touchHandler)),a.swipe&&(Bangle.swipeHandler=a.swipe,Bangle.on("swipe",Bangle.swipeHandler)),a.btn?Bangle.btnWatches=[setWatch(function(){a.btn(1)},BTN1,{repeat:1,edge:"falling"}),setWatch(function(){a.btn(2)},BTN2,{repeat:1,edge:"falling"}),setWatch(function(){a.btn(3)},BTN3,{repeat:1,edge:"falling"})]:a.clock&&(Bangle.btnWatches=[setWatch(Bangle.showLauncher,BTN2,{repeat:1,edge:"falling"})]); else throw Error("Unknown UI mode "+E.toJS(b));a.remove&&(Bangle.uiRemove=a.remove);a.redraw&&(Bangle.uiRedraw=a.redraw);if(a.back){var h=c=>{1==c&&a.back()};Bangle.on("touch",h);var e;void 0===Bangle.btnWatches&&(e=setWatch(function(){e=void 0;a.back()},BTN3,{edge:"falling"}));WIDGETS=Object.assign({back:{area:"tl",width:24,draw:c=>g.reset().setColor("#f00").drawImage(atob("GBiBAAAYAAH/gAf/4A//8B//+D///D///H/P/n+H/n8P/n4f/vwAP/wAP34f/n8P/n+H/n/P/j///D///B//+A//8Af/4AH/gAAYAA=="),c.x,c.y),remove:c=> {e&&clearWatch(e);Bangle.removeListener("touch",h);c||g.reset().clearRect({x:WIDGETS.back.x,y:WIDGETS.back.y,w:24,h:24});delete WIDGETS.back;c||Bangle.drawWidgets()}}},global.WIDGETS);f&&Bangle.drawWidgets()}}})