import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_common/index.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/utils/prompt_box.dart';
import 'package:flyinsono/rpc.dart';

class TableleHeader {
  List<FTableColumn<UserGroupDTO>> getStudentTableleHeader(
      FWidget Function(UserGroupDTO) operates) {
    final headerTextStyle = TextStyle(fontSize: 16);
    return <FTableColumn<UserGroupDTO>>[
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.className.t,
        render: (info, i) => FCenter(
          child: FText(
            info.name!,
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.relatedCourse.t,
        render: (info, i) => FCenter(
          child: FText(
            info.courseCount.toString(),
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.completedExercise.t,
        render: (info, i) => FCenter(
          child: FText(
            '0',
            // "${info.completedPracticeCount}/${info.practiceCount}",
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.participatedExam.t,
        render: (info, i) => FCenter(
          child: FText(
            '0',
            // "${info.completedExamCount}/${info.examCount}",
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.common.operation.t,
        width: 300,
        render: (info, i) => FCenter(
          child: operates(info),
        ),
      ),
    ];
  }

  List<FTableColumn<UserGroupDTO>> getTeachTableleHeader(
      FWidget Function(UserGroupDTO) operates) {
    final headerTextStyle = TextStyle(fontSize: 16);
    return <FTableColumn<UserGroupDTO>>[
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.serialNumber.t,
        width: 100,
        render: (info, i) => FCenter(
          child: FText(
            (i + 1).toString(),
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.className.t,
        width: 350,
        render: (info, i) => FCenter(
          child: FText(
            info.name!,
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
          headerText: i18nBook.college.classCode.t,
          width: 150,
          render: (info, i) {
            return FRow(
              mainAxisSize: MainAxisSize.min,
              children: [
                FText(
                  info.shortCode ?? '',
                  style: headerTextStyle,
                ),
                FIconButton(
                  icon: FIcon(
                    Icons.copy,
                    size: 20,
                    color: FTheme.ins.colorScheme.primary,
                  ),
                  onPressed: () {
                    if (FPlatform.isWindows || FPlatform.isMacOS) {
                      rpc.platform.copyToClipboard(info.shortCode!);
                    } else {
                      Clipboard.setData(ClipboardData(text: info.shortCode!));
                    }
                    PromptBox.toast(i18nBook.remedical.copySuccess.t);
                  },
                  businessParent: FVirtualPageWidget(''),
                  name: i18nBook.remedical.copyClassCode.t,
                )
              ],
            );
          }),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.numberOfStudents.t,
        render: (info, i) => FCenter(
          child: FText(
            info.studentCount.toString(),
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.bindCourse.t,
        render: (info, i) => FCenter(
          child: FText(
            info.courseCount.toString(),
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.bindExam.t,
        render: (info, i) => FCenter(
          child: FText(
            info.examCount.toString(),
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.college.bindExercise.t,
        render: (info, i) => FCenter(
          child: FText(
            info.practiceCount.toString(),
            style: headerTextStyle,
          ),
        ),
      ),
      FTableColumn<UserGroupDTO>(
        headerText: i18nBook.common.operation.t,
        width: i18nBook.isCurrentChinese ? 350 : 380,
        render: (info, i) => FCenter(
          child: operates(info),
        ),
      ),
    ];
  }
}
