import 'package:app/request/dto/room/room_user_dto.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class VideoSurface extends StatelessWidget {
  final RoomUserDto user;
  final Widget child;

  const VideoSurface({
    super.key,
    required this.user,
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    //摄像头是否关闭
    if (user.cameraStatus == 0) {
      return Align(
        child: ConstrainedBox(
          constraints: const BoxConstraints(
            maxWidth: 70,
          ),
          child: AspectRatio(
            aspectRatio: 1,
            child: Container(
              clipBehavior: Clip.hardEdge,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                border: Border.all(color: Colors.white, width: 1),
              ),
              child: CachedNetworkImage(
                imageUrl: user.avatar,
                fit: BoxFit.cover,
              ),
            ),
          ),
        ),
      );
    }
    if (user.online == 0) {
      return _empty('暂时离开');
    }
    return child;
  }

  Widget _empty(String title) {
    return Center(
      child: Text(title, style: TextStyle(color: Colors.white70)),
    );
  }
}
