import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import 'package:app/widgets/base/dialog/config_dialog.dart';
import 'package:app/widgets/room/other_widget.dart';
import 'package:app/widgets/room/video_surface.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

import '../viewmodel/stu_room_vm.dart';

class TeacherVideo extends StatelessWidget {
  const TeacherVideo({super.key});

  @override
  Widget build(BuildContext context) {
    final vm = context.watch<StuRoomVM>();
    final teacherInfo = vm.teacherInfo;
    return PopScope(
      canPop: false,
      onPopInvokedWithResult: (didPop, _) {
        if (!didPop) {
          showDialog(
            context: context,
            builder: (context) {
              return ConfigDialog(
                content: "是否退出自习室",
                onCancel: () {
                  context.pop();
                },
                onConfirm: () {
                  context.pop();
                  context.pop();
                },
              );
            },
          );
        }
      },
      child: IgnorePointer(
        child: Stack(
          alignment: Alignment.bottomCenter,
          children: [
            VideoSurface(
              user: teacherInfo!,
              child: AgoraVideoView(
                controller: VideoViewController(
                  rtcEngine: vm.engine!,
                  canvas: VideoCanvas(
                    uid: teacherInfo.rtcUid,
                  ),
                ),
              ),
            ),
            Positioned(
              top: 30,
              left: 10,
              child: Visibility(
                visible: !vm.cameraClose,
                child: Container(
                  width: 200,
                  color: Colors.black,
                  child: AspectRatio(
                    aspectRatio: 16 / 9,
                    child: AgoraVideoView(
                      controller: VideoViewController(
                        rtcEngine: vm.engine!,
                        canvas: const VideoCanvas(uid: 0),
                      ),
                    ),
                  ),
                ),
              ),
            ),
            if (vm.selfInfo?.handup == 1)
              Positioned(
                bottom: 60,
                child: HandRaiseButton(
                  onTap: vm.changeHandSwitch,
                ),
              ),
          ],
        ),
      ),
    );
  }
}
