import { Component, OnInit } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
//import { PROJECTS } from './projects';
import { GET_REPOS_API } from '../urls';
import { getProjectDetailsResponse } from '../responses';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Router } from '@angular/router';
export interface Tile {
  color: string;
  cols: number;
  rows: number;
  text: string;
}

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  project_stat$ = new Observable<getProjectDetailsResponse>;
  projects = new Array<{pid:string;pname:string;created_date:string;powner:string;confluence_id:string;git_id:string;jira_id:string;content:string;description:string}>();
  constructor(private cookieService: CookieService, private router: Router, private http: HttpClient ) { }
  setCookie(kname: string,value: string){
    this.cookieService.set(kname,value);
  }
  getCookie(kname: string){
    return this.cookieService.get(kname);
  }
  deleteCookie(kname: string){
    this.cookieService.delete(kname);
  }
  calColCount(){
    //console.log(window.innerWidth);
    if(window.innerWidth > 1000){
      return 3;
    }else if(window.innerWidth > 600){
      return 2;
    }else{
      return 1;
    }
  }
  ngOnInit(): void {
    console.log(this.getCookie('uid'));
    this.project_stat$ = this.http.get<getProjectDetailsResponse>(GET_REPOS_API+'?uid='+ this.getCookie('uid'));
    this.project_stat$.subscribe(
      (response) => {
        console.log(response);
        if (response.status == true) {
          for (let i = 0; i < response.repos.length; i++) {
            this.projects.push(response.repos[i]);
          }
          console.log(this.projects);
        } 
        else{
          alert('Invalid Credentials');
        }
      }
    );
  }
  tiles: Tile[] = [
    {text: 'One', cols: 1, rows: 1, color: 'white'},
  ];
}
