import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:get/get_navigation/src/router_report.dart';

import '../my_router_history_manager.dart';



final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();

/// 手动让getx感知原生路由 (固定代码无需修改)
class GetXRouterObserver extends NavigatorObserver {
  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    RouterReportManager.reportCurrentRoute(route);
    MyRouterHistoryManager().putRouterByName(route.settings.name);
    if (!kReleaseMode){
     print('添加之后-当前的My路由表：${MyRouterHistoryManager().routeNames.toString()}') ;
    }
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) async {
    RouterReportManager.reportRouteDispose(route);
    MyRouterHistoryManager().removeRouterByName(route.settings.name);
    if (!kReleaseMode){
      print('Pop之后-当前的My路由表：${MyRouterHistoryManager().routeNames.toString()}');
    }
  }

  @override
  void didRemove(Route route, Route? previousRoute) {
    MyRouterHistoryManager().removeRouterByName(route.settings.name);
    if (!kReleaseMode){
      print('Remove之后-当前的My路由表：${MyRouterHistoryManager().routeNames.toString()}');
    }
  }

  @override
  void didReplace({Route? newRoute, Route? oldRoute}) {
    MyRouterHistoryManager().putRouterByName(newRoute?.settings.name);
    MyRouterHistoryManager().removeRouterByName(oldRoute?.settings.name);
    if (!kReleaseMode){
      print('Replace之后-当前的My路由表：${MyRouterHistoryManager().routeNames.toString()}');
    }
  }
}
