//
//  NvCaptureFilterCell.m
//  SDKDemo
//
//  Created by ms20180425 on 2018/11/29.
 //
//

#import "NvCaptureFilterCell.h"
#import "NvHeader.h"
#import "UIImageView+WebCache.h"

@interface NvCaptureFilterCell()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *maskView;
@property (nonatomic, strong) UIImageView *coverView;

@property (nonatomic, assign) CGFloat sizeFloat;
@end

@implementation NvCaptureFilterCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.sizeFloat = frame.size.width;
        self.coverView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.width)];
        self.coverView.contentMode = UIViewContentModeScaleAspectFit;
        self.coverView.layer.cornerRadius = 4 * SCREANSCALE;
        [self.contentView addSubview:self.coverView];
        
        self.maskView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.width)];
        self.maskView.contentMode = UIViewContentModeScaleAspectFit;
        self.maskView.backgroundColor = [UIColor nv_colorWithHexARGB:@"#804A90E2"];
        self.maskView.layer.masksToBounds = YES;
        self.maskView.layer.cornerRadius = 4 * SCREANSCALE;
        [self.contentView addSubview:self.maskView];
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.maskView.frame.size.height + 8 * SCREANSCALE, frame.size.width, 15 * SCREANSCALE)];
        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        self.nameLabel.textColor = UIColor.whiteColor;
        self.nameLabel.alpha = 0.8;
        self.nameLabel.font = [NvUtils regularFontWithSize:11];
        [self.contentView addSubview:self.nameLabel];
    }
    return self;
}

- (void)renderCellWithModel:(NvBaseModel *)model{
    self.coverView.frame = CGRectMake(0, 0, self.sizeFloat, self.sizeFloat);
    self.coverView.layer.masksToBounds = YES;
    if ([model.displayName isEqualToString:@"无"]) {
        self.coverView.layer.masksToBounds = NO;
        self.coverView.frame = CGRectMake((self.sizeFloat - 30 * SCREANSCALE)/2.0, (self.sizeFloat - 30 * SCREANSCALE)/2.0, 30 * SCREANSCALE, 30 * SCREANSCALE);
    }
    if ([model.coverName hasPrefix:@"http"]) {
        [self.coverView sd_setImageWithURL:[NSURL URLWithString:model.coverName]];
    } else {
        self.coverView.image = [NvUtils imageWithName:model.coverName];
    }
    self.nameLabel.text = model.displayName;
    if (model.selected) {
        self.nameLabel.textColor = [UIColor nv_colorWithHexRGB:@"#4A90E2"];
        self.maskView.hidden = NO;
    }else{
        self.nameLabel.textColor = UIColor.whiteColor;
        self.maskView.hidden = YES;
    }
}

@end
