//
//  HomeCollectionItem2Cell.m
//  Open
//
//  Created by 雷俊博 on 2020/8/4.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "HomeCollectionItem2Cell.h"




@implementation NativeAdCustomView

#pragma mark - life

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //self.backgroundColor = [UIColor redColor];
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews
{
    [self addSubview:self.clickButton];
    
    [self.clickButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.offset(0);
    }];
}

- (void)setupWithModel:(DHCWNativeAdDataObject *)model
{
    if (model.buttonText.length) {
        [self.clickButton setTitle:model.buttonText forState:UIControlStateNormal];
    }
}


#pragma mark - lazy
- (UIButton *)clickButton
{
    if (!_clickButton) {
        _clickButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_clickButton setTitle:@"" forState:UIControlStateNormal];
        [_clickButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        _clickButton.titleLabel.font = [UIFont systemFontOfSize:13];
        _clickButton.layer.borderColor = [UIColor clearColor].CGColor;
        _clickButton.layer.borderWidth = 0.5;
        _clickButton.layer.cornerRadius = 5;
        _clickButton.layer.masksToBounds = true;
    }
    return _clickButton;
}

@end



@implementation HomeCollectionItem2Cell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.imgGif.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
    
  
    
}

#pragma mark - public

- (void)setupCellWithModel:(DHCWNativeAdDataObject *)model
                  delegate:(id<DHCWNativeAdViewDelegate>)delegate loca:(id<DHCWNativeLocaVideoAdDelegate>)localDelegate
        rootViewController:(UIViewController *)rootViewController
{
    self.adView = [[NativeAdCustomView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    [self.contentView addSubview:self.adView];
    
    [self.adView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.offset(0);
    } ];
    
    // 以下代码实现 请严谨按该顺序执行
    self.adView.delegate = delegate;

    [self.adView registerDataObject:model container:self.adView clickableViews:@[self.adView.clickButton]];
    self.adView.rootViewController = rootViewController;
    [self.adView setupWithModel:model];
    
    /**
            可选操作
     */
    self.localVideoAd = [[DHCWNativeLocalVideoAd alloc]init];
    self.localVideoAd.delegate = localDelegate;
    [self.adView configNativeLocalVideoAd:self.localVideoAd];
    
}

+ (CGFloat)cellHeightForModel:(DHCWNativeAdDataObject *)model
{
    return 100;
}


- (void)prepareForReuse
{
    [super prepareForReuse];
    [self.adView unregisterDataObject];
}




@end
