import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { AppDefinitionRepresentationModel } from "@alfresco/adf-process-services";
import { AppConfigService } from "@alfresco/adf-core";

@Component({
  selector: "app-apps",
  templateUrl: "./apps.component.html",
})
export class AppsComponent implements OnInit {
  constructor(private router: Router, private appConfig: AppConfigService) {}
  ngOnInit(): void {
    console.log("😀😀😀😀😀😀😀😀😀😀😀😀😀😀");

    // aps_ip: string = "100.134.1.229"; // 192.168.112.23 // 192.168.112.24
// http://192.168.112.24:7070
// http://192.168.112.23:7070
    // const aps_ip = this.appConfig.get("bpmHost");

    // const myHeaders = new Headers();
    // myHeaders.append(
    //   "Authorization",
    //   "Basic YWRtaW5AYXBwLmFjdGl2aXRpLmNvbTphZG1pbg=="
    // );

    // const requestOptions: RequestInit = {
    //   method: "GET",
    //   headers: myHeaders,
    //   redirect: "follow",
    // };

    // fetch(
    //   `${aps_ip}/activiti-app/api/enterprise/process-definitions`,
    //   requestOptions
    // )
    //   .then((response) => response.text())
    //   .then((result) => console.log(result))
    //   .catch((error) => console.error(error));
  }

  getAppVersion() {
    const myHeaders = new Headers();
    myHeaders.append(
      "Authorization",
      "Basic YWRtaW5AYXBwLmFjdGl2aXRpLmNvbTphZG1pbg=="
    );

    const requestOptions: RequestInit = {
      method: "GET",
      headers: myHeaders,
      redirect: "follow",
    };

    fetch(
      "http://100.134.1.229:7070/activiti-app/api/enterprise/app-version",
      requestOptions
    )
      .then((response) => response.text())
      .then((result) => console.log(result))
      .catch((error) => console.error(error));
  }

  onAppClicked(app: AppDefinitionRepresentationModel) {
    this.router.navigate(["/apps", app.id || 0, "tasks"]);
  }
}
