//
//  ERTCVideoMeetingMinePlayerView.m
//  ERTCDemo
//
//  Created by wangjinlong23 on 2022/5/13.
//

#import "ERTCVideoMeetingMinePlayerView.h"
#import "ERTCSmallPlayerStatusView.h"

@interface ERTCVideoMeetingMinePlayerView ()
@property (nonatomic, strong) ERTCSmallPlayerStatusView *statusView;
@end

@implementation ERTCVideoMeetingMinePlayerView
-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor blackColor];
        self.isShowMine = YES;
        [self addSubview:self.statusView];
        [self.statusView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)];
        [self addGestureRecognizer:tapGes];
    }
    return self;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    self.size = self.frame.size;
}

- (void)setPlayInfoModel:(ERTCUserInfo *)playInfoModel {
    _playInfoModel = playInfoModel;
    [self setNeedsLayout];
}

- (void)onMemberInfoUpdate:(ERTCUserInfo *)notifyModel {
    if (![notifyModel.uid isEqualToString:self.playInfoModel.uid]) return;
    [self.statusView onMemberInfoUpdate:notifyModel isSmall:!self.isBigView];
}

-(void)setIsBigView:(BOOL)isBigView {
    _isBigView = isBigView;
    if (isBigView == YES) {
        self.userInteractionEnabled = NO;
    } else {
        self.userInteractionEnabled = YES;
    }
}

-(void)hiddenTopBottomView {
    [self.statusView hiddenTopBottomView];
}

-(void)showTopBottomView {
    [self.statusView showTopBottomView];
}


-(void)setTopView:(UIView *)topView {
    _topView = topView;
    [self.statusView ysmas_makeConstraints:^(YSMASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    self.statusView.topView = topView;
}

-(void)tapView:(UITapGestureRecognizer *)tapGes {
    if ([self.delegate respondsToSelector:@selector(didClickMinePlayerView:tapGes:)]) {
        [self.delegate didClickMinePlayerView:self.isBigView tapGes:tapGes];
    }
}

-(ERTCSmallPlayerStatusView *)statusView {
    if (!_statusView) {
        _statusView = [ERTCSmallPlayerStatusView new];
        _statusView.userInteractionEnabled = NO;
    }
    
    return _statusView;
}

-(void)dealloc {
    NSLog(@"ERTCVideoMeetingMinePlayerView dealloc");
}



@end
