//
//  SeceneLibraryView.m
//  Lighting
//
//  Created by mac on 16/5/11.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "SeceneLibraryView.h"

@implementation SeceneLibraryView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self initdata];
        [self initView];
    }
    return self;
}
-(void)initdata
{
    self.arrayData=[[NSMutableArray alloc]init];
    self.array1=[[NSMutableArray alloc]initWithObjects:@"玄关",@"客厅",@"餐厅",@"主卧室",@"次卧室", @"书房",@"儿童房",@"过厅",@"过道",@"厨房",@"卫生间",@"休闲空间",nil];
     self.array2=[[NSMutableArray alloc]initWithObjects:@"现代简约",@"欧式古典",@"新古典",@"中式",@"新中式", @"混搭",@"小美式风格",@"古典美式风格",@"地中海",@"东南亚",@"日式",@"法式",nil];
     self.array3=[[NSMutableArray alloc]initWithObjects:@"田园",@"宫廷",@"乡村",@"日式风格",@"欧式风格", @"混搭风格",@"现代简约",nil];
    self.arrayData=self.array1;
}
-(void)initView
{

//    空间
    self.kongJianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.kongJianBtn.frame=CGRectMake(ScreenWidth-250, 52, 100, 46) ;
    self.kongJianBtn.backgroundColor=[UIColor whiteColor];
    [self.kongJianBtn setTitle:@"空间   " forState:UIControlStateNormal];
    [self.kongJianBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self.kongJianBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  self.kongJianBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    [self.kongJianBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.kongJianBtn.tag=101;
    self.kongJianBtn.layer.masksToBounds = YES;
    self.kongJianBtn.layer.cornerRadius = 15;
    [self addSubview:self.kongJianBtn];
//    风格
    self.fengGeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.fengGeBtn.frame=CGRectMake(ScreenWidth-250, 102, 100, 46) ;
     self.fengGeBtn.backgroundColor=[UIColor whiteColor];
    [self.fengGeBtn setTitle:@"风格  " forState:UIControlStateNormal];
    [self.fengGeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self.fengGeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    self.fengGeBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    [self.fengGeBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.fengGeBtn.tag=102;
    self.fengGeBtn.layer.masksToBounds = YES;
    self.fengGeBtn.layer.cornerRadius = 15;
    [self addSubview:self.fengGeBtn];
//类型
    self.leiXingBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.leiXingBtn.frame=CGRectMake(ScreenWidth-250, 152, 100, 46) ;
      self.leiXingBtn.backgroundColor=[UIColor whiteColor];
    [self.leiXingBtn setTitle:@"类型   " forState:UIControlStateNormal];
     [self.leiXingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self.leiXingBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
      self.leiXingBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    [self.leiXingBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.leiXingBtn.tag=103;
    self.leiXingBtn.layer.masksToBounds = YES;
    self.leiXingBtn.layer.cornerRadius = 15;
    [self addSubview:self.leiXingBtn];
    
   self.subView=[[UIView alloc]initWithFrame:CGRectMake(100, 50, ScreenWidth-300, ScreenHeight-200)];
    self.subView.backgroundColor=[UIColor whiteColor];
    [self  addSubview:self.subView];
    

    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView:)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [[UIApplication sharedApplication].keyWindow addGestureRecognizer:tap];
    [self initSubViews];
}
-(void)initSubViews
{
    self.headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.subView.frame.size.width-100, 50)];
    self.headerView.backgroundColor=[UIColor grayColor];
    [self.subView addSubview:self.headerView];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, 10, 30, 30);
    [btn setBackgroundImage:[UIImage imageNamed:@"changjingtubiao"] forState:UIControlStateNormal];
    [self.headerView addSubview:btn];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(45, 10, 100, 30)];
    lable.text=@"选择场景";
     [self.headerView addSubview:lable];
    self.seceneTableView=[[UITableView alloc]initWithFrame:CGRectMake( self.headerView.frame.size.width, 0, 100, self.subView.frame.size.height)];
    self.seceneTableView.delegate=self;
    self.seceneTableView.dataSource=self;
    [self.subView addSubview:self.seceneTableView];
    
    self.pictureTableView=[[UITableView alloc]initWithFrame:CGRectMake( 0, 50, self.headerView.frame.size.width, self.subView.frame.size.height-50)];
    self.pictureTableView.delegate=self;
    self.pictureTableView.dataSource=self;
    [self.subView addSubview:self.pictureTableView];
}
-(void)selectedType:(UIButton *)sender
{
    switch (sender.tag) {
        case 101:
//            空间
            self.arrayData=self.array1;
            break;
        case 102:
//            风格
             self.arrayData=self.array2;
            break;
        case 103:
//            类型
             self.arrayData=self.array3;
            break;
        default:
            break;
    }
    [self.seceneTableView reloadData];
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    if ([tableView isEqual:self.seceneTableView])
     {
          return self.arrayData.count;
      }else
      {
          return 5;
      }
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:self.seceneTableView])
    {
        return 50;
    }else
    {
        return 150;
    }

    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:self.seceneTableView])
    {
        static NSString *cellID = @"ChooseTansferCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            //        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        cell.textLabel.text=[self.arrayData objectAtIndex:indexPath.row];
        
        return cell;
    }else
    {
        
        static NSString *CellID = @"TansferCell";
        CustomPictureShowCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[CustomPictureShowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID withImageName:nil];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.pictureView1.image=[UIImage imageNamed:@"textpicture"];
        cell.pictureView2.image=[UIImage imageNamed:@"textpicture"];
        cell.pictureView3.image=[UIImage imageNamed:@"textpicture"];

        return cell;
    }
   
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}



-(void)DismissScreenView:(UITapGestureRecognizer*)sender{
    CGPoint point = [sender locationInView:self];
    if (point.x<100 || point.x >ScreenWidth-100||point.y<50||point.y>ScreenHeight-150) {
        
        if (self) {
            [self removeFromSuperview];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
