import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared/utils/log_utils.dart';
import 'package:shared/utils/screen_util.dart';
import 'package:shared/utils/util.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_appbar.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/my_load_image.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/no_shadow_scroll_behavior.dart';
import 'package:widgets/shatter/form_require_text.dart';
import 'package:widgets/shatter/round_my_text_field.dart';

import 'package:plugin_basic/base/base_stateless_page.dart';
import 'package:plugin_basic/utils/ext_get_nav.dart';
import 'package:router/path/router_path.dart';

import 'contract_rate_setting_controller.dart';
import 'contract_rate_setting_state.dart';

/*
 * 设置不同时间的时薪
 * 设置与修改页面
 */
class ContractRateSettingPage extends BaseStatelessPage<ContractRateSettingController> {
  ContractRateSettingPage({Key? key}) : super(key: key);

  //启动当前页面
  static void startInstance(
    String? contractId,
    String? positionId,
    void Function(dynamic value)? cb,
  ) {
    return Get.start(RouterPath.SGContractRateSetting, arguments: {'contractId': contractId, 'positionId': positionId, 'cb': cb});
  }

  late ContractRateSettingState state;

  @override
  void initState() {
    state = controller.state;
    state.contractId = Get.arguments['contractId'];
    state.positionId = Get.arguments['positionId'];
    state.isAddType = Utils.isEmpty(state.positionId);
    state.cb = Get.arguments['cb'] as void Function(dynamic)?;
  }

  @override
  ContractRateSettingController createRawController() {
    return ContractRateSettingController();
  }

  @override
  Widget buildWidget(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: MyAppBar.appBar(context, state.isAddType ? "Add New".tr : "Edit".tr),
        body: SafeArea(
        bottom: MediaQuery.of(context).padding.bottom > 38,
          top: false,
          child: Container(
            width: double.infinity,
            height: double.infinity,
            padding: EdgeInsets.only(top: kToolbarHeight + ScreenUtil.getStatusBarH(context) + 1),
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  Color(0xFF091D44),
                  Color(0xFF245A8A),
                  Color(0xFF7F7CEC),
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: Scrollbar(
              child: ScrollConfiguration(
                behavior: NoShadowScrollBehavior(),
                child: SingleChildScrollView(
                  scrollDirection: Axis.vertical,
                  physics: const BouncingScrollPhysics(),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      MyTextView(
                        "Agency".tr,
                        textColor: Colors.white,
                        fontSize: 14,
                        isFontRegular: true,
                        marginLeft: 15,
                        marginTop: 10,
                      ),

                      CustomTextField(
                        formKey: "agency_name",
                        formData: state.formData,
                        height: 45,
                        enabled: false,
                        fillBackgroundColor: const Color(0xFF4DCFF6).withOpacity(0.5),
                        fontSize: 14,
                        textInputType: TextInputType.number,
                        onSubmit: (key, value) {
                          state.formData[key]!['focusNode'].unfocus();
                          FocusScope.of(context).requestFocus(state.formData['hourly_rate']!['focusNode']);
                        },
                        marginTop: 5,
                      ),

                      //必选 - 选择职位
                      FormRequireText(text: "agency_position".tr).marginOnly(left: 15, top: 10),

                      //下拉选
                      Container(
                        padding: const EdgeInsets.only(left: 16, right: 10),
                        margin: const EdgeInsets.only(top: 5, left: 15, right: 15),
                        height: 45,
                        decoration: BoxDecoration(
                          color: const Color(0xFF4DCFF6).withOpacity(state.isAddType ? 0.2 : 0.5),
                          borderRadius: const BorderRadius.all(Radius.circular(5)),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            MyTextView(
                              state.positionName ?? "",
                              fontSize: 14,
                              hint: "Choose Position".tr,
                              textHintColor: ColorConstants.textGrayAECAE5,
                              isFontMedium: true,
                              textColor: ColorConstants.white,
                            ).expanded(),

                            //下拉选图标
                            const MyAssetImage(Assets.baseServiceTriangleDropDownIcon, width: 11.5, height: 6.28),
                          ],
                        ),
                      ).onTap(() {
                        if (state.positionList.isNotEmpty) {
                          FocusScope.of(context).unfocus();
                          controller.pickPosition();
                        }
                      }),

                      //必填 - 默认时薪
                      FormRequireText(text: "Hourly Rate".tr).marginOnly(left: 15, top: 10),

                      CustomTextField(
                        formKey: "hourly_rate",
                        formData: state.formData,
                        height: 45,
                        fontSize: 14,
                        textInputType: TextInputType.number,
                        onSubmit: (key, value) {
                          state.formData[key]!['focusNode'].unfocus();
                          FocusScope.of(context).requestFocus(state.formData['weekdays']!['focusNode']);
                        },
                        marginTop: 5,
                      ),

                      // 工作日与周末
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 工作日
                              MyTextView(
                                "Weekdays".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 15,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "weekdays",
                                formData: state.formData,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['weekends']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周末
                              MyTextView(
                                "Weekends".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 10,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "weekends",
                                formData: state.formData,
                                height: 45,
                                marginLeft: 10,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['monday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                        ],
                      ),

                      // 周一，周二
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周一
                              MyTextView(
                                "Monday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 15,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "monday",
                                formData: state.formData,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['tuesday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周二
                              MyTextView(
                                "Tuesday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 10,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "tuesday",
                                formData: state.formData,
                                marginLeft: 10,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['wednesday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                        ],
                      ),

                      // 周三，周四
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周三
                              MyTextView(
                                "Wednesday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 15,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "wednesday",
                                formData: state.formData,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['thursday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周四
                              MyTextView(
                                "Thursday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 10,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "thursday",
                                formData: state.formData,
                                marginLeft: 10,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['friday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                        ],
                      ),

                      //周五
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周五
                              MyTextView(
                                "Friday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 15,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "friday",
                                formData: state.formData,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['saturday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                          const SizedBox(height: 1).expanded(),
                        ],
                      ),

                      //周六，周日
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周六
                              MyTextView(
                                "Saturday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 15,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "saturday",
                                formData: state.formData,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['sunday']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 周日
                              MyTextView(
                                "Sunday".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 10,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "sunday",
                                formData: state.formData,
                                marginLeft: 10,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['eve_of_ph_day']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                        ],
                      ),

                      //法定节假日
                      Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 前夕
                              MyTextView(
                                "Eve of PH day".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 15,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "eve_of_ph_day",
                                formData: state.formData,
                                height: 45,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  state.formData[key]!['focusNode'].unfocus();
                                  FocusScope.of(context).requestFocus(state.formData['ph_days']!['focusNode']);
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 假日
                              MyTextView(
                                "PH Days".tr,
                                textColor: Colors.white,
                                fontSize: 14,
                                isFontRegular: true,
                                marginLeft: 10,
                                marginTop: 10,
                              ),

                              // 输入框
                              CustomTextField(
                                formKey: "ph_days",
                                formData: state.formData,
                                marginLeft: 10,
                                height: 45,
                                textInputAction: TextInputAction.done,
                                fontSize: 14,
                                textInputType: TextInputType.number,
                                onSubmit: (key, value) {
                                  FocusScope.of(context).unfocus();
                                  controller.doSubmit();
                                },
                                marginTop: 5,
                              ),
                            ],
                          ).expanded(),
                        ],
                      ),

                      //提交按钮
                      MyButton(
                        type: ClickType.throttle,
                        milliseconds: 500,
                        onPressed: () {
                          FocusScope.of(context).unfocus();
                          controller.doSubmit();
                        },
                        text: "Submit".tr,
                        textColor: ColorConstants.white,
                        fontSize: 16,
                        radius: 20,
                        backgroundColor: ColorConstants.textYellowFFBB1B,
                        fontWeight: FontWeight.w500,
                      ).marginSymmetric(vertical: 25, horizontal: 15),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    });
  }
}
