import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/job/class_item.dart';
import 'package:making_school_asignment_app/common/utils/enum_untils.dart';
import 'package:making_school_asignment_app/common/utils/utils.dart';
import 'package:making_school_asignment_app/page/global_widget/MyEmptyWidget.dart';

class StudentGroupList extends StatelessWidget {
  final List<ClassItem> studentGroups;
  final Function goNextPage;
  final Widget? rightBtn;

  const StudentGroupList(this.studentGroups, this.goNextPage, {super.key, this.rightBtn});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return studentGroups.isNotEmpty
          ? Utils.isPad()
              ? GridView(
                  shrinkWrap: true,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                    mainAxisSpacing: 10.r,
                    crossAxisSpacing: 10.r,
                    childAspectRatio: 556 / 112,
                  ),
                  children: List.generate(studentGroups.length, (index) {
                    ClassItem item = studentGroups[index];
                    return InkWell(
                      onTap: () {
                        goNextPage(item.classId, '${EnumUtils.formatGrade(item.grade)}${item.className}', item.subject);
                      },
                      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(
                                '${EnumUtils.formatGrade(item.grade)}${item.className}',
                                style: TextStyle(fontSize: 10.sp, color: Theme.of(context).primaryColor),
                              ),
                            ),
                            Text(
                              EnumUtils.formatSubject(item.subject!),
                              style: TextStyle(fontSize: 10.sp, color: const Color(0xFF8B8B8B)),
                            ),
                            const Spacer(),
                            /*Expanded(
                            child: Text(
                              classNames,
                              style: TextStyle(
                                fontSize: 10.sp,
                                color: Color(0xFF999999),
                                overflow: TextOverflow.ellipsis,
                              ),
                              textAlign: TextAlign.end,
                            ),
                          ),*/
                            rightBtn != null
                                ? rightBtn!
                                : Container(
                                    margin: EdgeInsets.only(left: 5.r),
                                    height: 20.r,
                                    width: 55.r,
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(Radius.circular(20.r)),
                                      color: Theme.of(context).primaryColor,
                                    ),
                                    child: Center(
                                      child: Text(
                                        '详情',
                                        style: TextStyle(fontSize: 10.sp, color: Colors.white),
                                      ),
                                    ),
                                  )
                          ],
                        ),
                      ),
                    );
                  }),
                )
              : ListView.builder(
                  shrinkWrap: true,
                  itemBuilder: (context, index) {
                    ClassItem item = studentGroups[index];
                    return InkWell(
                      onTap: () {
                        goNextPage(item.classId, '${EnumUtils.formatGrade(item.grade)}${item.className}', item.subject);
                      },
                      child: 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(
                                '${EnumUtils.formatGrade(item.grade)}${item.className}',
                                style: TextStyle(fontSize: 14.sp, color: Theme.of(context).primaryColor),
                              ),
                            ),
                            Text(
                              EnumUtils.formatSubject(item.subject!),
                              style: TextStyle(fontSize: 10.sp, color: const Color(0xFF8B8B8B)),
                            ),
                            const Spacer(),
                            /*   Expanded(
                            child: Text(
                              classNames,
                              style: TextStyle(
                                fontSize: 12.sp,
                                color: Color(0xFF999999),
                                overflow: TextOverflow.ellipsis,
                              ),
                              textAlign: TextAlign.end,
                            ),
                          ),*/
                            rightBtn != null
                                ? rightBtn!
                                : Container(
                                    margin: EdgeInsets.only(left: 5.r),
                                    height: 24.r,
                                    width: 55.r,
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(Radius.circular(20.r)),
                                      color: Theme.of(context).primaryColor,
                                    ),
                                    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: const MyEmptyWidget(),
            );
    });
  }
}
