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

import 'package:worker/core/theme/colors.dart';

/// Custom loading indicator widget with optional message text.
///
/// Displays a centered three rotating dots animation with an optional
/// message below it. Used for loading states throughout the app.
///
/// Example usage:
/// ```dart
/// CustomLoadingIndicator(
///   message: 'Loading products...',
/// )
/// ```
class CustomLoadingIndicator extends StatelessWidget {
  /// Optional message to display below the loading indicator
  final String? message;

  /// Size of the loading indicator. Defaults to 40.
  final double size;

  /// Color of the loading indicator. Defaults to primaryBlue.
  final Color? color;

  const CustomLoadingIndicator({
    super.key,
    this.message,
    this.size = 40,
    this.color,
  });

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          LoadingAnimationWidget.threeRotatingDots(
            color: color ?? colorScheme.primary,
            size: size,
          ),
          if (message != null) ...[
            const SizedBox(height: 16),
            Text(
              message!,
              style: const TextStyle(fontSize: 14, color: AppColors.grey500),
              textAlign: TextAlign.center,
            ),
          ],
        ],
      ),
    );
  }
}
