text: import*as Common from"../common/common.js";import*as UI from"../ui/ui.js";export class NetworkManageCustomHeadersView extends UI.Widget.VBox{constructor(e,t,s,i){super(!0),this.registerRequiredCSS("network/networkManageCustomHeadersView.css"),this.contentElement.classList.add("custom-headers-wrapper"),this.contentElement.createChild("div","header").textContent=Common.UIString.UIString("Manage Header Columns"),this._list=new UI.ListWidget.ListWidget(this),this._list.element.classList.add("custom-headers-list"),this._list.registerRequiredCSS("network/networkManageCustomHeadersView.css");const a=createElementWithClass("div","custom-headers-list-list-empty");a.textContent=Common.UIString.UIString("No custom headers"),this._list.setEmptyPlaceholder(a),this._list.show(this.contentElement),this.contentElement.appendChild(UI.UIUtils.createTextButton(Common.UIString.UIString("Add custom header…"),this._addButtonClicked.bind(this),"add-button")),this._columnConfigs=new Map,e.forEach(e=>this._columnConfigs.set(e.title.toLowerCase(),e)),this._addHeaderColumnCallback=t,this._changeHeaderColumnCallback=s,this._removeHeaderColumnCallback=i,this.contentElement.tabIndex=0}wasShown(){this._headersUpdated()}_headersUpdated(){this._list.clear(),this._columnConfigs.forEach(e=>this._list.appendItem({header:e.title},e.editable))}_addButtonClicked(){this._list.addNewItem(this._columnConfigs.size,{header:""})}renderItem(e,t){const s=createElementWithClass("div","custom-headers-list-item"),i=s.createChild("div","custom-header-name");return i.textContent=e.header,i.title=e.header,s}removeItemRequested(e,t){this._removeHeaderColumnCallback(e.header),this._columnConfigs.delete(e.header.toLowerCase()),this._headersUpdated()}commitEdit(e,t,s){const i=t.control("header").value.trim();let a;a=s?this._addHeaderColumnCallback(i):this._changeHeaderColumnCallback(e.header,i),a&&!s&&this._columnConfigs.delete(e.header.toLowerCase()),a&&this._columnConfigs.set(i.toLowerCase(),{title:i,editable:!0}),this._headersUpdated()}beginEdit(e){const t=this._createEditor();return t.control("header").value=e.header,t}_createEditor(){if(this._editor)return this._editor;const e=new UI.ListWidget.Editor;this._editor=e;const t=e.contentElement();t.createChild("div","custom-headers-edit-row").createChild("div","custom-headers-header").textContent=Common.UIString.UIString("Header Name");return t.createChild("div","custom-headers-edit-row").createChild("div","custom-headers-header").appendChild(e.createInput("header","text","x-custom-header",function(t,s,i){let a=!0;const r=e.control("header").value.trim().toLowerCase();this._columnConfigs.has(r)&&t.header!==r&&(a=!1);return{valid:a}}.bind(this))),e}}