//
//  XPRoomInfoView.m
//  xplan-ios
//
//  Created by 冯硕 on 2021/10/11.
//

#import "RoomHeaderView.h"
///Third
#import <NIMSDK/NIMSDK.h>
#import <Masonry/Masonry.h>
#import <MarqueeLabel.h>
#import <YYText/YYLabel.h>
#import "TTPopup.h"
///Tool
#import "UIImage+Utils.h"
#import "UIButton+EnlargeTouchArea.h"
#import "XPMacro.h"
#import "ThemeColor+Room.h"
#import "TTPopup.h"
#import "XCHUDTool.h"
#import "XPHtmlUrl.h"
#import "ApiHost.h"
#import "AccountInfoStorage.h"
#import "HttpRequestHelper.h"
#import "DESEncrypt.h"
#import "XPConstant.h"
#import "Api+Room.h"
#import "Api+RoomSetting.h"
///Model
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
#import "AttachMentModel.h"
#import "LittleGameInfoModel.h"
///View
#import "XPShareView.h"
#import "XPRoomLittleGameListView.h"
///VC
#import "XPWebViewcontroller.h"
#import "XPRoomOnLineViewController.h"

@interface RoomHeaderView ()<XCShareViewDelegate, XPRoomLittleGameListViewDelegate>
///返回按钮
@property (nonatomic,strong) UIButton *backButton;
///容器
@property (nonatomic,strong) UIStackView *nickStackView;
///
@property (nonatomic,strong) UIStackView *titleStackView;
///房间名字
@property (nonatomic,strong) MarqueeLabel *titleLabel;
///礼物特效
@property (nonatomic,strong) UIImageView *giftEffectImageView;
///锁房标识
@property (nonatomic,strong) UIImageView *lockRoomImageView;
///
@property (nonatomic,strong) UIStackView *onlineStackView;
///绿色的小圆点
@property (nonatomic,strong) UIView * greenDotView;
///id和在线人数
@property (nonatomic,strong) YYLabel *idLabel;
///收藏
@property (nonatomic,strong) UIButton *collectButton;
///分享
@property (nonatomic,strong) UIButton *shareButton;
///设置
@property (nonatomic,strong) UIButton *settingButton;
///显示游戏的切换
@property (nonatomic,strong) XPRoomLittleGameListView *gameListView;

@property (nonatomic, weak) id<RoomHostDelegate> hostDelegate;

@end

@implementation RoomHeaderView

- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
	self = [super init];
	if (self) {
        _hostDelegate = delegate;
		[self initSubViews];
		[self initSubViewConstraints];
	}
	return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
	//将当前tabbar的触摸点转换坐标系，转换到中间按钮的身上，生成一个新的点
	CGPoint newP = [self convertPoint:point toView:self.gameListView.tableView];
	if ([self.gameListView.tableView pointInside:newP withEvent:event]) {
		return self.gameListView.tableView;
	}
	return [super hitTest:point withEvent:event];
}
#pragma mark - Event Response
- (void)backButtonAction:(UIButton *)sender {
    [self.hostDelegate miniRoom];
}

- (void)shareButtonAction:(UIButton *)sender{
	[self showSharePanel];
}

- (void)settingButtonAction:(UIButton *)sender {
    TTActionSheetConfig *exitRoom = [TTActionSheetConfig normalTitle:@"退出房间" clickAction:^{
        [self.hostDelegate exitRoom];
    }];
    
    TTActionSheetConfig *reportRoom = [TTActionSheetConfig normalTitle:@"举报房间" clickAction:^{
	XPWebViewController * webVC = [[XPWebViewController alloc] init];
		NSString *urlstr = [NSString stringWithFormat:@"%@?reportUid=%ld&source=ROOM", URLWithType(kReportRoomURL),self.hostDelegate.getRoomInfo.uid];
		webVC.url = urlstr;
		[[self.hostDelegate getCurrentNav] pushViewController:webVC animated:YES];
    }];
    
    [TTPopup actionSheetWithItems:@[exitRoom, reportRoom]];
}

- (void)onlineTapRecognizer {
	XPRoomOnLineViewController * onlineVC = [[XPRoomOnLineViewController alloc] initWithDelegate:self.hostDelegate];
	[self.hostDelegate.getCurrentNav pushViewController:onlineVC animated:YES];
}
#pragma mark - Private Method
- (void)initSubViews {
	[self addSubview:self.backButton];
	[self addSubview:self.nickStackView];
	[self addSubview:self.collectButton];
	[self addSubview:self.shareButton];
	[self addSubview:self.settingButton];
	
	[self.nickStackView addArrangedSubview:self.titleStackView];
	[self.nickStackView addArrangedSubview:self.onlineStackView];
	
	[self.onlineStackView addArrangedSubview:self.greenDotView];
	[self.onlineStackView addArrangedSubview:self.idLabel];
	
	[self.titleStackView addArrangedSubview:self.titleLabel];
	[self.titleStackView addArrangedSubview:self.giftEffectImageView];
	[self.titleStackView addArrangedSubview:self.lockRoomImageView];
}

- (void)initSubViewConstraints {
	[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self).offset(14);
		make.bottom.equalTo(self).offset(-14);
		make.height.width.equalTo(@22);
	}];
	
	// 设置
	[self.settingButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.mas_equalTo(-14);
		make.centerY.mas_equalTo(self.backButton);
		make.width.height.mas_equalTo(20);
	}];
	
	[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(self.settingButton.mas_left).offset(-17);
		make.centerY.mas_equalTo(self.backButton);
		make.width.height.mas_equalTo(20);
	}];
	
	[self.collectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.backButton);
		make.left.equalTo(self.nickStackView.mas_right).offset(5);
		make.width.mas_equalTo(@53);
		make.height.mas_equalTo(@22);
	}];
	
	[self.nickStackView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.mas_equalTo(self.backButton);
		make.left.mas_equalTo(self.backButton.mas_right).offset(10);
	}];
	
	[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.width.mas_lessThanOrEqualTo(100);
	}];

	[self.greenDotView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.mas_equalTo(CGSizeMake(3,3));
	}];
	
	[self.giftEffectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.mas_equalTo(CGSizeMake(10,10));
	}];
	
	[self.lockRoomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.mas_equalTo(CGSizeMake(10,10));
	}];
}

- (void)configLittleGameState {
	RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
	if (roomInfo.isPermitRoom != PermitRoomType_Licnese && roomInfo.roomModeType != RoomModeType_Open_Blind && roomInfo.roomModeType != RoomModeType_Open_PK_Mode && roomInfo.roomModeType != RoomModeType_Open_AcrossRoomPK_mode && roomInfo.roomModeType != RoomModeType_Open_Micro_Mode && !roomInfo.leaveMode && roomInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
		if (!self.gameListView.superview) {
			[self addSubview:self.gameListView];
			[self.gameListView mas_makeConstraints:^(MASConstraintMaker *make) {
				make.right.mas_equalTo(self.shareButton.mas_left).offset(-3);
				make.top.mas_equalTo(self.shareButton);
			}];
		}
		self.gameListView.mgId = roomInfo.mgId.integerValue > 0 ? roomInfo.mgId : @"-1";
	} else {
		if (self.gameListView.superview) {
			[self.gameListView removeFromSuperview];
		}
	}
}

#pragma mark - RoomGuestDelegate
- (void)onRoomEntered {
	RoomInfoModel* roomInfo = self.hostDelegate.getRoomInfo;
	///最小化进房 人数不对的问题
	[[[NIMSDK sharedSDK] chatroomManager] fetchChatroomInfo:[NSString stringWithFormat:@"%ld", (long)self.hostDelegate.getRoomInfo.roomId]  completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom) {
		if (error == nil) {
			self.idLabel.text = [NSString stringWithFormat:@"大鹅号:%ld   %ld人在线", (long)roomInfo.erbanNo, (long)(chatroom.onlineUserCount > 0 ? chatroom.onlineUserCount : 0)];
		} else {
			self.idLabel.text = [NSString stringWithFormat:@"大鹅号:%ld   %ld人在线", (long)roomInfo.erbanNo, (long)(roomInfo.onlineNum > 0 ? roomInfo.onlineNum : 0)];
		}
	}];
	
	if (roomInfo) {
		self.titleLabel.text = roomInfo.title;
		self.giftEffectImageView.hidden = roomInfo.hasAnimationEffect;
		if (roomInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
			self.collectButton.hidden = YES;
		} else {
			self.collectButton.hidden = NO;
			self.collectButton.selected = roomInfo.isRoomFans;
		}
		self.lockRoomImageView.hidden = roomInfo.roomPwd.length <= 0;
	}
}

- (void)onRoomUpdate {
	RoomInfoModel* roomInfo = self.hostDelegate.getRoomInfo;
	self.titleLabel.text = roomInfo.title;
	self.idLabel.text = [NSString stringWithFormat:@"大鹅号:%ld   %ld人在线", (long)roomInfo.erbanNo, (long)(roomInfo.onlineNum > 0 ? roomInfo.onlineNum : 0)];
	self.giftEffectImageView.hidden = roomInfo.hasAnimationEffect;
	if (roomInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
		self.collectButton.hidden = YES;
	} else {
		self.collectButton.hidden = NO;
		self.collectButton.selected = roomInfo.isRoomFans;
	}
	self.lockRoomImageView.hidden = roomInfo.roomPwd.length <= 0;
	[self configLittleGameState];
}

#pragma mark - XPRoomLittleGameListViewDelegate
- (void)xPRoomLittleGameListView:(XPRoomLittleGameListView *)view didSelectItem:(LittleGameInfoModel *)itemInfo {
	RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
	NSMutableDictionary * params = [NSMutableDictionary dictionary];
	NSString * uid = [AccountInfoStorage instance].getUid;
	NSString * ticket = [AccountInfoStorage instance].getTicket;
	[params setObject:ticket forKey:@"ticket"];
	[params setObject:uid forKey:@"uid"];
	[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.uid] forKey:@"roomUid"];
	if (roomInfo.title.length > 0) {
		[params setObject:roomInfo.title forKey:@"title"];
	}
	
	if (roomInfo.roomPwd.length > 0) {
		NSString *pwdDes = [DESEncrypt encryptUseDES:roomInfo.roomPwd key:KeyWithType(KeyType_PasswordEncode)];
		[params setObject:pwdDes forKey:@"roomPwd"];
	} else{
		[params setObject:@"" forKey:@"roomPwd"];
	}
	
	if (roomInfo.tagId > 0) {
		[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.tagId] forKey:@"tagId"];
	}
	if ([itemInfo.mgId isEqualToString:@"-1"]) {
		[params setObject:@(RoomType_Game) forKey:@"type"];
	} else {
		[params setObject:@(RoomType_MiniGame) forKey:@"type"];
		[params setObject:itemInfo.mgId forKey:@"mgId"];
	}
	[params setObject:@(roomInfo.hasAnimationEffect) forKey:@"hasAnimationEffect"];
	[Api ownerUpdateRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
		if (code == 200) {
			
		} else {
			[XCHUDTool showErrorWithMessage:msg];
		}
	} params:params];
}
#pragma mark - Event Response
- (void)showSharePanel {
	XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];
	XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagWeChat title:@"微信好友" imageName:@"share_wechat_normal" disableImageName:@"share_wechat_disable"];
	XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagQQ title:@"QQ好友" imageName:@"share_qq_normal" disableImageName:@"share_qq_disable"];
	XPShareItem *qqzone = [XPShareItem itemWitTag:XPShareItemTagQQZone title:@"QQ空间" imageName:@"share_qqzone_normal" disableImageName:@"share_qqzone_disable"];
	NSArray * items = @[wechat,cycle, qq, qqzone];
	RoomInfoModel * roomInfo = [self.hostDelegate getRoomInfo];
	XPShareInfoModel * shareInfo = [[XPShareInfoModel alloc] init];
	shareInfo.shareTitle = @"来大鹅，开黑交友玩游戏";
	shareInfo.shareContent = @"人美声甜带上分，一起来玩吧~";
	shareInfo.shareImageUrl = [self.hostDelegate getRoomInfo].avatar;
	shareInfo.type = ShareType_Room;
	shareInfo.roomUid = roomInfo.uid;
	NSString * uid  = [AccountInfoStorage instance].getUid;
	NSString * urlString = [NSString stringWithFormat:@"%@/%@?shareUid=%@&uid=%ld&room_name=%@&room_id=%ld&room_avatar=%@&share_name=%@",API_HOST_URL,URLWithType(kShareRoomURL),uid,roomInfo.uid,roomInfo.title,roomInfo.erbanNo,roomInfo.avatar,roomInfo.nick];
	shareInfo.shareUrl = urlString;
	CGFloat margin = 15;
	CGSize itemSize = CGSizeMake((KScreenWidth-2*margin)/4, 65);
	XPShareView *shareView = [[XPShareView alloc] initWithItems:items itemSize:itemSize shareInfo:shareInfo];
	shareView.delegate = self;
	[TTPopup popupView:shareView style:TTPopupStyleActionSheet];
}

///保存一下分享的内容的 不需要处理错误码
- (void)saveShare:(XPShareInfoModel *)shareInfo {
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	NSString *uid = [AccountInfoStorage instance].getUid;
	NSString *ticket = [AccountInfoStorage instance].getTicket;
	[params setObject:uid forKey:@"uid"];
	[params setObject:@(shareInfo.shareType) forKey:@"shareType"];
	[params setObject:ticket forKey:@"ticket"];
	[params setObject:@(shareInfo.type) forKey:@"sharePageId"];
	if (shareInfo.shareUrl.length > 0) {
		[params setObject:shareInfo.shareUrl forKey:@"shareUrl"];
	}
	if (shareInfo.roomUid > 0) {
		[params setObject:@(shareInfo.roomUid) forKey:@"targetUid"];
	}
	[HttpRequestHelper POST:@"usershare/save" params:params success:^(BaseModel * _Nonnull data) {
	
	} failure:^(NSInteger resCode, NSString * _Nonnull message) {
	
	}];
}

- (void)collectButtonAction:(UIButton *)sender {
	NSString * type = sender.selected ? @"2" : @"1";
	NSString * uid = [AccountInfoStorage instance].getUid;
	NSString * roomUid = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
	[Api collectRoom:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
		if (code == 200) {
			sender.selected= !sender.selected;
			if ([type isEqualToString:@"1"]) {///收藏的话
				[XCHUDTool showSuccessWithMessage:@"收藏成功"];
				NSMutableDictionary * dic = [NSMutableDictionary dictionary];
				[dic setValue:[AccountInfoStorage instance].getUid forKey:@"uid"];
				[dic setValue:self.hostDelegate.getUserInfo.nick forKey:@"nick"];
				[dic setValue:[NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid] forKey:@"targetUid"];
				[dic setValue:self.hostDelegate.getRoomInfo.nick forKey:@"targetNick"];
				NSDictionary * data = @{@"data":dic};
				AttachmentModel *attachment = [[AttachmentModel alloc]init];
				attachment.first = CustomMessageType_Collection_Room;
				attachment.second = Custom_Message_Sub_Collect_Room_Tips;
				attachment.data = data;
				NIMMessage *message = [[NIMMessage alloc]init];
				NIMCustomObject *object = [[NIMCustomObject alloc] init];
				object.attachment = attachment;
				message.messageObject = object;
				NSString *sessionId = [NSString stringWithFormat:@"%ld",self.hostDelegate.getRoomInfo.roomId];
				//构造会话
				NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeChatroom];
				[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
			}
		} else {
			[XCHUDTool showErrorWithMessage:msg];
		}
	} roomUid:roomUid uid:uid type:type];
}

#pragma mark - XCShareViewDelegate
- (void)shareView:(XPShareView *)shareView shareFail:(NSString *)message {
	[TTPopup dismiss];
	[XCHUDTool showErrorWithMessage:message];
}

- (void)shareView:(XPShareView *)shareView didSuccess:(XPShareInfoModel *)shareInfo{
	[TTPopup dismiss];
	[XCHUDTool showErrorWithMessage:@"分享成功"];
	AttachmentModel * attachMent = [[AttachmentModel alloc] init];
	attachMent.first = CustomMessageType_Room_Tip;
	attachMent.second = Custom_Message_Sub_Room_Tip_ShareRoom;
	NSMutableDictionary * dic = [NSMutableDictionary dictionary];
	NSString * uid  = [AccountInfoStorage instance].getUid;
	[dic setValue:uid forKey:@"uid"];
	NSMutableDictionary * userDic = [NSMutableDictionary dictionary];
	UserInfoModel * userInfo = [self.hostDelegate getUserInfo];
	RoomInfoModel * roomInfo = [self.hostDelegate getRoomInfo];
	[userDic setValue:roomInfo.nick.length > 0 ? roomInfo.nick : @"" forKey:@"targetNick"];
	[userDic setValue:@(roomInfo.uid) forKey:@"targetUid"];
	[userDic setValue:userInfo.nick.length > 0 ? userInfo.nick : @"" forKey:@"nick"];
	[dic setValue:userDic forKey:@"data"];
	attachMent.data = dic;
	NSString *sessionID = [NSString stringWithFormat:@"%ld", [self.hostDelegate getRoomInfo].roomId];
	
	NIMMessage *message = [[NIMMessage alloc]init];
	NIMCustomObject *object = [[NIMCustomObject alloc] init];
	object.attachment = attachMent;
	message.messageObject = object;
	//构造会话
	NIMSession *session = [NIMSession session:sessionID type:NIMSessionTypeChatroom];
	[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
	///上报一下
	[self saveShare:shareInfo];
}

- (void)shareViewDidClickCancel:(XPShareView *)shareView {
	[TTPopup dismiss];
}

#pragma mark - Getters And Setters
- (UIButton *)backButton{
	if (!_backButton) {
		_backButton = [[UIButton alloc] init];
		[_backButton setImage:[UIImage imageNamed:@"room_info_back"] forState:UIControlStateNormal];
		[_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
		[_backButton setEnlargeEdgeWithTop:15 right:15 bottom:15 left:15];
	}
	return _backButton;
}

- (UIButton *)shareButton {
	if(!_shareButton){
		_shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
		[_shareButton setImage:[UIImage imageNamed:@"room_info_share"] forState:UIControlStateNormal];
		[_shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
		[_shareButton setEnlargeEdgeWithTop:8 right:8 bottom:8 left:8];
	}
	return _shareButton;
}

- (UIButton *)settingButton {
	if (!_settingButton) {
		_settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
		[_settingButton setImage:[UIImage imageNamed:@"room_info_setting"] forState:UIControlStateNormal];
		[_settingButton addTarget:self action:@selector(settingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
		[_settingButton setEnlargeEdgeWithTop:8 right:8 bottom:8 left:8];
	}
	return _settingButton;
}

- (UIButton *)collectButton {
	if (!_collectButton) {
		_collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
		[_collectButton setTitle:@"收藏" forState:UIControlStateNormal];
		[_collectButton setTitle:@"已收藏" forState:UIControlStateSelected];
		[_collectButton setTitleColor:[ThemeColor confirmButtonTextColor] forState:UIControlStateNormal];
		[_collectButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(53, 22)] forState:UIControlStateNormal];
		[_collectButton setBackgroundImage:[UIImage imageWithColor:[ThemeColor disableButtonColor]] forState:UIControlStateSelected];
		[_collectButton setTitleColor:[ThemeColor disableButtonTextColor] forState:UIControlStateSelected];
		_collectButton.titleLabel.font = [UIFont systemFontOfSize:12];
		_collectButton.layer.cornerRadius = 11;
		_collectButton.layer.masksToBounds = YES;
		[_collectButton addTarget:self action:@selector(collectButtonAction:) forControlEvents:UIControlEventTouchUpInside];
		_collectButton.hidden = YES;
	}
	return _collectButton;
}

- (UIStackView *)nickStackView {
	if (!_nickStackView) {
		_nickStackView = [[UIStackView alloc] init];
		_nickStackView.axis = UILayoutConstraintAxisVertical;
		_nickStackView.distribution = UIStackViewDistributionFill;
		_nickStackView.alignment = UIStackViewAlignmentLeading;
		_nickStackView.spacing = 3;
	}
	return _nickStackView;
}

- (UIStackView *)titleStackView {
	if (!_titleStackView) {
		_titleStackView = [[UIStackView alloc] init];
		_titleStackView.axis = UILayoutConstraintAxisHorizontal;
		_titleStackView.distribution = UIStackViewDistributionFill;
		_titleStackView.alignment = UIStackViewAlignmentCenter;
		_titleStackView.spacing = 5;
	}
	return _titleStackView;
}

- (MarqueeLabel *)titleLabel{
	if (!_titleLabel) {
		_titleLabel = [[MarqueeLabel alloc] init];
		_titleLabel.scrollDuration = 8.0;
		_titleLabel.fadeLength = 6.0f;
		_titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:14];
		_titleLabel.textColor = [ThemeColor roomOwnerNickColor];
	}
	return _titleLabel;
}

- (UIImageView *)giftEffectImageView {
	if (!_giftEffectImageView) {
		_giftEffectImageView = [[UIImageView alloc] init];
		_giftEffectImageView.userInteractionEnabled = YES;
		_giftEffectImageView.image = [UIImage imageNamed:@"room_info_gift_effect"];
	}
	return _giftEffectImageView;
}

- (UIImageView *)lockRoomImageView {
	if (!_lockRoomImageView) {
		_lockRoomImageView = [[UIImageView alloc] init];
		_lockRoomImageView.userInteractionEnabled = YES;
		_lockRoomImageView.image = [UIImage imageNamed:@"room_info_lock_room"];
		_lockRoomImageView.hidden = YES;
	}
	return _lockRoomImageView;
}

- (UIStackView *)onlineStackView {
	if (!_onlineStackView) {
		_onlineStackView = [[UIStackView alloc] init];
		_onlineStackView.axis = UILayoutConstraintAxisHorizontal;
		_onlineStackView.distribution = UIStackViewDistributionFill;
		_onlineStackView.alignment = UIStackViewAlignmentCenter;
		_onlineStackView.spacing = 2;
		UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onlineTapRecognizer)];
		[_onlineStackView addGestureRecognizer:tap];
	}
	return _onlineStackView;
}

- (UIView *)greenDotView {
	if (!_greenDotView) {
		_greenDotView = [[UIView alloc] init];
		_greenDotView.backgroundColor = [ThemeColor roomOnLineIdenColor];
		_greenDotView.layer.masksToBounds = YES;
		_greenDotView.layer.cornerRadius = 1.5;
	}
	return _greenDotView;
}

- (YYLabel *)idLabel {
	if (!_idLabel) {
		_idLabel = [[YYLabel alloc] init];
		_idLabel.textColor = [UIColor colorWithWhite:1 alpha:0.6];
		_idLabel.font = [UIFont systemFontOfSize:9];
	}
	return _idLabel;
}

- (XPRoomLittleGameListView *)gameListView {
	if (!_gameListView) {
		_gameListView = [[XPRoomLittleGameListView alloc] init];
		_gameListView.delegate = self;
	}
	return _gameListView;
}


@end
