import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:recording_tool/shared/widgets/app_network_image.dart';

class AppAvatar extends StatelessWidget {
  const AppAvatar({super.key, this.imageUrl, this.initials, this.size});

  final String? imageUrl;
  final String? initials;
  final double? size;

  @override
  Widget build(BuildContext context) {
    final effectiveSize = size ?? 40.r;
    final radius = BorderRadius.circular(effectiveSize / 2);
    return ClipRRect(
      borderRadius: radius,
      child: SizedBox.square(
        dimension: effectiveSize,
        child: imageUrl == null || imageUrl!.isEmpty
            ? ColoredBox(
                color: Theme.of(context).colorScheme.primaryContainer,
                child: Center(
                  child: Text(
                    (initials == null || initials!.isEmpty)
                        ? 'A'
                        : initials!.characters.first.toUpperCase(),
                    style: TextStyle(
                      color: Theme.of(context).colorScheme.onPrimaryContainer,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
              )
            : AppNetworkImage(url: imageUrl!, fit: BoxFit.cover),
      ),
    );
  }
}
