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

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

@interface ERTCMemberNetworkSendVideoContentCell ()
@property (nonatomic, strong) UILabel *videoSentBitrateLabel;//视频传输码率(上行)
@property (nonatomic, strong) UILabel *videoSentFrameRateLabel; //帧率大小
@property (nonatomic, strong) UILabel *videoPacketLossRateLabel; //视频丢包率
@property (nonatomic, strong) UILabel *videoStreamTypeLabel; //流类型
@property (nonatomic, strong) UILabel *sizeLabel;//视频宽高
@property (nonatomic, strong) UILabel *videoPacketCountLabel;//发视频总包数
@property (nonatomic, strong) UILabel *videoCompensateLossRateLabel;//补偿后丢包率

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

@implementation ERTCMemberNetworkSendVideoContentCell

-(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.videoSentBitrateLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.videoPacketLossRateLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.videoPacketCountLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.videoCompensateLossRateLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.videoSentFrameRateLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.videoStreamTypeLabel = label;
        
        label = [self getLabel];
        [self.stackView addArrangedSubview:label];
        self.sizeLabel = 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)setLocalVideoStats:(ERTCLocalVideoStatistics *)localVideoStats {
    self.videoSentBitrateLabel.text = [NSString stringWithFormat:@"%d",localVideoStats.videoSentBitrate];
    self.videoPacketLossRateLabel.text = [NSString stringWithFormat:@"%d",localVideoStats.videoPacketLossRate];
    self.videoPacketCountLabel.text = [NSString stringWithFormat:@"%d",localVideoStats.videoPacketCount];
    self.videoCompensateLossRateLabel.text = [NSString stringWithFormat:@"%d",localVideoStats.videoCompensateLossRate];
    self.videoSentFrameRateLabel.text = [NSString stringWithFormat:@"%d",localVideoStats.videoSentFrameRate];
    self.videoStreamTypeLabel.text = [NSString stringWithFormat:@"%d",localVideoStats.videoStreamType];
    self.sizeLabel.text = [NSString stringWithFormat:@"%d \n %d",localVideoStats.width,localVideoStats.heigth];
}

-(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 @"ERTCMemberNetworkSendVideoContentCell";
}
@end
