//
//  StickerCollectionViewCell.m
//  Caption
//
//  Created by  on 2017/8/23.
//  Copyright © 2017年 NewAuto video team. All rights reserved.
//

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

@interface NvAssetCollectionViewCell () {
    UIImageView *_coverImage;
    NvAssetCellModel *_item;
    UIView *_maskView;
    UIImageView *_playImageView;
}

@end

@implementation NvAssetCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(10 * SCREANSCALE, 10 * SCREANSCALE, frame.size.width - 20* SCREANSCALE, frame.size.height - 20* SCREANSCALE)];
        _coverImage.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_coverImage];
        
        _maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _maskView.layer.borderWidth = 2;
        _maskView.layer.borderColor = [UIColor nv_colorWithHexRGB:@"#4A90E2"].CGColor;
        _maskView.backgroundColor = [UIColor nv_colorWithHexARGB:@"#334A90E2"];;
        _maskView.layer.cornerRadius = 5 * SCREANSCALE;
        [self addSubview:_maskView];
        
        _playImageView = UIImageView.new;
        _playImageView.contentMode = UIViewContentModeScaleAspectFit;
        [_maskView addSubview:_playImageView];
        [_playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_maskView.mas_centerX);
            make.centerY.equalTo(self->_maskView.mas_centerY);
            make.width.height.equalTo(@(13*SCREANSCALE));
        }];
        
    }
    return self;
}

- (void)renderCellWithItem:(NvAssetCellModel *)item {
    if (item.isPlay) {
        _playImageView.image = [NvUtils imageWithName:@"NvPause"];
    }else{
        _playImageView.image = [NvUtils imageWithName:@"NvPlayback"];
    }
    
    _item = item;
    if (item.package) {
        if ([item.cover hasPrefix:@"http"]) {
            [_coverImage sd_setImageWithURL:[NSURL URLWithString:item.cover]];
        }else{
            _coverImage.image = [NvUtils imageWithName:item.cover];
        }
        
    } else {
        _coverImage.image = [NvUtils imageWithName:item.cover];
    }
    
    if (item.selected) {
        _playImageView.hidden = NO;
        _maskView.hidden = NO;
    } else {
        _playImageView.hidden = YES;
        _maskView.hidden = YES;
    }
}

@end
