//
//  MoreHotTagViewController.m
//  ALand
//
//  Created by Z on 16/4/27.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "MoreHotTagViewController.h"
#import "AddCommodityCollectionViewCell.h"
#import "CommodityListViewController.h"
#define kCellId @"AddCommodityCollectionViewCell.h"

#define kMargin 0
@interface MoreHotTagViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation MoreHotTagViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpCollectionView];
    // Do any additional setup after loading the view.
}

- (void)setUpCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((ScreenSize.width - kMargin * 2)/3, kAutoValue(70));
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    [self.view addSubview:_collectionView];
    _collectionView.sd_layout.topEqualToView(self.view).leftEqualToView(self.view).bottomEqualToView(self.view).rightEqualToView(self.view);
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = kSysWhite;
    _collectionView.contentInset = UIEdgeInsetsMake(0, kMargin, 0, kMargin);
    
    //cell
    [_collectionView registerNib:[UINib nibWithNibName:@"AddCommodityCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kCellId];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.arrItems.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    AddCommodityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
    [cell cellWithHotTagsModel:self.arrItems[indexPath.row] indexPath:indexPath];
    
    return cell;

}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    CommodityListViewController *commodityVC = [[CommodityListViewController alloc] init];
    commodityVC.hidesBottomBarWhenPushed = YES;
    commodityVC.isShowNavigationBar = YES;
    commodityVC.model = self.arrItems[indexPath.row];
    [self.navigationController pushViewController:commodityVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
