/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
v5.0.0-next.125 */
import a from"./QL2L2MHZ.js";import{b as m,c,d as p}from"./S3EFBHYY.js";import{f as x,g as v}from"./4DFWA57L.js";import{K as y}from"./AYUGR6ZA.js";export default $arcgis.t(([{getDeclaredPixelMembers:E},{b:T,c:M,d:F,e:P,f:k,g:b,h:A,i:I,j:V,k:D}])=>{async function S(e){let{apiVersion:n,bundles:i,hiddenApiItems:a}=e.toEditorProfileDefinition(),t=await L(e.dictionaryVariables);return{apiVersion:n,bundles:i,variables:t,hiddenApiItems:a?.map(r=>r.toLowerCase())}}async function L(e,n=m.Variable){return await Promise.all(e.map(async i=>{switch(i.type){case"dictionary":return await B(i,n);case"pixel":return await _(i,n);case"voxel":case"feature":return await K(i,n);default:return $(i,n)}}))}function $(e,n){let{name:i,type:a}=e,t=e.getDescription();return{name:i,description:t,type:a,completion:{label:i,detail:i,insertText:i,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:n,documentation:{kind:"markdown",value:t}}}}async function K(e,n){let i=await e.loadSource(),{name:a}=e,t=e.getDescription(),r={label:a,detail:a,insertText:a,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:n},s={name:a,description:t,type:"dictionary",properties:[],completion:r};if(!i)return s;let[o,l]=A(i.fields,t,!0);return s.properties=o,r.documentation={kind:"markdown",value:l},s}async function _(e,n){let i=await e.loadSource(),a=e.toProfileVariableDefinition();if(a.type!=="pixel")throw new Error("Incorrect definition passed to pixel variable");let{name:t}=e,r=e.getDescription(),s={label:t,detail:t,insertText:t,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:n},o={name:t,description:r,type:"dictionary",properties:[],completion:s};if(!i||!a.definition)return o;let l=await E(i),[d,u]=I(l,r);return o.properties=d,s.documentation={kind:"markdown",value:u},o}async function B(e,n){let{name:i,dictionaryVariables:a}=e,t=e.getDescription(),r=a.reduce((s,o)=>{s!==""&&(s+=`  
  
`),s+=`**${o.name}**  
${o.type}`;let l=o.getDescription();return l&&(s+=`  
${l}`),s},t);return{name:i,description:t,type:"dictionary",properties:await L(a,m.Field),completion:{label:i,detail:i,insertText:i,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:n,documentation:{kind:"markdown",value:r}}}}async function w(e="en"){let n=C.get(e);if(n)return n;if(!x.has(e))return await w("en");try{let i=await fetch(y(`./assets/arcade-language/profiles/arcade-profiles.t9n.${e}.json`));return i.ok?q(e,await i.json()):e==="en"?null:await w("en")}catch{return null}}var C=new Map;function q(e,n){let i=new Map;return n.forEach(a=>{i.set(a.id,a)}),C.set(e,i),i}async function z(e,n="en"){return(await w(n))?.get(e)??null}function G(e){return!!e&&typeof e=="object"&&"additionalVariables"in e&&Array.isArray(e.additionalVariables)}function H(e){return e?.map(h)}function h(e){switch(e.type){case"dictionary":return{...e,type:e.type,properties:H(e.properties)};case"array":return{...e,type:e.type,elementType:{type:"number",name:"number"}};default:return{...e,type:e.type}}}async function J(e,n="en"){if(!b(e))return;let i=await z(e.id,n);if(!i)return;let a={bundles:[...i.bundles],variables:[],hiddenApiItems:e.hiddenApiItems?.map(t=>t.toLowerCase())};return i.variables.forEach(t=>{if(e.disabledVariables?.includes(t.name))return;let r=e.definitions[t.name];switch(t.type){case"dictionary":return a.variables.push(h({...t,type:t.type,properties:Array.isArray(r)?[...r]:t.properties}));case"feature":return T(r)?a.variables.push({...t,type:"feature",definition:r}):void 0;case"pixel":return F(r)?a.variables.push({...t,type:t.type,definition:r}):void 0;case"voxel":return M(r)?a.variables.push({...t,type:t.type,definition:r}):void 0;case"featureSet":return P(r)?a.variables.push({...t,type:t.type,definition:r}):void 0;case"featureSetCollection":return k(r)?a.variables.push({...t,type:t.type,definition:r}):void 0;default:return a.variables.push(h(t))}}),G(e)&&a.variables.push(...e.additionalVariables??[]),a}var N=["catalog-footprint","catalog","csv","feature","geojson","knowledge-graph-sublayer","oriented-imagery","subtype-group","subtype-sublayer","wfs"];function O(e){return!!e&&typeof e=="object"&&"type"in e&&typeof e.type=="string"&&N.includes(e.type)}var Q={filterFsCollectionLayersFromMap:e=>O(e)},g=class extends D{#e=new Map;constructor(){super("arcade",{apiPath:"./assets/arcade-language/api",apiPrefix:"arcade-api.t9n."})}async setProfileForModel(n,i,a={locale:"en"}){let t=this._getApiKey(n),r=(this.#e.get(t)||Promise.resolve()).then(async()=>{let o=i,l=b(o)?await J(o,a.locale):o,d=await v(a.locale,y("./assets/editor-profile/t9n"),"messages.");if(!d)throw new Error(`Failed to load the language bundle for ${a.locale}`);this.disposeForModel(n);let u=new V(l,d,a.locale,Q);this._modelToProfileMap.set(t,u);let j=await S(u);this.updateApiContextForModel(n,{locale:a.locale,profile:j,snippets:a.snippets})}),s=r.finally(()=>{this.#e.get(t)===s&&this.#e.delete(t)});return this.#e.set(t,s),await r}},f=new g,R={setProfileForModel:f.setProfileForModel.bind(f),getApiLibraryForModel:f.getApiLibraryForModel.bind(f)};return f},"applications/Components/arcadeEditorUtils",a)