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';


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

  @override
  Widget build(BuildContext context) {
    return Consumer<AccountProvider>(
      builder: (context, provider, _) => UserAccountsDrawerHeader(
        accountName: Text(provider.account?.name ?? 'John Doe'),
        accountEmail: Text(provider.account?.login ?? 'john.doe@acme.com'),
        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),
        ),
      ),
    );
  }
}
