/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../PopupTemplate.js";import n from"../../core/Error.js";import{fetchMessageBundle as t}from"../../intl/messages.js";import i from"../../popup/ExpressionInfo.js";import o from"../../popup/FieldInfo.js";import{getFieldAndExpressionInfos as s,getContentFromFieldInfos as r,expressionFieldPrefix as a}from"./support/utils.js";import{getArcadeForOrderedFields as d,getArcadeForPredominantCategoryAlias as f}from"../statistics/support/predominanceUtils.js";async function l(e){const{layer:t,renderer:i}=e;await t.load();const o=i??("renderer"in t?t.renderer:void 0);if("dot-density"!==o?.type)throw new n("dot-density-popup:invalid-parameters","renderer.type must be 'dot-density'");return{layer:t,renderer:o}}async function p(n,t){const{fieldInfos:i,expressionInfos:o}=await s({renderer:n,layer:t});return new e({content:await r(t,{fieldInfos:i,expressionInfos:o}),expressionInfos:o,fieldInfos:i})}async function m(n,t,r){const{fieldInfos:f,expressionInfos:l}=await s({renderer:n,layer:t}),p=f.filter(e=>!e.fieldName?.includes(a)),m={fieldInfo:new o({fieldName:"expression/dot-density-categories-list"}),expressionInfo:new i({name:"dot-density-categories-list",title:r.listOfCategories,expression:d(p,l)})},c=new e({expressionInfos:[m.expressionInfo],fieldInfos:[m.fieldInfo],title:r.competingFields,content:`{${m.fieldInfo.fieldName}}`});return{name:"dot-density-categories-list",title:r.orderedListOfValues,value:c}}async function c(n,t,r){const{fieldInfos:d,expressionInfos:l}=await s({renderer:n,layer:t}),p=d.filter(e=>!e.fieldName?.includes(a)),m={fieldInfo:new o({fieldName:"expression/dot-density-category"}),expressionInfo:new i({name:"dot-density-category",title:r.predominantCategory,expression:f(p,l)})},c=new e({expressionInfos:[m.expressionInfo,...l],fieldInfos:[m.fieldInfo,...d],content:[{type:"text",text:`<div><b><font size="3">{${m.fieldInfo.fieldName}}</font></b></div>`},{type:"media",mediaInfos:{type:"pie-chart",title:r.competingFields,value:{fields:d.map(e=>e.fieldName)}}}]});return{name:"dot-density-category-chart",title:r.predominantCategoryWithChart,value:c}}async function y(e){const[{renderer:n,layer:i},o]=await Promise.all([l(e),t("esri/smartMapping/t9n/smartMapping")]);return{primaryTemplate:{name:"dot-density",title:o.dotDensity,value:await p(n,i)},secondaryTemplates:[await m(n,i,o),await c(n,i,o)]}}export{y as getTemplates};
