//
//  NvWatemarkCVCell.m
//  SDKDemo
//
//  Created by ms20180425 on 2018/10/18.
 //
//

#import "NvWatemarkCVCell.h"
#import "NVHeader.h"

@implementation NvWatemarkItem

@end

@interface NvWatemarkCVCell()

@property (nonatomic, strong) UIImageView *coverImageView;
@property (nonatomic, strong) UIImageView *selectImageView;
@property (nonatomic, strong) UIImageView *coverImageView_1;
@property (nonatomic, strong) UIImageView *coverImageView_2;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation NvWatemarkCVCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.layer.borderWidth = 1;
        self.contentView.layer.borderColor = [UIColor nv_colorWithHexRGB:@"#848788"].CGColor;
        self.coverImageView = [[UIImageView alloc]init];
        self.coverImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.coverImageView];
        [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView);
            make.left.equalTo(self.contentView);
            make.right.equalTo(self.contentView);
        }];
        
        self.coverImageView_2 = [[UIImageView alloc]init];
        self.coverImageView_2.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.coverImageView_2];
        [self.coverImageView_2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView.mas_centerX);
            make.centerY.equalTo(self.contentView.mas_centerY).offset(-10 * SCREANSCALE);
        }];
        
        self.titleLabel = [[UILabel alloc]init];
        self.titleLabel.font = [NvUtils fontWithSize:12];
        self.titleLabel.text = @"添加";
        self.titleLabel.textColor = [UIColor nv_colorWithHexRGB:@"#909293"];
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView.mas_centerX);
            make.centerY.equalTo(self.contentView.mas_centerY).offset(10 * SCREANSCALE);
        }];
        
        self.coverImageView_1 = [[UIImageView alloc]init];
        self.coverImageView_1.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.coverImageView_1];
        [self.coverImageView_1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.left.equalTo(self.contentView.mas_left).offset(5 * SCREANSCALE);
            make.right.equalTo(self.contentView.mas_right).offset(-5 * SCREANSCALE);
        }];
        
        self.selectImageView = [[UIImageView alloc]init];
        self.selectImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.selectImageView];
        self.selectImageView.backgroundColor = [UIColor nv_colorWithHexARGB:@"#994A90E2"];
        [self.selectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView);
            make.left.equalTo(self.contentView);
            make.right.equalTo(self.contentView);
        }];
    }
    return self;
}

- (void)renderCellWithItem:(NvWatemarkItem *)item {
    if ([item.coverString isEqualToString:@"NvEditWatemarButton"]) {
        self.coverImageView_2.image = [NvUtils imageWithName:item.coverString];
        self.titleLabel.hidden = NO;
        self.coverImageView_1.image = nil;
        self.coverImageView.image = nil;
    }else{
        self.titleLabel.hidden = YES;
        self.coverImageView_2.image = nil;
        if (item.isCacheImage) {
            self.coverImageView_1.image = nil;
            self.coverImageView.image = [UIImage imageWithContentsOfFile:[WATEMARK_PATH stringByAppendingPathComponent:[item.coverString stringByAppendingString:@".png"]]];
        }else{
            self.coverImageView.image = nil;
            self.coverImageView_1.image = [NvUtils imageWithName:item.coverString];
        }
    }
    
    if (item.selected) {
        self.selectImageView.hidden = NO;
    }else{
        self.selectImageView.hidden = YES;
    }
}
@end
