import 'package:flutter/material.dart';

class EmptyState extends StatelessWidget {
  final IconData icon;
  final String title;
  final String? message;
  final Widget? action;
  final Color? foregroundColor;


  final bool compact;

  const EmptyState({
    super.key,
    this.icon = Icons.inbox_outlined,
    required this.title,
    this.message,
    this.action,
    this.foregroundColor,
    this.compact = false,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final iconSize = compact ? 28.0 : 56.0;
    final pad = compact ? 16.0 : 32.0;
    final iconGap = compact ? 8.0 : 18.0;
    final messageGap = compact ? 8.0 : 10.0;
    final actionGap = compact ? 8.0 : 20.0;
    final iconAlpha = compact ? 0.5 : 0.4;
    final titleStyle = compact
        ? theme.textTheme.bodyMedium
        : theme.textTheme.titleMedium;
    final messageText = message == null
        ? null
        : Text(
            message!,
            textAlign: TextAlign.center,
            style: theme.textTheme.bodyMedium?.copyWith(
              color:
                  foregroundColor?.withValues(alpha: 0.72) ??
                  theme.colorScheme.onSurfaceVariant,
            ),
          );
    return Center(
      child: Padding(
        padding: EdgeInsets.all(pad),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Icon(
              icon,
              size: iconSize,
              color: (foregroundColor ?? theme.colorScheme.onSurfaceVariant)
                  .withValues(alpha: iconAlpha),
            ),
            SizedBox(height: iconGap),
            Text(title, style: titleStyle?.copyWith(color: foregroundColor)),
            if (messageText != null) ...[
              SizedBox(height: messageGap),
              compact
                  ? messageText
                  : ConstrainedBox(
                      constraints: const BoxConstraints(maxWidth: 280),
                      child: messageText,
                    ),
            ],
            if (action != null) ...[SizedBox(height: actionGap), action!],
          ],
        ),
      ),
    );
  }
}
