/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{remove as e}from"../../../../core/arrayUtils.js";import{LineSegment as t}from"../EditGeometry.js";class r{constructor(e,t){this._editGeometry=e,this._part=t,this._createdSegment=null}apply(){let e="redo";const{_part:r}=this;if(null==this._createdSegment){e="apply";const n=r.getFirstVertex(),i=r.getLastVertex();if(r.isClosed()||r.vertices.length<2||null==n||null==i)return;if(2===r.vertices.length&&"line"===i.leftSegment?.type)return;this._createdSegment=new t(this._part,i,n)}this._createdSegment.leftVertex.rightSegment=this._createdSegment,this._createdSegment.rightVertex.leftSegment=this._createdSegment,r.segments.push(this._createdSegment),this._editGeometry.notifyChanges({operation:e})}undo(){const{_part:t,_createdSegment:r,_editGeometry:n}=this;null!=r&&(e(t.segments,r),r.leftVertex.rightSegment=null,r.rightVertex.leftSegment=null,n.notifyChanges({operation:"undo"}))}accumulate(){return!1}}export{r as ClosePart};
