import*as Common from"../common/common.js";import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";import{DeveloperResourcesListView}from"./DeveloperResourcesListView.js";const UIStrings={enterTextToSearchTheUrlAndError:"Enter text to search the URL and Error columns",loadHttpsDeveloperResources:"Load `HTTP(S)` developer resources through the inspected target",enableLoadingThroughTarget:"Enable loading through target",resourcesCurrentlyLoading:"{PH1} resources, {PH2} currently loading",resources:"{PH1} resources"},str_=i18n.i18n.registerUIStrings("developer_resources/DeveloperResourcesView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let developerResourcesViewInstance;export class DeveloperResourcesView extends UI.Widget.VBox{constructor(){super(!0),this.registerRequiredCSS("developer_resources/developerResourcesView.css",{enableLegacyPatching:!0});const e=this.contentElement.createChild("div","developer-resource-view-toolbar-container"),t=new UI.Toolbar.Toolbar("developer-resource-view-toolbar",e);this._textFilterRegExp=null;this._filterInput=new UI.Toolbar.ToolbarInput(i18nString(UIStrings.enterTextToSearchTheUrlAndError),"",1),this._filterInput.addEventListener(UI.Toolbar.ToolbarInput.Event.TextChanged,this._onFilterChanged,this),t.appendToolbarItem(this._filterInput);const r=SDK.PageResourceLoader.getLoadThroughTargetSetting(),s=new UI.Toolbar.ToolbarSettingCheckbox(r,i18nString(UIStrings.loadHttpsDeveloperResources),i18nString(UIStrings.enableLoadingThroughTarget));t.appendToolbarItem(s),this._coverageResultsElement=this.contentElement.createChild("div","developer-resource-view-results"),this._listView=new DeveloperResourcesListView(this._isVisible.bind(this)),this._listView.show(this._coverageResultsElement),this._statusToolbarElement=this.contentElement.createChild("div","developer-resource-view-toolbar-summary"),this._statusMessageElement=this._statusToolbarElement.createChild("div","developer-resource-view-message"),this._throttler=new Common.Throttler.Throttler(100),this._loader=SDK.PageResourceLoader.PageResourceLoader.instance(),this._loader.addEventListener(SDK.PageResourceLoader.Events.Update,this._onUpdate,this),this._onUpdate()}static instance(){return developerResourcesViewInstance||(developerResourcesViewInstance=new DeveloperResourcesView),developerResourcesViewInstance}_onUpdate(){this._throttler.schedule(this._update.bind(this))}async _update(){this._listView.reset(),this._listView.update(this._loader.getResourcesLoaded().values()),this._updateStats()}_updateStats(){const{loading:e,resources:t}=this._loader.getNumberOfResources();this._statusMessageElement.textContent=e>0?i18nString(UIStrings.resourcesCurrentlyLoading,{PH1:t,PH2:e}):i18nString(UIStrings.resources,{PH1:t})}_isVisible(e){return!this._textFilterRegExp||this._textFilterRegExp.test(e.url)||this._textFilterRegExp.test(e.errorMessage||"")}_onFilterChanged(){if(!this._listView)return;const e=this._filterInput.value();this._textFilterRegExp=e?createPlainTextSearchRegex(e,"i"):null,this._listView.updateFilterAndHighlight(this._textFilterRegExp),this._updateStats()}}