//
//  ERTCBeautyConfigurationBar.m
//  ERTCDemo
//
//  Created by wangjinlong23 on 2022/8/16.
//

#import "ERTCBeautyConfigurationBar.h"
#import "ERTCBeautyModel.h"
#import "ERTCBeautySkinFilterView.h"
#import "ERTCBeautyBlurFilterView.h"
#import "ERTCBeautySliderView.h"
#import "ERTCBeautyManager.h"
#import "ERTCPlayerViewManager.h"

@interface ERTCBeautyConfigurationBar ()<ERTCBeautySkinFilterViewDelegate, ERTCBeautyBlurFilterViewDelegate>

@property (nonatomic, strong) UIButton *contrastBeautyBtn;

@property (nonatomic, strong) UIImageView *valueTipImageView;
@property (nonatomic, strong) UILabel *valueTipLabel;
@property (nonatomic, strong) ERTCBeautySliderView *slider;
@property (nonatomic, strong) UIImageView *defImageView;

@property (nonatomic, strong) UIButton *beautyBtn;
@property (nonatomic, strong) UIButton *blurBtn;
@property (nonatomic, strong) UIView *selectedLineView;
@property (nonatomic, strong) UIButton *resetBtn;

//美颜资源
@property (nonatomic, strong) ERTCBeautySkinFilterView *beautyFilterView;
@property (nonatomic, strong) NSArray<ERTCBeautyModel *> *beautyModels;

//滤镜资源
@property (nonatomic, strong) ERTCBeautyBlurFilterView *blurFilterView;
@property (nonatomic, strong) NSArray<ERTCBeautyModel *> *blurModels;

//当前选中的滤镜
@property (nonatomic, strong) ERTCBeautyModel *selectedBeautyModel;
@property (nonatomic, strong) ERTCBeautyModel *selectedBlurModel;

@property (nonatomic, strong) NSString *selectedBeautyKey;
@property (nonatomic, strong) NSString *selectedBlurKey;
@property (nonatomic, strong) NSDictionary *cacheFilterDict;

@end

@implementation ERTCBeautyConfigurationBar

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        self.cacheFilterDict = [userDefaults objectForKey:kBeautyConfigurationBarModels];
        NSLog(@"kBeautyConfigurationBarModels cacheFilterDict:%@", self.cacheFilterDict);
        
        [self addChildViews];
        
        /// 美颜与非美颜对比按钮(按下)事件
        [[self.contrastBeautyBtn ysrac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(__kindof UIControl * _Nullable control) {
            ERTCLog(@"关闭美颜");
            [[ERTCPlayerViewManager sharedInstance].engine setBeautyEnabled:NO];
        }];
        
        /// 美颜与非美颜对比按钮(抬起)事件
        [[self.contrastBeautyBtn ysrac_signalForControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside] subscribeNext:^(__kindof UIControl * _Nullable control) {
            [[ERTCPlayerViewManager sharedInstance].engine setBeautyEnabled:YES];
            ERTCLog(@"开启美颜");
        }];
    }
    
    return self;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    if (self.beautyFilterView.hidden == NO) {
        [self updateDefImageViewPos:self.selectedBeautyModel.defaultValue];
    }
    
    if(self.blurFilterView.hidden == NO)
    {
        [self updateDefImageViewPos:self.selectedBlurModel.defaultValue];
    }
}

#pragma mark - Action
-(void)sliderValueDidChanged:(UISlider *)slider {
    NSLog(@"slider value:%f",slider.value);
    if (self.beautyBtn.selected == YES) {
        self.selectedBeautyModel.value = slider.value;
        [ERTCBeautyManager beautyParamValueChange:self.selectedBeautyModel.value type:self.selectedBeautyModel.param];
    } else {
        self.selectedBlurModel.value = slider.value;
        [ERTCBeautyManager filterNameChange:self.selectedBlurModel.filterType filterValueChange:self.selectedBlurModel.value];
    }
}

-(void)beautyBtnClicked:(UIButton *)btn {
    if (self.beautyFilterView.hidden == YES) {
        [UIView transitionWithView:self.beautyFilterView
                          duration:0.5
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^
         {
            self.beautyFilterView.hidden = NO;
            [self updateBeautyViewChangeByModel];
            [self.beautyFilterView reloadFilterView];
        } completion:NULL];
        
        [UIView transitionWithView:self.blurFilterView
                          duration:0.5
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^
         {
            self.blurFilterView.hidden = YES;
        } completion:NULL];

        [self layoutIfNeeded];
        [UIView animateWithDuration:0.5 animations:^{
            [self.selectedLineView ysmas_updateConstraints:^(YSMASConstraintMaker *make) {
                make.left.equalTo(self.beautyBtn).with.offset(0);
            }];
    
            [self layoutIfNeeded];
        }];
    }
    
    self.beautyBtn.selected = YES;
    self.blurBtn.selected = NO;
    self.resetBtn.hidden = NO;
}

-(void)blurBtnClicked:(UIButton *)btn {
    if (self.blurFilterView.hidden == YES) {
        [UIView transitionWithView:self.blurFilterView
                          duration:0.5
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^
         {
            self.blurFilterView.hidden = NO;
            [self updateBlurViewChangeByModel];
            [self.blurFilterView reloadFilterView];
        } completion:NULL];
        
        [UIView transitionWithView:self.beautyFilterView
                          duration:0.5
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^
         {
            self.beautyFilterView.hidden = YES;
        } completion:NULL];
        
        [self layoutIfNeeded];
        [UIView animateWithDuration:0.5 animations:^{
            [self.selectedLineView ysmas_updateConstraints:^(YSMASConstraintMaker *make) {
                make.left.equalTo(self.beautyBtn).with.offset(55);
            }];
    
            [self layoutIfNeeded];
        }];
    }
    
    self.blurBtn.selected = YES;
    self.beautyBtn.selected = NO;
    self.resetBtn.hidden = YES;
}

-(void)resetBtnClicked:(UIButton *)btn {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认恢复为默认效果吗？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    @WeakObj(self);
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        @StrongObj(self);
        [self setupBeautyFilters];
        [self setCacheFilterConfig];
        self.beautyFilterView.models = self.beautyModels;
        self.blurFilterView.models = self.blurModels;
    }];
    
    [alertC addAction:cancelAction];
    [alertC addAction:confirmAction];
    
    [self.vc presentViewController:alertC animated:YES completion:nil];
}

#pragma mark - 数据源变更
-(void)setSelectedBeautyModel:(ERTCBeautyModel *)selectedBeautyModel {
    _selectedBeautyModel.selected = NO;
    _selectedBeautyModel = selectedBeautyModel;
    _selectedBeautyModel.selected = YES;
    
    [self updateBeautyViewChangeByModel];
}

-(void)setSelectedBlurModel:(ERTCBeautyModel *)selectedBlurModel {
    _selectedBlurModel.selected = NO;
    _selectedBlurModel = selectedBlurModel;
    _selectedBlurModel.selected = YES;
    
    if ([self.selectedBlurModel.titleKey isEqualToString:kERTCBlur_noneKey]) {
//        [ERTCBeautyManager filterNameChange:self.selectedBlurModel.filterType];
    }
    else
    {
//        [ERTCBeautyManager filterNameChange:self.selectedBlurModel.filterType];
//        [ERTCBeautyManager filterValueChange:self.selectedBlurModel.value];
    }
    
    [self updateBlurViewChangeByModel];
}

-(void)setVc:(UIViewController *)vc {
    _vc = vc;
    [self setupBeautyFilters];
    [self setupBlurFilters];
    [self loadCacheFilter];
//    [self setCacheFilterConfig];
    self.beautyFilterView.models = self.beautyModels;
    self.blurFilterView.models = self.blurModels;
}

-(void)updateDefImageViewPos:(double)value {
    CGFloat offset = CGRectGetWidth(self.slider.bounds)*value - CGRectGetWidth(self.defImageView.frame)/2.f;
    [self.defImageView ysmas_updateConstraints:^(YSMASConstraintMaker *make) {
        make.left.equalTo(self.slider).with.offset(offset);
    }];
}

-(void)updateBeautyViewChangeByModel {
    if ([self.selectedBeautyModel.titleKey isEqualToString:kBeauty_noneKey]) {
        self.slider.hidden = YES;
        self.defImageView.hidden = YES;
        
        [self.beautyModels enumerateObjectsUsingBlock:^(ERTCBeautyModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.value = 0;
//            [ERTCBeautyManager filterNameChange:obj.filterType];
            [ERTCBeautyManager beautyParamValueChange:obj.value type:obj.param];
        }];
    } else {
        self.slider.hidden = NO;
        self.defImageView.hidden = NO;
        
//        [ERTCBeautyManager filterNameChange:self.selectedBeautyModel.filterType];
        
        self.slider.value = self.selectedBeautyModel.value;
        [ERTCBeautyManager beautyParamValueChange:self.selectedBeautyModel.value type:self.selectedBeautyModel.param];
        
        [self updateDefImageViewPos:self.selectedBeautyModel.defaultValue];
    }
}

-(void)updateBlurViewChangeByModel {
    if (self.blurFilterView.hidden == NO) {
        if ([self.selectedBlurModel.titleKey isEqualToString:kERTCBlur_noneKey]) {
            self.slider.hidden = YES;
            self.defImageView.hidden = YES;
            [ERTCBeautyManager filterNameChange:self.selectedBlurModel.filterType filterValueChange:self.selectedBlurModel.value];
        } else {
            self.slider.hidden = NO;
            self.defImageView.hidden = NO;
            
            self.slider.value = self.selectedBlurModel.value;
            [ERTCBeautyManager filterNameChange:self.selectedBlurModel.filterType filterValueChange:self.selectedBlurModel.value];
            
            [self updateDefImageViewPos:self.selectedBlurModel.defaultValue];
        }
    }
}

#pragma mark - BeautySkinFilterViewDelegate
/// 开启美颜
- (void)filterSkinViewDidSelectedFilter:(ERTCBeautyModel *)param filterView:(ERTCBeautySkinFilterView *)filterView {
    self.selectedBeautyModel = param;
    [self.beautyFilterView reloadFilterView];
}

#pragma mark - BeautyBlurFilterViewDelegate
/// 开启滤镜
- (void)filterBlurViewDidSelectedFilter:(ERTCBeautyModel *)param filterView:(ERTCBeautyBlurFilterView *)filterView {
    self.selectedBlurModel = param;
    [self.blurFilterView reloadFilterView];
}

#pragma mark - 初始化滤镜
-(void)setupBeautyFilters {
    self.beautyModels = [ERTCBeautyManager loadBeautyFilters];
//    self.selectedBeautyModel = self.beautyModels[1];
}
    
-(void)setupBlurFilters {
    self.blurModels = [ERTCBeautyManager loadBlurFilters];
//    self.selectedBlurModel = self.blurModels[1];
}

-(void)loadCacheFilter {
    NSString *selectBeautyKey = self.cacheFilterDict[kSelectedBeautyKey];
    NSString *selectBlurKey = self.cacheFilterDict[kSelectedBlurKey];
    
    [self.beautyModels enumerateObjectsUsingBlock:^(ERTCBeautyModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *key = obj.titleKey;
        if (self.cacheFilterDict[key]) {
            obj.value = [self.cacheFilterDict[key] floatValue];
        }
        
        if ([key isEqualToString:selectBeautyKey]) {
            self.selectedBeautyModel = obj;
        }
    }];
    
    [self.blurModels enumerateObjectsUsingBlock:^(ERTCBeautyModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *key = obj.titleKey;
        if (self.cacheFilterDict[key]) {
            obj.value = [self.cacheFilterDict[key] floatValue];
        }
        
        if ([key isEqualToString:selectBlurKey]) {
            self.selectedBlurModel = obj;
        }
    }];
}

-(void)saveCacheFilter {
    NSMutableDictionary *beautyDict = [NSMutableDictionary dictionary];
    [self.beautyModels enumerateObjectsUsingBlock:^(ERTCBeautyModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [beautyDict setValue:@(obj.value) forKey:obj.titleKey];
    }];
    
    if (self.selectedBeautyModel) {
        [beautyDict setValue:self.selectedBeautyModel.titleKey forKey:kSelectedBeautyKey];
    }
    
    if (self.selectedBlurModel) {
        [beautyDict setValue:@(self.selectedBlurModel.value) forKey:self.selectedBlurModel.titleKey];
        [beautyDict setValue:self.selectedBlurModel.titleKey forKey:kSelectedBlurKey];
    }
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:beautyDict forKey:kBeautyConfigurationBarModels];
    [userDefaults synchronize];
}

-(void)setCacheFilterConfig {
    [self.beautyModels enumerateObjectsUsingBlock:^(ERTCBeautyModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (![obj.titleKey isEqualToString:kBeauty_noneKey]) {
//            [ERTCBeautyManager filterNameChange:obj.filterType];
            [ERTCBeautyManager filterNameChange:obj.filterType filterValueChange:obj.value];
            [ERTCBeautyManager beautyParamValueChange:obj.value type:obj.param];
        }
    }];
}

#pragma mark - UISlider
-(CGRect)thumbRectInView:(UISlider *)slider defValue:(CGFloat)defValue {
    CGRect trackRect = [slider trackRectForBounds:slider.bounds];
    CGRect thumbRect = [slider thumbRectForBounds:slider.bounds trackRect:trackRect value:defValue];
    return [self convertRect:thumbRect fromView:slider];
}

-(CGRect)thumbRectInView:(UISlider *)slider {
    CGRect trackRect = [slider trackRectForBounds:slider.bounds];
    CGRect thumbRect = [slider thumbRectForBounds:slider.bounds trackRect:trackRect value:slider.value];
    return [self convertRect:thumbRect fromView:slider];
}

-(void)dragged:(UISlider *)slider {
    CGRect rectInView = [self thumbRectInView:slider];
    CGPoint center = CGPointMake(CGRectGetMidX(rectInView), CGRectGetMidY(rectInView));
    [self updateThumbLbl:slider.value center:center];
}

-(void)updateThumbLbl:(CGFloat)value center:(CGPoint)center {
    NSLog(@"updateThumbLbl %@, %f", NSStringFromCGPoint(center), value);
    self.valueTipLabel.text = [NSString stringWithFormat:@"%d",(int)(value * 100)];
    
    CGFloat x = center.x - CGRectGetWidth(self.valueTipImageView.frame)/2.f;
    [self.valueTipImageView ysmas_updateConstraints:^(YSMASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(x);
    }];
}

-(void)updateBeautyEnabled {
//    self.contrastBeautyBtn.hidden = ![VCSBeautyManager sharedManager].beautyEnabled;
}

#pragma mark - UI Method
-(void)addChildViews {
    //美颜效果对比按钮
    [self addSubview:self.contrastBeautyBtn];
    
    /// 添加Slider
    [self addSubview:self.slider];
    
    /// 事件监听
    [self.slider addTarget:self action:@selector(sliderValueDidChanged:) forControlEvents:UIControlEventValueChanged];
    
    //slider 默认位置图
    UIImage *image = [UIImage imageNamed:@"img_dot_18x18"];
    self.defImageView = [[UIImageView alloc] initWithImage:image];
    [self addSubview:self.defImageView];
    
    //滑动条当前值
    image = [UIImage imageNamed:@"bu_number"];
    self.valueTipImageView = [[UIImageView alloc] initWithImage:image];
    [self addSubview:self.valueTipImageView];

    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    label.textColor = [UIColor colorWithRed:62/255.0 green:128/255.0 blue:255/255.0 alpha:1/1.0];
    self.valueTipLabel = label;
    [self.valueTipImageView addSubview:self.valueTipLabel];
    
    //背景视图
    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor colorWithRed:9/255.0 green:13/255.0 blue:20/255.0 alpha:0.75];
    [self addSubview:bgView];
    
    //模块切换按钮
    [self addSubview:self.beautyBtn];
    [self addSubview:self.blurBtn];
    [self addSubview:self.selectedLineView];
    [self addSubview:self.resetBtn];
    
    //美颜模块
    self.beautyFilterView = [[ERTCBeautySkinFilterView alloc] init];
    self.beautyFilterView.delegate = self;
    [self addSubview:self.beautyFilterView];
    
    //滤镜模块
    self.blurFilterView = [[ERTCBeautyBlurFilterView alloc] init];
    self.blurFilterView.delegate = self;
    self.blurFilterView.hidden = YES;
    [self addSubview:self.blurFilterView];
    
    [self updateBeautyEnabled];
    [self.contrastBeautyBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.top.equalTo(self);
        make.right.equalTo(kSafeMasRight(self)).with.offset(-15);
        make.height.width.ysmas_equalTo(40);
    }];
    
    [self.slider ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.top.equalTo(self.contrastBeautyBtn.ysmas_bottom).with.offset(26);
        make.left.equalTo(self).with.offset(48);
        make.right.equalTo(self).with.offset(-48);
    }];
    
    [self.defImageView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.size.ysmas_equalTo(18);
        make.left.equalTo(self.slider);
        make.bottom.equalTo(self.slider.ysmas_top).with.offset(12);
    }];
    
    [self.valueTipImageView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.width.ysmas_equalTo(28);
        make.height.ysmas_equalTo(29);
        make.bottom.equalTo(self.slider.ysmas_top).with.offset(-13);
        make.left.equalTo(self);
    }];
    
    [self.valueTipLabel ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.center.equalTo(self.valueTipImageView);
    }];
    
    [bgView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.top.equalTo(self.beautyBtn).with.offset(-17);
        make.left.right.bottom.equalTo(self);
    }];
    
    [self.beautyBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.top.equalTo(self.slider.ysmas_bottom).with.offset(37);
        make.left.equalTo(kSafeMasLeft(self)).with.offset(21);
        make.width.ysmas_equalTo(35);
        make.height.ysmas_equalTo(30);
    }];
    
    [self.blurBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.centerY.equalTo(self.beautyBtn);
        make.left.equalTo(self.beautyBtn.ysmas_right).with.offset(20);
        make.width.height.equalTo(self.beautyBtn);
    }];
    
    [self.selectedLineView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.left.equalTo(self.beautyBtn).with.offset(0);
        make.width.equalTo(self.beautyBtn);
        make.top.equalTo(self.beautyBtn.ysmas_bottom).with.offset(2);
        make.height.ysmas_equalTo(2);
    }];
    
    [self.resetBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.centerY.equalTo(self.beautyBtn);
        make.right.equalTo(kSafeMasRight(self)).with.offset(-16);
    }];
    
    [self.beautyFilterView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.top.equalTo(self.beautyBtn.ysmas_bottom).with.offset(10);
        make.left.equalTo(kSafeMasLeft(self)).with.offset(11);
        make.right.equalTo(kSafeMasRight(self)).with.offset(-11);
        make.bottom.equalTo(kSafeMasBottom(self));
        make.height.ysmas_equalTo(174);
    }];
    
    [self.blurFilterView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.edges.equalTo(self.beautyFilterView);
    }];
    
    self.beautyBtn.selected = YES;
    [self.slider addTarget:self action:@selector(dragged:) forControlEvents:(UIControlEventTouchDragInside)];
    self.valueTipImageView.hidden = YES;
    self.slider.tipImageView = self.valueTipImageView;
}

-(UIButton *)contrastBeautyBtn {
    if (!_contrastBeautyBtn) {
        _contrastBeautyBtn = [[UIButton alloc] init];
        _contrastBeautyBtn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        _contrastBeautyBtn.layer.cornerRadius = 20;
        UIImage *image = [UIImage imageNamed:@"icn_contrast"];
        [_contrastBeautyBtn setImage:image forState:(UIControlStateNormal)];
    }
    
    return _contrastBeautyBtn;
}

-(ERTCBeautySliderView *)slider {
    if (!_slider) {
        /// 创建Slider 设置Frame
        _slider = [[ERTCBeautySliderView alloc] init];
    }
    
    return _slider;
}

-(UIButton *)beautyBtn {
    if (!_beautyBtn) {
        _beautyBtn = [[UIButton alloc] init];
        _beautyBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_beautyBtn setTitle:@"美颜" forState:(UIControlStateNormal)];
        [_beautyBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1/1.0] forState:(UIControlStateNormal)];
        [_beautyBtn addTarget:self action:@selector(beautyBtnClicked:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    
    return _beautyBtn;
}

-(UIButton *)blurBtn {
    if (!_blurBtn) {
        _blurBtn = [[UIButton alloc] init];
        _blurBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_blurBtn setTitle:@"滤镜" forState:(UIControlStateNormal)];
        [_blurBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1/1.0] forState:(UIControlStateNormal)];
        [_blurBtn addTarget:self action:@selector(blurBtnClicked:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    
    return _blurBtn;
}

-(UIView *)selectedLineView {
    if (!_selectedLineView) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor colorWithRed:62/255.0 green:128/255.0 blue:255/255.0 alpha:1/1.0];
        _selectedLineView = view;
    }
    
    return _selectedLineView;
}

-(UIButton *)resetBtn {
    if (!_resetBtn) {
        _resetBtn = [[UIButton alloc] init];
        [_resetBtn setTitle:@"重置" forState:(UIControlStateNormal)];
        [_resetBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [_resetBtn addTarget:self action:@selector(resetBtnClicked:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    
    return _resetBtn;
}

-(void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}



@end
