//
//  EZSaaSVideoCMineVoiceExcitationTableViewCell.m
//  ERTCDemo
//
//  Created by wangjinlong23 on 2022/9/20.
//

#import "EZSaaSVideoCMineVoiceExcitationTableViewCell.h"

@interface EZSaaSVideoCMineVoiceExcitationTableViewCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UISwitch *switchBtn;
@property (nonatomic, strong) UIView *lineView;
@end

@implementation EZSaaSVideoCMineVoiceExcitationTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor YSSystemBackgroundWhiteColor];
        
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.switchBtn];
        [self.contentView addSubview:self.lineView];
        
        self.switchBtn.on = YES;
        [self.switchBtn addTarget:self action:@selector(valueChanged:) forControlEvents:(UIControlEventValueChanged)];
        
        [self.nameLabel ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(16);
            make.right.lessThanOrEqualTo(self.switchBtn.ysmas_left).with.offset(-5);
            make.centerY.equalTo(self.contentView);
        }];
        
        [self.switchBtn ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.right.equalTo(self.contentView).with.offset(-15);
            make.centerY.equalTo(self.contentView);
        }];
        
        [self.lineView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.height.ysmas_equalTo(0.5f);
            make.left.equalTo(self.contentView).with.offset(20);
            make.right.bottom.equalTo(self.contentView);
        }];
        
        [self.switchBtn setContentCompressionResistancePriority:(UILayoutPriorityRequired) forAxis:(UILayoutConstraintAxisHorizontal)];
        [self.switchBtn setContentHuggingPriority:(UILayoutPriorityRequired) forAxis:(UILayoutConstraintAxisHorizontal)];
    }
    
    return self;
}

-(void)valueChanged:(UISwitch *)switchBtn
{
//    [EZSaaSCommonCacheManager sharedManager].enableAudioExcitation = switchBtn.on;
    if (self.resultBlock) {
        self.resultBlock(switchBtn.on);
    }
}

-(void)configCell:(NSString *)cellName select:(BOOL)select showLine:(BOOL)showLine
{
    self.nameLabel.text = cellName;
    self.switchBtn.on = select;
    self.lineView.hidden = !showLine;
}

#pragma mark - UI Getter Method
-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.text = @"语音激励";
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textColor = [UIColor YSSystemBlackColor];
    }
    
    return _nameLabel;
}

-(UISwitch *)switchBtn
{
    if (!_switchBtn) {
        _switchBtn = [[UISwitch alloc] init];
        _switchBtn.onTintColor = [UIColor colorWithRed:(0x3E/255.f) green:(0x80/255.f) blue:(0xFF/255.f) alpha:1];
    }
    
    return _switchBtn;
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor YSInputColor];
    }
    
    return _lineView;
}

+(NSString *)cellReuseId
{
    return @"EZSaaSVideoCMineVoiceExcitationTableViewCellSID";
}

@end
