text: import*as Common from"../common/common.js";import*as UI from"../ui/ui.js";import{Events,IsolatedFileSystemManager}from"./IsolatedFileSystemManager.js";export class EditFileSystemView extends UI.Widget.VBox{constructor(e){super(!0),this.registerRequiredCSS("persistence/editFileSystemView.css"),this._fileSystemPath=e,this._eventListeners=[IsolatedFileSystemManager.instance().addEventListener(Events.ExcludedFolderAdded,this._update,this),IsolatedFileSystemManager.instance().addEventListener(Events.ExcludedFolderRemoved,this._update,this)];const t=this.contentElement.createChild("div","file-system-header");t.createChild("div","file-system-header-text").textContent=Common.UIString.UIString("Excluded folders"),t.appendChild(UI.UIUtils.createTextButton(Common.UIString.UIString("Add"),this._addExcludedFolderButtonClicked.bind(this),"add-button")),this._excludedFoldersList=new UI.ListWidget.ListWidget(this),this._excludedFoldersList.element.classList.add("file-system-list"),this._excludedFoldersList.registerRequiredCSS("persistence/editFileSystemView.css");const i=createElementWithClass("div","file-system-list-empty");i.textContent=Common.UIString.UIString("None"),this._excludedFoldersList.setEmptyPlaceholder(i),this._excludedFoldersList.show(this.contentElement),this._update()}dispose(){Common.EventTarget.EventTarget.removeEventListeners(this._eventListeners)}_update(){if(!this._muteUpdate){this._excludedFoldersList.clear(),this._excludedFolders=[];for(const e of IsolatedFileSystemManager.instance().fileSystem(this._fileSystemPath).excludedFolders().values())this._excludedFolders.push(e),this._excludedFoldersList.appendItem(e,!0)}}_addExcludedFolderButtonClicked(){this._excludedFoldersList.addNewItem(0,"")}renderItem(e,t){const i=createElementWithClass("div","file-system-list-item"),s=t?e:Common.UIString.UIString("%s (via .devtools)",e),d=i.createChild("div","file-system-value");return d.textContent=s,d.title=s,i}removeItemRequested(e,t){IsolatedFileSystemManager.instance().fileSystem(this._fileSystemPath).removeExcludedFolder(this._excludedFolders[t])}commitEdit(e,t,i){this._muteUpdate=!0,i||IsolatedFileSystemManager.instance().fileSystem(this._fileSystemPath).removeExcludedFolder(e),IsolatedFileSystemManager.instance().fileSystem(this._fileSystemPath).addExcludedFolder(this._normalizePrefix(t.control("pathPrefix").value)),this._muteUpdate=!1,this._update()}beginEdit(e){const t=this._createExcludedFolderEditor();return t.control("pathPrefix").value=e,t}_createExcludedFolderEditor(){if(this._excludedFolderEditor)return this._excludedFolderEditor;const e=new UI.ListWidget.Editor;this._excludedFolderEditor=e;const t=e.contentElement();t.createChild("div","file-system-edit-row").createChild("div","file-system-value").textContent=Common.UIString.UIString("Folder path");return t.createChild("div","file-system-edit-row").createChild("div","file-system-value").appendChild(e.createInput("pathPrefix","text","/path/to/folder/",function(e,t,i){const s=this._normalizePrefix(i.value.trim());if(!s)return{valid:!1,errorMessage:ls`Enter a path`};const d=IsolatedFileSystemManager.instance().fileSystem(this._fileSystemPath).excludedFolders().size;for(let e=0;e<d;++e)if(e!==t&&this._excludedFolders[e]===s)return{valid:!1,errorMessage:ls`Enter a unique path`};return{valid:!0}}.bind(this))),e}_normalizePrefix(e){return e?e+("/"===e[e.length-1]?"":"/"):""}}