//
//  LoginViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "LoginViewController.h"
#import "CustomTabbarController.h"
#import "AppDelegate.h"
#import "authenticateView.h"



@interface LoginViewController ()<RightVCselectedDelegate>

@property (nonatomic,strong) MMDrawerController *drawerController;
@property (nonatomic,strong) CustomTabbarController *customtabbar;

/**
 *  验证身份View
 */
@property (nonatomic,strong) authenticateView *identityView;

/**
 *  重置密码View
 */
@property (nonatomic,strong) authenticateView *resetPasswordView;

@end

@implementation LoginViewController


- (CustomTabbarController *)customtabbar
{
    if (_customtabbar == nil) {
        
        _customtabbar = [[CustomTabbarController alloc]init];
    }
    return _customtabbar;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}


#pragma mark -登陆
- (IBAction)LoginButtonClick:(UIButton *)sender {
    
    RightViewController *rightVC = [[RightViewController alloc]init];
    rightVC.delegate = self;
    self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:self.customtabbar rightDrawerViewController:rightVC];
    [self.drawerController setMaximumRightDrawerWidth:RightWidth];
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    SHARED_APPDELEGATE.mmdrawer = self.drawerController;
    SHARED_APPDELEGATE.window.rootViewController = self.drawerController;
    
}


#pragma mark -RightVCselectedDelegate 方法
- (void)SelectedControllerWithIndex:(NSString *)Name
{
    NSInteger selectedIndex;
    if ([Name isEqualToString:@"体验中心"]) {
        
        selectedIndex = 6;
        
    }else if ([Name isEqualToString:@"场景库"])
    {
       selectedIndex = 5;
    }else if ([Name isEqualToString:@"产品库"])
    {
        selectedIndex = 4;
    }else if ([Name isEqualToString:@"客户管理"])
    {
       selectedIndex = 3;
    }else if ([Name isEqualToString:@"所有客户"])
    {
        selectedIndex = 2;
    }else if ([Name isEqualToString:@"客户订单"])
    {
        selectedIndex = 1;
    }else if ([Name isEqualToString:@"关于"])
    {
        selectedIndex = 0;
    }
    
    self.customtabbar.selectedIndex = selectedIndex;
}







#pragma mark -忘记密码
- (IBAction)ForgotpasswordButtonClick:(UIButton *)sender {
    
    
    self.identityView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]firstObject];
    [self.identityView.backLoginButton addTarget:self action:@selector(BackloginButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.identityView.nextButton addTarget:self action:@selector(NextButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.identityView.alpha = 0;
    self.identityView.frame = self.userNameLoginView.frame;
    [self.view addSubview:self.identityView];
    [UIView animateWithDuration:0.2 animations:^{
        
        self.identityView.alpha = 1;
        
    }];
    
    
}




#pragma mark -返回登陆界面
- (void)BackloginButtonClick
{
    
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.identityView.alpha = 0;
        
    }completion:^(BOOL finished) {
        
        [self.identityView removeFromSuperview];
        
    }];
}



#pragma mark -下一步（重置密码界面）
- (void)NextButtonClick
{
    self.resetPasswordView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]lastObject];
    self.resetPasswordView.frame = self.userNameLoginView.frame;
    [self.resetPasswordView.backValidationView addTarget:self action:@selector(backButonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.resetPasswordView];
    self.resetPasswordView.alpha = 0;
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.resetPasswordView.alpha = 1;
        
    }];
}


#pragma mark -返回验证信息界面
- (void)backButonClick
{
    [UIView animateWithDuration:0.2 animations:^{
        
        self.resetPasswordView.alpha = 0;
        
    } completion:^(BOOL finished) {
        
        [self.resetPasswordView removeFromSuperview];
    }];
}







- (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
