import*as Host from"../host/host.js";import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";import{ProfilesPanel}from"./ProfilesPanel.js";import{instance}from"./ProfileTypeRegistry.js";const UIStrings={revealInSummaryView:"Reveal in Summary view"},str_=i18n.i18n.registerUIStrings("profiler/HeapProfilerPanel.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let heapProfilerPanelInstance;export class HeapProfilerPanel extends ProfilesPanel{constructor(){const e=instance;super("heap_profiler",[e.heapSnapshotProfileType,e.trackingHeapSnapshotProfileType,e.samplingHeapProfileType],"profiler.heap-toggle-recording")}static instance(){return heapProfilerPanelInstance||(heapProfilerPanelInstance=new HeapProfilerPanel),heapProfilerPanelInstance}appendApplicableItems(e,t,n){if(!(n instanceof SDK.RemoteObject.RemoteObject))return;if(!this.isShowing())return;const r=n;if(!r.objectId)return;const i=r.objectId;if(!instance.heapSnapshotProfileType.getProfiles().length)return;const o=r.runtimeModel().heapProfilerModel();o&&t.revealSection().appendItem(i18nString(UIStrings.revealInSummaryView),function(e){o.snapshotObjectIdForObjectId(i).then((t=>{this.isShowing()&&t&&this.showObject(t,e)}))}.bind(this,"Summary"))}handleAction(e,t){const n=UI.Context.Context.instance().flavor(HeapProfilerPanel);return console.assert(Boolean(n)&&n instanceof HeapProfilerPanel),n&&n.toggleRecord(),!0}wasShown(){UI.Context.Context.instance().setFlavor(HeapProfilerPanel,this),Host.userMetrics.panelLoaded("heap_profiler","DevTools.Launch.HeapProfiler")}willHide(){UI.Context.Context.instance().setFlavor(HeapProfilerPanel,null)}showObject(e,t){const n=instance.heapSnapshotProfileType.getProfiles();for(let r=0;r<n.length;r++){const i=n[r];if(i.maxJSObjectId>=parseInt(e,10)){this.showProfile(i);this.viewForProfile(i).selectLiveObject(t,e);break}}}}