import 'package:flutter/material.dart';

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

import 'package:pweb/controllers/operations/report_operations.dart';
import 'package:pweb/utils/report/payment_mapper.dart';
import 'package:pweb/app/router/payout_routes.dart';


Future<void> pickOperationsRange(
  BuildContext context,
  ReportOperationsController controller,
) async {
  final now = DateTime.now();
  final initial =
      controller.selectedRange ??
      DateTimeRange(start: now.subtract(const Duration(days: 30)), end: now);

  final picked = await showDateRangePicker(
    context: context,
    firstDate: DateTime(2000),
    lastDate: now.add(const Duration(days: 1)),
    initialDateRange: initial,
  );

  if (picked != null) {
    controller.setRange(picked);
  }
}

void openPaymentDetails(BuildContext context, OperationItem operation) {
  final paymentId = paymentIdFromOperation(operation);
  if (paymentId == null) return;

  context.pushToReportPayment(paymentId);
}
