import 'package:flutter/material.dart';
import 'package:sigap/src/utils/helpers/helper_functions.dart';

class DCircularLoader extends StatelessWidget {
  final double? size;
  final double width;
  final Color? color;
  final String? text;
  final TextStyle? textStyle;
  final MainAxisAlignment alignment;

  const DCircularLoader({
    super.key,
    this.size,
    this.width = 2.0,
    this.color,
    this.text,
    this.textStyle,
    this.alignment = MainAxisAlignment.center,
  });

  @override
  Widget build(BuildContext context) {
    final isDarkMode = THelperFunctions.isDarkMode(context);
    final loaderColor =
        color ??
        (isDarkMode
            ? Theme.of(context).colorScheme.primary
            : Theme.of(context).colorScheme.primary);

    return Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: alignment,
      children: [
        SizedBox(
          width: size,
          height: size,
          child: CircularProgressIndicator(
            strokeWidth: width,
            valueColor: AlwaysStoppedAnimation<Color>(loaderColor),
          ),
        ),
        if (text != null) ...[
          const SizedBox(height: 16),
          Text(
            text!,
            style:
                textStyle ??
                Theme.of(context).textTheme.bodyMedium?.copyWith(
                  color: isDarkMode ? Colors.white70 : Colors.black54,
                ),
            textAlign: TextAlign.center,
          ),
        ],
      ],
    );
  }
}

/// A utility class providing different variations of custom loaders
class TLoader {
  /// Returns a full-screen loader with optional text
  static Widget fullScreenLoader({String? text}) {
    return Center(child: DCircularLoader(text: text));
  }

  /// Returns a small loader for buttons or small components
  static Widget smallLoader({Color? color, double size = 20}) {
    return DCircularLoader(size: size, width: 1.5, color: color);
  }

  /// Returns a text loader with a message
  static Widget textLoader({required String text, Color? color}) {
    return DCircularLoader(text: text, color: color);
  }

  /// Returns a centered loader with configurable size
  static Widget centeredLoader({double? size, Color? color}) {
    return Center(child: DCircularLoader(size: size, color: color));
  }

  
}

