import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/managers/interfaces/live_course.dart';
import 'package:flyinsono/views/mobile/full_screen_player/index.dart';
import 'package:get/get.dart';
import 'package:fis_common/index.dart';

class MockPage extends FStatefulWidget implements FPage {
  @override
  FState<FStatefulWidget> createState() {
    return _FMyCourseState();
  }

  @override
  String get pageName => "MyCourse";
}

class _FMyCourseState extends FState<MockPage> {
  final liveCourseManager = Get.find<ILiveCourseManager>();
  @override
  FWidget build(BuildContext context) {
    var child = FColumn(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        FElevatedButton(
          businessParent: widget,
          name: 'start course',
          onPressed: () async {
            if (FPlatform.isPureWeb) {
              router.to(
                RouteNames.College.LiveCourseDetail,
                parameters: {
                  "courseCode": "736D77C1021C474298534127AE4B8C0C",
                },
              );
              return;
            }
            var courseCode = "9BFE63C1BFFB43F7A51DAA58AFA1C5BB";
            // //TODO(Loki):mock数据
            // var courses = await rpc.education.findCoursePagesAsync(
            //   FindCoursePagesRequest(
            //     teacherCode: Store.user.code,
            //     token: Store.user.token,
            //     languageCode: i18nBook.locale.toCodeString('-'),
            //   ),
            // );
            // var course = courses.pageData!.first;
            // courseCode = course.code ?? '';
            liveCourseManager.openLiveCoursePage(courseCode);
          },
          child: FText(i18nBook.college.startCourse.t),
        ),
        FSizedBox(
          height: 30,
        ),
        FElevatedButton(
          businessParent: widget,
          name: 'enter course',
          onPressed: () async {
            var courseCode = "8A2104F9A25A451D85EC49A5E1FE84BB";
            //TODO(Loki):mock数据
            // var courses = await rpc.education.findCoursePagesAsync(
            //   FindCoursePagesRequest(
            //     teacherCode: "5219FF3DE4A44506AFC19CA8D01F29B7",
            //     token: Store.user.token,
            //     languageCode: i18nBook.locale.toCodeString('-'),
            //   ),
            // );
            // var course = courses.pageData!.first;
            // courseCode = course.code ?? '';
            liveCourseManager.openLiveCoursePage(courseCode);
          },
          child: FText(i18nBook.college.enterCourse.t),
        ),
        FSizedBox(
          height: 30,
        ),
        FElevatedButton(
          businessParent: widget,
          name: 'download test',
          onPressed: () async {
            liveCourseManager.listeningManager
                .onOtherPlatformNotificationHandler(
              CourseEntryNotification(
                noticeData:
                    'download?token=https://flyinsono-bj-1300984704.cos.ap-beijing.myqcloud.com/新大头儿子小头爸爸_高清.mp4',
              ),
            );
          },
          child: FText("测试下载"),
        ),
        FElevatedButton(
          businessParent: widget,
          name: 'download test',
          onPressed: () async {
            Get.to(() => FullScreenPlayerPage(
                flvUrl:
                    "https://liveplay.fis.plus/live/vp0jmhyqdtem7k8is6ipomjfk.flv"));
          },
          child: FText("全屏播放测试"),
        ),
      ],
    );
    if (kIsMobile) {
      return FSafeArea(
        child: FScaffold(
          appBar: FAppBar.simple(
            title: i18nBook.college.myCourses.t,
            onBackClicked: (() => router.back()),
          ),
          body: FRow(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              child,
            ],
          ),
        ),
      );
    }
    return FExpanded(child: child);
  }
}
