//
//  NvTransitionCollectionViewCell.m
//  SDKDemo
//
//  Created by 刘东旭 on 2018/6/29.
 //
//

#import "NvTransitionCollectionViewCell.h"
#import "NVHeader.h"
#import "UIImageView+WebCache.h"

@interface NvTransitionCollectionViewCell()

@property (nonatomic, strong) UIImageView *noneImageView;
@property (nonatomic, strong) UIImageView *imageView;//图片外层
@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UIImageView *imageViewContent;//图片内层
@end

@implementation NvTransitionCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor nv_colorWithHexRGB:@"#242728"];
        self.imageView = [UIImageView new];
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
        self.imageViewContent = [UIImageView new];
        self.imageViewContent.contentMode = UIViewContentModeScaleAspectFit;
        self.noneImageView = [UIImageView new];
        self.noneImageView.contentMode = UIViewContentModeScaleAspectFit;
        self.imageView.layer.borderColor = [UIColor nv_colorWithHexRGB:@"#4D4F51"].CGColor;
        self.imageView.layer.borderWidth = 2;
        self.nameLabel = [UILabel nv_labelWithText:@"无" fontSize:15 textColor:[UIColor nv_colorWithHexARGB:@"#CCFFFFFF"]];
        self.nameLabel.font = [NvUtils regularFontWithSize:12];
        [self.contentView addSubview:self.imageView];
        [self.contentView addSubview:self.noneImageView];
        [self.contentView addSubview:self.nameLabel];
        [self.imageView addSubview:self.imageViewContent];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(@2);
            make.height.equalTo(@(48*SCREANSCALE));
        }];
        [self.imageViewContent mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.imageView.mas_centerX);
            make.centerY.equalTo(self.imageView.mas_centerY);
            make.width.equalTo(self.imageView.mas_width);
            make.height.offset(35 * SCREANSCALE);
        }];
        
        [self.noneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(@(12*SCREANSCALE));
            make.right.equalTo(@(-12*SCREANSCALE));
            make.height.equalTo(@(25*SCREANSCALE));
        }];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.imageView.mas_bottom).offset(8*SCREANSCALE);
            make.centerX.equalTo(self.imageView);
            make.left.equalTo(self.imageView.mas_left);
            make.right.equalTo(self.imageView.mas_right);
        }];
    }
    return self;
}

- (void)renderCellWithClipItem:(NvTransitionItem *)item {
    if (item.isSelect) {
        self.imageView.layer.borderColor = [UIColor nv_colorWithHexRGB:@"#4A90E2"].CGColor;
        self.imageView.layer.borderWidth = 2;
        self.imageView.layer.cornerRadius = 2;
        self.imageView.layer.masksToBounds = YES;
        self.nameLabel.textColor = [UIColor nv_colorWithHexRGB:@"#4A90E2"];
    } else {
        self.imageView.layer.borderColor = [UIColor nv_colorWithHexRGB:@"#4D4F51"].CGColor;
        self.imageView.layer.borderWidth = 2;
        self.imageView.layer.cornerRadius = 2;
        self.imageView.layer.masksToBounds = YES;
        self.nameLabel.textColor = [UIColor nv_colorWithHexARGB:@"#CCFFFFFF"];
    }
    if ([item.imageUrl containsString:@"http"]) {
        [self.imageViewContent sd_setImageWithURL:[NSURL URLWithString:item.imageUrl]];
        self.imageView.hidden = NO;
        self.imageViewContent.hidden = NO;
        self.noneImageView.hidden = YES;
    } else {
        if ([item.imageUrl isEqualToString:@"NvsFilterNone"]) {
            self.imageView.image = [UIImage new];
            self.imageView.hidden = NO;
            self.imageViewContent.image = [UIImage new];
            self.imageViewContent.hidden = NO;
            self.noneImageView.hidden = NO;
        }else{
            self.imageViewContent.image = [UIImage imageNamed:item.imageUrl];
            self.noneImageView.hidden = YES;
        }
        self.noneImageView.image = [NvUtils imageWithName:item.imageUrl];
    }
    self.nameLabel.text = item.name;
}

@end
