//
//  ConfirmForgetPassViewController.m
//  LifeLog
//
//  Created by Panasonic R&D Center Vietnam on 8/2/17.
//  Copyright © 2017 PhongNV. All rights reserved.
//

#import "ConfirmForgetPassViewController.h"
#import "ServerAPI.h"
#import "Utilities.h"

@interface ConfirmForgetPassViewController ()
@property (nonatomic, weak) IBOutlet UITextField *tfConfirm;
@property (nonatomic, weak) IBOutlet UIButton *btnConfirm;
@end

@implementation ConfirmForgetPassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
  self.title = @"Confirm Forget Password";
  
  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.tfConfirm attribute:NSLayoutAttributeTop multiplier:1 constant:-30]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)buttonConfirmTouchUpInside:(id)sender {
    if (_tfConfirm.text.length > 0) {
        ConfirmForgetPassViewController __weak *weakSelf = self;
        [[ServerAPI server] confirmForgetPass:self.email withConfirm:self.tfConfirm.text CompletionHandler:^(NSError *error) {
            if (error == nil) {
                // back screen Login
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                });
            }
            else {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSString *message = [error.userInfo objectForKey:@"message"];
                    [Utilities showErrorMessage:message withViewController:weakSelf];
                });
            }
        }];
    }
    else {
        [Utilities showErrorMessage:@"Please input code confirm" withViewController:self];
    }
}

@end
