var UR=UR||{};UR.render={widgets:{3:"Button",4:"Label",5:"List",6:"Item",7:"Slider",8:"Action",9:"Message",10:"Dialog",11:"Input",12:"Orb",13:"Image",14:"Text",15:"Toggle",16:"TOrb",17:"Touch",20:"Tab",21:"Row",22:"Tabs",23:"Space",24:"Area"},classname:function(a){return"remote-"+(a||"").toLowerCase()},toAction:function(d,a){var b=UR.render.widgets[d.Type];var c=_.cloneDeep(d);c.Type=b;c.Debug=d.Type+" -> "+b;c.Class=UR.render.classname(b);c.TabId=a;if(d.Icon!==undefined){c.Icon=UR.icons.resolveFa(d.Icon)}if(d.Text!==undefined){c.Text=d.Text}return c},flattenLayout:function(j){var h=[[]];var e="Tab";var a="Row";var g="Tabs";var l="Space";var b=["Button","Label","Slider","Image","Toggle"];var c;var k=0;c=function(n,i){_.forEach(n.Children,function(p){var o=UR.render.widgets[p.Type];if(o===g){c(p,true);return}if(o===e&&i){k++}if(o===a||o===e){h.push([]);c(p,false);return}if(o!==l){h[h.length-1].push(UR.render.toAction(p,k))}})};if(j.Default!==undefined){c(j.Default,false)}else{tip("No layout for this remote")}var m={};_.forEach(h,function(i){_.forEach(i,function(p){var n=m[p.TabId];var o=_.union(n,[p.Type]);m[p.TabId]=$(o).not(b).get()})});var f=0;var d=h;d=_.chain(d).filter(function(i){return _.any(i,function(n){var o=m[n.TabId];return(_.isEmpty(i)||_.isEmpty(o))})}).map(function(i){f++;return{Actions:i,Name:"Group::"+f,GroupId:f}}).value();return{Groups:d}},getWidgetElement:function(a){return $("#"+a.ID)},getIconElement:function(a){return a.children(".remote-icon")},getImageElement:function(a){return a.children(".remote-image")},getTextElement:function(a){return a.children(".remote-text")},getSliderElement:function(a){return a.children("input[type=range]")},getSliderTextElement:function(a){return a.children("center").children(".remote-slider-text")},getSliderValueTextElement:function(a){return a.children("center").children(".remote-slider-value-text")},bindHold:function(c,a){if(!(c||{}).OnHold){return}var b=UR.render.getWidgetElement(c);b.bind("taphold",a)},setSliderMaxProgress:function(c){var b=UR.render.getWidgetElement(c);var a=UR.render.getSliderElement(b);a.attr("max",c.ProgressMax)},setSliderProgress:function(i){var e=UR.render.getWidgetElement(i);var d=UR.render.getSliderElement(e);d.val(i.Progress);try{var a=parseFloat(d.attr("max"));var b=(100*i.Progress)/a;var g=Math.round(b);var c=UR.render.getSliderValueTextElement(e);c.text(" - "+g+"%")}catch(f){}},setSliderText:function(b){var a=UR.render.getWidgetElement(b);UR.render.getSliderTextElement(a).text(b.Text)},setText:function(b){var a=UR.render.getWidgetElement(b);UR.render.getTextElement(a).text(b.Text)},setIcon:function(d){var c=UR.render.getWidgetElement(d);var b=UR.render.getIconElement(c);var a=UR.icons.resolveFa(d.Icon);b.attr("class","");b.addClass("remote-icon");b.addClass(a)},setChecked:function(c,b){var a=UR.render.getWidgetElement(c);if(b){a.removeClass("raised");a.attr("data-down","yes")}else{a.addClass("raised");a.attr("data-down","no")}},isChecked:function(b){var a=UR.render.getWidgetElement(b);return a.attr("data-down")==="yes"},setImage:function(c){var b=UR.render.getWidgetElement(c);var a=UR.render.getImageElement(b);a.attr("src","data:image/jpg;base64,"+c.Image)},nl2br:function(a){return a.replace(/(\r\n|\n\r|\r|\n)/g,"<br>")},br2nl:function(a){return a.replace(/<br>/g,"\n")},prettyRows:function(a){var b=_.first(a.Groups);var c=(_.first((b||{}).Actions)||{}).TabId;_.forEach(a.Groups,function(g){if((g.Actions||[]).length<=1){return}var e=["Button","Label","Toggle"];var h=_.any(g.Actions,function(i){return _.indexOf(e,i.Type)===-1});if(h){return}var f=_.max(g.Actions,function(i){return $("#"+i.ID).height()});var d=$("#"+f.ID).height();_.forEach(g.Actions,function(i){if(i.TabId!==c){g.StartOfTab=true;c=i.TabId}$("#"+i.ID).height(d)})})}};