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

class KRSnackBarUtil {
  // 全局默认样式配置
  static const Color _defaultBackgroundColor = Colors.black;
  static const double _defaultBorderRadius = 8.0;
  static const EdgeInsets _defaultMargin = EdgeInsets.all(16);
  static const Duration _defaultDuration = Duration(seconds: 3);
  static const SnackPosition _defaultPosition = SnackPosition.TOP;

  static Color _getBgColor() {
    // 默认使用主题的主色
    return Get.theme.primaryColor;
  }

  /// 显示基础消息（使用全局默认样式）
  static void show(String title, String message) {
    Get.snackbar(
      title,
      message,
      backgroundColor: _defaultBackgroundColor,
      colorText: _getBgColor(),
      borderRadius: _defaultBorderRadius,
      margin: _defaultMargin,
      duration: _defaultDuration,
      snackPosition: _defaultPosition,
    );
  }

  /// 显示成功消息
  static void showSuccess(String title, String message) {
    Get.snackbar(
      title,
      message,
      backgroundColor: _defaultBackgroundColor,
      colorText: _getBgColor(),
      borderRadius: _defaultBorderRadius,
      margin: _defaultMargin,
      duration: _defaultDuration,
      snackPosition: _defaultPosition,
      icon: const Icon(
        Icons.check_circle,
        color: Colors.green,
      ),
    );
  }

  /// 显示错误消息
  static void showError(String title, String message) {
    Get.snackbar(
      title,
      message,
      backgroundColor: _defaultBackgroundColor,
      colorText: _getBgColor(),
      borderRadius: _defaultBorderRadius,
      margin: _defaultMargin,
      duration: _defaultDuration,
      snackPosition: _defaultPosition,
      icon: const Icon(
        Icons.error,
        color: Colors.red,
      ),
    );
  }

  /// 显示警告消息
  static void showWarning(String title, String message) {
    Get.snackbar(
      title,
      message,
      backgroundColor: _defaultBackgroundColor,
      colorText: _getBgColor(),
      borderRadius: _defaultBorderRadius,
      margin: _defaultMargin,
      duration: _defaultDuration,
      snackPosition: _defaultPosition,
      icon: const Icon(
        Icons.warning,
        color: Colors.orange,
      ),
    );
  }

  /// 显示信息消息
  static void showInfo(String title, String message) {
    Get.snackbar(
      title,
      message,
      backgroundColor: _defaultBackgroundColor,
      colorText: _getBgColor(),
      borderRadius: _defaultBorderRadius,
      margin: _defaultMargin,
      duration: _defaultDuration,
      snackPosition: _defaultPosition,
      icon: const Icon(
        Icons.info,
        color: Colors.blue,
      ),
    );
  }

  /// 显示自定义样式的消息
  static void showCustom({
    required String title,
    required String message,
    Color? backgroundColor,
    Color? textColor,
    Widget? icon,
    Duration? duration,
    SnackPosition? position,
    double? borderRadius,
    EdgeInsets? margin,
  }) {
    Get.snackbar(
      title,
      message,
      backgroundColor: backgroundColor ?? _defaultBackgroundColor,
      colorText: textColor ?? _getBgColor(),
      borderRadius: borderRadius ?? _defaultBorderRadius,
      margin: margin ?? _defaultMargin,
      duration: duration ?? _defaultDuration,
      snackPosition: position ?? _defaultPosition,
      icon: icon,
    );
  }
}