/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/maybe","../EditGeometry"],(function(e,t,i){"use strict";let s=function(){function e(e,t,i){this.editGeometry=e,this.component=t,this.pos=i,this.addedVertex=null,this.originalEdge=null,this.left=null,this.right=null}var s=e.prototype;return s.apply=function(){let e="redo";t.isNone(this.addedVertex)&&(e="apply",this.addedVertex=new i.Vertex(this.component));const s=this.component.getLastVertex();if(t.isNone(s))this.component.vertices.push(this.addedVertex),this.addedVertex.pos=this.pos,this.addedVertex.index=0;else{let e=null;s.rightEdge&&(this.originalEdge=s.rightEdge,e=this.originalEdge.rightVertex,this.component.edges.splice(this.component.edges.indexOf(this.originalEdge),1)),this.component.vertices.push(this.addedVertex),this.addedVertex.pos=this.pos,t.isNone(this.left)&&(this.left=new i.Edge(this.component,s,this.addedVertex)),this.component.edges.push(this.left),s.rightEdge=this.left,t.isSome(this.originalEdge)&&t.isSome(e)&&(t.isNone(this.right)&&(this.right=new i.Edge(this.component,this.addedVertex,e)),this.component.edges.push(this.right),e.leftEdge=this.right),this.component.updateVertexIndex(this.addedVertex,s.index+1)}this.editGeometry.notifyChanges({operation:e,addedVertices:[this.addedVertex]})},s.undo=function(){if(t.isNone(this.addedVertex))return null;this.component.vertices.splice(this.component.vertices.indexOf(this.addedVertex),1),t.isSome(this.left)&&(this.component.edges.splice(this.component.edges.indexOf(this.left),1),this.left.leftVertex.rightEdge=null),t.isSome(this.right)&&(this.component.edges.splice(this.component.edges.indexOf(this.right),1),this.right.rightVertex.leftEdge=null),t.isSome(this.originalEdge)&&(this.component.edges.push(this.originalEdge),this.originalEdge.leftVertex.rightEdge=this.originalEdge,this.originalEdge.rightVertex.leftEdge=this.originalEdge),t.isSome(this.left)?this.component.updateVertexIndex(this.left.leftVertex,this.left.leftVertex.index):this.component.updateVertexIndex(this.addedVertex,0),this.editGeometry.notifyChanges({operation:"undo",removedVertices:[this.addedVertex]})},s.accumulate=function(){return!1},e}();e.AppendVertex=s,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
