/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{isSome as e}from"../../../core/arrayUtils.js";import{getEffectiveFieldAlias as t}from"../../../editing/fieldUtils.js";import{getDisplayFieldName as o}from"../../../layers/support/fieldUtils.js";import{findEditorItemForLayer as r}from"../workflowUtils.js";import{loadPanelContentComponents as s,PanelContentSection as l,PanelContent as i}from"./PanelContent.js";import{loadCalciteComponents as n}from"../../support/componentsUtils.js";import{ItemList as a}from"../../support/ItemList.js";import{tsx as c}from"../../support/widget.js";const m=()=>Promise.all([s(),n({action:()=>import("@esri/calcite-components/dist/components/calcite-action")})]);function d({editorItems:t,filterText:o,id:s,messagesTemplates:n,onFilterTextChange:m,onSelectFeature:d,onZoomTo:p,workflow:g,editorMessages:j}){const y=new Map,I=g.data.candidates;let b=0;I.map(e=>({label:u(e),id:e.attributes[e.layer.objectIdField],data:e})).filter(({label:e,data:s})=>{const l=o.toLowerCase(),{title:i}=s.layer,n=r(t,s.sourceLayer);return n?n.supportsUpdateWorkflow&&(!l||e?.toLowerCase().includes(l)||i?.toLowerCase().includes(l)):null}).filter(e).forEach(e=>{b++;const t=e.data.layer;y.has(t)?y.get(t)?.items.push(e):y.set(t,{id:`${t.id}`,label:t.title??"",items:[e]})});const h=t.toArray().map(({layer:e})=>y.get(e)).filter(e),w=b>10||o.length>0;return c(i,{key:"feature-list"},c(l,null,a({enableListScroll:!1,filterEnabled:w,filterText:o,id:s,items:h,messages:{filterPlaceholder:n.filterPlaceholder,noItems:n.noItems,noMatches:n.noMatches},onFilterChange:e=>m(e),onItemMouseEnter:e=>d(e.data),onItemMouseLeave:()=>d(null),onItemSelect:e=>d(e.data,!0),renderItemActionEnd:e=>f(e.data,p,j.zoomTo)})))}function u(e){const r=e.sourceLayer??e.layer;if(!r)return null;const s=r.fieldsIndex.get(r.objectIdField);if(!s)return null;const l=t(s,r)||s.name,i=e.attributes,n=o(r);return n&&i[n]&&`${i[n]}`||`${l}: ${i[s.name]}`}function f(e,t,o){return c("calcite-action",{icon:"zoom-to-object",onclick:()=>t(e),slot:"actions-end",text:o,title:o})}export{d as FeatureList,m as loadFeatureListComponents};
