/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import{property as i,subclass as r}from"../../core/accessorSupport/decorators.js";import{convertLayoutTypeToWebSupportedFormat as a}from"../../layers/knowledgeGraph/supportUtils.js";let n=class extends o{constructor(t){super(t),this._goToExtentController=null,this._scaleExtent=(t,e)=>{const o=t,i=(t.xmax-t.xmin)/2*(e-1),r=(t.ymax-t.ymin)/2*(e-1);return o.xmin=t.xmin-i,o.ymin=t.ymin-r,o.xmax=t.xmax+i,o.ymax=t.ymax+r,o},this.switchLayout=this.switchLayout.bind(this)}destroy(){this._cancelGoToExtent(),this.view=null}set view(t){this._set("view",t),t&&t.when().then(()=>{if(this.view===t){if(!this.view.map?.linkChartProperties)throw new e("linkChartLayoutSwitcher:error","Link chart layouts are only supported on WebLinkCharts.");this.layout=a(this.view.map.linkChartProperties.layoutType)}})}get state(){return this.view?this.view.map?.linkChartProperties?"ready":"disabled":"loading"}get layout(){return this._get("layout")||"organic-standard"}set layout(t){this._set("layout",t)}get preventExtentUpdate(){return this._get("preventExtentUpdate")||!1}set preventExtentUpdate(t){this._set("preventExtentUpdate",t)}async switchLayout(t){if(!this.view||!this.view.map)throw new e("linkChartLayoutSwitcher:loading-state","Cannot change layout when link chart has not loaded.");if(this.layout=t,await this.view.map.applyLayout(t),!this.preventExtentUpdate&&this.view.map.diagramNodesExtent){const e="geographic-organic-standard"!==t?this._scaleExtent(this.view.map.diagramNodesExtent,1.4):this.view.map.diagramNodesExtent,i=new AbortController;this._goToExtentController=i;try{await this.view.when(),await this.view.goTo(e,{signal:i.signal})}catch(o){}this._goToExtentController=null}this.emit("switchLayout",{layout:t})}_cancelGoToExtent(){const{_goToExtentController:t}=this;t&&t.abort(),this._goToExtentController=null}};t([i()],n.prototype,"_goToExtentController",void 0),t([i()],n.prototype,"view",null),t([i({readOnly:!0})],n.prototype,"state",null),t([i()],n.prototype,"layout",null),t([i()],n.prototype,"preventExtentUpdate",null),n=t([r("esri.widgets.LinkChartLayoutSwitcher.LinkChartLayoutSwitcherViewModel")],n);const s=n;export{s as default};
