import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:domain/entity/response/job_list_detail_entity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:plugin_basic/base/base_state.dart';
import 'package:plugin_basic/base/base_stateful_page.dart';
import 'package:plugin_basic/utils/ext_get_nav.dart';
import 'package:router/path/router_path.dart';
import 'package:shared/utils/screen_util.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_appbar.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 'job_list_detail_controller.dart';
import 'job_list_detail_state.dart';

class UKJobListDetailPage extends BaseStatefulPage<JobListDetailController> {
  UKJobListDetailPage({Key? key}) : super(key: key);

  //启动当前页面
  static void startInstance(String? jobId) {
    return Get.start(RouterPath.UKJobListDetail, arguments: {'jobId': jobId});
  }

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

  @override
  State<UKJobListDetailPage> createState() => _JobListDetailState();
}

class _JobListDetailState extends BaseState<UKJobListDetailPage, JobListDetailController> {
  late JobListDetailState state;

  @override
  void initState() {
    super.initState();
    state = controller.state;
    state.jobId = Get.arguments['jobId'];
  }

  @override
  Widget build(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: MyAppBar.appBar(context, "Job Detail".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: [
                      //工作标题，选择模板
                      FormRequireText(
                        text: "Job Title".tr,
                      ).marginOnly(top: 15),

                      //工作标题
                      Container(
                        padding: EdgeInsets.only(left: 16, right: 10),
                        margin: EdgeInsets.only(top: 10),
                        height: 45,
                        decoration: BoxDecoration(
                          color: Color(0xFF4DCFF6).withOpacity(0.5),
                          borderRadius: const BorderRadius.all(Radius.circular(5)),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            MyTextView(
                              state.selectedJobTitle ?? "-",
                              fontSize: 14,
                              isFontMedium: true,
                              textColor: ColorConstants.white,
                            ).expanded(),
                          ],
                        ),
                      ),

                      //开始时间
                      FormRequireText(
                        text: "Start Time".tr,
                      ).marginOnly(top: 15),

                      //选择时间
                      Container(
                        padding: EdgeInsets.only(left: 16, right: 10),
                        margin: EdgeInsets.only(top: 10),
                        height: 45,
                        decoration: BoxDecoration(
                          color: Color(0xFF4DCFF6).withOpacity(0.5),
                          borderRadius: const BorderRadius.all(Radius.circular(5)),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            MyTextView(
                              state.selectedStartTime ?? "-",
                              fontSize: 14,
                              isFontMedium: true,
                              textColor: ColorConstants.white,
                            ).expanded(),
                          ],
                        ),
                      ),

                      //结束时间
                      FormRequireText(
                        text: "End Time".tr,
                      ).marginOnly(top: 15),

                      //选择时间
                      Container(
                        padding: EdgeInsets.only(left: 16, right: 10),
                        margin: EdgeInsets.only(top: 10),
                        height: 45,
                        decoration: BoxDecoration(
                          color: Color(0xFF4DCFF6).withOpacity(0.5),
                          borderRadius: const BorderRadius.all(Radius.circular(5)),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            MyTextView(
                              state.selectedEndTime ?? "-",
                              fontSize: 14,
                              isFontMedium: true,
                              textColor: ColorConstants.white,
                            ).expanded(),
                          ],
                        ),
                      ),

                      //工作选择部门
                      FormRequireText(
                        text: "Outlet".tr,
                      ).marginOnly(top: 15),

                      //选择部门
                      Container(
                        padding: EdgeInsets.only(left: 16, right: 10),
                        margin: EdgeInsets.only(top: 10),
                        height: 45,
                        decoration: BoxDecoration(
                          color: Color(0xFF4DCFF6).withOpacity(0.5),
                          borderRadius: const BorderRadius.all(Radius.circular(5)),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            MyTextView(
                              state.selectedDepartmentId == null || state.selectedDepartmentId == "0"
                                  ? ""
                                  : state.jobListDetail!.departmentList?.firstWhere((element) {
                                        return element.value.toString() == state.selectedDepartmentId!;
                                      }, orElse: () => JobListDetailDepartmentList()).txt ?? "",
                              fontSize: 14,
                              hint: "Choose Outlet".tr,
                              textHintColor: ColorConstants.textGrayAECAE5,
                              isFontMedium: true,
                              textColor: ColorConstants.white,
                            ).expanded(),
                          ],
                        ),
                      ),

                      //需要的人数
                      FormRequireText(
                        text: "No. of Staff".tr,
                      ).marginOnly(top: 15),

                      //输入框(只允许输入数字)
                      CustomTextField(
                        formKey: "no_of_staff",
                        marginLeft: 0,
                        marginRight: 0,
                        paddingTop: 0,
                        paddingBottom: 0,
                        height: 45,
                        fillBackgroundColor: Color(0xFF4DCFF6).withOpacity(0.5),
                        enabled: false,
                        inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
                        textInputType: TextInputType.number,
                        formData: state.formData,
                        textInputAction: TextInputAction.done,
                        onSubmit: (key, value) {
                          FocusScope.of(context).unfocus();
                        },
                        marginTop: 10,
                      ),
                    ],
                  ).paddingOnly(left: 15, right: 15),
                ),
              ),
            ),
          ),
        ),
      );
    });
  }
}
