import 'package:flutter/material.dart';

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

import 'package:pweb/pages/dashboard/payouts/single/adress_book/avatar.dart';
import 'package:pweb/pages/dashboard/payouts/single/adress_book/long_list/info_row.dart';
import 'package:pweb/utils/payment/label.dart';


class RecipientItem extends StatelessWidget {
  final Recipient recipient;
  final VoidCallback onTap;

  static const double _horizontalPadding = 16.0;
  static const double _verticalPadding = 8.0;
  static const double _avatarRadius = 20;
  static const double _spacingWidth = 12;

  const RecipientItem({
    super.key,
    required this.recipient,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Padding(
        padding: const EdgeInsets.symmetric(
          horizontal: _horizontalPadding,
          vertical: _verticalPadding,
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: ListTile(
                contentPadding: EdgeInsets.zero,
                leading: RecipientAvatar(
                  isVisible: false,
                  name: recipient.name,
                  avatarUrl: recipient.avatarUrl,
                  avatarRadius: _avatarRadius,
                  nameStyle: Theme.of(context).textTheme.bodyMedium,
                ),
                title: Text(recipient.name),
                subtitle: Text(recipient.email),
              ),
            ),
            const SizedBox(width: _spacingWidth),
            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                if (recipient.bank?.accountNumber.isNotEmpty == true)
                  PaymentInfoRow(
                    label: getPaymentTypeLabel(context, PaymentType.bankAccount),
                    value: recipient.bank!.accountNumber,
                  ),
                if (recipient.card?.pan.isNotEmpty == true)
                  PaymentInfoRow(
                    label: getPaymentTypeLabel(context, PaymentType.card),
                    value: recipient.card!.pan,
                  ),
                if (recipient.iban?.iban.isNotEmpty == true)
                  PaymentInfoRow(
                    label: getPaymentTypeLabel(context, PaymentType.iban),
                    value: recipient.iban!.iban,
                  ),
                if (recipient.wallet?.walletId.isNotEmpty == true)
                  PaymentInfoRow(
                    label: getPaymentTypeLabel(context, PaymentType.wallet),
                    value: recipient.wallet!.walletId,
                  ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
