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

#import "CoinsListItemTableViewCell.h"
#import "Constants.h"
#import <Masonry.h>

#import "CoinDetailModel.h"
#import "MyWalletListModel.h"
#import "LSLDecimalNumberTool.h"

@interface CoinsListItemTableViewCell ()

@property (nonatomic, strong)UILabel *lb_itemType;

@property (nonatomic, strong)UILabel *lb_timeStamp;

@property (nonatomic, strong)UILabel *lb_addOrReduce;

@property (nonatomic, strong)UILabel *lb_topNumber;

@property (nonatomic, strong)UILabel *lb_bottomMessage;

//@property (nonatomic, strong)

@property (nonatomic, strong)UIView *lineView;

@end
@implementation CoinsListItemTableViewCell
#pragma mark - life cycle
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.lb_itemType];
        [self.contentView addSubview:self.lb_timeStamp];
        [self.contentView addSubview:self.lb_addOrReduce];
        [self.contentView addSubview:self.lineView];
        [self.contentView addSubview:self.lb_topNumber];
        [self.contentView addSubview:self.lb_bottomMessage];
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    [self.lb_itemType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(15 * WIDTHRADIU);
        make.left.offset(10 * WIDTHRADIU);
        make.height.offset(16 * WIDTHRADIU);
    }];
    [self.lb_timeStamp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_itemType.mas_bottom).offset(5 * WIDTHRADIU);
        make.left.equalTo(self.lb_itemType);
        make.height.offset(12 * WIDTHRADIU);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(10 * WIDTHRADIU);
        make.bottom.offset(0);
        make.height.offset(0.5);
    }];
    [self.lb_addOrReduce mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.offset(-10 * WIDTHRADIU);
    }];
    
    [self.lb_topNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10 * WIDTHRADIU);
        make.right.offset(-10 * WIDTHRADIU);
    }];
    
    [self.lb_bottomMessage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_topNumber.mas_bottom).offset(4 * WIDTHRADIU);
        make.right.offset(-10 * WIDTHRADIU);
    }];
    
}

#pragma mark - public methods
- (void)refreshUIWithData:(id)model
{
    if ([model isKindOfClass:[CoinDetailModel class]]) {
        
        CoinDetailModel *myModel = (CoinDetailModel *)model;
        self.lb_itemType.text = myModel.sourcestr;
        self.lb_timeStamp.text = myModel.create_time;
        if (self.type == ListVCTypeCoinsDetail) {
            if (myModel.typeInfo.integerValue == 1) {
                 self.lb_addOrReduce.text = [NSString stringWithFormat:@"-%@",myModel.socre];
                self.lb_addOrReduce.textColor = K_MainColor;
            }else if (myModel.typeInfo.integerValue == 2){
                self.lb_addOrReduce.text = [NSString stringWithFormat:@"+%@",myModel.socre];
                self.lb_addOrReduce.textColor = [UIColor colorWithHex:0xed8b0b];
            }
            
        }else if (self.type == ListVCTypeCoinsCost){
            self.lb_addOrReduce.text = [NSString stringWithFormat:@"-%@",myModel.socre];
        }
        
    }else if ([model isKindOfClass:[MyWalletListModel class]]){
        MyWalletListModel *myModel = (MyWalletListModel *)model;
               self.lb_itemType.text = myModel.titleName;
               self.lb_timeStamp.text = myModel.createTime;
        
        if (myModel.recordStatus.integerValue == 0) {
            self.lb_topNumber.hidden = YES;
            self.lb_bottomMessage.hidden = YES;
            self.lb_addOrReduce.hidden = NO;
            if (myModel.transactionType.integerValue == 1001) {
                self.lb_addOrReduce.text = [NSString stringWithFormat:@"+%@",[LSLDecimalNumberTool stringWithDecimalNumber:myModel.randomMoney.doubleValue]];
                self.lb_addOrReduce.textColor = [UIColor colorWithHex:0xed8b0b];
            }else if (myModel.transactionType.integerValue == 1002){
                self.lb_addOrReduce.text = [NSString stringWithFormat:@"-%@",[LSLDecimalNumberTool stringWithDecimalNumber:myModel.randomMoney.doubleValue]];
                self.lb_addOrReduce.textColor = K_MainColor;
            }
        }else if (myModel.recordStatus.integerValue == 1){
            self.lb_topNumber.hidden = NO;
            self.lb_bottomMessage.hidden = NO;
            self.lb_addOrReduce.hidden = YES;
            if (myModel.transactionType.integerValue == 1001) {
                self.lb_topNumber.text = [NSString stringWithFormat:@"+%@",[LSLDecimalNumberTool stringWithDecimalNumber:myModel.randomMoney.doubleValue]];
            }else if (myModel.transactionType.integerValue == 1002){
                self.lb_topNumber.text = [NSString stringWithFormat:@"-%@",[LSLDecimalNumberTool stringWithDecimalNumber:myModel.randomMoney.doubleValue]];
            }
            self.lb_bottomMessage.text = @"提现失败";
        }
        
        
    }
}

#pragma mark - getters and setters
- (UILabel *)lb_itemType
{
    if (!_lb_itemType) {
        _lb_itemType = [[UILabel alloc]init];
        _lb_itemType.text = @"阅读收益";
        _lb_itemType.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_itemType.font = [UIFont systemFontOfSize:16 * WIDTHRADIU];
    }
    return _lb_itemType;
}

- (UILabel *)lb_timeStamp
{
    if (!_lb_timeStamp) {
        _lb_timeStamp = [[UILabel alloc]init];
        _lb_timeStamp.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
        _lb_timeStamp.textColor = [UIColor colorWithHex:0x808080];
        _lb_timeStamp.text = @"2019.06.03";
    }
    return _lb_timeStamp;
}

- (UILabel *)lb_addOrReduce
{
    if (!_lb_addOrReduce) {
        _lb_addOrReduce = [[UILabel alloc]init];
        _lb_addOrReduce.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        _lb_addOrReduce.textColor = [UIColor colorWithHex:0xed8b0b];
        _lb_addOrReduce.text = @"+200";
    }
    return _lb_addOrReduce;
}

- (UILabel *)lb_topNumber
{
    if (!_lb_topNumber) {
        _lb_topNumber = [[UILabel alloc]init];
        _lb_topNumber.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        _lb_topNumber.textColor = [UIColor redColor];
        _lb_topNumber.text = @"-0.0";
        _lb_topNumber.hidden = YES;
    }
    return _lb_topNumber;
}

- (UILabel *)lb_bottomMessage
{
    if (!_lb_bottomMessage) {
        _lb_bottomMessage = [[UILabel alloc]init];
        _lb_bottomMessage.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        _lb_bottomMessage.textColor = [UIColor redColor];
        _lb_bottomMessage.text = @"提现失败";
        _lb_bottomMessage.hidden = YES;
    }
    return _lb_bottomMessage;
}


- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _lineView;
}

- (void)setType:(ListVCType)type
{
    _type = type;
    if (type == ListVCTypeMyWallet) {
        _lb_itemType.text = @"金币兑换现金";
        _lb_addOrReduce.text = @"+2.00";
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
