//
//  RechargeProcessingController.m
//  Open
//
//  Created by 雷俊博 on 2020/8/10.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "RechargeProcessingController.h"
#import "UIView+frameAdjust.h"
#import "WithdrawalProcessing.h"

@interface RechargeProcessingController ()

@property (nonatomic, strong)UIView* topView;

@property (nonatomic, strong)UIView* cardView;

@end

@implementation RechargeProcessingController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.topView];
    
    [self.view addSubview:self.cardView];
}

#pragma mark - event response
- (void)closeBtnClick:(UIButton *)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark - public methods
-(id)getXiblWithClassName:(NSString *)className
{
    return [[NSBundle mainBundle]loadNibNamed:className owner:self options:nil].lastObject;
}

#pragma mark - getters
- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 223 * WIDTHRADIU + cl_kStatusBarHeight)];
        //顶部背景色
        UIView* bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 148* WIDTHRADIU + cl_kStatusBarHeight)];
        bgView.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [_topView addSubview:bgView];
        
        //底部圆弧
        UIImageView*bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, bgView.maxY, ScreenWidth, 55 * WIDTHRADIU)];
        bgImageView.image = [UIImage imageNamed:@"savesuccess_bg"];
        [_topView addSubview:bgImageView];
        
        
        //完成按钮
        UIButton* closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [closeBtn setTitle:@"完成" forState:UIControlStateNormal];
        [closeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        closeBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_topView addSubview:closeBtn];
        [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(cl_kStatusBarHeight);
            make.right.offset(0);
            make.width.offset(60);
            make.height.offset(44);
        }];
        
        //成功图标
        UIImageView* successImg = [[UIImageView alloc]init];
        successImg.image = [UIImage imageNamed:@"buySuccess"];
        [_topView addSubview:successImg];
        [successImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_topView);
            make.top.offset(cl_kStatusBarHeight + 20 * WIDTHRADIU);
            make.width.height.offset(75 * WIDTHRADIU);
        }];
        //购买成功
        UILabel*lb_success = [[UILabel alloc]init];
        lb_success.text = @"提现处理中";
        lb_success.textColor = [UIColor whiteColor];
        lb_success.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
        lb_success.textAlignment = NSTextAlignmentCenter;
        [_topView addSubview:lb_success];
        [lb_success mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_topView);
            make.top.equalTo(successImg.mas_bottom).offset(10 * WIDTHRADIU);
        }];
    }
    return _topView;
}

- (UIView *)cardView
{
    if (!_cardView) {
        _cardView = [[UIView alloc]initWithFrame:CGRectMake(10 * WIDTHRADIU, self.topView.maxY - 50 * WIDTHRADIU, ScreenWidth - 20 * WIDTHRADIU, ScreenHeight - (self.topView.maxY - 50 * WIDTHRADIU))];
        _cardView.backgroundColor = [UIColor whiteColor];
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_cardView.bounds
                                                                    byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                                          cornerRadii:CGSizeMake(12, 12)];
       CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
       maskLayer.frame = _cardView.bounds;
       maskLayer.path = maskPath.CGPath;
       _cardView.layer.mask = maskLayer;
        
       WithdrawalProcessing*infoView = [self getXiblWithClassName:@"WithdrawalProcessing"];

       [_cardView addSubview:infoView];
        [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.offset(0);
            make.height.mas_greaterThanOrEqualTo(50);
        }];
        
        
        
    }
    return _cardView;
}

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