/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{convertNumberFieldFormatToIntlOptions as t,convertNumberFormatToIntlOptions as e,formatNumber as n}from"../../../intl.js";import{millisecondsPerTimeUnit as i}from"../../../core/timeUtils.js";import o from"../../../layers/support/DateTimeFieldFormat.js";import{getFieldConfigurationsContainer as r}from"../../../layers/support/layerUtils.js";import l from"../../../popup/support/FieldInfoFormat.js";import{format as a}from"../../../renderers/support/numberUtils.js";import{formatAnyDate as A}from"../../../smartMapping/support/utils.js";import s from"../../../symbols/SimpleLineSymbol.js";const u="<",f=">";function m(t,e,n,i){let o="";0===e?o=`${u} `:e===n&&(o=`${f} `);const r=d(t,i);return null==r?"":o+r}function p(t){const{format:e,fieldFormat:n}=t||{};return"number"===n?.type||!!e&&null==e.dateFormat&&(null!=e.places||null!=e.digitSeparator)}function d(i,o){if(null==i)return i;const{fieldType:r,format:l,fieldFormat:s,timeZoneOptions:u}=o||{};if(U(r))return A(i,{fieldType:r,format:l?.dateFormat,fieldFormat:"date-time"===s?.type?s:void 0,timeZoneOptions:u});if("string"==typeof i&&p(o)){const t=Number(i);isNaN(t)||(i=t)}if("string"==typeof i)return i;const f="number"===s?.type?t(s):l?e(l):void 0;return f?n(i,f):a(i)}const c=["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAAAAAAAAAHqZRakAAAANUlEQVQ4jWPMy8v7z0BFwMLAwMAwcdIkqhiWn5fHwEQVk5DAqIGjBo4aOGrgqIEQwEjtKgAATl0Hu6JrzFUAAAAASUVORK5CYII=","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAAAAAAAAAHqZRakAAAANUlEQVQ4jWPMy8v7z0BFwMLAwMAwaeIkqhiWl5/HwEQVk5DAqIGjBo4aOGrgqIEQwEjtKgAATl0Hu6sKxboAAAAASUVORK5CYII=","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAAAAAAAAAHqZRakAAAANUlEQVQ4jWPMy8v7z0BFwMLAwMAwadJEqhiWl5fPwEQVk5DAqIGjBo4aOGrgqIEQwEjtKgAATl0Hu75+IUcAAAAASUVORK5CYII="];async function g(t){if(!("visualVariables"in t)||!t.visualVariables)return null;const e=t.visualVariables.find(t=>"color"===t.type);if(!e)return null;let n=null,i=null;if(e.stops){if(1===e.stops.length)return e.stops[0].color;n=e.stops[0].value,i=e.stops[e.stops.length-1].value}const o=null!=n&&null!=i?n+(i-n)/2:0,{getColor:r}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");return r(e,o)??null}async function w(t,e){const n=t.trailCap,i=t.trailWidth||1,o=e||await g(t)||t.color;return new s({cap:n,color:o,width:i})}function y(t,e){if(!e)return null;if("featureReduction"in t)switch(t.featureReduction?.type){case"cluster":case"binning":{const n=t.featureReduction.fields.find(({name:t})=>t.toLowerCase()===e.toLowerCase());return n?.type?n:n&&"getField"in t?t.getField(n.onStatisticField):null}}return"getField"in t?t.getField?.(e):null}function I(t,e){const n="popupTemplate"in t?t.popupTemplate?.fieldInfos:null;if(n?.length&&e)return n.find(t=>t.fieldName?.toLowerCase()===e.toLowerCase())}function F(t){let e=0,n=0;return t.stops?(e=t.stops?.at(0)?.value??e,n=t.stops?.at(-1)?.value??n):"minDataValue"in t&&"maxDataValue"in t&&(e=t.minDataValue??e,n=t.maxDataValue??n),n-e>2*i.days?"short-date":"short-date-short-time"}function U(t){return["date","date-only","time-only","timestamp-offset"].includes(t||"")}function h(t,e,n){const i=C(t,e.field,n);return i?(U(i.fieldType)&&(i.fieldConfigurationsContainer?i.fieldFormat??=new o({dateStyle:"short",timeStyle:"short-date-short-time"===F(e)?"short":null}):i.format??=new l({dateFormat:F(e)})),i):null}function C(t,e,n){const i=y(t,e),o=i?.name;if(!o)return null;const l=i?.type,a=r(t,{checkFeatureReduction:!0});return{fieldType:l,format:a?null:I(t,o)?.format,fieldFormat:a?a.getFieldConfiguration(o)?.fieldFormat:null,fieldConfigurationsContainer:a,timeZoneOptions:U(l)?{layerTimeZone:"preferredTimeZone"in t?t.preferredTimeZone:null,viewTimeZone:n,datesInUnknownTimezone:"datesInUnknownTimezone"in t&&t.datesInUnknownTimezone}:null}}function V(t,e){if("authoringInfo"in t)return t.authoringInfo?.visualVariables?.find(({theme:t})=>t===e)}function j(t,e){let n=null!=t?t:"";return null!=e&&e&&(n=n?"("+n+") AND ("+e+")":e),n}export{m as createStopLabel,d as formatValue,V as getAuthoringInfoVisualVariableByTheme,C as getFormatOptions,h as getFormatOptionsForVisualVariable,g as getMedianColor,w as getSymbolForFlowRenderer,j as mergeWhereClauses,c as rgbImgSource,f as specialCharsGreaterThan,u as specialCharsLessThan};
