/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{isSome as e}from"../../core/arrayUtils.js";import{templateHasKey as t,replace as r}from"../../core/string.js";import{convertDateTimeFieldFormatToIntlOptions as o}from"../../intl/date.js";import{defaultFieldFormat as i}from"../../layers/support/fieldFormatUtils.js";import{isTimeOnlyField as s}from"../../layers/support/fieldUtils.js";import{supportsFieldConfiguration as n}from"../../layers/support/layerUtils.js";import{isAnyDateField as m}from"../../smartMapping/support/utils.js";import{getLabelForDateFieldValue as a,getIntlOptionsForField as l}from"../support/dateUtils.js";function f(r){const{attributes:o,layer:i,label:s,timeZone:n}=r;if(!o||"object"!=typeof o)return s;const m=Object.keys(o).filter(e=>t(s,e)),a=m.map(e=>o[e]),l=m.map(e=>i.fieldsIndex.get(e)).filter(e);return p(s,u({fields:l,layer:i,timeZone:n,values:a}))}function p(e,t){return r(r(e,e=>`{${e.toLowerCase()}}`),Object.fromEntries(Object.entries(t).map(([e,t])=>[e.toLowerCase(),t])))}function u(e){const{layer:t,values:r}=e,o=e.fields??t.fields??[],i=e.timeZone??void 0,n=o.map((e,o)=>{let n=r[o];if("coded-value"===e.domain?.type){const t=e.domain.codedValues.find(e=>e.code===n);t?.name&&(n=t.name)}return(m(e)||s(e))&&(n=a(e,n,{timeZone:i,...d(t,e)})),[e.name,n]});return Object.fromEntries(n)}function d(e,t){if(n(e)){const r=e.getFieldConfiguration(t.name)?.fieldFormat??i(t);if("date-time"===r?.type)return o(r)}return l(t)}export{u as getComputedAttributes,d as getDateTimeFormatOptions,f as parseFormTemplateString,p as substituteFieldTemplatesInString};
