//
//  CoinsDetailHeaderView.m
//  Open
//
//  Created by 雷俊博 on 2019/7/7.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "CoinsDetailHeaderView.h"
#import "Constants.h"
#import "LSLDecimalNumberTool.h"

@interface CoinsDetailHeaderView ()

@property (nonatomic, strong)UIView *backView;

@property (nonatomic, strong)UILabel *lb_coinsNum;

@property (nonatomic, strong)UILabel *lb_coinsNumTitle;

@property (nonatomic, strong)UIButton *btn_award;

@property (nonatomic, strong)UIView* orangeView;

@property (nonatomic, strong)UILabel *lb_message;





@end
@implementation CoinsDetailHeaderView
#pragma mark - life cycle
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = RGBCOLOR(244, 244, 244);
        [self addSubview:self.backView];
        [self addSubview:self.lb_coinsNum];
        [self addSubview:self.lb_coinsNumTitle];
        
        NSDictionary *dic = [getPeopleID totalCoins];
        
        NSNumber *amountMoney = dic[@"amountMoney"];
        
        if (amountMoney.doubleValue > 0) {
            [self addSubview:self.orangeView];
        }
        
        
        [self addSubview:self.btn_award];
       
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    
    NSDictionary *dic = [getPeopleID totalCoins];
    
    NSNumber *amountMoney = dic[@"amountMoney"];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.offset(amountMoney.doubleValue > 0 ? 125 * WIDTHRADIU : 95 * WIDTHRADIU);
    }];
    [self.lb_coinsNum mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.offset(25 * WIDTHRADIU);
        make.centerX.equalTo(self);
        make.height.offset(25 * WIDTHRADIU);
    }];
    [self.lb_coinsNumTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_coinsNum.mas_bottom).offset(10 * WIDTHRADIU);
        make.centerX.equalTo(self);
        make.height.offset(13 * WIDTHRADIU);
    }];
    
   
    
    if (amountMoney.doubleValue > 0) {
        [self.orangeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.lb_coinsNumTitle.mas_bottom).offset(15);
            make.centerX.equalTo(self.lb_coinsNumTitle);
            make.width.offset(170);
            make.height.offset(25);
        }];
    }
    
    
    
    
    [self.btn_award mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.offset(-20 * WIDTHRADIU);
        make.height.offset(28 * WIDTHRADIU);
        make.width.offset(80);
    }];
   
    
    
}


#pragma mark - event response
- (void)btnClick:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickBtn)]) {
        [self.delegate clickBtn];
    }
}





#pragma mark - public methods
- (void)refreshData
{
//    _lb_allCoinsNumber.text = [NSString stringWithFormat:@"%@",[dic[@"totalScore"] stringValue]];
//    _lb_todayCoinsNumber.text = [NSString stringWithFormat:@"%@",[dic[@"todaySore"] stringValue]];
//    NSString *str = [NSString stringWithFormat:@"约%@元",dic[@"caculationMoney"] ];
    if (self.type == ListVCTypeMyWallet) {
        NSDictionary *dic = [getPeopleID totalCoins];
        
        NSNumber *currentotalProfit = dic[@"currenttotalMoney"];
        
        NSNumber *amountMoney = dic[@"amountMoney"];
               
        
        self.lb_coinsNum.text = [getPeopleID totalCoins] ? [LSLDecimalNumberTool stringWithDecimalNumber:currentotalProfit.doubleValue] : @"0";
        
        if (amountMoney.doubleValue > 0) {
            self.lb_message.text = [NSString stringWithFormat:@"别急，%@元奖励还在路上",[LSLDecimalNumberTool stringWithDecimalNumber:amountMoney.doubleValue]];
        }else{
            
        }
        
        
    }else if (self.type == ListVCTypeCoinsDetail){
        NSDictionary *dic = [getPeopleID totalCoins];
        self.lb_coinsNum.text = [getPeopleID totalCoins] ? [dic[@"totalScore"] stringValue] : @"0";
    }else if (self.type == ListVCTypeTodayProfit){
        NSDictionary *dic = [getPeopleID totalCoins];
        NSString *currentDayProfit = [NSString stringWithFormat:@"%@",dic[@"currentDayProfit"]];
        self.lb_coinsNum.text = currentDayProfit ? currentDayProfit : @"0";
    }
   
    
}

#pragma mark - setters and getters
- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = [UIColor colorWithHex:0xf98505];
    }
    return _backView;
}
- (UILabel *)lb_coinsNum
{
    if (!_lb_coinsNum) {
        _lb_coinsNum = [[UILabel alloc]init];
        _lb_coinsNum.text = @"10240";
        _lb_coinsNum.textColor = [UIColor whiteColor];
        _lb_coinsNum.font = [UIFont systemFontOfSize:35 * WIDTHRADIU];
        _lb_coinsNum.textAlignment = NSTextAlignmentCenter;
    }
    return _lb_coinsNum;
}

- (UILabel *)lb_coinsNumTitle
{
    if (!_lb_coinsNumTitle) {
        _lb_coinsNumTitle = [[UILabel alloc]init];
        _lb_coinsNumTitle.text = @"可用金币(个)";
        _lb_coinsNumTitle.textColor = [UIColor whiteColor];
        _lb_coinsNumTitle.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        _lb_coinsNumTitle.textAlignment = NSTextAlignmentCenter;
    }
    return _lb_coinsNumTitle;
}

- (UIView *)orangeView
{
    if (!_orangeView) {
        _orangeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 170, 25)];
        _orangeView.backgroundColor = RGBCOLOR(250, 143, 49);
        _orangeView.layer.cornerRadius = 12.5;
        
        UILabel*lb_message = [UILabel new];
        
        lb_message.textColor = [UIColor whiteColor];
        lb_message.font = [UIFont systemFontOfSize:12];
        lb_message.textAlignment = NSTextAlignmentCenter;
        [_orangeView addSubview:lb_message];
        self.lb_message = lb_message;
        [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self->_orangeView);
        }];
    }
    return _orangeView;
}

- (UIButton *)btn_award
{
    if (!_btn_award) {
        _btn_award = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_award setTitle:@"去赚钱" forState:UIControlStateNormal];
        [_btn_award setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_btn_award setImage:[UIImage imageNamed:@"nextArrow"] forState:UIControlStateNormal];
        _btn_award.titleLabel.font = [UIFont systemFontOfSize:15];
        [_btn_award layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:4];
        _btn_award.backgroundColor = [UIColor colorWithHex:0xf45610];
        _btn_award.layer.cornerRadius = 14 * WIDTHRADIU;
        [_btn_award addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_award;
}


- (void)setType:(ListVCType)type
{
    _type = type;
    if (type == ListVCTypeMyWallet) {
        self.lb_coinsNum.text = @"1.50";
        self.lb_coinsNumTitle.text = @"总金额(元)";
        [self.btn_award setTitle:@"去赚钱" forState:UIControlStateNormal];
    }else if (type == ListVCTypeCoinsDetail){
        [_btn_award setTitle:@"去抽奖" forState:UIControlStateNormal];
    }else if (type == ListVCTypeTodayProfit){
        self.lb_coinsNum.text = @"0.0";
        self.lb_coinsNumTitle.text = @"今日收益(元)";
        [self.btn_award setTitle:@"去抽奖" forState:UIControlStateNormal];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
