import*as ARIAUtils from"./ARIAUtils.js";import{Toolbar}from"./Toolbar.js";import{Tooltip}from"./Tooltip.js";import{VBox}from"./Widget.js";export class ReportView extends VBox{constructor(e){super(!0),this.registerRequiredCSS("ui/reportView.css",{enableLegacyPatching:!1}),this._contentBox=this.contentElement.createChild("div","report-content-box"),this._headerElement=this._contentBox.createChild("div","report-header vbox"),this._titleElement=this._headerElement.createChild("div","report-title"),e?this._titleElement.textContent=e:this._headerElement.classList.add("hidden"),ARIAUtils.markAsHeading(this._titleElement,1),this._sectionList=this._contentBox.createChild("div","vbox")}setTitle(e){this._titleElement.textContent!==e&&(this._titleElement.textContent=e,this._headerElement.classList.toggle("hidden",Boolean(e)))}setSubtitle(e){this._subtitleElement&&this._subtitleElement.textContent===e||(this._subtitleElement||(this._subtitleElement=this._headerElement.createChild("div","report-subtitle")),this._subtitleElement.textContent=e)}setURL(e){this._urlElement||(this._urlElement=this._headerElement.createChild("div","report-url link")),this._urlElement.removeChildren(),e&&this._urlElement.appendChild(e)}createToolbar(){const e=new Toolbar("");return this._headerElement.appendChild(e.element),e}appendSection(e,t){const i=new Section(e,t);return i.show(this._sectionList),i}sortSections(e){const t=this.children().slice();if(!t.every(((t,i,l)=>!i||e(l[i-1],l[i])<=0))){this.detachChildWidgets(),t.sort(e);for(const e of t)e.show(this._sectionList)}}setHeaderVisible(e){this._headerElement.classList.toggle("hidden",!e)}setBodyScrollable(e){this._contentBox.classList.toggle("no-scroll",!e)}}export class Section extends VBox{constructor(e,t){super(),this.element.classList.add("report-section"),t&&this.element.classList.add(t),this._headerElement=this.element.createChild("div","report-section-header"),this._titleElement=this._headerElement.createChild("div","report-section-title"),this.setTitle(e),ARIAUtils.markAsHeading(this._titleElement,2),this._fieldList=this.element.createChild("div","vbox"),this._fieldMap=new Map}title(){return this._titleElement.textContent||""}setTitle(e,t){this._titleElement.textContent!==e&&(this._titleElement.textContent=e),Tooltip.install(this._titleElement,t||""),this._titleElement.classList.toggle("hidden",!this._titleElement.textContent)}setUiGroupTitle(e){ARIAUtils.markAsGroup(this.element),ARIAUtils.setAccessibleName(this.element,e)}createToolbar(){const e=new Toolbar("");return this._headerElement.appendChild(e.element),e}appendField(e,t){let i=this._fieldMap.get(e);return i||(i=this._fieldList.createChild("div","report-field"),i.createChild("div","report-field-name").textContent=e,this._fieldMap.set(e,i),i.createChild("div","report-field-value")),t&&i.lastElementChild&&(i.lastElementChild.textContent=t),i.lastElementChild}appendFlexedField(e,t){const i=this.appendField(e,t);return i.classList.add("report-field-value-is-flexed"),i}removeField(e){const t=this._fieldMap.get(e);t&&t.remove(),this._fieldMap.delete(e)}setFieldVisible(e,t){const i=this._fieldMap.get(e);i&&i.classList.toggle("hidden",!t)}fieldValue(e){const t=this._fieldMap.get(e);return t?t.lastElementChild:null}appendRow(){return this._fieldList.createChild("div","report-row")}appendSelectableRow(){return this._fieldList.createChild("div","report-row report-row-selectable")}clearContent(){this._fieldList.removeChildren(),this._fieldMap.clear()}markFieldListAsGroup(){ARIAUtils.markAsGroup(this._fieldList),ARIAUtils.setAccessibleName(this._fieldList,this.title())}setIconMasked(e){this.element.classList.toggle("show-mask",e)}}