import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:cached_network_image/cached_network_image.dart';

import 'package:pshared/provider/account.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class AccountAvatar extends StatelessWidget {
  const AccountAvatar({super.key});

  @override
  Widget build(BuildContext context) {
    final loc = AppLocalizations.of(context)!;
    return Consumer<AccountProvider>(
      builder: (context, provider, _) => UserAccountsDrawerHeader(
        accountName: Text(provider.account?.name ?? loc.userNamePlaceholder),
        accountEmail: Text(provider.account?.login ?? loc.usernameHint),
        currentAccountPicture: CircleAvatar(
          backgroundImage: (provider.account?.avatarUrl?.isNotEmpty ?? false)
            ? CachedNetworkImageProvider(provider.account!.avatarUrl!)
            : null,
          child: (provider.account?.avatarUrl?.isNotEmpty ?? false)
            ? null
            : const Icon(Icons.account_circle, size: 50),
        ),
      ),
    );
  }
}
