//
//  OrderProgressViewController.m
//  Open
//
//  Created by 雷俊博 on 2019/10/18.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "OrderProgressViewController.h"
#import "Constants.h"

#import "OrderProcessTableViewCell.h"

#import "CoinsDetailListVC.h"

@interface OrderProgressViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic, strong)UIView *footerView;

@property (nonatomic, strong)UIButton *btn_footer;

@property (nonatomic, strong)NSMutableArray *dataArray;

@end

@implementation OrderProgressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self navConfig];
    
    [self.view addSubview:self.tableView];
    
    self.dataArray = [[NSMutableArray alloc]init];
    
        for (int i = 0; i < 2; i++) {
            OrderModel *model = [[OrderModel alloc]init];
            model.date = self.dateStr;
            if (i == 0) {
                model.dsc = @"提交提现申请";
                model.textColor = [UIColor colorWithHex:0xf98505];
                model.imgName = @"提交icon";
            }else{
                if (self.success) {
                    model.dsc = @"提现成功";
                    model.textColor = [UIColor colorWithHex:0xf98505];
                    model.imgName = @"到账icon";
                }else{
                    model.dsc = @"提现失败(请确认微信账户是否已实名认证)";
                    model.textColor = [UIColor colorWithHex:0x808080];
                    model.imgName = @"未到账icon";
                }
            }
            
            
            
            [self.dataArray addObject:model];
        }
    
    [self.tableView reloadData];
   
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xf98505];
//
//    [self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//        self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xf98505];
//         [self.navigationController.navigationBar setBackgroundImage:[UIImage  imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
//    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//    }];
//
//
//    
//
//    self.navigationController.navigationBar.translucent = NO;
    
    //禁止手势返回
    id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
    [self.view addGestureRecognizer:pan];
    
    [GTCountSDK trackCountEvent:@"life_tixianSuccess" withArgs:@{}];//个推统计
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = YES;
}

- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor colorWithHex:0xf98505];
    //返回按钮
    
    
    UILabel* lb_title = [UILabel new];
    lb_title.text = self.title;
    lb_title.font = [UIFont boldSystemFontOfSize:17];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.textColor = [UIColor whiteColor];
    [navView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(cl_kStatusBarHeight);
        make.centerX.equalTo(navView);
        make.height.offset(44);
    }];
    [self.view addSubview:navView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    OrderProcessTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[OrderProcessTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    if (indexPath.row == 0) {
        cell.hasUpLine = NO;
        cell.currented = YES;
        cell.hasDownLine = YES;
    } else {
        cell.hasUpLine = YES;
       
        cell.currented = self.success;
         cell.hasDownLine = NO;
    }
    
    [cell reloadDataWithModel:self.dataArray[indexPath.row]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}


#pragma mark - event response
- (void)goToBackvc
{
    
    if (self.success) {
        NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
        
        
        UIViewController *vc = viewControllers[1];
        if ([vc isKindOfClass:[CoinsDetailListVC class]]) {
            [self.navigationController popToViewController:vc animated:YES];
        }else{
             [self.navigationController popViewControllerAnimated:YES];
        }
        
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

#pragma mark - getters and setters
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight) style:UITableViewStyleGrouped];
        _tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = self.footerView;
    }
    return _tableView;
}

- (UIButton *)btn_footer
{
    if (!_btn_footer) {
        _btn_footer = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_footer.frame = CGRectMake(10, 45, ScreenWidth - 20, 45);
        _btn_footer.backgroundColor = [UIColor colorWithHex:0xf98505];
        _btn_footer.layer.cornerRadius = 5;
        [_btn_footer setTitle:@"完成" forState:UIControlStateNormal];
        [_btn_footer setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_footer.titleLabel.font = [UIFont systemFontOfSize:15];
        [_btn_footer addTarget:self action:@selector(goToBackvc) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _btn_footer;
}

- (UIView *)footerView
{
    if (!_footerView) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 135)];
        _footerView.backgroundColor = [UIColor clearColor];
        [_footerView addSubview:self.btn_footer];
    }
    return _footerView;
}

/*
#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
