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