import 'package:cs_resources/constants/color_constants.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/load_state_layout.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/search_app_bar.dart';
import 'package:widgets/widget_export.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/my_appbar.dart';

import 'applied_er_staff_detail_controller.dart';
import 'applied_er_staff_detail_state.dart';
import 'staff_detail_widget.dart';
import 'staff_labour_history_item.dart';

class AppliedErStaffDetailPage extends BaseStatefulPage<AppliedErStaffDetailController> {
  AppliedErStaffDetailPage({Key? key}) : super(key: key);

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

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

  @override
  State<AppliedErStaffDetailPage> createState() => _AppliedStaffDetailState();
}

class _AppliedStaffDetailState extends BaseState<AppliedErStaffDetailPage, AppliedErStaffDetailController> {
  late AppliedErStaffDetailState state;

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

  @override
  Widget build(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return SafeArea(
        bottom: MediaQuery.of(context).padding.bottom > 38,
          top: false,
          child: Container(
            width: double.infinity,
            height: double.infinity,
            padding: EdgeInsets.only(top:ScreenUtil.getStatusBarH(context)),
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  Color(0xFF091D44),
                  Color(0xFF245A8A),
                  Color(0xFF7F7CEC),
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: Column(
              children: [
                MyAppBar.titleBar(context, "Staff Detail".tr),

                EasyRefresh(
                  controller: controller.refreshController,
                  onRefresh: controller.onRefresh,
                  onLoad: controller.loadMore,
                  child: LoadStateLayout(
                    state: controller.loadingState,
                    errorMessage: controller.errorMessage,
                    errorRetry: () {
                      controller.retryRequest();
                    },
                    successSliverWidget: [
                      //顶部用户信息
                      SliverToBoxAdapter(
                        child: StaffDetailWidget(detail: state.detail,onRemarkAction: (){
                          controller.gotoRemarkHistoryPage();
                        }),
                      ),

                      //中间搜索布局
                      SliverToBoxAdapter(
                        child: _buildSearchWidget(),
                      ),

                      //底部工作历史列表
                      SliverList(
                          delegate: SliverChildBuilderDelegate(
                        (context, index) {
                          return StaffLabourHistoryItem(index: index, item: state.datas[index]);
                        },
                        childCount: state.datas.length,
                      ))
                    ],
                  ),
                ).marginOnly(top: 5,bottom: 5).expanded(),
              ],
            ),
          ),
        );
    });
  }

  // 搜索的布局
  Widget _buildSearchWidget() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        MyTextView(
          "Job History",
          marginLeft: 15,
          marginTop: 10,
          fontSize: 17,
          textColor: ColorConstants.white,
          isFontMedium: true,
        ),
        SearchAppBar(
          value: state.keyword,
          searchBarHeight: 38,
          onSearch: (keyword) {
            controller.doSearch(keyword);
          },
          hintText: "Job Title".tr,
        ).marginOnly(left: 16.5, right: 1.5, bottom: 10, top: 10),
      ],
    );
  }
}
