import 'package:flutter/material.dart';
import 'package:flutter/services.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/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/widget_export.dart';

import 'report_list_controller.dart';
import 'report_list_item.dart';
import 'report_list_state.dart';

/*
 *  报表的列表
 */
class SGReportListPage extends BaseStatefulPage<SGReportListController> {
  SGReportListPage({super.key});

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

  @override
  State<SGReportListPage> createState() => _MainPageState();

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

class _MainPageState extends BaseState<SGReportListPage, SGReportListController> {
  late ReportListState state;

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

  @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(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              MyAppBar.titleBar(context, "Report".tr),

              //底部的列表
              EasyRefresh(
                controller: null,
                onRefresh: null,
                child: ListView.builder(
                  padding: const EdgeInsets.only(top: 0),
                  itemCount: state.datas.length,
                  itemBuilder: (_, int index) {
                    return ReportListItem(state.datas[index], () {
                      controller.gotoReportPage(state.datas[index]);
                    });
                  },
                ),
              ).paddingOnly(left: 15, right: 15, top: 10, bottom: 15).expanded(),
            ],
          ),
        ),
      );
    });
  }
}
