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

#import "LogLeftCell.h"
#import "LogLeftViewCell.h"

@interface LogLeftCell ()<UICollectionViewDelegate,UICollectionViewDataSource>


@property (nonatomic, strong)NSArray  *arrayBtns;
@property (nonatomic, strong)NSArray *arrayImages;

@end

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

- (void)setupUI
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collectionView];
}


#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 2;
    
}

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

    LogLeftViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LogLeftViewCell" forIndexPath:indexPath];
    cell.icon.image = [UIImage imageNamed:self.arrayImages[indexPath.item]];
    cell.icon.contentMode=UIViewContentModeScaleAspectFill;
    return cell;
}

/**
 cell的大小
 */
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat realWidth = (SCREEN_WIDTH-20*WIDTHRADIU)/2;
    
    return CGSizeMake(realWidth, 100* WIDTHRADIU);
}
/**
 每个分区的内边距（上左下右）
 */
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(2 * WIDTHRADIU, 5 * WIDTHRADIU, 2 * WIDTHRADIU, 5 * 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 0.0;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
        return CGSizeZero;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
   
    
    if (self.delegate ) {

        //[Tools showMessage:[NSString stringWithFormat:@"当前:%ld",(long)indexPath.item]];
        [self.delegate LogLeftClickWithIndex:indexPath.item];
    }
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor colorWithHex:0x000000 alpha:0.1];
}

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor clearColor];
}

#pragma mark - getters and setters
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *fl = [[UICollectionViewFlowLayout alloc]init];
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 105 * WIDTHRADIU) collectionViewLayout:fl];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        
        // _collectionView.backgroundColor = K_GrayColor;
        
        _collectionView.backgroundColor = [UIColor whiteColor];
        //布局
        fl.minimumLineSpacing = 0;
        fl.minimumInteritemSpacing = 0;
        
        //cell注册
        [_collectionView registerNib:[UINib nibWithNibName:@"LogLeftViewCell" bundle:nil] forCellWithReuseIdentifier:@"LogLeftViewCell"];
        
       
        
        
    }
    return _collectionView;
}
- (void)refreshWithData:(NSArray *)arr{
    self.midDataArr = arr;
    
    [self.collectionView reloadData];
}
- (NSArray *)arrayBtns
{
    if (!_arrayBtns) {
        _arrayBtns = @[
                       @"",@""
                       ];
    }
    return _arrayBtns;
}

- (NSArray *)arrayImages
{
    if (!_arrayImages) {
        _arrayImages = @[
                       @"mine_new_sign_left",@"mine_new_sign_left01"];
    }
    return _arrayImages;
}


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

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

    // Configure the view for the selected state
}

@end
