//
//  FindEntertainmentCell.m
//  Open
//
//  Created by 雷俊博 on 2020/6/2.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "FindEntertainmentCell.h"
#import "FindPlayCollectionViewCell.h"
#import "KKProgressView.h"

@interface FindEntertainmentCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewHeightLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconLeftLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLeftLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnRightLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewHeightLayout;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftLeadingLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightLeadingLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLeadingLayout;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconImgWidthLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconImgHeightLayout;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet KKProgressView *progressView;

@end

@implementation FindEntertainmentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.topViewHeightLayout.constant = 48 * WIDTHRADIU;
    self.iconLeftLayout.constant = 15 * WIDTHRADIU;
    self.titleLeftLayout.constant = 5 * WIDTHRADIU;
    self.moreBtnRightLayout.constant = 10 * WIDTHRADIU;
    self.leftLeadingLayout.constant = 15 * WIDTHRADIU;
    self.rightLeadingLayout.constant = 15 * WIDTHRADIU;
    self.topLeadingLayout.constant = 15 * WIDTHRADIU;
    self.iconImgWidthLayout.constant = 18 * WIDTHRADIU;
    self.iconImgHeightLayout.constant = 14 * WIDTHRADIU;
    self.collectionViewHeightLayout.constant = 123 * WIDTHRADIU;
    
    self.lb_title.attributedText = [[NSMutableAttributedString alloc] initWithString:@"休闲娱乐" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Semibold" size: 16 * WIDTHRADIU],NSForegroundColorAttributeName: [UIColor colorWithHex:0x333333]}];
       
       self.moreBtn.titleLabel.font = [UIFont fontWithName:@"PingFang  SC" size: 14 * WIDTHRADIU];
       [self.moreBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"FindPlayCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
    self.collectionView.alwaysBounceHorizontal = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"x:%.2f",scrollView.contentOffset.x);
    CGFloat x = scrollView.contentOffset.x;
    CGFloat width = self.collectionView.contentSize.width - self.collectionView.bounds.size.width;
    CGFloat progress = x/width;
    if (progress < 0) {
        progress = 0.0;
    }else if(progress > 1){
        progress = 1.0;
    }
    self.progressView.progress = progress;
    
}


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

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    FindPlayCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    
    return cell;
}

/**
 cell的大小
 */
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(105 * WIDTHRADIU, 123 * WIDTHRADIU);
   
}

/**
 每个分区的内边距（上左下右）
 */
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
/**
 分区内cell之间的最小行间距
 */

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

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

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
   
        return CGSizeZero;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
}

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

    // Configure the view for the selected state
}

@end
