/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../chunks/_rollupPluginBabelHelpers","../../../../../chunks/tslib.es6","../../../../../core/Accessor","../../../../../core/HandleOwner","../../../../../core/mathUtils","../../../../../core/maybe","../../../../../core/reactiveUtils","../../../../../core/accessorSupport/decorators/property","../../../../../core/arrayUtils","../../../../../core/has","../../../../../core/accessorSupport/ensureType","../../../../../core/accessorSupport/decorators/subclass","../../../../../geometry/support/axisAngleDegrees","../../../../ViewingMode","./undoRecords"],(function(e,t,o,r,a,i,n,s,c,l,p,h,g,d,u,y){"use strict";e.ScaleRotateMeshAdapter=function(e){function o(t){var o;return(o=e.call(this,t)||this).interactionState=null,o}t._inheritsLoose(o,e);var r=o.prototype;return r.initialize=function(){this.own([s.when((()=>n.isSome(this.interactionState)&&this.interactionState.angle!==this.interactionState.previousAngle?{interactionState:this.interactionState,angle:this.interactionState.state.angle}:null),(({interactionState:e})=>{this._updateMeshRotation(e)}),s.sync),s.when((()=>n.isSome(this.interactionState)&&this.interactionState.scale!==this.interactionState.previousScale?{interactionState:this.interactionState,scale:this.interactionState.state.scale}:null),(({interactionState:e})=>{this._updateMeshSize(e)}),s.sync)])},r.startInteraction=function(){const e=new S({angle:this.angle});this.interactionState=e;const t=()=>this.interactionState=null;return{state:e,done:t,cancel:()=>{e.cancel(),t()}}},r.createUndoRecord=function(){return y.createGraphicGeometryUndoRecord(this.graphic)},r._updateMeshRotation=function(e){const t=this.geometry.anchor,o=this.viewingMode===u.ViewingMode.Global,{angle:r,previousAngle:a}=e;this.geometry.rotate(0,0,i.rad2deg(r-a),{origin:t,geographic:o}),e.previousAngle=r,n.isSome(this.geometry.transform)&&this.graphic.notifyMeshTransformChanged(),this.graphic.notifyGeometryChanged()},r._updateMeshSize=function(e){const t=this.geometry.anchor,o=this.viewingMode===u.ViewingMode.Global,{scale:r,previousScale:a}=e;this.geometry.scale(r/a,{origin:t,geographic:o}),e.previousScale=r,n.isSome(this.geometry.transform)&&this.graphic.notifyMeshTransformChanged(),this.graphic.notifyGeometryChanged()},t._createClass(o,[{key:"angle",get:function(){const e=this.geometry.transform;if(n.isNone(e))return 0;const t=d.axis(e.rotation)[2];return Math.abs(t)>.999999?i.deg2rad(d.angle(e.rotation))*Math.sign(t):0}},{key:"scale",get:function(){return n.isSome(this.interactionState)?this.interactionState.scale:1}}]),o}(a.HandleOwner),o.__decorate([c.property({constructOnly:!0})],e.ScaleRotateMeshAdapter.prototype,"graphic",void 0),o.__decorate([c.property({constructOnly:!0})],e.ScaleRotateMeshAdapter.prototype,"geometry",void 0),o.__decorate([c.property({constructOnly:!0})],e.ScaleRotateMeshAdapter.prototype,"viewingMode",void 0),o.__decorate([c.property()],e.ScaleRotateMeshAdapter.prototype,"angle",null),o.__decorate([c.property()],e.ScaleRotateMeshAdapter.prototype,"scale",null),o.__decorate([c.property()],e.ScaleRotateMeshAdapter.prototype,"interactionState",void 0),e.ScaleRotateMeshAdapter=o.__decorate([g.subclass("esri.views.3d.interactive.editingTools.transformGraphic.ScaleRotateMeshAdapter")],e.ScaleRotateMeshAdapter);let S=function(e){function o(t){var o;return(o=e.call(this,t)||this).angle=0,o.initialAngle=0,o.previousAngle=0,o.previousScale=1,o.scale=1,o.initialAngle=t.angle,o.previousAngle=t.angle,o}return t._inheritsLoose(o,e),o.prototype.cancel=function(){this.angle=this.initialAngle,this.scale=1},t._createClass(o,[{key:"state",get:function(){const{angle:e,scale:t}=this;return{angle:e,scale:t}}}]),o}(r);o.__decorate([c.property()],S.prototype,"angle",void 0),o.__decorate([c.property()],S.prototype,"initialAngle",void 0),o.__decorate([c.property()],S.prototype,"previousAngle",void 0),o.__decorate([c.property()],S.prototype,"previousScale",void 0),o.__decorate([c.property()],S.prototype,"scale",void 0),o.__decorate([c.property()],S.prototype,"state",null),S=o.__decorate([g.subclass("InteractionState")],S),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
