import { Component } from '@angular/core'
import { Observable, of } from 'rxjs'
import { CanComponentDeactivate, CanComponentDeactivateResult } from '@app/core/routing/can-deactivate-guard.service'

@Component({
  selector: 'app-upload-events',
  templateUrl: './event-upload.component.html',
  styleUrls: ['./event-upload.component.scss']
})
export class UploadEventsComponent implements CanComponentDeactivate {

  private formDirty = false // change this when form is edited

  // This is REQUIRED by the guard
  canDeactivate(): CanComponentDeactivateResult {
    if (!this.formDirty) {
      return { canDeactivate: true }
    }

    return {
      canDeactivate: false,
      text: 'You have unsaved event changes. Leave without saving?'
    }
  }

  reset() {
    this.formDirty = false
  }
}
