import{IssuesManager as t}from"../browser_sdk/browser_sdk.js";import{Console as e,Throttler as s}from"../common/common.js";import{userMetrics as o,UserMetrics as n}from"../host/host.js";import{ls as i}from"../platform/platform.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";class C{constructor(){C._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 s.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),t.IssuesManager.instance().addEventListener(t.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(),s=a.ConsoleModel.instance().warnings(),o=this._violationCounter?a.ConsoleModel.instance().violations():0,n=t.IssuesManager.instance().numberOfIssues();let r="";r=1===e?i`${e} error`:i`${e} errors`;let l="";l=1===s?i`${s} warning`:i`${s} warnings`,this._consoleCounter.setCounts([e,s]);let u="";e&&s?u=i`${r}, ${l}`:e?u=r:s&&(u=l);const c=i`Open Console to view ${u}`;if(d.Tooltip.install(this._consoleCounter,c),h.setAccessibleName(this._consoleCounter,c),this._consoleCounter.classList.toggle("hidden",!(e||s)),this._violationCounter){this._violationCounter.setCounts([o]);let t="";t=1===o?i`${o} violation`:i`${o} violations`;const e=i`Open Lighthouse to view ${t}`;d.Tooltip.install(this._violationCounter,e),h.setAccessibleName(this._violationCounter,e),this._violationCounter.classList.toggle("hidden",!o)}this._issuesCounter.setCounts([n]);let C="";C=1===n?i`${n} issue`:i`${n} issues`;const p=i`Open Issues to view ${C}`;d.Tooltip.install(this._issuesCounter,p),h.setAccessibleName(this._issuesCounter,p),this._issuesCounter.classList.toggle("hidden",!n),this._toolbarItem.setVisible(Boolean(e||s||o||n)),_.InspectorView.instance().toolbarItemResized(),this._updatingForTest=!1,this._updatedForTest()}item(){return this._toolbarItem}}C._instanceForTest=null;var p=Object.freeze({__proto__:null,WarningErrorCounter:C});export{p as WarningErrorCounter};
