//
//  NvBeautyView.m
//  SDKDemo
//
//  Created by ms20180425 on 2018/6/4.
 //
//

#import "NvBeautyView.h"
#import "NVHeader.h"

@interface NvBeautyView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UIView *topView;       //上半部分视图
@property (nonatomic, strong) UIView *bottomView;    //下半部分视图

@property (nonatomic, strong) UIView *beautyBCView;  //美颜视图
@property (nonatomic, strong) UIView *beautyTypeBCView; //美型视图

@property (nonatomic, strong) UILabel *beautyLabel;     //美颜开光旁边的显示文字
@property (nonatomic, strong) UILabel *beautyTypeLabel; //美型开光旁边的显示文字

@property (nonatomic, strong) UISlider *beautySlider;//美颜
@property (nonatomic, strong) UISlider *beautyTypeSlider;//美型
@property (nonatomic, strong) UISlider *basisFilterSlider;//基础滤镜

@property (nonatomic, strong) UIButton *sharpenBtn;  //锐化按钮
@property (nonatomic, strong) UIButton *filterBtn;   //基础滤镜

@property (nonatomic, strong) UIButton *resetBtn;    //重置按钮

@property (nonatomic, strong) UICollectionView *beautyCollectionView;//美颜滚动视图
@property (nonatomic, strong) NSMutableArray *currentArray_1;        //美颜model数组
@property (nonatomic, strong) UIView *maskView_1;                    //美颜遮罩层，关闭美颜起作用
@property (nonatomic, strong) NvBeautyTypeModel *currentModel_1;     //美颜当前选中model

@property (nonatomic, strong) UICollectionView *beautyTypeCollectionView;//美型滚动视图
@property (nonatomic, strong) NSMutableArray *currentArray;          //美型model数组
@property (nonatomic, strong) UIView *maskView;                      //美型遮罩层，关闭美型起作用
@property (nonatomic, strong) NvBeautyTypeModel *currentModel;       //美型当前选中model
@property (nonatomic, strong) NSMutableArray *originalArray;         //美型初始数据，用于重置

@property (nonatomic, assign) BOOL isFilder;   //正在操作的对象是不是基础滤镜，用于区别隐藏基础滤镜调节杆和美颜调节杆

@property (nonatomic, strong) NvBeautyTypeModel *filterModel;   //基础滤镜model
@property (nonatomic, strong) NvBeautyTypeModel *sharpenModel;  //锐化model

@end

@implementation NvBeautyView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.clearColor;
        [self addSubviews];
    }
    return self;
}

#pragma mark 添加子视图
- (void)addSubviews{
    self.topView = [[UIView alloc]init];
    self.topView.backgroundColor = UIColor.clearColor;
    
    self.bottomView = [[UIView alloc]init];
    self.bottomView.backgroundColor = [UIColor nv_colorWithHexARGB:@"#99000000"];
    
    self.beautyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.beautyBtn setTitle:@"美颜" forState:UIControlStateNormal];
    self.beautyBtn.titleLabel.font = [NvUtils fontWithSize:12];
    [self.beautyBtn setTitleColor:[UIColor nv_colorWithHexRGB:@"#4A90E2"] forState:UIControlStateNormal];
    self.beautyBtn.backgroundColor = UIColor.clearColor;
    
    self.beautyTypeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.beautyTypeBtn setTitle:@"美型" forState:UIControlStateNormal];
    self.beautyTypeBtn.titleLabel.font = [NvUtils fontWithSize:12];
    [self.beautyTypeBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    self.beautyTypeBtn.backgroundColor = UIColor.clearColor;
    
    UILabel *horizontalLine = [UILabel new];
    horizontalLine.backgroundColor = [UIColor nv_colorWithHexRGB:@"#979797"];
    
    UILabel *verticalLine = [UILabel new];
    verticalLine.backgroundColor = [UIColor nv_colorWithHexRGB:@"#979797"];
    
    [self addSubview:self.topView];
    [self addSubview:self.bottomView];
    [self.bottomView addSubview:self.beautyBtn];
    [self.bottomView addSubview:self.beautyTypeBtn];
    [self.bottomView addSubview:horizontalLine];
    [self.bottomView addSubview:verticalLine];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.width.equalTo(self.mas_width);
        make.height.offset(80 * SCREANSCALE);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.equalTo(self);
        make.bottom.equalTo(self);
        make.width.equalTo(self.mas_width);
    }];
    
    [self.beautyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView.mas_top);
        make.left.equalTo(self);
        make.width.offset(self.frame.size.width/2);
        make.height.offset(30 * SCREANSCALE);
    }];
    
    [self.beautyTypeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView.mas_top);
        make.right.equalTo(self);
        make.width.offset(self.frame.size.width/2);
        make.height.offset(30 * SCREANSCALE);
    }];
    
    [horizontalLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyBtn.mas_bottom);
        make.width.offset(self.frame.size.width);
        make.height.offset(1 *SCREANSCALE);
    }];
    
    [verticalLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyBtn.mas_top).offset(8 * SCREANSCALE);
        make.bottom.equalTo(horizontalLine.mas_bottom).offset(-8 * SCREANSCALE);
        make.centerX.equalTo(self.bottomView.mas_centerX);
        make.width.offset(1);
    }];
    
    [self addBeauty];
    [self addBeautyType];
}

#pragma mark 添加美颜视图
- (void)addBeauty{
    
    self.beautySlider = [UISlider new];
    self.beautySlider.hidden = YES;
    [self.beautySlider setMinimumValue:0.0];
    [self.beautySlider setMaximumValue:1.0];
    self.beautySlider.minimumTrackTintColor = [UIColor whiteColor];
    self.beautySlider.maximumTrackTintColor = [UIColor whiteColor];
    [self.beautySlider setThumbImage:[NvUtils imageWithName:@"NvsliderWhite"] forState:UIControlStateNormal];
    [self.beautySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.beautySlider addTarget:self action:@selector(sliderValueEnd:) forControlEvents:UIControlEventTouchUpInside];
    [self.beautySlider addTarget:self action:@selector(sliderValueEnd:) forControlEvents:UIControlEventTouchUpOutside];
    [self.topView addSubview:self.beautySlider];
    [self.beautySlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.topView.mas_bottom).offset(-20 * SCREANSCALE);
        make.centerX.equalTo(self.topView.mas_centerX);
        make.width.offset(273 * SCREANSCALE);
        make.height.offset(10 * SCREANSCALE);
    }];
    
    self.beautyBCView = [UIView new];
    self.beautyBCView.backgroundColor = UIColor.clearColor;
    [self.bottomView addSubview:_beautyBCView];
    
    [_beautyBCView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyBtn.mas_bottom).offset(1 * SCREANSCALE);
        make.width.equalTo(self.bottomView.mas_width);
        make.bottom.equalTo(self.bottomView.mas_bottom);
    }];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake(49*SCREANSCALE, 79*SCREANSCALE);
    layout.minimumLineSpacing = 83*SCREANSCALE;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 30*SCREANSCALE, 0, 0);
    self.beautyCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,0,0) collectionViewLayout:layout];
    self.beautyCollectionView.delegate = self;
    self.beautyCollectionView.dataSource = self;
    self.beautyCollectionView.backgroundColor = [UIColor clearColor];
    self.beautyCollectionView.showsHorizontalScrollIndicator = NO;
    [_beautyBCView addSubview:self.beautyCollectionView];
    [self.beautyCollectionView registerClass:[NvBeautyTypeCViewCell class] forCellWithReuseIdentifier:@"NvBeautyCViewCell"];
    [self.beautyCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyBCView.mas_top).offset(10 * SCREANSCALE);
        make.left.equalTo(self.beautyBCView.mas_left);
        make.right.equalTo(self.beautyBCView.mas_right);
        make.height.offset(79 * SCREANSCALE);
    }];

    self.maskView_1 = [[UIView alloc] init];
    self.maskView_1.backgroundColor = UIColor.clearColor;
    [_beautyBCView addSubview:self.maskView_1];
    [self.maskView_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyBCView);
        make.left.equalTo(self.beautyBCView);
        make.right.equalTo(self.beautyBCView);
        make.bottom.equalTo(self.beautyBCView);
    }];
    
    self.beautySwitch = [[NvSwitchView alloc]initWithFrame:CGRectMake(0, 0, 32 * SCREANSCALE, 19 * SCREANSCALE) withType:2 withState:YES];
    self.beautySwitch.tag = 1000;
    
    self.beautyLabel = [UILabel new];
    self.beautyLabel.text = @"关闭美颜";
    self.beautyLabel.textColor = UIColor.whiteColor;
    self.beautyLabel.font = [NvUtils fontWithSize:11];
    
    [_beautyBCView addSubview:self.beautySwitch];
    [_beautyBCView addSubview:self.beautyLabel];
    
    [self.beautySwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyCollectionView.mas_bottom).offset(18 * SCREANSCALE);
        make.right.equalTo(self.beautyBCView.mas_right).offset(-10 * SCREANSCALE);
        make.width.offset(32 * SCREANSCALE);
        make.height.offset(19 * SCREANSCALE);
    }];
    
    [self.beautyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.beautySwitch.mas_left).offset(-5 * SCREANSCALE);
        make.centerY.equalTo(self.beautySwitch.mas_centerY);
    }];
}

#pragma mark sharpenBtnClick——锐化按钮点击
- (void)sharpenBtnClick:(UIButton *)sender{
    sender.selected = !sender.isSelected;
    self.sharpenModel.selected = sender.isSelected;
    self.sharpenBtn.alpha = sender.isSelected?1:0.2;
    [self.delegate nvBeautyView:self withModel:self.sharpenModel withState:YES];
}

#pragma mark filterBtnClick——基础按钮点击
- (void)filterBtnClick:(UIButton *)sender{
    if (self.isFilder == NO && sender.isSelected) {
        self.basisFilterSlider.hidden = NO;
        self.beautySlider.hidden = YES;
        self.isFilder = YES;
        return;
    }
    self.isFilder = YES;
    sender.selected = !sender.isSelected;
    self.filterModel.selected = sender.isSelected;
    self.filterBtn.alpha = sender.isSelected?1:0.2;
    self.basisFilterSlider.hidden = !sender.isSelected;
    if (self.currentModel_1.selected) {
        self.beautySlider.hidden = sender.isSelected;
    }
    [self.delegate nvBeautyView:self withModel:self.filterModel withState:YES];
}

#pragma mark 添加美型视图
- (void)addBeautyType{
    
    self.beautyTypeSlider = [UISlider new];
    self.beautyTypeSlider.hidden = YES;
    [self.beautyTypeSlider setMinimumValue:0.0];
    [self.beautyTypeSlider setMaximumValue:1.0];
    self.beautyTypeSlider.minimumTrackTintColor = [UIColor whiteColor];
    self.beautyTypeSlider.maximumTrackTintColor = [UIColor whiteColor];
    [self.beautyTypeSlider setThumbImage:[NvUtils imageWithName:@"NvsliderWhite"] forState:UIControlStateNormal];
    [self.beautyTypeSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.beautyTypeSlider addTarget:self action:@selector(sliderValueEnd:) forControlEvents:UIControlEventTouchUpInside];
    [self.beautyTypeSlider addTarget:self action:@selector(sliderValueEnd:) forControlEvents:UIControlEventTouchUpOutside];
    [self.topView addSubview:self.beautyTypeSlider];
    [self.beautyTypeSlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.topView.mas_bottom).offset(-20 * SCREANSCALE);
        make.centerX.equalTo(self.topView.mas_centerX);
        make.width.offset(273 * SCREANSCALE);
        make.height.offset(10 * SCREANSCALE);
    }];
    
    self.beautyTypeBCView = [UIView new];
    self.beautyTypeBCView.backgroundColor = UIColor.clearColor;
    [self.bottomView addSubview:_beautyTypeBCView];
    
    [_beautyTypeBCView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyBtn.mas_bottom).offset(1 * SCREANSCALE);
        make.width.equalTo(self.bottomView.mas_width);
        make.bottom.equalTo(self.bottomView.mas_bottom);
    }];

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake(49*SCREANSCALE, 79*SCREANSCALE);
    layout.minimumLineSpacing = 12*SCREANSCALE;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 11*SCREANSCALE, 0, 0);
    self.beautyTypeCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,0,0) collectionViewLayout:layout];
    self.beautyTypeCollectionView.delegate = self;
    self.beautyTypeCollectionView.dataSource = self;
    self.beautyTypeCollectionView.backgroundColor = [UIColor clearColor];
    self.beautyTypeCollectionView.showsHorizontalScrollIndicator = NO;
    [_beautyTypeBCView addSubview:self.beautyTypeCollectionView];
    [self.beautyTypeCollectionView registerClass:[NvBeautyTypeCViewCell class] forCellWithReuseIdentifier:@"NvBeautyTypeCViewCell"];
    [self.beautyTypeCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyTypeBCView.mas_top).offset(10 * SCREANSCALE);
        make.left.equalTo(self.beautyTypeBCView.mas_left);
        make.right.equalTo(self.beautyTypeBCView.mas_right);
        make.height.offset(79 * SCREANSCALE);
    }];
    
    self.resetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.resetBtn setTitle:@"重置" forState:UIControlStateNormal];
    [self.resetBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [self.resetBtn addTarget:self action:@selector(resetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.resetBtn.titleLabel.font = [NvUtils fontWithSize:11];
    [self.resetBtn setImage:[NvUtils imageWithName:@"NvCaptureBeautyTypeReset"] forState:UIControlStateNormal];
    self.resetBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);
    [_beautyTypeBCView addSubview:self.resetBtn];
    [self.resetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.beautyTypeBCView.mas_left).offset(5 * SCREANSCALE);
        make.top.equalTo(self.beautyTypeCollectionView.mas_bottom).offset(18 * SCREANSCALE);
        make.width.offset(80 * SCREANSCALE);
        make.height.offset(20 * SCREANSCALE);
    }];
    
    self.maskView = [[UIView alloc] init];
    self.maskView.backgroundColor = UIColor.clearColor;
    [_beautyTypeBCView addSubview:self.maskView];
    [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beautyTypeBCView);
        make.left.equalTo(self.beautyTypeBCView);
        make.right.equalTo(self.beautyTypeBCView);
        make.bottom.equalTo(self.beautyTypeBCView);
    }];
    
    self.beautyTypeSwitch = [[NvSwitchView alloc]initWithFrame:CGRectMake(0, 0, 32 * SCREANSCALE, 19 * SCREANSCALE) withType:2 withState:YES];
    self.beautyTypeSwitch.tag = 1001;
    [_beautyTypeBCView addSubview:_beautyTypeSwitch];
    
    self.beautyTypeLabel = [UILabel new];
    self.beautyTypeLabel.text = @"关闭美型";
    self.beautyTypeLabel.textColor = UIColor.whiteColor;
    self.beautyTypeLabel.font = [NvUtils fontWithSize:11];
    [_beautyTypeBCView addSubview:_beautyTypeLabel];
    
    [self.beautyTypeSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.beautyTypeBCView.mas_right).offset(-10 * SCREANSCALE);
        make.centerY.equalTo(self.beautyTypeLabel.mas_centerY);
        make.width.offset(32 * SCREANSCALE);
        make.height.offset(19 * SCREANSCALE);
    }];
    
    [self.beautyTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.resetBtn.mas_centerY);
        make.right.equalTo(self.beautyTypeSwitch.mas_left).offset(-5 * SCREANSCALE);
    }];
}

#pragma mark resetBtnClick——重置按钮点击
- (void)resetBtnClick:(UIButton *)sender{
    for (int i = 0; i<self.currentArray.count; i++) {
        NvBeautyTypeModel *model = self.currentArray[i];
        if (i==0) {
            self.currentModel = model;
            model.selected = YES;
        } else {
            model.selected = NO;
        }
        model.value = [self.originalArray[i] floatValue];
        if (i == 0) {
            self.beautyTypeSlider.value = 0;
        }
    }
    
    [self.delegate nvBeautyView:self withModelArray:self.currentArray];
    [self.beautyTypeCollectionView reloadData];
}

- (void)configBeautyByteArray:(NSMutableArray *)array{
    self.currentArray = [NSMutableArray array];
    self.originalArray = [NSMutableArray array];
    [self.currentArray addObjectsFromArray:array];
    for (int i = 0; i<array.count ; i++) {
        NvBeautyTypeModel *model = array[i];
        [self.originalArray addObject:@(model.value)];
    }
    self.currentModel = [self.currentArray firstObject];
    self.beautyTypeSlider.value = self.currentModel.value;
    
    [self.beautyTypeCollectionView reloadData];
}

- (void)configBeautyArray:(NSMutableArray *)array{
    self.currentArray_1 = [NSMutableArray array];
    [self.currentArray_1 addObjectsFromArray:array];
    self.currentModel_1 = [self.currentArray_1 firstObject];
    self.beautySlider.value = self.currentModel_1.value;
    
    [self.beautyCollectionView reloadData];
}

- (void)configBeautyFilter:(NvBeautyTypeModel *)filter withSharpen:(NvBeautyTypeModel *)sharpen{
    self.filterModel = filter;
    self.sharpenModel = sharpen;
    
    self.filterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.filterBtn addTarget:self action:@selector(filterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.filterBtn.alpha = 0.5;
    [self.filterBtn setImage:[NvUtils imageWithName:filter.coverImage] forState:UIControlStateNormal];
    [self.topView addSubview:self.filterBtn];
    [self.filterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.topView.mas_bottom).offset(-13 * SCREANSCALE);
        make.right.equalTo(self.topView.mas_right).offset(-12 * SCREANSCALE);
        make.width.offset(30 * SCREANSCALE);
        make.height.offset(30 * SCREANSCALE);
    }];
    
    self.basisFilterSlider = [UISlider new];
    self.basisFilterSlider.hidden = YES;
    [self.basisFilterSlider setMinimumValue:0.0];
    [self.basisFilterSlider setMaximumValue:1.0];
    self.basisFilterSlider.value = filter.value;
    self.basisFilterSlider.minimumTrackTintColor = [UIColor whiteColor];
    self.basisFilterSlider.maximumTrackTintColor = [UIColor whiteColor];
    [self.basisFilterSlider setThumbImage:[NvUtils imageWithName:@"NvsliderWhite"] forState:UIControlStateNormal];
    [self.basisFilterSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.basisFilterSlider addTarget:self action:@selector(sliderValueEnd:) forControlEvents:UIControlEventTouchUpInside];
    [self.basisFilterSlider addTarget:self action:@selector(sliderValueEnd:) forControlEvents:UIControlEventTouchUpOutside];
    [self.topView addSubview:self.basisFilterSlider];
    [self.basisFilterSlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.topView.mas_bottom).offset(-20 * SCREANSCALE);
        make.centerX.equalTo(self.topView.mas_centerX);
        make.width.offset(273 * SCREANSCALE);
        make.height.offset(10 * SCREANSCALE);
    }];
    
    self.sharpenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.sharpenBtn addTarget:self action:@selector(sharpenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.sharpenBtn.alpha = 0.5;
    [self.sharpenBtn setImage:[NvUtils imageWithName:sharpen.coverImage] forState:UIControlStateNormal];
    [self.topView addSubview:self.sharpenBtn];
    [self.sharpenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.filterBtn.mas_top).offset(-13 * SCREANSCALE);
        make.right.equalTo(self.topView.mas_right).offset(-12 * SCREANSCALE);
        make.width.offset(30 * SCREANSCALE);
        make.height.offset(30 * SCREANSCALE);
    }];
    
    self.sharpenBtn.enabled = NO;
    self.filterBtn.enabled = NO;
    self.filterBtn.selected = self.filterModel.selected;
    self.sharpenBtn.selected = self.sharpenModel.selected;
    self.isFilder = YES;
}

- (void)setHiddenBool:(BOOL)hiddenBool{
    _hiddenBool = hiddenBool;
    if (hiddenBool) {
        self.beautyTypeSlider.hidden = YES;
        self.beautyTypeBCView.hidden = YES;
        
        self.beautyBCView.hidden = NO;
        self.sharpenBtn.hidden = NO;
        self.filterBtn.hidden = NO;
        
        [self.beautyBtn setTitleColor:[UIColor nv_colorWithHexRGB:@"#4A90E2"] forState:UIControlStateNormal];
        [self.beautyTypeBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        
        if (self.beautySwitch.isSelected) {
            if (self.filterModel.selected) {
                if (self.isFilder) {
                    self.basisFilterSlider.hidden = NO;
                }else{
                    self.beautySlider.hidden = NO;
                }
            }else{
                self.beautySlider.hidden = NO;
            }
            
        }
        
    }else{
        if (self.beautyTypeSwitch.isSelected) {
            self.beautyTypeSlider.hidden = NO;
        }
        self.beautySlider.hidden = YES;
        self.beautyBCView.hidden = YES;
        self.basisFilterSlider.hidden = YES;
        self.sharpenBtn.hidden = YES;
        self.filterBtn.hidden = YES;
        self.beautyTypeBCView.hidden = NO;
        [self.beautyTypeBtn setTitleColor:[UIColor nv_colorWithHexRGB:@"#4A90E2"] forState:UIControlStateNormal];
        [self.beautyBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    }
}

- (void)editBool:(BOOL)edit withType:(BOOL)type{
    if (type) {
        //美颜
        if (edit) {
            self.beautyLabel.text = @"关闭美颜";
            self.maskView_1.hidden = YES;
            for (NvBeautyTypeModel *model in self.currentArray_1) {
                model.isOperation = YES;
            }
            [self.beautyCollectionView reloadData];
            
            self.beautyLabel.textColor = UIColor.whiteColor;
            
            self.beautySlider.hidden = NO;
            if (self.filterModel.selected) {
                if (self.isFilder) {
                    self.basisFilterSlider.hidden = NO;
                    self.beautySlider.hidden = YES;
                }else{
                    self.beautySlider.hidden = NO;
                    self.basisFilterSlider.hidden = YES;
                }
            }
            
            self.filterBtn.alpha = self.filterModel.selected?1:0.5;
            self.sharpenBtn.alpha = self.sharpenModel.selected?1:0.5;
            self.sharpenBtn.enabled = YES;
            self.filterBtn.enabled = YES;
            
        }else{
            self.beautyLabel.text = @"开启美颜";
            self.maskView_1.hidden = NO;
            for (NvBeautyTypeModel *model in self.currentArray_1) {
                model.isOperation = NO;
            }
            [self.beautyCollectionView reloadData];
            
            self.beautyLabel.textColor = [UIColor nv_colorWithHexRGB:@"#909293"];
            self.beautySlider.hidden = YES;
            self.basisFilterSlider.hidden = YES;
            
            self.sharpenBtn.enabled = NO;
            self.filterBtn.enabled = NO;
            self.filterBtn.alpha = 1;
            self.sharpenBtn.alpha = 1;
        }
    }else{
        //美型
        if (edit) {
            self.beautyTypeLabel.text = @"关闭美型";
            self.maskView.hidden = YES;
            for (NvBeautyTypeModel *model in self.currentArray) {
                model.isOperation = YES;
            }
            [self.beautyTypeCollectionView reloadData];
            
            self.beautyTypeLabel.textColor = UIColor.whiteColor;
            [self.resetBtn setImage:[NvUtils imageWithName:@"NvCaptureBeautyTypeReset"] forState:UIControlStateNormal];
            [self.resetBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
            self.beautyTypeSlider.hidden = NO;

        }else{
            self.beautyTypeLabel.text = @"开启美型";
            self.maskView.hidden = NO;
            for (NvBeautyTypeModel *model in self.currentArray) {
                model.isOperation = NO;
            }
            [self.beautyTypeCollectionView reloadData];
            
            self.beautyTypeLabel.textColor = [UIColor nv_colorWithHexRGB:@"#909293"];
            [self.resetBtn setImage:[NvUtils imageWithName:@"NvCaptureBeautyTypeReset_no"] forState:UIControlStateNormal];
            [self.resetBtn setTitleColor:[UIColor nv_colorWithHexRGB:@"#909293"] forState:UIControlStateNormal];
            self.beautyTypeSlider.hidden = YES;
        }
    }
}

#pragma mark 滑杆拖动的回调
-(void)sliderValueChanged:(UISlider *)paramSender{
    if ([self.beautyTypeSlider isEqual:paramSender]) {
        self.currentModel.value = paramSender.value;
        [self.delegate nvBeautyView:self withModel:self.currentModel withState:NO];
    }else if ([self.beautySlider isEqual:paramSender]){
        self.currentModel_1.value = paramSender.value;
        [self.delegate nvBeautyView:self withModel:self.currentModel_1 withState:NO];
    }else{
        self.filterModel.value = paramSender.value;
        [self.delegate nvBeautyView:self withModel:self.filterModel withState:NO];
    }
}

#pragma mark 滑杆拖动结束的回调
-(void)sliderValueEnd:(UISlider *)paramSender{
    if ([self.beautyTypeSlider isEqual:paramSender]) {
        [self.delegate nvBeautyView:self withModel:self.currentModel withState:YES];
    }else if ([self.beautySlider isEqual:paramSender]){
        [self.delegate nvBeautyView:self withModel:self.currentModel_1 withState:YES];
    }else{
        [self.delegate nvBeautyView:self withModel:self.filterModel withState:YES];
    }
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if ([self.beautyCollectionView isEqual:collectionView]) {
        return self.currentArray_1.count;
    }
    return self.currentArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.beautyCollectionView isEqual:collectionView]) {
        NvBeautyTypeCViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NvBeautyCViewCell" forIndexPath:indexPath];
        [cell renderCellWithModel:self.currentArray_1[indexPath.item]];
        return cell;
    }
    NvBeautyTypeCViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NvBeautyTypeCViewCell" forIndexPath:indexPath];
    [cell renderCellWithModel:self.currentArray[indexPath.item]];
    return cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.beautyCollectionView isEqual:collectionView]) {
        for (NvBeautyTypeModel *model in self.currentArray_1) {
            model.selected = NO;
        }
        self.currentModel_1 = self.currentArray_1[indexPath.item];
        self.currentModel_1.selected = YES;
        
        self.beautySlider.value = self.currentModel_1.value;
        self.beautySlider.hidden = NO;
        self.basisFilterSlider.hidden = YES;
        self.isFilder = NO;
    }else{
        for (NvBeautyTypeModel *model in self.currentArray) {
            model.selected = NO;
        }
        self.currentModel = self.currentArray[indexPath.item];
        self.currentModel.selected = YES;
        
        self.beautyTypeSlider.value = self.currentModel.value;
    }
    
    [collectionView reloadData];
}


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

@end
