import 'package:flutter/material.dart';

import 'package:pshared/models/recipient/recipient.dart';

import 'package:pweb/app/router/payout_routes.dart';
import 'package:pweb/widgets/sidebar/destinations.dart';


class PaymentBackButton extends StatelessWidget {
  final ValueChanged<Recipient?>? onBack;
  final Recipient? recipient;
  final PayoutDestination fallbackDestination;

  const PaymentBackButton({
    super.key,
    required this.onBack,
    required this.recipient,
    required this.fallbackDestination,
  });

  @override
  Widget build(BuildContext context) {
    return Align(
      alignment: Alignment.topLeft,
      child: IconButton(
        icon: const Icon(Icons.arrow_back),
        onPressed: () {
          if (onBack != null) {
            onBack!(recipient);
          } else {
            if (Navigator.of(context).canPop()) {
              Navigator.of(context).pop();
            } else {
              context.goToPayout(fallbackDestination);
            }
          }
        },
      ),
    );
  }
}