/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{getOrCreateMapValue as t}from"../../core/MapUtils.js";const e={key:Symbol(),label:"Other​"};function n(t){return"templateInfos"in t}function o(t){const e=[];for(const{layer:n,templates:o}of t)for(const t of o)e.push({layer:n,template:t});return e}function a(n,o){const a=new Map;for(const l of n){const n=o(l),{key:r,label:s}=null!=n.key?n:e;t(a,r,()=>({label:s,templateInfos:[]})).templateInfos.push(l)}return Array.from(a.values())}function l(t,e){return{label:t.title??"",templateInfos:e.map(e=>({layer:t,template:e}))}}async function r(t,e){return"subtype-sublayer"===t.type?await(t.parent?.load(e)):await t.load(e),t}function s(t){const e=new Map,n=[];for(const o of t)if(f(o)){n.push(o);for(const t of o.items)e.set(t.template,t)}else e.set(o.template,o);return[e,n]}const f=t=>"items"in t;export{n as isTemplateGroupInfo,f as isTemplateItemGroup,r as loadLayerWithTemplates,a as makeGroupItemInfos,l as makeTemplateGroupInfoForLayer,o as makeTemplateItemInfos,s as mapItemsByTemplate,e as nullGroupBy};
