import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';

import '../componentRouter/component_service_manager.dart';

// 扩展 RootStackRouter 类
extension RootStackRouterExtensions on RootStackRouter {
  // SlideFadeTransition 动画效果 （平移渐变动画）
  Widget applySlideFadeTransition(
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child,
      ) {
    return SlideTransition(
      position: Tween<Offset>(
        begin: const Offset(1.0, 0.0),
        end: Offset.zero,
      ).animate(animation),
      child: FadeTransition(
        opacity: animation,
        child: child,
      ),
    );
  }

  // SlideTransition 动画效果 (平移动画)
  Widget applySlideTransition(
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child,
      ) {
    return SlideTransition(
      position: Tween<Offset>(
        begin: const Offset(1.0, 0.0),
        end: Offset.zero,
      ).animate(animation),
      child: child,
    );
  }
}

//获取宿主的全局 AppRouter 对象，用于任意地方使用
extension AppRouterExtension on Object {
  RootStackRouter get appRouter => ComponentServiceManager().appService.getAppRouter();
}

//定义一个全局函数来获取 appRouter
RootStackRouter get appRouter => ComponentServiceManager().appService.getAppRouter();