import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/material.dart';

import '../../../common/theme/theme.dart';
import '../../../domain/auth/auth.dart';
import '../../../domain/user/user.dart';

class AppFlushbar {
  static void showSuccess(BuildContext context, String message) {
    Flushbar(
      messageText: Text(
        message,
        style: AppStyle.lg.copyWith(
          color: Colors.white,
          fontWeight: FontWeight.bold,
        ),
      ),
      icon: const Icon(Icons.check_circle, color: Colors.white),
      duration: const Duration(seconds: 2),
      flushbarPosition: FlushbarPosition.BOTTOM,
      backgroundColor: AppColor.secondary,
      borderRadius: BorderRadius.circular(12),
      margin: const EdgeInsets.all(12),
    ).show(context);
  }

  static void showError(BuildContext context, String message) {
    Flushbar(
      messageText: Text(
        message,
        style: AppStyle.lg.copyWith(
          color: Colors.white,
          fontWeight: FontWeight.bold,
          fontSize: 16,
        ),
      ),
      icon: const Icon(Icons.error, color: Colors.white),
      duration: const Duration(seconds: 3),
      flushbarPosition: FlushbarPosition.BOTTOM,
      backgroundColor: AppColor.error,
      borderRadius: BorderRadius.circular(12),
      margin: const EdgeInsets.all(12),
    ).show(context);
  }

  static void showAuthFailureToast(BuildContext context, AuthFailure failure) =>
      showError(
        context,
        failure.map(
          serverError: (value) => value.failure.toStringFormatted(context),
          dynamicErrorMessage: (value) => value.erroMessage,
          unexpectedError: (value) => 'Error has eccoured',
        ),
      );

  static void showUserFailureToast(BuildContext context, UserFailure failure) =>
      showError(
        context,
        failure.map(
          serverError: (value) => value.failure.toStringFormatted(context),
          dynamicErrorMessage: (value) => value.erroMessage,
          unexpectedError: (value) => 'Error has eccoured',
          empty: (value) => 'Data not found',
        ),
      );
}
