import*as i18n from"../i18n/i18n.js";import*as UI from"../ui/ui.js";import{Events}from"./ComputedStyleModel.js";const UIStrings={renderedFonts:"Rendered Fonts",networkResource:"Network resource",localFile:"Local file",dGlyph:"(1 glyph)",dGlyphs:"({PH1} glyphs)"},str_=i18n.i18n.registerUIStrings("elements/PlatformFontsWidget.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class PlatformFontsWidget extends UI.ThrottledWidget.ThrottledWidget{constructor(t){super(!0),this.registerRequiredCSS("elements/platformFontsWidget.css",{enableLegacyPatching:!0}),this._sharedModel=t,this._sharedModel.addEventListener(Events.ComputedStyleChanged,this.update,this),this._sectionTitle=document.createElement("div"),this._sectionTitle.classList.add("title"),this.contentElement.classList.add("platform-fonts"),this.contentElement.appendChild(this._sectionTitle),this._sectionTitle.textContent=i18nString(UIStrings.renderedFonts),this._fontStatsSection=this.contentElement.createChild("div","stats-section")}doUpdate(){const t=this._sharedModel.cssModel(),e=this._sharedModel.node();return e&&t?t.platformFontsPromise(e.id).then(this._refreshUI.bind(this,e)):Promise.resolve()}_refreshUI(t,e){if(this._sharedModel.node()!==t)return;this._fontStatsSection.removeChildren();const n=!e||!e.length;if(this._sectionTitle.classList.toggle("hidden",n),!n&&e){e.sort((function(t,e){return e.glyphCount-t.glyphCount}));for(let t=0;t<e.length;++t){const n=this._fontStatsSection.createChild("div","font-stats-item");n.createChild("span","font-name").textContent=e[t].familyName;n.createChild("span","font-delimeter").textContent="\u2014";n.createChild("span").textContent=e[t].isCustomFont?i18nString(UIStrings.networkResource):i18nString(UIStrings.localFile);const s=n.createChild("span","font-usage"),i=e[t].glyphCount;s.textContent=1===i?i18nString(UIStrings.dGlyph):i18nString(UIStrings.dGlyphs,{PH1:i})}}}}