/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../../PopupTemplate.js";import r from"../../core/Error.js";import{fetchMessageBundle as t}from"../../intl/messages.js";import{getContentAndInfos as s,getContentAndInfosForPieChart as n}from"./support/clusterUtils.js";import{isClusterCompatibleRenderer as i}from"../../views/2d/layers/support/clusterUtils.js";async function o(e){const{layer:t,renderer:s}=e;await t.load();const n=s??("renderer"in t?t.renderer:void 0);if(!i(n))throw new r("clusters-popup:invalid-parameters","'renderer' is not valid");return{layer:t,renderer:n}}async function l(r){const[{renderer:i,layer:l},a]=await Promise.all([o(r),t("esri/smartMapping/t9n/smartMapping")]),p=await s(l,i,a);if(null==p)return null;const u={name:"clusters",title:a.clusters.templateTitle,value:new e({fieldInfos:p.fieldInfos,expressionInfos:p.expressionInfos,content:p.content,title:a.clusters.clusterPopupTitle})},c=[],f=l.featureReduction,m=f&&"renderer"in f?f.renderer:null;if("pie-chart"===m?.type){const r=await n(l,m,a);null!=r&&c.push({name:"clusters-pie-chart",title:"clusters-pie-chart",value:new e({fieldInfos:r.fieldInfos,expressionInfos:r.expressionInfos,content:r.content,title:a.clusters.clusterPopupTitle})})}return{primaryTemplate:u,secondaryTemplates:c}}export{l as getTemplates};
