import{V as t}from"./p-46048b08.js";import{V as s,b as e}from"./p-b6152e4f.js";import"./p-dcc98162.js";class i extends s{constructor(t,s,e){super(),this.languageList=[],this.selectedLanguage="Select Language",this.labelRef=null,this.handleDropdownClick=t=>{this.setSelectedLanguage(t),"function"==typeof this.languageChangeCallback&&this.languageChangeCallback(this.selectedLanguage)},this.languageList=t,this.selectedLanguage=e,this.languageChangeCallback=s}setSelectedLanguage(t){this.selectedLanguage=t,this.labelRef&&(this.labelRef.textContent=this.getLanguageLabelByKey(t))}isHidden(){return!1}render(t,s){return this.renderDropdown(t,s,{source:this.languageList},[this.renderButton(t,s,{label:this.getLanguageLabelByKey(this.selectedLanguage),showArrowIcon:!0})])}renderButtonLabel(t,s,e){return t("vega-font",{variant:"font-field-label-sm",color:this.isDisabled(s)?"text-disabled":"text-primary",ref:t=>this.labelRef=t},e)}handleButtonClick(t){}getLanguageLabelByKey(t){return this.getListItemByKey(this.languageList,t).label}}class h extends e{constructor(t,s){super(),this.languageState={selectedLanguage:"",contentMap:{}},this.languageChangeCallBack=t=>{const s=this.languageState.selectedLanguage;this.extensionContext&&s&&(this.languageState.contentMap[s]=this.getRTELatestValue(this.extensionContext.host)),this.languageState.selectedLanguage=t,this.applyLanguageContent(t,this.languageState.contentMap)},s&&(this.languageState=Object.assign(Object.assign({},this.languageState),s)),!this.languageState.selectedLanguage&&t.length>0&&(this.languageState.selectedLanguage=t[0].key),this.languageToolbarButtonRenderer=new i(t,this.languageChangeCallBack,this.languageState.selectedLanguage),this.registerToolbarButtonRenderer("languages",this.languageToolbarButtonRenderer)}initialExtension(t){super.initialExtension(t);const{selectedLanguage:s,contentMap:e}=this.languageState;e&&e[s]&&this.applyLanguageContent(this.languageState.selectedLanguage,this.languageState.contentMap)}setState(t){const{selectedLanguage:s,contentMap:e}=t;this.languageToolbarButtonRenderer.setSelectedLanguage(s),this.languageState.selectedLanguage=s,this.languageState.contentMap=Object.assign({},e),this.applyLanguageContent(s,e)}getState(){const{selectedLanguage:t,contentMap:s}=this.languageState;return this.extensionContext&&(s[t]=this.getRTELatestValue(this.extensionContext.host)),this.languageState}applyLanguageContent(s,e){if(this.extensionContext&&e){let i=e[s];const{host:h,flushValue:n}=this.extensionContext;i=i?i instanceof t?i:t.fromJSON(i,h.sourceEditConfig):t.createEmptyContent(),h.value!==i&&n(i,!0)}}getRTELatestValue(s){var e;let i=s.value;if(this.extensionContext&&this.extensionContext.isSourceEditMode()&&s.shadowRoot){const h=s.shadowRoot.querySelector(".source-view-container vega-code-block");if(h){let n;s.sourceEditConfig&&(n={autoMatchFormat:null===(e=s.sourceEditConfig.autoMatchFormat)||void 0===e||e,filterInlineStyles:s.sourceEditConfig.filterInlineStyles}),i=t.fromHtml(h.value.code,n)}}return i}}const n=Object.freeze({__proto__:null,VegaRTELanguageExtension:h});export{i as R,h as V,n as l}