part of library;

class LibraryPage extends StatefulWidget {
  const LibraryPage({Key? key}) : super(key: key);

  @override
  State<LibraryPage> createState() => _LibraryPageState();
}

class _LibraryPageState extends State<LibraryPage> with AutomaticKeepAliveClientMixin {

  //AutomaticKeepAliveClientMixin
  @override
  Widget build(BuildContext context) {
    return GetBuilder<LibraryController>(
      init: LibraryController(),
        builder: (controller) => Scaffold(
          appBar: AppBar(
            title: const Text('图书馆'),
            actions: [
              IconButton(
                icon: const Icon(Icons.search_rounded),
                tooltip: 'Open shopping cart',
                onPressed: () {
                  context.pushNamed(Routes.search);
                },
              ),
            ],
          ),
          body: Stack(
            children: [
              Column(
                children: [
                  Container(
                    color: Colors.white,
                    width: double.infinity,
                    child: Container(
                      decoration: BoxDecoration(
                          border: Border.all(width: 0.5.w,color: Colours.cE5)
                      ),
                      child: Row(
                        children: [
                          Expanded(
                            child: TabBar(
                              indicator: BoxDecoration(
                                  border: const Border(bottom: BorderSide(color: Colors.transparent, width: 0.0)), // 将指示器的底边框颜色设置为透明
                                  color: const Color(0xFFC02D55).withOpacity(0.08)
                              ),
                              labelStyle: TextStyle(color: AppTheme.primary,fontSize: 14.w,height: 1.5,fontWeight: Fonts.medium),
                              unselectedLabelColor: Colours.c9,
                              unselectedLabelStyle:  TextStyle(color: Colours.c9,fontSize: 14.w,height: 1.5),
                              controller: controller.tabController,
                              isScrollable: true,
                              tabs: controller.categories.map((model){
                                return Tab(text: model.name);
                              }).toList(),
                            ),
                          ),
                          GestureDetector(
                            onTap: (){
                              controller.setShow(controller.show);
                              // showModalBottomSheet(
                              //   context: context,
                              //   isScrollControlled: true, // 设置为 true
                              //   builder: (BuildContext context) {
                              //     return Container(
                              //       height: MediaQuery.of(context).size.height * 0.9, // 设置高度
                              //       decoration: BoxDecoration(
                              //         color: Colors.white, // 替换为你的背景颜色
                              //       ),
                              //       child: FilterPage(),
                              //     );
                              //   },
                              // );
                            },
                            child: Container(
                              padding: EdgeInsets.symmetric(horizontal: 10.w),
                              alignment: Alignment.center,
                              // color: Colors.cyan,
                              height: 38.w,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    width: 12.w,
                                    height: 12.w,
                                    // color: Colors.red,
                                    alignment: Alignment.center,
                                    child: Image.asset(
                                      'assets/images/filter.png',
                                    ),
                                  ),
                                  Gaps.hGaps5,
                                  Text('筛选',style: TextStyle(color: Colours.c9,fontSize: 14.w,height: 1.5),)
                                ],
                              ),
                              // width: 75,
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 43.w,
                    color: Colours.cF9,
                    child: ListView.builder(
                      scrollDirection:Axis.horizontal ,
                      itemBuilder: (BuildContext context, int index){
                        return GestureDetector(
                          child: BuildLabelWidget(model: controller.labels[index],),
                          onTap: (){
                            controller.selectLabel( controller.labels[index]);
                          },
                        );
                      },
                      itemCount: controller.labels.length,
                    ),
                  ),
                  Container(
                    color: Colors.transparent,
                    padding: EdgeInsets.symmetric(horizontal: 10.w),
                    child: BuildBanner(items: controller.ads,),
                  ),
                  Expanded(
                    child: TabBarView(
                        controller: controller.tabController,
                        children: List.generate(controller.categories.length, (index){
                          print('=======================================$index');
                          return LibraryContentPage(controller: controller,);
                        })
                    ),
                  ),
                ],
              ),
              Visibility(
                visible: controller.show,
                child: FilterPage(
                  controller: controller,
                  sureTap: (){
                    controller.setShow(controller.show);
                },
                  resetTap: (){

                },),
              ),
            ],
          )
        ),
    );
  }


  @override
  bool get wantKeepAlive => true;
}
