"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=e(require("react")),i=e(require("./visualizer")),o=e(require("./timeline")),s=e(require("../../atom-react/mixins/pane-resize-event-mixin")),n=e(require("../../common/layout/layout")),r=e(require("../../common/layout/h-layout")),a=e(require("../../common/layout/v-layout")),d=e(require("./properties")),l=e(require("./face/face")),p=e(require("./video/video")),c=require("atom").CompositeDisposable,h=e(require("../../atom-react/core/react-editor")),u=e(require("lodash")),m=e(require("fs")),f=t.createClass({displayName:"EditorView",mixins:[s],getInitialState:function(){return{visualizerWidth:0,visualizerHeight:0,timelineWidth:0,timelineHeight:0,focusOnProps:!0}},componentWillMount:function(){var e=this,t=this;this.props.editor.animationModel.on("ondatachanged",function(){t.forceUpdate()}),this.props.editor.animationModel.on("onpropertieschanged",function(){e.checkModified()}),this.props.editor.animationModel.on("save",function(){e.checkModified()})},checkModified:function(){var e=this;try{m.readFile(this.props.editor.uri,"utf8",function(t,i){var o=JSON.parse(i);e.props.editor.animationModel.state&&(u.isEqual(o,e.props.editor.animationModel.state.keyframes)?e.props.editor.setModifiedStatus(!1):e.props.editor.setModifiedStatus(!0))})}catch(t){console.warn("error reading keyframes file, ",t)}},componentDidMount:function(){var e=this;this.setupPaneResizeEventMixin(),this.disposables=new c,this.disposables.add(atom.commands.add(this.getDOMNode(),{"jibo-sdk:select-all-keyframes":this.selectAllKeyframes,"jibo-sdk:clear-keyframe-selection":this.clearKeyframeSelection,"jibo-sdk:upsert-keyframe":this.upsertKeyframe,"jibo-sdk:upsert-all":this.upsertAllKeyframes,"jibo-sdk:reset-keyframes":this.resetKeyframes,"jibo-sdk:delete":this.deletePressed,"jibo-sdk:start-playing":this.startPlaying,"jibo-sdk:stop-playing":this.stopPlaying,"jibo-sdk:step-backward":this.stepBackward,"jibo-sdk:step-forward":this.stepForward,"jibo-sdk:next-layer":this.nextLayer,"jibo-sdk:previous-layer":this.previousLayer,"core:undo":this.undo,"core:redo":this.redo,"core:cut":this.cut,"core:copy":this.copy,"core:paste":this.paste,"jibo-sdk:lose-focus":this.setEditorFocus,"jibo-sdk:upsert-and-save":this.upsertAndSave}));var t=this;requestAnimationFrame(function(){t.setState({visualizerWidth:Math.floor(e.props.paneWidth/2)-4,visualizerHeight:Math.floor(e.props.paneHeight/2)-4,timelineWidth:Math.floor(e.props.paneWidth/2)-4,timelineHeight:Math.floor(e.props.paneHeight/2)-20})}),this.onFocusInCB=this.onFocusIn.bind(this),this.getDOMNode().addEventListener("focusin",this.onFocusInCB,!0),this.onFocusOutCB=this.onFocusOut.bind(this),this.getDOMNode().addEventListener("focusout",this.onFocusOutCB,!0)},onFocusIn:function(){},onFocusOut:function(e){this.props.editor.isPaneActive()!==!1&&(null===e.relatedTarget||e.relatedTarget===document.getElementsByClassName("workspace")[0])&&this.getDOMNode().focus()},startPlaying:function(){this.props.editor.animationModel.togglePlay()},stopPlaying:function(){this.props.editor.animationModel.isPlaying()&&this.props.editor.animationModel.togglePlay()},stepBackward:function(){this.props.editor.animationModel.stepTimeBackward(),this.props.editor.animationModel.keyframeSelection.clearSelection()},stepForward:function(){this.props.editor.animationModel.stepTimeForward(),this.props.editor.animationModel.keyframeSelection.clearSelection()},nextLayer:function(){this.props.editor.animationModel.nextLayer()},previousLayer:function(){this.props.editor.animationModel.previousLayer()},undo:function(){this.props.editor.animationModel.undo()},redo:function(){this.props.editor.animationModel.redo()},cut:function(){this.props.editor.animationModel.keyframeSelection.cutSelectedKeyframes()},copy:function(){this.props.editor.animationModel.keyframeSelection.copySelectedKeyframes()},paste:function(){if(this.props.editor.animationModel.keyframeSelection.isSingleSelect()){var e=this.props.editor.animationModel.keyframeSelection.getCurrentKeyframe();this.props.editor.animationModel.keyframeSelection.pasteKeyframes(e.layerId,e.keyframeIndex)}},deletePressed:function(){this.props.editor.animationModel.keyframeSelection.deleteKeyframes()},selectAllKeyframes:function(){this.props.editor.animationModel.keyframeSelection.selectAll()},clearKeyframeSelection:function(){this.props.editor.animationModel.keyframeSelection.clearSelection()},upsertKeyframe:function(){this.props.editor.animationModel.keyframeSelection.isSingleSelect()&&this.props.editor.animationModel.upsertKeyframes()},upsertAllKeyframes:function(){this.props.editor.animationModel.keyframeSelection.isSingleSelect()&&this.props.editor.animationModel.upsertKeyframes(!0)},resetKeyframes:function(){this.props.editor.animationModel.keyframeSelection.isSingleSelect()&&this.props.editor.animationModel.resetKeyframes()},upsertAndSave:function(){this.props.editor.animationModel.keyframeSelection.isSingleSelect()&&this.upsertKeyframe(),atom.commands.dispatch(this.getDOMNode(),"core:save")},setEditorFocus:function(){this.getDOMNode().focus()},componentWillUnmount:function(){this.cleanupPaneResizeEventMixin(),this.disposables.dispose(),this.getDOMNode().removeEventListener("focusout",this.onFocusOutCB),this.getDOMNode().removeEventListener("focusin",this.onFocusInCB)},onInnerHLayoutResize:function(e){this.setState({visualizerWidth:e[0],timelineWidth:this.state.timelineWidth})},onHLayoutResize:function(e){this.setState({visualizerWidth:e[0],timelineWidth:e[0]})},onVLayoutResize:function(e){this.setState({visualizerHeight:e[0],timelineHeight:e[1]})},render:function(){var e=null,s=t.createElement(l,{animationModel:this.props.editor.animationModel});if(this.props.editor.animationModel.getLayersOfType("Video").length>0){var c=h.getProjectRoot(this.props.editor.uri);e=t.createElement(a,null,s,t.createElement(p,{projectRoot:c,animationModel:this.props.editor.animationModel}))}else e=s;return t.createElement("div",{tabIndex:"1"},t.createElement(n,{ref:"topLevel",width:this.props.paneWidth,height:this.props.paneHeight-40,serialized:this.props.editor.layout},t.createElement(r,{onLayoutResize:this.onHLayoutResize},t.createElement(a,{onLayoutResize:this.onVLayoutResize},t.createElement(r,{onLayoutResize:this.onInnerHLayoutResize},t.createElement(i,{animationModel:this.props.editor.animationModel,width:this.state.visualizerWidth,height:this.state.visualizerHeight}),e),t.createElement(o,{playbackTime:this.props.editor.animationModel.uiState.currentKeyframe,onLabelonDoubleClick:this.onLabelonDoubleClick,animationModel:this.props.editor.animationModel,width:this.state.timelineWidth,height:this.state.timelineHeight,visualizerWidth:this.state.visualizerWidth,visualizerHeight:this.state.visualizerHeight})),t.createElement(d,{paneHeight:this.props.paneHeight,animationModel:this.props.editor.animationModel}))))}});module.exports=f;