import 'package:flutter/material.dart';

import 'package:pweb/utils/initials.dart';


class RecipientAvatar extends StatelessWidget {
  final String name;
  final String? avatarUrl;
  final double avatarRadius;
  final TextStyle? nameStyle;
  final bool isVisible;

  static const double _verticalSpacing = 5;

  const RecipientAvatar({
    super.key,
    required this.name,
    this.avatarUrl,
    required this.avatarRadius,
    this.nameStyle,
    required this.isVisible,
  });

  @override
  Widget build(BuildContext context) {
    final textColor = Theme.of(context).colorScheme.onSecondary;

    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        CircleAvatar(
          radius: avatarRadius,
          backgroundImage: avatarUrl != null ? NetworkImage(avatarUrl!) : null,
          backgroundColor: Theme.of(context).colorScheme.primaryFixed,
          child: avatarUrl == null
              ? Text(
                  getInitials(name),
                  style: TextStyle(
                    color: textColor,
                    fontSize: avatarRadius * 0.8,
                  ),
                )
              : null,
        ),
        const SizedBox(height: _verticalSpacing),
        if (isVisible)
          Text(
            name,
            overflow: TextOverflow.ellipsis,
            style: nameStyle ?? Theme.of(context).textTheme.bodyMedium?.copyWith(fontSize: 14),
          ),
      ],
    );
  }
}
