import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
import {AccountService} from "@app/_services";
import {UserJsonld, UserService} from "@app/core/api/v1";
import {UserDetailComponent} from "@app/_views/user/user-detail/user-detail.component";
import {AppHelperService} from "@app/_helpers/app-helper.service";

@Component({
    selector: 'app-profile',
    templateUrl: './profile.component.html',
    styleUrl: './profile.component.scss'
})
export class ProfileComponent implements OnInit, AfterViewInit {

    @ViewChild("userDetailComponent", {static: false}) userDetailComponent!: UserDetailComponent;

    protected user!: UserJsonld;

    constructor(
        private accountService: AccountService,
        private userService: UserService,
        private appHelperService: AppHelperService
    ) {
        const user = this.accountService.userValue;
        if (user?.id !== null && user?.id !== undefined) {
            this.userService.usersIdGet(
                this.appHelperService.extractId(user.id)
            ).subscribe(
                data => {
                    this.user = data;
                }
            );
        }
    }

    ngOnInit() {

    }

    ngAfterViewInit(): void {
    }


}
