import*as Common from"../common/common.js";import*as Host from"../host/host.js";let fileManagerInstance;export class FileManager extends Common.ObjectWrapper.ObjectWrapper{constructor(){super(),this._saveCallbacks=new Map,Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(Host.InspectorFrontendHostAPI.Events.SavedURL,this._savedURL,this),Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(Host.InspectorFrontendHostAPI.Events.CanceledSaveURL,this._canceledSavedURL,this),Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(Host.InspectorFrontendHostAPI.Events.AppendedToURL,this._appendedToURL,this)}static instance(e={forceNew:null}){const{forceNew:t}=e;return fileManagerInstance&&!t||(fileManagerInstance=new FileManager),fileManagerInstance}save(e,t,n){const s=new Promise((t=>this._saveCallbacks.set(e,t)));return Host.InspectorFrontendHost.InspectorFrontendHostInstance.save(e,t,n),s}_savedURL(e){const t=e.data.url,n=this._saveCallbacks.get(t);this._saveCallbacks.delete(t),n&&n({fileSystemPath:e.data.fileSystemPath})}_canceledSavedURL(e){const t=e.data,n=this._saveCallbacks.get(t);this._saveCallbacks.delete(t),n&&n(null)}append(e,t){Host.InspectorFrontendHost.InspectorFrontendHostInstance.append(e,t)}close(e){Host.InspectorFrontendHost.InspectorFrontendHostInstance.close(e)}_appendedToURL(e){const t=e.data;this.dispatchEventToListeners(Events.AppendedToURL,t)}}export var Events;!function(e){e.AppendedToURL="AppendedToURL"}(Events||(Events={}));