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/work_student.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';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/routes/app_pages.dart';

class AnswerTrajectoryJob extends StatelessWidget {
  final List<Items> jobList;

  const AnswerTrajectoryJob(this.jobList, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return jobList != null && jobList.isNotEmpty
        ? Utils.isPad()
            ? GridView(
                shrinkWrap: true,
                physics: const ClampingScrollPhysics(),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2, //横轴三个子widget
                    mainAxisSpacing: 10.h,
                    crossAxisSpacing: 6.w,
                    childAspectRatio: 2.4 //宽高比为1时，子widget
                    ),
                children: List.generate(jobList.length, (index) {
                  Items item = jobList[index];
                  return InkWell(
                    onTap: () {
                      Get.toNamed(Routes.answerTrajectoryDetailPage,arguments: {'homeworkId':item.id,'title':item.name,'grade':item.grade,'subject':item.subject});
                    },
                    child: Container(
                      padding: EdgeInsets.only(top: 10.h),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(6.r),
                        color: Colors.white,
                        boxShadow: const [
                          BoxShadow(
                            color: Color.fromRGBO(210, 216, 241, 1),
                            offset: Offset.zero, //阴影y轴偏移量
                            blurRadius: 5.8, //阴影模糊程度
                            spreadRadius: 0, //阴影扩散程度
                          )
                        ],
                      ),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          // 顶部任务名称
                          Padding(
                            padding: EdgeInsets.symmetric(horizontal: 6.w),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Container(
                                  width: 32.w,
                                  height: 22.h,
                                  alignment: Alignment.center,
                                  // padding: EdgeInsets.only(left: 2.w),
                                  decoration: BoxDecoration(
                                    color:Theme.of(context).primaryColor,
                                    borderRadius: BorderRadius.all(
                                     Radius.circular(5.r)
                                    ),
                                  ),
                                  margin: EdgeInsets.only(top:3.h,right: 4.w),
                                  child: quickText(
                                      item.assessType == 0 ? '作业' : '考试',
                                      color: Colors.white,
                                      size: 10.sp),
                                ),
                                Expanded(
                                  child: quickText(item.name,
                                      size: 12.sp,
                                      color: Color.fromRGBO(70, 70, 70, 1),
                                      maxLines: 2),
                                ),
                                SizedBox(
                                  width: 5.r,
                                ),
                                Container(
                                  padding: EdgeInsets.symmetric(
                                      vertical: 1.r, horizontal: 5.r),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(4.r),
                                    border: Border.all(
                                        width: 1.r, color: Theme.of(context).primaryColor),
                                  ),
                                  child: Center(
                                    child: Text(
                                      EnumUtils.formatSubject(item.subject),
                                      style: TextStyle(
                                          fontSize: 8.r,
                                          color: Theme.of(context).primaryColor),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.symmetric(horizontal: 6.r),
                            child: Text(
                              '时间：${item.publishTime.substring(0, 10)}',
                              style: TextStyle(fontSize: 10.sp),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(vertical: 6.h),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(6.r),
                                  bottomRight: Radius.circular(6.r)),
                              color: Colors.white,
                              boxShadow: const [
                                BoxShadow(
                                  color: Color.fromRGBO(0, 0, 0, 0.15),
                                  offset: Offset(0, -0.0001), //阴影y轴偏移量
                                  blurRadius: 4, //阴影模糊程度
                                  spreadRadius: 0, //阴影扩散程度
                                )
                              ],
                            ),
                            child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    alignment: Alignment.center,
                                    child: quickText('详情',
                                        color: Color(0xFFFFA115), size: 10.sp),
                                  ),
                                  Image.asset(
                                    'assets/images/icon_back_orange.png',
                                    width: 8.r,
                                    height: 8.r,
                                  ),
                                ]),
                          ),
                        ],
                      ),
                    ),
                  );
                }),
              )
            : ListView.builder(
                shrinkWrap: true,
                physics: ClampingScrollPhysics(),
                itemBuilder: (context, index) {
                  Items item = jobList[index];
                  return InkWell(
                    onTap: () {
                      /* RouterManager.router.navigateTo(context,
                          '${RouterManager.answerTrajectoryJobDetailPath}?&jobId=${item.id}&jobName=${Uri.encodeComponent(item.title)}&genderName=${Uri.encodeComponent(item.genderName)}',
                          transition: getTransition());*/
                    },
                    child: Container(
                      margin: EdgeInsets.symmetric(vertical: 10.r),
                      padding: EdgeInsets.only(top: 10.h),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(6.r),
                        color: Colors.white,
                        boxShadow: const [
                          BoxShadow(
                            color: Color.fromRGBO(210, 216, 241, 1),
                            offset: Offset.zero, //阴影y轴偏移量
                            blurRadius: 5.8, //阴影模糊程度
                            spreadRadius: 0, //阴影扩散程度
                          )
                        ],
                      ),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          // 顶部任务名称
                          Padding(
                            padding: EdgeInsets.symmetric(
                                vertical: 14.r, horizontal: 14.r),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Container(
                                  width: 32.w,
                                  height: 22.h,
                                  alignment: Alignment.center,
                                  // padding: EdgeInsets.only(left: 2.w),
                                  decoration: BoxDecoration(
                                    color:Theme.of(context).primaryColor,
                                    borderRadius: BorderRadius.all(
                                     Radius.circular(5.r)
                                    ),
                                  ),
                                  margin: EdgeInsets.only(top:3.h,right: 4.w),
                                  child: quickText(
                                      item.assessType == 0 ? '作业' : '考试',
                                      color: Colors.white,
                                      size: 10.sp),
                                ),
                                Expanded(
                                  child: quickText(item.name,
                                      size: 14.sp,
                                      color: Color.fromRGBO(70, 70, 70, 1),
                                      maxLines: 2),
                                ),
                                SizedBox(
                                  width: 5.r,
                                ),
                                Container(
                                  padding: EdgeInsets.symmetric(
                                      vertical: 1.r, horizontal: 5.r),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(4.r),
                                    border: Border.all(
                                        width: 1.r, color: Theme.of(context).primaryColor),
                                  ),
                                  child: Center(
                                    child: Text(
                                      EnumUtils.formatSubject(item.subject),
                                      style: TextStyle(
                                          fontSize: 12.r,
                                          color: Theme.of(context).primaryColor),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                          SizedBox(
                            height: 5.r,
                          ),
                          Padding(
                            padding: EdgeInsets.symmetric(horizontal: 14.r),
                            child: Text(
                              '时间：${item.publishTime.substring(0, 10)}',
                              style: TextStyle(fontSize: 10.sp),
                            ),
                          ),
                          SizedBox(
                            height: 10.r,
                          ),
                          Container(
                            height: 1.r,
                            color: Color(0xFFF5F5F5),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(vertical: 10.r),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(6.r),
                                  bottomRight: Radius.circular(6.r)),
                              color: Colors.white,
                              /*boxShadow: [
                                BoxShadow(
                                  color: const Color.fromRGBO(0, 0, 0, 0.15),
                                  offset: Offset(0, -0.0001), //阴影y轴偏移量
                                  blurRadius: 4, //阴影模糊程度
                                  spreadRadius: 0, //阴影扩散程度
                                )
                              ],*/
                            ),
                            child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    alignment: Alignment.center,
                                    child: quickText('详情',
                                        color: Color(0xFFFFA115), size: 10.sp),
                                  ),
                                  Image.asset(
                                    'assets/images/icon_back_orange.png',
                                    width: 8.r,
                                    height: 8.r,
                                  ),
                                ]),
                          ),
                        ],
                      ),
                    ),
                  );
                },
                itemCount: jobList.length,
              )
        : const MyEmptyWidget();
  }
}
