//
//  HomeNewAuthResultCell.m
//  Open
//
//  Created by 雷俊博 on 2021/4/13.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "HomeNewAuthResultCell.h"

@implementation HomeNewAuthResultCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.lb_content.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15];
    YYLabel  *msgLabel = [YYLabel new];
    msgLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15];
    msgLabel.textColor = [UIColor colorWithHex:0x4d4d4d];
    
    [self.contentView addSubview:msgLabel];
    
    self.lb_msg = msgLabel;
    
    [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(78);
        make.right.offset(-45);
        make.centerY.equalTo(self.msgView);
    }];
    
}

- (void)reloadDataWithModel:(KKNewMsgResultInfoModel *)model count:(NSInteger)count
{

//    if ([model.match_state isEqualToString:@"0"]) {
//        self.lb_content.text = [NSString stringWithFormat:@"%@ 认证成功",[EnercryTool desA:model.personName]];
//    }else if ([model.match_state isEqualToString:@"1"]){
//        self.lb_content.text = [NSString stringWithFormat:@"%@ 认证中",[EnercryTool desA:model.personName]];
//    }else if ([model.match_state isEqualToString:@"2"]){
//        self.lb_content.text = [NSString stringWithFormat:@"%@ 认证失败",[EnercryTool desA:model.personName]];
//    }else{
//        self.lb_content.text = [NSString stringWithFormat:@"%@ 人工审核中",[EnercryTool desA:model.personName]];
//    }
//
//    self.lb_time.text = [self compareCurrentTime:model.createTime];
    
    
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:15], NSForegroundColorAttributeName: [UIColor colorWithHex:0x4d4d4d]};
       
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:model.title attributes:attributes];
    
    
    self.lb_content.attributedText = text;
    
    self.lb_time.text = [self compareCurrentTime:model.noticeTime];
    
    self.redView.hidden = count == 0;
    
    if ([model.noticeType isEqualToString:@"1002"]) {
        
        NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:@"您有认证通知待查看" attributes:attributes];
        
        self.lb_msg.attributedText = text2;
    }else{
        NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:@"您有新的通知消息待查看" attributes:attributes];
        
        self.lb_msg.attributedText = text2;
    }
    
}


- (NSString *)compareCurrentTime:(NSString *)str
{
    
    //把字符串转为NSdate
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *timeDate = [dateFormatter dateFromString:str];
    
    //得到与当前时间差
    NSTimeInterval  timeInterval = [timeDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    timeInterval = timeInterval ;
    long temp = 0;
    NSString *result;
    if (timeInterval < 60 * 5) {
        result = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) < 60){
        result = [NSString stringWithFormat:@"%ld分钟前",temp];
    }
    
    else if((temp = temp/60) < 24){
        result = [NSString stringWithFormat:@"%ld小时前",temp];
    }
    
    else {
        result = @"";
    }
    
   
    
    return  result;
}




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

    // Configure the view for the selected state
}

@end
