import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/common/model/job/job_student_goups.dart';
import 'package:marking_app/utils/easy_refresh/MyEmptyWidget.dart';
import 'package:marking_app/utils/index.dart';

class StudentGroupList extends StatelessWidget {
  final List studentGroups;
  final Function goNextPage;
  const StudentGroupList(this.studentGroups,this.goNextPage,{Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return studentGroups != null && studentGroups.length > 0
        ? isPad()?GridView(
      shrinkWrap: true,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        mainAxisSpacing: 10.r,
        crossAxisSpacing: 10.r,
        childAspectRatio: 556 / 112,
      ),
      children: List.generate(studentGroups.length, (index) {
        JobStudentGroups item = studentGroups[index];
        String classNames = item.classNames.join("  ");
        return InkWell(
          onTap: (){
            goNextPage(item.groupId,item.groupName);
            // RouterManager.router.navigateTo(context, '${RouterManager.jobPriorityReviewSetPath}?&groupId=${item.groupId}',transition: getTransition());
          },
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 10.r),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(10.r)),
              color: Colors.white,
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Padding(
                  padding: EdgeInsets.only(right: 8.r),
                  child: Text(
                    item.groupName,
                    style: TextStyle(
                        fontSize: 10.sp, color: Color(0xFF6888FD)),
                  ),
                ),
                Expanded(
                  child: Text(
                    classNames,
                    style: TextStyle(
                      fontSize: 10.sp,
                      color: Color(0xFF999999),
                      overflow: TextOverflow.ellipsis,
                    ),
                    textAlign: TextAlign.end,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 5.r),
                  height: 20.r,
                  width: 55.r,
                  decoration: BoxDecoration(
                    borderRadius:
                    BorderRadius.all(Radius.circular(20.r)),
                    color: Color(0xFF6888FD),
                  ),
                  child: Center(
                    child: Text(
                      '详情',
                      style: TextStyle(
                          fontSize: 10.sp, color: Colors.white),
                    ),
                  ),
                )
              ],
            ),
          ),
        );
      }),
    ):ListView.builder(
      shrinkWrap: true,
      itemBuilder: (context,index){
        JobStudentGroups item = studentGroups[index];
        String classNames = item.classNames.join("  ");
        return Container(
          padding: EdgeInsets.symmetric(vertical:15.r,horizontal: 10.r),
          margin: EdgeInsets.only(bottom: 10.r),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(10.r)),
            color: Colors.white,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(right: 8.r),
                child: Text(
                  item.groupName,
                  style: TextStyle(
                      fontSize: 14.sp, color: Color(0xFF6888FD)),
                ),
              ),
              Expanded(
                child: Text(
                  classNames,
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: Color(0xFF999999),
                    overflow: TextOverflow.ellipsis,
                  ),
                  textAlign: TextAlign.end,
                ),
              ),
              InkWell(
                onTap: (){
                  goNextPage(item.groupId,item.groupName);
                  // RouterManager.router.navigateTo(context, '${RouterManager.jobPriorityReviewSetPath}?&groupId=${item.groupId}',transition: getTransition());
                },
                child: Container(
                  margin: EdgeInsets.only(left: 5.r),
                  height: 24.r,
                  width: 55.r,
                  decoration: BoxDecoration(
                    borderRadius:
                    BorderRadius.all(Radius.circular(20.r)),
                    color: Color(0xFF6888FD),
                  ),
                  child: Center(
                    child: Text(
                      '详情',
                      style: TextStyle(
                          fontSize: 10.sp, color: Colors.white),
                    ),
                  ),
                ),
              )
            ],
          ),
        );
      },
      itemCount: studentGroups.length,
    )
        : Padding(
      padding: EdgeInsets.only(top: MediaQuery.of(context).size.height/2 - 200.r),
      child: MyEmptyWidget(),
    );
  }
}
