import 'dart:async';

import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:vbvs_app/common/color/appColors.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/controller/mh_controller/my_experience_list_controller.dart';
import 'package:vbvs_app/pages/mh_page/Empty.dart';
import 'package:vbvs_app/pages/mh_page/my_experience_widget.dart';

class MyExperiencePage extends StatefulWidget {
  const MyExperiencePage({super.key});

  @override
  State<MyExperiencePage> createState() => _MyExperiencePageState();
}

class _MyExperiencePageState extends State<MyExperiencePage> {
  ScrollController scrollController = ScrollController();
  int runTime = 0;
  // @override
  // void initState() {
  //   super.initState();
  //   Timer(Duration.zero, () {
  //     controller.resetParm();
  //     controller.getAllBook();
  //     controller.page = 0;
  //     controller.getData();
  //     scrollController.addListener(() {
  //       print(
  //           "${scrollController.position.pixels} ${scrollController.position.maxScrollExtent}");
  //       int ctime = DateTime.now().millisecondsSinceEpoch;
  //       if (ctime - runTime > 100 &&
  //           scrollController.position.pixels + 80 >
  //               scrollController.position.maxScrollExtent) {
  //         runTime = ctime;
  //         print(
  //             "bottom get more data ${scrollController.position.pixels} ${scrollController.position.maxScrollExtent}");
  //         controller.getData();
  //       }
  //     });
  //   });
  // }

  get controller => Get.find<BookExperienceListController>();
  final scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () => FocusScope.of(context).unfocus(),
        child: Container(
          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/images/new_background.png'), // 本地图片
              fit: BoxFit.fill, // 填满整个 Container
            ),
          ),
          child: Scaffold(
            // key: scaffoldKey,
            backgroundColor: Colors.transparent,
            appBar: AppBar(
              backgroundColor: Colors.transparent,
              automaticallyImplyLeading: false,
              iconTheme: IconThemeData(color: Colors.white),
              titleSpacing: 0,
              // leading: returnIconButtomAddCallback(() {
              //   controller.saveDataApi();
              //   updateParm(isShowToast: false);
              // }),
              // leading: returnIconButtomNew,
              title: Container(
                width: double.infinity,
                height: 180.rpx,
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    // 中间居中的标题
                    Text(
                      '我的预约',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 30.rpx,
                      ),
                    ),
                    // 左侧图标
                    Positioned(
                      left: 0.rpx,
                      child: returnIconButtomNew,
                    ),
                  ],
                ),
              ),

              actions: [],
              centerTitle: false,
            ),

            body: Container(
              width: MediaQuery.sizeOf(context).width,
              height: MediaQuery.sizeOf(context).height * 1,
              decoration: BoxDecoration(
                color: Color(0xFFF6F6F6),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.max,
                children: [
                  // TitleComponentWidget(
                  //   titleName: '我的预约',
                  // ),
                  Obx(() {
                    if (controller.model.bookInfoList.length == 0) {
                      return Empty();
                    } else {
                      return Container();
                    }
                  }),
                  Expanded(
                    child: Container(
                        width: MediaQuery.sizeOf(context).width,
                        height: MediaQuery.sizeOf(context).height * 1,
                        decoration: BoxDecoration(),
                        child: Obx(() => ListView(
                              controller: scrollController,
                              shrinkWrap: true,
                              scrollDirection: Axis.vertical,
                              children: [
                                const SizedBox(
                                    height: AppConstants.list_start_height),
                                ...List.generate(
                                    controller.model.bookInfoList.length,
                                    (index) {
                                  return MyExperienceWidget(
                                      index: index,
                                      bookExperienceListController: controller);
                                }),
                                SizedBox(
                                  height: AppConstants.list_end_height,
                                )
                              ],
                            ))),
                  )
                ],
              ),
            ),
          ),
        ));
  }
}
