"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=e(require("react")),i=require("animation-utilities").MotionInterface,a=e(require("jibo/lib/lps-service")),n=e(require("../toolbar/run-configuration.js")),s=e(require("./views/lps-pane")),o=e(require("./views/body-pane")),r=e(require("./views/audio-speech-pane")),c=e(require("./views/system-health-pane")),l=e(require("jibo-keyframes")),u=e(require("./views/sidebar-button")),d=30;module.exports=t.createClass({displayName:"info-view-menu",getInitialState:function(){return{activeView:"LPS View",axisStates:{"Head Rotation":{name:"Head Rotation",velocity:0,state:{vel:0,ref:0,mode:0},id:0,isVisible:!0,data:0},"Torso Rotation":{name:"Torso Rotation",velocity:0,state:{vel:0,ref:0,mode:0},id:1,isVisible:!1,data:0},"Pelvis Rotation":{name:"Pelvis Rotation",velocity:0,state:{vel:0,ref:0,mode:0},id:2,isVisible:!1,data:0}}}},render:function(){var e=this,i=["LPS View","Body View","Audio-Speech","System Health"],n=[],l=0,v=void 0;return i.forEach(function(i){var u={};if(i==e.state.activeView)switch(u={backgroundColor:"#4182c4",color:"white"},i){case"LPS View":v=t.createElement(s,{parent:e,lpsService:a,intervalLength:d,editor:e.props.editor});break;case"Body View":v=t.createElement(o,{data:e.state.axisStates,onChangeConfiguration:e.onChangeConfiguration,parent:e,title:"Velocity",dataAxis:"Axis Velocity",lpsService:a,intervalLength:d});break;case"Audio-Speech":v=t.createElement(r,{editor:e.props.editor});break;case"System Health":v=t.createElement(c,{editor:e.props.editor})}n.push(t.createElement("li",{key:l,name:i,onClick:e.onSelectView.bind(e,i)},t.createElement("a",{style:u,key:l++,className:"icon icon-settings"},i)))}),t.createElement("div",{tabIndex:"-1"},t.createElement("div",{className:"settings-view pane-item",style:{height:700},tabindex:"-1",is:"space-pen-div"},t.createElement("div",{className:"config-menu"},t.createElement("ul",{className:"panels-menu nav nav-pills nav-stacked"},n),t.createElement(u,{text:"Connect",onClick:this.onConnect}),t.createElement(u,{text:"Toggle Pause",onClick:this.togglePause})),t.createElement("div",{className:"panels"},v)))},componentDidMount:function(){this.isConnected=!1,this.paused=!1,this.interval=setInterval(this.update.bind(this),30)},componentWillUnmount:function(){clearInterval(this.interval)},togglePause:function(){this.paused=!this.paused},onChangeConfiguration:function(){this.setState({axisStates:this.state.axisStates})},onSelectView:function(e){this.setState({activeView:e})},onConnect:function(){var e=this,t="";t="local"===n.type?"http://localhost:8181":n.host;var i=new XMLHttpRequest;i.timeout=2e3,i.onreadystatechange=function(){if(4===i.readyState&&200===i.status){var t=JSON.parse(i.responseText);t.forEach(function(t){e.connectService(t.name,t.host,t.port)})}else 4===i.readyState&&0===i.status&&console.warn("Could not connect to registry.")},i.open("GET",t,!0),i.send(null)},connectService:function(e,t,n){var s="ws://"+t+":"+n;if("lps"===e)a.init(s);else if("body"===e){var o=new i(s);this.motionInterface=o,this.isConnected=!0}else console.warn("Unable to find service "+e)},update:function(){if(!this.paused&&this.isConnected){var e=this.motionInterface.getMotionDOFNames(),t={},i=[];for(var a in e){var n=l.channels.dofNameToDisplayName(e[a]),s=this.state.axisStates[n];t[n]=s,t[n].state=this.motionInterface.getState(e[a]),t[n].state&&(t[n].data=t[n].state.vel),i.push(t[n].state)}var o=i.filter(function(e){return!e});0==o.length&&this.setState({axisStates:t})}}});