import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Store } from '@ngrx/store';

import { Member, MemberTotp } from '@overflow/commons-typescript/model/member';
import { Observable } from 'rxjs';
import { DomainMember } from '@overflow/commons-typescript/model/domain';

import * as TotpEntityStore from '../store/entity/member-totp';
import { AuthContainerSelector } from '@overflow/shared/auth/store';

@Component({
  selector: 'of-member-totp-container',
  templateUrl: './member-totp-container.component.html',
})
export class MemberTotpContainerComponent implements OnInit {
  domainMember$: Observable<DomainMember>;
  totp$: Observable<MemberTotp[]>;
  lists = [];

  constructor(
    private activatedRoute: ActivatedRoute,
    private router: Router,
    private store: Store<any>,
  ) { }

  ngOnInit() {
    this.domainMember$ = this.store.select(AuthContainerSelector.selectDomainMember);
  }

  regist(info: {member: Member, code: string, secretCode: string}) {
    const secretCode = 'X6AWAK573M5372NM';

    this.store.dispatch(new TotpEntityStore.Regist(info));
  }

  create(member: Member) {
    this.store.dispatch(new TotpEntityStore.CreateTotp(member));
  }
}
