import*as Common from"../../../core/common/common.js";import*as i18n from"../../../core/i18n/i18n.js";import*as IssuesManager from"../../../models/issues_manager/issues_manager.js";import*as ComponentHelpers from"../../components/helpers/helpers.js";import*as LitHtml from"../../lit-html/lit-html.js";import issueCounterStyles from"./issueCounter.css.js";const UIStrings={pageErrors:"{issueCount, plural, =1 {# page error} other {# page errors}}",breakingChanges:"{issueCount, plural, =1 {# breaking change} other {# breaking changes}}",possibleImprovements:"{issueCount, plural, =1 {# possible improvement} other {# possible improvements}}"},str_=i18n.i18n.registerUIStrings("ui/components/issue_counter/IssueCounter.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export function getIssueKindIconData(s){switch(s){case IssuesManager.Issue.IssueKind.PageError:return{iconName:"issue-cross-filled",color:"var(--icon-error)",width:"20px",height:"20px"};case IssuesManager.Issue.IssueKind.BreakingChange:return{iconName:"issue-exclamation-filled",color:"var(--icon-warning)",width:"20px",height:"20px"};case IssuesManager.Issue.IssueKind.Improvement:return{iconName:"issue-text-filled",color:"var(--icon-info)",width:"20px",height:"20px"}}}function toIconGroup({iconName:s,color:e,width:t,height:i},n){return n?{iconName:s,iconColor:e,iconWidth:n,iconHeight:n}:{iconName:s,iconColor:e,iconWidth:t,iconHeight:i}}const listFormat=new Intl.ListFormat(navigator.language,{type:"unit",style:"short"});export function getIssueCountsEnumeration(s,e=!0){const t=[s.numberOfIssues(IssuesManager.Issue.IssueKind.PageError),s.numberOfIssues(IssuesManager.Issue.IssueKind.BreakingChange),s.numberOfIssues(IssuesManager.Issue.IssueKind.Improvement)],i=[i18nString(UIStrings.pageErrors,{issueCount:t[0]}),i18nString(UIStrings.breakingChanges,{issueCount:t[1]}),i18nString(UIStrings.possibleImprovements,{issueCount:t[2]})];return listFormat.format(i.filter(((s,i)=>!e||t[i]>0)))}export class IssueCounter extends HTMLElement{static litTagName=LitHtml.literal`devtools-issue-counter`;#s=this.attachShadow({mode:"open"});#e=void 0;#t=void 0;#i="";#n;#r=[0,0,0];#a="OmitEmpty";#o=void 0;#u=void 0;#l;#c=!1;scheduleUpdate(){this.#n?this.#n.schedule((async()=>this.#h())):this.#h()}connectedCallback(){this.#s.adoptedStyleSheets=[issueCounterStyles]}set data(s){this.#e=s.clickHandler,this.#i=s.leadingText??"",this.#t=s.tooltipCallback,this.#a=s.displayMode??"OmitEmpty",this.#u=s.accessibleName,this.#l=s.throttlerTimeout,this.#c=Boolean(s.compact),this.#o!==s.issuesManager&&(this.#o?.removeEventListener("IssuesCountUpdated",this.scheduleUpdate,this),this.#o=s.issuesManager,this.#o.addEventListener("IssuesCountUpdated",this.scheduleUpdate,this)),0!==s.throttlerTimeout?this.#n=new Common.Throttler.Throttler(s.throttlerTimeout??100):this.#n=void 0,this.scheduleUpdate()}get data(){return{clickHandler:this.#e,leadingText:this.#i,tooltipCallback:this.#t,displayMode:this.#a,accessibleName:this.#u,throttlerTimeout:this.#l,compact:this.#c,issuesManager:this.#o}}#h(){if(!this.#o)return;this.#r=[this.#o.numberOfIssues(IssuesManager.Issue.IssueKind.PageError),this.#o.numberOfIssues(IssuesManager.Issue.IssueKind.BreakingChange),this.#o.numberOfIssues(IssuesManager.Issue.IssueKind.Improvement)];const s=[IssuesManager.Issue.IssueKind.PageError,IssuesManager.Issue.IssueKind.BreakingChange,IssuesManager.Issue.IssueKind.Improvement][this.#r.findIndex((s=>s>0))??2],e=(e,t)=>{switch(this.#a){case"OmitEmpty":return t>0?`${t}`:void 0;case"ShowAlways":return`${t}`;case"OnlyMostImportant":return e===s?`${t}`:void 0}},t="2ex",i={groups:[{...toIconGroup(getIssueKindIconData(IssuesManager.Issue.IssueKind.PageError),t),text:e(IssuesManager.Issue.IssueKind.PageError,this.#r[0])},{...toIconGroup(getIssueKindIconData(IssuesManager.Issue.IssueKind.BreakingChange),t),text:e(IssuesManager.Issue.IssueKind.BreakingChange,this.#r[1])},{...toIconGroup(getIssueKindIconData(IssuesManager.Issue.IssueKind.Improvement),t),text:e(IssuesManager.Issue.IssueKind.Improvement,this.#r[2])}],clickHandler:this.#e,leadingText:this.#i,accessibleName:this.#u,compact:this.#c};LitHtml.render(LitHtml.html`
        <icon-button .data=${i} .accessibleName=${this.#u}></icon-button>
        `,this.#s,{host:this}),this.#t?.()}}ComponentHelpers.CustomElements.defineComponent("devtools-issue-counter",IssueCounter);