/*
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","../../Viewpoint","../../core/Collection","../../core/Error","../../core/Evented","../../core/Logger","../../core/maybe","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/decorators/cast","../../core/accessorSupport/decorators/subclass","../../webdoc/support/SlideThumbnail","../../webmap/Bookmark","../support/GoTo"],(function(t,e,o,i,r,n,a,c,s,u,l,p,d,k,v,m){"use strict";const h="esri.widgets.Bookmarks.BookmarksViewModel",w=a.getLogger(h),y=i.ofType(v),f={width:128,height:128,format:"png"},_={takeScreenshot:!0,captureViewpoint:!0,captureRotation:!0,captureScale:!0,captureTimeExtent:!0},b={time:!0};let g=function(e){function i(t){var o;return(o=e.call(this,t)||this).abilities={...b},o.activeBookmark=null,o}t._inheritsLoose(i,e);var n=i.prototype;return n.destroy=function(){this.view=null,this._set("activeBookmark",null)},n.castAbilities=function(t){return{...b,...t}},n.createBookmark=function(){var e=t._asyncToGenerator((function*(t){const{view:e,defaultCreateOptions:o,abilities:i}=this;if(!e){const t=new r("create-bookmark:invalid-view","Cannot create a bookmark without a view.");throw w.error(t),t}const{takeScreenshot:n,screenshotSettings:a,captureViewpoint:s,captureRotation:u,captureScale:l,captureTimeExtent:p}={...o,...t},d=n?yield this._createThumbnail(a):void 0,k=i.time&&p&&c.isSome(e.timeExtent)?e.timeExtent.clone():void 0;return new v({...d&&{thumbnail:d},...p&&{timeExtent:k},...s&&{viewpoint:this._createViewpoint({view:e,captureScale:l,captureRotation:u})}})}));function o(t){return e.apply(this,arguments)}return o}(),n.editBookmark=function(){var e=t._asyncToGenerator((function*(t,e){const{view:o,defaultEditOptions:i}=this;if(!o){const t=new r("edit-bookmark:invalid-view","Cannot edit a bookmark without a view.");throw w.error(t),t}const{takeScreenshot:n,screenshotSettings:a,captureViewpoint:s,captureRotation:u,captureScale:l,captureTimeExtent:p}={...i,...e},d=n?yield this._createThumbnail(a):void 0;return d&&(t.thumbnail=d),s&&(t.viewpoint=this._createViewpoint({view:o,captureScale:l,captureRotation:u})),p&&c.isSome(o.timeExtent)&&(t.timeExtent=o.timeExtent.clone()),this.emit("bookmark-edit",{bookmark:t}),t}));function o(t,o){return e.apply(this,arguments)}return o}(),n.goTo=function(t){const{abilities:e,view:o}=this;if(!o){const t=new r("go-to:invalid-view","Cannot go to a bookmark without a view");return w.error(t),Promise.reject(t)}const i=null==t?void 0:t.viewpoint;if(!i){const e=new r("go-to:invalid-bookmark","Cannot go to a bookmark that does not contain a 'viewpoint'.",{bookmark:t});return w.error(e),Promise.reject(e)}this._set("activeBookmark",t);const n={target:i},a=this.callGoTo(n),c=null==t?void 0:t.timeExtent;return e.time&&c&&(o.timeExtent=c),this.emit("bookmark-select",{bookmark:t}),a.catch((()=>{})).then((()=>this._set("activeBookmark",null))),a},n._createThumbnail=function(){var e=t._asyncToGenerator((function*(t){const e=yield this.view.takeScreenshot({...f,...t});return new k.SlideThumbnail({url:e.dataUrl})}));function o(t){return e.apply(this,arguments)}return o}(),n._createViewpoint=function({view:t,captureRotation:e,captureScale:i}){var r,n;const a=null==(r=t.viewpoint)?void 0:r.clone();return new o({targetGeometry:null==(n=t.extent)?void 0:n.clone(),rotation:e&&(null==a?void 0:a.rotation)||0,scale:i&&(null==a?void 0:a.scale)||0})},t._createClass(i,[{key:"bookmarks",get:function(){return this.get("view.map.bookmarks")||new y},set:function(t){void 0!==t?this._override("bookmarks",t):this._clearOverride("bookmarks")}},{key:"defaultCreateOptions",get:function(){return _},set:function(t){this._set("defaultCreateOptions",{..._,...t})}},{key:"defaultEditOptions",get:function(){return _},set:function(t){this._set("defaultEditOptions",{..._,...t})}},{key:"state",get:function(){const t=this.get("view");return t&&!t.ready?"loading":"ready"}},{key:"view",get:function(){return this._get("view")},set:function(t){t&&"2d"!==t.type&&w.error(new r("view:invalid-view","SceneView is not supported",{view:t})),this._set("view",t)}}]),i}(m.GoToMixin(n.EventedAccessor));e.__decorate([s.property()],g.prototype,"abilities",void 0),e.__decorate([p.cast("abilities")],g.prototype,"castAbilities",null),e.__decorate([s.property({readOnly:!0})],g.prototype,"activeBookmark",void 0),e.__decorate([s.property({type:y})],g.prototype,"bookmarks",null),e.__decorate([s.property()],g.prototype,"defaultCreateOptions",null),e.__decorate([s.property()],g.prototype,"defaultEditOptions",null),e.__decorate([s.property({readOnly:!0})],g.prototype,"state",null),e.__decorate([s.property({value:null})],g.prototype,"view",null),g=e.__decorate([d.subclass(h)],g);return g}));
