import 'package:cs_resources/constants/color_constants.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared/utils/date_time_utils.dart';
import 'package:shared/utils/screen_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_text_view.dart';

import 'casual_payout_report_controller.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';

import 'casual_payout_report_item.dart';
import 'casual_payout_report_state.dart';

class UKCasualPayoutReportPage extends BaseStatelessPage<CasualPayoutReportController> {
  UKCasualPayoutReportPage({Key? key}) : super(key: key);

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

  late CasualPayoutReportState state;

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

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

  @override
  Widget buildWidget(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: MyAppBar.appBar(context, "YY Casual Labour Report".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: Column(
              children: [
                // 时间筛选
                Container(
                    width: double.infinity,
                    height: 36,
                    margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
                    decoration: BoxDecoration(
                      color: const Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
                      borderRadius: BorderRadius.circular(20.0), // 设置圆角
                    ),
                    child: Row(
                      children: [
                        MyTextView(
                          DateTimeUtils.formatDate(state.startDateTime, format: "yyyy-MM-dd"),
                          hint: "Start Date".tr,
                          textHintColor: ColorConstants.textGrayAECAE5,
                          fontSize: 15,
                          textAlign: TextAlign.center,
                          isFontRegular: true,
                          onClick: controller.pickerStartDate,
                          textColor: ColorConstants.textGrayAECAE5,
                        ).expanded(),
                        Container(color: ColorConstants.dividerBar, height: 21.5, width: 0.5),
                        MyTextView(
                          DateTimeUtils.formatDate(state.endDateTime, format: "yyyy-MM-dd"),
                          hint: "End Date".tr,
                          textHintColor: ColorConstants.textGrayAECAE5,
                          fontSize: 15,
                          textAlign: TextAlign.center,
                          isFontRegular: true,
                          onClick: controller.pickerEndDate,
                          textColor: ColorConstants.textGrayAECAE5,
                        ).expanded(),
                      ],
                    )),

                //动态列表
                LoadStateLayout(
                  state: controller.loadingState,
                  errorMessage: controller.errorMessage,
                  errorRetry: () {
                    controller.retryRequest();
                  },
                  successSliverWidget: [

                    SliverList(delegate: SliverChildBuilderDelegate((context, index) {
                        return ReportLabourItem(entity: state.entity, type: index);
                      },
                      childCount: state.datas.isNotEmpty ? 3 : 0,
                    ))

                  ],
                ).expanded(),
              ],
            ),
          ),
        ),
      );
    });
  }
}
