/*
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/Accessor","../../../core/screenUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../input/InputManager"],(function(t,e,i,r,o,n,s,a,h,c){"use strict";const l={container:"esri-zoom-box__container",overlay:"esri-zoom-box__overlay",background:"esri-zoom-box__overlay-background",box:"esri-zoom-box__outline"},u={zoom:"Shift",counter:"Ctrl"};let _=function(e){function i(i){var r;return(r=e.call(this,i)||this)._container=null,r._overlay=null,r._backgroundShape=null,r._boxShape=null,r._box={x:0,y:0,width:0,height:0},r._redraw=r._redraw.bind(t._assertThisInitialized(r)),r}t._inheritsLoose(i,e);var o=i.prototype;return o.destroy=function(){this.view=null},o._start=function(){this._createContainer(),this._createOverlay(),this.navigation.begin()},o._update=function(t,e,i,r){this._box.x=t,this._box.y=e,this._box.width=i,this._box.height=r,this._rafId||(this._rafId=requestAnimationFrame(this._redraw))},o._end=function(t,e,i,o,n){const s=this.view,a=s.toMap(r.createScreenPoint(t+.5*i,e+.5*o));let h=Math.max(i/s.width,o/s.height);-1===n&&(h=1/h),this._destroyOverlay(),this.navigation.end(),s.goTo({center:a,scale:s.scale*h})},o._updateBox=function(t,e,i,r){const o=this._boxShape;o.setAttributeNS(null,"x",""+t),o.setAttributeNS(null,"y",""+e),o.setAttributeNS(null,"width",""+i),o.setAttributeNS(null,"height",""+r),o.setAttributeNS(null,"class",l.box)},o._updateBackground=function(t,e,i,r){this._backgroundShape.setAttributeNS(null,"d",this._toSVGPath(t,e,i,r,this.view.width,this.view.height))},o._createContainer=function(){const t=document.createElement("div");t.className=l.container,this.view.root.appendChild(t),this._container=t},o._createOverlay=function(){const t=this.view.width,e=this.view.height,i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttributeNS(null,"d","M 0 0 L "+t+" 0 L "+t+" "+e+" L 0 "+e+" Z"),i.setAttributeNS(null,"class",l.background);const r=document.createElementNS("http://www.w3.org/2000/svg","rect"),o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),o.setAttributeNS(null,"class",l.overlay),o.appendChild(i),o.appendChild(r),this._container.appendChild(o),this._backgroundShape=i,this._boxShape=r,this._overlay=o},o._destroyOverlay=function(){this._container&&this._container.parentNode&&this._container.parentNode.removeChild(this._container),this._container=this._backgroundShape=this._boxShape=this._overlay=null},o._toSVGPath=function(t,e,i,r,o,n){const s=t+i,a=e+r;return"M 0 0 L "+o+" 0 L "+o+" "+n+" L 0 "+n+" ZM "+t+" "+e+" L "+t+" "+a+" L "+s+" "+a+" L "+s+" "+e+" Z"},o._handleDrag=function(t,e){const i=t.x,r=t.y,o=t.origin.x,n=t.origin.y;let s,a,h,c;switch(i>o?(s=o,h=i-o):(s=i,h=o-i),r>n?(a=n,c=r-n):(a=r,c=n-r),t.action){case"start":this._start();break;case"update":this._update(s,a,h,c);break;case"end":this._end(s,a,h,c,e)}t.stopPropagation()},o._redraw=function(){if(!this._rafId)return;if(this._rafId=null,!this._overlay)return;const{x:t,y:e,width:i,height:r}=this._box;this._updateBox(t,e,i,r),this._updateBackground(t,e,i,r),this._rafId=requestAnimationFrame(this._redraw)},t._createClass(i,[{key:"view",set:function(t){this._handles&&this._handles.forEach((t=>{t.remove()})),this._handles=null,this._destroyOverlay(),this._set("view",t),t&&(t.on("drag",[u.zoom],(t=>this._handleDrag(t,1)),c.ViewEventPriorities.INTERNAL),t.on("drag",[u.zoom,u.counter],(t=>this._handleDrag(t,-1)),c.ViewEventPriorities.INTERNAL))}}]),i}(i);e.__decorate([o.property()],_.prototype,"navigation",void 0),e.__decorate([o.property()],_.prototype,"view",null),_=e.__decorate([h.subclass("esri.views.2d.navigation.ZoomBox")],_);return _}));
