import 'package:flutter/widgets.dart';

import '../../../common/data/report_menu.dart';
import '../../../domain/analytic/analytic.dart';
import '../card/error_card.dart';

class AnalyticErrorStateWidget extends StatelessWidget {
  final AnalyticFailure failure;
  final ReportMenu menu;
  final Function() onRefresh;
  const AnalyticErrorStateWidget({
    super.key,
    required this.failure,
    required this.menu,
    required this.onRefresh,
  });

  @override
  Widget build(BuildContext context) {
    return failure.maybeMap(
      orElse: () => ErrorCard(
        title: menu.title,
        message: 'Terjadi kesalahan, Silakan coba lagi!',
        onTap: onRefresh,
      ),
      dynamicErrorMessage: (value) => ErrorCard(
        title: menu.title,
        message: value.erroMessage,
        onTap: onRefresh,
      ),
      serverError: (value) => ErrorCard(
        title: menu.title,
        message: 'Server Error, Silakan coba lagi!',
        onTap: onRefresh,
      ),
      unexpectedError: (value) => ErrorCard(
        title: menu.title,
        message: 'Terjadi kesalahan, Silakan coba lagi!',
        onTap: onRefresh,
      ),
    );
  }
}
