import 'dart:ui';
import 'package:flutter/material.dart';
import '../ui_colors.dart';
import '../ui_icons.dart';
import '../ui_typography.dart';

/// Types of snackbars available in the design system.
enum UiSnackbarType {
  /// Success state - green text and light blurred green background.
  success,

  /// Message state - blue text and light blurred blue background.
  message,

  /// Warning state - dark yellow text and light blurred yellow background.
  warning,

  /// Error state - red text and light blurred red background.
  error,
}

/// A centralized snackbar widget that adheres to the design system with glassmorphism effects.
class UiSnackbar {
  UiSnackbar._();

  /// Shows a snackbar with the specified [message] and [type].
  static void show(
    BuildContext context, {
    required String message,
    required UiSnackbarType type,
    Duration duration = const Duration(seconds: 3),
    EdgeInsetsGeometry? margin,
  }) {
    final Color textColor;
    final Color backgroundColor;
    final IconData icon;

    switch (type) {
      case UiSnackbarType.success:
        textColor = UiColors.textSuccess;
        backgroundColor = UiColors.tagSuccess.withValues(alpha: 0.7);
        icon = UiIcons.success;
        break;
      case UiSnackbarType.message:
        textColor = UiColors.primary;
        backgroundColor = UiColors.tagInProgress.withValues(alpha: 0.7);
        icon = UiIcons.info;
        break;
      case UiSnackbarType.warning:
        textColor = UiColors.textWarning;
        backgroundColor = UiColors.tagPending.withValues(alpha: 0.7);
        icon = UiIcons.warning;
        break;
      case UiSnackbarType.error:
        textColor = UiColors.textError;
        backgroundColor = UiColors.tagError.withValues(alpha: 0.7);
        icon = UiIcons.error;
        break;
    }

    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        duration: duration,
        backgroundColor: UiColors.transparent,
        elevation: 0,
        behavior: SnackBarBehavior.floating,
        margin: margin ?? const EdgeInsets.all(16),
        content: ClipRRect(
          borderRadius: BorderRadius.circular(12),
          child: BackdropFilter(
            filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
              decoration: BoxDecoration(
                color: backgroundColor,
                borderRadius: BorderRadius.circular(12),
                border: Border.all(
                  color: textColor.withValues(alpha: 0.2),
                  width: 1,
                ),
              ),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                spacing: 12,
                children: <Widget>[
                  Icon(icon, color: textColor, size: 20),
                  Expanded(
                    child: Text(
                      message,
                      style: UiTypography.body2b.copyWith(color: textColor),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
