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

#import "RechargeTopView.h"

@interface RechargeTopView ()

@property (nonatomic, strong)UIView* cardView;

@end

@implementation RechargeTopView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.frame = CGRectMake(0, 0, ScreenWidth, 100 * WIDTHRADIU);
    self.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    self.cardView.frame = CGRectMake(10 * WIDTHRADIU, 10 * WIDTHRADIU, ScreenWidth - 20 * WIDTHRADIU, 90 * WIDTHRADIU);
    [self addSubview:self.cardView];
    
    //圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.cardView.bounds
                                                         byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                               cornerRadii:CGSizeMake(8, 8)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.cardView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.cardView.layer.mask = maskLayer;
    
}

- (void)setMoneyWithMoney:(NSString *)str
{
    self.lb_money.attributedText = [self attributedStrWithFaultCode:str];
}

#pragma mark - getters
- (UIView *)cardView
{
    if (!_cardView) {
        _cardView = [[UIView alloc]init];
        _cardView.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [_cardView addSubview:self.lb_mark];
        [_cardView addSubview:self.lb_bankName];
        [_cardView addSubview:self.lb_number];
        [_cardView addSubview:self.lb_money];
        [_lb_mark mas_makeConstraints:^(MASConstraintMaker *make) {
                   make.top.offset(15);
                   make.left.offset(20);
                   make.height.offset(24);
                   make.width.offset(24);
                  
        }];
       [_lb_bankName mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerY.equalTo(self.lb_mark);
           make.left.equalTo(self.lb_mark.mas_right).offset(3);
       }];
       [_lb_number mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerY.equalTo(self.lb_mark);
           make.right.offset(-20);
       }];
        [_lb_money mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lb_mark);
            make.bottom.offset(-15);
        }];
    }
    return _cardView;
}

- (MarkLabel *)lb_mark
{
    if (!_lb_mark) {
        _lb_mark = [[MarkLabel alloc]init];
        _lb_mark.text = @"乌";
        _lb_mark.textColor = [UIColor whiteColor];
        _lb_mark.textAlignment = NSTextAlignmentCenter;
        _lb_mark.font = [UIFont boldSystemFontOfSize:17];
        _lb_mark.layer.cornerRadius = 12;
        _lb_mark.layer.borderColor = [UIColor whiteColor].CGColor;
        _lb_mark.layer.borderWidth = 0.5;
        _lb_mark.edgeInsets = UIEdgeInsetsMake(2, 2, 2, 2);//设置内边距
        [_lb_mark sizeToFit];
    }
    return _lb_mark;
}

- (UILabel *)lb_bankName
{
    if (!_lb_bankName) {
        _lb_bankName = [[UILabel alloc]init];
        _lb_bankName.text = @"乌当农商银行";
        _lb_bankName.textColor = [UIColor whiteColor];
        _lb_bankName.font = [UIFont boldSystemFontOfSize:17];
    }
    return _lb_bankName;
}

- (UILabel *)lb_number
{
    if (!_lb_number) {
        _lb_number = [[UILabel alloc]init];
        _lb_number.text = @"--";
        _lb_number.textColor = [UIColor whiteColor];
        _lb_number.font = [UIFont boldSystemFontOfSize:17];
    }
    return _lb_number;
}

- (UILabel *)lb_money
{
    if (!_lb_money) {
        _lb_money = [[UILabel alloc]init];
        _lb_money.textColor = [UIColor whiteColor];
        _lb_money.font = [UIFont systemFontOfSize:14];
        _lb_money.attributedText = [self attributedStrWithFaultCode:@"--"];
    }
    return _lb_money;
}

- (NSAttributedString *) attributedStrWithFaultCode:(NSString *)faultCode {
    NSString*text = [NSString stringWithFormat:@"余额: %@ 元",faultCode];
    
    NSMutableAttributedString * faultCode_ = [[NSMutableAttributedString alloc] initWithString:text];
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    
    NSDictionary * faultCodeAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:17],NSParagraphStyleAttributeName:paraStyle,NSForegroundColorAttributeName:[UIColor whiteColor]};
    [faultCode_ setAttributes:faultCodeAttributes range:NSMakeRange(4,faultCode.length)];
    return faultCode_;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
