/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../../core/Accessor.js";import s from"../../../../core/Collection.js";import{property as r,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{createLineOfSightObserverItem as i,createLineOfSightTargetItem as n,snapshotLineOfSightObserverState as a,snapshotLineOfSightTargetState as h}from"./LineOfSightAuthoringUtils.js";let l=class extends e{constructor(){super(...arguments),this.observerItem=null,this.targetItems=new s}setObserver(t){this.observerItem=i(t)}addTarget(t){this.targetItems.add(n(t))}truncateTargets(t){this.targetItems.splice(t)}syncFromAnalysis(t){const e=t.observer,s=a(e);let r=null;null!=e&&null!=s&&(r=this.observerItem?.observer===e?this.observerItem:{observer:e,snapshot:s},r===this.observerItem&&(r.snapshot=s)),this.observerItem=r;const o=new Map(this.targetItems.map(t=>[t.target,t])),i=t.targets.map(t=>{const e=o.get(t),s=h(t);return e?(e.snapshot=s,e):{target:t,snapshot:s}});m(this.targetItems,i)}syncTargetsToAnalysis(t,e=this.targetItems.length){m(t.targets,this.targetItems.slice(0,e).map(({target:t})=>t))}};function m(t,e){let s=-1;for(let r=0;r<Math.min(t.length,e.length);r++)if(t.getItemAt(r)!==e.at(r)){s=r;break}if(-1===s){if(t.length===e.length)return;s=Math.min(t.length,e.length)}t.splice(s,t.length-s,...e.slice(s))}t([r()],l.prototype,"observerItem",void 0),l=t([o("esri.views.3d.analysis.LineOfSight.LineOfSightAuthoringStore")],l);export{l as LineOfSightAuthoringStore};
