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

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

/// Custom error widget for displaying error states with retry functionality.
///
/// Shows an error icon, message, and optional retry button. Used throughout
/// the app for error states in async operations.
///
/// Example usage:
/// ```dart
/// CustomErrorWidget(
///   message: 'Failed to load products',
///   onRetry: () => _loadProducts(),
/// )
/// ```
class CustomErrorWidget extends StatelessWidget {
  /// Error message to display
  final String message;

  /// Optional callback for retry button. If null, no button is shown.
  final VoidCallback? onRetry;

  /// Optional icon to display. Defaults to error_outline.
  final IconData? icon;

  /// Size of the error icon. Defaults to 64.
  final double iconSize;

  const CustomErrorWidget({
    super.key,
    required this.message,
    this.onRetry,
    this.icon,
    this.iconSize = 64,
  });

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(24.0),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            FaIcon(
              icon ?? FontAwesomeIcons.circleExclamation,
              size: iconSize,
              color: AppColors.danger,
            ),
            const SizedBox(height: 16),
            Text(
              message,
              style: const TextStyle(
                fontSize: 16,
                color: AppColors.grey900,
                fontWeight: FontWeight.w500,
              ),
              textAlign: TextAlign.center,
            ),
            if (onRetry != null) ...[
              const SizedBox(height: 24),
              ElevatedButton.icon(
                onPressed: onRetry,
                icon: const FaIcon(FontAwesomeIcons.arrowsRotate, size: 16),
                label: const Text('Retry'),
                style: ElevatedButton.styleFrom(
                  backgroundColor: AppColors.primaryBlue,
                  foregroundColor: Colors.white,
                  padding: const EdgeInsets.symmetric(
                    horizontal: 24,
                    vertical: 12,
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8),
                  ),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
