//
//  HeathMedicalBtnTableViewCell.m
//  Open
//
//  Created by 雷俊博 on 2021/7/21.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "HeathMedicalBtnTableViewCell.h"
#import "ZWCollectionViewCell.h"


@interface HeathMedicalBtnTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong)UICollectionView*collectionView;

@property (nonatomic, strong)NSArray* bgArray;


@property (nonatomic, strong)NSArray* titleArray;

@end

@implementation HeathMedicalBtnTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    
    //UICollectionView
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    //布局
    layout.minimumLineSpacing = 0.0;
    layout.minimumInteritemSpacing = 0.0;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
           
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 108 * WIDTHRADIU) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.scrollEnabled = NO;
   
    // _collectionView.backgroundColor = K_GrayColor;
   
    _collectionView.backgroundColor = [UIColor whiteColor];
    
   
    //cell注册
    [_collectionView registerNib:[UINib nibWithNibName:@"ZWCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
    
    [self.contentView addSubview:_collectionView];
    
}


- (void)reloadData
{
    [self.collectionView reloadData];
}


#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.titleArray.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    
    ZWCollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.lb_title.text = self.titleArray[indexPath.item];
    cell.icon.image = [UIImage imageNamed:self.bgArray[indexPath.item]];
    
    cell.lb_title.textColor = [UIColor colorWithHex:0x404040];
    
    cell.backgroundColor = [UIColor whiteColor];
    
    
    
    if (indexPath.item == 2) {
        cell.gifImg.hidden = NO;
        
        
        
    }else{
        cell.gifImg.hidden = YES;
    }
    
    cell.gifImg.image = [JobUtil changeImageToGit:@"superYouhui.gif"];
    
    
    return cell;
}

/**
 cell的大小
 */
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
//    if (indexPath.section == 0) {
//        return CGSizeMake(ScreenWidth, 150 * WIDTHRADIU);
//    }
    
    CGFloat width = (ScreenWidth - 20 * WIDTHRADIU - 3.0)/4;
    CGFloat realWidth = (ScreenWidth - 20 * WIDTHRADIU - 3.0)  - 3 * width - 1;
    
    if (indexPath.row %4 != 3) {
        return CGSizeMake(width, 96 * WIDTHRADIU  );
    }
    
    return CGSizeMake(realWidth, 96 * WIDTHRADIU);
    
}

/**
 每个分区的内边距（上左下右）
 */
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
//    if (section == 0) {
//       return  UIEdgeInsetsZero;
//    }
    
    return UIEdgeInsetsMake(6 * WIDTHRADIU, 10 * WIDTHRADIU, 6 * WIDTHRADIU, 10 * WIDTHRADIU);
}


/**
 分区内cell之间的最小行间距
 */
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    
    return 0.0;
}
/**
 分区内cell之间的最小列间距
 */
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 1.0;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(HeathMedicalBtnClickWithIndex:)]) {
        [self.delegate HeathMedicalBtnClickWithIndex:indexPath.item];
    }
}


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


- (NSArray *)bgArray
{
    if (!_bgArray) {
//        _bgArray = @[@"hm_jsyz",@"hm_yygh",@"hm_pmyf",@"hm_smartDoctor",@"hm_jrtj",@"hm_jjbb",@"hm_etzq",@"hm_ylqx"];
        _bgArray = @[@"hm_jsyz",@"hm_yygh",@"hm_pmyf",@"hm_smartDoctor"];
        
    }
    return _bgArray;
}


- (NSArray *)titleArray
{
    if (!_titleArray) {
        
//        _titleArray = @[@"专家义诊",@"医院挂号",@"平价药房",@"智能问诊",@"今日特价",@"居家必备",@"儿童专区",@"医疗器械"];
        _titleArray = @[@"专家义诊",@"医院挂号",@"平价药房",@"智能问诊"];
        
    }
    return _titleArray;
}


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

    // Configure the view for the selected state
}

@end
