import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:making_school_asignment_app/common/job/annotated_class.dart';
import 'package:making_school_asignment_app/common/utils/enum_untils.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';

class DropdownSelection extends StatefulWidget {
  final List<AnnotatedClass>? involveClasses;
  final AnnotatedClass? classData;
  final Function(AnnotatedClass) call;
  final Color? bgColor;
  const DropdownSelection({Key? key, required this.involveClasses, required this.classData, required this.call,this.bgColor}) : super(key: key);

  @override
  State<DropdownSelection> createState() => _DropdownSelectionState();
}

class _DropdownSelectionState extends State<DropdownSelection> {
  @override
  Widget build(BuildContext context) {
    return Container(
      // width: 200.r,
      padding: EdgeInsets.symmetric(horizontal: 10.r),
      decoration: BoxDecoration(
          color: widget.bgColor ?? const Color(0xFFF5F5F5),
          borderRadius: const BorderRadius.vertical(
            top: Radius.elliptical(10, 10),
            bottom: Radius.elliptical(10, 10),
          )),
      child: DropdownButton(
        value: widget.classData?.classId ?? '-1',
        style: TextStyle(color: Color.fromRGBO(89, 89, 89, 1), fontSize: 12.sp),
        underline: Container(),
        // isExpanded:true,
        items: widget.involveClasses?.map((e) {
          return DropdownMenuItem(
            value: e.classId!,
            child: quickText(e.classId == '-1' ? '全部' : ' ${EnumUtils.formatGrade(e.grade)}${e.className}', size: 12.sp, color: Colors.black),
          );
        }).toList(),
        onChanged: (value) {
          if (value == null) return;
          widget.call(widget.involveClasses!.firstWhere((element) => element.classId == value));
        },
      ),
    );
  }
}
