import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/modules/kr_home/views/kr_home_view.dart';
import 'package:kaer_with_panels/app/modules/kr_invite/views/kr_invite_view.dart';
import 'package:kaer_with_panels/app/modules/kr_statistics/views/kr_statistics_view.dart';
import 'package:kaer_with_panels/app/modules/kr_user_info/views/kr_user_info_view.dart';
import 'package:kaer_with_panels/app/modules/kr_user_info/controllers/kr_user_info_controller.dart';
import 'package:kaer_with_panels/app/widgets/kr_keep_alive_wrapper.dart';

import '../../../widgets/kr_language_switch_dialog.dart';

enum MainRoutes {
  INDEX(0, '首页'),
  DYNAMICS(1, '看看'),
  TOTALLETTER(2, '邮筒'),
  MESSAGELIST(3, '消息'),
  USER_CENTER(4, '我的');

  final int i;
  final String title;

  const MainRoutes(this.i, this.title);
}

class KRMainController extends GetxController {
  static KRMainController get to => Get.find();
  DateTime? lastPopTime;
  var kr_currentIndex = 0.obs;
  final List<Widget> widgets = [
    KRKeepAliveWrapper(KRHomeView()),
    KRKeepAliveWrapper(KRInviteView()),
    KRKeepAliveWrapper(KRStatisticsView()),
    KRKeepAliveWrapper(KRUserInfoView()),
  ];

  /// 分页控制器
  PageController pageController = PageController(keepPage: true);
  @override
  void onInit() {
    super.onInit();


  
  }

  @override
  void onReady() {
    super.onReady();
   
  }

  @override
  void onClose() {
    super.onClose();
  }

  /// 到哪个页面，具体传值查看MainRoutes的枚举类
  kr_setPage(int index) {
    kr_currentIndex.value = index;
    pageController.jumpToPage(index);
    
    // 监控页面进入
    if (index == MainRoutes.USER_CENTER.i) {
      final userInfoController = Get.find<KRUserInfoController>();
      userInfoController.kr_onPageEnter();
    }
  }
}
