import 'package:cpt_sg/modules/agency/position_add/position_add_controller.dart';
import 'package:cpt_sg/modules/agency/position_add/position_add_state.dart';
import 'package:cs_resources/constants/color_constants.dart';
import 'package:flutter/material.dart';
import 'package:get/get.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_text_view.dart';
import 'package:widgets/no_shadow_scroll_behavior.dart';
import 'package:widgets/shatter/custom_radio_check.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';

/*
 * 中介的添加与编辑
 */
class SGPositionAddPage extends BaseStatelessPage<PositionAddController> {
  SGPositionAddPage({Key? key}) : super(key: key);

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

  late PositionAddState state;

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

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

  @override
  Widget buildWidget(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: MyAppBar.appBar(context, Utils.isEmpty(state.positionId) ? "Add Position".tr : "Edit Position".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: "agency_position".tr).marginOnly(left: 15, top: 19),

                      CustomTextField(
                        formKey: "position",
                        formData: state.formData,
                        height: 46,
                        fontSize: 14,
                        textInputAction: TextInputAction.done,
                        onSubmit: (key, value) {
                          FocusScope.of(context).unfocus();
                          controller.doSubmit();
                        },
                        marginTop: 10,
                      ),

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