//
//  ICGuideViewController.m
//  DHZL
//
//  Created by Mazy on 2020/6/20.
//  Copyright © 2020 Mazy. All rights reserved.
//

#import "ICGuideViewController.h"
#import "ICHomeViewController.h"
#import "ICNavigationController.h"
#import "ICGuideCollectionViewCell.h"
#import "DeviceInfo.h"

@interface ICGuideViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end

@implementation ICGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    self.flowLayout.minimumLineSpacing = CGFLOAT_MIN;
    self.flowLayout.minimumInteritemSpacing = CGFLOAT_MIN;
    
    [self.collectionView reloadData];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)dismissGuideView {
    ICHomeViewController *homeVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICHomeViewController"];
    ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:homeVC];
    [UIApplication sharedApplication].keyWindow.rootViewController = navc;
}

# pragma mark - UICollectionViewDataSource, UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ICGuideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: @"ICGuideCollectionViewCell" forIndexPath:indexPath];
    if ([UIScreen mainScreen].bounds.size.height >= 812) {
        cell.guideImageView.image = [UIImage imageNamed: [NSString stringWithFormat:@"guide_image_x_0%ld", (long)indexPath.row + 1]];
    } else {
        cell.guideImageView.image = [UIImage imageNamed: [NSString stringWithFormat:@"guide_image_0%ld", (long)indexPath.row + 1]];
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row <= 1) {
        [collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section] atScrollPosition: UICollectionViewScrollPositionCenteredHorizontally animated:true];
    } else {
        [self dismissGuideView];
    }
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return UIScreen.mainScreen.bounds.size;
}

@end
