import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pweb/controllers/operations/report_operations.dart';
import 'package:pweb/pages/report/operations/actions.dart';
import 'package:pweb/pages/report/operations/content.dart';
import 'package:pweb/pages/report/operations/states/error.dart';
import 'package:pweb/pages/report/operations/states/loading.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class OperationHistoryView extends StatelessWidget {
  const OperationHistoryView({super.key});

  @override
  Widget build(BuildContext context) {
    final loc = AppLocalizations.of(context)!;
    return Consumer<ReportOperationsController>(
      builder: (context, controller, child) {
        if (controller.isLoading) {
          return const OperationHistoryLoading();
        }

        if (controller.error != null) {
          final message = controller.error?.toString() ?? loc.noErrorInformation;
          return OperationHistoryError(
            message: loc.notificationError(message),
            retryLabel: loc.retry,
            onRetry: controller.refresh,
          );
        }

        return OperationHistoryContent(
          controller: controller,
          onPickRange: () => pickOperationsRange(context, controller),
          onOperationTap: (operation) =>
              openPaymentDetails(context, operation),
        );
      },
    );
  }
}
