import 'package:flutter/material.dart';

import 'package:pshared/models/payment/operation.dart';

import 'package:pweb/controllers/operations/report_operations.dart';
import 'package:pweb/models/state/load_more_state.dart';
import 'package:pweb/pages/report/cards/list.dart';
import 'package:pweb/pages/report/operations/charts_row.dart';
import 'package:pweb/pages/report/table/filters.dart';


class OperationHistoryContent extends StatelessWidget {
  final ReportOperationsController controller;
  final VoidCallback onPickRange;
  final ValueChanged<OperationItem> onOperationTap;

  const OperationHistoryContent({
    super.key,
    required this.controller,
    required this.onPickRange,
    required this.onOperationTap,
  });

  @override
  Widget build(BuildContext context) {
    final operations = controller.operations;
    final filteredOperations = controller.filteredOperations;

    return SingleChildScrollView(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        spacing: 16,
        children: [
          OperationHistoryChartsRow(operations: operations),
          OperationFilters(
            selectedRange: controller.selectedRange,
            selectedStatuses: controller.selectedStatuses,
            onPickRange: onPickRange,
            onToggleStatus: controller.toggleStatus,
            onClear: controller.clearFilters,
          ),
          OperationsCardsList(
            operations: filteredOperations,
            onTap: onOperationTap,
            loadMoreState: controller.loadMoreState,
            onLoadMore: controller.loadMoreState == LoadMoreState.available
                ? () => controller.loadMore()
                : null,
          ),
        ],
      ),
    );
  }
}
