/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import i from"../../core/Collection.js";import{watch as s,when as o,on as r}from"../../core/reactiveUtils.js";import{property as n,subclass as a}from"../../core/accessorSupport/decorators.js";import{getLyr3DWasm as l}from"../../views/3d/layers/Lyr3DWasm.js";function d(t,e){return t.length!==e.length||t.some((t,i)=>t.text!==e[i].text)}function h(t,e,i){if(!i||!e)return;t.find(t=>t.layerView===e&&t.text===i)||t.push({text:i,layerView:e})}const m=Symbol("attributions");let u=class extends e{constructor(t){super(t),this._clear=()=>{this.removeHandles(m)},this.items=new i,this.view=null,this._allLayerViewsChange=()=>{this.removeHandles(m);const t=this.view?.allLayerViews;let e=!1;if(t){for(const i of t)this.addHandles(s(()=>[i.attributionItems],()=>this._updateAttributionItems()),m),"type"in i&&"integrated-mesh-3dtiles"===i.type&&(e=!0,this.addHandles([s(()=>i.suspended,()=>this._updateAttributionItems()),i.on("visible-geometry-changed",()=>this._updateAttributionItems())],m));e&&this.addHandles(o(()=>!0===this.view?.stationary,()=>this._updateAttributionItems()),m)}this._updateAttributionItems()},this.addHandles([r(()=>this.view?.allLayerViews,"change",this._allLayerViewsChange,{onListenerAdd:this._allLayerViewsChange,onListenerRemove:this._clear})])}destroy(){this.view=null,this.items.removeAll()}get state(){return this.view?.ready?this.view.allLayerViews.some(t=>t.attributionUpdating)?"loading":"ready":"disabled"}_updateAttributionItems(){const t=this.view,e=t?.allLayerViews,i=[];let s=!1,o=null,r=null;if(t&&e){for(const t of e){if(t.suspended)continue;"type"in t&&"integrated-mesh-3dtiles"===t.type&&(r||=t,t.layer.hasGoogleUrl&&(s=!0,o=t));const e=t.attributionItems.slice().sort((t,e)=>e.score-t.score).map(t=>t.text).join(", ");h(i,t,e)}if(r){const e=l(t);if(e){const t=e.getAttributionText();for(let e=t.length-1;e>-1;--e)i.unshift({text:t[e],layerView:r})}}s&&o&&i.unshift({text:"Google Maps",layerView:o}),d(this.items,i)&&(this.items.removeAll(),this.items.addMany(i))}else this._clear()}};t([n({readOnly:!0,type:i})],u.prototype,"items",void 0),t([n({readOnly:!0})],u.prototype,"state",null),t([n()],u.prototype,"view",void 0),u=t([a("esri.widgets.Attribution.AttributionViewModel")],u);const c=u;export{c as default};
