/* 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{property as i,subclass as o}from"../../core/accessorSupport/decorators.js";import{fetchMessageBundle as s}from"../../intl/messages.js";import a from"../Widget.js";import{css as n}from"../Features/css.js";import{zoomToFeature as r}from"../Popup/actions.js";import{loadCalciteComponents as c}from"../support/componentsUtils.js";import{messageBundle as l,tsx as d,tsxFragment as u}from"../support/widget.js";const m=r.clone(),p={featureContent:`${"esri-utility-network-trace"}__feature-content`};let h=class extends a{constructor(e,t){super(e,t),this._utilityNetworkTraceMessages=null,this.closed=!1,this.closable=!0,this.messages=null,this.messagesCommon=null,this._handleAddNonspatialTraceLocation=e=>{this.emit("add-nso-trace-location",{featureWidget:e})},this._handleOpenFeature=e=>{this.emit("open-feature",{feature:e})},this._handleZoomToFeature=e=>{this.emit("zoom-to-feature",{featureWidget:e})}}initialize(){(async()=>{this._utilityNetworkTraceMessages=await s("esri/widgets/UtilityNetworkTrace/t9n/UtilityNetworkTrace")})()}loadDependencies(){return c({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item")})}get mode(){return this._get("mode")||"show-feature-info"}set mode(e){this._set("mode",e)}render(){const{flowItems:e}=this,t=e?.toArray();return d(u,null,t?.map((t,i)=>this._renderFlowItem(t,i===e.length-1)))}_renderAddNonspatialTraceLocationAction(e){const{_utilityNetworkTraceMessages:t}=this;return d("calcite-action",{bind:this,icon:"utility-network-trace",scale:"s",text:t.inputsStrings.addNonspatialOption,textEnabled:!0,title:t.inputsStrings.addNonspatialOption,onclick:()=>this._handleAddNonspatialTraceLocation(e)})}_renderFlowItem(e,t){const{messages:i,closable:o,closed:s}=this,a="graphic"in e&&!e.isTable,r="feature-association"===e.flowType,c=this._getExitMessage(e),l=i.selectFeature,u=e,m=u?u.graphic?.sourceLayer:null,h=!(m?m.geometryType:null);return d("calcite-flow-item",{bind:this,closable:o,closed:s,description:this._getDrillInFlowItemDescription(e),heading:e.title??"",key:`flow-item-${e.viewModel.uid}`,selected:t,onCalciteFlowItemBack:e=>{e.preventDefault(),this._handleDrillInBackClick()}},d("calcite-action",{bind:this,class:n.actionExit,icon:"move-up",key:"exit-action",slot:"header-actions-start",text:c,title:c,onclick:this._handleExitClick}),a?d("calcite-action",{bind:this,icon:"zoom-to-object",key:"open-feature-action",slot:"header-actions-end",text:l,title:l,onclick:()=>this._handleOpenFeature(e)}):null,"show-feature-info"===this.mode?d("calcite-action",{icon:"x",slot:"header-actions-end",text:this.messagesCommon.close,onclick:()=>{this.emit("close")}}):void 0,r&&"add-nso"===this.mode?d("calcite-action-bar",{expandDisabled:!0,expanded:!0,key:"header-action-bar",scale:"s",slot:"action-bar"},d("calcite-action-group",{overlayPositioning:"fixed",scale:"s"},h?this._renderAddNonspatialTraceLocationAction(e):this._renderZoomToFeatureAction(e))):null,d("div",{class:this.classes(n.container,p.featureContent)},e.render()))}_renderZoomToFeatureAction(e){const t=this._getActionTitle(m);return d("calcite-action",{active:m.active,bind:this,"data-action-uid":m.uid,disabled:m.disabled,icon:m.icon??"question",indicator:m.indicator,key:`action-${m.uid}`,loading:m.active,scale:"s",text:t,textEnabled:!0,title:t,onclick:()=>this._handleZoomToFeature(e)})}_getActionTitle(e){const{messages:i}=this,{id:o}=e,s=e.title??"";return"zoom-to-feature"===o?t(s,{messages:i}):s}_getDrillInFlowItemDescription(e){switch(e.flowType){case"feature":case"feature-association":case"feature-utility-network-associations":return e.viewModel.description??"";case"feature-relationship":return e.allItemsDescription;case"feature-utility-network-association-type":return e.description??""}}_getExitMessage(e){switch(e.flowType){case"feature":case"feature-association":return"";case"feature-relationship":return this.messages.exitRelatedRecords;case"feature-utility-network-associations":case"feature-utility-network-association-type":return this.messages.exitAssociations}}_handleDrillInBackClick(){const e=this.flowItems?.pop();e&&("showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e&&(e.viewModel=null,e.destroy()))}_handleExitClick(){this.emit("exit")}};e([i()],h.prototype,"closed",void 0),e([i()],h.prototype,"closable",void 0),e([i()],h.prototype,"flowItems",void 0),e([i(),l("esri/widgets/Features/t9n/Features")],h.prototype,"messages",void 0),e([i(),l("esri/t9n/common")],h.prototype,"messagesCommon",void 0),e([i()],h.prototype,"mode",null),h=e([o("esri.widgets.UtilityNetworkTrace.UtilityNetworkTraceFeaturesDrillIn")],h);const f=h;export{f as default};
