import 'package:flutter/material.dart';

import 'package:pweb/controllers/payouts/payout_volumes.dart';


Future<void> pickPayoutVolumesRange(
  BuildContext context,
  PayoutVolumesController controller,
) async {
  final now = DateTime.now();
  final initial = _dateOnlyRange(controller.range);
  final picked = await showDateRangePicker(
    context: context,
    firstDate: DateTime(2000),
    lastDate: DateUtils.dateOnly(now).add(const Duration(days: 1)),
    initialDateRange: initial,
  );
  if (picked != null) {
    controller.setRange(picked);
  }
}

DateTimeRange _dateOnlyRange(DateTimeRange range) {
  return DateTimeRange(
    start: DateUtils.dateOnly(range.start),
    end: DateUtils.dateOnly(range.end),
  );
}
