import 'package:flutter/material.dart';
import 'package:niogu_ecommerce_v1/core/constant/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_rounded, _successColor, message);
  }

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

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

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

    messenger.removeCurrentSnackBar();

    messenger.showSnackBar(
      SnackBar(
        content: Row(
          children: [
            Container(
              decoration: BoxDecoration(
                color: icon == Icons.warning_amber_rounded
                    ? Colors.transparent
                    : Colors.white,
                shape: BoxShape.circle,
              ),
              child: 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: Colors.white,
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ],
        ),
        backgroundColor: Colors.black,
        behavior: SnackBarBehavior.floating,
        elevation: 4,
        margin: EdgeInsets.all(4.w),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(2.5.w),
        ),
        duration: const Duration(seconds: 3),
      ),
    );
  }
}
