//
//  ExperienceCentreViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/6/1.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ExperienceCentreViewController.h"
#import "SceneViewController.h"
#import "sceneScreeningCollectionViewCell.h"
#import "ProductScreeningTableViewCell.h"

@interface ExperienceCentreViewController ()<AddImagesDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource>

/**
 *  选中场景数据
 */
@property (nonatomic,strong) NSMutableArray *sceneDatasArray;

/**
 *  选中产品数据源
 */
@property (nonatomic,strong) NSMutableArray *productDatasArray;


@end

@implementation ExperienceCentreViewController



- (NSMutableArray *)sceneDatasArray
{
    if (!_sceneDatasArray) {
        
        _sceneDatasArray = [NSMutableArray array];
    }
    return _sceneDatasArray;
}


- (NSMutableArray *)productDatasArray
{
    if (!_productDatasArray) {
        
        _productDatasArray = [NSMutableArray array];
    }
    return _productDatasArray;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
}


#pragma mark -UI
- (void)uiConfigAction
{
    //场景
    self.sceneLayout.itemSize = CGSizeMake(133, 100);
    self.sceneLayout.minimumLineSpacing = 10;
    self.sceneLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    self.sceneScrollview.delegate = self;
    self.sceneScrollview.dataSource = self;
    //产品
    self.productScrollview.dataSource = self;
    self.productScrollview.delegate = self;
    
}

#pragma mark -UICollectionViewDataSource场景
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.sceneDatasArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    sceneScreeningCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"sceneScreeningCollectionViewCell" forIndexPath:indexPath];
    cell.selectedScrenImageView.image = [self.sceneDatasArray objectAtIndex_opple:indexPath.item];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.sceneImageView.image = [self.sceneDatasArray objectAtIndex_opple:indexPath.item];
}



#pragma mark -UITableViewDataSource商品
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.productDatasArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProductScreeningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductScreeningTableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selectedGoodsImageView.image = [self.productDatasArray objectAtIndex_opple:indexPath.row];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}








#pragma mark -返回
- (IBAction)ReturnButtonClickAction:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark -购物袋
- (IBAction)ShoppingBagButtonClickAction:(UIButton *)sender {
}

#pragma mark -分享
- (IBAction)ShareButtonClickAction:(UIButton *)sender {
}

#pragma mark -拍照
- (IBAction)TakingPhotoButtonClickAction:(UIButton *)sender {
}

#pragma mark -全屏
- (IBAction)AmplificationButtonClickAction:(UIButton *)sender {
}

#pragma mark -帮助
- (IBAction)HelpButtonClickAction:(UIButton *)sender {
}




/**************************功能区**************************/
#pragma mark -场景筛选
- (IBAction)SceneSelectedButtonClickAction:(UIButton *)sender {
    
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SCENE"];
    SceneViewController *sceneVC = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"SceneController"];
    sceneVC.view.backgroundColor = [UIColor clearColor];
    sceneVC.searchBackView.hidden = YES;
    sceneVC.materialButton.hidden = YES;
    sceneVC.priceButton.hidden = YES;
    sceneVC.typeButton.hidden = YES;
    sceneVC.delegate = self;
    sceneVC.endAnimationPoint = self.sceneSelectedButton.center;
    sceneVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *pop = sceneVC.popoverPresentationController;
    pop.sourceView = sceneVC.view;
    [self presentViewController:sceneVC animated:YES completion:nil];
}

#pragma mark -产品筛选
- (IBAction)ProductSelectedButtonClickAction:(UIButton *)sender {
    
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"SCENE"];
    SceneViewController *sceneVC = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"SceneController"];
    sceneVC.view.backgroundColor = [UIColor clearColor];
    sceneVC.searchBackView.hidden = NO;
    sceneVC.materialButton.hidden = NO;
    sceneVC.priceButton.hidden = NO;
    sceneVC.typeButton.hidden = NO;
    sceneVC.delegate = self;
    sceneVC.endAnimationPoint = self.productSelectedButton.center;
    sceneVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *pop = sceneVC.popoverPresentationController;
    pop.sourceView = sceneVC.view;
    [self presentViewController:sceneVC animated:YES completion:nil];
}



#pragma mark -AddImagesDelegate选中图片
- (void)SelectedImages:(UIImage *)image withisScene:(BOOL)isScene returnResponse:(void (^)(BOOL))isThere
{
    if (isScene) {
        
        if (![self.sceneDatasArray containsObject:image]) {
            isThere(NO);
            [self.sceneDatasArray addObject:image];
        }else
        {
            isThere(YES);
            [self.sceneDatasArray removeObject:image];
            [self.sceneScrollview reloadData];
        }
        
    }else
    {
        if (![self.productDatasArray containsObject:image]) {
            isThere(NO);
            [self.productDatasArray addObject:image];
        }else
        {
            isThere(YES);
            [self.productDatasArray removeObject:image];
            [self.productScrollview reloadData];
        }
    }
}

#pragma mark -刷新
- (void)RefreshSceneAndProduct:(BOOL)isScene
{
    if (isScene) {
        
        [self.sceneScrollview reloadData];
        [self.sceneScrollview selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.sceneDatasArray.count-1 inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionRight];
        
    }else
    {
        [self.productScrollview reloadData];
        [self.productScrollview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.productDatasArray.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom 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
