import 'dart:typed_data';
import 'dart:ui';

import 'package:cs_resources/generated/assets.dart';
import 'package:domain/entity/response/job_applied_edit_index_s_g_entity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:shared/utils/date_time_utils.dart';
import 'package:shared/utils/util.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:cs_resources/constants/color_constants.dart';
import 'package:widgets/my_load_image.dart';
import 'package:widgets/my_text_field.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/picker/date_picker_util.dart';
import 'package:widgets/shatter/custom_radio_check.dart';
import 'package:widgets/widget_export.dart';

/*
 * 修改对应日期的时薪弹窗
 */
class EditRateDialog extends StatefulWidget {
  String? rate;
  void Function(String? rate)? confirmAction;

  EditRateDialog({this.rate, this.confirmAction});

  @override
  State<EditRateDialog> createState() => _DialogAppliedModifyState();
}

class _DialogAppliedModifyState extends State<EditRateDialog> {
  String? rate;
  late TextEditingController controller;
  late FocusNode focusNode;

  @override
  void initState() {
    super.initState();
    rate = widget.rate;
    controller = TextEditingController();
    if (Utils.isNotEmpty(rate)) {
      controller.text = rate!;
    }
    focusNode = FocusNode();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(
        bottom: MediaQuery.of(context).viewInsets.bottom,  //加上 Padding 与 MediaQuery的配置可以让 Dialog 弹出时，自动居中适配
      ),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16.5),
        width: 285,
        decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(15)),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            Center(
              // 标题
              child: MyTextView(
                "Hourly Rate".tr,
                fontSize: 19,
                isFontMedium: true,
                textColor: ColorConstants.black,
                marginTop: 22,
                marginBottom: 20,
              ),
            ),

            IgnoreKeyboardDismiss(
              child: MyTextField(
                "hourly_rate",
                rate ?? "",
                hintText: "Enter...".tr,
                hintStyle: const TextStyle(
                  color: ColorConstants.gray88,
                  fontSize: 14,
                  fontWeight: FontWeight.w400,
                ),
                controller: controller,
                focusNode: focusNode,
                margin: const EdgeInsets.only(left: 0, right: 0, top: 8),
                showDivider: false,
                fillBackgroundColor: ColorConstants.grayECECEC,
                fillCornerRadius: 5,
                padding: const EdgeInsets.only(left: 16, right: 16, top: 0, bottom: 0),
                height: 40,
                style: const TextStyle(
                  color: ColorConstants.black33,
                  fontSize: 14,
                  fontWeight: FontWeight.w400,
                ),
                inputType: TextInputType.number,
                textInputAction: TextInputAction.done,
                enabled: true,
                onSubmit: (key, value) {
                  FocusScope.of(context).unfocus();
                  //输入框需要手动赋值
                  rate = controller.text;
                  widget.confirmAction?.call(rate);
                  onCancel();
                },
                cursorColor: ColorConstants.black33,
                showLeftIcon: false,
                showRightIcon: false,
              ),
            ),

            //分割线
            Container(
              margin: const EdgeInsets.only(top: 25),
              color: const Color(0XFFCECECE),
              height: 0.5,
            ),
            Row(
              children: [
                Expanded(
                    flex: 1,
                    child: InkWell(
                      onTap: () {
                        onCancel();
                      },
                      child: MyTextView(
                        "Cancel".tr,
                        fontSize: 17.5,
                        isFontMedium: true,
                        textAlign: TextAlign.center,
                        textColor: const Color(0XFF0085C4),
                        cornerRadius: 3,
                        borderWidth: 1,
                      ),
                    )),
                Container(
                  color: const Color(0xff09141F).withOpacity(0.13),
                  width: 0.5,
                ),
                Expanded(
                    flex: 1,
                    child: InkWell(
                      onTap: () async {
                        FocusScope.of(context).unfocus();
                        //输入框需要手动赋值
                        rate = controller.text;
                        widget.confirmAction?.call(rate);
                        onCancel();
                      },
                      child: MyTextView(
                        "Submit".tr,
                        marginLeft: 10,
                        fontSize: 17.5,
                        isFontMedium: true,
                        textAlign: TextAlign.center,
                        textColor: const Color(0XFF0085C4),
                        cornerRadius: 3,
                      ),
                    )),
              ],
            ).constrained(height: 46),
          ],
        ),
      ),
    );
  }

  //取消弹框
  void onCancel() async {
    SmartDialog.dismiss();
  }
}
