/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
function e(e,n){const r=[];if(!e)return r;if("valueExpression"in e&&e.valueExpression){const t={expression:e.valueExpression,title:e.valueExpressionTitle,profileInfo:{name:"visualization",context:`${e.type}-renderer`,source:n}};r.push(t)}if("visualVariables"in e&&e.visualVariables){const t=e.visualVariables.filter(({valueExpression:e})=>e&&"$view.scale"!==e).map(({valueExpression:e,valueExpressionTitle:r,type:t})=>({expression:e,title:r,profileInfo:{name:"visualization",context:`${t}-variable`,source:n}}));r.push(...t)}if("attributes"in e&&e.attributes){const t=e?.attributes.filter(({valueExpression:e})=>e).map(({valueExpression:r,valueExpressionTitle:t})=>({expression:r,title:t,profileInfo:{name:"visualization",context:`${e.type}-renderer`,source:n}}));r.push(...t)}return r}function n(e,n){const r=[];if(e?.expressionInfos){const t=e?.expressionInfos.map(({title:e,name:r,expression:t,returnType:o})=>({title:e,name:r,expression:t,profileInfo:{name:"layer"===n?"popup":"popup-feature-reduction",context:"popup-template",returnType:o,source:n}}));r.push(...t)}if(e?.content&&Array.isArray(e.content)){const t=e?.content.filter(({type:e})=>"expression"===e).map(({expressionInfo:e})=>({title:e.title,expression:e.expression,profileInfo:{name:"layer"===n?"popup-element":"popup-element-feature-reduction",context:"popup-expression-content",returnType:e.returnType,source:n}}));r.push(...t)}return r}function r(e){const n=[];if(e?.featureExpressionInfo?.expression){const r={expression:e?.featureExpressionInfo?.expression,profileInfo:{name:"feature-z",context:"elevation-info",source:"layer"}};n.push(r)}return n}function t(e){const n=[];if(e){const r=e.filter(({valueExpression:e})=>e).map(({valueExpression:e})=>({expression:e,profileInfo:{name:"feature-z",context:"order-by",source:"layer"}}));n.push(...r)}return n}function o(e){const n=[];if(e?.expressionInfos){const r=e?.expressionInfos.map(({title:e,name:n,expression:r,returnType:t})=>({title:e,name:n,expression:r,profileInfo:{name:"boolean"===t?"form-constraint":"form-calculation",context:"form-template",returnType:t,source:"layer"}}));n.push(...r)}return n}function s(r){return[...n(r?.popupTemplate,"feature-reduction"),...p(r?.labelingInfo,"feature-reduction"),...e(r?.renderer,"feature-reduction"),...i(r?.fields)]}function i(e){const n=[];if(e){const r=e.filter(({onStatisticExpression:e,isAutoGenerated:n})=>e&&!n).map(({onStatisticExpression:{expression:e,title:n}})=>({expression:e,title:n,profileInfo:{name:"aggregate-field",context:"aggregate-field",source:"feature-reduction"}}));n.push(...r)}return n}function p(e,n){const r=[];if(e){const t=e.filter(({labelExpressionInfo:e})=>e?.expression).map(({labelExpressionInfo:e})=>({expression:e?.expression,title:e?.title,profileInfo:{name:"labeling",context:"label-class",source:n}}));r.push(...t)}return r}function a(i){const a=[...p(i.labelingInfo,"layer"),...n(i.popupTemplate,"layer"),...e(i.renderer,"layer")];if("elevationInfo"in i&&a.push(...r(i.elevationInfo)),"featureReduction"in i&&a.push(...s(i.featureReduction)),"trackInfo"in i){const r=i.trackInfo;a.push(...e(r?.latestObservations.renderer),...e(r?.previousObservations.renderer),...e(r?.trackLines.renderer),...p(r?.latestObservations.labelingInfo),...p(r?.previousObservations.labelingInfo),...p(r?.trackLines.labelingInfo),...n(r?.popupTemplate))}return"orderBy"in i&&a.push(...t(i.orderBy)),"formTemplate"in i&&a.push(...o(i.formTemplate)),a}export{a as getExpressionsFromLayer};
