/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Evented","../../../core/handleUtils","../../../core/maybe","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../Selector2D"],(function(e,t,o,r,i,n,s,a,c,l,p){"use strict";let u=function(t){function o(e){var o;return(o=t.call(this,e)||this)._operationHandlesGroup=null,o.activeOperation=null,o.layers=null,o.selector=new p,o}e._inheritsLoose(o,t);var n=o.prototype;return n.destroy=function(){this._operationHandlesGroup=i.removeMaybe(this._operationHandlesGroup),this.selector.destroy()},n.cancel=function(){"active"===this.state&&(this.activeOperation.cancel(),this.activeOperation=null),this.selector.candidates=null},n.activate=function(e){const{state:t}=this;if("disabled"===t)return;"active"===t&&this.cancel(),this.selector.candidates=this._getCandidates();const o=this.selector.draw(e);return this._operationHandlesGroup=r.handlesGroup([o.once("complete",(e=>this._onOperationComplete(e))),o.on("selection-change",(e=>this._onOperationSelectionChange(e)))]),this.activeOperation=o,o},n._getCandidates=function(){let e=[];return this.layers.forEach((t=>{e=e.concat(...t.graphics.toArray())})),e},n._onOperationSelectionChange=function(e){this.emit("selection-change",e)},n._onOperationComplete=function(e){this._operationHandlesGroup=i.removeMaybe(this._operationHandlesGroup),this.activeOperation=null,this.emit("complete",e)},e._createClass(o,[{key:"state",get:function(){var e,t;return this.activeOperation?"active":null!=(e=this.view)&&e.ready&&null!=(t=this.layers)&&t.length?"ready":"disabled"}},{key:"view",set:function(e){this.selector.view=e,this._set("view",e)}}]),o}(o.EventedAccessor);t.__decorate([n.property()],u.prototype,"activeOperation",void 0),t.__decorate([n.property()],u.prototype,"layers",void 0),t.__decorate([n.property({readOnly:!0})],u.prototype,"selector",void 0),t.__decorate([n.property({readOnly:!0})],u.prototype,"state",null),t.__decorate([n.property()],u.prototype,"view",null),u=t.__decorate([l.subclass("esri.widgets.support.SelectionToolbar.SelectionToolbarViewModel")],u);return u}));
