/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{destroyMaybe as t}from"../../core/maybe.js";import{watch as i,initial as o}from"../../core/reactiveUtils.js";import{stripHTML as s}from"../../core/string.js";import{property as n,subclass as r}from"../../core/accessorSupport/decorators.js";import l from"../Widget.js";import a from"./FeatureUtilityNetworkAssociations/VisibleElements.js";import c from"./support/FeatureElementInfo.js";import{loadCalciteComponents as d}from"../support/componentsUtils.js";import{globalCss as p}from"../support/globalCss.js";import{tsx as m,messageBundle as u}from"../support/widget.js";import h from"../support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js";const y="esri-feature-utility-network-associations",v=`${y}__loading-container`,f={base:y,listContainer:`${y}__list`,loadingContainer:v,loadingContainerSticky:`${v}--sticky`};let g=class extends l{constructor(e,t){super(e,t),this._featureElementInfo=null,this.onSelectAssociationType=()=>{},this.flowType="feature-utility-network-associations",this.flowItems=null,this.parentFeatureViewModel=null,this.headingLevel=5,this.viewModel=new h,this.messages=null,this.messagesCommon=null,this.visibleElements=new a}initialize(){this._featureElementInfo=new c,this.addHandles([i(()=>[this.viewModel.description,this.viewModel.title,this.headingLevel],()=>this._setupFeatureElementInfo(),o)])}loadDependencies(){return d({icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice")})}destroy(){this._featureElementInfo=t(this._featureElementInfo)}get description(){return this.viewModel.description}set description(e){this.viewModel.description=e}get title(){return this.viewModel.title}set title(e){this.viewModel.title=e}render(){const{state:e}=this.viewModel;return m("div",{class:this.classes(f.base,p.widget)},this._featureElementInfo?.render(),"loading"===e?this._renderLoading():"disabled"===e?this._renderAssociationNotFound():this._renderContent())}_renderStickyLoading(){return"querying"===this.viewModel.state?m("div",{class:f.loadingContainerSticky,key:"sticky-loader"},this._renderLoadingIcon()):null}_renderLoadingIcon(){return m("calcite-loader",{inline:!0,label:this.messagesCommon.loading})}_renderLoading(){return m("div",{class:f.loadingContainer,key:"loading-container"},this._renderLoadingIcon())}_renderAssociationNotFound(){return m("calcite-notice",{icon:"information",key:"association-not-found",kind:"info",open:!0,scale:"s",width:"full"},m("div",{slot:"message"},this.messages?.noAssociations))}_renderAssociationType(e){const{viewModel:t}=this,i=this._getAssociationTypeTitle(e);return m("calcite-list-item",{description:s(e.description),key:`association-type-${e.type}`,label:s(i),value:e.type,onCalciteListItemSelect:()=>this.onSelectAssociationType({viewModel:t,listType:e,title:i})},m("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderAssociations(e){const{viewModel:t}=this;return"featureForm"===t.source||t.getFeatureCountForAssociationType(e.type)>0?this._renderAssociationType(e):void 0}_renderContent(){const{messages:e,viewModel:t}=this,{state:i,associationTypes:o}=t;return m("div",{class:f.listContainer,key:"list-container"},"ready"===i?m("div",null,m("calcite-list",{displayMode:"flat",label:e?.associationsList},o.map(e=>this._renderAssociations(e)))):null,this._renderStickyLoading())}_getAssociationTypeTitle(e){const{messages:t}=this;if(e.title)return e.title;switch(e.type){case"attachment":return t.associationsAttachments;case"connectivity":return t.associationsConnectivity;case"structure":return t.associationsStructure;case"content":return t.associationsContents;case"container":return t.associationsContainer}}_setupFeatureElementInfo(){const{headingLevel:e,visibleElements:t}=this,i=t.description&&this.description,o=t.title&&this.title;this._featureElementInfo?.set({description:i,title:o,headingLevel:e})}};e([n({constructOnly:!0})],g.prototype,"onSelectAssociationType",void 0),e([n()],g.prototype,"flowType",void 0),e([n()],g.prototype,"flowItems",void 0),e([n()],g.prototype,"parentFeatureViewModel",void 0),e([n()],g.prototype,"featureVisibleElements",void 0),e([n()],g.prototype,"description",null),e([n()],g.prototype,"headingLevel",void 0),e([n()],g.prototype,"title",null),e([n({type:h})],g.prototype,"viewModel",void 0),e([n(),u("esri/widgets/Feature/t9n/Feature")],g.prototype,"messages",void 0),e([n(),u("esri/t9n/common")],g.prototype,"messagesCommon",void 0),e([n({type:a,nonNullable:!0})],g.prototype,"visibleElements",void 0),g=e([r("esri.widgets.Feature.FeatureUtilityNetworkAssociations")],g);export{g as default};
