import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {Observable, Observer} from 'rxjs';
import { GithubComponent } from '../github/github.component';
import { JiraComponent } from '../jira/jira.component';
import { SlackComponent } from '../slack/slack.component';
import { ConfluenceComponent } from '../confluence/confluence.component';
import { FetcherService } from '../fetcher.service';
import { CookieService } from 'ngx-cookie-service';
export interface ExampleTab {
  label: string;
  content: string;
}

@Component({
  selector: 'app-project',
  templateUrl: './project.component.html',
  styleUrls: ['./project.component.css']
})
export class ProjectComponent implements OnInit {
  id: number;
  name: string;
  tabInd = 1;
  asyncTabs: Observable<ExampleTab[]>;
  pid = '';
  constructor(private fetcherService: FetcherService, private cookieService: CookieService) {
    console.log(window.history.state);
    this.id = window.history.state.id;
    this.name = window.history.state.name;
    this.asyncTabs = new Observable((observer: Observer<ExampleTab[]>) => {
      setTimeout(() => {
        observer.next([
          {label: 'Github', content: 'Content 1'},
          {label: 'Confluence', content: 'Content 2'},
          {label: 'JIRA', content: 'Content 3'},
          {label: 'Slack', content: 'Content 4'}
        ]);
      }, 1000);
    });
  }
  changeTab(event: any) {
    this.tabInd = event.index+1;
  }
  ngOnInit(): void {
    this.pid = this.cookieService.get('pid');
    if (this.id != undefined && this.pid != this.id.toString()) {
      this.cookieService.set('pid', this.id.toString());
    }
    this.fetcherService.setCurrentProjectId(this.id);
    console.log(this.id);
  }

}
