import { SysDataService } from "../../../service/sys-data.service";
import { HelperService } from "../../../service/helper.service";
import { Router } from "@angular/router";
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";

@Component({
  selector: "app-sys002-view-user",
  templateUrl: "./sys002-view-user.component.html"
})
export class Sys002ViewUserComponent implements OnInit {
  errorMessage: String;
  data: any;
  selectRole: any;
  selectedUser: any;
  roleId: number;
  groupId: number;
  siteNameText: string;

  constructor(
    private sysDataService: SysDataService,
    private helperService: HelperService,
    private router: Router,
    private route: ActivatedRoute
  ) {}

  ngOnInit() {
    this.selectRole = this.helperService.RoleCode;
    this.route.data.subscribe((data: { selectedUser: any }) => {
      this.selectedUser = data.selectedUser;
      this.roleId = this.selectedUser.RoleCode_Id;
      this.groupId = this.selectedUser.GroupCode_Id;
    });
  }

  backPreviousPage() {
    this.router.navigateByUrl("/sys/sys002");
  }

  getRoleCodeText(id: number) {
    return this.helperService.getRoleCodeText(id);
  }

  getGroupCodeText(id: number) {
    return this.helperService.getGroupCodeText(id);
  }

  getSiteNameText(siteIdArray: any) {
    this.siteNameText = " ";
    for (let i = 0 ; i < siteIdArray.length; i++) {
      this.siteNameText += siteIdArray[i].SiteName + ", ";

    }
    return this.siteNameText;
  }
}
