/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{substitute as t}from"../../../intl.js";import{property as r,subclass as s}from"../../../core/accessorSupport/decorators.js";import i from"../../Widget.js";import{css as o}from"../css.js";import{loadCalciteComponents as n}from"../../support/componentsUtils.js";import{Heading as a,incrementHeadingLevel as c}from"../../support/Heading.js";import{ItemList as l}from"../../support/ItemList.js";import{fetchThumbnail as m}from"../../support/symbolPreviewUtils.js";import{messageBundle as d,tsx as p,tsxFragment as h}from"../../support/widget.js";let u=class extends i{constructor(){super(...arguments),this.workflow=null,this.headingLevel=4,this._iconIntersectionObserver=new IntersectionObserver((e,r)=>{e.forEach(async e=>{if(e.isIntersecting){const s=e.target;if(g(s))return void r.unobserve(s);const i=f(s),{graphic:o}=i,n=o.sourceLayer??this.workflow?.layer;if(!n||!o)return;v(s,!0);const a=i.id?t(this.messages.previewTemplateAriaLabel,{label:i.id}):this.messagesCommon.preview,c=await m(o,n,{ariaLabel:a}).catch(()=>(v(s,!1),null));if(null==c)return;s.appendChild(c)}})}),this.messages=null,this.messagesCommon=null,this._renderItemContentEnd=({graphic:e})=>{const{workflow:t}=this;if(t?.isKeyFeature(e)){const e=this.messages.preserved;return p("calcite-chip",{class:o.mergeFeaturesListItemPreserved,icon:"check",label:e,scale:"s",slot:"content-end"},e)}if(t?.isTemporaryHighlightFeature(e)){const e=this.messages.preserve;return p("calcite-chip",{label:e,scale:"s",slot:"content-end"},e)}},this._renderItemIcon=e=>{if(null!=e?.graphic?.geometry)return p("span",{afterCreate:this._afterItemCreateOrUpdate,afterRemoved:this._afterItemRemoved,afterUpdate:this._afterItemCreateOrUpdate,"data-has-icon":!1,"data-item":e,key:"icon"})},this._afterItemCreateOrUpdate=e=>{this._iconIntersectionObserver?.observe(e)},this._afterItemRemoved=e=>{this._iconIntersectionObserver?.unobserve(e)}}loadDependencies(){return n({chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),list:()=>import("@esri/calcite-components/dist/components/calcite-list")})}destroy(){this._iconIntersectionObserver?.disconnect(),this._iconIntersectionObserver=null}render(){const{workflow:e}=this;if(!e)return p(h,null,void 0);const t=this.messages,r=e.data.features.map((t,r)=>({disabled:!1,id:`${e.getFeatureTitle(t)??r}`,graphic:t,selected:t===e.data.keyFeature}));return p("div",{class:o.mergeFeaturesList},p(a,{level:c(this.headingLevel)},t.editFeaturesList),p("calcite-list",{label:t.result},l({enableListScroll:!1,filterEnabled:!1,id:"merge-features-pick-list",items:r,messages:{filterPlaceholder:"",noItems:"",noMatches:""},selectionMode:"single",renderIcon:this._renderItemIcon,renderItemLabel:e=>e.id,onItemMouseEnter:t=>{e&&(e.data.temporaryHighlightFeature=t.graphic)},onItemMouseLeave:()=>{e&&(e.data.temporaryHighlightFeature=null)},onItemSelect:e=>{this.workflow?.setKeyFeature(e.graphic)},renderItemContentEnd:this._renderItemContentEnd})))}};function f(e){return e?.["data-item"]}function g(e){return!!e?.["data-has-icon"]}function v(e,t){e&&(e["data-has-icon"]=t)}e([r()],u.prototype,"workflow",void 0),e([r()],u.prototype,"headingLevel",void 0),e([r(),d("esri/widgets/Editor/t9n/Editor")],u.prototype,"messages",void 0),e([r(),d("esri/t9n/common")],u.prototype,"messagesCommon",void 0),u=e([s("esri.widgets.Editor.components.MergeFeaturesList")],u);const I=u;export{I as default};
