/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{b as E}from"./CZ2DJPO4.js";import f from"./GXD4RF74.js";import{a as m}from"./B7THOFPO.js";import"./3RDQGPHK.js";import e from"./EEUNU5QU.js";import b from"./ZHZFKZA7.js";import"./MP6Z45SA.js";import"./IFNCCZ7O.js";import"./OZ65S2RS.js";import"./NKCYMRE4.js";import"./BQLG62QR.js";import"./UE4FNMRR.js";import"./UYBZWFE5.js";import{D as n,E as c,F as h,G as p,J as g,h as d,j as s,n as a,s as l}from"./4BNI5KJQ.js";import{b as t}from"./BCUUVBXH.js";import"./YLN7EMJC.js";import"./GHSEU7VA.js";import"./4OSKRQ5X.js";import"./NG7S6FUK.js";import"./3TTFCHAA.js";export default $arcgis.t(([,,,,,,,{E:_},{c:o},{a:b,b:u,c:f,d:v}])=>{var S=d`:host{height:100%}calcite-tooltip:not([calcite-hydrated])>*{display:none}`,r=class extends h{constructor(){super(...arguments),this._codeEditorElt=n(),this._disposables=[],this._modelId=l(),this.messages=m(),this._preparing=!1,this._resolvedLanguage=o,this.sideActionBarExpanded=!1,this.script="",this.hideSideBar=!1,this.openedSidePanel="none",this.arcgisDiagnosticsChange=a({bubbles:!1}),this.arcgisScriptChange=a({bubbles:!1})}static{this.properties={_editorProfile:16,_preparing:16,_resolvedLanguage:16,sideActionBarExpanded:16,profile:0,script:1,hideSideBar:5,messageOverrides:0,openedSidePanel:3}}static{this.styles=[S]}async setFocus(){await this._codeEditorElt.value?.setFocus()}async load(){await this._updateDataModelDeps().catch(t(this))}willUpdate(e){e.has("profile")&&this._updateDataModelDeps().catch(t(this))}async loaded(){let e=E();this._disposables.push(e.onDiagnosticsChange(i=>{i.uri.toString()===this._modelId&&!this._preparing&&this.arcgisDiagnosticsChange.emit(i.diagnostics)}))}disconnectedCallback(){for(super.disconnectedCallback();this._disposables.length;)this._disposables.pop()?.dispose();v().forEach(e=>e.disposeForModel(this._modelId))}async _updateDataModelDeps(){this._preparing=!0;try{let e=await b(this.profile);e!==this._resolvedLanguage&&(f(this._resolvedLanguage)?.disposeForModel(this._modelId),this._resolvedLanguage=e);let i=u(this._resolvedLanguage);await i.setProfileForModel(this._modelId,this.profile,{locale:this.messages._t9nLocale}),this._editorProfile=i.getEditorProfileForModel(this._modelId)}catch{this._editorProfile=void 0,this._resolvedLanguage=o}finally{this._preparing=!1}}_toggleSideActionBarExpanded(){this.sideActionBarExpanded=!this.sideActionBarExpanded}_toggleSidePanel(e){this.openedSidePanel=this.openedSidePanel===e?"none":e,this.openedSidePanel==="none"&&this._codeEditorElt.value?.setFocus().catch(t(this))}_onCodeEditorValueChange(e){e.stopPropagation(),this.script=e.detail,this.arcgisScriptChange.emit(e.detail)}_insertAsText(e){this._codeEditorElt.value?.insertText(e.detail).catch(t(this))}_getTablesVariable(){return this._editorProfile?.variables.find(_)}render(){let e=this._getTablesVariable();return s`<arcgis-code-editor-shell><arcgis-code-editor slot=editor .language=${this._resolvedLanguage} .modelId=${this._modelId} .value=${this.script??""} @arcgisValueChange=${this._onCodeEditorValueChange} ${c(this._codeEditorElt)}></arcgis-code-editor>${!this.hideSideBar&&s`<arcgis-editor-variables slot=side-panel .variable=${e} .heading=${this.messages.tables??"Tables"} .messageOverrides=${{profileempty:this.messages.profileempty}} .closed=${this.openedSidePanel!=="variables"} class=${p(this.openedSidePanel==="variables"?"":"hidden")} .loading=${this._preparing} .modelId=${this._modelId} @arcgisInternalItemSelected=${this._insertAsText} @arcgisInternalClosePanel=${()=>{this.openedSidePanel="none"}} data-panel-name=none></arcgis-editor-variables><calcite-action-bar slot=side-action-bar .expanded=${this.sideActionBarExpanded} position=end @calciteActionBarToggle=${this._toggleSideActionBarExpanded}><calcite-action id=tables-action .text=${this.messages.tables??"Tables"} icon=table .active=${this.openedSidePanel==="variables"} data-panel-name=variables @click=${()=>this._toggleSidePanel("variables")}></calcite-action>${!this.sideActionBarExpanded&&s`<calcite-tooltip reference-element=tables-action><span>${this.messages.tables??"Tables"}</span></calcite-tooltip>`||""}</calcite-action-bar>`||""}</arcgis-code-editor-shell>`}};g("arcgis-sql-layer-editor",r);return r},"portal/PortalItem","WebMap","WebScene","layers/FeatureLayer","applications/Components/arcadeEditorUtils","core/Error","portal/Portal",b,e,f)