import 'package:flutter/material.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:sizer/sizer.dart';

class CustomSnackbar {
  static const Color _successColor = Color(0xFF4CAF50);
  static const Color _errorColor = Color(0xFFE53935);
  static const Color _warningColor = Color(0xFFFFC107);

  static void showSuccess(BuildContext context, String message) {
    _show(
      context,
      Icons.check_circle_outline,
      Colors.white,
      message,
      Colors.white,
      _successColor,
    );
  }

  static void showError(BuildContext context, String message) {
    _show(
      context,
      Icons.error_outline,
      Colors.white,
      message,
      Colors.white,
      _errorColor,
    );
  }

  static void showWarning(BuildContext context, String message) {
    _show(
      context,
      Icons.warning_amber_outlined,
      Colors.black87,
      message,
      Colors.black87,
      _warningColor,
    );
  }

  static void _show(
    BuildContext context,
    IconData icon,
    Color iconColor,
    String message,
    Color messageColor,
    Color backgroundColor,
  ) {
    final bool isTablet = 100.w >= 600;
    final messenger = ScaffoldMessenger.of(context);

    messenger.removeCurrentSnackBar();

    messenger.showSnackBar(
      SnackBar(
        content: Row(
          children: [
            Icon(icon, color: iconColor, size: 6.w),
            SizedBox(width: 3.w),
            Expanded(
              child: Text(
                message,
                style: TextStyle(
                  fontSize: isTablet
                      ? AppFontSize.medium.sp
                      : AppFontSize.small.sp,
                  fontWeight: FontWeight.w600,
                  color: messageColor,
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ],
        ),
        backgroundColor: backgroundColor,
        behavior: SnackBarBehavior.floating,
        elevation: 4,
        margin: EdgeInsets.all(4.w),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(2.5.w),
        ),
        duration: const Duration(seconds: 3),
      ),
    );
  }
}
