import 'dart:ui';

import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:plugin_basic/base/base_stateful_page.dart';
import 'package:plugin_basic/base/base_state.dart';
import 'package:plugin_basic/base/mixin_state_lifecycle.dart';
import 'package:plugin_basic/utils/ext_get_nav.dart';
import 'package:router/path/router_path.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/load_state_layout.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/widget_export.dart';
import 'e_attendance_list_controller.dart';
import 'e_attendance_list_state.dart';
import 'item_e_attendance.dart';

/*
 * 电子考勤列表
 */
class UKEAttendanceListPage extends BaseStatefulPage<EAttendanceListController> {
  UKEAttendanceListPage({super.key});

  //启动当前页面
  static void startInstance() {
    return Get.start(RouterPath.UKAttendanceList);
  }

  @override
  State<UKEAttendanceListPage> createState() => _SignInSignOutPageState();

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

class _SignInSignOutPageState extends BaseState<UKEAttendanceListPage, EAttendanceListController> with StateLifecycle {
  late EAttendanceListState state;

  @override
  void initState() {
    super.initState();
    state = controller.state;
  }

  @override
  void dispose() {
    Get.delete<EAttendanceListController>();
    super.dispose();
  }

  @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, "E-Attendance".tr, actions: [
                  //筛选图标
                  const MyAssetImage(
                    Assets.baseServiceTitleBarFilterIcon,
                    width: 24,
                    height: 16.5,
                  ).onTap(() {
                    controller.showFilterDialog();
                  }).marginOnly(right: 15),
                ]),

                EasyRefresh(
                  controller: controller.refreshController,
                  onRefresh: controller.onRefresh,
                  child: LoadStateLayout(
                    state: controller.loadingState,
                    errorMessage: controller.errorMessage,
                    errorRetry: () {
                      controller.retryRequest();
                    },
                    successSliverWidget: [
                      //列表
                      SliverList(
                          delegate: SliverChildBuilderDelegate(
                        (context, index) {
                          return EAttendanceItem(
                            index: index,
                            item: state.datas[index],
                            onMemberAction: () {
                              controller.gotoStaffDetailPage(state.datas[index]);
                            },
                          );
                        },
                        childCount: state.datas.length,
                      ))
                    ],
                  ),
                ).marginOnly(top: 5).expanded(),
              ],
            ),
          ),
        );
      },
    );
  }
}
