/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{substitute as t}from"../../../intl.js";import o from"../../../core/ReactiveMap.js";import{watch as i}from"../../../core/reactiveUtils.js";import{property as r,subclass as n}from"../../../core/accessorSupport/decorators.js";import s from"../../Widget.js";import{loadCalciteComponents as a}from"../componentsUtils.js";import{tsx as c,messageBundle as u}from"../widget.js";import d from"./FeatureUtilityNetworkAssociationsViewModel.js";const l="esri-utility-network-association-list",p={featureObserver:`${l}__feature-observer`,limitNoticeContainer:`${l}__limit-notice-container`,loadingContainer:`${l}__loading-container`};let m=class extends s{constructor(e,t){super(e,t),this._isFeatureCountNoticeOpen=!0,this._observer=new IntersectionObserver(([e])=>{e?.isIntersecting&&this._increaseFeaturePage()},{root:window.document}),this._observerNode=null,this.featuresPerPage=50,this.headingLevel=5,this.maxFeatureCount=1e3,this.messagesFeature=null,this.messagesCommon=null,this.selectedLayer=null,this.tooltipReferenceMap=new o,this.viewModel=new d}initialize(){this.setUpObserver()}loadDependencies(){return a({icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice")})}destroy(){this.tooltipReferenceMap.clear()}get associatedFeatureCount(){const e=this.viewModel.associationViewModels,t=this.selectedLayer?e.get(this.selectedLayer):null;return t?t.length:0}set currentFeaturePage(e){const{featuresPerPage:t,associatedFeatureCount:o}=this,i=Math.ceil(o/t)||1,r=Math.max(Math.min(e,i),1);this._set("currentFeaturePage",r)}get currentFeaturePage(){return this._get("currentFeaturePage")??1}get endIndex(){const{currentFeaturePage:e,featuresPerPage:t,maxFeatureCount:o}=this;return Math.min(e*t,o)}renderConnectivityIcon(e,t){const{tooltipReferenceMap:o}=this;let i;switch(e){case"junction-edge-from-connectivity":i="connection-end-left";break;case"junction-edge-to-connectivity":i="connection-end-right";break;case"junction-edge-midspan-connectivity":i="connection-middle";break;default:i="connection-to-connection"}return c("calcite-icon",{afterCreate:e=>o.set(t,e),afterRemoved:()=>o.delete(t),icon:i,scale:"s",slot:"content-start"})}renderFeatureCountWarning(){const{associatedFeatureCount:e,maxFeatureCount:o,messagesFeature:i}=this;return e>o?c("calcite-notice",{class:this._isFeatureCountNoticeOpen?p.limitNoticeContainer:void 0,closable:!0,icon:"information",kind:"info",open:!0,scale:"s",width:"full",onCalciteNoticeBeforeOpen:()=>this._isFeatureCountNoticeOpen=!0,onCalciteNoticeClose:()=>this._isFeatureCountNoticeOpen=!1},c("div",{slot:"title"},i.associationsLimitNoticeTitle),c("div",{slot:"message"},t(i.associationsLimitNoticeMessage,{number:o}))):null}renderFeatureObserver(){return c("div",{afterCreate:this._onObserverCreate,bind:this,class:p.featureObserver,key:"feature-observer"})}renderLoading(){return c("div",{class:p.loadingContainer,key:"loading-container"},this.renderLoadingIcon())}renderLoadingIcon(){return c("calcite-loader",{inline:!0,label:this.messagesCommon.loading})}getConnectivityTooltip(e){const{messagesFeature:t}=this;switch(e){case"connectivity":case"junction-junction-connectivity":return t.associationsJunctionJunction;case"junction-edge-from-connectivity":return t.associationsJunctionEdgeFrom;case"junction-edge-midspan-connectivity":return t.associationsJunctionEdgeMidspan;case"junction-edge-to-connectivity":return t.associationsJunctionEdgeTo;default:return""}}setUpObserver(){this.addHandles(i(()=>this._observerNode,()=>this._onObserverChange()))}_increaseFeaturePage(){this.currentFeaturePage++}_onObserverChange(){this._observerNode&&this._observer.unobserve(this._observerNode);const{state:e,showAllEnabled:t}=this.viewModel;this._observerNode&&"ready"===e&&t&&this._observer.observe(this._observerNode)}_onObserverCreate(e){this._observerNode=e}};e([r()],m.prototype,"_observer",void 0),e([r()],m.prototype,"_observerNode",void 0),e([r()],m.prototype,"associatedFeatureCount",null),e([r()],m.prototype,"currentFeaturePage",null),e([r()],m.prototype,"endIndex",null),e([r()],m.prototype,"featuresPerPage",void 0),e([r()],m.prototype,"headingLevel",void 0),e([r()],m.prototype,"maxFeatureCount",void 0),e([r(),u("esri/widgets/Feature/t9n/Feature")],m.prototype,"messagesFeature",void 0),e([r(),u("esri/t9n/common")],m.prototype,"messagesCommon",void 0),e([r()],m.prototype,"selectedLayer",void 0),e([r()],m.prototype,"tooltipReferenceMap",void 0),e([r({type:d})],m.prototype,"viewModel",void 0),m=e([n("esri.widgets.support.UtilityNetworkAssociations.UtilityNetworkAssociationList")],m);export{m as default};
