import { Component, OnInit } from "@angular/core";
import { User } from "../../config/services/user";
import { UserService } from "../../config/user.service";
import { ServiceService } from "../../config/service.service";
import { Router, ActivatedRoute } from "@angular/router";

@Component({
  selector: "app-profile",
  templateUrl: "./profile.page.html",
  styleUrls: ["./profile.page.scss"]
})
export class ProfilePage implements OnInit {
  user: User;
  userdata: any;
  custId: String;

  constructor(
    private router: Router,
    private useService: UserService,
    private service: ServiceService
  ) {
    const params = this.useService.users;
    const userdata = this.service.get("user").then(data => {
      if (data) {
        data = JSON.parse(data);
        this.service.set("params", data);

        this.custId = data.uid;
      }
    });

    this.useService.getUserData("9cYSZwGvVpgkUHVcz8Dm6oqGX152");

    // .then(res => {
    //   console.log("asdasda", res);
    //   this.userdata = res;
    // });
  }

  goToPage(path, data = null) {
    this.router.navigateByUrl(path, { queryParams: data });
    document.body.scrollTop = document.documentElement.scrollTop = 0;
  }

  ngOnInit() {
    let This = this;
    setTimeout(() => {
      this.user = this.useService.users;
      console.log("[users]", this.user);
      this.service.set("params", this.user);
    }, 500);
  }
}
