/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../core/Error","../../support/utils","../../support/adapters/support/layerUtils"],(function(e,t,n,r){"use strict";const a=["date","number"],i=["years","months","days","hours","minutes","seconds"];function s(e,r,i,s){const o=[];let u=null;return[r,i].every((t=>{const r=n.getDateType(e,t);return r&&o.push(r),!!r}))?o[0]===o[1]?"field"===o[0]?r===i&&(u=new t(s,"'startTime' and 'endTime' parameters cannot be identical")):u=new t(s,"Invalid combination of 'startTime' and 'endTime' parameters"):a.includes(o[0])&&a.includes(o[1])&&(u=new t(s,"Invalid combination of 'startTime' and 'endTime' parameters")):u=new t(s,"'startTime' and 'endTime' parameters must be one of these values: a date object, unix epoch time, name of a valid date field or <now>"),u}function o(e){const t=e.map((e=>`$feature["${e}"];`));return t.length?t.join("\n")+"\n":""}function u(e,t,n){let r;return r="number"===t?e:"date"===t?e.getTime():'$feature["'+e+'"]',"var "+n+" = "+r+";"}function d(e,t,r,a){const i=n.getDateType(e,t),s=n.getDateType(e,r),d=[u(t,i,"startTime"),u(r,s,"endTime"),`var retVal = null;\n\n    if (startTime != null && endTime != null) {\n      startTime = Date(startTime);\n      endTime = Date(endTime);\n      retVal = DateDiff(endTime, startTime, "${a}");\n    }\n\n    return retVal;`],m=[];return"field"===i&&m.push(t),"field"===s&&m.push(r),o(m)+d.join("\n")}function m(e){const{layer:t,startTime:a,endTime:i}=e,s=r.createLayerAdapter(t),o=e.unit||"days",u=n.getDateDiffSQL(s,a,i,o);return{valueExpression:d(s,a,i,o),statisticsQuery:u,histogramQuery:u}}e.getAgeExpressions=m,e.supportedAgeUnits=i,e.verifyDates=s,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
