import {
  Component, EventEmitter,
  OnDestroy,
  OnInit, Output,
} from '@angular/core';
import { Member } from '@overflow/commons-typescript/model/member';
import {select, Store} from '@ngrx/store';

import * as MemberEntityStore from '../store/entity/member';
import { MemberSignupContainerSelector } from '../store';
import { Observable } from 'rxjs';

@Component({
  selector: 'of-member-signup-container',
  templateUrl: './member-signup-container.component.html',
})
export class MemberSignupContainerComponent implements OnInit, OnDestroy {

  member$: Observable<Member>;

  constructor(
    private store: Store<any>,
  ) { }

  ngOnInit() {
    this.member$ = this.store.pipe(select(MemberSignupContainerSelector.selectMember));
  }

  ngOnDestroy() {
  }

  onSignup(info: {member: Member, password: string}) {
    this.store.dispatch(new MemberEntityStore.Signup(info));
  }

}
