import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'kr_simple_loading.dart';

/// 加载动画类型
enum KRLoadingType {
  /// 波纹动画
  kr_ripple,
  
  /// 双波纹动画
  kr_doubleBounce,
  
  /// 波浪动画
  kr_wave,
  
  /// 脉冲动画
  kr_pulse,
  
  /// 旋转动画
  kr_rotatingCircle,
  
  /// 折叠动画
  kr_foldingCube,
}

/// 自定义加载动画组件
class KRLoadingAnimation extends StatelessWidget {
  /// 动画颜色
  final Color? color;
  
  /// 动画大小
  final double? size;
  
  /// 动画类型
  final KRLoadingType type;

  /// 构造函数
  const KRLoadingAnimation({
    Key? key,
    this.color = Colors.blue,
    this.size,
    this.type = KRLoadingType.kr_ripple,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final defaultColor = color ?? Theme.of(context).primaryColor;
    final defaultSize = size ?? 15.0;

    return _kr_buildAnimation(defaultColor, defaultSize);
  }

  /// 构建动画
  Widget _kr_buildAnimation(Color color, double size) {
    switch (type) {
      case KRLoadingType.kr_ripple:
        return KRSimpleLoading(
          color: color,
          size: size,
        );
      case KRLoadingType.kr_doubleBounce:
        return KRSimpleLoading(
          color: color,
          size: size,
        );
      case KRLoadingType.kr_wave:
        return KRSimpleWave(
          color: color,
          size: size,
        );
      case KRLoadingType.kr_pulse:
        return KRSimplePulse(
          color: color,
          size: size,
        );
      case KRLoadingType.kr_rotatingCircle:
        return KRSimpleLoading(
          color: color,
          size: size,
        );
      case KRLoadingType.kr_foldingCube:
        return KRSimpleLoading(
          color: color,
          size: size,
        );
    }
  }
} 