import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/routes/app_router.gr.dart';
import 'package:smart_hotel_app/views/home/index/cubit/home_index_cubit.dart';
import 'package:smart_hotel_app/views/report/index/cubit/report_index_cubit.dart';
import 'package:smart_hotel_app/views/service/index/cubit/service_index_cubit.dart';

@RoutePage()
class DefaultLayoutView extends StatefulWidget {
  const DefaultLayoutView({super.key});

  @override
  State<DefaultLayoutView> createState() => _DefaultLayoutViewState();
}

class _DefaultLayoutViewState extends State<DefaultLayoutView> {
  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider(create: (_) => HomeIndexCubit()),
        BlocProvider(create: (_) => ServiceIndexCubit()),
        BlocProvider(create: (_) => ReportIndexCubit()),
      ],
      child: AutoTabsScaffold(
      routes: const [HomeRoute(), ServiceIndexRoute(), ReportIndexRoute(), ProfileRoute()],
      transitionBuilder: (context, child, animation) => child,
      bottomNavigationBuilder: (context, tabsRouter) {
        return Container(
          decoration: const BoxDecoration(
            color: Colors.white,
            border: Border(
              top: BorderSide(color: Color(0xFFE5E5E5), width: 0.5),
            ),
          ),
          child: BottomNavigationBar(
            currentIndex: tabsRouter.activeIndex,
            onTap: tabsRouter.setActiveIndex,
            elevation: 0,
            backgroundColor: Colors.white,
            selectedItemColor: const Color(0xFF4995EA),
            unselectedItemColor: const Color(0xFF666666),
            type: BottomNavigationBarType.fixed,
            selectedFontSize: 24.sp,
            unselectedFontSize: 24.sp,
            items: [
              BottomNavigationBarItem(
                icon: Image.asset(
                  'lib/assets/tab/tab1.png',
                  width: 48.w,
                  height: 48.h,
                ),
                activeIcon: Image.asset(
                  'lib/assets/tab/tab1_active.png',
                  width: 48.w,
                  height: 48.h,
                ),
                label: "告警",
              ),
              BottomNavigationBarItem(
                icon: Image.asset(
                  'lib/assets/tab/tab2.png',
                  width: 48.w,
                  height: 48.h,
                ),
                activeIcon: Image.asset(
                  'lib/assets/tab/tab2_active.png',
                  width: 48.w,
                  height: 48.h,
                ),
                label: "管理",
              ),
              BottomNavigationBarItem(
                icon: Image.asset(
                  'lib/assets/tab/tab3.png',
                  width: 48.w,
                  height: 48.h,
                ),
                activeIcon: Image.asset(
                  'lib/assets/tab/tab3_active.png',
                  width: 48.w,
                  height: 48.h,
                ),
                label: "能耗",
              ),
              BottomNavigationBarItem(
                icon: Image.asset(
                  'lib/assets/tab/tab4.png',
                  width: 48.w,
                  height: 48.h,
                ),
                activeIcon: Image.asset(
                  'lib/assets/tab/tab4_active.png',
                  width: 48.w,
                  height: 48.h,
                ),
                label: "我的",
              ),
            ],
          ),
        );
      },
    ),
    );
  }
}
