//
//  SignInCollectionViewCell.m
//  Open
//
//  Created by 雷俊博 on 2019/8/6.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "SignInCollectionViewCell.h"

#import "Constants.h"
#import <JDFTooltipView.h>

@interface SignInCollectionViewCell ()



@property (nonatomic, strong)UILabel *lb_num;

@property (nonatomic, strong)UILabel *lb_date;

@property (nonatomic, assign)NSInteger currentIndex;

@property (nonatomic, strong)JDFTooltipView *tipView;



@end

@implementation SignInCollectionViewCell
#pragma mark - life cycle
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.img_back];
        [self addSubview:self.lb_num];
        [self addSubview:self.lb_date];
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    [self.img_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.centerX.equalTo(self);
        make.width.height.offset(33 * WIDTHRADIU);
    }];
    
    [self.lb_num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.img_back);
    }];
    
    [self.lb_date mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.img_back.mas_bottom).offset(5 * WIDTHRADIU);
        make.centerX.equalTo(self.img_back);
        make.height.offset(11 * WIDTHRADIU);
    }];
    
}

#pragma mark - public methods
- (void)refreshUIWithData:(NSDictionary *)dic index:(NSInteger)index currentIndex:(NSInteger)currentIndex view:(UIView *)superView
{
    
    self.currentIndex = currentIndex;
    
    if (index == 2) {
        self.type = ListCoinsPackageTypeRedPacket;
        
    }else if (index == 4){
        self.type = ListCoinsPackageTypeGiftBag;
        
    }else if (index == 6){
        self.type = ListCoinsPackageTypeTreasureBox;
    }else{
        self.type = ListCoinsPackageTypeNumber;
    }
    
    
    
    NSString *status = [NSString stringWithFormat:@"%@",dic[@"status"]];
    
    if ([status isEqualToString:@"302"]) {
        self.state = ListCoinsPackageStateSigned;
    }else if ([status isEqualToString:@"301"]) {
        self.state = ListCoinsPackageStateNoSigned;
    }else if ([status isEqualToString:@"303"]) {
        self.state = ListCoinsPackageStateToSign;
    }
    
    if (currentIndex > 0 && (index == (currentIndex - 1)) && self.state == ListCoinsPackageStateNoSigned) {
        self.state = ListCoinsPackageStateBuQian;
    }
    
    
    switch (self.state) {
        case ListCoinsPackageStateToSign:
        {
            switch (self.type) {
                case ListCoinsPackageTypeRedPacket:
                {
                    self.img_back.image = [UIImage imageNamed:@"my_gold_Checkin_ Wednesday_normal"];
                    self.lb_num.hidden = YES;
                }
                    break;
                case ListCoinsPackageTypeGiftBag:
                {
                    self.img_back.image = [UIImage imageNamed:@"my_gold_Checkin_Friday_normal"];
                    self.lb_num.hidden = YES;
                }
                    break;
                case ListCoinsPackageTypeTreasureBox:
                {
                    self.img_back.image = [UIImage imageNamed:@"my_gold_Checkin_Sunday_normal"];
                    self.lb_num.hidden = YES;
                }
                    break;
                case ListCoinsPackageTypeNumber:
                {
                    self.img_back.image = [UIImage imageNamed:@"my_gold_Checkin_bg_normal"];
                    self.lb_num.hidden = NO;
                }
                    break;
                    
                default:
                    break;
            }
        }
            
            break;
        case ListCoinsPackageStateNoSigned:
        {
            self.img_back.image = [UIImage imageNamed:@"my_gold_Checkin_bg_Signed_normal"];
            self.lb_num.hidden = NO;
        }
            break;
        case ListCoinsPackageStateSigned:
        {
            self.img_back.image = [UIImage imageNamed:@"coins-signSuccess"];
            self.lb_num.hidden = YES;
        }
            break;
        case ListCoinsPackageStateBuQian:
        {
            self.img_back.image = [UIImage imageNamed:@"my_gold_Checkin_bg_buqian"];
            self.lb_num.hidden = YES;
        }
            break;
            
        default:
            break;
    }
    
    
    
    self.lb_num.text = [NSString stringWithFormat:@"%@",dic[@"sourceScore"]];
    NSString* describ = [NSString stringWithFormat:@"%@",dic[@"desc"]];
    if ([describ isEqualToString:@"待签到"]) {
        self.lb_date.text = @"待打卡";
    }else if ([describ isEqualToString:@"已签到"]){
        self.lb_date.text = @"已打卡";
    }else if ([describ isEqualToString:@"未签到"]){
        self.lb_date.text = @"未打卡";
    } else{
        self.lb_date.text = dic[@"desc"];
    }
    
    
        
}

#pragma mark - getters and setters
- (void)setType:(ListCoinsPackageType)type
{
    _type = type;
}

- (void)setState:(ListCoinsPackageState)state
{
    _state= state;
}

- (UIImageView *)img_back
{
    if (!_img_back) {
        _img_back = [[UIImageView alloc]init];
        _img_back.image = [UIImage imageNamed:@"my_gold_Checkin_bg_normal"];
    }
    return _img_back;
}

- (UILabel *)lb_num
{
    if (!_lb_num) {
        _lb_num = [[UILabel alloc]init];
        _lb_num.text = @"20";
        _lb_num.textColor = [UIColor whiteColor];
        _lb_num.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
    }
    return _lb_num;
}

- (UILabel *)lb_date
{
    if (!_lb_date) {
        _lb_date = [[UILabel alloc]init];
        _lb_date.text = @"周一";
        _lb_date.textColor = [UIColor colorWithHex:0x808080];
        _lb_date.font = [UIFont systemFontOfSize:11 * WIDTHRADIU];
    }
    return _lb_date;
}

@end
