import*as Common from"../common/common.js";export class ProfileHeader extends Common.ObjectWrapper.ObjectWrapper{constructor(e,t){super(),this._profileType=e,this.title=t,this.uid=e.incrementProfileUid(),this._fromFile=!1,this.tempFile=null}setTitle(e){this.title=e,this.dispatchEventToListeners(Events.ProfileTitleChanged,this)}profileType(){return this._profileType}updateStatus(e,t){this.dispatchEventToListeners(Events.UpdateStatus,new StatusUpdate(e,t))}createSidebarTreeElement(e){throw new Error("Not implemented.")}createView(e){throw new Error("Not implemented.")}removeTempFile(){this.tempFile&&this.tempFile.remove()}dispose(){}canSaveToFile(){return!1}saveToFile(){throw new Error("Not implemented.")}loadFromFile(e){throw new Error("Not implemented.")}fromFile(){return this._fromFile}setFromFile(){this._fromFile=!0}setProfile(e){}}export class StatusUpdate{constructor(e,t){this.subtitle=e,this.wait=t}}export var Events;!function(e){e.UpdateStatus="UpdateStatus",e.ProfileReceived="ProfileReceived",e.ProfileTitleChanged="ProfileTitleChanged"}(Events||(Events={}));export class ProfileType extends Common.ObjectWrapper.ObjectWrapper{constructor(e,t){super(),this._id=e,this._name=t,this._profiles=[],this._profileBeingRecorded=null,this._nextProfileUid=1,window.opener||window.addEventListener("unload",this._clearTempStorage.bind(this),!1)}typeName(){return""}nextProfileUid(){return this._nextProfileUid}incrementProfileUid(){return this._nextProfileUid++}hasTemporaryView(){return!1}fileExtension(){return null}get buttonTooltip(){return""}get id(){return this._id}get treeItemTitle(){return this._name}get name(){return this._name}buttonClicked(){return!1}get description(){return""}isInstantProfile(){return!1}isEnabled(){return!0}getProfiles(){return this._profiles.filter(function(e){return this._profileBeingRecorded!==e}.bind(this))}customContent(){return null}setCustomContentEnabled(e){}getProfile(e){for(let t=0;t<this._profiles.length;++t)if(this._profiles[t].uid===e)return this._profiles[t];return null}loadFromFile(e){let t=e.name;const i=this.fileExtension();i&&t.endsWith(i)&&(t=t.substr(0,t.length-i.length));const r=this.createProfileLoadedFromFile(t);return r.setFromFile(),this.setProfileBeingRecorded(r),this.addProfile(r),r.loadFromFile(e)}addProfile(e){this._profiles.push(e),this.dispatchEventToListeners(ProfileEvents.AddProfileHeader,e)}removeProfile(e){const t=this._profiles.indexOf(e);-1!==t&&(this._profiles.splice(t,1),this._disposeProfile(e))}_clearTempStorage(){for(let e=0;e<this._profiles.length;++e)this._profiles[e].removeTempFile()}profileBeingRecorded(){return this._profileBeingRecorded}setProfileBeingRecorded(e){this._profileBeingRecorded=e}profileBeingRecordedRemoved(){}reset(){for(const e of this._profiles.slice())this._disposeProfile(e);this._profiles=[],this._nextProfileUid=1}_disposeProfile(e){this.dispatchEventToListeners(ProfileEvents.RemoveProfileHeader,e),e.dispose(),this._profileBeingRecorded===e&&(this.profileBeingRecordedRemoved(),this.setProfileBeingRecorded(null))}}export var ProfileEvents;!function(e){e.AddProfileHeader="add-profile-header",e.ProfileComplete="profile-complete",e.RemoveProfileHeader="remove-profile-header",e.ViewUpdated="view-updated"}(ProfileEvents||(ProfileEvents={}));