import 'package:flutter/material.dart';

import 'package:pshared/models/recipient/recipient.dart';
import 'package:pweb/pages/dashboard/payouts/single/address_book/avatar.dart';


class ShortListAddressBookPayout extends StatelessWidget {
  final List<Recipient> recipients;
  final ValueChanged<Recipient> onSelected;
  final Widget? leading;

  const ShortListAddressBookPayout({
    super.key,
    required this.recipients,
    required this.onSelected,
    this.leading,
  });

  static const double _avatarRadius = 20;
  static const double _avatarSize = 80;
  static const EdgeInsets _padding = EdgeInsets.symmetric(
    horizontal: 10,
    vertical: 8,
  );
  static const TextStyle _nameStyle = TextStyle(fontSize: 12);

  @override
  Widget build(BuildContext context) {
    final leadingWidget = leading;
    final recipientItems = recipients.map((recipient) {
      return Padding(
        padding: _padding,
        child: InkWell(
          borderRadius: BorderRadius.circular(5),
          hoverColor: Theme.of(context).colorScheme.onTertiary,
          onTap: () => onSelected(recipient),
          child: SizedBox(
            height: _avatarSize,
            width: _avatarSize,
            child: RecipientAvatar(
              isVisible: true,
              name: recipient.name,
              avatarUrl: recipient.avatarUrl,
              avatarRadius: _avatarRadius,
              nameStyle: _nameStyle,
            ),
          ),
        ),
      );
    });

    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Row(
        children: [
          if (leadingWidget != null)
            Padding(padding: _padding, child: leadingWidget),
          ...recipientItems,
        ],
      ),
    );
  }
}
