/*
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/Collection","../../core/compilerUtils","../../core/Handles","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../../layers/Layer","../../views/layers/support/ClipRect"],(function(e,t,i,r,n,o,s,l,a,p,c,y,d,u){"use strict";const _=r.ofType(d);function h(e,t){const i=10**t;return Math.round(e*i)/i}const g={left:0,right:0,top:0,bottom:0};let v=function(t){function i(e){var i;return(i=t.call(this,e)||this)._handles=new o,i._leadingClips=new Map,i._trailingClips=new Map,i.direction="horizontal",i.leadingLayers=new _,i.max=100,i.min=0,i.precision=4,i.step=.5,i.stepMultiplier=10,i.trailingLayers=new _,i.view=null,i}e._inheritsLoose(i,t);var r=i.prototype;return r.initialize=function(){this._handles.add([s.watch((()=>{var e;return[this.view,null==(e=this.view)?void 0:e.ready,this.position,this.direction]}),(()=>this._clipLayers()),s.initial),s.on((()=>this.leadingLayers),"change",(()=>this._clipLeadingLayers())),s.on((()=>this.trailingLayers),"change",(()=>this._clipTrailingLayers()))])},r.destroy=function(){this._removeExistingClips(),this._handles.destroy(),this._handles=null},r._clipLayers=function(){this._clipLeadingLayers(),this._clipTrailingLayers()},r._clipLeadingLayers=function(){this._removeClips("leading");const{leadingLayers:e}=this;e.forEach((e=>this._clipLayer({layer:e,type:"leading"})))},r._clipTrailingLayers=function(){this._removeClips("trailing");const{trailingLayers:e}=this;e.forEach((e=>this._clipLayer({layer:e,type:"trailing"})))},r._getLayerView=function(){var t=e._asyncToGenerator((function*(e){const{view:t}=this;if(!e||!t)return null;const i=yield n.typeCast(t)().whenLayerView(e);return"clips"in i?i:null}));function i(e){return t.apply(this,arguments)}return i}(),r._getVerticalClipRect=function(e){const{position:t}=this;return"leading"===e?new u({...g,bottom:100-t+"%"}):"trailing"===e?new u({...g,top:`${t}%`}):null},r._getHorizontalClipRect=function(e){const{position:t}=this;return"leading"===e?new u({...g,right:100-t+"%"}):"trailing"===e?new u({...g,left:`${t}%`}):null},r._getClipRect=function(e){const{direction:t}=this;return"vertical"===t?this._getVerticalClipRect(e):"horizontal"===t?this._getHorizontalClipRect(e):null},r._clipLayer=function(){var t=e._asyncToGenerator((function*(e){const{_leadingClips:t,_trailingClips:i}=this,{layer:r,type:n}=e,o="trailing"===n?i:"leading"===n?t:null,s=yield this._getLayerView(r);if(!(s&&"clips"in s&&o&&s.hasOwnProperty("clips")))return;const l=o.get(s);l&&s.clips.remove(l);const a=this._getClipRect(n);a&&(o.set(s,a),s.clips.add(a))}));function i(e){return t.apply(this,arguments)}return i}(),r._removeClips=function(e){const{_leadingClips:t,_trailingClips:i}=this,r="trailing"===e?i:"leading"===e?t:null;r&&(r.forEach(((e,t)=>{t&&t.hasOwnProperty("clips")&&t.clips.remove(e)})),r.clear())},r._removeExistingClips=function(){this._removeClips("leading"),this._removeClips("trailing")},e._createClass(i,[{key:"position",get:function(){return 25},set:function(e){const{precision:t,min:i,max:r}=this;this._set("position",h(Math.max(Math.min(e,r),i),t))}},{key:"state",get:function(){const{view:e}=this;return e&&e.ready?"ready":"disabled"}}]),i}(i);t.__decorate([l.property()],v.prototype,"direction",void 0),t.__decorate([l.property({type:_})],v.prototype,"leadingLayers",void 0),t.__decorate([l.property({readOnly:!0})],v.prototype,"max",void 0),t.__decorate([l.property({readOnly:!0})],v.prototype,"min",void 0),t.__decorate([l.property()],v.prototype,"position",null),t.__decorate([l.property()],v.prototype,"precision",void 0),t.__decorate([l.property({readOnly:!0})],v.prototype,"state",null),t.__decorate([l.property()],v.prototype,"step",void 0),t.__decorate([l.property()],v.prototype,"stepMultiplier",void 0),t.__decorate([l.property({type:_})],v.prototype,"trailingLayers",void 0),t.__decorate([l.property()],v.prototype,"view",void 0),v=t.__decorate([y.subclass("esri.widgets.Swipe.SwipeViewModel")],v);return v}));
