//
//  NvFilterStrength.m
//  SDKDemo
//
//  Created by 刘东旭 on 2018/7/19.
 //
//

#import "NvFilterStrength.h"
#include "NVHeader.h"

@interface NvFilterStrength()

@property (nonatomic, strong)UIView *bottomLine;
@property (nonatomic, strong)UILabel *strengthLabel;
@property (nonatomic, strong)UISlider *strengthSlider;

@end

@implementation NvFilterStrength

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = UIColorFromRGB(0x242728);
        self.bottomLine = [UIView new];
        [self addSubview:self.bottomLine];
        [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(@0);
            make.height.equalTo(@1);
        }];
        
        self.strengthLabel = [UILabel nv_labelWithText:@"强度" fontSize:15 textColor:UIColor.whiteColor];
        [self addSubview:self.strengthLabel];
        [self.strengthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(15*SCREANSCALE));
            make.bottom.equalTo(@(-15*SCREANSCALE));
            make.top.equalTo(@(15*SCREANSCALE));
        }];
        
        self.strengthSlider = [UISlider new];
        self.strengthSlider.value = 1;
        [self.strengthSlider setThumbImage:[NvUtils imageWithName:@"NvVolum30"] forState:UIControlStateNormal];
        self.strengthSlider.minimumTrackTintColor = [UIColor whiteColor];
        self.strengthSlider.maximumTrackTintColor = [UIColor whiteColor];
        [self.strengthSlider addTarget:self action:@selector(strengthValueChange:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:self.strengthSlider];
        [self.strengthSlider mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.strengthLabel.mas_right).equalTo(@(26*SCREANSCALE));
            make.right.equalTo(self).equalTo(@(-12*SCREANSCALE));
            make.centerY.equalTo(self);
        }];
    }
    return self;
}

- (void)strengthValueChange:(UISlider *)slider {
    if ([self.delegate respondsToSelector:@selector(filterStrengthValueChange:)]) {
        [self.delegate filterStrengthValueChange:slider.value];
    }
}

- (void)setFilterStrengthValue:(float)value {
    self.strengthSlider.value = value;
}

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

@end
