/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"./Field.js";const a="Raster.",n="Raster.Dim.",t=".Max",i={servicePixelValue:"Raster.ServicePixelValue",rawServicePixelValue:"Raster.ServicePixelValue.Raw",itemPixelValue:"Raster.ItemPixelValue",magnitude:"Raster.Magnitude",direction:"Raster.Direction",variable:"Raster.Variable"},r=new Map([["quarters","Quarter"],["months","Month"],["weeks","Week of the year"],["days","Day of the year"]]);function l(a,n){return new e({name:a,alias:n,domain:null,editable:!1,length:50,type:"string"})}function s(a,n){return new e({name:a,alias:n,domain:null,editable:!1,type:"double"})}function u(a,n){return new e({name:a,alias:n,domain:null,editable:!1,type:"date"})}function o(e){return l(i.servicePixelValue,e??"Service Pixel Value")}function c(e){return l(i.rawServicePixelValue,e??"Raw Service Pixel Value")}function m(){return l(i.itemPixelValue,"Item Pixel Value")}function f(e){return l(`${i.servicePixelValue}.${e}`,e)}function d(e){return s(`${i.magnitude}`,"Magnitude"+(e?` (${e})`:""))}function $(){return s(`${i.direction}`,"Direction (°)")}function v(e){return e.fields.filter(e=>"oid"!==e.type&&"value"!==e.name.toLowerCase()).map(e=>{const n=e.clone();return n.name=`${a}${e.name}`,n})}function p(e){const a=new Set,r=new Set,o=new Map;e.variables.forEach(({dimensions:e})=>{e.forEach(e=>{if(e.recurring)o.set(e.name,e.unit);else{const n="ISO8601"===e.unit?.trim()||"stdtime"===e.name?.trim()?.toLowerCase()?a:r;n.add(e.name),e.hasRanges&&n.add(`${e.name}${t}`)}})});return[l(i.variable,"Variable"),...[...a].map(e=>u(`${n}${e}`,x(e))),...[...r].map(e=>s(`${n}${e}`,x(e))),...[...o].map(([e,a])=>s(`${n}${e}`,h(e,a)))]}function h(e,a){return a=a?.toLowerCase(),a&&r.has(a)?r.get(a):x(e)}function x(e){const a=e.endsWith(t),n=a?e.slice(0,-4):e,i="StdTime"===n?"Standard Time":"StdZ"===n?"Standard Z":n;return a?`${i} Max`:i}function w(e,a){return a?new Date(e):e}function V(e,a,r){r?.length&&(a[i.variable]=r[0].variableName,r.forEach(({dimensionName:i,values:r})=>{if(i&&r?.length){const l=`${n}${i}`,s=e.find(({name:e})=>e===l);if(!s)return;const u="date"===s.type,o=r[0];if(Array.isArray(o)){if(a[`${n}${i}`]=w(o[0],u),null!=o[1]){const r=`${n}${i}${t}`;if(e.some(({name:e})=>e===r)){const e=w(o[1],u);a[r]=e}}}else a[`${n}${i}`]=w(o,u)}}))}function b(e,a){if(a.pixelType.startsWith("f")&&e.forEach(({format:e,fieldName:a})=>{e&&a&&/^raster\.(item|service)pixelvalue/i.test(a)&&(e.places=2)}),a.multidimensionalInfo){const i=a.multidimensionalInfo.variables.flatMap(({dimensions:e})=>e);e.forEach(({format:e,fieldName:a})=>{if(e&&a?.startsWith(n)){const r=a.slice(n.length),l=`${r}${t}`,s=i.find(({name:e})=>e===r||e===l);s?.values?.every(e=>Number.isInteger(e))&&(e.places=0)}})}}export{V as addMultidimensionalFieldValues,i as commonRasterFieldNames,$ as getDirectionField,m as getItemPixelValueField,d as getMagnitudeField,p as getMultidimensionalFields,f as getProcessedServicePixelValueField,v as getRasterAttributeTableFields,c as getRawServicePixelValueField,o as getServicePixelValueField,n as rasterDimensionFieldPrefix,a as rasterFieldPrefix,b as setDefaultRasterFieldFormats};
