//
//  HomeService2TableViewCell.m
//  Open
//
//  Created by 雷俊博 on 2021/2/26.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "HomeService2TableViewCell.h"

@interface HomeService2TableViewCell ()

@property (nonatomic, strong)UIView* titleView;

@property (nonatomic, strong)UIView* view1;

@property (nonatomic, strong)UIView* lb_line1;

@end

@implementation HomeService2TableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //添加view
        [self.contentView addSubview:self.titleView];
        [self.titleView addSubview:self.lb_title];
        [self.contentView addSubview:self.view1];
        
        [self.view1 addSubview:self.imageView1];
        [self.view1 addSubview:self.imageView2];
        [self.view1 addSubview:self.lb_line1];
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    //布局
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(50 * WIDTHRADIU);
    }];
    
    [self.lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleView);
        make.left.offset(10 * WIDTHRADIU);
    }];
    //添加阴影
    [self addShadowToView:self.view1 withColor:[UIColor colorWithHex:0x6c6c6c]];
    
    [self.imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.width.offset((ScreenWidth - 20 * WIDTHRADIU)/2.0);
    }];
    [self.imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.right.offset(0);
        make.width.offset((ScreenWidth - 20 * WIDTHRADIU)/2.0);
    }];
    
    [self.lb_line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view1).offset(5);;
        make.width.offset(1);
        make.top.offset(10);
        make.bottom.offset(-10);
    }];
    
    
    UITapGestureRecognizer * tag1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
    UITapGestureRecognizer * tag2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
    [self.imageView1 addGestureRecognizer:tag1];
    [self.imageView2 addGestureRecognizer:tag2];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

#pragma mark - event response
-(void)onClick:(UITapGestureRecognizer *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(cell2:didSelectImage:)]) {
        [self.delegate cell2:self didSelectImage:(UIImageView *)sender.view];
    }
}


#pragma mark - 添加阴影
/// 添加四边阴影效果
- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
    // 阴影颜色
    theView.layer.shadowColor = theColor.CGColor;
    // 阴影偏移，默认(0, -3)
    theView.layer.shadowOffset = CGSizeMake(0,0);
    // 阴影透明度，默认0
    theView.layer.shadowOpacity = 0.25;
    // 阴影半径，默认3
    theView.layer.shadowRadius = 3;
}



#pragma mark - getters and setters
- (UIView *)titleView {
    
    if (!_titleView) {
        _titleView = [[UIView alloc]init];
    }
    return _titleView;
}

- (UILabel *)lb_title {
    
    if (!_lb_title) {
        _lb_title = [[UILabel alloc]init];
        _lb_title.font = [UIFont boldSystemFontOfSize:20 * WIDTHRADIU];
        _lb_title.textColor = [UIColor colorWithHex:0x4d4d4d];
    }
    return _lb_title;
}

- (UIView *)view1 {
    if (!_view1) {
        _view1 = [[UIView alloc]initWithFrame:CGRectMake(10 * WIDTHRADIU, 50 * WIDTHRADIU, ScreenWidth - 20 * WIDTHRADIU, 90* WIDTHRADIU)];
        _view1.backgroundColor = [UIColor whiteColor];
        _view1.layer.cornerRadius = 5;
    }
    return _view1;
}

- (UIImageView *)imageView1
{
    if (!_imageView1) {
        _imageView1 = [[UIImageView alloc]init];
        _imageView1.userInteractionEnabled = YES;
    }
    return _imageView1;
}

- (UIImageView *)imageView2
{
    if (!_imageView2) {
        _imageView2 = [[UIImageView alloc]init];
        _imageView2.userInteractionEnabled = YES;
    }
    return _imageView2;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
