import{IssuesManager as s}from"../browser_sdk/browser_sdk.js";import{Console as e,Throttler as t}from"../common/common.js";import{userMetrics as o,UserMetrics as n}from"../host/host.js";import{i18n as i}from"../i18n/i18n.js";import{Runtime as r}from"../root/root.js";import{ConsoleModel as a}from"../sdk/sdk.js";import{CounterButton as l}from"../ui/components/components.js";import{Toolbar as u,ViewManager as c,Tooltip as d,ARIAUtils as h,InspectorView as _}from"../ui/ui.js";const C={sError:"{PH1} error",sErrors:"{PH1} errors",sWarning:"{PH1} warning",sWarnings:"{PH1} warnings",openConsoleToViewS:"Open Console to view {PH1}",sViolation:"{PH1} violation",sViolations:"{PH1} violations",openLighthouseToViewS:"Open Lighthouse to view {PH1}",sIssue:"{PH1} issue",sIssues:"{PH1} issues",openIssuesToViewS:"Open Issues to view {PH1}"},p=i.registerUIStrings("console_counters/WarningErrorCounter.js",C),m=i.getLocalizedString.bind(void 0,p);class g{constructor(){g._instanceForTest=this;const i=document.createElement("div");this._toolbarItem=new u.ToolbarItem(i),this._toolbarItem.setVisible(!1),this._consoleCounter=new l.CounterButton,i.appendChild(this._consoleCounter),this._consoleCounter.data={clickHandler:e.Console.instance().show.bind(e.Console.instance()),counters:[{iconName:"error_icon"},{iconName:"warning_icon"}]},this._violationCounter=null,r.experiments.isEnabled("spotlight")&&(this._violationCounter=new l.CounterButton,i.appendChild(this._violationCounter),this._violationCounter.data={clickHandler:()=>c.ViewManager.instance().showView("lighthouse"),counters:[{iconName:"ic_info_black_18dp",iconColor:"#2a53cd"}]}),this._issuesCounter=new l.CounterButton,i.appendChild(this._issuesCounter),this._issuesCounter.data={clickHandler:()=>{o.issuesPanelOpenedFrom(n.IssueOpener.StatusBarIssuesCounter),c.ViewManager.instance().showView("issues-pane")},counters:[{iconName:"issue-text-icon",iconColor:"#1a73e8"}]},this._throttler=new t.Throttler(100),a.ConsoleModel.instance().addEventListener(a.Events.ConsoleCleared,this._update,this),a.ConsoleModel.instance().addEventListener(a.Events.MessageAdded,this._update,this),a.ConsoleModel.instance().addEventListener(a.Events.MessageUpdated,this._update,this),s.IssuesManager.instance().addEventListener(s.Events.IssuesCountUpdated,this._update,this),this._update()}_updatedForTest(){}_update(){this._updatingForTest=!0,this._throttler.schedule(this._updateThrottled.bind(this))}get titlesForTesting(){return this._consoleCounter.getAttribute("aria-label")}async _updateThrottled(){const e=a.ConsoleModel.instance().errors(),t=a.ConsoleModel.instance().warnings(),o=this._violationCounter?a.ConsoleModel.instance().violations():0,n=s.IssuesManager.instance().numberOfIssues();let i="";i=m(1===e?C.sError:C.sErrors,{PH1:e});let r="";r=m(1===t?C.sWarning:C.sWarnings,{PH1:t}),this._consoleCounter.setCounts([e,t]);let l="";e&&t?l=`${i}, ${r}`:e?l=i:t&&(l=r);const u=m(C.openConsoleToViewS,{PH1:l});if(d.Tooltip.install(this._consoleCounter,u),h.setAccessibleName(this._consoleCounter,u),this._consoleCounter.classList.toggle("hidden",!(e||t)),this._violationCounter){this._violationCounter.setCounts([o]);let s="";s=m(1===o?C.sViolation:C.sViolations,{PH1:o});const e=m(C.openLighthouseToViewS,{PH1:s});d.Tooltip.install(this._violationCounter,e),h.setAccessibleName(this._violationCounter,e),this._violationCounter.classList.toggle("hidden",!o)}this._issuesCounter.setCounts([n]);let c="";c=m(1===n?C.sIssue:C.sIssues,{PH1:n});const p=m(C.openIssuesToViewS,{PH1:c});d.Tooltip.install(this._issuesCounter,p),h.setAccessibleName(this._issuesCounter,p),this._issuesCounter.classList.toggle("hidden",!n),this._toolbarItem.setVisible(Boolean(e||t||o||n)),_.InspectorView.instance().toolbarItemResized(),this._updatingForTest=!1,this._updatedForTest()}item(){return this._toolbarItem}}g._instanceForTest=null;var w=Object.freeze({__proto__:null,UIStrings:C,WarningErrorCounter:g});export{w as WarningErrorCounter};
