import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/provider/payment/multiple/quotation.dart';

import 'package:pweb/controllers/payouts/multiple_payouts.dart';
import 'package:pweb/controllers/payouts/payout_verification.dart';
import 'package:pweb/utils/payment/verification_flow.dart';
import 'package:pweb/widgets/dialogs/payment_status_dialog.dart';


Future<void> handleMultiplePayoutSend(
  BuildContext context,
  MultiplePayoutsController controller,
) async {
  final verificationController = context.read<PayoutVerificationController>();
  final quotationProvider = context.read<MultiQuotationProvider>();
  final verificationContextKey = quotationProvider.quotation?.quoteRef ??
      quotationProvider.quotation?.idempotencyKey;
  final verified = await runPayoutVerification(
    context: context,
    controller: verificationController,
    contextKey: verificationContextKey,
  );
  if (!verified) return;

  final outcome = await controller.sendAndGetOutcome();

  if (!context.mounted) return;

  await showPaymentStatusDialog(
    context,
    isSuccess: outcome == MultiplePayoutSendOutcome.success,
  );

  controller.removeUploadedFile();
}
