/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{i as E}from"./YM4U4HSN.js";export default $arcgis.t(([v])=>{var p={FEATURE:"feature",GROUP:"group"};function F(n){return n===p.FEATURE}function I(n){return n===p.GROUP}var b=5e3,R=1e4,y=Symbol("TIMEOUT");function h(n,e,t,r=b){return Promise.race([n,new Promise(o=>{setTimeout(()=>{console.warn(`[InteractiveLegend] Timed out waiting for ${e}${t?` (layer: ${t})`:""} after ${r}ms; continuing.`),o(y)},r)})])}function f(n,e,t,r=b){return h(v.whenOnce(n).then(()=>!0),e,t,r)}function w(n,e,t){let r=t?.layer?.id;n.push(h(j(e,t),"createInteractiveLegendDataForLayer",r).then(o=>o===y?null:o))}function $(n,e){return t=>{let r=t?.layer?.type;if(F(r)||I(r)){w(n,e,t);let o=a=>{w(n,e,a)};t.children.forEach(a=>{o(a),a?.children?.length>0&&a.children.forEach(l=>{o(l),l?.children?.length>0&&l.children.forEach(i=>{o(i)})})})}}}async function j(n,e){try{let t=e?.layer?.id,r=I(e?.layer?.type),o=e?.layer?.layers?.some(s=>s.visible),a=e?.layer?.layers?.every(s=>!s?.legendEnabled);await f(()=>n?.state==="ready","legendViewModel ready",t),!r||r&&o?r&&a?await f(()=>e?.layer?.loaded,"group layer loaded",t):await f(()=>e?.ready,"activeLayerInfo ready",t):await f(()=>!!e?.legendElements,"legendElements",t);let l=e?.legendElements?.[0],i=new Map,u=e.layer,g=n?.view?.whenLayerView(u);if(!g)return null;let m=await h(g,"whenLayerView",t,R);if(m===y)return null;let d=m,L=u.renderer?.field??"";l!==void 0&&l?.infos?.forEach(s=>{if(E(s)){let c=[];s.infos.forEach(U=>{let A={count:null,selected:!1,legendElementInfo:U};c.push(A)});let T={count:null,selected:!1,legendElementInfo:s,nestedInfos:c};i.set(s.title,T)}else{let c={count:null,selected:!1,legendElementInfo:s};i.set(s.label??u.id,c)}});let O=[];return d?Promise.resolve({activeLayerInfo:e,title:d.layer.title,categories:i,field:L,queryExpressions:O,totalCount:null,fLayerView:d,legendElement:l}):Promise.resolve(null)}catch{return await Promise.resolve(null)}}function V(n){return Array.from(n,e=>e[1])}function G(n,e,t,r,o){if(r)return r?.nestedInfos?.[o];let a="label"in t&&t?.label?t?.label:e?.id;return n?.categories?.get(a)}function q(n,e){return n?.nestedInfos?.[e]}function x(n,e){if(typeof e?.title=="string")return n?.categories?.get(e?.title)}async function C(n){let e={},t=[];n.activeLayerInfos.forEach($(t,n));try{return(await Promise.all(t)).forEach(r=>{let o=r?.activeLayerInfo?.layer?.id;e[o]=r}),Promise.resolve(e)}catch{return await Promise.reject(new Error("Failed to generate data"))}}function D(n){let e=[];return n.forEach(t=>P(t,e)),e}function P(n,e){e.push(n),n.children&&n.children.length>0&&n.children.forEach(t=>{P(t,e)})}function S(n,e,t){return!!e[n]||!!t[n]}function N(n,e,t,r){let o={...n};for(let[a,l]of Object.entries(t))l&&(o[a]=l);for(let[a,l]of Object.entries(r))l&&(o[a]=l);return{...o,...e}}return{a:F,b:j,c:V,d:G,e:q,f:x,g:C,h:D,i:S,j:N}},"core/reactiveUtils")