//
//  ERTCMemberNetworkSendAudioContentCell.m
//  EZSaaSVideoConferenceSDK
//
//  Created by wangjinlong23 on 2022/6/23.
//  Copyright © 2022 EZSaaS. All rights reserved.
//

#import "ERTCMemberNetworkSendAudioContentCell.h"
#import <ERTC/ERTCStatistics.h>

@interface ERTCMemberNetworkSendAudioContentCell ()
@property (nonatomic, strong) UILabel *audioSentBitrateLabel;//音频传输码率
@property (nonatomic, strong) UILabel *audioPacketLossRateLabel;//音频丢包率
@property (nonatomic, strong) UILabel *audioPacketCountLable;//发音频总包数

@property (nonatomic, strong) UIStackView *stackView;
@end

@implementation ERTCMemberNetworkSendAudioContentCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.stackView];

        UILabel *label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.audioSentBitrateLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.audioPacketCountLable = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.audioPacketLossRateLabel = label;
   
        [self.stackView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView).with.offset(-1);
        }];
    }
    
    return self;
}

- (void)setLocalAudioStats:(ERTCLocalAudioStatistics *)localAudioStas {
    self.audioSentBitrateLabel.text = [NSString stringWithFormat:@"%d",localAudioStas.audioSentBitrate];
    self.audioPacketCountLable.text = [NSString stringWithFormat:@"%d",localAudioStas.audioPacketCount];
    self.audioPacketLossRateLabel.text = [NSString stringWithFormat:@"%d",localAudioStas.audioPacketLossRate];
}

-(UIStackView *)stackView {
    if (!_stackView) {
        _stackView = [[UIStackView alloc] init];
        _stackView.backgroundColor = [UIColor clearColor];
        _stackView.spacing = 1;
        _stackView.distribution = UIStackViewDistributionFillEqually;
        _stackView.layer.cornerRadius = 5;
    }
    
    return _stackView;
}

-(UILabel *)getLabel {
    UILabel *label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor colorWithRed:131/255.f green:131/255.f blue:131/255.f alpha:0.55];//[UIColor whiteColor];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:15];
    label.textAlignment = NSTextAlignmentCenter;
    return label;
}

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

@end
