//
//  SaleInputAddViewController.m
//  HDMall
//
//  Created by Javen on 2017/7/31.
//  Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//

#import "SaleInputAddViewController.h"
#import "SaleInputViewModel.h"
#import "SaleInputAmountCollectionViewCell.h"
@interface SaleInputAddViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIButton *btnBottom;
@property (strong, nonatomic) SaleInputViewModel *viewModel;
@property (strong, nonatomic) NSMutableArray *arrData;
@end

@implementation SaleInputAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    WS(weakSelf);
    [self.viewModel httpAllPayments:^(NSMutableArray<HMSaleInputDetail_payments_payment *> *arrPayments) {
        weakSelf.arrData = arrPayments;
        [weakSelf.collectionView reloadData];
        CLog(@"%@", arrPayments);
    }];
}

#pragma mark - UICollectionViewDelegateFlowLayout
#pragma mark - item的列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

#pragma mark - item的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    if (0 == section) {
        return 0;
    } else {
        return 5;
    }
}

//定义每个UICollectionView item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (0 == indexPath.section) {
        return CGSizeMake(kWidth, 50);
    } else {
        return CGSizeMake((kWidth - 30) / 2, kAutoValue(120));
    }
}

//定义每个UICollectionView section的 margin
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    if (0 == section) {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    } else {
        return UIEdgeInsetsMake(0, 10, 0, 10);
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 0);
    } else {
        return CGSizeMake(kWidth, 50);
    }
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView *header;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"picHeaderView" forIndexPath:indexPath];
    }
    return header;
}

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

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    //输入各种支付方式的金额
    SaleInputAmountCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SaleInputAmountCollectionViewCell" forIndexPath:indexPath];
    cell.isEdit = self.viewModel.type != SaleInputTypeReadOnly;
    [cell configCellWithArray:self.arrData indexPath:indexPath];
//    WS(weakSelf);
    cell.blockNumberChanged = ^{
//        [weakSelf allInputMoney];
    };
    return cell;
}

//
- (void)httpPayments {
    
}

ZJLazy(SaleInputViewModel, viewModel);
ZJLazy(NSMutableArray, arrData);
@end
