/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../PopupTemplate.js";import r from"../../core/Error.js";import{fetchMessageBundle as n}from"../../intl/messages.js";import{getPrimaryVisualVariables as s,hasNormalizedField as t,getFieldAndExpressionInfos as i,getContentFromFieldInfos as p}from"./support/utils.js";import{createPopupTemplate as a}from"../../support/popupUtils.js";async function o(e){const{layer:n,renderer:s}=e;await n.load();const t=s??("renderer"in n?n.renderer:void 0);if("simple"!==t?.type)throw new r("simple-popup:invalid-parameters","renderer.type must be 'simple'");return{layer:n,renderer:t}}async function l(r,n,s="divide"){const{fieldInfos:t,expressionInfos:a}=await i({renderer:r,layer:n,normFieldExpressionTemplate:s});return new e({content:await p(n,{fieldInfos:t,expressionInfos:a}),expressionInfos:a,fieldInfos:t})}async function m(e){const[{renderer:r,layer:i},p]=await Promise.all([o(e),n("esri/smartMapping/t9n/smartMapping")]),m=[];if(!s(r).length){const e=a(i);return e?{primaryTemplate:{name:"simple",title:p.simple,value:e},secondaryTemplates:m}:null}const c={name:"simple",title:p.simple,value:await l(r,i)};return t(r)&&m.push({name:"simple-percent",title:p.simpleNormFieldAsPercent,value:await l(r,i,"percentage")}),{primaryTemplate:c,secondaryTemplates:m}}export{m as getTemplates};
