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/date_time_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_specific_controller.dart';
import 'contract_rate_specific_state.dart';

/*
 * 设置指定日期的时薪
 */
class SGContractRateSpecificPage extends BaseStatelessPage<ContractRateSpecificController> {
  SGContractRateSpecificPage({Key? key}) : super(key: key);

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

  late ContractRateSpecificState state;

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

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

  @override
  Widget buildWidget(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: MyAppBar.appBar(context, "Specific Day".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['position']!['focusNode']);
                        },
                        marginTop: 5,
                      ),

                      //职位
                      MyTextView(
                        "Position".tr,
                        textColor: Colors.white,
                        fontSize: 14,
                        isFontRegular: true,
                        marginLeft: 15,
                        marginTop: 10,
                      ),

                      CustomTextField(
                        formKey: "position",
                        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['date']!['focusNode']);
                        },
                        marginTop: 5,
                      ),

                      //必选 - 选择职位
                      FormRequireText(text: "Date".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(0.2),
                          borderRadius: const BorderRadius.all(Radius.circular(5)),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            MyTextView(
                              state.selectedDate == null ? "" : DateTimeUtils.formatDate(state.selectedDate!, format: "yyyy-MM-dd"),
                              fontSize: 14,
                              hint: "Select Date".tr,
                              textHintColor: ColorConstants.textGrayAECAE5,
                              isFontMedium: true,
                              textColor: ColorConstants.white,
                            ).expanded(),

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

                      //必填 - 默认时薪
                      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,
                      ),

                      //提交按钮
                      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),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    });
  }
}
