import 'package:flutter/material.dart';

import '../theme/kc_colors.dart';
import '../theme/kc_spacing.dart';
import 'kc_card.dart';

/// A shared error-state widget for use across Kell Creations apps.
///
/// Displays a warning icon, an error [message], and an optional [onRetry]
/// action button. Wraps content in a [KcCard] for visual consistency.
class KcErrorState extends StatelessWidget {
  /// The error message to display.
  final String message;

  /// Optional retry callback. When provided, a "Retry" button is shown.
  final VoidCallback? onRetry;

  const KcErrorState({super.key, required this.message, this.onRetry});

  @override
  Widget build(BuildContext context) {
    return KcCard(
      child: Center(
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: KcSpacing.xl),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Icon(Icons.error_outline, size: 48, color: KcColors.danger),
              const SizedBox(height: KcSpacing.md),
              Text(
                message,
                style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: KcColors.danger),
                textAlign: TextAlign.center,
              ),
              if (onRetry != null) ...[
                const SizedBox(height: KcSpacing.md),
                FilledButton.icon(
                  onPressed: onRetry,
                  icon: const Icon(Icons.refresh),
                  label: const Text('Retry'),
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}
