import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../services/login-api';
import { NbWindowService, NbDialogService } from '@nebular/theme';
import { FrontcraftCreateRaidsComponent } from './createraid.compontent';

@Component({
  selector: 'raids',
  templateUrl: 'raids.component.html',
  styleUrls: ['raids.component.scss'],
})
export class FrontcraftRaidsComponent implements OnInit{


  manageRaid
  raids = []
  oldraids = []
  pageSize = 10;

  constructor(
    private api: ApiService,
    private dialogService: NbDialogService
  ) {
    this.manageRaid = this.api.get('manageRaid')

  }

  ngOnInit(): void {
    this.refresh()
  }

  refresh() {
    this.api.get('RaidManager').getRaids().then(raids => {
      this.raids = raids
    })

    const raidManager = this.api.get('RaidManager')
    raidManager.getPastRaids(10).then(raiddata => {
      this.oldraids = raiddata
    })
  }

  create(){
    this.dialogService.open(FrontcraftCreateRaidsComponent, { 
      closeOnBackdropClick: true,
      closeOnEsc: true,
      context: {
        templates: this.oldraids
      } 
    }).onClose.subscribe(()=>{
      this.refresh()
    });

  }
}
