import { Component, OnInit } from '@angular/core';
import { GroupBoilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service';
import { NotifierService } from "angular-notifier";

@Component({
  selector: 'app-groupboil',
  templateUrl: './groupboil.component.html',
  styleUrls: ['./groupboil.component.scss']
})
export class GroupboilComponent implements OnInit {
  grouboilerplates?: GroupBoilerplate[];
  title = '';

  private readonly notifier: NotifierService;
  constructor(private boilerplateService: BoilerplateService, notifierService: NotifierService) {
    this.notifier = notifierService;
  }

  ngOnInit(): void {
    this.retrievegroupBoilerplates();
  }

  retrievegroupBoilerplates(): void {
    this.boilerplateService.getAllgroupboil()
      .subscribe(
        data => {
          this.grouboilerplates = data;
          //console.log(data);
        },
        error => {
          console.log(error);
        });

  }

  deleteGroupBoilerplate(id: any): void {
    if (confirm("Αre you sure you want to delete this Project?")) {
      this.boilerplateService.deletegroupboil(id.id)
        .subscribe(
          response => {
            //console.log(response);
            this.notifier.notify("success", "Project deleted");

            this.retrievegroupBoilerplates();
          },
          error => {
            this.notifier.notify("warning", (JSON.stringify(error["error"]["title"][0])));
          });
    }
  }

}
