/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import{destroyMaybe as t}from"../../core/maybe.js";import{after as r}from"../../core/promiseUtils.js";import{watch as s,initial as i,on as o}from"../../core/reactiveUtils.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import{cast as a}from"../../core/accessorSupport/decorators/cast.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import d from"../Widget.js";import c from"./FeatureRelationship/FeatureRelationshipViewModel.js";import u from"./support/FeatureElementInfo.js";import{isRTL as h}from"../support/widgetUtils.js";import{messageBundle as p}from"../support/decorators/messageBundle.js";import{tsx as m}from"../support/jsxFactory.js";import{substitute as v}from"../../intl/substitute.js";const g={base:"esri-feature-relationship",esriWidget:"esri-widget",listContainer:"esri-feature-relationship__list",listContainerQuerying:"esri-feature-relationship__list--querying",featureObserver:"esri-feature__feature-observer",stickySpinnerContainer:"esri-feature__sticky-loading-container",loadingSpinnerContainer:"esri-feature__loading-container",spinner:"esri-feature__loading-spinner",iconLoading:"esri-icon-loading-indicator esri-rotating"},f={title:!0,description:!0};let w=class extends d{constructor(e,t){super(e,t),this._featureElementInfo=null,this._relatedFeatureIntersectionObserver=new IntersectionObserver((([e])=>{e?.isIntersecting&&this._increaseFeaturePage()}),{root:window.document}),this.headingLevel=2,this.viewModel=new c,this.messages=null,this.messagesCommon=null,this.visibleElements={...f},this._increaseFeaturePage=()=>{const{state:e,showAllEnabled:t,relatedFeatures:r,featuresPerPage:s,featurePage:i}=this.viewModel;"ready"===e&&t&&r.length>=s*i&&this.viewModel.featurePage++}}initialize(){this._featureElementInfo=new u,this.addHandles([s((()=>[this.viewModel.description,this.viewModel.title,this.headingLevel]),(()=>this._setupFeatureElementInfo()),i),s((()=>[this.viewModel.state,this.viewModel.showAllEnabled,this._relatedFeatureIntersectionObserverNode]),(()=>this._handleRelatedFeatureObserverChange())),o((()=>this.viewModel.relatedFeatureViewModels),"change",(()=>this._setupRelatedFeatureViewModels()))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-list.js"),import("@esri/calcite-components/dist/components/calcite-list-item.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-notice.js")])}destroy(){this._unobserveRelatedFeatureObserver(),this._featureElementInfo=t(this._featureElementInfo)}get displayShowAllButton(){const{showAllEnabled:e,featureCount:t,displayCount:r}=this.viewModel;return!e&&(t>r||0===r)}get displayListItems(){return this.displayShowAllButton||this.viewModel.relatedFeatureViewModels.length>0}get description(){return this.viewModel.description}set description(e){this.viewModel.description=e}get featureCountDescription(){const{messages:e}=this,{featureCount:t}=this.viewModel;return v(1===t?e?.numberRecord:e?.numberRecords,{number:t})}get title(){return this.viewModel.title}set title(e){this.viewModel.title=e}castVisibleElements(e){return{...f,...e}}renderStickyLoading(){return"querying"===this.viewModel.state?m("div",{key:"sticky-loader",class:g.stickySpinnerContainer},this.renderLoadingIcon()):null}renderLoadingIcon(){return m("span",{class:this.classes(g.iconLoading,g.spinner)})}renderLoading(){return m("div",{key:"loading-container",class:g.loadingSpinnerContainer},this.renderLoadingIcon())}renderShowAllIconNode(){return m("calcite-icon",{scale:"s",icon:"list",slot:"content-end"})}renderChevronIconNode(){const e=h(this.container)?"chevron-left":"chevron-right";return m("calcite-icon",{scale:"s",icon:e,slot:"content-end"})}renderRelatedFeature(e){const{itemDescriptionFieldName:t}=this.viewModel,r=e.title;e.description=t&&e.formattedAttributes?.global[t];const s="loading"===e.state;return m("calcite-list-item",{key:e.uid,label:s?`${this.messagesCommon?.loading}…`:r,description:s?"…":e.description,onclick:()=>this.emit("select-record",{featureViewModel:e})},this.renderChevronIconNode())}renderShowAllListItem(){return this.displayShowAllButton?m("calcite-list-item",{key:"show-all-item",label:this.messages?.showAll,description:this.featureCountDescription,onclick:()=>this.emit("show-all-records")},this.renderShowAllIconNode()):null}renderNoRelatedFeaturesMessage(){return m("calcite-notice",{key:"no-related-features-message",icon:"information",open:!0,color:"blue",scale:"s",width:"full"},m("div",{slot:"message"},this.messages?.noRelatedFeatures))}renderFeatureObserver(){return m("div",{key:"feature-observer",class:g.featureObserver,bind:this,afterCreate:this._relatedFeatureIntersectionObserverCreated})}renderList(){const{relatedFeatureViewModels:e}=this.viewModel;return m("calcite-list",null,e.toArray().map((e=>this.renderRelatedFeature(e))),this.renderShowAllListItem())}renderRelatedFeatures(){const{displayListItems:e}=this,{state:t}=this.viewModel;return m("div",{key:"list-container",class:this.classes(g.listContainer,{[g.listContainerQuerying]:"querying"===t})},e?this.renderList():"ready"===t?this.renderNoRelatedFeaturesMessage():null,this.renderStickyLoading(),this.renderFeatureObserver())}renderRelationshipNotFound(){return m("calcite-notice",{key:"relationship-not-found",icon:"exclamation-mark-triangle",open:!0,color:"red",scale:"s",width:"full"},m("div",{slot:"message"},this.messages?.relationshipNotFound))}render(){const{state:e}=this.viewModel;return m("div",{class:this.classes(g.base,g.esriWidget)},this._featureElementInfo?.render(),"loading"===e?this.renderLoading():"disabled"===e?this.renderRelationshipNotFound():this.renderRelatedFeatures())}_setupRelatedFeatureViewModels(){const{relatedFeatureViewModels:e}=this.viewModel,t="related-feature-viewmodels";this.removeHandles(t),e?.forEach((e=>{this.addHandles(s((()=>[e.title,e.state]),(()=>this.scheduleRender()),i),t)})),this.scheduleRender()}_setupFeatureElementInfo(){const{headingLevel:e,visibleElements:t}=this,r=t.description&&this.description,s=t.title&&this.title;this._featureElementInfo.set({description:r,title:s,headingLevel:e})}async _handleRelatedFeatureObserverChange(){this._unobserveRelatedFeatureObserver();const{state:e,showAllEnabled:t}=this.viewModel;await r(0),this._relatedFeatureIntersectionObserverNode&&"ready"===e&&t&&this._relatedFeatureIntersectionObserver.observe(this._relatedFeatureIntersectionObserverNode)}_relatedFeatureIntersectionObserverCreated(e){this._relatedFeatureIntersectionObserverNode=e}_unobserveRelatedFeatureObserver(){this._relatedFeatureIntersectionObserverNode&&this._relatedFeatureIntersectionObserver.unobserve(this._relatedFeatureIntersectionObserverNode)}};e([n()],w.prototype,"_relatedFeatureIntersectionObserverNode",void 0),e([n({readOnly:!0})],w.prototype,"displayShowAllButton",null),e([n({readOnly:!0})],w.prototype,"displayListItems",null),e([n()],w.prototype,"description",null),e([n({readOnly:!0})],w.prototype,"featureCountDescription",null),e([n()],w.prototype,"headingLevel",void 0),e([n()],w.prototype,"title",null),e([n({type:c})],w.prototype,"viewModel",void 0),e([n(),p("esri/widgets/Feature/t9n/Feature")],w.prototype,"messages",void 0),e([n(),p("esri/t9n/common")],w.prototype,"messagesCommon",void 0),e([n()],w.prototype,"visibleElements",void 0),e([a("visibleElements")],w.prototype,"castVisibleElements",null),w=e([l("esri.widgets.Feature.FeatureRelationship")],w);const b=w;export{b as default};