import 'package:clean/module/calendar/calendar_view.dart';
import 'package:clean/module/more/more_view.dart';
import 'package:clean/utils/expand.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../base/base_page.dart';
import '../../resource/assets.gen.dart';
import '../../router/app_pages.dart';
import '../home/home_view.dart';
import 'main_controller.dart';
import 'package:flutter/Material.dart';
import 'package:get/get.dart';

class MainTabPage extends BasePage<MainController> {
  MainTabPage({super.key});

  final pages = [
    const CalendarPage(),
    const HomePage(),
    const MorePage(),
  ];

  static void start() {
    Get.offNamed(RoutePath.mainTab, arguments: {});
  }

  @override
  bool immersive() {
    return true;
  }

  @override
  bool statusBarDarkFont() {
    // TODO: implement statusBarDarkFont
    return false;
  }

  @override
  Widget buildBody(BuildContext context) {
    return PopScope(
      canPop: false,
      child: Scaffold(
        bottomNavigationBar: buildBottomAppBar(),
        drawerEdgeDragWidth: 0,
        body: Obx(() {
          return pages[controller.currentIndex];
        }),
      ),
    );
  }

  Widget buildBottomAppBar() {
    return StyleProvider(
      style: BottomTabBarStyle(),
      child: ConvexAppBar(
        height: 65.h,
        backgroundColor: "#0F0F16".color,
        activeColor: Colors.transparent,
        items: [
          TabItem(
              icon: Assets.images.iconTabCalendarUnselect.image(),
              activeIcon: Assets.images.iconTabCalendarSelected.image()),
          TabItem(
              icon: Assets.images.iconTabHomeUnselect.image(),
              activeIcon: Assets.images.iconTabHomeSelected.image()),
          TabItem(
              icon: Assets.images.iconTabMoreUnselect.image(),
              activeIcon: Assets.images.iconTabMoreSelected.image()),
        ],
        initialActiveIndex: controller.currentIndex,
        onTap: (int i) {
          if (controller.currentIndex != i) {
            controller.changeIndex(i);
          }
        },
      ),
    );
  }
}

// tabbar样式
class BottomTabBarStyle extends StyleHook {
  @override
  double get activeIconSize => 52.w;

  @override
  double get activeIconMargin => 12.w;

  @override
  double get iconSize => 24.w;

  @override
  TextStyle textStyle(Color color, String? fontFamily) {
    // TODO: implement textStyle
    return TextStyle(fontSize: 20, color: color);
  }
}
