/*! 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.87 */
import a from"./PWAA4CRD.js";import{b as f,c,d as p}from"./VXGTTGEB.js";import{f as h,g as x}from"./BDRKA3H4.js";import{L as u}from"./VLOVVVTE.js";export default $arcgis.t(([{getDeclaredPixelMembers:C},{b:v,c:g,d:T,e:M,f:F,g:m,h:P,i:k,j:A,k:I}])=>{async function S(e){let{apiVersion:r,bundles:t,hiddenApiItems:a}=e.toEditorProfileDefinition(),i=await V(e.dictionaryVariables);return{apiVersion:r,bundles:t,variables:i,hiddenApiItems:a?.map(n=>n.toLowerCase())}}async function V(e,r=f.Variable){return await Promise.all(e.map(async t=>{switch(t.type){case"dictionary":return await _(t,r);case"pixel":return await K(t,r);case"voxel":case"feature":return await j(t,r);default:return $(t,r)}}))}function $(e,r){let{name:t,type:a}=e,i=e.getDescription();return{name:t,description:i,type:a,completion:{label:t,detail:t,insertText:t,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:r,documentation:{kind:"markdown",value:i}}}}async function j(e,r){let t=await e.loadSource(),{name:a}=e,i=e.getDescription(),n={label:a,detail:a,insertText:a,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:r},s={name:a,description:i,type:"dictionary",properties:[],completion:n};if(!t)return s;let[o,l]=P(t.fields,i,!0);return s.properties=o,n.documentation={kind:"markdown",value:l},s}async function K(e,r){let t=await e.loadSource(),a=e.toProfileVariableDefinition();if(a.type!=="pixel")throw new Error("Incorrect definition passed to pixel variable");let{name:i}=e,n=e.getDescription(),s={label:i,detail:i,insertText:i,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:r},o={name:i,description:n,type:"dictionary",properties:[],completion:s};if(!t||!a.definition)return o;let l=await C(t),[E,L]=k(l,n);return o.properties=E,s.documentation={kind:"markdown",value:L},o}async function _(e,r){let{name:t,dictionaryVariables:a}=e,i=e.getDescription(),n=a.reduce((s,o)=>{s!==""&&(s+=`  
  
`),s+=`**${o.name}**  
${o.type}`;let l=o.getDescription();return l&&(s+=`  
${l}`),s},i);return{name:t,description:i,type:"dictionary",properties:await V(a,f.Field),completion:{label:t,detail:t,insertText:t,insertTextMode:p.asIs,insertTextFormat:c.PlainText,kind:r,documentation:{kind:"markdown",value:n}}}}async function y(e="en"){let r=D.get(e);if(r)return r;if(!h.has(e))return await y("en");try{let t=await fetch(u(`./assets/arcade-language/profiles/arcade-profiles.t9n.${e}.json`));return t.ok?B(e,await t.json()):e==="en"?null:await y("en")}catch{return null}}var D=new Map;function B(e,r){let t=new Map;return r.forEach(a=>{t.set(a.id,a)}),D.set(e,t),t}async function q(e,r="en"){return(await y(r))?.get(e)??null}function z(e){return!!e&&typeof e=="object"&&"additionalVariables"in e&&Array.isArray(e.additionalVariables)}function G(e){return e?.map(b)}function b(e){switch(e.type){case"dictionary":return{...e,type:e.type,properties:G(e.properties)};case"array":return{...e,type:e.type,elementType:{type:"number",name:"number"}};default:return{...e,type:e.type}}}async function H(e,r="en"){if(!m(e))return;let t=await q(e.id,r);if(!t)return;let a={bundles:[...t.bundles],variables:[],hiddenApiItems:e.hiddenApiItems?.map(i=>i.toLowerCase())};return t.variables.forEach(i=>{if(e.disabledVariables?.includes(i.name))return;let n=e.definitions[i.name];switch(i.type){case"dictionary":return a.variables.push(b({...i,type:i.type,properties:Array.isArray(n)?[...n]:i.properties}));case"feature":return v(n)?a.variables.push({...i,type:"feature",definition:n}):void 0;case"pixel":return T(n)?a.variables.push({...i,type:i.type,definition:n}):void 0;case"voxel":return g(n)?a.variables.push({...i,type:i.type,definition:n}):void 0;case"featureSet":return M(n)?a.variables.push({...i,type:i.type,definition:n}):void 0;case"featureSetCollection":return F(n)?a.variables.push({...i,type:i.type,definition:n}):void 0;default:return a.variables.push(b(i))}}),z(e)&&a.variables.push(...e.additionalVariables??[]),a}var w=class extends I{constructor(){super("arcade",{apiPath:"./assets/arcade-language/api",apiPrefix:"arcade-api.t9n."})}async setProfileForModel(r,t,a={locale:"en"}){m(t)&&(t=await H(t,a.locale));let i=await x(a.locale,u("./assets/editor-profile/t9n"),"messages.");if(!i)throw new Error(`Failed to load the language bundle for ${a.locale}`);this.disposeForModel(r);let n=this._getApiKey(r),s=new A(t,i);this._modelToProfileMap.set(n,s);let o=await S(s);this.updateApiContextForModel(r,{locale:a.locale,profile:o,snippets:a.snippets})}},d=new w,U={setProfileForModel:d.setProfileForModel.bind(d),getApiLibraryForModel:d.getApiLibraryForModel.bind(d)};return d},"applications/Components/arcadeEditorUtils",a)