import*as Common from"../common/common.js";import*as i18n from"../i18n/i18n.js";import*as Root from"../root/root.js";import*as ARIAUtils from"./ARIAUtils.js";import{InspectorView}from"./InspectorView.js";import{Tooltip}from"./Tooltip.js";import{CheckboxLabel}from"./UIUtils.js";const UIStrings={srequiresReload:"{PH1}Requires reload",oneOrMoreSettingsHaveChanged:"One or more settings have changed which requires a reload to take effect."},str_=i18n.i18n.registerUIStrings("ui/SettingsUI.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export const createSettingCheckbox=function(e,t,n,o){const r=CheckboxLabel.create(e);o&&Tooltip.install(r,o);const i=r.checkboxElement;if(i.name=e,bindCheckbox(i,t),n)return r;const s=document.createElement("p");return s.appendChild(r),s};const createSettingSelect=function(e,t,n,o,r){const i=document.createElement("p"),s=i.createChild("label"),c=i.createChild("select","chrome-select");s.textContent=e,r&&(i.classList.add("chrome-select-label"),s.createChild("p").textContent=r),ARIAUtils.bindLabelToControl(s,c);for(const d of t)d.text&&"string"===typeof d.value&&c.add(new Option(d.text,d.value));let l=null;return n&&(l=i.createChild("span","reload-warning hidden"),l.textContent=i18nString(UIStrings.srequiresReload,{PH1:"*"}),ARIAUtils.markAsAlert(l)),o.addChangeListener(a),a(),c.addEventListener("change",(function(){o.set(t[c.selectedIndex].value),l&&(l.classList.remove("hidden"),InspectorView.instance().displayReloadRequiredWarning(i18nString(UIStrings.oneOrMoreSettingsHaveChanged)))}),!1),i;function a(){const e=o.get();for(let n=0;n<t.length;n++)t[n].value===e&&(c.selectedIndex=n)}};export const bindCheckbox=function(e,t){const n=e;function o(){n.checked!==t.get()&&(n.checked=t.get())}t.addChangeListener(o),o(),n.addEventListener("change",(function(){t.get()!==n.checked&&t.set(n.checked)}),!1)};export const createCustomSetting=function(e,t){const n=document.createElement("p"),o=n.createChild("fieldset"),r=o.createChild("label");return r.textContent=e,ARIAUtils.bindLabelToControl(r,t),o.appendChild(t),n};class SettingsRuntimeExtensionDescriptor extends Root.Runtime.RuntimeExtensionDescriptor{constructor(){super(),this.options,this.reloadRequired}}export const createControlForSetting=function(e,t){const n=e.title();switch(e.type()){case"boolean":return createSettingCheckbox(n,e);case"enum":return Array.isArray(e.options())?createSettingSelect(n,e.options(),e.reloadRequired(),e,t):(console.error("Enum setting defined without options"),null);default:return console.error("Invalid setting type: "+e.type()),null}};export class SettingUI{settingElement(){throw new Error("not implemented")}}