//
//  NvFontColloCollectionViewCell.m
//  SDKDemo
//
//  Created by Meicam on 2018/6/7.
//  Copyright © 2018年 刘东旭. All rights reserved.
//

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

@interface NvFontCollectionViewCell()

@property (nonatomic, strong) UIImageView *view;
@property (nonatomic, strong) UIImageView *noneImageView;

@end

@implementation NvFontCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor nv_colorWithHexRGB:@"#242728"];
        self.view = [UIImageView new];
        self.view.contentMode = UIViewContentModeScaleAspectFit;
        self.noneImageView = [UIImageView new];
        self.noneImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self.contentView addSubview:self.view];
        [self.contentView addSubview:self.noneImageView];
        [self.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(@0);
        }];
        
        [self.noneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@(12*SCREANSCALE));
            make.left.equalTo(@(26*SCREANSCALE));
            make.right.equalTo(@(-26*SCREANSCALE));
            make.height.equalTo(@(25*SCREANSCALE));
        }];
    }
    return self;
}

- (void)renderCellWithItem:(NvCaptionFontItem *)item {
    if ([item.imageUrl containsString:@"http"]) {
        [self.view sd_setImageWithURL:[NSURL URLWithString:item.imageUrl]];
        self.noneImageView.hidden = YES;
        self.view.hidden = NO;
    } else {
        if ([item.imageUrl isEqualToString:@"NvsFilterNone"]) {
            self.noneImageView.hidden = NO;
            self.view.image = [UIImage new];
        } else {
            self.noneImageView.hidden = YES;
            self.view.image = [NvUtils imageWithName:item.imageUrl];
        }
        
        self.noneImageView.image = [NvUtils imageWithName:item.imageUrl];
    }
    if (item.isSelect) {
        self.view.layer.borderWidth = 2;
        self.view.layer.borderColor = [UIColor nv_colorWithHexRGB:@"#4A90E2"].CGColor;
        self.view.layer.cornerRadius = 4;
        self.view.layer.masksToBounds = YES;
    } else {
        self.view.layer.borderWidth = 0;
        self.view.layer.borderColor = [UIColor clearColor].CGColor;
        self.view.layer.cornerRadius = 0;
        self.view.layer.masksToBounds = YES;
    }
}

@end
