//
//  NextResetPasswordViewController.m
//  ALand
//
//  Created by Z on 16/3/18.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "NextResetPasswordViewController.h"
#import "UIButton+countDown.h"
@interface NextResetPasswordViewController ()
@property (weak, nonatomic) IBOutlet UIButton *sendCode;
@property (weak, nonatomic) IBOutlet UIButton *setPasswordVisible;
@property (weak, nonatomic) IBOutlet UITextField *labelCode;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (nonatomic) BOOL isPasswordVisible;
@end

@implementation NextResetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isPasswordVisible = NO;
    self.navigationItem.title = @"重置密码";
    [self.sendCode startWithTime:60 title:@"重新发送" countDownTitle:@"秒" mainColor:nil countColor:nil mainTitleColor:[UIColor colorWithHexString:@"51B2F6"] countTitleColor:[UIColor colorWithHexString:@"888888"]];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)sendCodeAction:(UIButton *)sender {
    [self.sendCode startWithTime:60 title:@"重新发送" countDownTitle:@"秒" mainColor:nil countColor:nil mainTitleColor:[UIColor colorWithHexString:@"51B2F6"] countTitleColor:[UIColor colorWithHexString:@"888888"]];
    
}

//确定
- (IBAction)confirmAction:(UIButton *)sender {
    
    if (self.password.text.length < 6 || self.password.text.length > 12) {
        [MBProgressHUD Javen_showError:@"密码长度6~12位" onView:kWindow delay:0.5 complete:nil];
        return;
    }
    
    
    NSDictionary *params = @{@"domain" : kDomain,
                                   @"mobilephone" : self.mobilePhone,
                                   @"smsCode" : self.labelCode.text,
                                   @"password" : [self.password.text MD5String]};
    WS(weakSelf)
    if (self.labelCode.text.length > 0 || self.password.text.length > 0) {
        
        [[HTTPCilent shareCilent] POST:@"app/resellerResetPwd" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
            if (kIsResponseSuccess(responseObject)) {
                
                [[NSUserDefaults standardUserDefaults] setObject:weakSelf.mobilePhone forKey:@"userName"];
                [[NSUserDefaults standardUserDefaults] setObject:[weakSelf.password.text MD5String] forKey:@"passWord"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                
                [MBProgressHUD Javen_showSuccess:@"重置成功！" onView:weakSelf.view delay:0.5 complete:^{
                    
                    [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                }];
                
            }else{
                NSString *message = responseObject[@"message"];
                [MBProgressHUD Javen_showError:message onView:weakSelf.view delay:0.7 complete:nil];
            }

        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            
        }];
        
        
        
    }else{
        [MBProgressHUD Javen_showError:@"" onView:self.view delay:0.7 complete:nil];
    }
    
}


- (IBAction)setPasswordVisibleAction:(UIButton *)sender {
    self.isPasswordVisible = !self.isPasswordVisible;
    if (self.isPasswordVisible) {
        [self.setPasswordVisible setImage:[UIImage imageNamed:@"visible_icon"] forState:UIControlStateNormal];
        self.password.secureTextEntry = NO;
    }else{
        [self.setPasswordVisible setImage:[UIImage imageNamed:@"Invisible_icon"] forState:UIControlStateNormal];
        self.password.secureTextEntry = YES;
        
    }
}

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

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
