import { Component, OnInit } from '@angular/core';
import { FamilyMember } from '../../entity/Member';
import { FamilyMemberService } from '../../services/crudServices/family-member.service';
import { first } from "rxjs/operators";
import { DropDownOptions } from '../../entity/dropDownOption';
import { NbToastrService } from '@nebular/theme';
import { LoginUserService } from '../../services/login-user.service';
@Component({
  selector: 'ngx-user-profile',
  templateUrl: './user-profile.component.html',
  styleUrls: ['./user-profile.component.scss']
})
export class UserProfileComponent implements OnInit {
  GenderOptions = DropDownOptions.GenderOptions;

  constructor(
    private memberService: FamilyMemberService,
    private loginUserService: LoginUserService,
    private toastrService: NbToastrService,
  ) { }
  data: FamilyMember;
  processing: boolean;
  ngOnInit(): void {
    this.memberService.getById(this.loginUserService.userAccess.memberId).pipe(first()).subscribe(result => {
      this.data = result;
      if (this.data.dateOfBaptized == undefined) this.data.dateOfBaptized = null;
      if (this.data.dateOfWalkIn == undefined) this.data.dateOfWalkIn = null;
      if (this.data.birthday == undefined) this.data.birthday = null;
    });

  }
  close() {

  }
  update() {
    this.memberService.createOrUpdate(this.data).pipe(first()).subscribe(result => {

      this.toastrService.success('更新完成!', '個人資料');
    });
  }
}
