/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../../core/Error.js";import i from"../statistics/summaryStatisticsForAge.js";import{supportedAgeUnits as s}from"../statistics/support/ageUtils.js";import{defaultStatisticTypes as n,unitValueInDays as a}from"../support/utils.js";function o(t){const i=Math.abs(t.avg);let n=null;return s.some(t=>{const s=a[t];return i>2*s&&(n=t),!!n}),n}async function r(s){const a="days",r={...s,outStatisticTypes:n,unit:a},u=await i(r);if(null==u.avg)throw new t("age-unit:insufficient-info","'avg' statistics is invalid");const c=o({...u,avg:u.avg});if(c===a)return{unit:c,statistics:u};r.unit=c;const e=await i(r);if(null==e.avg)throw new t("age-unit:insufficient-info","'avg' statistics is invalid");return{unit:c,statistics:e}}export{r as default};
