//
//  ERTCMoreTipView.m
//  EZSaaSVideoConferenceSDK
//
//  Created by wangjinlong23 on 2022/7/15.
//  Copyright © 2022 EZSaaS. All rights reserved.
//

#import "ERTCMoreTipView.h"

@interface ERTCMoreTipView ()

@property (nonatomic, strong) UIView *tapView;

@property (nonatomic, strong) UIButton *beautyButton;

@property (nonatomic, strong) UIButton *settingButton;
@end

@implementation ERTCMoreTipView

-(instancetype)init {
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.tapView];

        [self.tapView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];

        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelTipView:)];
        [self.tapView addGestureRecognizer:tapGes];

        
        self.beautyButton = [self getBtnImageName:@"icn_beauty" title:@"美颜"
                                  selectImageName:@"" selectTitle:@""
                                 disableImageName:@"" disableTitle:@""];
        
        [self addSubview:self.beautyButton];
        [self.beautyButton addTarget:self action:@selector(clickBeautyButtonView:) forControlEvents:(UIControlEventTouchUpInside)];

        
        self.settingButton = [self getBtnImageName:@"icn_setting_more" title:@"设置"
                                  selectImageName:@"" selectTitle:@""
                                 disableImageName:@"" disableTitle:@""];
        
        [self.settingButton addTarget:self action:@selector(clickSettingTipView:) forControlEvents:(UIControlEventTouchUpInside)];

        [self addSubview:self.beautyButton];
        [self addSubview:self.settingButton];
        
        [self.beautyButton ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.width.height.ysmas_equalTo(76);
            make.centerY.equalTo(self.settingButton);
            make.right.equalTo(self.settingButton.ysmas_left).with.offset(-14);
        }];
        
        [self.settingButton ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.width.height.ysmas_equalTo(76);
            make.right.equalTo(kSafeMasRight(self)).with.offset(-10);
            make.bottom.equalTo(self).with.offset(-10);
        }];
    }

    return self;
}


-(void)cancelMoreTipView {
    [self cancelTipView:nil];
}

#pragma mark - UITapGestureRecognizer
-(void)cancelTipView:(UITapGestureRecognizer *)tapGes {
    self.hidden = YES;
    [self removeFromSuperview];
}

-(void)tapLabel:(UITapGestureRecognizer *)tapGes {
    [self cancelTipView:nil];
}

-(void)clickBeautyButtonView:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(clickBeautyTipView:)]) {
        [self.delegate clickBeautyTipView:self];
    }

    [self cancelTipView:nil];
}

-(void)clickSettingTipView:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(clickSettingModelTipView:)]) {
        [self.delegate clickSettingModelTipView:self];
    }

    [self cancelTipView:nil];
}

#pragma mark - UI Getter Method
-(UIButton *)settingButton {
    if (!_settingButton) {
        _settingButton = [[UIButton alloc] init];
        [_settingButton setImage:[UIImage imageNamed:@"shezhi1"] forState:(UIControlStateNormal)];
    }

    return _settingButton;
}

-(UIView *)tapView {
    if (!_tapView) {
        _tapView = [UIView new];
        _tapView.backgroundColor = [UIColor clearColor];
    }

    return _tapView;
}

-(UIButton *)getBtnImageName:(NSString *)imageName
                       title:(NSString *)title
             selectImageName:(NSString *)selectImageName
                 selectTitle:(NSString *)selectTitle
            disableImageName:(NSString *)disableImageName
                disableTitle:(NSString *)disableTitle {
    UIButton *btn = [[UIButton alloc] init];
    UIView *centerView = [UIView new];
    centerView.backgroundColor = [UIColor clearColor];
    centerView.userInteractionEnabled = NO;
    
    UIButton *imageBtn = [[UIButton alloc] init];
    imageBtn.backgroundColor = [UIColor clearColor];
    [imageBtn setImage:[UIImage imageNamed:imageName]
              forState:(UIControlStateNormal)];
    [imageBtn setImage:[UIImage imageNamed:selectImageName]
              forState:(UIControlStateSelected)];
    [imageBtn setImage:[UIImage imageNamed:disableImageName]
              forState:(UIControlStateDisabled)];
    imageBtn.userInteractionEnabled = NO;
    imageBtn.tag = 9998;
    [centerView addSubview:imageBtn];
    
    UIButton *titleBtn = [[UIButton alloc] init];
    [titleBtn setTitle:title forState:(UIControlStateNormal)];
    [titleBtn setTitle:selectTitle forState:(UIControlStateSelected)];
    [titleBtn setTitle:disableTitle forState:(UIControlStateDisabled)];
    titleBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    [titleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    titleBtn.userInteractionEnabled = NO;
    titleBtn.tag = 9999;
    [centerView addSubview:titleBtn];
    [btn addSubview:centerView];
    
    [centerView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.width.ysmas_equalTo(30);
        make.center.equalTo(btn);
    }];
    
    [imageBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.top.equalTo(centerView);
        make.bottom.equalTo(titleBtn.ysmas_top).with.offset(-0.5);
        make.centerX.equalTo(centerView);
        make.width.height.ysmas_equalTo(30);
    }];
    
    [titleBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.bottom.equalTo(centerView);
        make.centerX.equalTo(centerView);
        make.height.ysmas_equalTo(14);
    }];
    
    btn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    btn.layer.cornerRadius = 10;

    return btn;
}

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