import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";const UIStrings={paused:"paused"},str_=i18n.i18n.registerUIStrings("sources/ThreadsSidebarPane.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let threadsSidebarPaneInstance;export class ThreadsSidebarPane extends UI.Widget.VBox{constructor(){super(!0),this.registerRequiredCSS("sources/threadsSidebarPane.css",{enableLegacyPatching:!0}),this._items=new UI.ListModel.ListModel,this._list=new UI.ListControl.ListControl(this._items,this,UI.ListControl.ListMode.NonViewport);const e=UI.Context.Context.instance().flavor(SDK.SDKModel.Target);this._selectedModel=null!==e?e.model(SDK.DebuggerModel.DebuggerModel):null,this.contentElement.appendChild(this._list.element),UI.Context.Context.instance().addFlavorChangeListener(SDK.SDKModel.Target,this._targetFlavorChanged,this),SDK.SDKModel.TargetManager.instance().observeModels(SDK.DebuggerModel.DebuggerModel,this)}static instance(){return threadsSidebarPaneInstance||(threadsSidebarPaneInstance=new ThreadsSidebarPane),threadsSidebarPaneInstance}static shouldBeShown(){return SDK.SDKModel.TargetManager.instance().models(SDK.DebuggerModel.DebuggerModel).length>=2}createElementForItem(e){const t=document.createElement("div");t.classList.add("thread-item");const s=t.createChild("div","thread-item-title"),n=t.createChild("div","thread-item-paused-state");t.appendChild(UI.Icon.Icon.create("smallicon-thick-right-arrow","selected-thread-icon")),t.tabIndex=-1,self.onInvokeElement(t,(t=>{UI.Context.Context.instance().setFlavor(SDK.SDKModel.Target,e.target()),t.consume(!0)}));const i=UI.Context.Context.instance().flavor(SDK.SDKModel.Target)===e.target();function a(){const t=e.runtimeModel().defaultExecutionContext();s.textContent=t&&t.label()?t.label():e.target().name()}function r(){n.textContent=e.isPaused()?i18nString(UIStrings.paused):""}return t.classList.toggle("selected",i),UI.ARIAUtils.setSelected(t,i),e.addEventListener(SDK.DebuggerModel.Events.DebuggerPaused,r),e.addEventListener(SDK.DebuggerModel.Events.DebuggerResumed,r),e.runtimeModel().addEventListener(SDK.RuntimeModel.Events.ExecutionContextChanged,a),SDK.SDKModel.TargetManager.instance().addEventListener(SDK.SDKModel.Events.NameChanged,(function(t){t.data===e.target()&&a()})),r(),a(),t}heightForItem(e){return console.assert(!1),0}isItemSelectable(e){return!0}selectedItemChanged(e,t,s,n){s&&(s.tabIndex=-1);const i=n;i&&(this.setDefaultFocusedElement(i),i.tabIndex=0,this.hasFocus()&&i.focus())}updateSelectedItemARIA(e,t){return!1}modelAdded(e){this._items.insert(this._items.length,e);UI.Context.Context.instance().flavor(SDK.SDKModel.Target)===e.target()&&this._list.selectItem(e)}modelRemoved(e){this._items.remove(this._items.indexOf(e))}_targetFlavorChanged(e){const t=this.hasFocus(),s=e.data.model(SDK.DebuggerModel.DebuggerModel);this._list.selectItem(s),s&&this._list.refreshItem(s),null!==this._selectedModel&&this._list.refreshItem(this._selectedModel),this._selectedModel=s,t&&this.focus()}}