import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/controller/mh_controller/score_controller.dart' as mh;
class ScorePage extends GetView<mh.ScoreController> {
  BoxConstraints? bodysize;
  final scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    // UserInfoController userInfoController = Get.find();
    // userInfoController.model.user;
    controller.model.score = 5;
    return LayoutBuilder(builder: (context, cc) {
      bodysize = cc;
      return GestureDetector(
          onTap: () => FocusScope.of(context).unfocus(),
          child: Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/new_background.png'), // 本地图片
                fit: BoxFit.fill, // 填满整个 Container
              ),
            ),
            child: Scaffold(
              // key: scaffoldKey,
              backgroundColor: Colors.transparent,
              appBar: AppBar(
                backgroundColor: Colors.transparent,
                iconTheme: const IconThemeData(color: Colors.white),
                automaticallyImplyLeading: false,
                titleSpacing: 0,
                title: SizedBox(
                  width: double.infinity,
                  height: 180.rpx,
                  child: Stack(
                    alignment: Alignment.center,
                    children: [
                      // 中间居中的标题
                      Text(
                        '评价'.tr,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 30.rpx,
                        ),
                      ),
                      // 左侧图标
                      Positioned(
                        left: 0.rpx,
                        child: returnIconButtomNew,
                      ),
                    ],
                  ),
                ),
                centerTitle: false,
              ),

              body: Container(
                width: bodysize!.maxWidth,
                height: bodysize!.maxHeight * 1,
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    // TitleComponentWidget(
                    //   titleName: '评价',
                    // ),
                    Expanded(
                      child: Container(
                        width: bodysize!.maxWidth,
                        child: SingleChildScrollView(
                          child: Column(
                            mainAxisSize: MainAxisSize.max,
                            children: [
                              Padding(
                                padding: EdgeInsetsDirectional.fromSTEB(
                                    30.rpx, 26.rpx, 30.rpx, 0),
                                child: Container(
                                  width: bodysize!.maxWidth,
                                  constraints: BoxConstraints(
                                    minWidth: 346,
                                    minHeight: 115,
                                  ),
                                  decoration: BoxDecoration(
                                    color: Color(0xFF003058),
                                    borderRadius: BorderRadius.circular(16),
                                  ),
                                  child: Padding(
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        22, 27, 17, 22),
                                    child: Container(
                                      width: bodysize!.maxWidth,
                                      decoration: BoxDecoration(
                                        color: Color(0xFF003058),
                                        borderRadius: BorderRadius.circular(16),
                                      ),
                                      child: Column(
                                        mainAxisSize: MainAxisSize.max,
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Align(
                                            alignment:
                                                AlignmentDirectional(0, 0),
                                            child: Text(
                                              '我要评价'.tr,
                                              style: TextStyle(
                                                  fontFamily: 'Readex Pro',
                                                  fontSize: 30.rpx,
                                                  letterSpacing: 0,
                                                  color: Colors.white),
                                            ),
                                          ),
                                          Row(
                                            mainAxisSize: MainAxisSize.max,
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              InkWell(
                                                onTap: () {
                                                  controller.model.score = 1;
                                                  controller.updateAll();
                                                },
                                                child: Obx(() {
                                                  return Icon(
                                                    Icons.star,
                                                    color: controller
                                                                .model.score! >=
                                                            1
                                                        ? stringToColor(
                                                            "#F8AE00")
                                                        : stringToColor(
                                                            "#D0D0D0"),
                                                    size: 40,
                                                  );
                                                }),
                                              ),
                                              InkWell(
                                                onTap: () {
                                                  controller.model.score = 2;
                                                  controller.updateAll();
                                                },
                                                child: Obx(() {
                                                  return Icon(
                                                    Icons.star,
                                                    color: controller
                                                                .model.score! >=
                                                            2
                                                        ? stringToColor(
                                                            "#F8AE00")
                                                        : stringToColor(
                                                            "#D0D0D0"),
                                                    size: 40,
                                                  );
                                                }),
                                              ),
                                              InkWell(
                                                onTap: () {
                                                  controller.model.score = 3;
                                                  controller.updateAll();
                                                },
                                                child: Obx(() {
                                                  return Icon(
                                                    Icons.star,
                                                    color: controller
                                                                .model.score! >=
                                                            3
                                                        ? stringToColor(
                                                            "#F8AE00")
                                                        : stringToColor(
                                                            "#D0D0D0"),
                                                    size: 40,
                                                  );
                                                }),
                                              ),
                                              InkWell(
                                                onTap: () {
                                                  controller.model.score = 4;
                                                  controller.updateAll();
                                                },
                                                child: Obx(() {
                                                  return Icon(
                                                    Icons.star,
                                                    color: controller
                                                                .model.score! >=
                                                            4
                                                        ? stringToColor(
                                                            "#F8AE00")
                                                        : stringToColor(
                                                            "#D0D0D0"),
                                                    size: 40,
                                                  );
                                                }),
                                              ),
                                              InkWell(
                                                onTap: () {
                                                  controller.model.score = 5;
                                                  controller.updateAll();
                                                },
                                                child: Obx(() {
                                                  return Icon(
                                                    Icons.star,
                                                    color: controller
                                                                .model.score! >=
                                                            5
                                                        ? stringToColor(
                                                            "#F8AE00")
                                                        : stringToColor(
                                                            "#D0D0D0"),
                                                    size: 40,
                                                  );
                                                }),
                                              ),
                                            ].divide(SizedBox(width: 10)),
                                          ),
                                        ].divide(SizedBox(height: 26)),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              Padding(
                                padding: EdgeInsetsDirectional.fromSTEB(
                                    30.rpx, 30.rpx, 30.rpx, 0),
                                child: Container(
                                  width: bodysize!.maxWidth,
                                  constraints: BoxConstraints(
                                    minWidth: 346,
                                    minHeight: 152,
                                  ),
                                  decoration: BoxDecoration(
                                    color: Color(0xFF003058),
                                    borderRadius: BorderRadius.circular(16.rpx),
                                  ),
                                  child: Padding(
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        14, 14, 14, 21),
                                    child: Container(
                                      width: bodysize!.maxWidth,
                                      decoration: BoxDecoration(
                                        color: Color(0xFF003058),
                                        borderRadius:
                                            BorderRadius.circular(16.rpx),
                                      ),
                                      child: Column(
                                        mainAxisSize: MainAxisSize.max,
                                        children: [
                                          Align(
                                            alignment:
                                                AlignmentDirectional(0, 0),
                                            child: Obx(() {
                                              String scoreText;
                                              Color scoreColor;
                                              if (controller.model.score == 1) {
                                                scoreText = '差';
                                                scoreColor =
                                                    stringToColor("#E55E92");
                                              } else if (controller
                                                      .model.score ==
                                                  2) {
                                                scoreText = '较差';
                                                scoreColor =
                                                    stringToColor("#E55E92");
                                              } else if (controller
                                                      .model.score ==
                                                  3) {
                                                scoreText = '一般';
                                                scoreColor =
                                                    stringToColor("#07C160");
                                              } else if (controller
                                                      .model.score ==
                                                  4) {
                                                scoreText = '优秀';
                                                scoreColor =
                                                    stringToColor("#F8AE00");
                                              } else if (controller
                                                      .model.score ==
                                                  5) {
                                                scoreText = '完美';
                                                scoreColor =
                                                    stringToColor("#F8AE00");
                                              } else {
                                                scoreText =
                                                    '未评分'; // 如果没有评分显示默认文字
                                                scoreColor =
                                                    Colors.grey; // 默认颜色
                                              }
                                              return Text(
                                                scoreText,
                                                style: TextStyle(
                                                    fontFamily: 'Readex Pro',
                                                    fontSize: 30.rpx,
                                                    letterSpacing: 0,
                                                    color: scoreColor,
                                                    fontWeight:
                                                        FontWeight.bold),
                                              );
                                            }),
                                          ),
                                          Align(
                                            alignment:
                                                AlignmentDirectional(-1, 0),
                                            child: Padding(
                                              padding: EdgeInsetsDirectional
                                                  .fromSTEB(0, 17, 0, 0),
                                              child: Text(
                                                '再多的溢美之词，都比不上您真心的评价。我们愿付出200%的努力，只为您100%的满意～感谢您的支持与厚爱！',
                                                style: TextStyle(
                                                    fontFamily: 'Readex Pro',
                                                    fontSize: 26.rpx,
                                                    letterSpacing: 0,
                                                    color: Color(0xFF9AA0B3)),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                    Padding(
                      padding: EdgeInsetsDirectional.fromSTEB(
                          15, 0, 15, AppConstants.page_button_bottom_padding),
                      child: Container(
                          width: bodysize!.maxWidth,
                          height: bodysize!.maxHeight * 0.056,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(16.rpx),
                          ),
                          // child: Container(
                          //   width: bodysize!.maxWidth,
                          //   height: bodysize!.maxHeight * 0.056,
                          //   decoration: BoxDecoration(
                          //     color: FlutterFlowTheme.of(context)
                          //         .secondaryBackground,
                          //     borderRadius: BorderRadius.circular(12),
                          //   ),
                          //   child: FFButtonWidget(
                          //     onPressed: () {
                          //       // RepairListController repairListController =
                          //       //     Get.find();
                          //       // RepairInfoController repairInfoController =
                          //       //     Get.find();
                          //       // repairListController
                          //       //     .addScore(
                          //       //         repairInfoController
                          //       //             .model.applyRepairModel!.id!,
                          //       //         controller.model.score!)
                          //       //     .then((String msg) {
                          //       //   if (msg != null && msg.isNotEmpty) {
                          //       //     MyDialogController myDialogController =
                          //       //         Get.find();
                          //       //     showToast("评价失败，请稍后再试");
                          //       //   } else {
                          //       //     MyDialogController myDialogController =
                          //       //         Get.find();
                          //       //     myDialogController
                          //       //         .showCustomDialog(context, "评价成功",
                          //       //             textColor: stringToColor("#71E2A3"))
                          //       //         .then((_) {
                          //       //       // 弹窗关闭后执行的代码
                          //       //       // Get.toNamed("/userInfoPage");
                          //       //       repairInfoController.model.applyRepairModel!
                          //       //           .score = controller.model.score!;
                          //       //       repairInfoController.updateAll();
                          //       //       Get.back();
                          //       //     }).catchError((error) {
                          //       //       // 处理弹窗显示错误的逻辑
                          //       //       print("弹窗显示失败: $error");
                          //       //     });
                          //       //   }
                          //       // });
                          //     },
                          //     text: '确定',
                          //     options: FFButtonOptions(
                          //       height: 40,
                          //       padding:
                          //           EdgeInsetsDirectional.fromSTEB(24, 0, 24, 0),
                          //       iconPadding:
                          //           EdgeInsetsDirectional.fromSTEB(0, 0, 0, 0),
                          //       color: Color(0xFFD3B684),
                          //       textStyle: FlutterFlowTheme.of(context)
                          //           .titleSmall
                          //           .override(
                          //             fontFamily: 'Readex Pro',
                          //             color: Colors.white,
                          //             fontSize: 13,
                          //             letterSpacing: 0,
                          //           ),
                          //       elevation: 0,
                          //       borderSide: BorderSide(
                          //         color: Colors.transparent,
                          //         width: 1,
                          //       ),
                          //       borderRadius: BorderRadius.circular(8),
                          //     ),
                          //   ),
                          // ),

                          child: CustomCard(
                            borderRadius: 16.rpx,
                            gradientDirection: GradientDirection.vertical,
                            onTap: () {
                              Get.toNamed("/applyRepairPage");
                            },
                            colors: const [
                              Color(0xFFFCFCFC),
                              Color(0xFFF8FAF9),
                              Color(0XFFECF6F3),
                              Color(0XFFD9F0E9),
                              Color(0xFFCEECE3)
                            ],
                            child: Container(
                              width: double.infinity,
                              height: 90.rpx,
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(16.rpx),
                              ),
                              child: Text(
                                "提交",
                                style: TextStyle(
                                  fontFamily: 'Readex Pro',
                                  color: stringToColor("#011D33"),
                                  letterSpacing: 0,
                                  fontSize: 30.rpx,
                                ),
                              ),
                            ),
                          )),
                    ),
                  ],
                ),
              ),
            ),
          ));
    });
  }
}
