export class InspectorMainImpl extends Common.Object{async run(){let firstCall=true;await SDK.initMainConnection(async()=>{const type=Root.Runtime.queryParam('v8only')?SDK.Target.Type.Node:SDK.Target.Type.Frame;const waitForDebuggerInPage=type===SDK.Target.Type.Frame&&Root.Runtime.queryParam('panel')==='sources';const target=SDK.targetManager.createTarget('main',Common.UIString('Main'),type,null,undefined,waitForDebuggerInPage);if(!firstCall){return;}
firstCall=false;if(waitForDebuggerInPage){const debuggerModel=target.model(SDK.DebuggerModel);if(!debuggerModel.isReadyToPause()){await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause);}
debuggerModel.pause();}
target.runtimeAgent().runIfWaitingForDebugger();},Components.TargetDetachedDialog.webSocketConnectionLost);new SourcesPanelIndicator();new InspectorMain.BackendSettingsSync();new MobileThrottling.NetworkPanelIndicator();Host.InspectorFrontendHost.events.addEventListener(Host.InspectorFrontendHostAPI.Events.ReloadInspectedPage,event=>{const hard=(event.data);SDK.ResourceTreeModel.reloadAllPages(hard);});}}
export class ReloadActionDelegate{handleAction(context,actionId){switch(actionId){case'inspector_main.reload':SDK.ResourceTreeModel.reloadAllPages(false);return true;case'inspector_main.hard-reload':SDK.ResourceTreeModel.reloadAllPages(true);return true;}
return false;}}
export class FocusDebuggeeActionDelegate{handleAction(context,actionId){SDK.targetManager.mainTarget().pageAgent().bringToFront();return true;}}
export class NodeIndicator{constructor(){const element=createElement('div');const shadowRoot=UI.createShadowRootWithCoreStyles(element,'inspector_main/nodeIcon.css');this._element=shadowRoot.createChild('div','node-icon');element.addEventListener('click',()=>Host.InspectorFrontendHost.openNodeFrontend(),false);this._button=new UI.ToolbarItem(element);this._button.setTitle(Common.UIString('Open dedicated DevTools for Node.js'));SDK.targetManager.addEventListener(SDK.TargetManager.Events.AvailableTargetsChanged,event=>this._update((event.data)));this._button.setVisible(false);this._update([]);}
_update(targetInfos){const hasNode=!!targetInfos.find(target=>target.type==='node'&&!target.attached);this._element.classList.toggle('inactive',!hasNode);if(hasNode){this._button.setVisible(true);}}
item(){return this._button;}}
export class SourcesPanelIndicator{constructor(){Common.moduleSetting('javaScriptDisabled').addChangeListener(javaScriptDisabledChanged);javaScriptDisabledChanged();function javaScriptDisabledChanged(){let icon=null;const javaScriptDisabled=Common.moduleSetting('javaScriptDisabled').get();if(javaScriptDisabled){icon=UI.Icon.create('smallicon-warning');icon.title=Common.UIString('JavaScript is disabled');}
UI.inspectorView.setPanelIcon('sources',icon);}}}
export class BackendSettingsSync{constructor(){this._autoAttachSetting=Common.settings.moduleSetting('autoAttachToCreatedPages');this._autoAttachSetting.addChangeListener(this._updateAutoAttach,this);this._updateAutoAttach();this._adBlockEnabledSetting=Common.settings.moduleSetting('network.adBlockingEnabled');this._adBlockEnabledSetting.addChangeListener(this._update,this);this._emulatePageFocusSetting=Common.settings.moduleSetting('emulatePageFocus');this._emulatePageFocusSetting.addChangeListener(this._update,this);SDK.targetManager.observeTargets(this);}
_updateTarget(target){if(target.type()!==SDK.Target.Type.Frame||target.parentTarget()){return;}
target.pageAgent().setAdBlockingEnabled(this._adBlockEnabledSetting.get());target.emulationAgent().setFocusEmulationEnabled(this._emulatePageFocusSetting.get());}
_updateAutoAttach(){Host.InspectorFrontendHost.setOpenNewWindowForPopups(this._autoAttachSetting.get());}
_update(){for(const target of SDK.targetManager.targets()){this._updateTarget(target);}}
targetAdded(target){this._updateTarget(target);}
targetRemoved(target){}}
SDK.ChildTargetManager.install();self.InspectorMain=self.InspectorMain||{};InspectorMain=InspectorMain||{};InspectorMain.InspectorMain=InspectorMainImpl;InspectorMain.ReloadActionDelegate=ReloadActionDelegate;InspectorMain.FocusDebuggeeActionDelegate=FocusDebuggeeActionDelegate;InspectorMain.NodeIndicator=NodeIndicator;InspectorMain.SourcesPanelIndicator=SourcesPanelIndicator;InspectorMain.BackendSettingsSync=BackendSettingsSync;