import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";import{ExtensionNotifierView,ExtensionView}from"./ExtensionView.js";export class ExtensionPanel extends UI.Panel.Panel{constructor(e,t,i,s){super(t),this._server=e,this._id=i,this.setHideOnDetach(),this._panelToolbar=new UI.Toolbar.Toolbar("hidden",this.element),this._searchableView=new UI.SearchableView.SearchableView(this,null),this._searchableView.show(this.element);new ExtensionView(e,this._id,s,"extension").show(this._searchableView.element)}addToolbarItem(e){this._panelToolbar.element.classList.remove("hidden"),this._panelToolbar.appendToolbarItem(e)}searchCanceled(){this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.CancelSearch),this._searchableView.updateSearchMatchesCount(0)}searchableView(){return this._searchableView}performSearch(e,t,i){const s=e.query;this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.PerformSearch,s)}jumpToNextSearchResult(){this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.NextSearchResult)}jumpToPreviousSearchResult(){this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.PreviousSearchResult)}supportsCaseSensitiveSearch(){return!1}supportsRegexSearch(){return!1}}export class ExtensionButton{constructor(e,t,i,s,o){this._id=t,this._toolbarButton=new UI.Toolbar.ToolbarButton("",""),this._toolbarButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click,e.notifyButtonClicked.bind(e,this._id)),this.update(i,s,o)}update(e,t,i){"string"===typeof e&&this._toolbarButton.setBackgroundImage(e),"string"===typeof t&&this._toolbarButton.setTitle(t),"boolean"===typeof i&&this._toolbarButton.setEnabled(!i)}toolbarButton(){return this._toolbarButton}}export class ExtensionSidebarPane extends UI.View.SimpleView{constructor(e,t,i,s){super(i),this.element.classList.add("fill"),this._panelName=t,this._server=e,this._id=s}id(){return this._id}panelName(){return this._panelName}setObject(e,t,i){this._createObjectPropertiesView(),this._setObject(SDK.RemoteObject.RemoteObject.fromLocalObject(e),t,i)}setExpression(e,t,i,s,o){this._createObjectPropertiesView(),this._server.evaluate(e,!0,!1,i,s,this._onEvaluate.bind(this,t,o))}setPage(e){this._objectPropertiesView&&(this._objectPropertiesView.detach(),delete this._objectPropertiesView),this._extensionView&&this._extensionView.detach(!0),this._extensionView=new ExtensionView(this._server,this._id,e,"extension fill"),this._extensionView.show(this.element),this.element.style.height||this.setHeight("150px")}setHeight(e){this.element.style.height=e}_onEvaluate(e,t,i,s,o){i?t(i.toString()):s?this._setObject(s,e,t):t()}_createObjectPropertiesView(){this._objectPropertiesView||(this._extensionView&&(this._extensionView.detach(!0),delete this._extensionView),this._objectPropertiesView=new ExtensionNotifierView(this._server,this._id),this._objectPropertiesView.show(this.element))}_setObject(e,t,i){const s=this._objectPropertiesView;s?(s.element.removeChildren(),UI.UIUtils.Renderer.render(e,{title:t,editable:!1}).then((e=>{if(!e)return void i();const t=e.tree&&e.tree.firstChild();t&&t.expand(),s.element.appendChild(e.node),i()}))):i("operation cancelled")}}