import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'slide_transparent_transition.dart';

/// 全局页面过渡动画配置类
class TransitionConfig {
  static Duration _defaultDuration = const Duration(milliseconds: 150);
  static const SlideDirection _defaultDirection = SlideDirection.rightToLeft;
  static const Curve _defaultCurve = Curves.easeOutCubic;

  /// 默认动画持续时间
  static Duration get defaultDuration => _defaultDuration;

  /// 默认滑动方向
  static SlideDirection get defaultDirection => _defaultDirection;

  /// 默认动画曲线
  static Curve get defaultCurve => _defaultCurve;

  /// 创建默认的滑动过渡动画
  static SlideTransparentTransition createDefaultTransition() {
    return SlideTransparentTransition(
      direction: _defaultDirection,
      duration: _defaultDuration,
    );
  }

  /// 创建自定义滑动过渡动画
  static SlideTransparentTransition createCustomTransition({
    SlideDirection? direction,
    Duration? duration,
  }) {
    return SlideTransparentTransition(
      direction: direction ?? _defaultDirection,
      duration: duration ?? _defaultDuration,
    );
  }

  /// 创建从左到右的过渡动画（通常用于返回操作）
  static SlideTransparentTransition createLeftToRightTransition({
    Duration? duration,
  }) {
    return SlideTransparentTransition(
      direction: SlideDirection.leftToRight,
      duration: duration ?? _defaultDuration,
    );
  }

  /// 创建从右到左的过渡动画（通常用于前进操作）
  static SlideTransparentTransition createRightToLeftTransition({
    Duration? duration,
  }) {
    return SlideTransparentTransition(
      direction: SlideDirection.rightToLeft,
      duration: duration ?? _defaultDuration,
    );
  }
}

/// 全局路由助手类
class RouteHelper {
  /// 使用自定义过渡动画跳转到指定页面
  static Future<T?>? toWithCustomTransition<T>(
    Widget page, {
    SlideDirection? direction,
    Duration? duration,
    bool? opaque,
    Curve? curve,
    String? routeName,
    bool fullscreenDialog = false,
    dynamic arguments,
    Bindings? binding,
    bool preventDuplicates = true,
    bool? popGesture,
  }) {
    // 使用 Get.to 并依赖全局配置的 customTransition
    return Get.to<T>(
      page,
      duration: duration ?? TransitionConfig.defaultDuration,
      opaque: opaque,
      curve: curve ?? TransitionConfig.defaultCurve,
      routeName: routeName,
      fullscreenDialog: fullscreenDialog,
      arguments: arguments,
      binding: binding,
      preventDuplicates: preventDuplicates,
      popGesture: popGesture,
    );
  }

  /// 使用自定义过渡动画跳转到命名路由
  static Future<T?>? toNamedWithCustomTransition<T>(
    String page, {
    dynamic arguments,
    bool preventDuplicates = true,
    Map<String, String>? parameters,
  }) {
    return Get.toNamed<T>(
      page,
      arguments: arguments,
      preventDuplicates: preventDuplicates,
      parameters: parameters,
    );
  }
}
