import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/common/model/report/detail_base_info.dart';
import 'package:marking_app/pages/report_detail/widgets/basic_tablecell.dart';

class BasicTable extends StatelessWidget {
  final BaseInfo? baseInfo;
  final bool? showGrade;

  const BasicTable(this.baseInfo, this.showGrade ,{Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 14.r),
      padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 10.r),
      width: MediaQuery.of(context).size.width,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(5.r)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Container(
            decoration: BoxDecoration(
              // color: Color(0xFFF5F7FF),
                border: Border(
                  bottom: BorderSide(width: 1, color: Color(0xFFE8EBFF)),
                )
            ),
            child: IntrinsicHeight(
              child: Row(
                children: [
                  Expanded(flex: 1, child: BasicTableCell('考试名称', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.examName, true)),
                  Expanded(flex: 1, child: BasicTableCell('考试类型', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.examType, true)),
                ],
              ),
            ),
          ),
          Container(
            decoration: BoxDecoration(
              border: Border(bottom: BorderSide(width: 1, color: Color(0xFFE8EBFF)))
            ),
            child: IntrinsicHeight(
              child: Row(
                children: [
                  Expanded(flex: 1, child: BasicTableCell('年级', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.grade, true)),
                  Expanded(flex: 1, child: BasicTableCell('学科', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.subject, true)),
                ],
              ),
            ),
          ),
          Container(
            decoration: BoxDecoration(
                border: Border(bottom: BorderSide(width: 1, color: Color(0xFFE8EBFF)))
            ),
            child: IntrinsicHeight(
              child: Row(
                children: [
                  Expanded(flex: 1, child: BasicTableCell('考试日期', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.examTime, true)),
                  Expanded(flex: 1, child: BasicTableCell('满分', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.totalScore.toString(), true)),
                ],
              ),
            ),
          ),
          Container(
            decoration: BoxDecoration(
                border: Border(bottom: BorderSide(width: 1, color: Color(0xFFE8EBFF)))
            ),
            child: IntrinsicHeight(
              child: Row(
                children: [
                  Expanded(flex: 1, child: BasicTableCell('平均分', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.avgScore.toString(), true)),
                  Expanded(flex: 1, child: BasicTableCell('最高分', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.maxScore.toString(), true)),
                ],
              ),
            ),
          ),
          Container(
            decoration: BoxDecoration(
                border: Border(bottom: BorderSide(width: 1, color: Color(0xFFE8EBFF)))
            ),
            child: IntrinsicHeight(
              child: Row(
                children: [
                  Expanded(flex: 1, child: BasicTableCell('优秀率', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.rateGood, true)),
                  Expanded(flex: 1, child: BasicTableCell('及格率', false)),
                  Expanded(flex: 1, child: BasicTableCell(baseInfo!.ratePass, true)),
                ],
              ),
            ),
          ),
          if(showGrade == true)
            Container(
              decoration: BoxDecoration(
                  border: Border(bottom: BorderSide(width: 1, color: Color(0xFFE8EBFF)))
              ),
              child: IntrinsicHeight(
                child: Row(
                  children: [
                    Expanded(flex: 1, child: BasicTableCell('平均分排名', false)),
                    Expanded(flex: 1, child: BasicTableCell(baseInfo!.totalRank != null?baseInfo!.totalRank.toString():'--', true)),
                    Expanded(flex: 1, child: BasicTableCell('参考班级总数', false)),
                    Expanded(flex: 1, child: BasicTableCell(baseInfo!.joinCount != null?baseInfo!.joinCount.toString():'--', true)),
                  ],
                ),
              ),
            )
        ],
      ),
    );
  }
}
