import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';


@Component({
  selector: 'dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
  sampleData: any[] = [];
  objectKeys = Object.keys; // Expose Object.keys as a class property

  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    console.log("inside ngOnInit..");
    this.getJsonData();
  }

  getJsonData() {
    const serviceUrl = "http://192.168.0.116:9090/ibase/rest/UserTasksService/getUserTasks?REF_SER=N-PRO&REF_ID=prop-3";
    console.log("getDescriptionData >> serviceUrl :: ", serviceUrl);

    const headers = new HttpHeaders({
      'TOKEN_ID': 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuZXlKcWRHa2lPaUl3TURBd01EQXdOREV4SWl3aVlYQndiR2xqWVhScGIyNUpaQ0k2SWtaTVZWUlVSVkpCVUZBaUxDSnlaV2RwYjI0aU9pSWlMQ0prWlhOcFoyNWhkR2x2YmlJNklpSXNJbkpsY0c5eWRGUnZRMjlrWlNJNklpSXNJbTVoYldVaU9pSWdJaXdpWkdsMmFYTnBiMjRpT2lJaUxDSmxiV0ZwYkNJNklpSXNJbWh4SWpvaUlpd2laVzUwYVhSNVZIbHdaU0k2SWtRaUxDSmxiblJwZEhsRGIyUmxJam9pUVcxdmJGTWlMQ0psYm5SbGNuQnlhWE5sSWpvaVFWQlFWa2xUSWl3aWRISmhibk5FUWlJNklrRlFVRlpKVXlJc0lteHZaMmx1VTJsMFpTSTZJbE13TURBeElpd2ljSEp2Wm1sc1pVbGtJam9pUVVSTlNVNGlMQ0psZUhBaU9qRTNORGN6TWprM01UTTBmUS5NTjRqS00xelQ1NS1OZjZrdHIyWjVHdGRmY3BocFhFeWVQemRwcGFPT2Nv'
    });

    this.http.get<any>(serviceUrl, { headers }).subscribe({
      next: (response: any) => {
        console.log("getDescriptionData >> response :: ", response);

        if (response && Array.isArray(response) && response.length > 0) {
          this.sampleData = response;
          console.log(this.sampleData);
        }
      },
      error: (error: any) => {
        console.error("Error:", error);
      },
      complete: () => {
        console.log("Request completed");
      }
    });
  }

}
