import{html as e,css as t,LitElement as i}from"../../../lit/index.js";import{HaxSchematizer as s,HaxElementizer as a}from"../../hax-body-behaviors/lib/HAXFields.js";import"../../simple-icon/lib/simple-icon-lite.js";import"../../hax-iconset/lib/simple-hax-iconset.js";import"../../simple-icon/lib/simple-icon-button.js";import"../../simple-fields/simple-fields.js";import{HAXStore as o}from"./hax-store.js";import{autorun as n,toJS as r}from"../../../mobx/dist/mobx.esm.js";import{I18NMixin as l,I18NManagerStore as h}from"../../i18n-manager/lib/I18NMixin.js";class HaxPreferencesDialog extends(l(i)){static get styles(){return[t`
        :host {
          display: block;
        }
        .pref-container {
          text-align: left;
        }
        simple-icon-lite {
          --simple-icon-height: 36px;
          --simple-icon-width: 36px;
        }
      `]}constructor(){super(),this.hideLink=!1,this.t={learnAboutHAXTheWeb:"Learn about HAXTheWeb",haxUITheme:"HAX UI Theme",language:"Language",english:"English",spanish:"Spanish"},this.udpateSchema(),this.registerLocalization({context:this,namespace:"hax",updateCallback:"udpateSchema"}),n((()=>{this.globalPreferences=r(o.globalPreferences),this.globalPreferences.haxLang&&h.lang!=this.globalPreferences.haxLang&&(h.lang=this.globalPreferences.haxLang||"en",this.udpateSchema())}))}udpateSchema(){let e=h.lang;e.indexOf("-")&&(e=e.split("-")[0]),this.schema=[{property:"haxUiTheme",title:this.t.haxUITheme,description:"Change the theme of the HAX interface (not the site's content).",inputMethod:"radio",options:{hax:"Default (light)",haxdark:"Dark",system:"System Default"},value:"hax"},{property:"haxLang",title:this.t.language,description:"Toggle between supported languages for internationalization",inputMethod:"radio",options:{en:this.t.english,es:this.t.spanish},value:e}],this.schemaValues={haxUiTheme:"hax",haxLang:e},this.shadowRoot&&this.shadowRoot.querySelector("#settingsform")&&this.reloadPreferencesForm()}closeBtn(e){this.dispatchEvent(new CustomEvent("hax-tray-button-click",{bubbles:!0,cancelable:!0,composed:!0,detail:{eventName:"open-preferences",index:0,value:!0}}))}render(){return e`
      <div style="height: 100%; overflow: auto;" class="pref-container">
        <simple-fields
          id="settingsform"
          .schematizer="${s}"
          .elementizer="${a}"
        >
        </simple-fields>
      </div>
    `}static get tag(){return"hax-preferences-dialog"}static get properties(){return{hideLink:{type:Boolean},schema:{type:Object},globalPreferences:{type:Object}}}firstUpdated(e){this.reloadPreferencesForm(),this.shadowRoot.querySelector("#settingsform").addEventListener("value-changed",this.__valueChangedEvent.bind(this))}__valueChangedEvent(e){e.detail.value&&(o.globalPreferences={...e.detail.value},this.schemaValues={...e.detail.value})}reloadPreferencesForm(){this.shadowRoot.querySelector("#settingsform").fields=[...this.schema],this.shadowRoot.querySelector("#settingsform").value={...this.schemaValues}}}customElements.define(HaxPreferencesDialog.tag,HaxPreferencesDialog);export{HaxPreferencesDialog};