/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/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,r){let t;if("layer"!==e)t="-feature-reduction";else switch(n){case"imagery":case"imagery-tile":t="-imagery";break;case"voxel":t="-voxel";break;default:t=""}return`${r?"popup-element":"popup"}${t}`}function r(e,r,t){const o=[];if(e?.expressionInfos){const s=e?.expressionInfos.map(({title:e,name:o,expression:s,returnType:i})=>({title:e,name:o,expression:s,profileInfo:{name:n(r,t,!1),context:"popup-template",returnType:i,source:r}}));o.push(...s)}if(e?.content&&Array.isArray(e.content)){const s=e?.content.filter(({type:e})=>"expression"===e).map(({expressionInfo:e})=>({title:e.title,expression:e.expression,profileInfo:{name:n(r,t,!0),context:"popup-expression-content",returnType:e.returnType,source:r}}));o.push(...s)}return o}function t(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 o(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 s(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 i(n){return[...r(n?.popupTemplate,"feature-reduction"),...p(n?.labelingInfo,"feature-reduction"),...e(n?.renderer,"feature-reduction"),...a(n?.fields)]}function a(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 l(n){const a=[];if("labelingInfo"in n&&a.push(...p(n.labelingInfo,"layer")),a.push(...r(n.popupTemplate,"layer",n.type)),"renderer"in n&&"imagery"!==n.type&&"imagery-tile"!==n.type&&a.push(...e(n.renderer,"layer")),"elevationInfo"in n&&a.push(...t(n.elevationInfo)),"featureReduction"in n&&a.push(...i(n.featureReduction)),"trackInfo"in n){const t=n.trackInfo;a.push(...e(t?.latestObservations.renderer),...e(t?.previousObservations.renderer),...e(t?.trackLines.renderer),...p(t?.latestObservations.labelingInfo),...p(t?.previousObservations.labelingInfo),...p(t?.trackLines.labelingInfo),...r(t?.popupTemplate))}return"orderBy"in n&&a.push(...o(n.orderBy)),"formTemplate"in n&&a.push(...s(n.formTemplate)),a}export{l as getExpressionsFromLayer};
