/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../Viewpoint.js";import o from"../../core/Collection.js";import{deprecateUnnecessaryViewModel as i}from"../../core/deprecate.js";import a from"../../core/Error.js";import{EventedAccessor as r}from"../../core/Evented.js";import n from"../../core/Logger.js";import{property as s,cast as c,subclass as p}from"../../core/accessorSupport/decorators.js";import l from"../../webdoc/support/SlideThumbnail.js";import m from"../../webmap/Bookmark.js";import{GoTo as u}from"../support/GoTo.js";const k=o.ofType(m),w={width:128,height:128,format:"png"},h={takeScreenshot:!0,captureViewpoint:!0,captureRotation:!0,captureScale:!0,captureTimeExtent:!0},d={time:!0};let v=class extends(u(r)){constructor(t){super(t),this.capabilities={...d},this.activeBookmark=null,this.view=null,t?.suppressDeprecationWarning||i(n.getLogger(this),"Bookmarks","arcgis-bookmarks",{version:"5.0"})}normalizeCtorArgs(t){const{suppressDeprecationWarning:e,...o}=t??{};return o}destroy(){this.view=null,this._set("activeBookmark",null)}castCapabilities(t){return{...d,...t}}get bookmarks(){return this.view?.map?.bookmarks??new k}set bookmarks(t){this._overrideIfSome("bookmarks",t)}set defaultCreateOptions(t){this._set("defaultCreateOptions",{...h,...t})}get defaultCreateOptions(){return h}set defaultEditOptions(t){this._set("defaultEditOptions",{...h,...t})}get defaultEditOptions(){return h}get state(){const{view:t}=this;return t&&!t.ready?"loading":"ready"}async createBookmark(t){const{view:e,defaultCreateOptions:o,capabilities:i}=this;if(!e)throw new a("create-bookmark:invalid-view","Cannot create a bookmark without a view.");const{takeScreenshot:r,screenshotSettings:n,captureViewpoint:s,captureRotation:c,captureScale:p,captureTimeExtent:l}={...o,...t},u=r?await this._createThumbnail(n):void 0,k=i.time&&l&&null!=e.timeExtent?e.timeExtent.clone():void 0;return new m({...u&&{thumbnail:u},...l&&{timeExtent:k},...s&&{viewpoint:this._createViewpoint({view:e,captureScale:p,captureRotation:c})}})}async editBookmark(t,e){if(!t)return t;const{view:o,defaultEditOptions:i}=this;if(!o)throw new a("edit-bookmark:invalid-view","Cannot edit a bookmark without a view.");const{takeScreenshot:r,screenshotSettings:n,captureViewpoint:s,captureRotation:c,captureScale:p,captureTimeExtent:l}={...i,...e},m=r?await this._createThumbnail(n):void 0;return m&&(t.thumbnail=m),s&&(t.viewpoint=this._createViewpoint({view:o,captureScale:p,captureRotation:c})),l&&null!=o.timeExtent&&(t.timeExtent=o.timeExtent.clone()),this.emit("bookmark-edit",{bookmark:t}),t}goTo(t){const{capabilities:e,view:o}=this;if(!o)throw new a("go-to:invalid-view","Cannot go to a bookmark without a view");const i=t?.viewpoint;if(!i)throw new a("go-to:invalid-bookmark","Cannot go to a bookmark that does not contain a 'viewpoint'.",{bookmark:t});this._set("activeBookmark",t);const r=this.callGoTo({target:i}),n=t?.timeExtent;return e.time&&n&&(o.timeExtent=n),this.emit("bookmark-select",{bookmark:t}),r.catch(()=>{}).then(()=>this._set("activeBookmark",null)),r}async _createThumbnail(t){const{view:e}=this;if(!e)throw new a("bookmark:invalid-view","Cannot create slide thumbnail without a view");const o=await e.takeScreenshot({...w,...t});return new l({url:o.dataUrl})}_createViewpoint({view:t,captureRotation:o,captureScale:i}){const a=t.viewpoint?.clone();return new e({targetGeometry:t.extent?.clone(),rotation:(o?a?.rotation:null)??0,scale:(i?a?.scale:null)??0})}};t([s()],v.prototype,"capabilities",void 0),t([c("capabilities")],v.prototype,"castCapabilities",null),t([s({readOnly:!0})],v.prototype,"activeBookmark",void 0),t([s({type:k})],v.prototype,"bookmarks",null),t([s()],v.prototype,"defaultCreateOptions",null),t([s()],v.prototype,"defaultEditOptions",null),t([s({readOnly:!0})],v.prototype,"state",null),t([s()],v.prototype,"view",void 0),v=t([p("esri.widgets.Bookmarks.BookmarksViewModel")],v);const b=v;export{b as default};
