//
//  NvDouyinBeautyView.m
//  SDKDemo
//
//  Created by 刘东旭 on 2018/11/9.
 //
//

#import "NvDouyinBeautyView.h"
#import "NVHeader.h"

@interface NvDouyinBeautyView()

@property (nonatomic, strong) UILabel *strengthLabel;
@property (nonatomic, strong) UILabel *eyeEnlargingLabel;
@property (nonatomic, strong) UILabel *cheekThinningLabel;

@property (nonatomic, strong) UILabel *strengthNum;
@property (nonatomic, strong) UILabel *eyeEnlargingNum;
@property (nonatomic, strong) UILabel *cheekThinningNum;

@property (nonatomic, strong) UISlider *strengthSlider;
@property (nonatomic, strong) UISlider *eyeEnlargingSlider;
@property (nonatomic, strong) UISlider *cheekThinningSlider;

@end

@implementation NvDouyinBeautyView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor nv_colorWithHexARGB:@"#99000000"];
        self.strengthLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.strengthLabel.text = @"磨皮";
        self.strengthLabel.textColor = [UIColor whiteColor];
        self.strengthLabel.textAlignment = NSTextAlignmentCenter;
        self.strengthLabel.font = [NvUtils fontWithSize:12];
        self.cheekThinningLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.cheekThinningLabel.text = @"瘦脸";
        self.cheekThinningLabel.textColor = [UIColor whiteColor];
        self.cheekThinningLabel.textAlignment = NSTextAlignmentCenter;
        self.cheekThinningLabel.font = [NvUtils fontWithSize:12];
        self.eyeEnlargingLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.eyeEnlargingLabel.textColor = [UIColor whiteColor];
        self.eyeEnlargingLabel.textAlignment = NSTextAlignmentCenter;
        self.eyeEnlargingLabel.text = @"大眼";
        self.eyeEnlargingLabel.font = [NvUtils fontWithSize:12];
        [self addSubview:self.strengthLabel];
        [self addSubview:self.cheekThinningLabel];
        [self addSubview:self.eyeEnlargingLabel];
        [self.strengthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(12*SCREANSCALE));
            make.top.equalTo(@(12*SCREANSCALE));
            make.width.equalTo(@(50*SCREANSCALE));
            make.height.equalTo(@(30*SCREANSCALE));
        }];
        [self.cheekThinningLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(12*SCREANSCALE));
            make.top.equalTo(self.strengthLabel.mas_bottom).offset(20*SCREANSCALE);
            make.width.equalTo(@(50*SCREANSCALE));
            make.height.equalTo(@(30*SCREANSCALE));
            
        }];
        [self.eyeEnlargingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(12*SCREANSCALE));
            make.top.equalTo(self.cheekThinningLabel.mas_bottom).offset(20*SCREANSCALE);
            make.width.equalTo(@(50*SCREANSCALE));
            make.height.equalTo(@(30*SCREANSCALE));
            if (@available(iOS 11.0, *)) {
                make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom).offset(-12*SCREANSCALE);
            } else {
                // Fallback on earlier versions
                make.bottom.equalTo(self.mas_bottom).offset(-12*SCREANSCALE);
            }
        }];
        
        self.strengthNum = [[UILabel alloc] initWithFrame:CGRectZero];
        self.strengthNum.textColor = [UIColor whiteColor];
        self.strengthNum.textAlignment = NSTextAlignmentCenter;
        self.strengthNum.text = @"50";
        self.strengthNum.font = [NvUtils fontWithSize:12];
        self.cheekThinningNum = [[UILabel alloc] initWithFrame:CGRectZero];
        self.cheekThinningNum.textColor = [UIColor whiteColor];
        self.cheekThinningNum.textAlignment = NSTextAlignmentCenter;
        self.cheekThinningNum.text = @"50";
        self.cheekThinningNum.font = [NvUtils fontWithSize:12];
        self.eyeEnlargingNum = [[UILabel alloc] initWithFrame:CGRectZero];
        self.eyeEnlargingNum.textColor = [UIColor whiteColor];
        self.eyeEnlargingNum.textAlignment = NSTextAlignmentCenter;
        self.eyeEnlargingNum.text = @"50";
        self.eyeEnlargingNum.font = [NvUtils fontWithSize:12];
        [self addSubview:self.strengthNum];
        [self addSubview:self.cheekThinningNum];
        [self addSubview:self.eyeEnlargingNum];
        [self.strengthNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-18*SCREANSCALE));
            make.centerY.equalTo(self.strengthLabel);
        }];
        [self.cheekThinningNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-18*SCREANSCALE));
            make.centerY.equalTo(self.cheekThinningLabel);
        }];
        [self.eyeEnlargingNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-18*SCREANSCALE));
            make.centerY.equalTo(self.eyeEnlargingLabel);
        }];
        
        self.strengthSlider = [UISlider new];
        [self.strengthSlider setMinimumValue:0.0];
        self.strengthSlider.value = 0.5;
        [self.strengthSlider setMaximumValue:1.0];
        self.strengthSlider.minimumTrackTintColor = [UIColor whiteColor];
        self.strengthSlider.maximumTrackTintColor = [UIColor whiteColor];
        [self.strengthSlider setThumbImage:[NvUtils imageWithName:@"Nvslider"] forState:UIControlStateNormal];
        [self.strengthSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
        self.cheekThinningSlider = [UISlider new];
        [self.cheekThinningSlider setMinimumValue:0.0];
        [self.cheekThinningSlider setMaximumValue:1.0];
        self.cheekThinningSlider.minimumTrackTintColor = [UIColor whiteColor];
        self.cheekThinningSlider.maximumTrackTintColor = [UIColor whiteColor];
        [self.cheekThinningSlider setThumbImage:[NvUtils imageWithName:@"Nvslider"] forState:UIControlStateNormal];
        [self.cheekThinningSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
        self.eyeEnlargingSlider = [UISlider new];
        [self.eyeEnlargingSlider setMinimumValue:0.0];
        [self.eyeEnlargingSlider setMaximumValue:1.0];
        self.eyeEnlargingSlider.minimumTrackTintColor = [UIColor whiteColor];
        self.eyeEnlargingSlider.maximumTrackTintColor = [UIColor whiteColor];
        [self.eyeEnlargingSlider setThumbImage:[NvUtils imageWithName:@"Nvslider"] forState:UIControlStateNormal];
        [self.eyeEnlargingSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:self.strengthSlider];
        [self addSubview:self.cheekThinningSlider];
        [self addSubview:self.eyeEnlargingSlider];

        [self.strengthSlider mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.strengthLabel.mas_right).offset(8*SCREANSCALE);
            make.right.equalTo(self.strengthNum.mas_left).offset(-13*SCREANSCALE);
            make.centerY.equalTo(self.strengthLabel);
        }];
        [self.cheekThinningSlider mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cheekThinningLabel.mas_right).offset(8*SCREANSCALE);
            make.right.equalTo(self.cheekThinningNum.mas_left).offset(-13*SCREANSCALE);
            make.centerY.equalTo(self.cheekThinningLabel);
        }];
        [self.eyeEnlargingSlider mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.eyeEnlargingLabel.mas_right).offset(8*SCREANSCALE);
            make.right.equalTo(self.eyeEnlargingNum.mas_left).offset(-13*SCREANSCALE);
            make.centerY.equalTo(self.eyeEnlargingLabel);
        }];
        
    }
    return self;
}

- (void)setStrength:(float)strength eyeEnlarging:(float)eyeEnlarging cheekThinning:(float)cheekThinning {
    self.strengthNum.text = [NSString stringWithFormat:@"%d",(int)strength*100];
    [self.strengthSlider setValue:strength animated:YES];
    
    self.cheekThinningNum.text = [NSString stringWithFormat:@"%d",(int)eyeEnlarging*100];;
    [self.cheekThinningSlider setValue:eyeEnlarging animated:YES];
    
    self.eyeEnlargingNum.text = [NSString stringWithFormat:@"%d",(int)cheekThinning*100];;
    [self.eyeEnlargingSlider setValue:cheekThinning animated:YES];
}

- (void)sliderValueChanged:(UISlider *)slider {
    if (slider == self.strengthSlider) {
        self.strengthNum.text = [NSString stringWithFormat:@"%d",(int)(slider.value*100)];
        if ([self.delegate respondsToSelector:@selector(slider:valueChanged:)]) {
            [self.delegate slider:0 valueChanged:slider.value];
        }
    } else if (slider == self.eyeEnlargingSlider) {
        self.eyeEnlargingNum.text = [NSString stringWithFormat:@"%d",(int)(slider.value*100)];
        if ([self.delegate respondsToSelector:@selector(slider:valueChanged:)]) {
            [self.delegate slider:1 valueChanged:slider.value];
        }
    } else if (slider == self.cheekThinningSlider) {
        self.cheekThinningNum.text = [NSString stringWithFormat:@"%d",(int)(slider.value*100)];
        if ([self.delegate respondsToSelector:@selector(slider:valueChanged:)]) {
            [self.delegate slider:2 valueChanged:slider.value];
        }
    }
}

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

@end
