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

import 'app_inline_alert.dart';

enum AppSnackTone { neutral, error, success, warning }

void showAppSnackBar(
  BuildContext context,
  String message, {
  AppSnackTone tone = AppSnackTone.neutral,
}) {
  final messenger = ScaffoldMessenger.maybeOf(context);
  if (messenger == null) return;

  messenger
    ..hideCurrentSnackBar()
    ..showSnackBar(
      SnackBar(
        content: Text(message),
        behavior: SnackBarBehavior.floating,
        backgroundColor: _backgroundColor(tone),
      ),
    );
}

void showAppToast(
  BuildContext context,
  String message, {
  AppAlertTone tone = AppAlertTone.info,
}) {
  showFToast(
    context: context,
    title: Text(message),
    icon: Icon(_toastIcon(tone), size: 16),
    variant: tone == AppAlertTone.error
        ? FToastVariant.destructive
        : FToastVariant.primary,
  );
}

Color? _backgroundColor(AppSnackTone tone) {
  return switch (tone) {
    AppSnackTone.neutral => null,
    AppSnackTone.error => const Color(0xFFB42318),
    AppSnackTone.success => const Color(0xFF107C41),
    AppSnackTone.warning => const Color(0xFF9A6700),
  };
}

IconData _toastIcon(AppAlertTone tone) {
  return switch (tone) {
    AppAlertTone.error => Icons.error_outline,
    AppAlertTone.warning => Icons.warning_amber_rounded,
    AppAlertTone.info => Icons.info_outline,
    AppAlertTone.success => Icons.check_circle_outline,
  };
}
